minister-settings.ts 16.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
import { NgRedux } from "@angular-redux/store";
import { Component, OnDestroy, OnInit } from "@angular/core";
import { Injectable } from "@angular/core";
import { FormBuilder, FormGroup, Validators } from "@angular/forms";
import { Router } from "@angular/router";
import { BehaviorSubject, Subscription } from "rxjs/Rx";
import { IMyDpOptions } from "mydatepicker";

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";

@Component({
    selector: "minister-settings",
    template: `

    <div
19
      class = "loading" *ngIf="(dataRetrieved == -1  || (showLoader | async) === true)" >
20 21 22 23 24 25 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
    </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 novalidate [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">
73
              <label for="applicantsLoginDisabled">Απενεργοποίηση δυνατότητας υποβολής δήλωσης προτίμησης</label>
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
            </div>
          </div>
          <br>

          <div class="row">
            <div class="col-md-1 ">
              <input type="checkbox" [checked]="applicantsAppModifyDisabled" formControlName="applicantsAppModifyDisabled"
              (click)="toggleApplicantsAppModify()" >
            </div>
            <div class="col-md-9">
              <label for="applicantsAppModifyDisabled">Απενεργοποίηση δυνατότητας τροποποίησης αίτησης </label>
            </div>
          </div>
          <br>

          <div class="row">
            <div class="col-md-1 ">
              <input type="checkbox" [checked]="applicantsAppDeleteDisabled" formControlName="applicantsAppDeleteDisabled"
              (click)="toggleApplicantsAppDelete()" >
            </div>
            <div class="col-md-9">
              <label for="applicantsAppDeleteDisabled">Απενεργοποίηση δυνατότητας διαγραφής αίτησης </label>
            </div>
          </div>
          <br>

          <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>

          <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>

          <div class="row" *ngIf = "secondPeriodEnabled">
            <div class="col-md-1 "></div>
            <div class="col-md-9 ">
              <label for="distributionstartdate">Ημερομηνία εκκίνησης υποπεριόδου δεύτερης περιόδου αιτήσεων(<span style="color: #ff0000;">*</span>)</label>
            </div>
          </div>
          <div class="row" *ngIf = "secondPeriodEnabled">
            <div class="col-md-1 "></div>
            <div class="col-md-9 ">
              <my-date-picker name="distributionstartdate" [options]="myDatePickerOptions" formControlName="distributionstartdate" locale="el"></my-date-picker>
              <div class="alert alert-danger" *ngIf="formGroup.get('distributionstartdate').touched && formGroup.get('distributionstartdate').hasError('required')">
                  Συμπληρώστε την ημερομηνία εκκίνησης!
              </div>
            </div>
          </div>
137 138 139 140 141 142
           <div class="row">
            <div class="col-md-1 ">
              <input type="checkbox" [checked]="smallClassApproved"  formControlName="smallClassApproved"
              (click)="toggleSmallClassesFilter()" >
            </div>
            <div class="col-md-9">
143
              <label for="smallClassApproved">Ενεργοποίηση μη διαθεσιμότητας μη εγκεκριμένων τμημάτων</label>
144 145
            </div>
          </div>
146 147
          <br>

148 149 150 151 152 153 154 155 156
          <div class="row">
           <div class="col-md-1 ">
             <input type="checkbox" [checked]="wsIdentEnabled"  formControlName="wsIdentEnabled"
             (click)="toggleWsIdent()" >
           </div>
           <div class="col-md-9">
             <label for="wsIdentEnabled">Ενεργοποίηση Web Service Ταυτοποίησης Μαθητή του ΠΣ Myschool</label>
           </div>
         </div>
157
         <br>
158

159 160 161 162 163 164 165 166 167
         <div class="row">
          <div class="col-md-1 ">
            <input type="checkbox" [checked]="gsisIdentEnabled"  formControlName="gsisIdentEnabled"
            (click)="toggleGsisIdent()" >
          </div>
          <div class="col-md-9">
            <label for="gsisIdentEnabled">Ενεργοποίηση χρήσης δεδομένων από τη ΓΓΠΣ</label>
          </div>
        </div>
168 169
          <br>

170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
          <button type="submit" class="btn btn-md pull-right"  (click)="storeSettings()" [disabled] = "secondPeriodEnabled && formGroup.get('distributionstartdate').hasError('required')" >
              Εφαρμογή
          </button>

        </form>

      </div>

   `
})

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

    private formGroup: FormGroup;
    private loginInfo$: BehaviorSubject<ILoginInfoRecords>;
    private modalTitle: BehaviorSubject<string>;
    private modalText: BehaviorSubject<string>;
    private modalHeader: BehaviorSubject<string>;
    private settings$: BehaviorSubject<any>;
