minister-settings.ts 10 KB
Newer Older
1 2
import { Component, OnInit, OnDestroy, ElementRef, ViewChild} from "@angular/core";
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 7 8 9 10
import { Http, Headers, RequestOptions} from "@angular/http";
import { NgRedux, select } from "@angular-redux/store";
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
import { LOGININFO_INITIAL_STATE } from "../../store/logininfo/logininfo.initial-state";
13 14 15 16 17 18 19 20


import {
    FormBuilder,
    FormGroup,
    FormControl,
    FormArray,
    Validators,
21
} from "@angular/forms";
22 23 24


@Component({
25
    selector: "minister-settings",
26 27 28 29 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
    template: `

    <div
      class = "loading" *ngIf="dataRetrieved == -1 " >
    </div>

    <div id="configNotice" (onHidden)="onHidden()" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
      <div class="modal-dialog modal-lg">
        <div class="modal-content">
          <div class="modal-header {{modalHeader | async}}" >
              <h3 class="modal-title pull-left"><i class="fa fa-check-square-o"></i>&nbsp;&nbsp;{{ modalTitle | async }}</h3>
            <button type="button" class="close pull-right" aria-label="Close" (click)="hideModal()">
              <span aria-hidden="true"><i class="fa fa-times"></i></span>
            </button>
          </div>
          <div class="modal-body">
              <p>{{ modalText | async }}</p>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default pull-left" data-dismiss="modal">Κλείσιμο</button>
          </div>
        </div>
      </div>
    </div>

    <div *ngIf="(loginInfo$ | async).size !== 0">

        <form [formGroup]="formGroup"  #form>
          <h5> >Ρυθμίσεις <br><br></h5>
          <div class="row">
            <div class="col-md-1 ">
              <input type="checkbox" [checked]="capacityDisabled"  formControlName="capacityDisabled"
              (click)="toggleCapacityFilter()" >
            </div>
            <div class="col-md-9">
              <label for="capacityDisabled">Απενεργοποίηση δυνατότητας τροποποίησης χωρητικότητας από τους Διευθυντές σχολείων</label>
            </div>
          </div>
          <br>

          <div class="row">
            <div class="col-md-1 ">
              <input type="checkbox" [checked]="directorViewDisabled" formControlName="directorViewDisabled"
              (click)="toggleDirectorView()" >
            </div>
            <div class="col-md-9">
              <label for="directorViewDisabled">Απενεργοποίηση δυνατότητας προβολής κατανομής μαθητών από τους Διευθυντές σχολείων</label>
            </div>
          </div>
          <br>

          <div class="row">
            <div class="col-md-1 ">
              <input type="checkbox" [checked]="applicantsLoginDisabled" formControlName="applicantsLoginDisabled"
              (click)="toggleApplicantsLogin()" >
            </div>
            <div class="col-md-9">
83
              <label for="applicantsLoginDisabled">Απενεργοποίηση δυνατότητας υποβολής δήλωσης προτίμησης ΕΠΑΛ</label>
84 85 86 87
            </div>
          </div>
          <br>

88 89 90 91 92 93 94 95 96 97 98
          <div class="row">
            <div class="col-md-1 ">
              <input type="checkbox" [checked]="applicantsResultsDisabled" formControlName="applicantsResultsDisabled"
              (click)="toggleApplicantsResults()" >
            </div>
            <div class="col-md-9">
              <label for="applicantsResultsDisabled">Απενεργοποίηση δυνατότητας προβολής αποτελεσμάτων κατανομής από τους μαθητές </label>
            </div>
          </div>
          <br>

99 100 101 102 103 104 105 106 107 108 109
          <div class="row">
            <div class="col-md-1 ">
              <input type="checkbox" [checked]="secondPeriodEnabled" formControlName="secondPeriodEnabled"
              (click)="toggleSecondPeriod()" >
            </div>
            <div class="col-md-9">
              <label for="secondPeriodEnabled">Ενεργοποίηση δεύτερης περιόδου αιτήσεων </label>
            </div>
          </div>
          <br>

110 111 112 113 114 115 116 117 118 119 120 121 122
          <button type="submit" class="btn btn-md pull-right"  (click)="storeSettings()" >
              Εφαρμογή
          </button>

        </form>

      </div>

   `
})

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

123
    private formGroup: FormGroup;
124
    private loginInfo$: BehaviorSubject<ILoginInfoRecords>;
125 126 127 128
    private modalTitle: BehaviorSubject<string>;
    private modalText: BehaviorSubject<string>;
    private modalHeader: BehaviorSubject<string>;
    private settings$: BehaviorSubject<any>;
129
    private loginInfoSub: Subscription;
130 131 132 133 134
    private settingsSub: Subscription;

    private capacityDisabled: boolean;
    private directorViewDisabled: boolean;
    private applicantsLoginDisabled: boolean;
135
    private applicantsResultsDisabled: boolean;
136
    private secondPeriodEnabled: boolean;
