sectorfields.actions.ts 1.36 KB
Newer Older
1
import { SECTORFIELDS_RECEIVED, SECTORFIELDS_SELECTED_SAVE, SECTORFIELDS_INIT } from '../constants';
2
import { Injectable } from '@angular/core';
3
import { NgRedux } from '@angular-redux/store';
4 5 6 7 8
import { IAppState } from '../store';
import { HelperDataService } from '../services/helper-data-service';

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

13 14 15 16 17 18 19 20 21 22 23
    getSectorFields = (reload) => {
        const { sectorFields } = this._ngRedux.getState();
        //if (sectorFields.size === 0) {
        if (reload === true || (reload === false && sectorFields.size === 0)) {
            return this._hds.getSectorFields().then(sectorFields => {
                return this._ngRedux.dispatch({
                    type: SECTORFIELDS_RECEIVED,
                    payload: {
                        sectorFields
                    }
                });
24
            });
25 26 27 28 29 30 31 32
        }
    };

    initSectorFields = () => {
        return this._ngRedux.dispatch({
            type: SECTORFIELDS_INIT,
            payload: {
            }
33
        });
34
    };
35

36 37 38 39 40 41 42 43 44

    saveSectorFieldsSelected = (sectorFieldsSelected) => {
        return this._ngRedux.dispatch({
            type: SECTORFIELDS_SELECTED_SAVE,
            payload: {
                sectorFieldsSelected
            }
        });
    };
45 46

}