home.ts 3.75 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
commit  
Open Source Developer committed
8 9 10 11 12 13
import {
    FormBuilder,
    FormGroup,
    FormControl,
    FormArray
} from '@angular/forms';
14 15

import { API_ENDPOINT } from '../app.settings';
16
@Component({
17 18
    selector: 'home',
    template: `
19
  <div>
Open Source Developer's avatar
Open Source Developer committed
20
           <input type="hidden" name="X-oauth-enabled" value="true"> -->
21 22

            <div *ngFor="let loginInfoToken$ of loginInfo$ | async; let i=index"></div>
Open Source Developer's avatar
Open Source Developer committed
23
               <div class="row">
24 25 26 27 28 29 30
                    <div class="col-md-6">
                        {{loginInfoToken$.auth_token}}
                    </div>
                    <div class="col-md-6">
                        {{loginInfoToken$.auth_role}}
                    </div>
                </div>
31 32
            </div> -->
            <div class="row" style="min-height: 300px; margin-top: 100px;">
33

34 35
            <div *ngIf="!authToken" class="col-md-8 offset-md-4">
                <button type="submit" class="btn-primary btn-lg" (click)="form.submit()">
36
                Είσοδος μέσω TaxisNet<span class="glyphicon glyphicon-menu-right"></span>
Open Source Developer's avatar
commit  
Open Source Developer committed
37 38
                </button>
            </div>
39
            </div>
40
            <!--
41 42 43 44 45 46 47 48 49 50 51 52 53
            <div class="row">
            <div *ngIf="authToken" class="col-md-7 col-md-offset-5">
                <h3>Καλώς ήρθατε</h3>
            </div>
            </div>
            <div class="row">
            <div *ngIf="authToken" class="col-md-7 col-md-offset-5">
                <input type="hidden" name="dologout" value="true">
                <button type="submit" class="btn-primary btn-lg pull-center" (click)="form.submit()">
                Αποσύνδεση<span class="glyphicon glyphicon-menu-right"></span>
                </button>
            </div>
            </div>
54
            -->
55
     </form>
56 57 58
  </div>
  `
})
59 60 61 62 63
export default class Home implements OnInit {
    public formGroup: FormGroup;
    private authToken: string;
    private authRole: string;
    private loginInfo$: Observable<ILoginInfo>;
64 65
    private apiEndPoint = API_ENDPOINT;

66 67 68
    constructor(private fb: FormBuilder,
        private _ata: LoginInfoActions,
        private _ngRedux: NgRedux<IAppState>,
69 70
        private activatedRoute: ActivatedRoute,
        private router: Router
71 72 73 74
        ) {
            this.authToken = '';
            this.authRole = '';
        this.formGroup = this.fb.group({
75 76
//            Username: [],
//            Paswd: []
77 78
        });
    };
Open Source Developer's avatar
commit  
Open Source Developer committed
79

80
    ngOnInit() {
81 82 83 84 85
        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;
86 87
                    if (this.authToken && this.authToken.length > 0)
                        this.router.navigate(['/epal-class-select']);
88 89 90
                    return loginInfoToken;
                }, {});
            }
91

92 93 94 95
            return state.loginInfo;
        });

        // subscribe to router event
96
        this.activatedRoute.queryParams.subscribe((params: Params) => {
97 98 99 100
            if (params) {
                this.authToken = params['auth_token'];
                this.authRole = params['auth_role'];
            }
101 102 103
            if (this.authToken && this.authRole)
            this._ata.saveLoginInfo({ auth_token: this.authToken, auth_role: this.authRole });
    //        console.log(this.authToken);
104

105 106
        });
    }
107 108


Open Source Developer's avatar
commit  
Open Source Developer committed
109

110
    checkvalidation() {
Open Source Developer's avatar
commit  
Open Source Developer committed
111

112
    }
113
}