home.ts 4.62 KB
Newer Older
1 2 3
import {Router, ActivatedRoute, Params} from '@angular/router';
import {OnInit, Component} from '@angular/core';
import { LoginInfoActions } from '../actions/logininfo.actions';
4 5 6 7
import { ILoginInfo } from '../store/logininfo/logininfo.types';
import { NgRedux, select } from 'ng2-redux';
import { Observable } from 'rxjs/Rx';
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';
Open Source Developer's avatar
Open Source Developer committed
11 12 13 14 15 16
import {
    FormBuilder,
    FormGroup,
    FormControl,
    FormArray
} from '@angular/forms';
17

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

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



Open Source Developer's avatar
Open Source Developer committed
43

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

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

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

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

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

84
    ngOnInit() {
85

86 87 88 89 90
        this.loginInfo$ = this._ngRedux.select(state => {
            if (state.loginInfo.size > 0) {
                state.loginInfo.reduce(({}, loginInfoToken) => {
                    this.authToken = loginInfoToken.auth_token;
                    this.authRole = loginInfoToken.auth_role;
91 92 93 94 95 96 97
                    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']);
                        }
                    }
98 99 100
                    return loginInfoToken;
                }, {});
            }
101

102 103 104 105
            return state.loginInfo;
        });

        // subscribe to router event
106
        this.activatedRoute.queryParams.subscribe((params: Params) => {
107 108 109 110
            if (params) {
                this.authToken = params['auth_token'];
                this.authRole = params['auth_role'];
            }
111

112
            if (this.authToken && this.authRole)
113
                this._ata.getloginInfo({ auth_token: this.authToken, auth_role: this.authRole });
114

115
        });
116 117 118 119
    }

    getCookie(key: string){
        return this._cookieService.get(key);
120
    }
121 122 123 124 125

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

126
    checkvalidation() {
Open Source Developer's avatar
Open Source Developer committed
127

128
    }
129
}