137 138 139 140 141 142 143 144 145 146
    private dataRetrieved: number;

    private minedu_userName: string;
    private minedu_userPassword: string;

    constructor(private fb: FormBuilder,
        private _ngRedux: NgRedux<IAppState>,
        private _hds: HelperDataService,
        private router: Router) {

147
        this.formGroup = this.fb.group({
148 149 150 151 152
            capacityDisabled: ["", []],
            directorViewDisabled: ["", []],
            applicantsLoginDisabled: ["", []],
            applicantsResultsDisabled: ["", []],
            secondPeriodEnabled: ["", []],
153 154 155 156 157 158 159
        });

        this.loginInfo$ = new BehaviorSubject(LOGININFO_INITIAL_STATE);
        this.settings$ = new BehaviorSubject([{}]);
        this.modalTitle = new BehaviorSubject("");
        this.modalText = new BehaviorSubject("");
        this.modalHeader = new BehaviorSubject("");
160 161 162

    }

163
    public showModal(): void {
164
        (<any>$("#configNotice")).modal("show");
165 166
    }

167
    public hideModal(): void {
168
        (<any>$("#configNotice")).modal("hide");
169 170
    }

171
    public onHidden(): void {
172
        // this.isModalShown.next(false);
173 174 175 176 177
    }


    ngOnDestroy() {

178
        (<any>$("#configNotice")).remove();
179

180 181 182 183
        if (this.loginInfoSub)
            this.loginInfoSub.unsubscribe();
        if (this.settingsSub)
            this.settingsSub.unsubscribe();
184 185 186 187
    }

    ngOnInit() {

188 189 190
        (<any>$("#configNotice")).appendTo("body");

        this.loginInfoSub = this._ngRedux.select("loginInfo")
191
            .map(loginInfo => <ILoginInfoRecords>loginInfo)
192 193
            .subscribe(loginInfo => {
                if (loginInfo.size > 0) {
194 195 196 197
                    loginInfo.reduce(({}, loginInfoObj) => {
                        this.minedu_userName = loginInfoObj.minedu_username;
                        this.minedu_userPassword = loginInfoObj.minedu_userpassword;
                        return loginInfoObj;
198 199 200 201
                    }, {});
                }
                this.loginInfo$.next(loginInfo);
            }, error => console.log("error selecting loginInfo"));
202

203
        this.retrieveSettings();
204 205 206

    }

207 208 209 210 211 212
    retrieveSettings() {

        this.dataRetrieved = -1;

        this.settingsSub = this._hds.retrieveAdminSettings(this.minedu_userName, this.minedu_userPassword).subscribe(data => {
            this.settings$.next(data);
213 214 215 216 217
            this.capacityDisabled = Boolean(Number(this.settings$.value["capacityDisabled"]));
            this.directorViewDisabled = Boolean(Number(this.settings$.value["directorViewDisabled"]));
            this.applicantsLoginDisabled = Boolean(Number(this.settings$.value["applicantsLoginDisabled"]));
            this.applicantsResultsDisabled = Boolean(Number(this.settings$.value["applicantsResultsDisabled"]));
            this.secondPeriodEnabled = Boolean(Number(this.settings$.value["secondPeriodEnabled"]));
218 219 220 221 222 223 224 225

            this.dataRetrieved = 1;
        },
            error => {
                this.settings$.next([{}]);
                this.dataRetrieved = 0;
                console.log("Error Getting MinisterRetrieveSettings");
            });
226 227 228 229
    }

    storeSettings() {

230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
        this.dataRetrieved = -1;

        this.settingsSub = this._hds.storeAdminSettings(this.minedu_userName, this.minedu_userPassword,
            this.capacityDisabled, this.directorViewDisabled, this.applicantsLoginDisabled, this.applicantsResultsDisabled, this.secondPeriodEnabled)
            .subscribe(data => {
                this.settings$.next(data);
                this.dataRetrieved = 1;

                this.modalTitle.next("Ρύθμιση Παραμέτρων");
                this.modalText.next("Έγινε εφαρμογή των νέων σας ρυθμίσεων.");
                this.modalHeader.next("modal-header-success");
                this.showModal();
            },
            error => {
                this.settings$.next([{}]);
                this.dataRetrieved = 0;
                console.log("Error Getting MinisterStoreSettings");

                this.modalTitle.next("Ρύθμιση Παραμέτρων");
                this.modalText.next("ΑΠΟΤΥΧΙΑ εφαρμογής των νέων σας ρυθμίσεων.");
                this.modalHeader.next("modal-header-danger");
                this.showModal();
            });
253 254
    }

255 256
    toggleCapacityFilter() {
        this.capacityDisabled = !this.capacityDisabled;
257 258
    }

259
    toggleDirectorView() {
260 261 262 263
        this.directorViewDisabled = !this.directorViewDisabled;
    }

    toggleApplicantsLogin() {
264
        this.applicantsLoginDisabled = !this.applicantsLoginDisabled;
265 266
    }

267
    toggleApplicantsResults() {
268
        this.applicantsResultsDisabled = !this.applicantsResultsDisabled;
269
    }
270

271
    toggleSecondPeriod() {
272
        this.secondPeriodEnabled = !this.secondPeriodEnabled;
273 274
    }

275
}