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

Merge branch 'front_end_antipattern_fix' into 'develop'

Front end antipattern fix

See merge request !32
parents cd245a43 b2b5fef3
......@@ -13,7 +13,6 @@ export class RegionSchoolsActions {
getRegionSchools = (classActive,courseActive, reload) => {
const { regions } = this._ngRedux.getState();
if (reload === true || (reload === false && regions.size === 0)) {
console.log("test1", classActive,courseActive, reload);
return this._hds.getRegionsWithSchools(classActive,courseActive).then(regions => {
return this._ngRedux.dispatch({
type: REGIONSCHOOLS_RECEIVED,
......@@ -49,11 +48,13 @@ export class RegionSchoolsActions {
};
*/
saveRegionSchoolsSelected = (regionSchoolsSelected) => {
saveRegionSchoolsSelected = (checked, i, j) => {
return this._ngRedux.dispatch({
type: REGIONSCHOOLS_SELECTED_SAVE,
payload: {
regionSchoolsSelected
checked: checked,
rIndex: i,
sIndex: j
}
});
};
......
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, OnDestroy } from '@angular/core';
import { Router } from '@angular/router';
import { Observable } from 'rxjs/Rx';
import { BehaviorSubject, Subscription } from 'rxjs/Rx';
import { Injectable } from "@angular/core";
import { NgRedux, select } from 'ng2-redux';
import { IAppState } from '../../store/store';
......@@ -9,14 +9,18 @@ import { SectorCoursesActions } from '../../actions/sectorcourses.actions';
import { RegionSchoolsActions } from '../../actions/regionschools.actions';
import { StudentDataFieldsActions } from '../../actions/studentdatafields.actions';
import { EpalClassesActions } from '../../actions/epalclass.actions';
import { AmkaFillsActions } from '../../actions/amkafill.actions';
import { ISectorFields } from '../../store/sectorfields/sectorfields.types';
import { ISectors } from '../../store/sectorcourses/sectorcourses.types';
import { IRegions } from '../../store/regionschools/regionschools.types';
import { IStudentDataFields } from '../../store/studentdatafields/studentdatafields.types';
import { IEpalClasses } from '../../store/epalclasses/epalclasses.types';
import { IAmkaFills } from '../../store/amkafill/amkafills.types';
import {AppSettings} from '../../app.settings';
import { REGION_SCHOOLS_INITIAL_STATE } from '../../store/regionschools/regionschools.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_FIELDS_INITIAL_STATE } from '../../store/sectorfields/sectorfields.initial-state';
import { STUDENT_DATA_FIELDS_INITIAL_STATE } from '../../store/studentdatafields/studentdatafields.initial-state';
@Component({
......@@ -35,7 +39,6 @@ import {AppSettings} from '../../app.settings';
</ul>
</div>
<div *ngFor="let sectorField$ of sectorFields$ | async">
<ul class="list-group left-side-view">
<li class="list-group-item active" *ngIf="sectorField$.selected === true" >
......@@ -119,12 +122,16 @@ import {AppSettings} from '../../app.settings';
})
@Injectable() export default class ApplicationPreview implements OnInit {
private sectors$: Observable<ISectors>;
private regions$: Observable<IRegions>;
private sectorFields$: Observable<ISectorFields>;
private studentDataFields$: Observable<IStudentDataFields>;
private selectedAmkaFills$: Observable<IAmkaFills>;
private epalclasses$: Observable<IEpalClasses>;
private sectors$: BehaviorSubject<ISectors>;
private regions$: BehaviorSubject<IRegions>;
private sectorFields$: BehaviorSubject<ISectorFields>;
private studentDataFields$: BehaviorSubject<IStudentDataFields>;
private epalclasses$: BehaviorSubject<IEpalClasses>;
private sectorsSub: Subscription;
private regionsSub: Subscription;
private sectorFieldsSub: Subscription;
private studentDataFieldsSub: Subscription;
private epalclassesSub: Subscription;
private courseActive = "-1";
private numSelectedSchools = <number>0;
private numSelectedOrder = <number>0;
......@@ -133,32 +140,34 @@ import {AppSettings} from '../../app.settings';
constructor(private _ngRedux: NgRedux<IAppState>,
private router: Router
) {
this.regions$ = new BehaviorSubject(REGION_SCHOOLS_INITIAL_STATE);
this.epalclasses$ = new BehaviorSubject(EPALCLASSES_INITIAL_STATE);
this.sectors$ = new BehaviorSubject(SECTOR_COURSES_INITIAL_STATE);
this.sectorFields$ = new BehaviorSubject(SECTOR_FIELDS_INITIAL_STATE);
this.studentDataFields$ = new BehaviorSubject(STUDENT_DATA_FIELDS_INITIAL_STATE);
};
ngOnInit() {
this.courseActive = this.getCourseActive();
this.sectors$ = this._ngRedux.select(state => {
//let numsel = 0;
this.sectorsSub = this._ngRedux.select(state => {
state.sectors.reduce((prevSector, sector) => {
//if (sector.sector_selected)
console.log("hello" + sector.sector_selected);
sector.courses.reduce((prevCourse, course) => {
//if (course.selected === true) {
// numsel++;
//}
if (course.selected === true) {
this.courseActive = course.course_id;
}
return course;
}, {});
return sector;
}, {});
//this.numSelectedCourses = numsel;
return state.sectors;
});
}).subscribe(this.sectors$);
this.regions$ = this._ngRedux.select(state => {
this.regionsSub = this._ngRedux.select(state => {
let numsel = 0, numsel2 = 0;
state.regions.reduce((prevRegion, region) => {
region.epals.reduce((prevEpal, epal) => {
console.log("hello" + epal.selected);
if (epal.selected === true) {
numsel++;
}
......@@ -172,30 +181,30 @@ import {AppSettings} from '../../app.settings';
this.numSelectedSchools = numsel;
this.numSelectedOrder = numsel2;
return state.regions;
});
}).subscribe(this.regions$);
this.sectorFields$ = this._ngRedux.select(state => {
this.sectorFieldsSub = this._ngRedux.select(state => {
state.sectorFields.reduce(({}, sectorField) => {
return sectorField;
}, {});
return state.sectorFields;
});
}).subscribe(this.sectorFields$);
this.studentDataFields$ = this._ngRedux.select(state => {
this.studentDataFieldsSub = this._ngRedux.select(state => {
state.studentDataFields.reduce(({}, studentDataField) => {
return studentDataField;
}, {});
return state.studentDataFields;
});
}).subscribe(this.studentDataFields$);
this.selectedAmkaFills$ = this._ngRedux.select(state => {
/* this.selectedAmkaFills$ = this._ngRedux.select(state => {
state.amkafills.reduce(({}, selectedAmkaFill) => {
return selectedAmkaFill;
}, {});
return state.amkafills;
});
}); */
this.epalclasses$ = this._ngRedux.select(state => {
this._ngRedux.select(state => {
state.epalclasses.reduce(({}, epalclass) => {
if (epalclass.name === "Α' Λυκείου")
this.classSelected = 1;
......@@ -206,42 +215,23 @@ import {AppSettings} from '../../app.settings';
return epalclass;
}, {});
return state.epalclasses;
});
}
defineSector() {
this.router.navigate(['/sector-fields-select']);
}
defineSchools() {
this.router.navigate(['/region-schools-select']);
}
definePersonalData() {
this.router.navigate(['/student-application-form-main']);
}
defineClass() {
this.router.navigate(['/epal-class-select']);
}
}).subscribe(this.epalclasses$);
getCourseActive() {
const { sectors } = this._ngRedux.getState();
let l, m;
for (l = 0; l < sectors.size; l++)
if (sectors["_tail"]["array"][l]["sector_selected"] === true)
for (m = 0; m < sectors["_tail"]["array"][l]["courses"].length; m++)
if (sectors["_tail"]["array"][l]["courses"][m]["selected"] === true)
return sectors["_tail"]["array"][l]["courses"][m]["course_id"];
}
defineCourse() {
this.router.navigate(['/sectorcourses-fields-select']);
ngOnDestroy() {
this.regionsSub.unsubscribe();
this.epalclassesSub.unsubscribe();
this.sectorsSub.unsubscribe();
this.sectorFieldsSub.unsubscribe();
this.studentDataFieldsSub.unsubscribe();
}
defineOrder() {
this.router.navigate(['/schools-order-select']);
showValues() {
console.log(this.epalclasses$);
console.log(this.studentDataFields$);
console.log(this.regions$);
console.log(this.sectors$);
}
}
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, OnDestroy } from '@angular/core';
import { Router } from '@angular/router';
import { Observable } from 'rxjs/Rx';
import { BehaviorSubject, Subscription } from 'rxjs/Rx';
import { Injectable } from "@angular/core";
import { RegionSchoolsActions } from '../../actions/regionschools.actions';
import { NgRedux, select } from 'ng2-redux';
import { IRegions } from '../../store/regionschools/regionschools.types';
import { REGION_SCHOOLS_INITIAL_STATE } from '../../store/regionschools/regionschools.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_FIELDS_INITIAL_STATE } from '../../store/sectorfields/sectorfields.initial-state';
import { SectorCoursesActions } from '../../actions/sectorcourses.actions';
import { ISectors } from '../../store/sectorcourses/sectorcourses.types';
import { IAppState } from '../../store/store';
import {RemoveSpaces} from '../../pipes/removespaces';
import { RemoveSpaces } from '../../pipes/removespaces';
import { IEpalClasses } from '../../store/epalclasses/epalclasses.types';
import { ISectorFields } from '../../store/sectorfields/sectorfields.types';
import {
......@@ -20,9 +26,9 @@ import {
import {AppSettings} from '../../app.settings';
@Component({
selector: 'course-fields-select',
selector: 'region-schools-select',
template: `
<div class = "loading" *ngIf="showLoader$ | async">
<div class = "loading" *ngIf="(regions$ | async).size === 0">
</div>
<!-- <div class="row equal">
<div class="col-md-12"> -->
......@@ -39,7 +45,7 @@ import {AppSettings} from '../../app.settings';
<div class="row">
<div class="col-md-2 col-md-offset-1">
<input #cb type="checkbox" formControlName="{{ epal$.globalIndex }}"
(change)="saveSelected(cb,j)"
(change)="saveSelected(cb.checked,i,j)"
[hidden] = "numSelected === 3 && cb.checked === false"
>
</div>
......@@ -53,39 +59,40 @@ import {AppSettings} from '../../app.settings';
</div>
</ul>
</div>
<div class="row" style="margin-top: 20px;" *ngIf="!(showLoader$ | async)">
<div class="row" style="margin-top: 20px;" *ngIf="(regions$ | async).size > 0">
<div class="col-md-6">
<button [hidden] = "objLoaderStatus == true" type="button" class="btn-primary btn-lg pull-left" (click)="navigateBack()" >
<button type="button" class="btn-primary btn-lg pull-left" (click)="navigateBack()" >
<i class="fa fa-backward"></i>
</button>
</div>
<div class="col-md-6">
<button [hidden] = "objLoaderStatus == true" type="button" class="btn-primary btn-lg pull-right" (click)="navigateToApplication()" [disabled] = "numSelected === 0" >
<button type="button" class="btn-primary btn-lg pull-right" (click)="navigateToApplication()" [disabled] = "numSelected === 0" >
<i class="fa fa-forward"></i>
</button>
</div>
</div>
</form>
<!-- </div>
</div> -->
`
})
@Injectable() export default class RegionSchoolsSelect implements OnInit {
private regions$: Observable<IRegions>;
private sectors$: Observable<ISectors>;
private showLoader$: Observable<boolean>;
@Injectable() export default class RegionSchoolsSelect implements OnInit, OnDestroy {
private epalclasses$: BehaviorSubject<IEpalClasses>;
private regions$: BehaviorSubject<IRegions>;
private sectors$: BehaviorSubject<ISectors>;
private sectorFields$: BehaviorSubject<ISectorFields>;
private epalclassesSub: Subscription;
private regionsSub: Subscription;
private sectorsSub: Subscription;
private sectorFieldsSub: Subscription;
private formGroup: FormGroup;
private rss = new FormArray([]);
private classActive = "-1";
private regionActive = <number>-1;
private courseActive = -1;
private courseActive = <number>-1;
private numSelected = <number>0;
//private schoolArray: Array<boolean> = new Array();
constructor(private fb: FormBuilder,
private _rsa: RegionSchoolsActions,
private _rsb: SectorCoursesActions,
......@@ -93,6 +100,10 @@ import {AppSettings} from '../../app.settings';
private router: Router
) {
this.regions$ = new BehaviorSubject(REGION_SCHOOLS_INITIAL_STATE);
this.epalclasses$ = new BehaviorSubject(EPALCLASSES_INITIAL_STATE);
this.sectors$ = new BehaviorSubject(SECTOR_COURSES_INITIAL_STATE);
this.sectorFields$ = new BehaviorSubject(SECTOR_FIELDS_INITIAL_STATE);
this.formGroup = this.fb.group({
formArray: this.rss
......@@ -101,25 +112,34 @@ import {AppSettings} from '../../app.settings';
};
ngOnInit() {
this.selectEpalClasses();
this.classActive = this.classActive = this.getClassActive();
this.selectRegionSchools();
}
let class_id = -1;
if (this.classActive === "Α' Λυκείου") {
//είναι Α' Λυκείου, οπότε courseActive = "-1" (είναι ήδη ορισμένο με αυτή την τιμή από την αρχικοποίηση)
class_id = 1;
}
else if (this.classActive === "Β' Λυκείου") {
class_id = 2;
this.courseActive = this.getSectorActive();
}
else if (this.classActive === "Γ' Λυκείου") {
class_id = 3;
this.courseActive = this.getCourseActive();
}
ngOnDestroy() {
if (this.epalclassesSub) this.epalclassesSub.unsubscribe();
if (this.regionsSub) this.regionsSub.unsubscribe();
if (this.sectorsSub) this.sectorsSub.unsubscribe();
if (this.sectorFieldsSub) this.sectorFieldsSub.unsubscribe();
}
selectEpalClasses() {
this.epalclassesSub = this._ngRedux.select(state => {
if (state.epalclasses.size > 0) {
state.epalclasses.reduce(({}, epalclass, i) => {
this.setClassActive(epalclass.name);
this.getAppropriateSchools(epalclass.name);
return epalclass;
}, {});
}
return state.epalclasses;
}).subscribe(this.epalclasses$);
}
selectRegionSchools() {
this._rsa.getRegionSchools(class_id,this.courseActive, false);
this.regions$ = this._ngRedux.select(state => {
this.regionsSub = this._ngRedux.select(state => {
let numsel = 0;
state.regions.reduce((prevRegion, region) =>{
region.epals.reduce((prevEpal, epal) =>{
......@@ -133,8 +153,46 @@ import {AppSettings} from '../../app.settings';
}, {});
this.numSelected = numsel;
return state.regions;
});
this.showLoader$ = this.regions$.map(regions => regions.size === 0);
}).subscribe(this.regions$);
}
setClassActive(className) {
this.classActive = className;
}
getAppropriateSchools(epalClass) {
if (epalClass === "Α' Λυκείου") {
this._rsa.getRegionSchools(1,"-1", false);
}
else if (epalClass === "Β' Λυκείου") {
this.sectorFieldsSub = this._ngRedux.select(state => {
state.sectorFields.reduce(({}, sectorField) =>{
if (sectorField.selected === true) {
this.courseActive = sectorField.id;
this._rsa.getRegionSchools(2,this.courseActive, false);
}
return sectorField;
}, {});
return state.sectorFields;
}).subscribe(this.sectorFields$);
}
else if (epalClass === "Γ' Λυκείου") {
this.sectorsSub = this._ngRedux.select(state => {
state.sectors.reduce((prevSector, sector) =>{
if (sector.sector_selected === true) {
sector.courses.reduce((prevCourse, course) =>{
if (course.selected === true) {
this.courseActive = parseInt(course.course_id);
this._rsa.getRegionSchools(3,this.courseActive, false);
}
return course;
}, {});
}
return sector;
}, {});
return state.sectors;
}).subscribe(this.sectors$);
}
}
navigateBack() {
......@@ -156,45 +214,12 @@ import {AppSettings} from '../../app.settings';
this.regionActive = ind;
}
saveSelected(cb,j) {
this._rsa.saveRegionSchoolsSelected(this.formGroup.value.formArray);
saveSelected(checked,i,j) {
this._rsa.saveRegionSchoolsSelected(checked, i, j);
}
navigateToApplication() {
//if (this.numSelected > 1)
this.router.navigate(['/schools-order-select']);
//else
// this.router.navigate(['/student-application-form-main']);
}
getCourseActive() {
const { sectors } = this._ngRedux.getState();
let l,m;
for ( l=0; l<sectors.size; l++)
if (sectors["_tail"]["array"][l]["sector_selected"] === true)
for ( m=0; m < sectors["_tail"]["array"][l]["courses"].length; m++)
if (sectors["_tail"]["array"][l]["courses"][m]["selected"] === true)
return sectors["_tail"]["array"][l]["courses"][m]["course_id"];
return "-1";
}
getClassActive() {
const { epalclasses } = this._ngRedux.getState();
let l,m;
if (epalclasses.size !== 0 && epalclasses["_tail"]["array"][0]["name"].length !==0 )
return epalclasses["_tail"]["array"][0]["name"];
return "-1";
}
getSectorActive() {
const { sectorFields } = this._ngRedux.getState();
let l,m;
for ( l=0; l<sectorFields.size; l++) {
if (sectorFields["_tail"]["array"][l]["selected"] === true) {
return sectorFields["_tail"]["array"][l]["id"];
}
}
return "-1";
}
}
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, OnDestroy } from '@angular/core';
import { Router } from '@angular/router';
import { Observable } from 'rxjs/Rx';
import { BehaviorSubject, Subscription } from 'rxjs/Rx';
import { Injectable } from "@angular/core";
import { SectorCoursesActions } from '../../actions/sectorcourses.actions';
import { ISectors } from '../../store/sectorcourses/sectorcourses.types';
import { RegionSchoolsActions } from '../../actions/regionschools.actions';
import { IRegions } from '../../store/regionschools/regionschools.types';
import { SECTOR_COURSES_INITIAL_STATE } from '../../store/sectorcourses/sectorcourses.initial-state';
import { NgRedux, select } from 'ng2-redux';
import { IAppState } from '../../store/store';
import {RemoveSpaces} from '../../pipes/removespaces';
......@@ -21,7 +20,7 @@ import {AppSettings} from '../../app.settings';
@Component({
selector: 'sectorcourses-fields-select',
template: `
<div class = "loading" *ngIf="(showLoader$ | async) && (showLoader2$ | async)">
<div class = "loading" *ngIf="(sectors$ | async).size === 0">
</div>
<form [formGroup]="formGroup">
<div formArrayName="formArray">
......@@ -47,9 +46,9 @@ import {AppSettings} from '../../app.settings';
</ul>
</div>
<div class="row" style="margin-top: 20px;" *ngIf="!(showLoader$ | async) || !(showLoader2$ | async)">
<div class="row" style="margin-top: 20px;" *ngIf="(sectors$ | async).size > 0">
<div class="col-md-6">
<button [hidden] = "objLoaderStatus == true" type="button" class="btn-primary btn-lg pull-left" (click)="router.navigate(['/epal-class-select']);" >
<button type="button" class="btn-primary btn-lg pull-left" (click)="router.navigate(['/epal-class-select']);" >
<i class="fa fa-backward"></i>
</button>
</div>
......@@ -62,11 +61,9 @@ import {AppSettings} from '../../app.settings';
</form>
`
})
@Injectable() export default class SectorCoursesSelect implements OnInit {
private sectors$: Observable<ISectors>;
private regions$: Observable<IRegions>;
private showLoader$: Observable<boolean>;
private showLoader2$: Observable<boolean>;
@Injectable() export default class SectorCoursesSelect implements OnInit, OnDestroy {
private sectors$: BehaviorSubject<ISectors>;
private sectorsSub: Subscription;
private formGroup: FormGroup;
private rss = new FormArray([]);
private sectorActive = <number>-1;
......@@ -74,35 +71,33 @@ import {AppSettings} from '../../app.settings';
private sectorsList: Array<boolean> = new Array();
constructor(private fb: FormBuilder,
private _rsa: SectorCoursesActions,
private _rsr: RegionSchoolsActions,
private _sca: SectorCoursesActions,
private _ngRedux: NgRedux<IAppState>,
private router: Router
) {
this.sectors$ = new BehaviorSubject(SECTOR_COURSES_INITIAL_STATE);
this.formGroup = this.fb.group({
formArray: this.rss
});
};
ngOnInit() {
//re-initialize schools-redux-state
this.getAllSchools();
this._rsa.getSectorCourses(true);
this._sca.getSectorCourses(false);
let ids = 0;
this.sectors$ = this._ngRedux.select(state => {
this.sectorsSub = this._ngRedux.select(state => {
state.sectors.reduce((prevSector, sector) =>{
this.sectorsList[ids] = sector.sector_selected;
ids++;
//In case we want to preserve last checked option when we revisit the form
//if (sector.sector_selected === true)
//this.sectorActive = ids-1;
if (sector.sector_selected === true)
this.sectorActive = ids-1;
sector.courses.reduce((prevCourse, course) =>{
this.rss.push( new FormControl(course.selected, []));
//this.retrieveCheck();
if (course.selected === true) {
//In case we want to preserve last checked option when we revisit the form
//this.idx = course.globalIndex;
this.idx = course.globalIndex;
}
return course;
}, {});
......@@ -110,9 +105,12 @@ import {AppSettings} from '../../app.settings';
}, {});