perfecture-view.ts 7.55 KB
Newer Older
1 2 3
import { Component, Injectable, OnDestroy, OnInit } from "@angular/core";
import { FormBuilder, FormGroup } from "@angular/forms";
import { Router } from "@angular/router";
4
import { BehaviorSubject, Subscription } from "rxjs/Rx";
5 6 7

import { HelperDataService } from "../../services/helper-data-service";

Open Source Developer's avatar
trans  
Open Source Developer committed
8
@Component({
9
    selector: "perfecture-view",
Open Source Developer's avatar
trans  
Open Source Developer committed
10
    template: `
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
      <div class="loading" *ngIf="(showLoader | async) === true"></div>
      <div id="informationfeedback" class="modal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static" data-keyboard="false">
        <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" (click)="hideModal()">Κλείσιμο</button>
                </div>
            </div>
        </div>
      </div>
Open Source Developer's avatar
Open Source Developer committed
28 29
      <div style="min-height: 500px;">
        <form [formGroup]="formGroup">
30 31 32 33 34
            <p style="margin-top: 20px; line-height: 2em;">Στην παρακάτω λίστα βλέπετε τα σχολεία ευθύνης σας.
            <br/>Επιλέξτε σχολείο για να εμφανιστούν τα τμήματα του σχολείου.</p>
            <div class="row" style="margin-top: 20px; line-height: 2em;"><p><strong>Τα τμήματα</strong></p></div>
            <div *ngFor="let SchoolNames$  of SchoolsPerPerf$  | async; let i=index; let isOdd=odd; let isEven=even" style="font-size: 0.8em; font-weight: bold;">
                <li class="list-group-item isclickable" (click)="setActiveRegion(SchoolNames$.id)"
Open Source Developer's avatar
Open Source Developer committed
35
                     [class.oddout]="isOdd"
36
                    [class.evenout]="isEven" [class.selectedout]="regionActive === SchoolNames$.id" >
Open Source Developer's avatar
Open Source Developer committed
37
                    <div [class.changelistcolor]= "SchoolNames$.status === false" class="col-md-12">{{SchoolNames$.name}}</div>
Open Source Developer's avatar
Open Source Developer committed
38 39 40 41 42
                    <div class = "row" [hidden]="SchoolNames$.id !== regionActive" style="margin: 0px 2px 0px 2px;">
                        <div class="col-md-8">Τμήματα</div>
                        <div class="col-md-2">Επιλεχθέντες</div>
                        <div class="col-md-2">Χωρητικότητα</div>
                    </div>
43 44 45 46
                    <div class = "row" *ngFor="let CoursesNames$  of CoursesPerPerf$  | async; let j=index; let isOdd2=odd; let isEven2=even"
                        [class.oddin]="isOdd2" [class.evenin]="isEven2" [class.changecolor]="calccolor(CoursesNames$.size,CoursesNames$.limitdown)"
                        [class.selectedappout]="regionActive === j"
                        [hidden]="SchoolNames$.id !== regionActive" style="margin: 0px 2px 0px 2px;">
Open Source Developer's avatar
Open Source Developer committed
47 48 49
                       <div class="col-md-8">{{CoursesNames$.name}}</div>
                        <div class="col-md-2">{{CoursesNames$.size}}</div>
                        <div class="col-md-2">{{CoursesNames$.capc}}</div>
50 51
                    </div>
                </li>
52
            </div>
Open Source Developer's avatar
Open Source Developer committed
53 54
        </form>
     </div>
Open Source Developer's avatar
trans  
Open Source Developer committed
55 56 57 58

   `
})

Open Source Developer's avatar
Open Source Developer committed
59
@Injectable() export default class EduadminView implements OnInit, OnDestroy {
Open Source Developer's avatar
trans  
Open Source Developer committed
60

61
    private formGroup: FormGroup;
Open Source Developer's avatar
trans  
Open Source Developer committed
62 63
    private SchoolsPerPerf$: BehaviorSubject<any>;
    private SchoolPerPerfSub: Subscription;
Open Source Developer's avatar
trans  
Open Source Developer committed
64 65
    private LimitPerCateg$: BehaviorSubject<any>;
    private LimitPerCategSub: Subscription;
Open Source Developer's avatar
trans  
Open Source Developer committed
66 67
    private CoursesPerPerf$: BehaviorSubject<any>;
    private CoursesPerPerfSub: Subscription;
Open Source Developer's avatar
trans  
Open Source Developer committed
68 69
    private StudentsSize$: BehaviorSubject<any>;
    private StudentsSizeSub: Subscription;
Open Source Developer's avatar
Open Source Developer committed
70
    private showLoader: BehaviorSubject<boolean>;
Open Source Developer's avatar
trans  
Open Source Developer committed
71
    private regionActive = <number>-1;
Open Source Developer's avatar
Open Source Developer committed
72 73
    private School$: BehaviorSubject<any>;
    private SchoolSub: Subscription;
74 75 76
    private modalTitle: BehaviorSubject<string>;
    private modalText: BehaviorSubject<string>;
    private modalHeader: BehaviorSubject<string>;
Open Source Developer's avatar
trans  
Open Source Developer committed
77 78

