criteria.actions.ts 1.21 KB
Newer Older
1
import { CRITERIA_RECEIVED, CRITERIA_SAVE, CRITERIA_INIT } from '../constants';
2
import { Injectable } from '@angular/core';
3
import { NgRedux } from '@angular-redux/store';
4
import { IAppState } from '../store';
5
import { HelperDataService } from '../services/helper-data-service';
6 7 8 9

@Injectable()
export class CriteriaActions {
  constructor(
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
    private _ngRedux: NgRedux<IAppState>,
    private _hds: HelperDataService) {}

    getCriteria = (reload) => {
        const { criter } = this._ngRedux.getState();
        //if (sectorFields.size === 0) {
        if (reload === true || (reload === false && criter.size === 0)) {
            return this._hds.getCriteria().then(criteria => {
                return this._ngRedux.dispatch({
                    type: CRITERIA_RECEIVED,
                    payload: {
                        criteria
                    }
                });
            });
        }
    };
27 28 29 30 31 32 33 34 35 36

  saveCriteria = (criter) => {
      return this._ngRedux.dispatch({
        type: CRITERIA_SAVE,
        payload: {
          criter
        }
      });
  };

37 38 39 40 41 42 43 44
  initCriteria = () => {
        return this._ngRedux.dispatch({
            type: CRITERIA_INIT,
            payload: {
            }
        });
    };

45
}