sectorcourses.actions.ts 1.94 KB
Newer Older
1
import { SECTORCOURSES_RECEIVED, SECTORCOURSES_SECTOR_SELECTED_SAVE, SECTORCOURSES_SELECTED_SAVE, SECTORCOURSES_INIT } from "../constants";
2
3
4
5
import { Injectable } from "@angular/core";
import { NgRedux } from "@angular-redux/store";
import { IAppState } from "../store";
import { HelperDataService } from "../services/helper-data-service";
6
7
8

@Injectable()
export class SectorCoursesActions {
9
10
11
    constructor(
        private _ngRedux: NgRedux<IAppState>,
        private _hds: HelperDataService) { }
12

13
14
15
16
17
18
19
20
21
22
23
    getSectorCourses = (reload) => {
        const { sectors } = this._ngRedux.getState();
        // if (sectors.size === 0) {
        if (reload === true || (reload === false && sectors.size === 0)) {
            return this._hds.getSectorsWithCourses().then(sectors => {
                return this._ngRedux.dispatch({
                    type: SECTORCOURSES_RECEIVED,
                    payload: {
                        sectors
                    }
                });
24
            });
25
26
        }
    };
27

28
29
30
31
32
    initSectorCourses = () => {
        return this._ngRedux.dispatch({
            type: SECTORCOURSES_INIT,
            payload: {
            }
33
        });
34
    };
35

36
37
38
39
40
41
42
43
44
45
46
47
48
    selectSector = (prevChoice, newChoice) => {
        return this._ngRedux.dispatch({
            type: SECTORCOURSES_SECTOR_SELECTED_SAVE,
            payload: {
                prevChoice: prevChoice,
                newChoice: newChoice
//                sectorCoursesSelected,
//                sectorSelected
            }
        });
    }

    saveSectorCoursesSelected = (oldSIndex, oldCIndex, checked, i, j) => {
49
50
51
        return this._ngRedux.dispatch({
            type: SECTORCOURSES_SELECTED_SAVE,
            payload: {
52
53
54
55
56
57
58
                oldSIndex: oldSIndex,
                oldCIndex: oldCIndex,
                checked: checked,
                sIndex: i,
                cIndex: j
//                sectorCoursesSelected,
//                sectorSelected
59
60
61
            }
        });
    };
62
63

}