eduadmin-view.ts 4.94 KB
Newer Older
Open Source Developer's avatar
Open Source Developer committed
1
2
3
4
5
6
7
8
9
10
11
12
13
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 '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 {
    FormBuilder,
14
    FormGroup,
Open Source Developer's avatar
Open Source Developer committed
15
16
17
18
19
20
21
    FormControl,
    FormArray,
    Validators,
} from '@angular/forms';
@Component({
    selector: 'eduadmin-view',
    template: `
Open Source Developer's avatar
changes    
Open Source Developer committed
22
23
24
25
26
27
      <div class = "loading" *ngIf="(showLoader | async) === true"></div>
      <div style="min-height: 500px;">
        <form [formGroup]="formGroup">
         <p style="margin-top: 20px; line-height: 2em;">Στην παρακάτω λίστα βλέπετε τα σχολεία ευθύνης σας.
         </p>
            <div class="row" style="margin-top: 20px; line-height: 2em;" > <b> Τα τμήματα. </b>
Open Source Developer's avatar
Open Source Developer committed
28
            </div>
Open Source Developer's avatar
changes    
Open Source Developer committed
29
30
31
32
33
34
                <div *ngFor="let SchoolNames$  of SchoolsPerPerf$  | async; let i=index; let isOdd=odd; let isEven=even"  >
                      <li class="list-group-item isclickable" (click)="setActiveRegion(SchoolNames$.id)"
                       [class.changelistcolor]= "SchoolNames$.status === false" [class.oddout]="isOdd"
                        [class.evenout]="isEven" [class.selectedout]="regionActive === SchoolNames$.id" >
                            <div class="col-md-12" style="font-size: 0.8em; font-weight: bold;" >{{SchoolNames$.name}}</div>
                      </li>
35
36

                      <div class = "row" *ngFor="let CoursesNames$  of CoursesPerPerf$  | async; let j=index; let isOdd2=odd; let isEven2=even"
Open Source Developer's avatar
changes    
Open Source Developer committed
37
                       [class.oddin]="isOdd2" [class.evenin]="isEven2" [class.changecolor]="calccolor(CoursesNames$.size,CoursesNames$.limitdown)"
38
                       [class.selectedappout]="regionActive === j"
Open Source Developer's avatar
changes    
Open Source Developer committed
39
40
41
42
                       [hidden]="SchoolNames$.id !== regionActive" style="margin: 0px 2px 0px 2px;">
                          <div class="col-md-6" style="font-size: 0.8em; font-weight: bold;" >{{CoursesNames$.name}}</div>
                          <div class="col-md-6" style="font-size: 0.8em; font-weight: bold;" >{{CoursesNames$.size}}</div>
                       </div>
43
44


Open Source Developer's avatar
Open Source Developer committed
45
                </div>
Open Source Developer's avatar
changes    
Open Source Developer committed
46
47
        </form>
     </div>
Open Source Developer's avatar
Open Source Developer committed
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

   `
})

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

    public formGroup: FormGroup;
    private SchoolsPerPerf$: BehaviorSubject<any>;
    private SchoolPerPerfSub: Subscription;
    private LimitPerCateg$: BehaviorSubject<any>;
    private LimitPerCategSub: Subscription;
    private CoursesPerPerf$: BehaviorSubject<any>;
    private CoursesPerPerfSub: Subscription;
    private StudentsSize$: BehaviorSubject<any>;
    private StudentsSizeSub: Subscription;
Open Source Developer's avatar
changes    
Open Source Developer committed
63
    private showLoader: BehaviorSubject<boolean>;
64
    public perfecture;
Open Source Developer's avatar
Open Source Developer committed
65
66
67
68
69
70
71
    private regionActive = <number>-1;
    private School$: BehaviorSubject<any>;
    private SchoolSub: Subscription;



    constructor(private fb: FormBuilder,
72
73
74
        private router: Router,
        private _hds: HelperDataService,
    ) {
Open Source Developer's avatar
Open Source Developer committed
75
76
77
78
79
        this.SchoolsPerPerf$ = new BehaviorSubject([{}]);
        this.LimitPerCateg$ = new BehaviorSubject([{}]);
        this.CoursesPerPerf$ = new BehaviorSubject([{}]);
        this.StudentsSize$ = new BehaviorSubject({});
        this.School$ = new BehaviorSubject([{}]);
Open Source Developer's avatar
changes    
Open Source Developer committed
80
        this.showLoader = new BehaviorSubject(false);
Open Source Developer's avatar
Open Source Developer committed
81
82
83
84
85
86
        this.formGroup = this.fb.group({
        });

    }

    ngOnDestroy() {
87
    }
Open Source Developer's avatar
Open Source Developer committed
88
89
90
91

    ngOnInit() {


92
93
94
95
96
97
98
99
100
        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");
            });
Open Source Developer's avatar
Open Source Developer committed
101
102
103
104
105

    }



106
    calccolor(size, limit) {
Open Source Developer's avatar
changes    
Open Source Developer committed
107

108
109
110
111
        if (size < limit)
            return true;
        else
            return false;
Open Source Developer's avatar
changes    
Open Source Developer committed
112
    }
Open Source Developer's avatar
Open Source Developer committed
113

Open Source Developer's avatar
changes    
Open Source Developer committed
114
115
116
117



    setActiveRegion(ind) {
118
119
120
121
122
123
124
125
126
127
        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);
Open Source Developer's avatar
changes    
Open Source Developer committed
128
                this.showLoader.next(false);
Open Source Developer's avatar
Open Source Developer committed
129
            },
130
131
132
133
134
135
136
                error => {
                    this.CoursesPerPerf$.next([{}]);
                    console.log("Error Getting Courses");
                    this.showLoader.next(false);
                });
        }
        this.regionActive = ind;
Open Source Developer's avatar
Open Source Developer committed
137
138
139
140
141
142


    }


}