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

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

10
export function criteriaReducer(state: ICriter = CRITERIA_INITIAL_STATE, action): ICriter {
11
  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;
*/