Merge branch 'edge_v4' into 'develop_v4'

Restructured sectorFields. Fixed form bugs

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