NgRedux.select() rewrite(WIP)

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