diff --git a/source/actions/coursefields.actions.ts b/source/actions/coursefields.actions.ts index 21af6af3e5ce7d23b40164ac8684bc233916d253..f97ef169939c4b2ab868285ef54ca0581d823e41 100644 --- a/source/actions/coursefields.actions.ts +++ b/source/actions/coursefields.actions.ts @@ -11,14 +11,17 @@ export class CourseFieldsActions { private _hds: HelperDataService) {} getCourseFields = () => { - return this._hds.getCourseFields().then(courseFields => { - return this._ngRedux.dispatch({ - type: COURSEFIELDS_RECEIVED, - payload: { - courseFields - } - }); - }); + const { courseFields } = this._ngRedux.getState(); + if (courseFields.size === 0) { + return this._hds.getCourseFields().then(courseFields => { + return this._ngRedux.dispatch({ + type: COURSEFIELDS_RECEIVED, + payload: { + courseFields + } + }); + }); + } }; saveCourseFieldsSelected = (courseFieldsSelected) => { diff --git a/source/components/student-application-form/course-fields-select.ts b/source/components/student-application-form/course-fields-select.ts index 50dbc73f3eb78f2a0ab8cc20eb139e3b2b50bf12..210c19f5ad50eac46be462f10fcef3d6899db337 100644 --- a/source/components/student-application-form/course-fields-select.ts +++ b/source/components/student-application-form/course-fields-select.ts @@ -4,7 +4,7 @@ import { Observable } from 'rxjs/Rx'; import { Injectable } from "@angular/core"; import { CourseFieldsActions } from '../../actions/coursefields.actions'; import { DevToolsExtension, NgRedux, select } from 'ng2-redux'; -import { ICourseFields } from '../../store/coursefields/coursefields.types'; +import { ICourseFields, ICourseField } from '../../store/coursefields/coursefields.types'; import { IAppState } from '../../store/store'; import { @@ -53,12 +53,14 @@ import {AppSettings} from '../../app.settings'; }; ngOnInit() { + this._cfa.getCourseFields(); this.courseFields$ = this._ngRedux.select(state => { - for (let courseField in state.courseFields) { - this.cfs.push(new FormControl('', [])); - } + state.courseFields.reduce(({}, courseField) =>{ + this.cfs.push(new FormControl(courseField.selected, [])); + return courseField; + }, {}); return state.courseFields; }); @@ -67,4 +69,6 @@ import {AppSettings} from '../../app.settings'; saveSelected() { this._cfa.saveCourseFieldsSelected(this.formGroup.value.formArray); } + + }