NgRedux.select() rewrite(WIP)

parent 44065f73
...@@ -38,6 +38,7 @@ export default class HeaderComponent implements OnInit, OnDestroy { ...@@ -38,6 +38,7 @@ export default class HeaderComponent implements OnInit, OnDestroy {
private TotalStudentsSub: Subscription; private TotalStudentsSub: Subscription;
private showLoader: BehaviorSubject<boolean>; private showLoader: BehaviorSubject<boolean>;
private hasvalue: boolean; private hasvalue: boolean;
private loginInfoSub: Subscription;
constructor(private _ata: LoginInfoActions, constructor(private _ata: LoginInfoActions,
private _hds: HelperDataService, private _hds: HelperDataService,
...@@ -67,7 +68,7 @@ export default class HeaderComponent implements OnInit, OnDestroy { ...@@ -67,7 +68,7 @@ export default class HeaderComponent implements OnInit, OnDestroy {
ngOnInit() { ngOnInit() {
(<any>$("#headerNotice")).appendTo("body"); (<any>$("#headerNotice")).appendTo("body");
this._ngRedux.select(state => { this.loginInfoSub = this._ngRedux.select(state => {
if (state.loginInfo.size > 0) { if (state.loginInfo.size > 0) {
state.loginInfo.reduce(({}, loginInfoToken) => { state.loginInfo.reduce(({}, loginInfoToken) => {
this.authToken = loginInfoToken.auth_token; this.authToken = loginInfoToken.auth_token;
...@@ -104,7 +105,10 @@ export default class HeaderComponent implements OnInit, OnDestroy { ...@@ -104,7 +105,10 @@ export default class HeaderComponent implements OnInit, OnDestroy {
ngOnDestroy() { ngOnDestroy() {
(<any>$("#headerNotice")).remove(); (<any>$("#headerNotice")).remove();
this.loginInfo$.unsubscribe(); if (this.loginInfoSub) {
this.loginInfoSub.unsubscribe();
}
// this.loginInfo$.unsubscribe();
} }
......
...@@ -2,7 +2,7 @@ import {Component, OnInit, OnDestroy} from '@angular/core'; ...@@ -2,7 +2,7 @@ import {Component, OnInit, OnDestroy} from '@angular/core';
import {Router} from '@angular/router'; import {Router} from '@angular/router';
import { Injectable } from "@angular/core"; import { Injectable } from "@angular/core";
import { BehaviorSubject } from 'rxjs/Rx'; import { BehaviorSubject, Subscription } from 'rxjs/Rx';
import { NgRedux, select } from '@angular-redux/store'; import { NgRedux, select } from '@angular-redux/store';
import { IAppState } from '../../store/store'; import { IAppState } from '../../store/store';
import { ILoginInfo, ILoginInfoToken } from '../../store/logininfo/logininfo.types'; import { ILoginInfo, ILoginInfoToken } from '../../store/logininfo/logininfo.types';
...@@ -22,6 +22,7 @@ import { LOGININFO_INITIAL_STATE } from '../../store/logininfo/logininfo.initial ...@@ -22,6 +22,7 @@ import { LOGININFO_INITIAL_STATE } from '../../store/logininfo/logininfo.initial
private cuName: string; private cuName: string;
private loginInfo$: BehaviorSubject<ILoginInfo>; private loginInfo$: BehaviorSubject<ILoginInfo>;
public cuser :any; public cuser :any;
private loginInfoSub: Subscription;
constructor( private _ngRedux: NgRedux<IAppState> constructor( private _ngRedux: NgRedux<IAppState>
) { ) {
...@@ -36,7 +37,7 @@ import { LOGININFO_INITIAL_STATE } from '../../store/logininfo/logininfo.initial ...@@ -36,7 +37,7 @@ import { LOGININFO_INITIAL_STATE } from '../../store/logininfo/logininfo.initial
}; };
ngOnInit() { ngOnInit() {
this._ngRedux.select(state => { this.loginInfoSub = this._ngRedux.select(state => {
if (state.loginInfo.size > 0) { if (state.loginInfo.size > 0) {
state.loginInfo.reduce(({}, loginInfoToken) => { state.loginInfo.reduce(({}, loginInfoToken) => {
this.authToken = loginInfoToken.auth_token; this.authToken = loginInfoToken.auth_token;
...@@ -60,7 +61,8 @@ import { LOGININFO_INITIAL_STATE } from '../../store/logininfo/logininfo.initial ...@@ -60,7 +61,8 @@ import { LOGININFO_INITIAL_STATE } from '../../store/logininfo/logininfo.initial
} }
ngOnDestroy() { ngOnDestroy() {
this.loginInfo$.unsubscribe(); if (this.loginInfoSub)
this.loginInfoSub.unsubscribe();
} }
......
import {Router} from '@angular/router'; import {Router} from '@angular/router';
import {OnInit, OnDestroy, Component, Injectable} from '@angular/core'; import {OnInit, OnDestroy, Component, Injectable} from '@angular/core';
import { HelperDataService } from '../../services/helper-data-service'; import { HelperDataService } from '../../services/helper-data-service';
import { BehaviorSubject } from 'rxjs/Rx'; import { BehaviorSubject, Subscription } from 'rxjs/Rx';
import { NgRedux, select } from '@angular-redux/store'; import { NgRedux, select } from '@angular-redux/store';
import { IAppState } from '../../store/store'; import { IAppState } from '../../store/store';
import { ILoginInfo, ILoginInfoToken } from '../../store/logininfo/logininfo.types'; import { ILoginInfo, ILoginInfoToken } from '../../store/logininfo/logininfo.types';
...@@ -41,6 +41,7 @@ import { StudentDataFieldsActions } from '../../actions/studentdatafields.action ...@@ -41,6 +41,7 @@ import { StudentDataFieldsActions } from '../../actions/studentdatafields.action
private loginInfo$: BehaviorSubject<ILoginInfo>; private loginInfo$: BehaviorSubject<ILoginInfo>;
public cuser: any; public cuser: any;
private showLoader$: BehaviorSubject<boolean>; private showLoader$: BehaviorSubject<boolean>;
private loginInfoSub: Subscription;
constructor( constructor(
private _ata: LoginInfoActions, private _ata: LoginInfoActions,
...@@ -58,7 +59,7 @@ import { StudentDataFieldsActions } from '../../actions/studentdatafields.action ...@@ -58,7 +59,7 @@ import { StudentDataFieldsActions } from '../../actions/studentdatafields.action
}; };
ngOnInit() { ngOnInit() {
this._ngRedux.select(state => { this.loginInfoSub = this._ngRedux.select(state => {
if (state.loginInfo.size > 0) { if (state.loginInfo.size > 0) {
state.loginInfo.reduce(({}, loginInfoToken) => { state.loginInfo.reduce(({}, loginInfoToken) => {
this.authToken = loginInfoToken.auth_token; this.authToken = loginInfoToken.auth_token;
...@@ -73,8 +74,8 @@ import { StudentDataFieldsActions } from '../../actions/studentdatafields.action ...@@ -73,8 +74,8 @@ import { StudentDataFieldsActions } from '../../actions/studentdatafields.action
} }
ngOnDestroy() { ngOnDestroy() {
if (this.loginInfo$) if (this.loginInfoSub)
this.loginInfo$.unsubscribe(); this.loginInfoSub.unsubscribe();
} }
......
...@@ -29,7 +29,7 @@ import { HelperDataService } from "../../services/helper-data-service"; ...@@ -29,7 +29,7 @@ import { HelperDataService } from "../../services/helper-data-service";
@Component({ @Component({
selector: "application-submit", selector: "application-submit",
template: ` template: `
<div class = "loading" *ngIf="(studentDataFields$ | async).size === 0 || (regions$ | async).size === 0 || (epalclasses$ | async).size === 0 || (loginInfo$ | async).size === 0 || (showLoader | async) === true"></div> <div class = "loading" *ngIf="(studentDataFields$ | async).size === 0 || (epalSelected$ | async).length === 0 || (epalclasses$ | async).size === 0 || (loginInfo$ | async).size === 0 || (showLoader | async) === true"></div>
<div id="studentFormSentNotice" (onHidden)="onHidden()" class="modal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static" data-keyboard="false"> <div id="studentFormSentNotice" (onHidden)="onHidden()" class="modal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog modal-lg"> <div class="modal-dialog modal-lg">
<div class="modal-content"> <div class="modal-content">
...@@ -117,14 +117,13 @@ import { HelperDataService } from "../../services/helper-data-service"; ...@@ -117,14 +117,13 @@ import { HelperDataService } from "../../services/helper-data-service";
@Injectable() export default class ApplicationSubmit implements OnInit { @Injectable() export default class ApplicationSubmit implements OnInit {
private authToken; private authToken;
private epalSelected: Array<number> = new Array(); private epalSelected$: BehaviorSubject<Array<number>> = new BehaviorSubject(new Array());
private epalSelectedOrder: Array<number> = new Array(); private epalSelectedOrder: Array<number> = new Array();
private courseSelected; private courseSelected;
private sectorSelected; private sectorSelected;
private classSelected; private classSelected;
private totalPoints = <number>0; private totalPoints = <number>0;
private studentDataFields$: BehaviorSubject<IStudentDataFields>; private studentDataFields$: BehaviorSubject<IStudentDataFields>;
private regions$: BehaviorSubject<IRegionRecords>;
private sectors$: BehaviorSubject<ISectors>; private sectors$: BehaviorSubject<ISectors>;
private sectorFields$: BehaviorSubject<ISectorFields>; private sectorFields$: BehaviorSubject<ISectorFields>;
private epalclasses$: BehaviorSubject<IEpalClasses>; private epalclasses$: BehaviorSubject<IEpalClasses>;
...@@ -159,7 +158,7 @@ import { HelperDataService } from "../../services/helper-data-service"; ...@@ -159,7 +158,7 @@ import { HelperDataService } from "../../services/helper-data-service";
private http: Http private http: Http
) { ) {
this.regions$ = new BehaviorSubject(REGION_SCHOOLS_INITIAL_STATE); // this.regions$ = new BehaviorSubject(REGION_SCHOOLS_INITIAL_STATE);
this.epalclasses$ = new BehaviorSubject(EPALCLASSES_INITIAL_STATE); this.epalclasses$ = new BehaviorSubject(EPALCLASSES_INITIAL_STATE);
this.sectors$ = new BehaviorSubject(SECTOR_COURSES_INITIAL_STATE); this.sectors$ = new BehaviorSubject(SECTOR_COURSES_INITIAL_STATE);
this.sectorFields$ = new BehaviorSubject(SECTOR_FIELDS_INITIAL_STATE); this.sectorFields$ = new BehaviorSubject(SECTOR_FIELDS_INITIAL_STATE);
...@@ -209,7 +208,7 @@ import { HelperDataService } from "../../services/helper-data-service"; ...@@ -209,7 +208,7 @@ import { HelperDataService } from "../../services/helper-data-service";
return state.studentDataFields; return state.studentDataFields;
}).subscribe(this.studentDataFields$); }).subscribe(this.studentDataFields$);
this.regionsSub = this._ngRedux.select(state => { /* this.regionsSub = this._ngRedux.select((state) => {
console.log("SELECTOR3"); console.log("SELECTOR3");
state.regions.reduce((prevRegion, region) => { state.regions.reduce((prevRegion, region) => {
region.epals.reduce((prevEpal, epal) => { region.epals.reduce((prevEpal, epal) => {
...@@ -222,7 +221,34 @@ import { HelperDataService } from "../../services/helper-data-service"; ...@@ -222,7 +221,34 @@ import { HelperDataService } from "../../services/helper-data-service";
return region; return region;
}, {}); }, {});
return state.regions; return state.regions;
}).subscribe(this.regions$); }).subscribe(this.regions$); */
this.regionsSub = this._ngRedux.select('regions').
subscribe(regions => {
console.log("SELECTOR: REGIONS");
let rgns = <IRegionRecords>regions;
let prevSelected: Array<number> = new Array();
rgns.reduce((prevRgn, rgn) => {
rgn.epals.reduce((prevSchool, school) => {
if (school.selected === true) {
prevSelected = this.epalSelected$.getValue();
prevSelected[prevSelected.length] = <number>parseInt(school.epal_id);
this.epalSelected$.next(prevSelected);
this.epalSelectedOrder.push(school.order_id);
}
return school;
}, {});
return rgn;
}, {});
// this.regions$.next(<IRegionRecords>regions);
},
error => {
console.log("Error Selecting Regions");
}
);
this.sectorsSub = this._ngRedux.select(state => { this.sectorsSub = this._ngRedux.select(state => {
console.log("SELECTOR2"); console.log("SELECTOR2");
...@@ -283,7 +309,7 @@ import { HelperDataService } from "../../services/helper-data-service"; ...@@ -283,7 +309,7 @@ import { HelperDataService } from "../../services/helper-data-service";
// αποστολή στοιχείων μαθητή στο entity: epal_student // αποστολή στοιχείων μαθητή στο entity: epal_student
// let aitisiObj: Array<Student | StudentEpalChosen[] | StudentCriteriaChosen[] | StudentCourseChosen | StudentSectorChosen > = []; // let aitisiObj: Array<Student | StudentEpalChosen[] | StudentCriteriaChosen[] | StudentCourseChosen | StudentSectorChosen > = [];
if (this.studentDataFields$.getValue().size === 0 || this.regions$.getValue().size === 0 || this.epalclasses$.getValue().size === 0 || this.loginInfo$.getValue().size === 0) if (this.studentDataFields$.getValue().size === 0 || this.epalSelected$.getValue().length === 0 || this.epalclasses$.getValue().size === 0 || this.loginInfo$.getValue().size === 0)
return; return;
let aitisiObj: Array<any> = []; let aitisiObj: Array<any> = [];
...@@ -319,8 +345,9 @@ import { HelperDataService } from "../../services/helper-data-service"; ...@@ -319,8 +345,9 @@ import { HelperDataService } from "../../services/helper-data-service";
aitisiObj[0].disclaimer_checked = this.disclaimer_checked; aitisiObj[0].disclaimer_checked = this.disclaimer_checked;
aitisiObj[0].currentclass = this.classSelected; aitisiObj[0].currentclass = this.classSelected;
for (let i = 0; i < this.epalSelected.length; i++) { let epalSelected = this.epalSelected$.getValue();
epalObj[i] = new StudentEpalChosen(null, this.epalSelected[i], this.epalSelectedOrder[i]); for (let i = 0; i < epalSelected.length; i++) {
epalObj[i] = new StudentEpalChosen(null, epalSelected[i], this.epalSelectedOrder[i]);
} }
aitisiObj["1"] = epalObj; aitisiObj["1"] = epalObj;
......
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