189
    private OffLineCalculation$: BehaviorSubject<any>;
190
    private OffLineCalculationSub: Subscription;
191 192 193 194 195 196 197 198 199 200 201
    private loginInfoSub: Subscription;
    private settingsSub: Subscription;
    private capacityDisabled: boolean;
    private directorViewDisabled: boolean;
    private applicantsLoginDisabled: boolean;
    private applicantsAppModifyDisabled: boolean;
    private applicantsAppDeleteDisabled: boolean;
    private applicantsResultsDisabled: boolean;
    private secondPeriodEnabled: boolean;
    private dateStartBPeriod: string;
    private dataRetrieved: number;
202
    private smallClassApproved: boolean;
203
    private wsIdentEnabled: boolean;
204
    private gsisIdentEnabled: boolean;
205
    private showLoader: BehaviorSubject<boolean>;
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230

    private minedu_userName: string;
    private minedu_userPassword: string;

    private myDatePickerOptions: IMyDpOptions = {
        // other options...
        sunHighlight: false,
        editableDateField: false,
        dateFormat: "dd/mm/yyyy",
    };

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

        this.formGroup = this.fb.group({
            capacityDisabled: ["", []],
            directorViewDisabled: ["", []],
            applicantsLoginDisabled: ["", []],
            applicantsAppModifyDisabled: ["", []],
            applicantsAppDeleteDisabled: ["", []],
            applicantsResultsDisabled: ["", []],
            secondPeriodEnabled: ["", []],
            distributionstartdate:["", [Validators.required]],
231
            smallClassApproved:["",[]],
232
            wsIdentEnabled:["",[]],
233
            gsisIdentEnabled:["",[]],
234 235 236 237 238 239 240
        });

        this.loginInfo$ = new BehaviorSubject(LOGININFO_INITIAL_STATE);
        this.settings$ = new BehaviorSubject([{}]);
        this.modalTitle = new BehaviorSubject("");
        this.modalText = new BehaviorSubject("");
        this.modalHeader = new BehaviorSubject("");
