minister-reports.ts 4.67 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 { MINISTRY_ROLE, 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
        <h5> >Επιλογή Αναφοράς<br><br></h5>
33 34

        <div class="col-md-1">
35
          <button type="button" class="btn btn-alert"  (click)="nav_to_reportpath(1)" [hidden]="minedu_userName == '' || userRole == 'pde' || userRole == 'dide'" >
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
          </button>
          <br><br>
50 51 52 53 54
          <button type="button" class="btn btn-alert"  (click)="nav_to_reportpath(4)" [hidden]="minedu_userName == ''" >
          <i class="fa fa-file-text"></i>
              Σχολικές μονάδες που δεν έχουν δηλώσει Χωρητικότητα τμημάτων
          </button>
          <br><br>
55 56
        </div>

57 58
    </div>

59 60 61 62 63
   `
})

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

64
    public formGroup: FormGroup;
65 66 67 68 69 70
    loginInfo$: BehaviorSubject<ILoginInfo>;
    loginInfoSub: Subscription;
    private apiEndPoint = API_ENDPOINT;
    private minedu_userName: string;
    private minedu_userPassword: string;
    private distStatus = "READY";
71
    private userRole: string;
72

73
    constructor(private fb: FormBuilder,
74 75 76 77 78
        private _ngRedux: NgRedux<IAppState>,
        private _hds: HelperDataService,
        private activatedRoute: ActivatedRoute,
        private router: Router) {

79 80 81 82 83
          this.formGroup = this.fb.group({
              region: ['', []],
              adminarea: ['', []],
              schoollist: ['', []],
          });
84 85

          this.loginInfo$ = new BehaviorSubject(LOGININFO_INITIAL_STATE);
86
          this.minedu_userName = '';
87
          this.userRole = MINISTRY_ROLE;
88 89 90 91 92 93 94 95 96 97

    }

    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;
98 99 100 101
                console.log("Role:");
                console.log(loginInfoToken.auth_role);
                if (loginInfoToken.auth_role == PDE_ROLE || loginInfoToken.auth_role == DIDE_ROLE)  {
                    console.log("inside..");
102
                    this.userRole = loginInfoToken.auth_role;
103 104 105 106
                    this.minedu_userName = loginInfoToken.auth_token;
                    this.minedu_userPassword = loginInfoToken.auth_token;
                }
                return loginInfoToken;
107 108 109 110 111 112
              }, {});
          }
          return state.loginInfo;
      }).subscribe(this.loginInfo$);

    }
113

114
    ngOnDestroy() {
115

116 117
      if (this.loginInfoSub)
        this.loginInfoSub.unsubscribe();
118 119
    }

120

121
    nav_to_reportpath(repId) {
122

123 124
      if (repId == 1)
        this.router.navigate(['/ministry/report-general', repId]);
125
      else if (repId == 2 || repId == 3)
126
        this.router.navigate(['/ministry/report-all-stat', repId]);
127 128
      else if (repId == 4)
        this.router.navigate(['/ministry/report-no-capacity', repId]);
129 130 131

    }

132 133 134


}