Restructured sectorFields. Fixed form bugs

parent b3b0fba0
...@@ -34,11 +34,12 @@ export class SectorFieldsActions { ...@@ -34,11 +34,12 @@ export class SectorFieldsActions {
}; };
saveSectorFieldsSelected = (sectorFieldsSelected) => { saveSectorFieldsSelected = (prevChoice: number, newChoice: number) => {
return this._ngRedux.dispatch({ return this._ngRedux.dispatch({
type: SECTORFIELDS_SELECTED_SAVE, type: SECTORFIELDS_SELECTED_SAVE,
payload: { payload: {
sectorFieldsSelected prevChoice: prevChoice,
newChoice: newChoice
} }
}); });
}; };
......
...@@ -8,7 +8,7 @@ import { SectorFieldsActions } from "../../actions/sectorfields.actions"; ...@@ -8,7 +8,7 @@ import { SectorFieldsActions } from "../../actions/sectorfields.actions";
import { SectorCoursesActions } from "../../actions/sectorcourses.actions"; import { SectorCoursesActions } from "../../actions/sectorcourses.actions";
import { RegionSchoolsActions } from "../../actions/regionschools.actions"; import { RegionSchoolsActions } from "../../actions/regionschools.actions";
import { EpalClassesActions } from "../../actions/epalclass.actions"; import { EpalClassesActions } from "../../actions/epalclass.actions";
import { ISectorFields } from "../../store/sectorfields/sectorfields.types"; import { ISectorFieldRecords } from "../../store/sectorfields/sectorfields.types";
import { ISectors } from "../../store/sectorcourses/sectorcourses.types"; import { ISectors } from "../../store/sectorcourses/sectorcourses.types";
import { IRegionRecord, IRegionRecords, IRegionSchoolRecord } from "../../store/regionschools/regionschools.types"; import { IRegionRecord, IRegionRecords, IRegionSchoolRecord } from "../../store/regionschools/regionschools.types";
import { IEpalClasses } from "../../store/epalclasses/epalclasses.types"; import { IEpalClasses } from "../../store/epalclasses/epalclasses.types";
...@@ -82,7 +82,7 @@ import { SECTOR_FIELDS_INITIAL_STATE } from "../../store/sectorfields/sectorfiel ...@@ -82,7 +82,7 @@ import { SECTOR_FIELDS_INITIAL_STATE } from "../../store/sectorfields/sectorfiel
private sectors$: BehaviorSubject<ISectors>; private sectors$: BehaviorSubject<ISectors>;
private regions$: BehaviorSubject<IRegionRecords>; private regions$: BehaviorSubject<IRegionRecords>;
private selectedSchools$: BehaviorSubject<Array<IRegionSchoolRecord>> = new BehaviorSubject(Array()); private selectedSchools$: BehaviorSubject<Array<IRegionSchoolRecord>> = new BehaviorSubject(Array());
private sectorFields$: BehaviorSubject<ISectorFields>; private sectorFields$: BehaviorSubject<ISectorFieldRecords>;
private epalclasses$: BehaviorSubject<IEpalClasses>; private epalclasses$: BehaviorSubject<IEpalClasses>;
private epalclassesSub: Subscription; private epalclassesSub: Subscription;
private sectorsSub: Subscription; private sectorsSub: Subscription;
...@@ -128,8 +128,6 @@ import { SECTOR_FIELDS_INITIAL_STATE } from "../../store/sectorfields/sectorfiel ...@@ -128,8 +128,6 @@ import { SECTOR_FIELDS_INITIAL_STATE } from "../../store/sectorfields/sectorfiel
let rgns = <IRegionRecords>regions; let rgns = <IRegionRecords>regions;
let numsel = 0, numsel2 = 0; let numsel = 0, numsel2 = 0;
let selectedSchools = Array<IRegionSchoolRecord>(); let selectedSchools = Array<IRegionSchoolRecord>();
if (rgns.size === 0)
return;
rgns.reduce((prevRegion, region) => { rgns.reduce((prevRegion, region) => {
region.get("epals").reduce((prevEpal, epal) => { region.get("epals").reduce((prevEpal, epal) => {
if (epal.get("selected") === true) { if (epal.get("selected") === true) {
...@@ -150,7 +148,7 @@ import { SECTOR_FIELDS_INITIAL_STATE } from "../../store/sectorfields/sectorfiel ...@@ -150,7 +148,7 @@ import { SECTOR_FIELDS_INITIAL_STATE } from "../../store/sectorfields/sectorfiel
this.sectorFieldsSub = this._ngRedux.select("sectorFields") this.sectorFieldsSub = this._ngRedux.select("sectorFields")
.subscribe(sectorFields => { .subscribe(sectorFields => {
this.sectorFields$.next(<ISectorFields>sectorFields); this.sectorFields$.next(<ISectorFieldRecords>sectorFields);
}, error => { console.log("error selecting sectorFields"); }); }, error => { console.log("error selecting sectorFields"); });
this.epalclassesSub = this._ngRedux.select("epalclasses") this.epalclassesSub = this._ngRedux.select("epalclasses")
......
...@@ -8,7 +8,7 @@ import { IAppState } from "../../store/store"; ...@@ -8,7 +8,7 @@ import { IAppState } from "../../store/store";
import { IStudentDataFields } from "../../store/studentdatafields/studentdatafields.types"; import { IStudentDataFields } from "../../store/studentdatafields/studentdatafields.types";
import { IRegionRecord, IRegionRecords, IRegionSchoolRecord } from "../../store/regionschools/regionschools.types"; import { IRegionRecord, IRegionRecords, IRegionSchoolRecord } from "../../store/regionschools/regionschools.types";
import { ISectors } from "../../store/sectorcourses/sectorcourses.types"; import { ISectors } from "../../store/sectorcourses/sectorcourses.types";
import { ISectorFields } from "../../store/sectorfields/sectorfields.types"; import { ISectorFieldRecords } from "../../store/sectorfields/sectorfields.types";
import { IEpalClasses } from "../../store/epalclasses/epalclasses.types"; import { IEpalClasses } from "../../store/epalclasses/epalclasses.types";
import { STUDENT_DATA_FIELDS_INITIAL_STATE } from "../../store/studentdatafields/studentdatafields.initial-state"; import { STUDENT_DATA_FIELDS_INITIAL_STATE } from "../../store/studentdatafields/studentdatafields.initial-state";
import { REGION_SCHOOLS_INITIAL_STATE } from "../../store/regionschools/regionschools.initial-state"; import { REGION_SCHOOLS_INITIAL_STATE } from "../../store/regionschools/regionschools.initial-state";
...@@ -250,8 +250,8 @@ import { HelperDataService } from "../../services/helper-data-service"; ...@@ -250,8 +250,8 @@ import { HelperDataService } from "../../services/helper-data-service";
}); });
this.sectorFieldsSub = this._ngRedux.select("sectorFields") this.sectorFieldsSub = this._ngRedux.select("sectorFields")
.subscribe(sectorFields => { .map(sectorFields => <ISectorFieldRecords>sectorFields)
let sfds = <ISectorFields>sectorFields; .subscribe(sfds => {
console.log("SELECTOR"); console.log("SELECTOR");
sfds.reduce(({ }, sectorField) => { sfds.reduce(({ }, sectorField) => {
if (sectorField.selected === true) { if (sectorField.selected === true) {
......
...@@ -10,7 +10,7 @@ import { ISectors } from "../../store/sectorcourses/sectorcourses.types"; ...@@ -10,7 +10,7 @@ import { ISectors } from "../../store/sectorcourses/sectorcourses.types";
import { IAppState } from "../../store/store"; import { IAppState } from "../../store/store";
import { RemoveSpaces } from "../../pipes/removespaces"; import { RemoveSpaces } from "../../pipes/removespaces";
import { IEpalClasses } from "../../store/epalclasses/epalclasses.types"; import { IEpalClasses } from "../../store/epalclasses/epalclasses.types";
import { ISectorFields } from "../../store/sectorfields/sectorfields.types"; import { ISectorFieldRecords } from "../../store/sectorfields/sectorfields.types";
import { import {
...@@ -191,6 +191,7 @@ import {AppSettings} from "../../app.settings"; ...@@ -191,6 +191,7 @@ import {AppSettings} from "../../app.settings";
selectEpalClasses() { selectEpalClasses() {
this.epalclassesSub = this._ngRedux.select("epalclasses") this.epalclassesSub = this._ngRedux.select("epalclasses")
.subscribe(epalclasses => { .subscribe(epalclasses => {
console.log(epalclasses);
let ecs = <IEpalClasses>epalclasses; let ecs = <IEpalClasses>epalclasses;
if (ecs.size > 0) { if (ecs.size > 0) {
ecs.reduce(({}, epalclass, i) => { ecs.reduce(({}, epalclass, i) => {
...@@ -214,24 +215,24 @@ import {AppSettings} from "../../app.settings"; ...@@ -214,24 +215,24 @@ import {AppSettings} from "../../app.settings";
let numreg = 0; // count reduced regions in order to set activeRegion when user comes back to his choices let numreg = 0; // count reduced regions in order to set activeRegion when user comes back to his choices
console.log("selectRegionSchools"); console.log("selectRegionSchools");
this.selectionLimitOptional.next(false); this.selectionLimitOptional.next(false);
let pushControls = false;
if (rgns.size === 0) if (this.rss.length === 0)
return; pushControls = true;
rgns.reduce((prevRegion, region) => { rgns.reduce((prevRegion, region) => {
numreg++; numreg++;
region.get("epals").reduce((prevEpal, epal) => { region.get("epals").reduce((prevEpal, epal) => {
this.rss.push(new FormControl(epal.get("selected"), [])); if (pushControls)
this.rss.push(new FormControl(epal.get("selected"), []));
if (epal.get("selected") === true) { if (epal.get("selected") === true) {
numsel++; numsel++;
if (epal.get("epal_special_case") === "1") { if (epal.get("epal_special_case") === "1") {
this.selectionLimitOptional.next(true); this.selectionLimitOptional.next(true);
} }
this.regionActiveId = Number(region.region_id); this.regionActiveId = parseInt(region.region_id);
this.regionActive = numreg - 1; this.regionActive = numreg - 1;
} }
if (Number(region.region_id) === this.regionActiveId) { if (parseInt(region.region_id) === this.regionActiveId) {
if (region.get("epals").length < this.regionSizeLimit) if (region.get("epals").size < this.regionSizeLimit)
this.selectionLimitOptional.next(true); this.selectionLimitOptional.next(true);
} }
return epal; return epal;
...@@ -258,8 +259,8 @@ import {AppSettings} from "../../app.settings"; ...@@ -258,8 +259,8 @@ import {AppSettings} from "../../app.settings";
} }
else if (epalClass === "2") { else if (epalClass === "2") {
this.sectorFieldsSub = this._ngRedux.select("sectorFields") this.sectorFieldsSub = this._ngRedux.select("sectorFields")
.subscribe(sectorFields => { .map(sectorFields => <ISectorFieldRecords>sectorFields)
let sfds = <ISectorFields>sectorFields; .subscribe(sfds => {
console.log("sectorFieldsSub"); console.log("sectorFieldsSub");
sfds.reduce(({}, sectorField) => { sfds.reduce(({}, sectorField) => {
if (sectorField.selected === true) { if (sectorField.selected === true) {
...@@ -285,7 +286,7 @@ import {AppSettings} from "../../app.settings"; ...@@ -285,7 +286,7 @@ import {AppSettings} from "../../app.settings";
if (course.selected === true) { if (course.selected === true) {
this.courseActive = parseInt(course.course_id); this.courseActive = parseInt(course.course_id);
// this._rsa.getRegionSchools(3,this.courseActive, false); // this._rsa.getRegionSchools(3,this.courseActive, false);
this._rsa.getRegionSchools(Number(epalClass), this.courseActive, false); this._rsa.getRegionSchools(parseInt(epalClass), this.courseActive, false);
} }
return course; return course;
}, {}); }, {});
......
...@@ -4,7 +4,7 @@ import { BehaviorSubject, Subscription } from "rxjs/Rx"; ...@@ -4,7 +4,7 @@ import { BehaviorSubject, Subscription } from "rxjs/Rx";
import { Injectable } from "@angular/core"; import { Injectable } from "@angular/core";
import { SectorFieldsActions } from "../../actions/sectorfields.actions"; import { SectorFieldsActions } from "../../actions/sectorfields.actions";
import { NgRedux, select } from "@angular-redux/store"; import { NgRedux, select } from "@angular-redux/store";
import { ISectorFields } from "../../store/sectorfields/sectorfields.types"; import { ISectorFieldRecord, ISectorFieldRecords } from "../../store/sectorfields/sectorfields.types";
import { IAppState } from "../../store/store"; import { IAppState } from "../../store/store";
import { SECTOR_FIELDS_INITIAL_STATE } from "../../store/sectorfields/sectorfields.initial-state"; import { SECTOR_FIELDS_INITIAL_STATE } from "../../store/sectorfields/sectorfields.initial-state";
...@@ -45,19 +45,15 @@ import {AppSettings} from "../../app.settings"; ...@@ -45,19 +45,15 @@ import {AppSettings} from "../../app.settings";
<h4> Επιλογή Τομέα </h4> <h4> Επιλογή Τομέα </h4>
<div class = "loading" *ngIf="(sectorFields$ | async).size === 0"> <div class = "loading" *ngIf="(sectorFields$ | async).size === 0">
</div> </div>
<form [formGroup]="formGroup">
<p style="margin-top: 20px; line-height: 2em;"> Παρακαλώ επιλέξτε τον τομέα στον οποίο θα φοιτήσει ο μαθητής το νέο σχολικό έτος στην επαγγελματική εκπαίδευση. Έπειτα επιλέξτε <i>Συνέχεια</i>.</p> <p style="margin-top: 20px; line-height: 2em;"> Παρακαλώ επιλέξτε τον τομέα στον οποίο θα φοιτήσει ο μαθητής το νέο σχολικό έτος στην επαγγελματική εκπαίδευση. Έπειτα επιλέξτε <i>Συνέχεια</i>.</p>
<div formArrayName="formArray">
<ul class="list-group main-view"> <ul class="list-group main-view">
<div *ngFor="let sectorField$ of sectorFields$ | async; let i=index; let isOdd=odd; let isEven=even"> <div *ngFor="let sectorField$ of sectorFields$ | async; let i=index; let isOdd=odd; let isEven=even">
<li class="list-group-item isclickable" (click)="setActiveSectorAndSave(i)" [class.oddout]="isOdd" [class.evenout]="isEven" [class.selectedout]="sectorActive === i"> <li class="list-group-item isclickable" (click)="saveSelected(i)" [class.oddout]="isOdd" [class.evenout]="isEven" [class.selectedout]="sectorActive === i">
<h5>{{sectorField$.name}}</h5> <h5>{{sectorField$.name}}</h5>
</li> </li>
</div> </div>
</ul> </ul>
</div>
<div class="row" style="margin-top: 20px; margin-bottom: 20px;" *ngIf="(sectorFields$ | async).size > 0"> <div class="row" style="margin-top: 20px; margin-bottom: 20px;" *ngIf="(sectorFields$ | async).size > 0">
<div class="col-md-6"> <div class="col-md-6">
<button type="button" class="btn-primary btn-lg pull-left" (click)="router.navigate(['/epal-class-select']);" > <button type="button" class="btn-primary btn-lg pull-left" (click)="router.navigate(['/epal-class-select']);" >
...@@ -70,16 +66,13 @@ import {AppSettings} from "../../app.settings"; ...@@ -70,16 +66,13 @@ import {AppSettings} from "../../app.settings";
</button> </button>
</div> </div>
</div> </div>
`
</form>
`
}) })
@Injectable() export default class SectorFieldsSelect implements OnInit, OnDestroy { @Injectable() export default class SectorFieldsSelect implements OnInit, OnDestroy {
private sectorFields$: BehaviorSubject<ISectorFields>; private sectorFields$: BehaviorSubject<ISectorFieldRecords>;
private sectorFieldsSub: Subscription; private sectorFieldsSub: Subscription;
private formGroup: FormGroup; private formGroup: FormGroup;
private cfs = new FormArray([]);
private sectorActive = <number>-1; private sectorActive = <number>-1;
private modalTitle: BehaviorSubject<string>; private modalTitle: BehaviorSubject<string>;
private modalText: BehaviorSubject<string>; private modalText: BehaviorSubject<string>;
...@@ -93,9 +86,6 @@ import {AppSettings} from "../../app.settings"; ...@@ -93,9 +86,6 @@ import {AppSettings} from "../../app.settings";
private router: Router) { private router: Router) {
this.sectorFields$ = new BehaviorSubject(SECTOR_FIELDS_INITIAL_STATE); this.sectorFields$ = new BehaviorSubject(SECTOR_FIELDS_INITIAL_STATE);
this.formGroup = this.fb.group({
formArray: this.cfs
});
this.modalTitle = new BehaviorSubject(""); this.modalTitle = new BehaviorSubject("");
this.modalText = new BehaviorSubject(""); this.modalText = new BehaviorSubject("");
this.modalHeader = new BehaviorSubject(""); this.modalHeader = new BehaviorSubject("");
...@@ -106,14 +96,11 @@ import {AppSettings} from "../../app.settings"; ...@@ -106,14 +96,11 @@ import {AppSettings} from "../../app.settings";
(<any>$("#sectorFieldsNotice")).appendTo("body"); (<any>$("#sectorFieldsNotice")).appendTo("body");
this._cfa.getSectorFields(false); this._cfa.getSectorFields(false);
this.sectorFieldsSub = this._ngRedux.select("sectorFields") this.sectorFieldsSub = this._ngRedux.select("sectorFields")
.subscribe(sectorFields => { .map(sectorFields => <ISectorFieldRecords>sectorFields)
let sfds = <ISectorFields>sectorFields; .subscribe(sfds => {
sfds.reduce(({}, sectorField) => { sfds.reduce(({}, sectorField) => {
this.cfs.push(new FormControl(sectorField.selected, [])); if (sectorField.get("selected") === true) {
// in case we want to retrieve last check when we return to the form this.sectorActive = sectorField.get("id") - 1;
if (sectorField.selected === true) {
this.sectorActive = sectorField.id - 1;
} }
return sectorField; return sectorField;
...@@ -151,22 +138,14 @@ import {AppSettings} from "../../app.settings"; ...@@ -151,22 +138,14 @@ import {AppSettings} from "../../app.settings";
} }
} }
saveSelected() { private saveSelected(ind: number): void {
for (let i = 0; i < this.formGroup.value.formArray.length; i++) if (ind === this.sectorActive)
this.formGroup.value.formArray[i] = false; return;
if (this.sectorActive !== -1)
this.formGroup.value.formArray[this.sectorActive] = true;
this._cfa.saveSectorFieldsSelected(this.formGroup.value.formArray); this._cfa.saveSectorFieldsSelected(this.sectorActive, ind);
this.sectorActive = ind;
this._rsa.initRegionSchools(); this._rsa.initRegionSchools();
} }
setActiveSectorAndSave(ind) {
if (ind === this.sectorActive)
ind = -1;
this.sectorActive = ind;
this.saveSelected();
}
} }
...@@ -20,6 +20,7 @@ export class AuthService { ...@@ -20,6 +20,7 @@ export class AuthService {
return new Promise<boolean>((resolve, reject) => { return new Promise<boolean>((resolve, reject) => {
this._ngRedux.select("loginInfo").subscribe(loginInfo => { this._ngRedux.select("loginInfo").subscribe(loginInfo => {
let linfo = <ILoginInfo>loginInfo; let linfo = <ILoginInfo>loginInfo;
if (linfo.size > 0) { if (linfo.size > 0) {
linfo.reduce(({}, loginInfoToken) => { linfo.reduce(({}, loginInfoToken) => {
if ((loginInfoToken.auth_token && loginInfoToken.auth_token.length > 0 && loginInfoToken.auth_role === role) || if ((loginInfoToken.auth_token && loginInfoToken.auth_token.length > 0 && loginInfoToken.auth_role === role) ||
......
import {createLogger} from "redux-logger"; import {createLogger} from "redux-logger";
import { IAppState, rootReducer, deimmutify } from "./store"; import { IAppState, rootReducer, deimmutify } from "./store";
import { ISectorField, ISectorFields } from "./sectorfields/sectorfields.types"; import { ISectorFieldRecord, ISectorFieldRecords } from "./sectorfields/sectorfields.types";
import { IRRegion, IRRegionSchool, IRegionRecord, IRegionRecords, IRegionSchoolRecord, IRegionSchoolRecords } from "./regionschools/regionschools.types"; import { IRRegion, IRRegionSchool, IRegionRecord, IRegionRecords, IRegionSchoolRecord, IRegionSchoolRecords } from "./regionschools/regionschools.types";
import { ISectors, ISector, ISectorCourse } from "./sectorcourses/sectorcourses.types"; import { ISectors, ISector, ISectorCourse } from "./sectorcourses/sectorcourses.types";
import { IStudentDataField, IStudentDataFields } from "./studentdatafields/studentdatafields.types"; import { IStudentDataField, IStudentDataFields } from "./studentdatafields/studentdatafields.types";
...@@ -11,8 +11,8 @@ import { ILoginInfoToken, ILoginInfo } from "./logininfo/logininfo.types"; ...@@ -11,8 +11,8 @@ import { ILoginInfoToken, ILoginInfo } from "./logininfo/logininfo.types";
export { export {
IAppState, IAppState,
rootReducer, rootReducer,
ISectorField, ISectorFieldRecord,
ISectorFields, ISectorFieldRecords,
IRRegion, IRRegion,
IRegionRecord, IRegionRecord,
IRegionRecords, IRegionRecords,
......
import { IRegionRecord, IRegionRecords } from "./regionschools.types"; import { IRegionRecords } from "./regionschools.types";
export function deimmutifyRegionSchools(state: IRegionRecords): IRegionRecords { export function deimmutifyRegionSchools(state: IRegionRecords): IRegionRecords {
return state; return state;
......
import { List, Map } from "immutable"; import { List } from "immutable";
import {TypedRecord} from "typed-immutable-record"; import {TypedRecord} from "typed-immutable-record";
export interface IRRegion { export interface IRRegion {
......
import { ISectorField, ISectorFields } from "./sectorfields.types"; import { ISectorFieldRecord, ISectorFieldRecords } from "./sectorfields.types";
import { sectorFieldsReducer } from "./sectorfields.reducer"; import { sectorFieldsReducer } from "./sectorfields.reducer";
import { deimmutifySectorFields } from "./sectorfields.transformers"; import { deimmutifySectorFields } from "./sectorfields.transformers";
export { export {
ISectorField, ISectorFieldRecord,
ISectorFields, ISectorFieldRecords,
sectorFieldsReducer, sectorFieldsReducer,
deimmutifySectorFields, deimmutifySectorFields,
}; };
import { List } from "immutable"; /* import { List } from "immutable";
import { ISectorField } from "./sectorfields.types"; import { ISectorField } from "./sectorfields.types";
export const SECTOR_FIELDS_INITIAL_STATE = List<ISectorField>(); export const SECTOR_FIELDS_INITIAL_STATE = List<ISectorField>(); */
import { List } from "immutable";
import { ISectorFieldRecord, ISectorField } from "./sectorfields.types";
import {recordify} from "typed-immutable-record";
export const SECTOR_FIELDS_INITIAL_STATE = List<ISectorFieldRecord>();
import { ISectorFields, ISectorField } from "./sectorfields.types"; import { ISectorFieldRecords, ISectorFieldRecord, ISectorField } from "./sectorfields.types";
import { SECTOR_FIELDS_INITIAL_STATE } from "./sectorfields.initial-state"; import { SECTOR_FIELDS_INITIAL_STATE } from "./sectorfields.initial-state";
import { Seq } from "immutable"; import { Seq, List } from "immutable";
import {recordify} from "typed-immutable-record";
import { import {
SECTORFIELDS_RECEIVED, SECTORFIELDS_RECEIVED,
...@@ -8,24 +9,24 @@ import { ...@@ -8,24 +9,24 @@ import {
SECTORFIELDS_INIT SECTORFIELDS_INIT
} from "../../constants"; } from "../../constants";
export function sectorFieldsReducer(state: ISectorFields = SECTOR_FIELDS_INITIAL_STATE, action): ISectorFields { export function sectorFieldsReducer(state: ISectorFieldRecords = SECTOR_FIELDS_INITIAL_STATE, action): ISectorFieldRecords {
switch (action.type) { switch (action.type) {
case SECTORFIELDS_RECEIVED: case SECTORFIELDS_RECEIVED:
let newSectorFields = Array<ISectorField>(); let newSectorFields = Array<ISectorFieldRecord>();
let i = 0; let i = 0;
action.payload.sectorFields.forEach(sectorField => { action.payload.sectorFields.forEach(sectorField => {
newSectorFields.push(<ISectorField>{ id: sectorField.id, name: sectorField.name, selected: false }); newSectorFields.push(recordify<ISectorField, ISectorFieldRecord>({ id: sectorField.id, name: sectorField.name, selected: false }));
i++; i++;
}); });
return Seq(newSectorFields).map(n => n).toList(); return List(newSectorFields);
case SECTORFIELDS_SELECTED_SAVE: case SECTORFIELDS_SELECTED_SAVE:
let selectedSectorFields = Array<ISectorField>(); return state.withMutations(function(list) {
let ind = 0; if (action.payload.prevChoice >= 0)
state.forEach(sectorField => { list.setIn([action.payload.prevChoice, "selected"], false);
selectedSectorFields.push(<ISectorField>{ id: sectorField.id, name: sectorField.name, selected: action.payload.sectorFieldsSelected[ind] }); if (action.payload.newChoice >= 0)
ind++; list.setIn([action.payload.newChoice, "selected"], true);
}); });
return Seq(selectedSectorFields).map(n => n).toList();
case SECTORFIELDS_INIT: case SECTORFIELDS_INIT:
return SECTOR_FIELDS_INITIAL_STATE; return SECTOR_FIELDS_INITIAL_STATE;
default: return state; default: return state;
......
import { ISectorFields, ISectorField } from "./sectorfields.types"; import { ISectorFieldRecords } from "./sectorfields.types";
export function deimmutifySectorFields(state: ISectorFields): ISectorField[] { export function deimmutifySectorFields(state: ISectorFieldRecords): ISectorFieldRecords {
let fetchedSectorFields = new Array(); return state;
state.forEach(sectorField => {
fetchedSectorFields.push(<ISectorField>{ id: sectorField.id, name: sectorField.name, selected: sectorField.selected });
});
return fetchedSectorFields;
}; };
import { List } from "immutable"; import { List } from "immutable";
import {TypedRecord} from "typed-immutable-record";
export interface ISectorField { export interface ISectorField {
id: number; id: number;
...@@ -6,4 +7,6 @@ export interface ISectorField { ...@@ -6,4 +7,6 @@ export interface ISectorField {
selected: boolean; selected: boolean;
} }
export type ISectorFields = List<ISectorField>; export interface ISectorFieldRecord extends TypedRecord<ISectorFieldRecord>, ISectorField { };
export type ISectorFieldRecords = List<ISectorFieldRecord>;
// export type ISectorFields = List<ISectorField>;
...@@ -7,7 +7,7 @@ import * as epalclasses from "./epalclasses"; ...@@ -7,7 +7,7 @@ import * as epalclasses from "./epalclasses";
import * as loginInfo from "./logininfo"; import * as loginInfo from "./logininfo";
export interface IAppState { export interface IAppState {
sectorFields?: sectorFields.ISectorFields; sectorFields?: sectorFields.ISectorFieldRecords;
regions?: regions.IRegionRecords; regions?: regions.IRegionRecords;
sectors?: sectors.ISectors; sectors?: sectors.ISectors;
studentDataFields?: studentDataFields.IStudentDataFields; studentDataFields?: studentDataFields.IStudentDataFields;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment