minister-reports.ts 5.73 KB
Newer Older
1
import { Component, OnInit, OnDestroy } from "@angular/core";
2
import { Injectable } from "@angular/core";
3 4
import { AppSettings } from "../../app.settings";
import { HelperDataService } from "../../services/helper-data-service";
5
import { Observable} from "rxjs/Observable";
6
import { Http, Headers, RequestOptions} from "@angular/http";
7
import { NgRedux, select } from "@angular-redux/store";
8 9 10 11 12 13
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";
import { MINISTRY_ROLE, PDE_ROLE, DIDE_ROLE } from "../../constants";
14

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

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

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

30 31 32


  <div style="min-height: 500px; ">
33

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

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

38 39 40 41 42 43 44
        <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>
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75

        <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)"  >
76 77 78 79
          <i class="fa fa-file-text"></i>
              Ολιγομελή τμήματα (Προσωρινά τοποθετημένοι μαθητές)
          </button>
          <br><br>
80
        </div>
81
      </div>
82

83 84
    </div>

85 86 87 88 89
   `
})

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

90
    public formGroup: FormGroup;
91 92 93 94 95 96
    loginInfo$: BehaviorSubject<ILoginInfo>;
    loginInfoSub: Subscription;
    private apiEndPoint = API_ENDPOINT;
    private minedu_userName: string;
    private minedu_userPassword: string;
    private distStatus = "READY";
97
    private userRole: string;
98

99
    constructor(private fb: FormBuilder,
100 101 102 103 104
        private _ngRedux: NgRedux<IAppState>,
        private _hds: HelperDataService,
        private activatedRoute: ActivatedRoute,
        private router: Router) {

105
        this.formGroup = this.fb.group({
106 107 108
            region: ["", []],
            adminarea: ["", []],
            schoollist: ["", []],
109
        });
110

111
        this.loginInfo$ = new BehaviorSubject(LOGININFO_INITIAL_STATE);
112
        this.minedu_userName = "";
113
        this.userRole = MINISTRY_ROLE;
114 115 116 117 118

    }

    ngOnInit() {

119 120 121 122 123
        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;
124
                    if (loginInfoToken.auth_role === PDE_ROLE || loginInfoToken.auth_role === DIDE_ROLE) {
125 126 127 128 129 130 131 132 133
                        this.userRole = loginInfoToken.auth_role;
                        this.minedu_userName = loginInfoToken.auth_token;
                        this.minedu_userPassword = loginInfoToken.auth_token;
                    }
                    return loginInfoToken;
                }, {});
            }
            return state.loginInfo;
        }).subscribe(this.loginInfo$);
134 135

    }
136

137
    ngOnDestroy() {
138
        if (this.loginInfoSub) {
139
            this.loginInfoSub.unsubscribe();
140 141
        }
        if (this.loginInfo$) {
142
            this.loginInfo$.unsubscribe();
143
        }
144 145
    }

146
    nav_to_reportpath(repId) {
147 148 149 150 151 152 153 154 155
        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]);
        }
156 157
    }

158
}