NgRedux.select rewrite(WIP)

parent f4987505
...@@ -68,9 +68,11 @@ export default class HeaderComponent implements OnInit, OnDestroy { ...@@ -68,9 +68,11 @@ export default class HeaderComponent implements OnInit, OnDestroy {
ngOnInit() { ngOnInit() {
(<any>$("#headerNotice")).appendTo("body"); (<any>$("#headerNotice")).appendTo("body");
this.loginInfoSub = this._ngRedux.select(state => { this.loginInfoSub = this._ngRedux.select('loginInfo')
if (state.loginInfo.size > 0) { .map(loginInfo => <ILoginInfo>loginInfo)
state.loginInfo.reduce(({}, loginInfoToken) => { .subscribe(loginInfo => {
if (loginInfo.size > 0) {
loginInfo.reduce(({}, loginInfoToken) => {
this.authToken = loginInfoToken.auth_token; this.authToken = loginInfoToken.auth_token;
this.authRole = loginInfoToken.auth_role; this.authRole = loginInfoToken.auth_role;
this.cuName = loginInfoToken.cu_name; this.cuName = loginInfoToken.cu_name;
...@@ -95,8 +97,8 @@ export default class HeaderComponent implements OnInit, OnDestroy { ...@@ -95,8 +97,8 @@ export default class HeaderComponent implements OnInit, OnDestroy {
} }
return state.loginInfo; this.loginInfo$.next(loginInfo);
}).subscribe(this.loginInfo$); });
......
import {Router, ActivatedRoute, Params} from '@angular/router'; import {Router, ActivatedRoute, Params} from '@angular/router';
import {OnInit, Component} from '@angular/core'; import {OnInit, OnDestroy, Component} from '@angular/core';
import { LoginInfoActions } from '../actions/logininfo.actions'; import { LoginInfoActions } from '../actions/logininfo.actions';
import { ILoginInfo } from '../store/logininfo/logininfo.types'; import { ILoginInfo } from '../store/logininfo/logininfo.types';
import { NgRedux, select } from '@angular-redux/store'; import { NgRedux, select } from '@angular-redux/store';
import { Observable } from 'rxjs/Rx'; import { BehaviorSubject, Subscription } from 'rxjs/Rx';
import { IAppState } from '../store/store'; import { IAppState } from '../store/store';
import { HelperDataService } from '../services/helper-data-service'; import { HelperDataService } from '../services/helper-data-service';
import { CookieService } from 'ngx-cookie'; import { CookieService } from 'ngx-cookie';
import { STUDENT_ROLE } from '../constants'; import { STUDENT_ROLE } from '../constants';
import { LOGININFO_INITIAL_STATE } from "../store/logininfo/logininfo.initial-state";
import { import {
FormBuilder, FormBuilder,
FormGroup, FormGroup,
...@@ -56,15 +57,16 @@ import { API_ENDPOINT, API_ENDPOINT_PARAMS } from '../app.settings'; ...@@ -56,15 +57,16 @@ import { API_ENDPOINT, API_ENDPOINT_PARAMS } from '../app.settings';
` `
}) })
export default class Home implements OnInit { export default class Home implements OnInit, OnDestroy {
public formGroup: FormGroup; public formGroup: FormGroup;
private authToken: string; private authToken: string;
private authRole: string; private authRole: string;
private name: any; private name: any;
private xcsrftoken: any; private xcsrftoken: any;
private loginInfo$: Observable<ILoginInfo>; private loginInfo$: BehaviorSubject<ILoginInfo>;
private apiEndPoint = API_ENDPOINT; private apiEndPoint = API_ENDPOINT;
private apiEndPointParams = API_ENDPOINT_PARAMS; private apiEndPointParams = API_ENDPOINT_PARAMS;
private loginInfoSub: Subscription;
constructor(private fb: FormBuilder, constructor(private fb: FormBuilder,
private _ata: LoginInfoActions, private _ata: LoginInfoActions,
...@@ -79,13 +81,15 @@ export default class Home implements OnInit { ...@@ -79,13 +81,15 @@ export default class Home implements OnInit {
this.name = ''; this.name = '';
this.formGroup = this.fb.group({ this.formGroup = this.fb.group({
}); });
this.loginInfo$ = new BehaviorSubject(LOGININFO_INITIAL_STATE);
}; };
ngOnInit() { ngOnInit() {
this.loginInfo$ = this._ngRedux.select(state => { this.loginInfoSub = this._ngRedux.select('loginInfo').subscribe(loginInfo => {
if (state.loginInfo.size > 0) { let linfo=<ILoginInfo>loginInfo;
state.loginInfo.reduce(({}, loginInfoToken) => { if (linfo.size > 0) {
linfo.reduce(({}, loginInfoToken) => {
this.authToken = loginInfoToken.auth_token; this.authToken = loginInfoToken.auth_token;
this.authRole = loginInfoToken.auth_role; this.authRole = loginInfoToken.auth_role;
if (this.authToken && this.authToken.length > 0 && this.authRole && this.authRole === STUDENT_ROLE) { if (this.authToken && this.authToken.length > 0 && this.authRole && this.authRole === STUDENT_ROLE) {
...@@ -99,8 +103,8 @@ export default class Home implements OnInit { ...@@ -99,8 +103,8 @@ export default class Home implements OnInit {
}, {}); }, {});
} }
return state.loginInfo; this.loginInfo$.next(linfo);
}); }, error => {console.log("error selecting loginInfo");});
// subscribe to router event // subscribe to router event
this.activatedRoute.queryParams.subscribe((params: Params) => { this.activatedRoute.queryParams.subscribe((params: Params) => {
...@@ -115,6 +119,10 @@ export default class Home implements OnInit { ...@@ -115,6 +119,10 @@ export default class Home implements OnInit {
}); });
} }
ngOnDestroy () {
if (this.loginInfoSub) this.loginInfoSub.unsubscribe();
}
getCookie(key: string){ getCookie(key: string){
return this._cookieService.get(key); return this._cookieService.get(key);
} }
......
import { Router, Params} from '@angular/router'; import { Router, Params} from '@angular/router';
import { OnInit, Component} from '@angular/core'; import { OnInit, OnDestroy, Component} from '@angular/core';
import { LoginInfoActions } from '../actions/logininfo.actions'; import { LoginInfoActions } from '../actions/logininfo.actions';
import { ILoginInfo } from '../store/logininfo/logininfo.types'; import { ILoginInfo } from '../store/logininfo/logininfo.types';
import { NgRedux, select } from '@angular-redux/store'; import { NgRedux, select } from '@angular-redux/store';
import { Observable } from 'rxjs/Rx'; import { BehaviorSubject, Subscription } from 'rxjs/Rx';
import { IAppState } from '../store/store'; import { IAppState } from '../store/store';
import { HelperDataService } from '../services/helper-data-service'; import { HelperDataService } from '../services/helper-data-service';
import {Http, Response, RequestOptions} from '@angular/http'; import {Http, Response, RequestOptions} from '@angular/http';
import { LOGININFO_INITIAL_STATE } from "../store/logininfo/logininfo.initial-state";
import { import {
FormBuilder, FormBuilder,
FormGroup, FormGroup,
...@@ -57,14 +58,15 @@ import { API_ENDPOINT } from '../app.settings'; ...@@ -57,14 +58,15 @@ import { API_ENDPOINT } from '../app.settings';
` `
}) })
export default class MinistryHome implements OnInit { export default class MinistryHome implements OnInit, OnDestroy {
public userDataGroup: FormGroup; public userDataGroup: FormGroup;
private authRole: string; private authRole: string;
private mineduUsername: string; private mineduUsername: string;
//private mineduPassword: string; //private mineduPassword: string;
//private cuName: string; //private cuName: string;
private validLogin: number; private validLogin: number;
private loginInfo$: Observable<ILoginInfo>; private loginInfo$: BehaviorSubject<ILoginInfo>;
private loginInfoSub: Subscription;
private apiEndPoint = API_ENDPOINT; private apiEndPoint = API_ENDPOINT;
constructor(private fb: FormBuilder, constructor(private fb: FormBuilder,
...@@ -89,12 +91,15 @@ export default class MinistryHome implements OnInit { ...@@ -89,12 +91,15 @@ export default class MinistryHome implements OnInit {
cu_name: [''], cu_name: [''],
auth_role: [''], auth_role: [''],
}); });
this.loginInfo$ = new BehaviorSubject(LOGININFO_INITIAL_STATE);
}; };
ngOnInit() { ngOnInit() {
this.loginInfo$ = this._ngRedux.select(state => { this.loginInfoSub = this._ngRedux.select('loginInfo')
if (state.loginInfo.size > 0) { .subscribe(loginInfo => {
state.loginInfo.reduce(({}, loginInfoToken) => { let linfo = <ILoginInfo>loginInfo;
if (linfo.size > 0) {
linfo.reduce(({}, loginInfoToken) => {
this.mineduUsername = loginInfoToken.minedu_username; this.mineduUsername = loginInfoToken.minedu_username;
//this.mineduPassword = loginInfoToken.minedu_userpassword; //this.mineduPassword = loginInfoToken.minedu_userpassword;
if (this.mineduUsername && this.mineduUsername.length > 0) if (this.mineduUsername && this.mineduUsername.length > 0)
...@@ -102,9 +107,13 @@ export default class MinistryHome implements OnInit { ...@@ -102,9 +107,13 @@ export default class MinistryHome implements OnInit {
return loginInfoToken; return loginInfoToken;
}, {}); }, {});
} }
return state.loginInfo; this.loginInfo$.next(linfo);
}); }, error => {console.log("error selecting loginInfo");});
}
ngOnDestroy() {
if (this.loginInfoSub) this.loginInfoSub.unsubscribe();
} }
submitCredentials() { submitCredentials() {
......
...@@ -87,9 +87,11 @@ export default class SchoolHome implements OnInit, OnDestroy { ...@@ -87,9 +87,11 @@ export default class SchoolHome implements OnInit, OnDestroy {
}; };
ngOnInit() { ngOnInit() {
this.loginInfoSub = this._ngRedux.select(state => { this.loginInfoSub = this._ngRedux.select('loginInfo')
if (state.loginInfo.size > 0) { .subscribe(loginInfo => {
state.loginInfo.reduce(({ }, loginInfoToken) => { let linfo=<ILoginInfo>loginInfo;
if (linfo.size > 0) {
linfo.reduce(({ }, loginInfoToken) => {
this.authToken = loginInfoToken.auth_token; this.authToken = loginInfoToken.auth_token;
this.authRole = loginInfoToken.auth_role; this.authRole = loginInfoToken.auth_role;
if (this.authToken && this.authToken.length > 0) { if (this.authToken && this.authToken.length > 0) {
...@@ -105,8 +107,8 @@ export default class SchoolHome implements OnInit, OnDestroy { ...@@ -105,8 +107,8 @@ export default class SchoolHome implements OnInit, OnDestroy {
}, {}); }, {});
} }
return state.loginInfo; this.loginInfo$.next(linfo);
}).subscribe(this.loginInfo$); });
// subscribe to router event // subscribe to router event
this.activatedRoute.queryParams.subscribe((params: Params) => { this.activatedRoute.queryParams.subscribe((params: Params) => {
......
...@@ -38,7 +38,6 @@ import { StudentDataFieldsActions } from '../../actions/studentdatafields.action ...@@ -38,7 +38,6 @@ import { StudentDataFieldsActions } from '../../actions/studentdatafields.action
private authToken: string; private authToken: string;
private authRole: string; private authRole: string;
private cuName: string; private cuName: string;
private loginInfo$: BehaviorSubject<ILoginInfo>;
public cuser: any; public cuser: any;
private showLoader$: BehaviorSubject<boolean>; private showLoader$: BehaviorSubject<boolean>;
private loginInfoSub: Subscription; private loginInfoSub: Subscription;
...@@ -59,25 +58,24 @@ import { StudentDataFieldsActions } from '../../actions/studentdatafields.action ...@@ -59,25 +58,24 @@ import { StudentDataFieldsActions } from '../../actions/studentdatafields.action
}; };
ngOnInit() { ngOnInit() {
this.loginInfoSub = this._ngRedux.select(state => { this.loginInfoSub = this._ngRedux.select('loginInfo')
if (state.loginInfo.size > 0) { .subscribe(loginInfo => {
state.loginInfo.reduce(({}, loginInfoToken) => { let linfo = <ILoginInfo>loginInfo;
if (linfo.size > 0) {
linfo.reduce(({}, loginInfoToken) => {
this.authToken = loginInfoToken.auth_token; this.authToken = loginInfoToken.auth_token;
this.authRole = loginInfoToken.auth_role; this.authRole = loginInfoToken.auth_role;
this.cuName = loginInfoToken.cu_name; this.cuName = loginInfoToken.cu_name;
return loginInfoToken; return loginInfoToken;
}, {}) }, {});
}
return state.loginInfo;
}).subscribe(this.loginInfo$);
} }
}, error => {console.log("error selecting epalclasses")});
};
ngOnDestroy() { ngOnDestroy() {
if (this.loginInfoSub) if (this.loginInfoSub)
this.loginInfoSub.unsubscribe(); this.loginInfoSub.unsubscribe();
};
}
signOut() { signOut() {
this.showLoader$.next(true); this.showLoader$.next(true);
......
...@@ -32,17 +32,17 @@ import { ...@@ -32,17 +32,17 @@ import {
@Injectable() export default class StudentApplicationMain implements OnInit { @Injectable() export default class StudentApplicationMain implements OnInit {
private loginInfo$: BehaviorSubject<ILoginInfo>;
private studentDataFields$: BehaviorSubject<IStudentDataFields>; private studentDataFields$: BehaviorSubject<IStudentDataFields>;
private criteria$: BehaviorSubject<ICriter>; private criteria$: BehaviorSubject<ICriter>;
private studentDataFieldsSub: Subscription; private studentDataFieldsSub: Subscription;
private loginInfoSub: Subscription;
private criteriaSub: Subscription; private criteriaSub: Subscription;
public studentDataGroup: FormGroup; public studentDataGroup: FormGroup;
public studentCriteriaGroup: FormGroup; public studentCriteriaGroup: FormGroup;
private loginInfo$: BehaviorSubject<ILoginInfo>;
private modalTitle: BehaviorSubject<string>; private modalTitle: BehaviorSubject<string>;
private modalText: BehaviorSubject<string>; private modalText: BehaviorSubject<string>;
private modalHeader: BehaviorSubject<string>; private modalHeader: BehaviorSubject<string>;
...@@ -84,11 +84,11 @@ import { ...@@ -84,11 +84,11 @@ import {
private router: Router, private router: Router,
private http: Http) { private http: Http) {
this.populateSchoolyears(); this.populateSchoolyears();
this.loginInfo$ = new BehaviorSubject(LOGININFO_INITIAL_STATE);
this.modalTitle = new BehaviorSubject(""); this.modalTitle = new BehaviorSubject("");
this.modalText = new BehaviorSubject(""); this.modalText = new BehaviorSubject("");
this.modalHeader = new BehaviorSubject(""); this.modalHeader = new BehaviorSubject("");
this.loginInfo$ = new BehaviorSubject(LOGININFO_INITIAL_STATE);
this.studentDataFields$ = new BehaviorSubject(STUDENT_DATA_FIELDS_INITIAL_STATE); this.studentDataFields$ = new BehaviorSubject(STUDENT_DATA_FIELDS_INITIAL_STATE);
this.criteria$ = new BehaviorSubject(CRITERIA_INITIAL_STATE); this.criteria$ = new BehaviorSubject(CRITERIA_INITIAL_STATE);
this.studentDataGroup = this.fb.group({ this.studentDataGroup = this.fb.group({
...@@ -111,18 +111,16 @@ import { ...@@ -111,18 +111,16 @@ import {
ngOnInit() { ngOnInit() {
(<any>$("#applicationFormNotice")).appendTo("body"); (<any>$("#applicationFormNotice")).appendTo("body");
this._ngRedux.select(state => { this.loginInfoSub = this._ngRedux.select('loginInfo')
if (state.loginInfo.size > 0) { .subscribe(loginInfo => {
state.loginInfo.reduce(({}, loginInfoToken) => { this.loginInfo$.next(<ILoginInfo>loginInfo);
return loginInfoToken; }, error => {console.log("error selecting loginInfo");});
}, {});
}
return state.loginInfo;
}).subscribe(this.loginInfo$);
this.studentDataFieldsSub = this._ngRedux.select(state => { this.studentDataFieldsSub = this._ngRedux.select('studentDataFields')
if (state.studentDataFields.size > 0) { .subscribe(studentDataFields => {
state.studentDataFields.reduce(({}, studentDataField) => { let sdfds = <IStudentDataFields>studentDataFields;
if (sdfds.size > 0) {
sdfds.reduce(({}, studentDataField) => {
this.studentDataGroup.controls["name"].setValue(studentDataField.name); this.studentDataGroup.controls["name"].setValue(studentDataField.name);
this.studentDataGroup.controls["studentsurname"].setValue(studentDataField.studentsurname); this.studentDataGroup.controls["studentsurname"].setValue(studentDataField.studentsurname);
...@@ -140,16 +138,14 @@ import { ...@@ -140,16 +138,14 @@ import {
return studentDataField; return studentDataField;
}, {}); }, {});
} }
return state.studentDataFields; this.studentDataFields$.next(sdfds);
}).subscribe(this.studentDataFields$); }, error => {console.log("error selecting studentDataFields");});
}; };
ngOnDestroy() { ngOnDestroy() {
(<any>$("#applicationFormNotice")).remove(); (<any>$("#applicationFormNotice")).remove();
if (this.studentDataFieldsSub) this.studentDataFieldsSub.unsubscribe(); if (this.studentDataFieldsSub) this.studentDataFieldsSub.unsubscribe();
if (this.studentDataFields$) this.studentDataFields$.unsubscribe();
if (this.loginInfo$) this.loginInfo$.unsubscribe();
} }
navigateBack() { navigateBack() {
......
...@@ -66,7 +66,7 @@ import { SECTOR_FIELDS_INITIAL_STATE } from '../../store/sectorfields/sectorfiel ...@@ -66,7 +66,7 @@ import { SECTOR_FIELDS_INITIAL_STATE } from '../../store/sectorfields/sectorfiel
</ul> </ul>
</div> </div>
<ul *ngIf="(regions$ | async)" class="list-group left-side-view" style="margin-bottom: 20px;"> <ul *ngIf="(selectedSchools$ | async)" class="list-group left-side-view" style="margin-bottom: 20px;">
<div *ngFor="let epal$ of selectedSchools$ | async; let i=index; let isOdd=odd; let isEven=even" > <div *ngFor="let epal$ of selectedSchools$ | async; let i=index; let isOdd=odd; let isEven=even" >
...@@ -107,8 +107,10 @@ import { SECTOR_FIELDS_INITIAL_STATE } from '../../store/sectorfields/sectorfiel ...@@ -107,8 +107,10 @@ import { SECTOR_FIELDS_INITIAL_STATE } from '../../store/sectorfields/sectorfiel
ngOnInit() { ngOnInit() {
this.currentUrl = this.router.url; this.currentUrl = this.router.url;
this.sectorsSub = this._ngRedux.select(state => { this.sectorsSub = this._ngRedux.select('sectors')
state.sectors.reduce((prevSector, sector) => { .subscribe(sectors => {
let scs = <ISectors>sectors;
scs.reduce((prevSector, sector) => {
sector.courses.reduce((prevCourse, course) => { sector.courses.reduce((prevCourse, course) => {
if (course.selected === true) { if (course.selected === true) {
this.courseActive = course.course_id; this.courseActive = course.course_id;
...@@ -118,16 +120,17 @@ import { SECTOR_FIELDS_INITIAL_STATE } from '../../store/sectorfields/sectorfiel ...@@ -118,16 +120,17 @@ import { SECTOR_FIELDS_INITIAL_STATE } from '../../store/sectorfields/sectorfiel
}, {}); }, {});
return sector; return sector;
}, {}); }, {});
//this.numSelectedCourses = numsel; this.sectors$.next(scs);
return state.sectors; });
}).subscribe(this.sectors$);
this.regionsSub = this._ngRedux.select(state => { this.regionsSub = this._ngRedux.select('regions')
.subscribe(regions => {
let rgns = <IRegionRecords>regions;
let numsel = 0, numsel2 = 0; let numsel = 0, numsel2 = 0;
let selectedSchools = Array<IRegionSchoolRecord>(); let selectedSchools = Array<IRegionSchoolRecord>();
if (state.regions.size === 0) if (rgns.size === 0)
return; return;
state.regions.reduce((prevRegion, region) => { rgns.reduce((prevRegion, region) => {
region.get("epals").reduce((prevEpal, epal) => { region.get("epals").reduce((prevEpal, epal) => {
if (epal.get("selected") === true) { if (epal.get("selected") === true) {
numsel++; numsel++;
...@@ -143,19 +146,17 @@ import { SECTOR_FIELDS_INITIAL_STATE } from '../../store/sectorfields/sectorfiel ...@@ -143,19 +146,17 @@ import { SECTOR_FIELDS_INITIAL_STATE } from '../../store/sectorfields/sectorfiel
this.numSelectedSchools = numsel; this.numSelectedSchools = numsel;
this.numSelectedOrder = numsel2; this.numSelectedOrder = numsel2;
this.selectedSchools$.next(selectedSchools.sort(this.compareSchools)); this.selectedSchools$.next(selectedSchools.sort(this.compareSchools));
// this.selectedSchools$.next(selectedSchools); });
return state.regions;
}).subscribe(this.regions$);
this.sectorFieldsSub = this._ngRedux.select(state => { this.sectorFieldsSub = this._ngRedux.select('sectorFields')
state.sectorFields.reduce(({}, sectorField) => { .subscribe(sectorFields => {
return sectorField; this.sectorFields$.next(<ISectorFields>sectorFields);
}, {}); }, error => {console.log("error selecting sectorFields");});
return state.sectorFields;
}).subscribe(this.sectorFields$);
this.epalclassesSub = this._ngRedux.select(state => { this.epalclassesSub = this._ngRedux.select('epalclasses')
state.epalclasses.reduce(({}, epalclass) => { .subscribe(epalclasses => {
let ecs = <IEpalClasses>epalclasses;
ecs.reduce(({}, epalclass) => {
if (epalclass.name === "Α' Λυκείου") if (epalclass.name === "Α' Λυκείου")
this.classSelected = 1; this.classSelected = 1;
else if (epalclass.name === "Β' Λυκείου") else if (epalclass.name === "Β' Λυκείου")
...@@ -166,8 +167,8 @@ import { SECTOR_FIELDS_INITIAL_STATE } from '../../store/sectorfields/sectorfiel ...@@ -166,8 +167,8 @@ import { SECTOR_FIELDS_INITIAL_STATE } from '../../store/sectorfields/sectorfiel
this.classSelected = 4; this.classSelected = 4;
return epalclass; return epalclass;
}, {}); }, {});
return state.epalclasses; this.epalclasses$.next(ecs);
}).subscribe(this.epalclasses$); }, error => {console.log("error selecting epalclasses");});
} }
......
...@@ -124,8 +124,6 @@ import { HelperDataService } from "../../services/helper-data-service"; ...@@ -124,8 +124,6 @@ import { HelperDataService } from "../../services/helper-data-service";
private classSelected; private classSelected;
private totalPoints = <number>0; private totalPoints = <number>0;
private studentDataFields$: BehaviorSubject<IStudentDataFields>; private studentDataFields$: BehaviorSubject<IStudentDataFields>;
private sectors$: BehaviorSubject<ISectors>;
private sectorFields$: BehaviorSubject<ISectorFields>;
private epalclasses$: BehaviorSubject<IEpalClasses>; private epalclasses$: BehaviorSubject<IEpalClasses>;
private loginInfo$: BehaviorSubject<ILoginInfo>; private loginInfo$: BehaviorSubject<ILoginInfo>;
private studentDataFieldsSub: Subscription; private studentDataFieldsSub: Subscription;
...@@ -160,8 +158,6 @@ import { HelperDataService } from "../../services/helper-data-service"; ...@@ -160,8 +158,6 @@ import { HelperDataService } from "../../services/helper-data-service";
// 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.sectorFields$ = new BehaviorSubject(SECTOR_FIELDS_INITIAL_STATE);
this.studentDataFields$ = new BehaviorSubject(STUDENT_DATA_FIELDS_INITIAL_STATE); this.studentDataFields$ = new BehaviorSubject(STUDENT_DATA_FIELDS_INITIAL_STATE);
this.loginInfo$ = new BehaviorSubject(LOGININFO_INITIAL_STATE); this.loginInfo$ = new BehaviorSubject(LOGININFO_INITIAL_STATE);
...@@ -175,10 +171,12 @@ import { HelperDataService } from "../../services/helper-data-service"; ...@@ -175,10 +171,12 @@ import { HelperDataService } from "../../services/helper-data-service";
ngOnInit() { ngOnInit() {
(<any>$("#studentFormSentNotice")).appendTo("body"); (<any>$("#studentFormSentNotice")).appendTo("body");
this.loginInfoSub = this._ngRedux.select(state => { this.loginInfoSub = this._ngRedux.select('loginInfo')
.subscribe(loginInfo => {
let linfo = <ILoginInfo>loginInfo;
console.log("SELECTOR5"); console.log("SELECTOR5");
if (state.loginInfo.size > 0) { if (linfo.size > 0) {
state.loginInfo.reduce(({ }, loginInfoToken) => { linfo.reduce(({ }, loginInfoToken) => {
this.authToken = loginInfoToken.auth_token; this.authToken = loginInfoToken.auth_token;
this.cu_name = loginInfoToken.cu_name; this.cu_name = loginInfoToken.cu_name;
...@@ -190,23 +188,25 @@ import { HelperDataService } from "../../services/helper-data-service"; ...@@ -190,23 +188,25 @@ import { HelperDataService } from "../../services/helper-data-service";
return loginInfoToken; return loginInfoToken;
}, {}); }, {});
} }
return state.loginInfo; this.loginInfo$.next(linfo);
}).subscribe(this.loginInfo$); }, error => {console.log("error selecting loginInfo")});
this.epalclassesSub = this._ngRedux.select(state => { this.epalclassesSub = this._ngRedux.select('epalclasses').subscribe(epalclasses => {
let ecs = <IEpalClasses>epalclasses;
console.log("SELECTOR4"); console.log("SELECTOR4");
if (state.epalclasses.size > 0) { if (ecs.size > 0) {
state.epalclasses.reduce(({ }, epalclass) => { ecs.reduce(({ }, epalclass) => {
this.classSelected = epalclass.name; this.classSelected = epalclass.name;
return epalclass; return epalclass;
}, {}); }, {});
}