after.submit.ts 4.06 KB
Newer Older
1 2 3 4 5 6
import {Router} from "@angular/router";
import {OnInit, OnDestroy, Component, Injectable} from "@angular/core";
import { HelperDataService } from "../../services/helper-data-service";
import { BehaviorSubject, Subscription } from "rxjs/Rx";
import { NgRedux, select } from "@angular-redux/store";
import { IAppState } from "../../store/store";
7
import { ILoginInfoRecords } from "../../store/logininfo/logininfo.types";
8 9 10 11 12 13 14 15
import { LoginInfoActions } from "../../actions/logininfo.actions";
import { LOGININFO_INITIAL_STATE } from "../../store/logininfo/logininfo.initial-state";
import { SCHOOL_ROLE, STUDENT_ROLE, PDE_ROLE, DIDE_ROLE, MINISTRY_ROLE } from "../../constants";
import { EpalClassesActions } from "../../actions/epalclass.actions";
import { SectorFieldsActions } from "../../actions/sectorfields.actions";
import { RegionSchoolsActions } from "../../actions/regionschools.actions";
import { SectorCoursesActions } from "../../actions/sectorcourses.actions";
import { StudentDataFieldsActions } from "../../actions/studentdatafields.actions";
16 17

@Component({
18
    selector: "post-submit",
19 20 21 22
    template: `
        <div class = "loading" *ngIf="(showLoader$ | async) === true"></div>
           <div class="row" style="margin-top: 130px; margin-bottom: 200px;">
               <div class="col-md-3 offset-md-3">
23
                <button type="submit" class="btn-primary btn-lg btn-block isclickable" style="margin: 0px; font-size: 1em; padding: 5px; height: 8em;" (click)="submittedView()">
24
                Εμφάνιση<br />Εκτύπωση<br />Δήλωσης<br />Προτίμησης
25 26 27
                </button>
                </div>
                <div class="col-md-6">
28
                 <button type="submit" class="btn-primary btn-lg btn-block isclickable" style="margin: 0px; font-size: 1em; padding: 5px; height: 8em;" (click)="signOut()">
29 30 31 32 33 34 35 36 37 38 39
                Αποσύνδεση
                </button>
               </div>
            </div>
  `
})

@Injectable() export default class AfterSubmit implements OnInit, OnDestroy {
    private authToken: string;
    private authRole: string;
    private cuName: string;
40
    private cuser: any;
41
    private showLoader$: BehaviorSubject<boolean>;
42
    private loginInfoSub: Subscription;
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58

    constructor(
        private _ata: LoginInfoActions,
        private _hds: HelperDataService,
        private _csa: SectorCoursesActions,
        private _sfa: SectorFieldsActions,
        private _rsa: RegionSchoolsActions,
        private _eca: EpalClassesActions,
        private _sdfa: StudentDataFieldsActions,
        private _ngRedux: NgRedux<IAppState>,
        private router: Router
    ) {
        this.showLoader$ = new BehaviorSubject(false);
    };

    ngOnInit() {
59
        this.loginInfoSub = this._ngRedux.select("loginInfo")
60 61
            .map(loginInfo => <ILoginInfoRecords>loginInfo)
            .subscribe(linfo => {
62
                if (linfo.size > 0) {
63 64 65 66 67
                    linfo.reduce(({}, loginInfoObj) => {
                        this.authToken = loginInfoObj.auth_token;
                        this.authRole = loginInfoObj.auth_role;
                        this.cuName = loginInfoObj.cu_name;
                        return loginInfoObj;
68 69
                    }, {});
                }
70
            }, error => { console.log("error selecting epalclasses"); });
71
    };
72 73

    ngOnDestroy() {
74 75
        if (this.loginInfoSub)
            this.loginInfoSub.unsubscribe();
76
    };
77 78 79 80 81 82 83 84 85 86

    signOut() {
        this.showLoader$.next(true);
        this._hds.signOut().then(data => {
            this._ata.initLoginInfo();
            this._eca.initEpalClasses();
            this._sfa.initSectorFields();
            this._rsa.initRegionSchools();
            this._csa.initSectorCourses();
            this._sdfa.initStudentDataFields();
87 88 89
            this.router.navigate([""]);
            this.authToken = "";
            this.authRole = "";
90 91 92
            this.showLoader$.next(false);
        }).catch(err => {
            this.showLoader$.next(false);
93
            console.log(err);
94 95 96 97 98
        });

    }

    submittedView() {
99
        this.router.navigate(["/submited-preview"]);
100 101 102
    }

}