regionschools.actions.ts 1.96 KB
Newer Older
1
import { REGIONSCHOOLS_RECEIVED, REGIONSCHOOLS_SELECTED_SAVE,  REGIONSCHOOLS_ORDER_SAVE, REGIONSCHOOLS_INIT } from '../constants';
2 3 4 5 6 7 8 9 10 11 12
import { Injectable } from '@angular/core';
import { NgRedux } from 'ng2-redux';
import { IAppState } from '../store';
import { HelperDataService } from '../services/helper-data-service';

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

13
  getRegionSchools = (classActive,courseActive, reload) => {
14
    const { regions } = this._ngRedux.getState();
15
    if (reload === true || (reload === false && regions.size === 0)) {
Open Source Developer's avatar
Open Source Developer committed
16
        console.log("test1", classActive,courseActive, reload);
17
        return this._hds.getRegionsWithSchools(classActive,courseActive).then(regions => {
18 19 20 21 22 23 24 25 26 27
            return this._ngRedux.dispatch({
                type: REGIONSCHOOLS_RECEIVED,
                payload: {
                    regions
                }
            });
        });
    }
  };

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

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

52 53 54 55 56 57 58 59 60
  saveRegionSchoolsSelected = (regionSchoolsSelected) => {
      return this._ngRedux.dispatch({
        type: REGIONSCHOOLS_SELECTED_SAVE,
        payload: {
          regionSchoolsSelected
        }
      });
  };

61 62 63 64 65 66 67 68 69
  saveRegionSchoolsOrder = (regionSchoolsOrder) => {
      return this._ngRedux.dispatch({
        type: REGIONSCHOOLS_ORDER_SAVE,
        payload: {
          regionSchoolsOrder
        }
      });
  };

70
}