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 '@angular-redux/store'; 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: `
>Ρυθμίσεις






` }) @Injectable() export default class MinisterSettings implements OnInit, OnDestroy { public formGroup: FormGroup; loginInfo$: BehaviorSubject; private modalTitle: BehaviorSubject; private modalText: BehaviorSubject; private modalHeader: BehaviorSubject; private settings$: BehaviorSubject; loginInfoSub: Subscription; private settingsSub: Subscription; private capacityDisabled: boolean; private directorViewDisabled: boolean; private applicantsLoginDisabled: boolean; private applicantsResultsDisabled: boolean; private secondPeriodEnabled: boolean; private dataRetrieved: number; private minedu_userName: string; private minedu_userPassword: string; constructor(private fb: FormBuilder, private _ngRedux: NgRedux, private _hds: HelperDataService, private router: Router) { 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(""); } public showModal(): void { ($('#configNotice')).modal('show'); } public hideModal(): void { ($('#configNotice')).modal('hide'); } public onHidden(): void { //this.isModalShown.next(false); } ngOnDestroy() { ($('#configNotice')).remove(); if (this.loginInfoSub) this.loginInfoSub.unsubscribe(); if (this.settingsSub) this.settingsSub.unsubscribe(); if (this.loginInfo$) this.loginInfo$.unsubscribe(); if (this.settings$) this.settings$.unsubscribe(); } ngOnInit() { ($('#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.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"); }); } storeSettings() { 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(); }); } toggleCapacityFilter() { this.capacityDisabled = !this.capacityDisabled; } toggleDirectorView() { this.directorViewDisabled = !this.directorViewDisabled; } toggleApplicantsLogin() { this.applicantsLoginDisabled = !this.applicantsLoginDisabled; } toggleApplicantsResults() { this.applicantsResultsDisabled = !this.applicantsResultsDisabled; } toggleSecondPeriod() { this.secondPeriodEnabled = !this.secondPeriodEnabled; } }