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 { 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';
}, {});
ids = 0;
return state.sectors;
});
this.showLoader$ = this.sectors$.map(sectors => sectors.size === 0);
}).subscribe(this.sectors$);
}
ngOnDestroy() {
if (this.sectorsSub) this.sectorsSub.unsubscribe();
}
setActiveSector(ind) {
......@@ -122,7 +120,7 @@ import {AppSettings} from '../../app.settings';
}
saveSelected() {
this._rsa.saveSectorCoursesSelected(this.formGroup.value.formArray, this.sectorsList);
this._sca.saveSectorCoursesSelected(this.formGroup.value.formArray, this.sectorsList);
}
navigateToSchools() {
......@@ -142,25 +140,6 @@ import {AppSettings} from '../../app.settings';
this.sectorsList[this.sectorActive] = true;
this.saveSelected();
}
getAllSchools() {
//store in Redux the whole schools
this._rsr.getRegionSchools(3,"-1", true);
this.regions$ = this._ngRedux.select(state => {
let numsel = 0;
state.regions.reduce((prevRegion, region) =>{
region.epals.reduce((prevEpal, epal) =>{
this.rss.push( new FormControl(epal.selected, []));
return epal;
}, {});
return region;
}, {});
return state.regions;
});
this.showLoader2$ = this.regions$.map(regions => regions.size === 0);
}
}
}
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 { SectorFieldsActions } from '../../actions/sectorfields.actions';
import { NgRedux, select } from 'ng2-redux';
import { ISectorFields } from '../../store/sectorfields/sectorfields.types';
import { IAppState } from '../../store/store';
import { RegionSchoolsActions } from '../../actions/regionschools.actions';
import { IRegions } from '../../store/regionschools/regionschools.types';
import { SECTOR_FIELDS_INITIAL_STATE } from '../../store/sectorfields/sectorfields.initial-state';
import {
FormBuilder,
......@@ -20,11 +19,7 @@ import {AppSettings} from '../../app.settings';
@Component({
selector: 'sector-fields-select',
template: `
<!-- <div class="row equal">
<div class="col-md-12"> -->
<div class = "loading" *ngIf="(showLoader$ | async) && (showLoader2$ | async)">
<div class = "loading" *ngIf="(sectorFields$ | async).size === 0">
</div>
<form [formGroup]="formGroup">
<div formArrayName="formArray">
......@@ -36,83 +31,63 @@ import {AppSettings} from '../../app.settings';
</div>
</ul>
<!--CHECK BOXES USING BOTSTRAP
<div *ngFor="let sectorField$ of sectorFields$ | async; let i=index">
<div class="[ form-group ]">
<input type="checkbox" name="{{i}}" id="{{i}}" autocomplete="off" />
<div class="[ btn-group ]">
<label for="{{i}}" class="[ btn btn-primary ]">
<span class="[ glyphicon glyphicon-ok ]"></span>
<span> </span>
</label>
<label for="{{i}}" class="[ btn btn-default active ]">
{{sectorField$.name}}
</label>
</div>
</div>
</div>
-->
</div>
<div class="row" style="margin-top: 20px;" *ngIf="!(showLoader$ | async) || !(showLoader2$ | async)">
<div class="row" style="margin-top: 20px;" *ngIf="(sectorFields$ | 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>
<div class="col-md-6">
<button [hidden] = "objLoaderStatus == true" type="button" class="btn-primary btn-lg pull-right" (click)="navigateToSchools()" [disabled]="sectorActive === -1" >
<button type="button" class="btn-primary btn-lg pull-right" (click)="navigateToSchools()" [disabled]="sectorActive === -1" >
<i class="fa fa-forward"></i>
</button>
</div>
</div>
</form>
<!-- </div>
</div> -->
`
})
@Injectable() export default class SectorFieldsSelect implements OnInit {
private sectorFields$: Observable<ISectorFields>;
private regions$: Observable<IRegions>;
private showLoader$: Observable<boolean>;
private showLoader2$: Observable<boolean>;
private sectorFields$: BehaviorSubject<ISectorFields>;
private sectorFieldsSub: Subscription;
public formGroup: FormGroup;
public cfs = new FormArray([]);
private sectorActive = <number>-1;
constructor(private fb: FormBuilder,
private _cfa: SectorFieldsActions,
private _rsr: RegionSchoolsActions,
private _ngRedux: NgRedux<IAppState>,
private router: Router) {
this.sectorFields$ = new BehaviorSubject(SECTOR_FIELDS_INITIAL_STATE);
this.formGroup = this.fb.group({
formArray: this.cfs
});
};
ngOnInit() {
//re-initialize schools-redux-state
this.getAllSchools();
this._cfa.getSectorFields(true);
this.sectorFields$ = this._ngRedux.select(state => {
this._cfa.getSectorFields(false);
this.sectorFieldsSub = this._ngRedux.select(state => {
state.sectorFields.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;
}
*/
return sectorField;
}, {});
return state.sectorFields;
});
this.showLoader$ = this.sectorFields$.map(sectorFields => sectorFields.size === 0);
}).subscribe(this.sectorFields$);
}
ngOnDestroy() {
if (this.sectorFieldsSub) this.sectorFieldsSub.unsubscribe();
}
navigateToSchools() {
......@@ -136,22 +111,4 @@ import {AppSettings} from '../../app.settings';
this.saveSelected();
}
getAllSchools() {
//store in Redux the whole schools
this._rsr.getRegionSchools(3,"-1", true);
this.regions$ = this._ngRedux.select(state => {
let numsel = 0;
state.regions.reduce((prevRegion, region) =>{
region.epals.reduce((prevEpal, epal) =>{
this.cfs.push( new FormControl(epal.selected, []));
return epal;
}, {});
return region;
}, {});
return state.regions;
});
this.showLoader2$ = this.regions$.map(regions => regions.size === 0);
}
}
......@@ -28,13 +28,11 @@ export class HelperDataService {
if (state.loginInfo.size > 0) {
state.loginInfo.reduce(({}, loginInfoToken) => {
this.authToken = loginInfoToken.auth_token;
console.log('hey authtoken:' + this.authToken );
return loginInfoToken;
}, {});
}
return state.loginInfo;
});
console.log('hey hey authtoken:' + this.authToken);
};
......@@ -45,7 +43,6 @@ export class HelperDataService {
getCourseFields() {
this.loginInfo$.forEach(loginInfoToken => {
console.log(loginInfoToken.get(0));
this.authToken = loginInfoToken.get(0).auth_token;
});
let headers = new Headers({
......@@ -78,7 +75,6 @@ export class HelperDataService {
getSectorFields() {
this.loginInfo$.forEach(loginInfoToken => {
console.log(loginInfoToken.get(0));
this.authToken = loginInfoToken.get(0).auth_token;
});
let headers = new Headers({
......@@ -110,7 +106,6 @@ export class HelperDataService {
getRegionsWithSchools(classActive,courseActive) {
this.loginInfo$.forEach(loginInfoToken => {
console.log(loginInfoToken.get(0));
this.authToken = loginInfoToken.get(0).auth_token;
});
let headers = new Headers({
......@@ -137,11 +132,6 @@ export class HelperDataService {
else if (classActive === 3)
getConnectionString = `${AppSettings.API_ENDPOINT}/coursesperschool/list?course_id=${courseActive}`;
//getConnectionString = `${AppSettings.API_ENDPOINT}/coursesperschool/list?${courseActive}`;
// console.log(getConnectionString,class);
//this.http.get(`${AppSettings.API_ENDPOINT}/regions/list`)
//this.http.get(`${AppSettings.API_ENDPOINT}/`.concat(`coursesperschool/list?course_id=${courseActive}`))
this.http.get(getConnectionString, options)
.map(response => response.json())
.subscribe(data => {
......@@ -157,7 +147,6 @@ export class HelperDataService {
getSectorsWithCourses() {
this.loginInfo$.forEach(loginInfoToken => {
console.log(loginInfoToken.get(0));
this.authToken = loginInfoToken.get(0).auth_token;
});
let headers = new Headers({
......@@ -177,7 +166,6 @@ export class HelperDataService {
this.http.get(`${AppSettings.API_ENDPOINT}/coursesectorfields/list`, options)
.map(response => response.json())
.subscribe(data => {
// console.log(data);
resolve(this.transformSectorCoursesSchema(data));
}, // put the data returned from the server in our variable
error => {
......@@ -296,7 +284,6 @@ transformUserSchema(userlogin:any,oauthtoken:string, oauthrole:string){
signOut() {
this.loginInfo$.forEach(loginInfoToken => {
console.log(loginInfoToken.get(0));
this.authToken = loginInfoToken.get(0).auth_token;
});
let headers = new Headers({
......@@ -321,7 +308,6 @@ transformUserSchema(userlogin:any,oauthtoken:string, oauthrole:string){
.map(response => response)
.subscribe(data => {
resolve(data);
console.log(data);
}, // put the data returned from the server in our variable
error => {
console.log("Error Logout"); // in case of failure show this message
......
......@@ -2,6 +2,4 @@ import { List } from 'immutable';
import { IEpalClass} from './epalclasses.types';
export const INITIAL_STATE = List<IEpalClass>();
export const EPALCLASSES_INITIAL_STATE = List<IEpalClass>();
import { IEpalClasses, IEpalClass } from './epalclasses.types';
import { INITIAL_STATE } from './epalclasses.initial-state';