implemented a new structure for regions and schools using TypedRecord

parent f3f705c5
...@@ -12,7 +12,7 @@ export class RegionSchoolsActions { ...@@ -12,7 +12,7 @@ export class RegionSchoolsActions {
getRegionSchools = (classActive,courseActive, reload) => { getRegionSchools = (classActive,courseActive, reload) => {
const { regions } = this._ngRedux.getState(); const { regions } = this._ngRedux.getState();
if (reload === true || (reload === false && regions.size === 0)) { if (reload === true || (reload === false && (regions.length === 0 || regions[0].get("region_id") === null))) {
return this._hds.getRegionsWithSchools(classActive,courseActive).then(regions => { return this._hds.getRegionsWithSchools(classActive,courseActive).then(regions => {
return this._ngRedux.dispatch({ return this._ngRedux.dispatch({
type: REGIONSCHOOLS_RECEIVED, type: REGIONSCHOOLS_RECEIVED,
......
...@@ -10,7 +10,7 @@ import { RegionSchoolsActions } from '../../actions/regionschools.actions'; ...@@ -10,7 +10,7 @@ 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 { ISectorFields } from '../../store/sectorfields/sectorfields.types';
import { ISectors } from '../../store/sectorcourses/sectorcourses.types'; import { ISectors } from '../../store/sectorcourses/sectorcourses.types';
import { IRegions, IRegionSchool } from '../../store/regionschools/regionschools.types'; import { IRegionRecord, IRegionSchoolRecord } from '../../store/regionschools/regionschools.types';
import { IEpalClasses } from '../../store/epalclasses/epalclasses.types'; import { IEpalClasses } from '../../store/epalclasses/epalclasses.types';
import {AppSettings} from '../../app.settings'; import {AppSettings} from '../../app.settings';
import { REGION_SCHOOLS_INITIAL_STATE } from '../../store/regionschools/regionschools.initial-state'; import { REGION_SCHOOLS_INITIAL_STATE } from '../../store/regionschools/regionschools.initial-state';
...@@ -80,8 +80,8 @@ import { SECTOR_FIELDS_INITIAL_STATE } from '../../store/sectorfields/sectorfiel ...@@ -80,8 +80,8 @@ import { SECTOR_FIELDS_INITIAL_STATE } from '../../store/sectorfields/sectorfiel
@Injectable() export default class ApplicationPreview implements OnInit { @Injectable() export default class ApplicationPreview implements OnInit {
private sectors$: BehaviorSubject<ISectors>; private sectors$: BehaviorSubject<ISectors>;
private regions$: BehaviorSubject<IRegions>; private regions$: BehaviorSubject<Array<IRegionRecord>>;
private selectedSchools$: BehaviorSubject<Array<IRegionSchool>> = new BehaviorSubject(Array()); private selectedSchools$: BehaviorSubject<Array<IRegionSchoolRecord>> = new BehaviorSubject(Array());
private sectorFields$: BehaviorSubject<ISectorFields>; private sectorFields$: BehaviorSubject<ISectorFields>;
private epalclasses$: BehaviorSubject<IEpalClasses>; private epalclasses$: BehaviorSubject<IEpalClasses>;
private sectorsSub: Subscription; private sectorsSub: Subscription;
...@@ -123,12 +123,10 @@ import { SECTOR_FIELDS_INITIAL_STATE } from '../../store/sectorfields/sectorfiel ...@@ -123,12 +123,10 @@ import { SECTOR_FIELDS_INITIAL_STATE } from '../../store/sectorfields/sectorfiel
this.regionsSub = this._ngRedux.select(state => { this.regionsSub = this._ngRedux.select(state => {
let numsel = 0, numsel2 = 0; let numsel = 0, numsel2 = 0;
let selectedSchools = Array<IRegionSchool>(); let selectedSchools = Array<IRegionSchoolRecord>();
if (state.regions.size === 0) if (state.regions.length === 0 || state.regions[0].get("region_id") === null)
return; return;
console.log(state.regions);
state.regions.reduce((prevRegion, region) => { state.regions.reduce((prevRegion, region) => {
console.log(region);
region.get("epals").reduce((prevEpal, epal) => { region.get("epals").reduce((prevEpal, epal) => {
if (epal.get("selected") === true) { if (epal.get("selected") === true) {
numsel++; numsel++;
...@@ -172,7 +170,7 @@ import { SECTOR_FIELDS_INITIAL_STATE } from '../../store/sectorfields/sectorfiel ...@@ -172,7 +170,7 @@ import { SECTOR_FIELDS_INITIAL_STATE } from '../../store/sectorfields/sectorfiel
} }
compareSchools(a: IRegionSchool,b: IRegionSchool) { compareSchools(a: IRegionSchoolRecord,b: IRegionSchoolRecord) {
if (a.order_id < b.order_id) if (a.order_id < b.order_id)
return -1; return -1;
if (a.order_id > b.order_id) if (a.order_id > b.order_id)
......
...@@ -6,7 +6,7 @@ import { Injectable } from "@angular/core"; ...@@ -6,7 +6,7 @@ import { Injectable } from "@angular/core";
import { NgRedux, select } from "ng2-redux"; import { NgRedux, select } from "ng2-redux";
import { IAppState } from "../../store/store"; import { IAppState } from "../../store/store";
import { IStudentDataFields } from "../../store/studentdatafields/studentdatafields.types"; import { IStudentDataFields } from "../../store/studentdatafields/studentdatafields.types";
import { IRegions } from "../../store/regionschools/regionschools.types"; import { IRegionRecord, 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 { ISectorFields } from "../../store/sectorfields/sectorfields.types";
import { IEpalClasses } from "../../store/epalclasses/epalclasses.types"; import { IEpalClasses } from "../../store/epalclasses/epalclasses.types";
...@@ -106,7 +106,7 @@ import { HelperDataService } from "../../services/helper-data-service"; ...@@ -106,7 +106,7 @@ import { HelperDataService } from "../../services/helper-data-service";
</button> </button>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<button type="button" *ngIf="(studentDataFields$ | async).size > 0 && (regions$ | async).size > 0 && (epalclasses$ | async).size > 0 && (loginInfo$ | async).size > 0" class="btn-primary btn-lg pull-right isclickable" style="width: 9em;" (click)="submitNow()"> <button type="button" *ngIf="(studentDataFields$ | async).size > 0 && (regions$ | async) && (regions$ | async).length > 0 && (regions$ | async)[0].region_id !== null && (epalclasses$ | async).size > 0 && (loginInfo$ | async).size > 0" class="btn-primary btn-lg pull-right isclickable" style="width: 9em;" (click)="submitNow()">
<span style="font-size: 0.9em; font-weight: bold;">Υποβολή&nbsp;&nbsp;&nbsp;</span><i class="fa fa-forward"></i> <span style="font-size: 0.9em; font-weight: bold;">Υποβολή&nbsp;&nbsp;&nbsp;</span><i class="fa fa-forward"></i>
</button> </button>
</div> </div>
...@@ -124,7 +124,7 @@ import { HelperDataService } from "../../services/helper-data-service"; ...@@ -124,7 +124,7 @@ import { HelperDataService } from "../../services/helper-data-service";
private classSelected; private classSelected;
private totalPoints = <number>0; private totalPoints = <number>0;
private studentDataFields$: BehaviorSubject<IStudentDataFields>; private studentDataFields$: BehaviorSubject<IStudentDataFields>;
private regions$: BehaviorSubject<IRegions>; private regions$: BehaviorSubject<Array<IRegionRecord>>;
private sectors$: BehaviorSubject<ISectors>; private sectors$: BehaviorSubject<ISectors>;
private sectorFields$: BehaviorSubject<ISectorFields>; private sectorFields$: BehaviorSubject<ISectorFields>;
private epalclasses$: BehaviorSubject<IEpalClasses>; private epalclasses$: BehaviorSubject<IEpalClasses>;
......
...@@ -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 { RegionSchoolsActions } from '../../actions/regionschools.actions'; import { RegionSchoolsActions } from '../../actions/regionschools.actions';
import { NgRedux, select } from 'ng2-redux'; import { NgRedux, select } from 'ng2-redux';
import { IRegions } from '../../store/regionschools/regionschools.types'; import { IRegionRecord } from '../../store/regionschools/regionschools.types';
import { REGION_SCHOOLS_INITIAL_STATE } from '../../store/regionschools/regionschools.initial-state'; import { REGION_SCHOOLS_INITIAL_STATE } from '../../store/regionschools/regionschools.initial-state';
import { EPALCLASSES_INITIAL_STATE } from '../../store/epalclasses/epalclasses.initial-state'; import { EPALCLASSES_INITIAL_STATE } from '../../store/epalclasses/epalclasses.initial-state';
import { SECTOR_COURSES_INITIAL_STATE } from '../../store/sectorcourses/sectorcourses.initial-state'; import { SECTOR_COURSES_INITIAL_STATE } from '../../store/sectorcourses/sectorcourses.initial-state';
...@@ -32,7 +32,7 @@ import {AppSettings} from '../../app.settings'; ...@@ -32,7 +32,7 @@ import {AppSettings} from '../../app.settings';
<breadcrumbs></breadcrumbs> <breadcrumbs></breadcrumbs>
</div> </div>
<div class = "loading" *ngIf="!(regions$ | async)"> <div class = "loading" *ngIf="!(regions$ | async) || (regions$ | async)[0].region_id===null">
</div> </div>
<!-- <div class="row equal"> <!-- <div class="row equal">
<div class="col-md-12"> --> <div class="col-md-12"> -->
...@@ -115,7 +115,7 @@ import {AppSettings} from '../../app.settings'; ...@@ -115,7 +115,7 @@ import {AppSettings} from '../../app.settings';
}) })
@Injectable() export default class RegionSchoolsSelect implements OnInit, OnDestroy { @Injectable() export default class RegionSchoolsSelect implements OnInit, OnDestroy {
private epalclasses$: BehaviorSubject<IEpalClasses>; private epalclasses$: BehaviorSubject<IEpalClasses>;
private regions$: BehaviorSubject<IRegions>; private regions$: BehaviorSubject<IRegionRecord[]>;
private sectors$: BehaviorSubject<ISectors>; private sectors$: BehaviorSubject<ISectors>;
private sectorFields$: BehaviorSubject<ISectorFields>; private sectorFields$: BehaviorSubject<ISectorFields>;
private epalclassesSub: Subscription; private epalclassesSub: Subscription;
...@@ -234,11 +234,7 @@ import {AppSettings} from '../../app.settings'; ...@@ -234,11 +234,7 @@ 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
this.selectionLimitOptional.next(false); this.selectionLimitOptional.next(false);
console.log("numsel="+numsel); if (state.regions.length === 0 || state.regions[0].get("region_id") === null)
console.log(state.regions);
console.log(state.regions.size);
console.log(this.regions$.getValue());
if (state.regions.size === 0)
return; return;
state.regions.reduce((prevRegion, region) =>{ state.regions.reduce((prevRegion, region) =>{
...@@ -247,7 +243,6 @@ import {AppSettings} from '../../app.settings'; ...@@ -247,7 +243,6 @@ import {AppSettings} from '../../app.settings';
this.rss.push( new FormControl(epal.get("selected"), [])); this.rss.push( new FormControl(epal.get("selected"), []));
if (epal.get("selected") === true) { if (epal.get("selected") === true) {
numsel++; numsel++;
console.log("numsel2="+numsel);
if ( epal.get("epal_special_case") === "1") { if ( epal.get("epal_special_case") === "1") {
this.selectionLimitOptional.next(true); this.selectionLimitOptional.next(true);
} }
...@@ -264,7 +259,6 @@ import {AppSettings} from '../../app.settings'; ...@@ -264,7 +259,6 @@ import {AppSettings} from '../../app.settings';
return region; return region;
}, {}); }, {});
console.log("numsel3="+numsel);
this.numSelected.next(numsel); this.numSelected.next(numsel);
return state.regions; return state.regions;
}).subscribe(this.regions$); }).subscribe(this.regions$);
......
...@@ -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 { NgRedux, select } from 'ng2-redux'; import { NgRedux, select } from 'ng2-redux';
import { RegionSchoolsActions } from '../../actions/regionschools.actions'; import { RegionSchoolsActions } from '../../actions/regionschools.actions';
import { IRegions, IRegionSchool } from '../../store/regionschools/regionschools.types'; import { IRegionRecord, IRegionSchoolRecord } from '../../store/regionschools/regionschools.types';
import { REGION_SCHOOLS_INITIAL_STATE } from '../../store/regionschools/regionschools.initial-state'; import { REGION_SCHOOLS_INITIAL_STATE } from '../../store/regionschools/regionschools.initial-state';
import { IAppState } from '../../store/store'; import { IAppState } from '../../store/store';
import {AppSettings} from '../../app.settings'; import {AppSettings} from '../../app.settings';
...@@ -15,8 +15,9 @@ import {AppSettings} from '../../app.settings'; ...@@ -15,8 +15,9 @@ import {AppSettings} from '../../app.settings';
<div class="row"> <div class="row">
<breadcrumbs></breadcrumbs> <breadcrumbs></breadcrumbs>
</div> </div>
<div class = "loading" *ngIf="(selectedSchools$ | async).length === 0 || (regions$ | async).size === 0"> <div class = "loading" *ngIf="(selectedSchools$ | async).length === 0 || !(regions$ | async) || ((regions$ | async).length === 1 && (regions$ | async)[0].region_id === null)">
</div> </div>
<h4> Σειρά προτίμησης</h4> <h4> Σειρά προτίμησης</h4>
<p style="margin-top: 20px; line-height: 2em;" *ngIf = "(selectedSchools$ | async).length === 1" >Έχετε επιλέξει το παρακάτω σχολείο. Εάν συμφωνείτε με την επιλογή σας <p style="margin-top: 20px; line-height: 2em;" *ngIf = "(selectedSchools$ | async).length === 1" >Έχετε επιλέξει το παρακάτω σχολείο. Εάν συμφωνείτε με την επιλογή σας
πατήστε Συνέχεια, διαφορετικά μπορείτε να τροποποιήστε τις επιλογές σας επιστρέφοντας στην προηγούμενη οθόνη από το αριστερό βέλος κάτω αριστερά.</p> πατήστε Συνέχεια, διαφορετικά μπορείτε να τροποποιήστε τις επιλογές σας επιστρέφοντας στην προηγούμενη οθόνη από το αριστερό βέλος κάτω αριστερά.</p>
...@@ -50,9 +51,9 @@ import {AppSettings} from '../../app.settings'; ...@@ -50,9 +51,9 @@ import {AppSettings} from '../../app.settings';
}) })
@Injectable() export default class SchoolsOrderSelect implements OnInit, OnDestroy { @Injectable() export default class SchoolsOrderSelect implements OnInit, OnDestroy {
// public formGroup: FormGroup; // public formGroup: FormGroup;
private regions$: BehaviorSubject<IRegions>; private regions$: BehaviorSubject<Array<IRegionRecord>>;
private regionsSub: Subscription; private regionsSub: Subscription;
private selectedSchools$: BehaviorSubject<Array<IRegionSchool>> = new BehaviorSubject(Array()); private selectedSchools$: BehaviorSubject<Array<IRegionSchoolRecord>> = new BehaviorSubject(Array());
constructor(private _cfa: RegionSchoolsActions, constructor(private _cfa: RegionSchoolsActions,
private _ngRedux: NgRedux<IAppState>, private _ngRedux: NgRedux<IAppState>,
...@@ -62,12 +63,12 @@ import {AppSettings} from '../../app.settings'; ...@@ -62,12 +63,12 @@ import {AppSettings} from '../../app.settings';
ngOnInit() { ngOnInit() {
this.regionsSub = this._ngRedux.select(state => { this.regionsSub = this._ngRedux.select(state => {
let selectedSchools = Array<IRegionSchool>(); let selectedSchools = Array<IRegionSchoolRecord>();
state.regions.reduce((prevRegion, region) => { state.regions.reduce((prevRegion, region) => {
region.epals.reduce((prevEpal, epal) => { region.get("epals").reduce((prevEpal, epal) => {
if (epal.selected === true) { if (epal.get("selected") === true) {
selectedSchools.push(epal); selectedSchools.push(epal.toJS());
} }
return epal; return epal;
...@@ -97,7 +98,7 @@ import {AppSettings} from '../../app.settings'; ...@@ -97,7 +98,7 @@ import {AppSettings} from '../../app.settings';
if (this.regions$) this.regions$.unsubscribe(); if (this.regions$) this.regions$.unsubscribe();
} }
compareSchools(a: IRegionSchool, b: IRegionSchool) { compareSchools(a: IRegionSchoolRecord, b: IRegionSchoolRecord) {
if (a.order_id < b.order_id) if (a.order_id < b.order_id)
return -1; return -1;
if (a.order_id > b.order_id) if (a.order_id > b.order_id)
...@@ -106,7 +107,7 @@ import {AppSettings} from '../../app.settings'; ...@@ -106,7 +107,7 @@ import {AppSettings} from '../../app.settings';
} }
changeOrder(i) { changeOrder(i) {
let selectedSchools = Array<IRegionSchool>(); let selectedSchools = Array<IRegionSchoolRecord>();
selectedSchools = this.selectedSchools$.getValue(); selectedSchools = this.selectedSchools$.getValue();
if (i === 1) { if (i === 1) {
......
...@@ -4,7 +4,7 @@ import { BehaviorSubject } from "rxjs/Rx"; ...@@ -4,7 +4,7 @@ import { BehaviorSubject } from "rxjs/Rx";
import "rxjs/add/operator/map"; import "rxjs/add/operator/map";
import { ICourseField } from "../store/coursefields/coursefields.types"; import { ICourseField } from "../store/coursefields/coursefields.types";
import { ISectorField } from "../store/sectorfields/sectorfields.types"; import { ISectorField } from "../store/sectorfields/sectorfields.types";
import { IRegion, IRegions, IRegionSchool } from "../store/regionschools/regionschools.types"; import { IRegionRecord, IRegionSchoolRecord, IRRegion, IRRegionSchool } from "../store/regionschools/regionschools.types";
import { ISector, ISectors, ISectorCourse } from "../store/sectorcourses/sectorcourses.types"; import { ISector, ISectors, ISectorCourse } from "../store/sectorcourses/sectorcourses.types";
import { AppSettings } from "../app.settings"; import { AppSettings } from "../app.settings";
import { NgRedux, select } from "ng2-redux"; import { NgRedux, select } from "ng2-redux";
...@@ -278,7 +278,7 @@ export class HelperDataService implements OnInit, OnDestroy { ...@@ -278,7 +278,7 @@ export class HelperDataService implements OnInit, OnDestroy {
}; };
transformRegionSchoolsSchema(regionSchools: any) { transformRegionSchoolsSchema(regionSchools: any) {
let rsa = Array<IRegion>(); let rsa = Array<IRRegion>();
let trackRegionId: string; let trackRegionId: string;
let trackIndex: number; let trackIndex: number;
...@@ -289,10 +289,10 @@ export class HelperDataService implements OnInit, OnDestroy { ...@@ -289,10 +289,10 @@ export class HelperDataService implements OnInit, OnDestroy {
regionSchools.forEach(regionSchool => { regionSchools.forEach(regionSchool => {
if (trackRegionId !== regionSchool.region_id) { if (trackRegionId !== regionSchool.region_id) {
trackIndex++; trackIndex++;
rsa.push(<IRegion>{ "region_id": regionSchool.region_id, "region_name": regionSchool.region_name, "epals": Array<IRegionSchool>() }); rsa.push(<IRRegion>{ "region_id": regionSchool.region_id, "region_name": regionSchool.region_name, "epals": Array<IRRegionSchool>() });
trackRegionId = regionSchool.region_id; trackRegionId = regionSchool.region_id;
} }
rsa[trackIndex].epals.push(<IRegionSchool>{ "epal_id": regionSchool.epal_id, "epal_name": regionSchool.epal_name, "epal_special_case": regionSchool.epal_special_case, "globalIndex": j, "selected": false, "order_id": 0 }); rsa[trackIndex].epals.push(<IRRegionSchool>{ "epal_id": regionSchool.epal_id, "epal_name": regionSchool.epal_name, "epal_special_case": regionSchool.epal_special_case, "globalIndex": j, "selected": false, "order_id": 0 });
j++; j++;
}); });
return rsa; return rsa;
...@@ -1057,5 +1057,3 @@ deleteApplicationforDirector(appId) { ...@@ -1057,5 +1057,3 @@ deleteApplicationforDirector(appId) {
} }
...@@ -3,7 +3,7 @@ import * as createLogger from 'redux-logger'; ...@@ -3,7 +3,7 @@ import * as createLogger from 'redux-logger';
import { IAppState, rootReducer, deimmutify } from './store'; import { IAppState, rootReducer, deimmutify } from './store';
import { ICourseField, ICourseFields } from './coursefields/coursefields.types'; import { ICourseField, ICourseFields } from './coursefields/coursefields.types';
import { ISectorField, ISectorFields } from './sectorfields/sectorfields.types'; import { ISectorField, ISectorFields } from './sectorfields/sectorfields.types';
import { IRegions, IRegion, RegionSchool } from './regionschools/regionschools.types'; import { IRRegion, IRRegionSchool, IRegionRecord, IRegionSchoolRecord } 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';
import { IEpalClass, IEpalClasses } from './epalclasses/epalclasses.types'; import { IEpalClass, IEpalClasses } from './epalclasses/epalclasses.types';
...@@ -17,9 +17,10 @@ export { ...@@ -17,9 +17,10 @@ export {
ICourseFields, ICourseFields,
ISectorField, ISectorField,
ISectorFields, ISectorFields,
IRegions, IRRegion,
IRegion, IRegionRecord,
RegionSchool, IRegionSchoolRecord,
IRRegionSchool,
ISectors, ISectors,
ISector, ISector,
ISectorCourse, ISectorCourse,
......
import { IRegions, IRegion, IRegionM, RegionSchool } from './regionschools.types'; import { IRegionRecord, IRRegion, IRRegionSchool, IRegionSchoolRecord } from './regionschools.types';
import { regionSchoolsReducer } from './regionschools.reducer'; import { regionSchoolsReducer } from './regionschools.reducer';
import { deimmutifyRegionSchools } from './regionschools.transformers'; import { deimmutifyRegionSchools } from './regionschools.transformers';
export { export {
IRegion, IRRegion,
IRegionM, IRegionRecord,
IRegions, IRegionSchoolRecord,
RegionSchool, IRRegionSchool,
regionSchoolsReducer, regionSchoolsReducer,
deimmutifyRegionSchools, deimmutifyRegionSchools,
}; };
import { List } from 'immutable'; import { List } from 'immutable';
import { IRegion, IRegionM } from './regionschools.types'; import { IRegion, IRegionM, IRegionRecord, IRRegion, IRRegionSchool, IRegionSchoolRecord } from './regionschools.types';
import {recordify} from 'typed-immutable-record';
// export const INITIAL_STATE = List<ICourseField>([new CourseFieldRecord({})]); // export const INITIAL_STATE = List<ICourseField>([new CourseFieldRecord({})]);
export const REGION_SCHOOLS_INITIAL_STATE = List<IRegionM>(); // export const REGION_SCHOOLS_INITIAL_STATE = List<IRegionM>();
export const REGION_SCHOOLS_INITIAL_STATE = new Array(recordify<IRRegion, IRegionRecord>({region_id: null, region_name: null, epals: new Array(recordify<IRRegionSchool, IRegionSchoolRecord>({epal_id: null, epal_name: null, epal_special_case: null, globalIndex: -1, selected: false, order_id: -1 })) }));
import { IRegions, Region, IRegion, IRegionM, RegionSchool, IRegionSchools } from './regionschools.types'; import { IRegions, Region, IRegion, IRRegion, IRegionM, RegionSchool, IRRegionSchool, IRegionSchools, IRegionSchoolRecord, IRegionSchoolRecords, IRegionRecord } from './regionschools.types';
import { REGION_SCHOOLS_INITIAL_STATE } from './regionschools.initial-state'; import { REGION_SCHOOLS_INITIAL_STATE } from './regionschools.initial-state';
import { Seq, Map, fromJS } from 'immutable'; import { Seq, Map, fromJS } from 'immutable';
import {recordify} from 'typed-immutable-record';
import { import {
REGIONSCHOOLS_RECEIVED, REGIONSCHOOLS_RECEIVED,
...@@ -9,33 +10,58 @@ import { ...@@ -9,33 +10,58 @@ import {
REGIONSCHOOLS_INIT REGIONSCHOOLS_INIT
} from '../../constants'; } from '../../constants';
export function regionSchoolsReducer(state: IRegions = REGION_SCHOOLS_INITIAL_STATE, action): IRegions { export function regionSchoolsReducer(state: IRegionRecord[] = REGION_SCHOOLS_INITIAL_STATE, action): IRegionRecord[] {
switch (action.type) { switch (action.type) {
case REGIONSCHOOLS_RECEIVED: case REGIONSCHOOLS_RECEIVED:
let newRegions = Array<Region>(); let newRegions = Array<IRegionRecord>();
let i=0; let i=0, j=0;
let ii=0;
action.payload.regions.forEach(region => { action.payload.regions.forEach(region => {
newRegions.push(<any>{region_id: region.region_id, region_name: region.region_name, epals: <any>[] });
region.epals.forEach(epal => { region.epals.forEach(epal => {
newRegions[i].epals.push(<any>{epal_id: epal.epal_id, epal_name: epal.epal_name, epal_special_case: epal.epal_special_case, globalIndex: epal.globalIndex, selected: epal.selected, order_id: epal.order_id }); if (j !== i || (i === 0 && ii===0)) {
newRegions.push(recordify<IRRegion, IRegionRecord>({region_id: region.region_id, region_name: region.region_name, epals: new Array(recordify<IRRegionSchool, IRegionSchoolRecord>({epal_id: epal.epal_id, epal_name: epal.epal_name, epal_special_case: epal.epal_special_case, globalIndex: epal.globalIndex, selected: epal.selected, order_id: epal.order_id })) }));
j = i;
} else
newRegions[i].epals.push(recordify<IRRegionSchool, IRegionSchoolRecord>({epal_id: epal.epal_id, epal_name: epal.epal_name, epal_special_case: epal.epal_special_case, globalIndex: epal.globalIndex, selected: epal.selected, order_id: epal.order_id }));
ii++;
}) })
i++; i++;
}); });
return fromJS(newRegions); return newRegions;
case REGIONSCHOOLS_SELECTED_SAVE: case REGIONSCHOOLS_SELECTED_SAVE:
// let ind=0; // let ind=0;
let region: IRegionM; let region: IRegionRecord;
let epals: IRegionSchools;
region = state.get(action.payload.rIndex); region = state[action.payload.rIndex];
console.log(region); let newState = Array<IRegionRecord>();
i=0, j=0;
ii=0;
state.forEach(region => {
let epals: IRegionSchoolRecords;
epals = region.get("epals");
ii=0;
epals.forEach(epal => {
if (j !== i || (i === 0 && ii===0)) {
if (i===action.payload.rIndex && ii===action.payload.sIndex)
newState.push(recordify<IRRegion, IRegionRecord>({region_id: region.region_id, region_name: region.region_name, epals: new Array(recordify<IRRegionSchool, IRegionSchoolRecord>({epal_id: epal.epal_id, epal_name: epal.epal_name, epal_special_case: epal.epal_special_case, globalIndex: epal.globalIndex, selected: action.payload.checked, order_id: epal.order_id })) }));
else
newState.push(recordify<IRRegion, IRegionRecord>({region_id: region.region_id, region_name: region.region_name, epals: new Array(recordify<IRRegionSchool, IRegionSchoolRecord>({epal_id: epal.epal_id, epal_name: epal.epal_name, epal_special_case: epal.epal_special_case, globalIndex: epal.globalIndex, selected: epal.selected, order_id: epal.order_id })) }));
j = i;
} else {
if (i===action.payload.rIndex && ii===action.payload.sIndex)
newState[i].epals.push(recordify<IRRegionSchool, IRegionSchoolRecord>({epal_id: epal.epal_id, epal_name: epal.epal_name, epal_special_case: epal.epal_special_case, globalIndex: epal.globalIndex, selected: action.payload.checked, order_id: epal.order_id }));
else
newState[i].epals.push(recordify<IRRegionSchool, IRegionSchoolRecord>({epal_id: epal.epal_id, epal_name: epal.epal_name, epal_special_case: epal.epal_special_case, globalIndex: epal.globalIndex, selected: epal.selected, order_id: epal.order_id }));
}
ii++;
})
i++;
})
epals = region.get("epals").epals; return newState;
let epal = epals.get(action.payload.sIndex);
epal.set("selected", action.payload.checked);
region = region.set("epals", epals.set(action.payload.sIndex,
epal.set("selected", action.payload.checked)));
return state
.set(action.payload.rIndex, region);
/* state.forEach(region => { /* state.forEach(region => {
if (ind === action.payload.rIndex) { if (ind === action.payload.rIndex) {
...@@ -50,39 +76,37 @@ export function regionSchoolsReducer(state: IRegions = REGION_SCHOOLS_INITIAL_ST ...@@ -50,39 +76,37 @@ export function regionSchoolsReducer(state: IRegions = REGION_SCHOOLS_INITIAL_ST
// return state; // return state;
case REGIONSCHOOLS_ORDER_SAVE: case REGIONSCHOOLS_ORDER_SAVE:
region = state[action.payload.rIndex];
let newState2 = Array<IRegionRecord>();
i=0, j=0;
let ind2=0; let ind2=0;
state.forEach(region => { state.forEach(region => {
for(let i=0; i<region.epals.length; i++){ let epals: IRegionSchoolRecords;
if (region.epals[i].globalIndex === action.payload.selectedSchools[0].globalIndex) { epals = region.get("epals");
region.epals[i].order_id = action.payload.selectedSchools[0].order_id epals.forEach(epal => {
return state.withMutations(function (list) { let newOrderId = epal.order_id;
list.set(ind2++, region); for (let jjj=0; jjj<3; jjj++) {
}); if (typeof action.payload.selectedSchools[jjj] !== 'undefined' &&
epal.globalIndex === action.payload.selectedSchools[jjj].globalIndex) {
newOrderId = action.payload.selectedSchools[jjj].order_id;
break;
}
} }
if (typeof action.payload.selectedSchools[1] !== 'undefined' && if (j !== i || i === 0) {
region.epals[i].globalIndex === action.payload.selectedSchools[1].globalIndex) { newState2.push(recordify<IRRegion, IRegionRecord>({region_id: region.region_id, region_name: region.region_name, epals: new Array(recordify<IRRegionSchool, IRegionSchoolRecord>({epal_id: epal.epal_id, epal_name: epal.epal_name, epal_special_case: epal.epal_special_case, globalIndex: epal.globalIndex, selected: epal.selected, order_id: newOrderId })) }));
region.epals[i].order_id = action.payload.selectedSchools[1].order_id j = i;
return state.withMutations(function (list) { } else {
list.set(ind2++, region); newState2[i].epals.push(recordify<IRRegionSchool, IRegionSchoolRecord>({epal_id: epal.epal_id, epal_name: epal.epal_name, epal_special_case: epal.epal_special_case, globalIndex: epal.globalIndex, selected: epal.selected, order_id: newOrderId }));
});
} }
if (typeof action.payload.selectedSchools[2] !== 'undefined' && });
region.epals[i].globalIndex === action.payload.selectedSchools[2].globalIndex) { i++;
region.epals[i].order_id = action.payload.selectedSchools[2].order_id
return state.withMutations(function (list) {
list.set(ind2++, region);
});
}
//}
}
ind2++;
}); });
return state;
case REGIONSCHOOLS_INIT: return newState2;
return REGION_SCHOOLS_INITIAL_STATE; case REGIONSCHOOLS_INIT:
return REGION_SCHOOLS_INITIAL_STATE;
default: return state; default: return state;
} }
}; };
import { IRegions, IRegion } from './regionschools.types'; import { IRegionRecord } from './regionschools.types';
export function deimmutifyRegionSchools(state: IRegions): IRegions { export function deimmutifyRegionSchools(state: IRegionRecord[]): IRegionRecord[] {
// let fetchedRegions = new Array<IRegion>(); // let fetchedRegions = new Array<IRegion>();
// let i = 0; // let i = 0;
......
import { List, Map } from 'immutable'; import { List, Map } from 'immutable';
import {TypedRecord} from 'typed-immutable-record';
export interface IRRegion {
region_id: string;
region_name: string;
epals: IRRegionSchool[];
}
export interface IRRegionSchool {
epal_id: string;
epal_name: string;
epal_special_case: string;
globalIndex: number;
selected: boolean;
order_id: number;
}
export interface IRegionRecord extends TypedRecord<IRegionRecord>, IRRegion {};
export interface IRegionSchoolRecord extends TypedRecord<IRegionSchoolRecord>, IRRegionSchool {};
export type IRegionSchoolRecords = IRegionSchoolRecord[];
export interface Region { export interface Region {
...@@ -26,4 +46,4 @@ export type IRegions = List<IRegionM>; ...@@ -26,4 +46,4 @@ export type IRegions = List<IRegionM>;
// export type IRegionM = Map<IRegion>; // export type IRegionM = Map<IRegion>;
export type IRegionM = Map<string, IRegion>; export type IRegionM = Map<string, IRegion>;
export type IRegionSchoolM = Map<string, RegionSchool>; export type IRegionSchoolM = Map<string, RegionSchool>;
export type IRegionSchools = Map<string, List<IRegionSchoolM>>; export type IRegionSchools = List<RegionSchool>;
...@@ -15,7 +15,7 @@ import * as criter from './criteria'; ...@@ -15,7 +15,7 @@ import * as criter from './criteria';
export interface IAppState { export interface IAppState {
courseFields?: courseFields.ICourseFields; courseFields?: courseFields.ICourseFields;
sectorFields?: sectorFields.ISectorFields; sectorFields?: sectorFields.ISectorFields;
regions?: regions.IRegions; regions?: regions.IRegionRecord[];
sectors?: sectors.ISectors; sectors?: sectors.ISectors;
studentDataFields?: studentDataFields.IStudentDataFields; studentDataFields?: studentDataFields.IStudentDataFields;