director-classcapacity.ts 9.17 KB
Newer Older
1
import { Component, OnInit, OnDestroy, ElementRef, ViewChild} from "@angular/core";
Open Source Developer's avatar
Open Source Developer committed
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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 {
    FormBuilder,
    FormGroup,
    FormControl,
    FormArray,
    Validators,
} from '@angular/forms';
@Component({
    selector: 'director-classcapacity',
    template: `
23
    <div style="min-height: 500px;">
Open Source Developer's avatar
Open Source Developer committed
24
25
26
27
28
29
30
31
  <form [formGroup]="formGroup">
      <label for="taxi">Τάξη</label><br/>
      <div class="form-group">
            <select #txoption  class="form-control" (change)="verifyclass(txoption)" formControlName="taxi">
              <option value="1" >Α' Λυκείου</option>
              <option value="2" >Β' Λυκείου</option>
              <option value="3" >Γ' Λυκείου</option>
            </select>
32
      </div>
Open Source Developer's avatar
Open Source Developer committed
33
34
35
36
37
38
39
      <div class="form-group">

            <select #tmop class="form-control" *ngIf="(selectionBClass | async)" (change)="checkbclass(tmop,txoption)" formControlName="tomeas">
              <option *ngFor="let SectorSelection$  of StudentSelected$ | async; let i=index" [value] = "SectorSelection$.id"> {{SectorSelection$.sector_id}} </option>
            </select>
      </div>
      <div class="form-group">
Open Source Developer's avatar
trans    
Open Source Developer committed
40
            <select #spop class="form-control" *ngIf="(selectionCClass | async)" (change)="checkcclass(tmop,txoption,spop)"  formControlName="specialit">
Open Source Developer's avatar
Open Source Developer committed
41
42
43
              <option *ngFor="let SpecialSelection$  of StudentSelectedSpecial$ | async; let i=index" [value] = "SpecialSelection$.id"> {{SpecialSelection$.specialty_id}} </option>
            </select>
      </div>
44

Open Source Developer's avatar
trans    
Open Source Developer committed
45
46

      <div *ngIf="(retrievedStudent | async) && (modify === false)">
Open Source Developer's avatar
Open Source Developer committed
47
      <strong>Δυναμική σε τμήματα:</strong>
Open Source Developer's avatar
trans    
Open Source Developer committed
48
49
50
      <div *ngFor="let classCapac$  of classCapacity$ | async;"  >
          <div><label for="capc">Τρέχουσα Δυναμική:</label> <p class="form-control" id = "capc" style="border:1px solid #eceeef;"> {{classCapac$.capacity}} </p></div>
        </div>
51

Open Source Developer's avatar
trans    
Open Source Developer committed
52
53
54
55
56
57
      <p style="margin-top: 20px; line-height: 2em;"> Αν θέλετε να αλλάξετε τη δυναμική σε τμήματα για τη συγκεκριμένή επιλογή συνέχεια επιλέξτε <i>Τροποποίηση</i>.</p>
              <button type="button" class="btn-primary btn-sm pull-right" (click) ="modifyCapacity()">
                Τροποποίηση
               </button>
       </div>
      <div *ngIf="(modify === true)">
Open Source Developer's avatar
Open Source Developer committed
58
      <input  type="number" formControlName="capacity" min="1" max="10">
59

Open Source Developer's avatar
Open Source Developer committed
60
61
62
            <button type="button" class="btn-primary btn-sm pull-right" (click) ="saveCapacity()">
                Αποθήκευση
             </button>
Open Source Developer's avatar
trans    
Open Source Developer committed
63
       </div>
64
65
       </form>
       </div>
Open Source Developer's avatar
Open Source Developer committed
66
67
68
   `
})

69
@Injectable() export default class DirectorClassCapacity implements OnInit, OnDestroy {
Open Source Developer's avatar
Open Source Developer committed
70
71
72
73
74
75
76
77

