minister-reports.ts 5.35 KB
Newer Older
1 2
import { NgRedux } from "@angular-redux/store";
import { Component, OnDestroy, OnInit } from "@angular/core";
3
import { Injectable } from "@angular/core";
4
import { ActivatedRoute, Router } from "@angular/router";
5
import { BehaviorSubject, Subscription } from "rxjs/Rx";
6

7
import { API_ENDPOINT } from "../../app.settings";
8 9 10 11 12
import { DIDE_ROLE, MINISTRY_ROLE, PDE_ROLE } from "../../constants";
import { HelperDataService } from "../../services/helper-data-service";
import { LOGININFO_INITIAL_STATE } from "../../store/logininfo/logininfo.initial-state";
import { ILoginInfoRecords } from "../../store/logininfo/logininfo.types";
import { IAppState } from "../../store/store";
13 14

@Component({
15 16
    selector: "minister-reports",
    // encapsulation: ViewEncapsulation.None,
17
    template: `
18
  <div style="min-height: 500px; ">
19
        <h5> >Επιλογή Αναφοράς<br><br></h5>
20 21

        <div class="col-md-1">
22

23 24 25 26 27 28 29
        <div *ngIf = "minedu_userName != '' && userRole != 'pde' && userRole != 'dide'">
          <button type="button" class="btn btn-alert"  (click)="nav_to_reportpath(0)"  >
          <i class="fa fa-file-text"></i>
              Αριθμός Αιτήσεων / Εγγεγραμμένων Χρηστών
          </button>
          <br><br>
        </div>
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60

        <div *ngIf = "minedu_userName != '' && userRole != 'pde' && userRole != 'dide'">
          <button type="button" class="btn btn-alert"  (click)="nav_to_reportpath(1)"  >
          <i class="fa fa-file-text"></i>
              Κατανομή Μαθητών με Βάση τη Σειρά Προτίμησης
          </button>
          <br><br>
        </div>
        <div *ngIf = "minedu_userName != ''" >
          <button type="button" class="btn btn-alert"  (click)="nav_to_reportpath(2)"  >
          <i class="fa fa-file-text"></i>
              Συνολική Πληρότητα σχολικών μονάδων ΕΠΑΛ ανά τάξη
          </button>
          <br><br>
        </div>
        <div *ngIf = "minedu_userName != ''" >
          <button type="button" class="btn btn-alert"  (click)="nav_to_reportpath(3)"  >
          <i class="fa fa-file-text"></i>
              Αριθμός Μαθητών και Πληρότητα σχολικών μονάδων ΕΠΑΛ
          </button>
          <br><br>
        </div>
        <div *ngIf = "minedu_userName != '' && userRole != 'pde' && userRole != 'dide'">
          <button type="button" class="btn btn-alert"  (click)="nav_to_reportpath(4)"  >
          <i class="fa fa-file-text"></i>
              Σχολικές μονάδες που δεν έχουν δηλώσει Χωρητικότητα τμημάτων
          </button>
          <br><br>
        </div>
        <div *ngIf = "minedu_userName != '' && userRole != 'pde' && userRole != 'dide'">
          <button type="button" class="btn btn-alert"  (click)="nav_to_reportpath(5)"  >
61 62 63 64
          <i class="fa fa-file-text"></i>
              Ολιγομελή τμήματα (Προσωρινά τοποθετημένοι μαθητές)
          </button>
          <br><br>
65
        </div>
66
      </div>
67

68 69
    </div>

70 71 72 73 74
   `
})

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

75
    private loginInfo$: BehaviorSubject<ILoginInfoRecords>;
76
    private loginInfoSub: Subscription;
77 78 79 80
    private apiEndPoint = API_ENDPOINT;
    private minedu_userName: string;
    private minedu_userPassword: string;
    private distStatus = "READY";
81
    private userRole: string;
82

83
    constructor(
84 85 86
        private _ngRedux: NgRedux<IAppState>,
        private _hds: HelperDataService,
        private activatedRoute: ActivatedRoute,
87 88
        private router: Router
    ) {
89
        this.loginInfo$ = new BehaviorSubject(LOGININFO_INITIAL_STATE);
90
        this.minedu_userName = "";
91
        this.userRole = MINISTRY_ROLE;
92 93 94 95
    }

    ngOnInit() {

96
        this.loginInfoSub = this._ngRedux.select("loginInfo")
97
            .map(loginInfo => <ILoginInfoRecords>loginInfo)
98 99
            .subscribe(loginInfo => {
                if (loginInfo.size > 0) {
100 101 102 103 104 105 106
                    loginInfo.reduce(({}, loginInfoObj) => {
                        this.minedu_userName = loginInfoObj.minedu_username;
                        this.minedu_userPassword = loginInfoObj.minedu_userpassword;
                        if (loginInfoObj.auth_role === PDE_ROLE || loginInfoObj.auth_role === DIDE_ROLE) {
                            this.userRole = loginInfoObj.auth_role;
                            this.minedu_userName = loginInfoObj.auth_token;
                            this.minedu_userPassword = loginInfoObj.auth_token;
107
                        }
108
                        return loginInfoObj;
109 110 111 112
                    }, {});
                }
                this.loginInfo$.next(loginInfo);
            }, error => console.log("error selecting loginInfo"));
113
    }
114

115
    ngOnDestroy() {
116
        if (this.loginInfoSub) {
117
            this.loginInfoSub.unsubscribe();
118
        }
119 120
    }

121
    nav_to_reportpath(repId) {
122 123 124 125 126 127 128 129 130
        if (repId === 0) {
            this.router.navigate(["/ministry/report-users", repId]);
        } else if (repId === 1) {
            this.router.navigate(["/ministry/report-general"]);
        } else if (repId === 2 || repId === 3 || repId === 5) {
            this.router.navigate(["/ministry/report-all-stat", repId]);
        } else if (repId === 4) {
            this.router.navigate(["/ministry/report-no-capacity", repId]);
        }
131 132
    }

133
}