Merge branch 'edge_v4' into 'develop_v4'

Restructured ISectors

See merge request !241
parents b4746228 e0a77286
import { SECTORCOURSES_RECEIVED, SECTORCOURSES_SELECTED_SAVE, SECTORCOURSES_INIT } from "../constants"; import { SECTORCOURSES_RECEIVED, SECTORCOURSES_SECTOR_SELECTED_SAVE, SECTORCOURSES_SELECTED_SAVE, SECTORCOURSES_INIT } from "../constants";
import { Injectable } from "@angular/core"; import { Injectable } from "@angular/core";
import { NgRedux } from "@angular-redux/store"; import { NgRedux } from "@angular-redux/store";
import { IAppState } from "../store"; import { IAppState } from "../store";
...@@ -33,12 +33,29 @@ export class SectorCoursesActions { ...@@ -33,12 +33,29 @@ export class SectorCoursesActions {
}); });
}; };
saveSectorCoursesSelected = (sectorCoursesSelected, sectorSelected) => { selectSector = (prevChoice, newChoice) => {
return this._ngRedux.dispatch({
type: SECTORCOURSES_SECTOR_SELECTED_SAVE,
payload: {
prevChoice: prevChoice,
newChoice: newChoice
// sectorCoursesSelected,
// sectorSelected
}
});
}
saveSectorCoursesSelected = (oldSIndex, oldCIndex, checked, i, j) => {
return this._ngRedux.dispatch({ return this._ngRedux.dispatch({
type: SECTORCOURSES_SELECTED_SAVE, type: SECTORCOURSES_SELECTED_SAVE,
payload: { payload: {
sectorCoursesSelected, oldSIndex: oldSIndex,
sectorSelected oldCIndex: oldCIndex,
checked: checked,
sIndex: i,
cIndex: j
// sectorCoursesSelected,
// sectorSelected
} }
}); });
}; };
......
...@@ -9,7 +9,7 @@ import { SectorCoursesActions } from "../../actions/sectorcourses.actions"; ...@@ -9,7 +9,7 @@ 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 { ISectorFieldRecords } from "../../store/sectorfields/sectorfields.types"; import { ISectorFieldRecords } from "../../store/sectorfields/sectorfields.types";
import { ISectors } from "../../store/sectorcourses/sectorcourses.types"; import { ISectorRecords } 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";
import {AppSettings} from "../../app.settings"; import {AppSettings} from "../../app.settings";
...@@ -45,21 +45,21 @@ import { SECTOR_FIELDS_INITIAL_STATE } from "../../store/sectorfields/sectorfiel ...@@ -45,21 +45,21 @@ import { SECTOR_FIELDS_INITIAL_STATE } from "../../store/sectorfields/sectorfiel
<div *ngFor="let sectorField$ of sectorFields$ | async"> <div *ngFor="let sectorField$ of sectorFields$ | async">
<ul class="list-group left-side-view"> <ul class="list-group left-side-view">
<li class="list-group-item active" *ngIf="sectorField$.selected === true" > <li class="list-group-item active" *ngIf="sectorField$.get('selected') === true" >
{{sectorField$.name}} {{sectorField$.get("name")}}
</li> </li>
</ul> </ul>
</div> </div>
<div *ngFor="let sector$ of sectors$ | async;"> <div *ngFor="let sector$ of sectors$ | async;">
<ul class="list-group left-side-view" style="margin-bottom: 20px;" *ngIf="sector$.sector_selected === true"> <ul class="list-group left-side-view" style="margin-bottom: 20px;" *ngIf="sector$.get('sector_selected') === true">
<li class="list-group-item active" *ngIf="sector$.sector_selected === true" > <li class="list-group-item active" *ngIf="sector$.get('sector_selected') === true" >
{{sector$.sector_name }} {{sector$.get("sector_name") }}
</li> </li>
<div *ngFor="let course$ of sector$.courses;" > <div *ngFor="let course$ of sector$.courses;" >
<li class="list-group-item" *ngIf="course$.selected === true"> <li class="list-group-item" *ngIf="course$.selected === true">
{{course$.course_name }} {{course$.get("course_name") }}
</li> </li>
</div> </div>
...@@ -79,7 +79,7 @@ import { SECTOR_FIELDS_INITIAL_STATE } from "../../store/sectorfields/sectorfiel ...@@ -79,7 +79,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<ISectorRecords>;
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<ISectorFieldRecords>; private sectorFields$: BehaviorSubject<ISectorFieldRecords>;
...@@ -108,12 +108,12 @@ import { SECTOR_FIELDS_INITIAL_STATE } from "../../store/sectorfields/sectorfiel ...@@ -108,12 +108,12 @@ import { SECTOR_FIELDS_INITIAL_STATE } from "../../store/sectorfields/sectorfiel
ngOnInit() { ngOnInit() {
this.currentUrl = this.router.url; this.currentUrl = this.router.url;
this.sectorsSub = this._ngRedux.select("sectors") this.sectorsSub = this._ngRedux.select("sectors")
.subscribe(sectors => { .map(sectors => <ISectorRecords>sectors)
let scs = <ISectors>sectors; .subscribe(scs => {
scs.reduce((prevSector, sector) => { scs.reduce((prevSector, sector) => {
sector.courses.reduce((prevCourse, course) => { sector.get("courses").reduce((prevCourse, course) => {
if (course.selected === true) { if (course.get("selected") === true) {
this.courseActive = course.course_id; this.courseActive = course.get("course_id");
} }
return course; return course;
......
...@@ -7,7 +7,7 @@ import { NgRedux, select } from "@angular-redux/store"; ...@@ -7,7 +7,7 @@ import { NgRedux, select } from "@angular-redux/store";
import { IAppState } from "../../store/store"; import { IAppState } from "../../store/store";
import { IStudentDataFieldRecords } from "../../store/studentdatafields/studentdatafields.types"; import { IStudentDataFieldRecords } 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 { ISectorRecords } from "../../store/sectorcourses/sectorcourses.types";
import { ISectorFieldRecords } 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";
...@@ -235,13 +235,13 @@ import { HelperDataService } from "../../services/helper-data-service"; ...@@ -235,13 +235,13 @@ import { HelperDataService } from "../../services/helper-data-service";
this.sectorsSub = this._ngRedux.select("sectors") this.sectorsSub = this._ngRedux.select("sectors")
.subscribe(sectors => { .map(sectors => <ISectorRecords>sectors)
let scs = <ISectors>sectors; .subscribe(scs => {
console.log("SELECTOR2"); console.log("SELECTOR2");
scs.reduce((prevSector, sector) => { scs.reduce((prevSector, sector) => {
sector.courses.reduce((prevCourse, course) => { sector.get("courses").reduce((prevCourse, course) => {
if (course.selected === true) { if (course.get("selected") === true) {
this.courseSelected = course.course_id; this.courseSelected = course.get("course_id");
} }
return course; return course;
}, {}); }, {});
......
...@@ -6,7 +6,7 @@ import { RegionSchoolsActions } from "../../actions/regionschools.actions"; ...@@ -6,7 +6,7 @@ import { RegionSchoolsActions } from "../../actions/regionschools.actions";
import { NgRedux, select } from "@angular-redux/store"; import { NgRedux, select } from "@angular-redux/store";
import { IRegionRecord, IRegionRecords } 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 { ISectors } from "../../store/sectorcourses/sectorcourses.types"; import { ISectorRecords } 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";
...@@ -277,14 +277,14 @@ import {AppSettings} from "../../app.settings"; ...@@ -277,14 +277,14 @@ import {AppSettings} from "../../app.settings";
else if (epalClass === "3" || epalClass === "4") { else if (epalClass === "3" || epalClass === "4") {
this.sectorsSub = this._ngRedux.select("sectors") this.sectorsSub = this._ngRedux.select("sectors")
.map(sectors => <ISectors>sectors) .map(sectors => <ISectorRecords>sectors)
.subscribe(sectors => { .subscribe(sectors => {
console.log("sectorsSub"); console.log("sectorsSub");
sectors.reduce((prevSector, sector) => { sectors.reduce((prevSector, sector) => {
if (sector.sector_selected === true) { if (sector.get("sector_selected") === true) {
sector.courses.reduce((prevCourse, course) => { sector.get("courses").reduce((prevCourse, course) => {
if (course.selected === true) { if (course.get("selected") === true) {
this.courseActive = parseInt(course.course_id); this.courseActive = parseInt(course.get("course_id"));
// this._rsa.getRegionSchools(3,this.courseActive, false); // this._rsa.getRegionSchools(3,this.courseActive, false);
this._rsa.getRegionSchools(parseInt(epalClass), this.courseActive, false); this._rsa.getRegionSchools(parseInt(epalClass), this.courseActive, false);
} }
......
...@@ -3,7 +3,7 @@ import { Router } from "@angular/router"; ...@@ -3,7 +3,7 @@ import { Router } from "@angular/router";
import { BehaviorSubject, Subscription } from "rxjs/Rx"; import { BehaviorSubject, Subscription } from "rxjs/Rx";
import { Injectable } from "@angular/core"; import { Injectable } from "@angular/core";
import { SectorCoursesActions } from "../../actions/sectorcourses.actions"; import { SectorCoursesActions } from "../../actions/sectorcourses.actions";
import { ISectors } from "../../store/sectorcourses/sectorcourses.types"; import { ISectorRecords } from "../../store/sectorcourses/sectorcourses.types";
import { SECTOR_COURSES_INITIAL_STATE } from "../../store/sectorcourses/sectorcourses.initial-state"; import { SECTOR_COURSES_INITIAL_STATE } from "../../store/sectorcourses/sectorcourses.initial-state";
import { NgRedux, select } from "@angular-redux/store"; import { NgRedux, select } from "@angular-redux/store";
import { IAppState } from "../../store/store"; import { IAppState } from "../../store/store";
...@@ -52,20 +52,20 @@ import {AppSettings} from "../../app.settings"; ...@@ -52,20 +52,20 @@ import {AppSettings} from "../../app.settings";
<ul class="list-group"> <ul class="list-group">
<div *ngFor="let sector$ of sectors$ | async; let i=index; let isOdd=odd; let isEven=even"> <div *ngFor="let sector$ of sectors$ | async; let i=index; let isOdd=odd; let isEven=even">
<li class="list-group-item isclickable" (click)="setActiveSector(i)" [class.oddout]="isOdd" [class.evenout]="isEven" [class.selectedout]="sectorActive === i"> <li class="list-group-item isclickable" (click)="setActiveSector(i)" [class.oddout]="isOdd" [class.evenout]="isEven" [class.selectedout]="sectorActive === i">
<h5>{{sector$.sector_name}}</h5> <h5>{{sector$.get("sector_name")}}</h5>
</li> </li>
<div *ngFor="let course$ of sector$.courses; let j=index; let isOdd2=odd; let isEven2=even" [class.oddin]="isOdd2" [class.evenin]="isEven2" [hidden]="i !== sectorActive"> <div *ngFor="let course$ of sector$.get('courses'); let j=index; let isOdd2=odd; let isEven2=even" [class.oddin]="isOdd2" [class.evenin]="isEven2" [hidden]="i !== sectorActive">
<div class="row"> <div class="row">
<div class="col-md-2 col-md-offset-1"> <div class="col-md-2 col-md-offset-1">
<input #cb type="checkbox" formControlName="{{ course$.globalIndex }}" <input #cb type="checkbox" formControlName="{{ course$.get('globalIndex') }}"
(change)="updateCheckedOptions(course$.globalIndex, cb)" (change)="updateCheckedOptions(course$.get('globalIndex'), i, j, cb)"
[checked] = " course$.globalIndex === idx " [checked] = " course$.get('globalIndex') === idx "
> >
</div> </div>
<div class="col-md-8 col-md-offset-1 isclickable"> <div class="col-md-8 col-md-offset-1 isclickable">
{{course$.course_name | removeSpaces}} {{course$.course_name | removeSpaces}}
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</ul> </ul>
...@@ -87,12 +87,17 @@ import {AppSettings} from "../../app.settings"; ...@@ -87,12 +87,17 @@ import {AppSettings} from "../../app.settings";
` `
}) })
@Injectable() export default class SectorCoursesSelect implements OnInit, OnDestroy { @Injectable() export default class SectorCoursesSelect implements OnInit, OnDestroy {
private sectors$: BehaviorSubject<ISectors>; private sectors$: BehaviorSubject<ISectorRecords>;
private sectorsSub: Subscription; private sectorsSub: Subscription;
private formGroup: FormGroup; private formGroup: FormGroup;
private rss = new FormArray([]); private scsControls = new FormArray([]);
private sectorActive = <number>-1; private sectorActive = <number>-1;
private sectorBelonging = <number>-1;
private sectorBelongingPrev = <number>-1;
private courseSelected = <number>-1;
private courseSelectedPrev = <number>-1;
private idx = <number>-1; private idx = <number>-1;
private idxPrev = <number>-1;
private sectorsList: Array<boolean> = new Array(); private sectorsList: Array<boolean> = new Array();
private modalTitle: BehaviorSubject<string>; private modalTitle: BehaviorSubject<string>;
private modalText: BehaviorSubject<string>; private modalText: BehaviorSubject<string>;
...@@ -108,7 +113,7 @@ import {AppSettings} from "../../app.settings"; ...@@ -108,7 +113,7 @@ import {AppSettings} from "../../app.settings";
this.sectors$ = new BehaviorSubject(SECTOR_COURSES_INITIAL_STATE); this.sectors$ = new BehaviorSubject(SECTOR_COURSES_INITIAL_STATE);
this.formGroup = this.fb.group({ this.formGroup = this.fb.group({
formArray: this.rss formArray: this.scsControls
}); });
this.modalTitle = new BehaviorSubject(""); this.modalTitle = new BehaviorSubject("");
this.modalText = new BehaviorSubject(""); this.modalText = new BehaviorSubject("");
...@@ -119,31 +124,46 @@ import {AppSettings} from "../../app.settings"; ...@@ -119,31 +124,46 @@ import {AppSettings} from "../../app.settings";
ngOnInit() { ngOnInit() {
(<any>$("#sectorCourseNotice")).appendTo("body"); (<any>$("#sectorCourseNotice")).appendTo("body");
this._sca.getSectorCourses(false); this._sca.getSectorCourses(false);
let ids = 0; let ids = 0, idc = 0;
this.sectorsSub = this._ngRedux.select("sectors").subscribe(sectors => { this.sectorsSub = this._ngRedux.select("sectors")
let scs = <ISectors>sectors; .map(sectors => <ISectorRecords>sectors)
scs.reduce((prevSector, sector) => { .subscribe(scs => {
this.sectorsList[ids] = sector.sector_selected;
ids++; let pushControls = false;
// In case we want to preserve last checked option when we revisit the form if (this.scsControls.length === 0)
if (sector.sector_selected === true) pushControls = true;
this.sectorActive = ids - 1;
sector.courses.reduce((prevCourse, course) => { scs.reduce((prevSector, sector) => {
this.rss.push(new FormControl(course.selected, [])); this.sectorsList[ids] = sector.get("sector_selected");
// this.retrieveCheck();
if (course.selected === true) { // In case we want to preserve last checked option when we revisit the form
// In case we want to preserve last checked option when we revisit the form if (sector.get("sector_selected") === true)
this.idx = course.globalIndex; this.sectorActive = ids;
} sector.get("courses").reduce((prevCourse, course) => {
return course; if (pushControls)
this.scsControls.push(new FormControl(course.get("selected"), []));
// this.retrieveCheck();
if (course.get("selected") === true) {
// In case we want to preserve last checked option when we revisit the form
this.sectorBelongingPrev = this.sectorBelonging;
this.sectorBelonging = ids;
this.courseSelectedPrev = this.courseSelected;
this.courseSelected = idc;
this.idxPrev = this.idx;
this.idx = course.get("globalIndex");
}
idc++;
return course;
}, {});
ids++;
idc = 0;
return sector;
}, {}); }, {});
return sector; ids = 0;
}, {}); this.sectors$.next(scs);
ids = 0; }, error => { console.log("error selecting sectors"); });
this.sectors$.next(scs); };
}, error => { console.log("error selecting sectors"); });
}
ngOnDestroy() { ngOnDestroy() {
(<any>$("#sectorCourseNotice")).remove(); (<any>$("#sectorCourseNotice")).remove();
...@@ -164,17 +184,10 @@ import {AppSettings} from "../../app.settings"; ...@@ -164,17 +184,10 @@ import {AppSettings} from "../../app.settings";
} }
setActiveSector(ind) { setActiveSector(ind) {
if (ind === this.sectorActive) // this._sca.selectSector(this.sectorActive, ind);
ind = -1;
this.sectorActive = ind; this.sectorActive = ind;
} }
saveSelected() {
this._sca.saveSectorCoursesSelected(this.formGroup.value.formArray, this.sectorsList);
this._rsa.initRegionSchools();
}
navigateToSchools() { navigateToSchools() {
if (this.idx === -1) { if (this.idx === -1) {
...@@ -187,19 +200,35 @@ import {AppSettings} from "../../app.settings"; ...@@ -187,19 +200,35 @@ import {AppSettings} from "../../app.settings";
} }
} }
updateCheckedOptions(globalIndex, cb) { updateCheckedOptions(globalIndex, i, j, cb) {
this.sectorBelongingPrev = this.sectorBelonging;
this.sectorBelonging = i;
this.courseSelectedPrev = this.courseSelected;
this.courseSelected = j;
this.idxPrev = this.idx;
this.idx = globalIndex; this.idx = globalIndex;
for (let i = 0; i < this.formGroup.value.formArray.length; i++) /* for (let i = 0; i < this.formGroup.value.formArray.length; i++)
this.formGroup.value.formArray[i] = false; this.formGroup.value.formArray[i] = false; */
this.formGroup.value.formArray[globalIndex] = cb.checked; if (this.idxPrev >= 0)
if (cb.checked === false) this.formGroup.value.formArray[this.idxPrev] = false;
if (this.idx >= 0)
this.formGroup.value.formArray[globalIndex] = cb.checked;
this._sca.saveSectorCoursesSelected(this.sectorBelongingPrev, this.courseSelectedPrev, cb.checked, i, j);
if (cb.checked === false) {
this.idxPrev = -1;
this.idx = -1; this.idx = -1;
}
this._rsa.initRegionSchools();
for (let i = 0; i < this.sectorsList.length; i++) /* for (let i = 0; i < this.sectorsList.length; i++)
this.sectorsList[i] = false; this.sectorsList[i] = false;
this.sectorsList[this.sectorActive] = true; this.sectorsList[this.sectorActive] = true; */
this.saveSelected(); // this.saveSelected();
} }
} }
...@@ -16,6 +16,7 @@ export const REGIONSCHOOLS_INIT = "REGIONSCHOOLS_INIT"; ...@@ -16,6 +16,7 @@ export const REGIONSCHOOLS_INIT = "REGIONSCHOOLS_INIT";
export const SECTORCOURSES_RECEIVED = "SECTORCOURSES_RECEIVED"; export const SECTORCOURSES_RECEIVED = "SECTORCOURSES_RECEIVED";
export const SECTORCOURSES_SELECTED_SAVE = "SECTORCOURSES_SELECTED_SAVE"; export const SECTORCOURSES_SELECTED_SAVE = "SECTORCOURSES_SELECTED_SAVE";
export const SECTORCOURSES_SECTOR_SELECTED_SAVE = "SECTORCOURSES_SECTOR_SELECTED_SAVE";
export const SECTORCOURSES_INIT = "SECTORCOURSES_INIT"; export const SECTORCOURSES_INIT = "SECTORCOURSES_INIT";
export const STUDENTDATAFIELDS_SAVE = "STUDENTDATAFIELDS_SAVE"; export const STUDENTDATAFIELDS_SAVE = "STUDENTDATAFIELDS_SAVE";
......
...@@ -4,7 +4,7 @@ import { BehaviorSubject, Subscription } from "rxjs/Rx"; ...@@ -4,7 +4,7 @@ import { BehaviorSubject, Subscription } from "rxjs/Rx";
import "rxjs/add/operator/map"; import "rxjs/add/operator/map";
import { ISectorField } from "../store/sectorfields/sectorfields.types"; import { ISectorField } from "../store/sectorfields/sectorfields.types";
import { IRegionRecord, IRegionSchoolRecord, IRRegion, IRRegionSchool } 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 { ISectorRecord, ISectorRecords, ISectorCourse } from "../store/sectorcourses/sectorcourses.types";
import { AppSettings } from "../app.settings"; import { AppSettings } from "../app.settings";
import { NgRedux, select } from "@angular-redux/store"; import { NgRedux, select } from "@angular-redux/store";
import { IAppState } from "../store/store"; import { IAppState } from "../store/store";
...@@ -276,7 +276,7 @@ export class HelperDataService implements OnInit, OnDestroy { ...@@ -276,7 +276,7 @@ export class HelperDataService implements OnInit, OnDestroy {
} }
transformSectorCoursesSchema(sectorCourses: any) { transformSectorCoursesSchema(sectorCourses: any) {
let rsa = Array<ISector>(); let rsa = Array<any>();
let trackSectorId: string; let trackSectorId: string;
let trackIndex: number; let trackIndex: number;
...@@ -287,7 +287,7 @@ export class HelperDataService implements OnInit, OnDestroy { ...@@ -287,7 +287,7 @@ export class HelperDataService implements OnInit, OnDestroy {
sectorCourses.forEach(sectorCourse => { sectorCourses.forEach(sectorCourse => {
if (trackSectorId !== sectorCourse.sector_id) { if (trackSectorId !== sectorCourse.sector_id) {
trackIndex++; trackIndex++;
rsa.push(<ISector>{ "sector_id": sectorCourse.sector_id, "sector_name": sectorCourse.sector_name, "sector_selected": false, "courses": Array<ISectorCourse>() }); rsa.push(<any>{ "sector_id": sectorCourse.sector_id, "sector_name": sectorCourse.sector_name, "sector_selected": false, "courses": Array<any>() });
trackSectorId = sectorCourse.sector_id; trackSectorId = sectorCourse.sector_id;
} }
rsa[trackIndex].courses.push(<ISectorCourse>{ "course_id": sectorCourse.course_id, "course_name": sectorCourse.course_name, "globalIndex": j, "selected": false }); rsa[trackIndex].courses.push(<ISectorCourse>{ "course_id": sectorCourse.course_id, "course_name": sectorCourse.course_name, "globalIndex": j, "selected": false });
......
...@@ -3,7 +3,7 @@ import {createLogger} from "redux-logger"; ...@@ -3,7 +3,7 @@ import {createLogger} from "redux-logger";
import { IAppState, rootReducer, deimmutify } from "./store"; import { IAppState, rootReducer, deimmutify } from "./store";
import { ISectorFieldRecord, ISectorFieldRecords } 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 { ISectorRecords, ISectorRecord, ISector, ISectorCourseRecords, ISectorCourseRecord, ISectorCourse } from "./sectorcourses/sectorcourses.types";
import { IStudentDataFieldRecord, IStudentDataFieldRecords } from "./studentdatafields/studentdatafields.types"; import { IStudentDataFieldRecord, IStudentDataFieldRecords } from "./studentdatafields/studentdatafields.types";
import { IEpalClass, IEpalClasses } from "./epalclasses/epalclasses.types"; import { IEpalClass, IEpalClasses } from "./epalclasses/epalclasses.types";
import { ILoginInfoToken, ILoginInfo } from "./logininfo/logininfo.types"; import { ILoginInfoToken, ILoginInfo } from "./logininfo/logininfo.types";
...@@ -19,8 +19,11 @@ IRegionRecords, ...@@ -19,8 +19,11 @@ IRegionRecords,
IRegionSchoolRecord, IRegionSchoolRecord,
IRegionSchoolRecords, IRegionSchoolRecords,
IRRegionSchool, IRRegionSchool,
ISectors, ISectorRecords,
ISectorRecord,
ISector, ISector,
ISectorCourseRecords,
ISectorCourseRecord,
ISectorCourse, ISectorCourse,
IStudentDataFieldRecord, IStudentDataFieldRecord,
IStudentDataFieldRecords, IStudentDataFieldRecords,
......
import { List } from "immutable"; import { List } from "immutable";
import { IRegionRecord, IRRegion, IRRegionSchool, IRegionSchoolRecord, IRegionSchoolRecords } from "./regionschools.types"; import { IRegionRecord } from "./regionschools.types";
import {recordify} from "typed-immutable-record";
export const REGION_SCHOOLS_INITIAL_STATE = List<IRegionRecord>(); export const REGION_SCHOOLS_INITIAL_STATE = List<IRegionRecord>();
import { IRRegion, IRRegionSchool, IRegionSchoolRecord, IRegionSchoolRecords, IRegionRecord, IRegionRecords } 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, List } from "immutable"; import { List } from "immutable";
import {recordify} from "typed-immutable-record"; import {recordify} from "typed-immutable-record";
import { import {
...@@ -29,10 +29,8 @@ export function regionSchoolsReducer(state: IRegionRecords = REGION_SCHOOLS_INIT ...@@ -29,10 +29,8 @@ export function regionSchoolsReducer(state: IRegionRecords = REGION_SCHOOLS_INIT
}); });
return List(newRegions); return List(newRegions);
case REGIONSCHOOLS_SELECTED_SAVE: case REGIONSCHOOLS_SELECTED_SAVE:
let ind = 0;
return state.withMutations(function(list) { 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)); list.setIn([action.payload.rIndex, "epals"], list.get(action.payload.rIndex).get("epals").setIn([action.payload.sIndex, "selected"], action.payload.checked));
}); });
case REGIONSCHOOLS_ORDER_SAVE: case REGIONSCHOOLS_ORDER_SAVE:
......
import { ISectors, ISector, ISectorCourse } from "./sectorcourses.types"; import { ISectorRecords, ISectorRecord, ISector, ISectorCourseRecords, ISectorCourseRecord, ISectorCourse } from "./sectorcourses.types";
import { sectorCoursesReducer } from "./sectorcourses.reducer"; import { sectorCoursesReducer } from "./sectorcourses.reducer";
import { deimmutifySectorCourses } from "./sectorcourses.transformers"; import { deimmutifySectorCourses } from "./sectorcourses.transformers";
export { export {
ISectorRecords,
ISectorRecord,
ISector, ISector,
ISectors, ISectorCourseRecords,
ISectorCourseRecord,
ISectorCourse, ISectorCourse,
sectorCoursesReducer, sectorCoursesReducer,
deimmutifySectorCourses, deimmutifySectorCourses,
......
import { List } from "immutable"; import { List } from "immutable";
import { ISector } from "./sectorcourses.types"; import { ISectorRecord } from "./sectorcourses.types";
export const SECTOR_COURSES_INITIAL_STATE = List<ISector>(); export const SECTOR_COURSES_INITIAL_STATE = List<ISectorRecord>();
import { ISectors, ISector, ISectorCourse } from "./sectorcourses.types"; import { ISectorRecords, ISectorRecord, ISectorCourseRecord, ISector, ISectorCourse } from "./sectorcourses.types";
import { SECTOR_COURSES_INITIAL_STATE } from "./sectorcourses.initial-state"; import { SECTOR_COURSES_INITIAL_STATE } from "./sectorcourses.initial-state";
import { Seq } from "immutable"; import { List } from "immutable";
import {recordify} from "typed-immutable-record";
import { import {
SECTORCOURSES_RECEIVED, SECTORCOURSES_RECEIVED,
SECTORCOURSES_SECTOR_SELECTED_SAVE,
SECTORCOURSES_SELECTED_SAVE, SECTORCOURSES_SELECTED_SAVE,
SECTORCOURSES_INIT SECTORCOURSES_INIT
} from "../../constants"; } from "../../constants";
export function sectorCoursesReducer(state: ISectors = SECTOR_COURSES_INITIAL_STATE, action): ISectors { export function sectorCoursesReducer(state: ISectorRecords = SECTOR_COURSES_INITIAL_STATE, action): ISectorRecords {
switch (action.type) { switch (action.type) {
case SECTORCOURSES_RECEIVED: case SECTORCOURSES_RECEIVED:
let newSectors = Array<ISector>(); let newSectors = Array<ISectorRecord>();
let i = 0; let newCourses = Array<ISectorCourseRecord>();
action.payload.sectors.forEach(sector => { let i = 0, j = 0;
newSectors.push(<ISector>{ sector_id: sector.sector_id, sector_name: sector.sector_name, sector_selected: sector.sector_selected, courses: Array<ISectorCourse>() }); let ii = 0;
sector.courses.forEach(course => {
newSectors[i].courses.push(<ISectorCourse>{ course_id: course.course_id, course_name: course.course_name, globalIndex: course.globalIndex, selected: course.selected }); action.payload.sectors.forEach(sector => {
}); sector.courses.forEach(course => {
i++; newCourses.push(recordify<ISectorCourse, ISectorCourseRecord>({ course_id: course.course_id, course_name: course.course_name, globalIndex: course.globalIndex, selected: course.selected }));
ii++;
});
newSectors.push(recordify<ISector, ISectorRecord>({ sector_id: sector.sector_id, sector_name: sector.sector_name, sector_selected: sector.sector_selected, courses: List(newCourses) }));
newCourses = Array<ISectorCourseRecord>();
i++;
});
return List(newSectors);
case SECTORCOURSES_SECTOR_SELECTED_SAVE:
return state.withMutations(function(list) {
if (action.payload.prevChoice >= 0)
list.setIn([action.payload.prevChoice, "sector_selected"], false