minister-reports.ts 5.83 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
import { IAppState } from "../../store/store";
import { Router, ActivatedRoute, Params} from "@angular/router";
import { BehaviorSubject, Subscription } from "rxjs/Rx";
11
import { ILoginInfoRecords } from "../../store/logininfo/logininfo.types";
12 13
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
  <div style="min-height: 500px; ">
31

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

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

36 37 38 39 40 41 42
        <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>
43 44 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

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

81 82
    </div>

83 84 85 86 87
   `
})

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

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

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

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

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

    }

    ngOnInit() {

117
        this.loginInfoSub = this._ngRedux.select("loginInfo")
118
            .map(loginInfo => <ILoginInfoRecords>loginInfo)
119 120
            .subscribe(loginInfo => {
                if (loginInfo.size > 0) {
121 122 123 124 125 126 127
                    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;
128
                        }
129
                        return loginInfoObj;
130 131 132 133
                    }, {});
                }
                this.loginInfo$.next(loginInfo);
            }, error => console.log("error selecting loginInfo"));
134
    }
135

136
    ngOnDestroy() {
137
        if (this.loginInfoSub) {
138
            this.loginInfoSub.unsubscribe();
139
        }
140 141
    }

142
    nav_to_reportpath(repId) {
143 144 145 146 147 148 149 150 151
        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]);
        }
152 153
    }

154
}