home.ts 5.06 KB
Newer Older
1
import {Router, ActivatedRoute, Params} from '@angular/router';
2
import {OnInit, OnDestroy, Component} from '@angular/core';
3
import { LoginInfoActions } from '../actions/logininfo.actions';
4
import { ILoginInfo } from '../store/logininfo/logininfo.types';
5
import { NgRedux, select } from '@angular-redux/store';
6
import { BehaviorSubject, Subscription } from 'rxjs/Rx';
7
import { IAppState } from '../store/store';
Open Source Developer's avatar
Open Source Developer committed
8
import { HelperDataService } from '../services/helper-data-service';
9
import { CookieService } from 'ngx-cookie';
10
import { STUDENT_ROLE } from '../constants';
11
import { LOGININFO_INITIAL_STATE } from "../store/logininfo/logininfo.initial-state";
Open Source Developer's avatar
Open Source Developer committed
12 13 14 15 16 17
import {
    FormBuilder,
    FormGroup,
    FormControl,
    FormArray
} from '@angular/forms';
18

19
import { API_ENDPOINT, API_ENDPOINT_PARAMS } from '../app.settings';
20
@Component({
21 22
    selector: 'home',
    template: `
23
  <div>
24
       <form [formGroup]="formGroup" method = "POST" action="{{apiEndPoint}}/oauth/login{{apiEndPointParams}}" #form>
Open Source Developer's avatar
Open Source Developer committed
25
<!--            <input type="hidden" name="X-oauth-enabled" value="true"> -->
26

Open Source Developer's avatar
news  
Open Source Developer committed
27 28 29 30
            <div class="bg-warning" style="padding: 2em;">
            <p>
            <strong>Ανακοίνωση:</strong> Παρακαλείσθε να μην καταχωρείτε δήλωση προτίμησης επιλέγοντας τα παρακάτω:</p>
            <ul>
31
                <li> 9ο ΕΠΑ.Λ. Πειραιά, Β τάξη, Τομέας Ναυτιλιακών Επαγγελμάτων, Γ τάξη-Ειδικότητες Πλοίαρχος Εμπορικού Ναυτικού, Μηχανικός Εμπορικού Ναυτικού
Open Source Developer's avatar
news  
Open Source Developer committed
32
                </li>
33
                <li> 1ο ΕΠΑ.Λ. Δάφνης, Γ τάξη, Ειδικότητα Βοηθός Νοσηλευτή
Open Source Developer's avatar
news  
Open Source Developer committed
34
                </li>
35
                <li> 1ο Ημερήσιο ΕΠΑ.Λ. Σιβιτανιδείου, Γ τάξη, Ειδικότητα Βοηθός Νοσηλευτή
Open Source Developer's avatar
news  
Open Source Developer committed
36 37 38 39
                </li>
             </ul>
             <p>Τα τμήματα έχουν πληρότητα από την 1η περίοδο κατανομής.
            </p>
40
            </div>
Open Source Developer's avatar
news  
Open Source Developer committed
41 42 43



Open Source Developer's avatar
news  
Open Source Developer committed
44

45 46
            <div *ngFor="let loginInfoToken$ of loginInfo$ | async; let i=index"></div>
            <div class="row" style="min-height: 300px; margin-top: 100px;">
47

48 49
            <div *ngIf="!authToken" class="col-md-8 offset-md-4">
                <button type="submit" class="btn-primary btn-lg" (click)="form.submit()">
50
                Είσοδος μέσω TaxisNet
Open Source Developer's avatar
Open Source Developer committed
51 52
                </button>
            </div>
53
            </div>
54

55
     </form>
56 57 58
  </div>
  `
})
Open Source Developer's avatar
Open Source Developer committed
59

60
export default class Home implements OnInit, OnDestroy {
61 62 63
    public formGroup: FormGroup;
    private authToken: string;
    private authRole: string;
64 65
    private name: any;
    private xcsrftoken: any;
66
    private loginInfo$: BehaviorSubject<ILoginInfo>;
67
    private apiEndPoint = API_ENDPOINT;
68
    private apiEndPointParams = API_ENDPOINT_PARAMS;
69
    private loginInfoSub: Subscription;
70

71 72 73
    constructor(private fb: FormBuilder,
        private _ata: LoginInfoActions,
        private _ngRedux: NgRedux<IAppState>,
74
        private activatedRoute: ActivatedRoute,
75
        private _hds: HelperDataService,
76 77
        private router: Router,
        private _cookieService:CookieService
78 79 80 81
    ) {
        this.authToken = '';
        this.authRole = '';
        this.name = '';
82 83
        this.formGroup = this.fb.group({
        });
84
        this.loginInfo$ = new BehaviorSubject(LOGININFO_INITIAL_STATE);
85
    };
Open Source Developer's avatar
Open Source Developer committed
86

87
    ngOnInit() {
88

89 90 91 92
        this.loginInfoSub = this._ngRedux.select('loginInfo').subscribe(loginInfo => {
            let linfo=<ILoginInfo>loginInfo;
            if (linfo.size > 0) {
                linfo.reduce(({}, loginInfoToken) => {
93 94
                    this.authToken = loginInfoToken.auth_token;
                    this.authRole = loginInfoToken.auth_role;
95 96 97 98 99 100 101
                    if (this.authToken && this.authToken.length > 0 && this.authRole && this.authRole === STUDENT_ROLE) {
                        if (loginInfoToken.lock_application === 1)
                            this.router.navigate(['/info']);
                        else {
                            this.router.navigate(['/parent-form']);
                        }
                    }
102 103 104
                    return loginInfoToken;
                }, {});
            }
105

106 107
            this.loginInfo$.next(linfo);
        }, error => {console.log("error selecting loginInfo");});
108 109

        // subscribe to router event
110
        this.activatedRoute.queryParams.subscribe((params: Params) => {
111 112 113 114
            if (params) {
                this.authToken = params['auth_token'];
                this.authRole = params['auth_role'];
            }
115

116
            if (this.authToken && this.authRole)
117
                this._ata.getloginInfo({ auth_token: this.authToken, auth_role: this.authRole });
118

119
        });
120 121
    }

122 123 124 125
    ngOnDestroy () {
        if (this.loginInfoSub) this.loginInfoSub.unsubscribe();
    }

126 127
    getCookie(key: string){
        return this._cookieService.get(key);
128
    }
129 130 131 132 133

    removeCookie(key: string){
        return this._cookieService.remove(key);
    }

134
    checkvalidation() {
Open Source Developer's avatar
Open Source Developer committed
135

136
    }
137
}