Commit 8074c820 authored by Χάρης Παπαδόπουλος's avatar Χάρης Παπαδόπουλος
Browse files

Restructured region schools. Rewrote reducers.

parent 286e72e6
...@@ -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.length === 0 || regions[0].get("region_id") === null))) { if (reload === true || (reload === false && regions.size === 0)) {
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,
......
import 'reflect-metadata'; import "reflect-metadata";
import 'babel-polyfill'; import "babel-polyfill";
import 'core-js/es6'; import "core-js/es6";
import 'core-js/es7/reflect'; import "core-js/es7/reflect";
import { NgModule } from '@angular/core'; import { NgModule } from "@angular/core";
import { NgReduxModule, DevToolsExtension, NgRedux } from 'ng2-redux'; import { NgReduxModule, DevToolsExtension, NgRedux } from "ng2-redux";
import {BrowserModule} from '@angular/platform-browser'; import {BrowserModule} from "@angular/platform-browser";
import { CookieModule } from 'ngx-cookie'; import { CookieModule } from "ngx-cookie";
import { MyDatePickerModule } from 'mydatepicker'; import { MyDatePickerModule } from "mydatepicker";
import { NguiAutoCompleteModule } from '@ngui/auto-complete'; import { NguiAutoCompleteModule } from "@ngui/auto-complete";
import { import {
FormsModule, FormsModule,
ReactiveFormsModule, ReactiveFormsModule,
} from '@angular/forms'; } from "@angular/forms";
import {RouterModule} from '@angular/router'; import {RouterModule} from "@angular/router";
import { HttpModule } from '@angular/http'; import { HttpModule } from "@angular/http";
import { import {
APP_BASE_HREF, APP_BASE_HREF,
HashLocationStrategy, HashLocationStrategy,
LocationStrategy, LocationStrategy,
NgLocalization, NgLocalization,
} from '@angular/common'; } from "@angular/common";
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { platformBrowserDynamic } from "@angular/platform-browser-dynamic";
import Main from './containers/main'; import Main from "./containers/main";
import { APP_ROUTER_PROVIDERS, APP_DECLARATIONS } from './app.routes'; import { APP_ROUTER_PROVIDERS, APP_DECLARATIONS } from "./app.routes";
/* Here we import services */ /* Here we import services */
import {HelperDataService} from './services/helper-data-service'; import {HelperDataService} from "./services/helper-data-service";
import {LoaderService} from './services/Spinner.service'; import {LoaderService} from "./services/Spinner.service";
import {AuthService} from './services/auth.service'; import {AuthService} from "./services/auth.service";
import SchoolAuthGuard from './guards/school.auth.guard'; import SchoolAuthGuard from "./guards/school.auth.guard";
import SchoolStudentsLockedGuard from './guards/school.students.locked.guard'; import SchoolStudentsLockedGuard from "./guards/school.students.locked.guard";
import SchoolCapacityLockedGuard from './guards/school.capacity.locked.guard'; import SchoolCapacityLockedGuard from "./guards/school.capacity.locked.guard";
import StudentAuthGuard from './guards/student.auth.guard'; import StudentAuthGuard from "./guards/student.auth.guard";
import ReportsAuthGuard from './guards/reports.auth.guard'; import ReportsAuthGuard from "./guards/reports.auth.guard";
import StudentLockGuard from './guards/student.lock.guard'; import StudentLockGuard from "./guards/student.lock.guard";
import RegionEduAuthGuard from './guards/regionedu.auth.guard'; import RegionEduAuthGuard from "./guards/regionedu.auth.guard";
import EduAdminAuthGuard from './guards/eduadmin.auth.guard'; import EduAdminAuthGuard from "./guards/eduadmin.auth.guard";
import MinistryAuthGuard from './guards/ministry.auth.guard'; import MinistryAuthGuard from "./guards/ministry.auth.guard";
import * as $ from 'jquery'; import * as $ from "jquery";
import { ACTION_PROVIDERS } from './actions'; import { ACTION_PROVIDERS } from "./actions";
import Home from './components/home'; import Home from "./components/home";
import { Ng2SmartTableModule, LocalDataSource } from 'ng2-smart-table'; import { Ng2SmartTableModule, LocalDataSource } from "ng2-smart-table";
import HeaderComponent from './components/header/header.component'; import HeaderComponent from "./components/header/header.component";
import NavbarComponent from './components/navbar/navbar.component'; import NavbarComponent from "./components/navbar/navbar.component";
import MainComponent from './components/main/main.component'; import MainComponent from "./components/main/main.component";
import FooterComponent from './components/footer/footer.component'; import FooterComponent from "./components/footer/footer.component";
import {enableProdMode} from '@angular/core'; import {enableProdMode} from "@angular/core";
class MyLocalization extends NgLocalization { class MyLocalization extends NgLocalization {
getPluralCategory(value: any) { getPluralCategory(value: any) {
if (value < 5) { if (value < 5) {
return 'few'; return "few";
} }
} }
} }
...@@ -80,12 +80,12 @@ class MyLocalization extends NgLocalization { ...@@ -80,12 +80,12 @@ class MyLocalization extends NgLocalization {
], ],
bootstrap: [ Main ], bootstrap: [ Main ],
providers: [ providers: [
{ provide: APP_BASE_HREF, useValue: '/' }, { provide: APP_BASE_HREF, useValue: "/" },
{ provide: LocationStrategy, useClass: HashLocationStrategy }, { provide: LocationStrategy, useClass: HashLocationStrategy },
{ provide: NgLocalization, useClass: MyLocalization }, { provide: NgLocalization, useClass: MyLocalization },
DevToolsExtension, DevToolsExtension,
ACTION_PROVIDERS, ACTION_PROVIDERS,
//Service1, again services here // Service1, again services here
HelperDataService, HelperDataService,
LoaderService, LoaderService,
AuthService, AuthService,
......
...@@ -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 { IRegionRecord, 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';
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,7 +80,7 @@ import { SECTOR_FIELDS_INITIAL_STATE } from '../../store/sectorfields/sectorfiel ...@@ -80,7 +80,7 @@ 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<Array<IRegionRecord>>; 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<ISectorFields>;
private epalclasses$: BehaviorSubject<IEpalClasses>; private epalclasses$: BehaviorSubject<IEpalClasses>;
...@@ -124,7 +124,7 @@ import { SECTOR_FIELDS_INITIAL_STATE } from '../../store/sectorfields/sectorfiel ...@@ -124,7 +124,7 @@ 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<IRegionSchoolRecord>(); let selectedSchools = Array<IRegionSchoolRecord>();
if (state.regions.length === 0 || state.regions[0].get("region_id") === null) if (state.regions.size === 0)
return; return;
state.regions.reduce((prevRegion, region) => { state.regions.reduce((prevRegion, region) => {
region.get("epals").reduce((prevEpal, epal) => { region.get("epals").reduce((prevEpal, epal) => {
......
...@@ -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 { IRegionRecord, 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 { 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) && (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()"> <button type="button" *ngIf="(studentDataFields$ | async).size > 0 && (regions$ | async) && (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()">
<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<Array<IRegionRecord>>; private regions$: BehaviorSubject<IRegionRecords>;
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 { IRegionRecord } from '../../store/regionschools/regionschools.types'; import { IRegionRecord, IRegionRecords } 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) || (regions$ | async)[0].region_id===null"> <div class = "loading" *ngIf="!(regions$ | async) || (regions$ | async).size===0">
</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<IRegionRecord[]>; private regions$: BehaviorSubject<IRegionRecords>;
private sectors$: BehaviorSubject<ISectors>; private sectors$: BehaviorSubject<ISectors>;
private sectorFields$: BehaviorSubject<ISectorFields>; private sectorFields$: BehaviorSubject<ISectorFields>;
private epalclassesSub: Subscription; private epalclassesSub: Subscription;
...@@ -234,7 +234,7 @@ import {AppSettings} from '../../app.settings'; ...@@ -234,7 +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);
if (state.regions.length === 0 || state.regions[0].get("region_id") === null) if (state.regions.size === 0)
return; return;
state.regions.reduce((prevRegion, region) =>{ state.regions.reduce((prevRegion, region) =>{
......
...@@ -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 { IRegionRecord, IRegionSchoolRecord } from '../../store/regionschools/regionschools.types'; import { IRegionRecord, IRegionRecords, 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,7 +15,7 @@ import {AppSettings} from '../../app.settings'; ...@@ -15,7 +15,7 @@ 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) || ((regions$ | async).length === 1 && (regions$ | async)[0].region_id === null)"> <div class = "loading" *ngIf="(selectedSchools$ | async).length === 0 || !(regions$ | async) || (regions$ | async).size === 0">
</div> </div>
<h4> Σειρά προτίμησης</h4> <h4> Σειρά προτίμησης</h4>
...@@ -51,7 +51,7 @@ import {AppSettings} from '../../app.settings'; ...@@ -51,7 +51,7 @@ 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<Array<IRegionRecord>>; private regions$: BehaviorSubject<IRegionRecords>;
private regionsSub: Subscription; private regionsSub: Subscription;
private selectedSchools$: BehaviorSubject<Array<IRegionSchoolRecord>> = new BehaviorSubject(Array()); private selectedSchools$: BehaviorSubject<Array<IRegionSchoolRecord>> = new BehaviorSubject(Array());
......
...@@ -32,8 +32,6 @@ export class HelperDataService implements OnInit, OnDestroy { ...@@ -32,8 +32,6 @@ export class HelperDataService implements OnInit, OnDestroy {
private _ngRedux: NgRedux<IAppState>, private _ngRedux: NgRedux<IAppState>,
private _cookieService: CookieService) { private _cookieService: CookieService) {
this.loginInfo$ = new BehaviorSubject(LOGININFO_INITIAL_STATE); this.loginInfo$ = new BehaviorSubject(LOGININFO_INITIAL_STATE);
}; };
ngOnInit() { ngOnInit() {
...@@ -278,7 +276,7 @@ export class HelperDataService implements OnInit, OnDestroy { ...@@ -278,7 +276,7 @@ export class HelperDataService implements OnInit, OnDestroy {
}; };
transformRegionSchoolsSchema(regionSchools: any) { transformRegionSchoolsSchema(regionSchools: any) {
let rsa = Array<IRRegion>(); let rsa = Array<any>();
let trackRegionId: string; let trackRegionId: string;
let trackIndex: number; let trackIndex: number;
...@@ -289,7 +287,7 @@ export class HelperDataService implements OnInit, OnDestroy { ...@@ -289,7 +287,7 @@ 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(<IRRegion>{ "region_id": regionSchool.region_id, "region_name": regionSchool.region_name, "epals": Array<IRRegionSchool>() }); rsa.push(<any>{ "region_id": regionSchool.region_id, "region_name": regionSchool.region_name, "epals": Array<any>() });
trackRegionId = regionSchool.region_id; trackRegionId = regionSchool.region_id;
} }
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 }); 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 });
......
...@@ -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 { IRRegion, IRRegionSchool, IRegionRecord, IRegionSchoolRecord } 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';
import { IEpalClass, IEpalClasses } from './epalclasses/epalclasses.types'; import { IEpalClass, IEpalClasses } from './epalclasses/epalclasses.types';
...@@ -19,7 +19,9 @@ export { ...@@ -19,7 +19,9 @@ export {
ISectorFields, ISectorFields,
IRRegion, IRRegion,
IRegionRecord, IRegionRecord,
IRegionRecords,
IRegionSchoolRecord, IRegionSchoolRecord,
IRegionSchoolRecords,
IRRegionSchool, IRRegionSchool,
ISectors, ISectors,
ISector, ISector,
......
import { IRegionRecord, IRRegion, IRRegionSchool, IRegionSchoolRecord } from './regionschools.types'; import { IRegionRecord, IRegionRecords, IRRegion, IRRegionSchool, IRegionSchoolRecord, IRegionSchoolRecords } 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 {
IRRegion, IRRegion,
IRegionRecord, IRegionRecord,
IRegionRecords,
IRegionSchoolRecord, IRegionSchoolRecord,
IRegionSchoolRecords,
IRRegionSchool, IRRegionSchool,
regionSchoolsReducer, regionSchoolsReducer,
deimmutifyRegionSchools, deimmutifyRegionSchools,
......
import { List } from 'immutable'; import { List } from 'immutable';
import { IRegion, IRegionM, IRegionRecord, IRRegion, IRRegionSchool, IRegionSchoolRecord } from './regionschools.types'; import { IRegionRecord, IRRegion, IRRegionSchool, IRegionSchoolRecord, IRegionSchoolRecords } from './regionschools.types';
import {recordify} from 'typed-immutable-record'; 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<IRegionRecord>();
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 })) })); // 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, IRRegion, IRegionM, RegionSchool, IRRegionSchool, IRegionSchools, IRegionSchoolRecord, IRegionSchoolRecords, IRegionRecord } from './regionschools.types'; import { IRRegion, IRRegionSchool, IRegionSchoolRecord, IRegionSchoolRecords, IRegionRecord, IRegionRecords } 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, List } from 'immutable';
import {recordify} from 'typed-immutable-record'; import {recordify} from 'typed-immutable-record';
import { import {
...@@ -10,79 +10,40 @@ import { ...@@ -10,79 +10,40 @@ import {
REGIONSCHOOLS_INIT REGIONSCHOOLS_INIT
} from '../../constants'; } from '../../constants';
export function regionSchoolsReducer(state: IRegionRecord[] = REGION_SCHOOLS_INITIAL_STATE, action): IRegionRecord[] { export function regionSchoolsReducer(state: IRegionRecords = REGION_SCHOOLS_INITIAL_STATE, action): IRegionRecords {
switch (action.type) { switch (action.type) {
case REGIONSCHOOLS_RECEIVED: case REGIONSCHOOLS_RECEIVED:
let newRegions = Array<IRegionRecord>(); let newRegions = Array<IRegionRecord>();
let newEpals = Array<IRegionSchoolRecord>();
let i=0, j=0; let i=0, j=0;
let ii=0; let ii=0;
action.payload.regions.forEach(region => { action.payload.regions.forEach(region => {
region.epals.forEach(epal => { region.epals.forEach(epal => {
if (j !== i || (i === 0 && ii===0)) { newEpals.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 }));
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++; ii++;
}) })
newRegions.push(recordify<IRRegion, IRegionRecord>({region_id: region.region_id, region_name: region.region_name, epals: List(newEpals) }));
newEpals = Array<IRegionSchoolRecord>();
i++; i++;
}); });
return newRegions; return List(newRegions);
case REGIONSCHOOLS_SELECTED_SAVE: case REGIONSCHOOLS_SELECTED_SAVE:
// let ind=0;
let region: IRegionRecord;
region = state[action.payload.rIndex]; let ind=0;
let newState = Array<IRegionRecord>(); return state.withMutations(function (list) {
list.setIn([action.payload.rIndex, "epals"], state.get(action.payload.rIndex).get("epals").setIn([action.payload.sIndex, "selected"], action.payload.checked));
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++;
})
return newState;
/* state.forEach(region => {
if (ind === action.payload.rIndex) {
let regionCopy = state.get(ind);
regionCopy.epals[action.payload.sIndex].selected = action.payload.checked;
return state.withMutations(function (list) {
list.set(ind++, regionCopy);
}); });
}
ind++;
}); */
// return state;
case REGIONSCHOOLS_ORDER_SAVE: case REGIONSCHOOLS_ORDER_SAVE:
region = state[action.payload.rIndex];
let newState2 = Array<IRegionRecord>(); let newState2 = Array<IRegionRecord>();
newEpals = Array<IRegionSchoolRecord>();
i=0, j=0; i=0, j=0;
let ind2=0; let ind2=0;
state.forEach(region => { state.forEach(region => {
let epals: IRegionSchoolRecords; let epals: IRegionSchoolRecords;
epals = region.get("epals"); epals = region.get("epals");
epals.forEach(epal => { epals.forEach(epal => {
let newOrderId = epal.order_id; let newOrderId = epal.order_id;
...@@ -93,18 +54,15 @@ export function regionSchoolsReducer(state: IRegionRecord[] = REGION_SCHOOLS_INI ...@@ -93,18 +54,15 @@ export function regionSchoolsReducer(state: IRegionRecord[] = REGION_SCHOOLS_INI
break; break;
}