after.submit.ts 4.21 KB
Newer Older
1 2 3
import {Router} from '@angular/router';
import {OnInit, OnDestroy, Component, Injectable} from '@angular/core';
import { HelperDataService } from '../../services/helper-data-service';
4
import { BehaviorSubject, Subscription } from 'rxjs/Rx';
5
import { NgRedux, select } from '@angular-redux/store';
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
import { IAppState } from '../../store/store';
import { ILoginInfo, ILoginInfoToken } from '../../store/logininfo/logininfo.types';
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 { CriteriaActions } from '../../actions/criteria.actions';
import { StudentDataFieldsActions } from '../../actions/studentdatafields.actions';

@Component({
    selector: 'post-submit',
    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">
24
                <button type="submit" class="btn-primary btn-lg btn-block isclickable" style="margin: 0px; font-size: 1em; padding: 5px; height: 8em;" (click)="submittedView()">
25
                Εμφάνιση<br />Εκτύπωση<br />Δήλωσης<br />Προτίμησης
26 27 28
                </button>
                </div>
                <div class="col-md-6">
29
                 <button type="submit" class="btn-primary btn-lg btn-block isclickable" style="margin: 0px; font-size: 1em; padding: 5px; height: 8em;" (click)="signOut()">
30 31 32 33 34 35 36 37 38 39 40 41 42
                Αποσύνδεση
                </button>
               </div>
            </div>
  `
})

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

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

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

    ngOnDestroy() {
76 77
        if (this.loginInfoSub)
            this.loginInfoSub.unsubscribe();
78
    };
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105

    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();
            this._cria.initCriteria();
            this.router.navigate(['']);
            this.authToken = '';
            this.authRole = '';
            this.showLoader$.next(false);
        }).catch(err => {
            this.showLoader$.next(false);
            console.log(err)
        });

    }

    submittedView() {
        this.router.navigate(['/submited-preview']);
    }

}