import { Component, OnInit, OnDestroy, ElementRef, ViewChild, 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 {
FormBuilder,
FormGroup,
FormControl,
FormArray,
Validators,
} from "@angular/forms";
@Component({
selector: "eduadmin-view",
template: `
`
})
@Injectable() export default class EduadminView implements OnInit, OnDestroy {
public formGroup: FormGroup;
private SchoolsPerPerf$: BehaviorSubject;
private SchoolPerPerfSub: Subscription;
private LimitPerCateg$: BehaviorSubject;
private LimitPerCategSub: Subscription;
private CoursesPerPerf$: BehaviorSubject;
private CoursesPerPerfSub: Subscription;
private StudentsSize$: BehaviorSubject;
private StudentsSizeSub: Subscription;
private showLoader: BehaviorSubject;
public perfecture;
private regionActive = -1;
private School$: BehaviorSubject;
private SchoolSub: Subscription;
private modalTitle: BehaviorSubject;
private modalText: BehaviorSubject;
private modalHeader: BehaviorSubject;
constructor(private fb: FormBuilder,
private router: Router,
private _hds: HelperDataService,
) {
this.SchoolsPerPerf$ = new BehaviorSubject([{}]);
this.LimitPerCateg$ = new BehaviorSubject([{}]);
this.CoursesPerPerf$ = new BehaviorSubject([{}]);
this.StudentsSize$ = new BehaviorSubject({});
this.School$ = new BehaviorSubject([{}]);
this.showLoader = new BehaviorSubject(false);
this.formGroup = this.fb.group({
});
this.modalTitle = new BehaviorSubject("");
this.modalText = new BehaviorSubject("");
this.modalHeader = new BehaviorSubject("");
}
ngOnDestroy() {
($("#informationfeedback")).remove();
}
ngOnInit() {
($("#informationfeedback")).appendTo("body");
this.showLoader.next(true);
this.SchoolPerPerfSub = this._hds.getSchools()
.subscribe(data => {
this.SchoolsPerPerf$.next(data);
this.showLoader.next(false);
},
error => {
this.SchoolsPerPerf$.next([{}]);
console.log("Error Getting Schools");
this.modalHeader.next("modal-header-danger");
this.modalTitle.next("Αδυναμία άντλησης στοιχείων");
this.modalText.next("Προέκυψε σφάλμα κατά την άντληση των στοιχείων. Παρακαλώ δοκιμάστε ξανά. Εφόσον το πρόβλημα συνεχίσει να υφίσταται, επικοινωνήστε με την ομάδα υποστήριξης.");
this.showModal();
this.showLoader.next(false);
});
}
calccolor(size, limit) {
if (size < limit) {
return true;
} else {
return false;
}
}
setActiveRegion(ind) {
this.CoursesPerPerf$.next([{}]);
if (ind === this.regionActive) {
ind = -1;
this.regionActive = ind;
}
else {
this.regionActive = ind;
this.showLoader.next(true);
this.CoursesPerPerfSub = this._hds.getCoursePerPerfecture(this.regionActive)
.subscribe(data => {
this.CoursesPerPerf$.next(data);
this.showLoader.next(false);
},
error => {
this.CoursesPerPerf$.next([{}]);
console.log("Error Getting Courses");
this.modalHeader.next("modal-header-danger");
this.modalTitle.next("Αδυναμία άντλησης στοιχείων");
this.modalText.next("Προέκυψε σφάλμα κατά την άντληση των στοιχείων. Παρακαλώ δοκιμάστε ξανά. Εφόσον το πρόβλημα συνεχίσει να υφίσταται, επικοινωνήστε με την ομάδα υποστήριξης.");
this.showModal();
this.showLoader.next(false);
});
}
}
public showModal(): void {
($("#informationfeedback")).modal("show");
}
public hideModal(): void {
($("#informationfeedback")).modal("hide");
}
}