minister-settings.ts 10.2 KB
Newer Older
1
2
3
4
5
6
7
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
83
84
85
86
87
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';
import { NgRedux, select } from 'ng2-redux';
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">
              <label for="applicantsLoginDisabled">Απενεργοποίηση δυνατότητας αίτησης μαθητών</label>
            </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
147
148
149
150
    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) {

          this.formGroup = this.fb.group({
              capacityDisabled: ['', []],
              directorViewDisabled: ['', []],
              applicantsLoginDisabled: ['', []],
151
              applicantsResultsDisabled: ['', []],
152
              secondPeriodEnabled: ['', []],
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
          });

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

    }

    public showModal():void {
        console.log("about to show modal");
        (<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();
185
186
187
188
      if (this.loginInfo$)
        this.loginInfo$.unsubscribe();
      if (this.settings$)
        this.settings$.unsubscribe();
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
    }

    ngOnInit() {

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

      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$);

      this.retrieveSettings();

    }

    retrieveSettings()  {

      this.dataRetrieved = -1;

      this.settingsSub = this._hds.retrieveAdminSettings(this.minedu_userName, this.minedu_userPassword).subscribe(data => {
           this.settings$.next(data);
           //this.data = data;
       },
         error => {
           this.settings$.next([{}]);
           this.dataRetrieved = 0;
           console.log("Error Getting MinisterRetrieveSettings");
         },
         () => {
           console.log("Success Getting MinisterRetrieveSettings");

           this.capacityDisabled = Boolean(Number(this.settings$.value['capacityDisabled']));
           this.directorViewDisabled = Boolean(Number(this.settings$.value['directorViewDisabled']));
           this.applicantsLoginDisabled = Boolean(Number(this.settings$.value['applicantsLoginDisabled']));
229
           this.applicantsResultsDisabled = Boolean(Number(this.settings$.value['applicantsResultsDisabled']));
230
           this.secondPeriodEnabled = Boolean(Number(this.settings$.value['secondPeriodEnabled']));
231
232
233
234
235
236
237
238
239
240
241

           this.dataRetrieved = 1;
         }
       )

    }

    storeSettings() {

      this.dataRetrieved = -1;

242
      this.settingsSub = this._hds.storeAdminSettings(this.minedu_userName, this.minedu_userPassword,
243
              this.capacityDisabled, this.directorViewDisabled, this.applicantsLoginDisabled, this.applicantsResultsDisabled, this.secondPeriodEnabled )
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
        .subscribe(data => {
           this.settings$.next(data);
           //this.data = data;
       },
         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();
         },
         () => {
           console.log("Success Getting MinisterStoreSettings");
           this.dataRetrieved = 1;

           this.modalTitle.next("Ρύθμιση Παραμέτρων");
           this.modalText.next("Έγινε εφαρμογή των νέων σας ρυθμίσεων.");
           this.modalHeader.next("modal-header-success");
           this.showModal();

           //redundunt and has risk..Appear a modal!
           //this.retrieveSettings();

         }
       )

    }

    toggleCapacityFilter()  {

      this.capacityDisabled = !this.capacityDisabled;

    }

    toggleDirectorView()  {

        this.directorViewDisabled = !this.directorViewDisabled;

    }

    toggleApplicantsLogin() {

      this.applicantsLoginDisabled = !this.applicantsLoginDisabled;

    }

293
    toggleApplicantsResults() {
294

295
      this.applicantsResultsDisabled = !this.applicantsResultsDisabled;
296

297
    }
298

299
300
301
302
303
304
    toggleSecondPeriod() {

      this.secondPeriodEnabled = !this.secondPeriodEnabled;

    }

305
306
307
308



}