region.schools.select fix WIP

parent 0e8caf80
...@@ -8,7 +8,9 @@ import { IRegions } from '../../store/regionschools/regionschools.types'; ...@@ -8,7 +8,9 @@ import { IRegions } from '../../store/regionschools/regionschools.types';
import { SectorCoursesActions } from '../../actions/sectorcourses.actions'; import { SectorCoursesActions } from '../../actions/sectorcourses.actions';
import { ISectors } from '../../store/sectorcourses/sectorcourses.types'; import { ISectors } 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 { ISectorFields } from '../../store/sectorfields/sectorfields.types';
import { import {
...@@ -20,7 +22,7 @@ import { ...@@ -20,7 +22,7 @@ import {
import {AppSettings} from '../../app.settings'; import {AppSettings} from '../../app.settings';
@Component({ @Component({
selector: 'course-fields-select', selector: 'region-schools-select',
template: ` template: `
<div class = "loading" *ngIf="showLoader$ | async"> <div class = "loading" *ngIf="showLoader$ | async">
</div> </div>
...@@ -73,6 +75,7 @@ import {AppSettings} from '../../app.settings'; ...@@ -73,6 +75,7 @@ import {AppSettings} from '../../app.settings';
` `
}) })
@Injectable() export default class RegionSchoolsSelect implements OnInit { @Injectable() export default class RegionSchoolsSelect implements OnInit {
private epalclasses$: Observable<IEpalClasses>;
private regions$: Observable<IRegions>; private regions$: Observable<IRegions>;
private sectors$: Observable<ISectors>; private sectors$: Observable<ISectors>;
private showLoader$: Observable<boolean>; private showLoader$: Observable<boolean>;
...@@ -80,8 +83,9 @@ import {AppSettings} from '../../app.settings'; ...@@ -80,8 +83,9 @@ import {AppSettings} from '../../app.settings';
private rss = new FormArray([]); private rss = new FormArray([]);
private classActive = "-1"; private classActive = "-1";
private regionActive = <number>-1; private regionActive = <number>-1;
private courseActive = -1; private courseActive = <number>-1;
private numSelected = <number>0; private numSelected = <number>0;
private sectorFields$: Observable<ISectorFields>;
//private schoolArray: Array<boolean> = new Array(); //private schoolArray: Array<boolean> = new Array();
...@@ -101,24 +105,18 @@ import {AppSettings} from '../../app.settings'; ...@@ -101,24 +105,18 @@ import {AppSettings} from '../../app.settings';
}; };
ngOnInit() { ngOnInit() {
console.log("hello");
this.classActive = this.classActive = this.getClassActive(); this.epalclasses$ = this._ngRedux.select(state => {
console.log("size=" + state.epalclasses.size);
let class_id = -1; if (state.epalclasses.size > 0) {
if (this.classActive === "Α' Λυκείου") { state.epalclasses.reduce(({}, epalclass) => {
//είναι Α' Λυκείου, οπότε courseActive = "-1" (είναι ήδη ορισμένο με αυτή την τιμή από την αρχικοποίηση) this.selectAppropriateData(epalclass);
class_id = 1; return epalclass;
} }, {});
else if (this.classActive === "Β' Λυκείου") { }
class_id = 2; return state.epalclasses;
this.courseActive = this.getSectorActive(); });
} console.log("hello2");
else if (this.classActive === "Γ' Λυκείου") {
class_id = 3;
this.courseActive = this.getCourseActive();
}
this._rsa.getRegionSchools(class_id,this.courseActive, false);
this.regions$ = this._ngRedux.select(state => { this.regions$ = this._ngRedux.select(state => {
let numsel = 0; let numsel = 0;
state.regions.reduce((prevRegion, region) =>{ state.regions.reduce((prevRegion, region) =>{
...@@ -135,6 +133,43 @@ import {AppSettings} from '../../app.settings'; ...@@ -135,6 +133,43 @@ import {AppSettings} from '../../app.settings';
return state.regions; return state.regions;
}); });
this.showLoader$ = this.regions$.map(regions => regions.size === 0); this.showLoader$ = this.regions$.map(regions => regions.size === 0);
console.log("hello3");
}
selectAppropriateData(epalClass) {
if (epalClass === "Α' Λυκείου") {
this._rsa.getRegionSchools(1,"-1", false);
}
else if (epalClass === "Β' Λυκείου") {
this.sectorFields$ = 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;
});
}
else if (epalClass === "Γ' Λυκείου") {
this.sectors$ = 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;
});
}
} }
navigateBack() { navigateBack() {
......
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