minister-settings.ts 10 KB
Newer Older
1 2 3 4 5 6
import { Component, OnInit, OnDestroy, ElementRef, ViewChild} from "@angular/core";
import { Injectable } from "@angular/core";
import { AppSettings } from '../../app.settings';
import { HelperDataService } from '../../services/helper-data-service';
import { Observable} from "rxjs/Observable";
import { Http, Headers, RequestOptions} from '@angular/http';
7
import { NgRedux, select } from '@angular-redux/store';
8 9 10 11 12 13 14 15 16 17 18 19 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 73 74 75 76 77 78 79 80 81 82
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 {
    FormBuilder,
    FormGroup,
    FormControl,
    FormArray,
    Validators,
} from '@angular/forms';


@Component({
    selector: 'minister-settings',
    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 123 124 125 126 127 128 129 130 131 132 133 134
          <button type="submit" class="btn btn-md pull-right"  (click)="storeSettings()" >
              Εφαρμογή
          </button>

        </form>

      </div>

   `
})

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

    public formGroup: FormGroup;
    loginInfo$: BehaviorSubject<ILoginInfo>;
    private modalTitle: BehaviorSubject<string>;
    private modalText: BehaviorSubject<string>;
    private modalHeader: BehaviorSubject<string>;
    private settings$: BehaviorSubject<any>;
    loginInfoSub: Subscription;
    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 148 149 150 151 152 153 154 155 156 157 158 159
        this.formGroup = this.fb.group({
            capacityDisabled: ['', []],
            directorViewDisabled: ['', []],
            applicantsLoginDisabled: ['', []],
            applicantsResultsDisabled: ['', []],
            secondPeriodEnabled: ['', []],
        });

        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 165 166
        (<any>$('#configNotice')).modal('show');
    }

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

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


    ngOnDestroy() {

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

180 181 182 183 184 185 186 187
        if (this.loginInfoSub)
            this.loginInfoSub.unsubscribe();
        if (this.settingsSub)
            this.settingsSub.unsubscribe();
        if (this.loginInfo$)
            this.loginInfo$.unsubscribe();
        if (this.settings$)
            this.settings$.unsubscribe();
188 189 190 191
    }

    ngOnInit() {

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

194 195 196 197 198 199 200 201 202 203
        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;
                    return loginInfoToken;
                }, {});
            }
            return state.loginInfo;
        }).subscribe(this.loginInfo$);
204

205
        this.retrieveSettings();
206 207 208

    }

209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
    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.applicantsResultsDisabled = Boolean(Number(this.settings$.value['applicantsResultsDisabled']));
            this.secondPeriodEnabled = Boolean(Number(this.settings$.value['secondPeriodEnabled']));

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

    storeSettings() {

232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
        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();
            });
255 256
    }

257
    toggleCapacityFilter() {
258

259
        this.capacityDisabled = !this.capacityDisabled;
260 261 262

    }

263
    toggleDirectorView() {
264 265 266 267 268 269 270

        this.directorViewDisabled = !this.directorViewDisabled;

    }

    toggleApplicantsLogin() {

271
        this.applicantsLoginDisabled = !this.applicantsLoginDisabled;
272 273 274

    }

275
    toggleApplicantsResults() {
276

277
        this.applicantsResultsDisabled = !this.applicantsResultsDisabled;
278

279
    }
280

281 282
    toggleSecondPeriod() {

283
        this.secondPeriodEnabled = !this.secondPeriodEnabled;
284 285 286

    }

287 288 289 290



}