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

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

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

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

36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
 /*
  getSectorCourses_Reload = () => {
    const { sectors } = this._ngRedux.getState();
    //if (sectors.size === 0) {
        return this._hds.getSectorsWithCourses().then(sectors => {
            return this._ngRedux.dispatch({
                type: SECTORCOURSES_RECEIVED,
                payload: {
                    sectors
                }
            });
        });
    //}
  };
  */

  saveSectorCoursesSelected = (sectorCoursesSelected,sectorSelected) => {
53 54 55
      return this._ngRedux.dispatch({
        type: SECTORCOURSES_SELECTED_SAVE,
        payload: {
56 57
          sectorCoursesSelected,
          sectorSelected
58 59 60 61 62
        }
      });
  };

}