    public formGroup: FormGroup;
    private StudentSelected$: BehaviorSubject<any>;
    private StudentSelectedSub: Subscription;
    private StudentSelectedSpecial$: BehaviorSubject<any>;
    private StudentSelectedSpecialSub: Subscription;
    private selectionBClass: BehaviorSubject<boolean>;
    private selectionCClass: BehaviorSubject<boolean>;
78
    private SchoolId = 147;
Open Source Developer's avatar
Open Source Developer committed
79
    private currentclass: Number;
Open Source Developer's avatar
trans    
Open Source Developer committed
80
81
82
83
    private classCapacity$: BehaviorSubject<any>;
    private classCapacitySub: Subscription;
    private retrievedStudent: BehaviorSubject<boolean>;
    private modify = false;
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103



    constructor(private fb: FormBuilder,
        private _hds: HelperDataService,
        private activatedRoute: ActivatedRoute,
        private router: Router) {
        this.StudentSelected$ = new BehaviorSubject([{}]);
        this.StudentSelectedSpecial$ = new BehaviorSubject([{}]);
        this.classCapacity$ = new BehaviorSubject([{}]);
        this.selectionBClass = new BehaviorSubject(false);
        this.selectionCClass = new BehaviorSubject(false);
        this.retrievedStudent = new BehaviorSubject(false);
        this.formGroup = this.fb.group({
            tomeas: ['', []],
            taxi: ['', []],
            specialit: ['', []],
            capacity: ['', []],
        });

Open Source Developer's avatar
Open Source Developer committed
104
105
    }

106
    ngOnDestroy() {
Open Source Developer's avatar
Open Source Developer committed
107
108
109
110
111
112
113
        if (this.StudentSelectedSub)
            this.StudentSelectedSub.unsubscribe();
        if (this.StudentSelectedSpecialSub)
            this.StudentSelectedSpecialSub.unsubscribe();
        if (this.selectionBClass)
            this.selectionBClass.unsubscribe();
        if (this.selectionCClass)
114
            this.selectionCClass.unsubscribe();
Open Source Developer's avatar
trans    
Open Source Developer committed
115
116
117
        if (this.classCapacitySub)
            this.classCapacitySub.unsubscribe();
        if (this.retrievedStudent)
118
            this.retrievedStudent.unsubscribe();
Open Source Developer's avatar
Open Source Developer committed
119
    }
120

Open Source Developer's avatar
Open Source Developer committed
121
    ngOnInit() {
Open Source Developer's avatar
trans    
Open Source Developer committed
122
        this.retrievedStudent.next(false);
Open Source Developer's avatar
Open Source Developer committed
123
124
125
    }


126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
    verifyclass(txop) {
        this.modify = false;
        console.log(this.formGroup.value.specialit, "speciality");
        if (txop.value === "1") {
            this.selectionBClass.next(false);
            this.selectionCClass.next(false);
            this.formGroup.patchValue({
                tomeas: '',
                specialit: '',
            });
            console.log("a class");
            this.classCapacitySub = this._hds.getCapacityPerSchool(this.formGroup.value.taxi, 0, 0, this.SchoolId).subscribe(data => {
                this.classCapacity$.next(data);
                this.retrievedStudent.next(true);
            },
                error => {
                    this.classCapacity$.next([{}]);
                    console.log("Error Getting Capacity");
                },
                () => console.log("Getting Capacity"));
Open Source Developer's avatar
Open Source Developer committed
146

147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
        }
        else if (txop.value === "2") {
            this.formGroup.patchValue({
                specialit: '',
            });
            this.selectionBClass.next(true);
            this.selectionCClass.next(false);
            this.StudentSelected$ = new BehaviorSubject([{}]);
            this.StudentSelectedSub = this._hds.getSectorPerSchool(this.SchoolId).subscribe(this.StudentSelected$);
        }
        else if (txop.value === "3") {
            var sectorint = +this.formGroup.value.tomeas;
            console.log(sectorint, "test");
            if (this.formGroup.value.tomeas != '') {
                var sectorint = +this.formGroup.value.tomeas;
                this.StudentSelectedSpecial$ = new BehaviorSubject([{}]);
                this.StudentSelectedSpecialSub = this._hds.getSpecialityPerSchool(this.SchoolId, sectorint).subscribe(this.StudentSelectedSpecial$);
Open Source Developer's avatar
Open Source Developer committed
164
            }
165
166
167
168
169
170
171
172
173
            this.selectionBClass.next(true);
            this.selectionCClass.next(true);
            this.StudentSelected$ = new BehaviorSubject([{}]);
            this.StudentSelectedSub = this._hds.getSectorPerSchool(this.SchoolId).subscribe(this.StudentSelected$);
        }




Open Source Developer's avatar
Open Source Developer committed
174
175
176
    }


177
178
    checkbclass(tmop, txop) {
        this.modify = false;
Open Source Developer's avatar
Open Source Developer committed
179
        var sectorint = +this.formGroup.value.tomeas;
180
181
182
183
184
185
186
187
188
189
190
191
        console.log(sectorint, "tomeas");
        if (txop.value === "2") {
            console.log("b class");
            this.classCapacitySub = this._hds.getCapacityPerSchool(this.formGroup.value.taxi, sectorint, 0, this.SchoolId).subscribe(data => {
                this.classCapacity$.next(data);
                this.retrievedStudent.next(true);
            },
                error => {
                    this.classCapacity$.next([{}]);
                    console.log("Error Getting Capacity");
                },
                () => console.log("Getting Capacity"));
Open Source Developer's avatar
trans    
Open Source Developer committed
192
        }
193
        if (txop.value === "3") {
Open Source Developer's avatar
Open Source Developer committed
194
            this.StudentSelectedSpecial$ = new BehaviorSubject([{}]);
195
196
            this.StudentSelectedSpecialSub = this._hds.getSpecialityPerSchool(this.SchoolId, sectorint).subscribe(this.StudentSelectedSpecial$);

Open Source Developer's avatar
trans    
Open Source Developer committed
197

Open Source Developer's avatar
Open Source Developer committed
198
        }
Open Source Developer's avatar
trans    
Open Source Developer committed
199
200
201

    }

202
203
204
    checkcclass(tmop, txop, spop) {
        this.modify = false;
        var sectorint = +this.formGroup.value.tomeas;
Open Source Developer's avatar
trans    
Open Source Developer committed
205
        var specialint = +this.formGroup.value.specialit;
206
207
208
209
210
211
212
213
214
215
216
217

        if (txop.value === "3") {
            console.log("c class");
            this.classCapacitySub = this._hds.getCapacityPerSchool(this.formGroup.value.taxi, sectorint, specialint, this.SchoolId).subscribe(data => {
                this.classCapacity$.next(data);
                this.retrievedStudent.next(true);
            },
                error => {
                    this.classCapacity$.next([{}]);
                    console.log("Error Getting Capacity");
                },
                () => console.log("Getting Capacity"));
Open Source Developer's avatar
trans    
Open Source Developer committed
218
219
220

        }

Open Source Developer's avatar
Open Source Developer committed
221
222
223
224
225
    }




226
    saveCapacity() {
Open Source Developer's avatar
Open Source Developer committed
227

228
229
230
231
        var tomeas = +this.formGroup.value.tomeas;
        var specialit = +this.formGroup.value.specialit;
        console.log(tomeas, specialit);
        this._hds.saveCapacity(this.formGroup.value.taxi, tomeas, specialit, this.formGroup.value.capacity, this.SchoolId);
Open Source Developer's avatar
Open Source Developer committed
232

233
    }
Open Source Developer's avatar
Open Source Developer committed
234

235
    modifyCapacity() {
Open Source Developer's avatar
trans    
Open Source Developer committed
236

237
238
        this.modify = true;
    }
Open Source Developer's avatar
trans    
Open Source Developer committed
239

240
}