criteria.reducer.ts 1.46 KB
Newer Older
1 2 3 4 5
import { ICriteria, ICriter } from './criteria.types';
import { INITIAL_STATE } from './criteria.initial-state';
import { Seq } from 'immutable';

import {
6
  CRITERIA_RECEIVED,
7 8 9 10 11
  CRITERIA_SAVE
} from '../../constants';

export function criteriaReducer(state: ICriter = INITIAL_STATE, action): ICriter {
  switch (action.type) {
12 13 14 15 16 17 18 19 20
    case CRITERIA_RECEIVED:
        let newCriter = Array<ICriteria>();
        let i=0;
        action.payload.criteria.forEach(criteria => {
            newCriter.push(<ICriteria>{id: criteria.id, name: criteria.name, mutual_disabled_id: criteria.mutual_disabled_id, selected:  false});
            i++;
        });
        return Seq(newCriter).map(n => n).toList();

21 22 23
    case CRITERIA_SAVE:
        let criter = Array<ICriteria>();
        let ind=0;
24 25
        state.forEach(criteria => {
            criter.push(<ICriteria>{id: criteria.id, name: criteria.name, mutual_disabled_id: criteria.mutual_disabled_id, selected: action.payload.criter[0][ind]});
26 27 28 29 30 31 32
            ind++;
        });

        return Seq(criter).map(n => n).toList();
    default: return state;
  }
};
33 34 35 36 37 38 39 40 41 42 43
/*
case COURSEFIELDS_SELECTED_SAVE:
    let selectedCourseFields = Array<ICourseField>();
    let ind=0;
    state.forEach(courseField => {
        selectedCourseFields.push(<ICourseField>{id: courseField.id, name: courseField.name, selected: action.payload.courseFieldsSelected[ind]});
        ind++;
    });
    return Seq(selectedCourseFields).map(n => n).toList();
default: return state;
*/