sectorcourses.actions.ts 1.49 KB
Newer Older
1
import { NgRedux } from "@angular-redux/store";
2 3 4
import { Injectable } from "@angular/core";

import { SECTORCOURSES_INIT, SECTORCOURSES_RECEIVED, SECTORCOURSES_SELECTED_SAVE } from "../constants";
5
import { HelperDataService } from "../services/helper-data-service";
6
import { IAppState } from "../store";
7 8 9

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

14 15 16 17 18 19 20 21 22 23 24
    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
                    }
                });
25
            });
26 27
        }
    };
28

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

37
    saveSectorCoursesSelected = (oldSIndex, oldCIndex, checked, i, j) => {
38 39 40
        return this._ngRedux.dispatch({
            type: SECTORCOURSES_SELECTED_SAVE,
            payload: {
41 42 43 44 45
                oldSIndex: oldSIndex,
                oldCIndex: oldCIndex,
                checked: checked,
                sIndex: i,
                cIndex: j
46 47 48
            }
        });
    };
49 50

}