minister-reports.ts 4.06 KB
Newer Older
1
import { Component, OnInit, OnDestroy } from "@angular/core";
2 3 4 5 6 7 8 9 10 11 12
import { Injectable } from "@angular/core";
import { AppSettings } from '../../app.settings';
import { HelperDataService } from '../../services/helper-data-service';
import { Observable} from "rxjs/Observable";
import { Http, Headers, RequestOptions} from '@angular/http';
import { NgRedux, select } from 'ng2-redux';
import { IAppState } from '../../store/store';
import { Router, ActivatedRoute, Params} from '@angular/router';
import { BehaviorSubject, Subscription } from 'rxjs/Rx';
import { ILoginInfo } from '../../store/logininfo/logininfo.types';
import { LOGININFO_INITIAL_STATE } from '../../store/logininfo/logininfo.initial-state';
13
import { PDE_ROLE, DIDE_ROLE } from '../../constants';
14

15 16 17 18 19 20 21 22
import {
    FormBuilder,
    FormGroup,
    FormControl,
    FormArray,
    Validators,
} from '@angular/forms';

23 24 25 26
import { API_ENDPOINT } from '../../app.settings';

@Component({
    selector: 'minister-reports',
27
    //encapsulation: ViewEncapsulation.None,
28 29
    template: `

30
  <div>
31

32 33 34
        <h5><br> >Επιλογή Αναφοράς<br><br></h5>

        <div class="col-md-1">
35
          <button type="button" class="btn btn-alert"  (click)="nav_to_reportpath(1)" [hidden]="minedu_userName == ''" >
36 37 38 39
          <i class="fa fa-file-text"></i>
              Κατανομή Μαθητών με Βάση τη Σειρά Προτίμησης
          </button>
          <br><br>
40
          <button type="button" class="btn btn-alert"  (click)="nav_to_reportpath(2)" [hidden]="minedu_userName == ''" >
41
          <i class="fa fa-file-text"></i>
42
              Συνολική Πληρότητα σχολικών μονάδων ΕΠΑΛ ανά τάξη
43 44
          </button>
          <br><br>
45
          <button type="button" class="btn btn-alert"  (click)="nav_to_reportpath(3)" [hidden]="minedu_userName == ''" >
46
          <i class="fa fa-file-text"></i>
47
              Αριθμός Μαθητών και Πληρότητα σχολικών μονάδων ΕΠΑΛ
48 49 50 51
          </button>
          <br><br>
        </div>

52 53
    </div>

54 55 56 57 58
   `
})

@Injectable() export default class MinisterReports implements OnInit, OnDestroy {

59
    public formGroup: FormGroup;
60 61 62 63 64 65
    loginInfo$: BehaviorSubject<ILoginInfo>;
    loginInfoSub: Subscription;
    private apiEndPoint = API_ENDPOINT;
    private minedu_userName: string;
    private minedu_userPassword: string;
    private distStatus = "READY";
66

67
    constructor(private fb: FormBuilder,
68 69 70 71 72
        private _ngRedux: NgRedux<IAppState>,
        private _hds: HelperDataService,
        private activatedRoute: ActivatedRoute,
        private router: Router) {

73 74 75 76 77
          this.formGroup = this.fb.group({
              region: ['', []],
              adminarea: ['', []],
              schoollist: ['', []],
          });
78 79

          this.loginInfo$ = new BehaviorSubject(LOGININFO_INITIAL_STATE);
80
          this.minedu_userName = '';
81 82 83 84 85 86 87 88 89 90

    }

    ngOnInit() {

      this.loginInfoSub = this._ngRedux.select(state => {
          if (state.loginInfo.size > 0) {
              state.loginInfo.reduce(({}, loginInfoToken) => {
                this.minedu_userName = loginInfoToken.minedu_username;
                this.minedu_userPassword = loginInfoToken.minedu_userpassword;
91 92 93 94 95 96 97 98
                console.log("Role:");
                console.log(loginInfoToken.auth_role);
                if (loginInfoToken.auth_role == PDE_ROLE || loginInfoToken.auth_role == DIDE_ROLE)  {
                    console.log("inside..");
                    this.minedu_userName = loginInfoToken.auth_token;
                    this.minedu_userPassword = loginInfoToken.auth_token;
                }
                return loginInfoToken;
99 100 101 102 103 104
              }, {});
          }
          return state.loginInfo;
      }).subscribe(this.loginInfo$);

    }
105

106
    ngOnDestroy() {
107

108 109
      if (this.loginInfoSub)
        this.loginInfoSub.unsubscribe();
110 111
    }

112

113
    nav_to_reportpath(repId) {
114

115 116 117 118
      if (repId == 1)
        this.router.navigate(['/ministry/report-general', repId]);
      if (repId == 2 || repId == 3)
        this.router.navigate(['/ministry/report-all-stat', repId]);
119 120 121

    }

122 123 124


}