minister-reports.ts 5.1 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
          <button type="button" class="btn btn-alert"  (click)="nav_to_reportpath(4)" [hidden]="minedu_userName == '' || userRole == 'pde' || userRole == 'dide' " >
51 52 53 54
          <i class="fa fa-file-text"></i>
              Σχολικές μονάδες που δεν έχουν δηλώσει Χωρητικότητα τμημάτων
          </button>
          <br><br>
55 56 57 58 59
          <button type="button" class="btn btn-alert"  (click)="nav_to_reportpath(5)" [hidden]="minedu_userName == '' " >
          <i class="fa fa-file-text"></i>
              Ολιγομελή τμήματα (Προσωρινά τοποθετημένοι μαθητές)
          </button>
          <br><br>
60 61
        </div>

62 63
    </div>

64 65 66 67 68
   `
})

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

69
    public formGroup: FormGroup;
70 71 72 73 74 75
    loginInfo$: BehaviorSubject<ILoginInfo>;
    loginInfoSub: Subscription;
    private apiEndPoint = API_ENDPOINT;
    private minedu_userName: string;
    private minedu_userPassword: string;
    private distStatus = "READY";
76
    private userRole: string;
77

78
    constructor(private fb: FormBuilder,
79 80 81 82 83
        private _ngRedux: NgRedux<IAppState>,
        private _hds: HelperDataService,
        private activatedRoute: ActivatedRoute,
        private router: Router) {

84 85 86 87 88
          this.formGroup = this.fb.group({
              region: ['', []],
              adminarea: ['', []],
              schoollist: ['', []],
          });
89 90

          this.loginInfo$ = new BehaviorSubject(LOGININFO_INITIAL_STATE);
91
          this.minedu_userName = '';
92
          this.userRole = MINISTRY_ROLE;
93 94 95 96 97 98 99 100 101 102

    }

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

    }
118

119
    ngOnDestroy() {
120

121 122
      if (this.loginInfoSub)
        this.loginInfoSub.unsubscribe();
123 124
        if (this.loginInfo$)
          this.loginInfo$.unsubscribe();
125 126
    }

127

128
    nav_to_reportpath(repId) {
129

130 131
      if (repId == 1)
        this.router.navigate(['/ministry/report-general', repId]);
132
      else if (repId == 2 || repId == 3 || repId == 5)
133
        this.router.navigate(['/ministry/report-all-stat', repId]);
134 135
      else if (repId == 4)
        this.router.navigate(['/ministry/report-no-capacity', repId]);
136 137 138

    }

139 140 141


}