241 242
        this.OffLineCalculation$ = new BehaviorSubject([{}]);
        this.showLoader = new BehaviorSubject(false);
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308

    }

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

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

    public onHidden(): void {
        // this.isModalShown.next(false);
    }


    ngOnDestroy() {

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

        if (this.loginInfoSub)
            this.loginInfoSub.unsubscribe();
        if (this.settingsSub)
            this.settingsSub.unsubscribe();
    }

    ngOnInit() {

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

        this.loginInfoSub = this._ngRedux.select("loginInfo")
            .map(loginInfo => <ILoginInfoRecords>loginInfo)
            .subscribe(loginInfo => {
                if (loginInfo.size > 0) {
                    loginInfo.reduce(({}, loginInfoObj) => {
                        this.minedu_userName = loginInfoObj.minedu_username;
                        this.minedu_userPassword = loginInfoObj.minedu_userpassword;
                        return loginInfoObj;
                    }, {});
                }
                this.loginInfo$.next(loginInfo);
            }, error => console.log("error selecting loginInfo"));

        this.retrieveSettings();

    }

    retrieveSettings() {

        this.dataRetrieved = -1;

        this.settingsSub = this._hds.retrieveAdminSettings(this.minedu_userName, this.minedu_userPassword).subscribe(data => {
            this.settings$.next(data);
            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.applicantsAppModifyDisabled = Boolean(Number(this.settings$.value["applicantsAppModifyDisabled"]));
            this.applicantsAppDeleteDisabled = Boolean(Number(this.settings$.value["applicantsAppDeleteDisabled"]));
            this.applicantsResultsDisabled = Boolean(Number(this.settings$.value["applicantsResultsDisabled"]));
            this.secondPeriodEnabled = Boolean(Number(this.settings$.value["secondPeriodEnabled"]));
            this.dateStartBPeriod = this.settings$.value["dateStart"];
            if (this.dateStartBPeriod != '')  {
              let dateparts = this.dateStartBPeriod.split("-",3);
              this.formGroup.controls["distributionstartdate"].setValue( {date: {year: Number(dateparts[2]), month: Number(dateparts[1]), day: Number(dateparts[0])}} );
            }
            //this.formGroup.controls["distributionstartdate"].setValue(this.populateDate(this.dateStartBPeriod));
309 310
            this.smallClassApproved = Boolean(Number(this.settings$.value["smallClassApproved"]));
            this.wsIdentEnabled = Boolean(Number(this.settings$.value["wsIdentEnabled"]));
311
            this.gsisIdentEnabled = Boolean(Number(this.settings$.value["gsisIdentEnabled"]));
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337

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

    storeSettings() {

        this.dataRetrieved = -1;

        if (this.secondPeriodEnabled) {
          this.dateStartBPeriod = this.formGroup.controls["distributionstartdate"].value.date.day + "-" +
              this.formGroup.controls["distributionstartdate"].value.date.month + "-" +
              this.formGroup.controls["distributionstartdate"].value.date.year;
        }
        else
            this.dateStartBPeriod = "0-0-0000";


        this.settingsSub = this._hds.storeAdminSettings(this.minedu_userName, this.minedu_userPassword,
            this.capacityDisabled, this.directorViewDisabled, this.applicantsLoginDisabled,
            this.applicantsAppModifyDisabled, this.applicantsAppDeleteDisabled, this.applicantsResultsDisabled,
338
            this.secondPeriodEnabled, this.dateStartBPeriod, this.smallClassApproved, this.wsIdentEnabled, this.gsisIdentEnabled)
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387
            .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();
            });
    }

    toggleCapacityFilter() {
        this.capacityDisabled = !this.capacityDisabled;
    }

    toggleDirectorView() {
        this.directorViewDisabled = !this.directorViewDisabled;
    }

    toggleApplicantsLogin() {
        this.applicantsLoginDisabled = !this.applicantsLoginDisabled;
    }

    toggleApplicantsAppModify() {
        this.applicantsAppModifyDisabled = !this.applicantsAppModifyDisabled;
    }

    toggleApplicantsAppDelete() {
        this.applicantsAppDeleteDisabled = !this.applicantsAppDeleteDisabled;
    }

    toggleApplicantsResults() {
        this.applicantsResultsDisabled = !this.applicantsResultsDisabled;
    }

    toggleSecondPeriod() {
        this.secondPeriodEnabled = !this.secondPeriodEnabled;
    }

388
    toggleSmallClassesFilter(){
389 390

      this.showLoader.next(true);
391
       this.OffLineCalculationSub = this._hds.OffLinecalculationofSmallClasses(this.minedu_userName, this.minedu_userPassword)
392 393 394 395 396 397 398 399 400
                .subscribe(data => {
                    this.showLoader.next(false);
                    this.OffLineCalculation$.next(data);
                },
                error => {
                    this.showLoader.next(false);
                    console.log("Error for the offlineCalculation");
                });

401 402 403
       this.smallClassApproved =!this.smallClassApproved;
    }

404 405 406
    toggleWsIdent(){
       this.wsIdentEnabled =!this.wsIdentEnabled;
    }
407 408 409 410 411

    toggleGsisIdent(){
       this.gsisIdentEnabled =!this.gsisIdentEnabled;
    }

412

413
}