    constructor(private fb: FormBuilder,
79 80 81
        private router: Router,
        private _hds: HelperDataService,
    ) {
Open Source Developer's avatar
trans  
Open Source Developer committed
82
        this.SchoolsPerPerf$ = new BehaviorSubject([{}]);
Open Source Developer's avatar
trans  
Open Source Developer committed
83 84
        this.LimitPerCateg$ = new BehaviorSubject([{}]);
        this.CoursesPerPerf$ = new BehaviorSubject([{}]);
Open Source Developer's avatar
trans  
Open Source Developer committed
85
        this.StudentsSize$ = new BehaviorSubject({});
Open Source Developer's avatar
Open Source Developer committed
86
        this.School$ = new BehaviorSubject([{}]);
Open Source Developer's avatar
Open Source Developer committed
87
        this.showLoader = new BehaviorSubject(false);
Open Source Developer's avatar
trans  
Open Source Developer committed
88 89
        this.formGroup = this.fb.group({
        });
90 91 92
        this.modalTitle = new BehaviorSubject("");
        this.modalText = new BehaviorSubject("");
        this.modalHeader = new BehaviorSubject("");
Open Source Developer's avatar
trans  
Open Source Developer committed
93 94 95
    }

    ngOnDestroy() {
96
        (<any>$("#informationfeedback")).remove();
97
    }
Open Source Developer's avatar
trans  
Open Source Developer committed
98 99

    ngOnInit() {
100
        (<any>$("#informationfeedback")).appendTo("body");
Open Source Developer's avatar
Open Source Developer committed
101
        this.showLoader.next(true);
102 103 104 105 106
        this.SchoolPerPerfSub = this._hds.getSchools()
            .subscribe(data => {
                this.SchoolsPerPerf$.next(data);
                this.showLoader.next(false);
            },
107 108 109
            error => {
                this.SchoolsPerPerf$.next([{}]);
                console.log("Error Getting Schools");
110 111 112 113 114
                this.modalHeader.next("modal-header-danger");
                this.modalTitle.next("Αδυναμία άντλησης στοιχείων");
                this.modalText.next("Προέκυψε σφάλμα κατά την άντληση των στοιχείων. Παρακαλώ δοκιμάστε ξανά. Εφόσον το πρόβλημα συνεχίσει να υφίσταται, επικοινωνήστε με την ομάδα υποστήριξης.");
                this.showModal();
                this.showLoader.next(false);
115
            });
Open Source Developer's avatar
trans  
Open Source Developer committed
116 117
    }

Open Source Developer's avatar
Open Source Developer committed
118 119 120 121 122
    calccolor(size, limit) {
        if (size < limit)
            return true;
        else
            return false;
Open Source Developer's avatar
trans  
Open Source Developer committed
123 124
    }

Open Source Developer's avatar
Open Source Developer committed
125
    setActiveRegion(ind) {
126
        this.CoursesPerPerf$.next([{}]);
Open Source Developer's avatar
Open Source Developer committed
127 128 129 130 131 132 133
        if (ind === this.regionActive) {
            ind = -1;
            this.regionActive = ind;
        }
        else {
            this.regionActive = ind;
            this.showLoader.next(true);
134 135 136 137 138
            this.CoursesPerPerfSub = this._hds.getCoursePerPerfecture(this.regionActive)
                .subscribe(data => {
                    this.CoursesPerPerf$.next(data);
                    this.showLoader.next(false);
                },
Open Source Developer's avatar
Open Source Developer committed
139 140
                error => {
                    console.log("Error Getting Courses");
141 142 143 144
                    this.modalHeader.next("modal-header-danger");
                    this.modalTitle.next("Αδυναμία άντλησης στοιχείων");
                    this.modalText.next("Προέκυψε σφάλμα κατά την άντληση των στοιχείων. Παρακαλώ δοκιμάστε ξανά. Εφόσον το πρόβλημα συνεχίσει να υφίσταται, επικοινωνήστε με την ομάδα υποστήριξης.");
                    this.showModal();
Open Source Developer's avatar
Open Source Developer committed
145 146 147
                    this.showLoader.next(false);
                });
        }
148
    }
Open Source Developer's avatar
trans  
Open Source Developer committed
149

150 151
    public showModal(): void {
        (<any>$("#informationfeedback")).modal("show");
Open Source Developer's avatar
trans  
Open Source Developer committed
152 153
    }

154 155 156
    public hideModal(): void {
        (<any>$("#informationfeedback")).modal("hide");
    }
Open Source Developer's avatar
Open Source Developer committed
157

Open Source Developer's avatar
trans  
Open Source Developer committed
158
}