director-view.ts 16.8 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
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';
Open Source Developer's avatar
tran    
Open Source Developer committed
7
import { NgRedux, select } from 'ng2-redux';
Open Source Developer's avatar
Open Source Developer committed
8
9
10
import { IAppState } from '../../store/store';
import {Router, ActivatedRoute, Params} from '@angular/router';
import { BehaviorSubject, Subscription } from 'rxjs/Rx';
Open Source Developer's avatar
transf    
Open Source Developer committed
11
import { ILoginInfo } from '../../store/logininfo/logininfo.types';
Open Source Developer's avatar
trans    
Open Source Developer committed
12

Open Source Developer's avatar
trans    
Open Source Developer committed
13
14
15
16
17
18
19
import {
    FormBuilder,
    FormGroup,
    FormControl,
    FormArray,
    Validators,
} from '@angular/forms';
Open Source Developer's avatar
Open Source Developer committed
20
21
22
@Component({
    selector: 'director-view',
    template: `
Open Source Developer's avatar
trans    
Open Source Developer committed
23
  <form [formGroup]="formGroup">
Open Source Developer's avatar
paging    
Open Source Developer committed
24
25
       

Open Source Developer's avatar
trans    
Open Source Developer committed
26
27
28
29
30
31
32
      <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>
33
      </div>
Open Source Developer's avatar
trans    
Open Source Developer committed
34
      <div class="form-group">
Open Source Developer's avatar
trans    
Open Source Developer committed
35
            <select #tmop class="form-control" *ngIf="(selectionBClass | async)" (change)="checkbclass(tmop,txoption)" formControlName="tomeas">
Open Source Developer's avatar
trans    
Open Source Developer committed
36
              <option *ngFor="let SectorSelection$  of StudentSelected$ | async; let i=index" [value] = "SectorSelection$.id"> {{SectorSelection$.sector_id}} </option>
Open Source Developer's avatar
trans    
Open Source Developer committed
37
38
39
            </select>
      </div>
      <div class="form-group">
Open Source Developer's avatar
trans    
Open Source Developer committed
40
41
            <select #spop class="form-control" *ngIf="(selectionCClass | async)" (change) ="checkcclass()" formControlName="specialit">
              <option *ngFor="let SpecialSelection$  of StudentSelectedSpecial$ | async; let i=index" [value] = "SpecialSelection$.id"> {{SpecialSelection$.specialty_id}} </option>
Open Source Developer's avatar
trans    
Open Source Developer committed
42
43
            </select>
      </div>
Open Source Developer's avatar
paging    
Open Source Developer committed
44
            <button type="button" class="btn-primary btn-sm pull-right" (click)="findstudent(txoption,1)">
Open Source Developer's avatar
trans    
Open Source Developer committed
45
46
                Αναζήτηση
             </button>
47

Open Source Developer's avatar
trans    
Open Source Developer committed
48
49
50
51
52
53
54
55

              <ul class="list-group main-view">
              <div *ngIf="(retrievedStudent | async)">

               <div *ngFor="let StudentDetails$  of StudentInfo$ | async; let i=index; let isOdd=odd; let isEven=even"  >
                 <li class="list-group-item isclickable" [class.oddout]="isOdd" [class.evenout]="isEven" (click)="setActiveUser(StudentDetails$.i)" [class.selectedout]="userActive === StudentDetails$.i" >
                  <h5> {{StudentDetails$.name}}&nbsp;{{StudentDetails$.name}} </h5>
                </li>
56
                 <strong>Επιβεβαίωση Εγγραφής: </strong>
Open Source Developer's avatar
Open Source Developer committed
57
                 <input #cb class="pull-right" type="checkbox" name="{{ StudentDetails$.id }}" (change)="updateCheckedOptions(StudentDetails$.id, $event)" >
58

Open Source Developer's avatar
trans    
Open Source Developer committed
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
                  <div [hidden]="userActive !== StudentDetails$.i" >
                      <table>
                        <tr><td>
                          <div class="form-group" *ngIf="StudentDetails$.relationtostudent === 'Μαθητής' ">
                            <label for="guardianfirstname">Όνομα κηδεμόνα</label><p class="form-control" id="guardianfirstname" style="border:1px solid #eceeef;">{{StudentDetails$.guardianfirstname}} </p> 
                          </div>
                        </td>
                        <td>
                         <div class="form-group" *ngIf="StudentDetails$.relationtostudent === 'Μαθητής' ">
                            <label for="guardiansurname">Επώνυμο κηδεμόνα</label><p class="form-control" id="guardiansurname" style="border:1px solid #eceeef;">{{StudentDetails$.guardiansurname}} </p> 
                          </div>
                        </td></tr>
                      </table>
                      <div class="form-group"><label for="name">Όνομα μαθητή</label> <p class="form-control" id="name" style="border:1px solid #eceeef;">    {{StudentDetails$.name}} </p> </div>
                      <div><label for="studentsurname">Επώνυμο μαθητή</label> <p class="form-control" id = "studentsurname" style="border:1px solid #eceeef;"> {{StudentDetails$.studentsurname}} </p></div>
                      <div><label for="fatherfirstname">Όνομα Πατέρα</label> <p class="form-control" id = "fatherfirstname" style="border:1px solid #eceeef;"> {{StudentDetails$.fatherfirstname}} </p></div>
                      <div><label for="fathersurname">Επώνυμο Πατέρα</label> <p class="form-control" id = "fathersurname" style="border:1px solid #eceeef;"> {{StudentDetails$.fathersurname}} </p></div>
                      <div><label for="motherfirstname">Όνομα Μητέρας</label> <p class="form-control" id = "motherfirstname" style="border:1px solid #eceeef;"> {{StudentDetails$.motherfirstname}} </p></div>
                      <div><label for="mothersurname">Επώνυμο Μητέρας</label> <p class="form-control" id = "mothersurname" style="border:1px solid #eceeef;"> {{StudentDetails$.mothersurname}} </p></div>                
                      <div><label for="birthdate">Ημερομηνία Γέννησης</label> <p class="form-control" id = "birthdate" style="border:1px solid #eceeef;"> {{StudentDetails$.birthdate}} </p></div>                


                      <table>
                              <tr>
                                  <td>
                                      <div class="form-group">
                                          <label for="regionaddress">Διεύθυνση κατοικίας</label><p class="form-control" id = "regionaddress" style="border:1px solid #eceeef;"> {{StudentDetails$.regionaddress}} </p>
                                      </div>
                                  </td>
                                  <td>
                                      <div class="form-group">
                                          <label for="regiontk">TK </label><p class="form-control" id = "regiontk" style="border:1px solid #eceeef;"> {{StudentDetails$.regiontk}} </p>
                                      </div>
                                  </td>
                                  <td>
                                      <div class="form-group">
                                          <label for="regionarea">Πόλη/Περιοχή</label><p class="form-control" id = "regionarea" style="border:1px solid #eceeef;"> {{StudentDetails$.regionarea}} </p>
                                      </div>
                                  </td>
                             </tr>
                      </table>
                      <div><label for="certificatetype">Τύπος απολυτηρίου</label> <p class="form-control" id = "certificatetype" style="border:1px solid #eceeef;"> {{StudentDetails$.certificatetype}} </p></div>                
                      <div><label for="telnum">Τηλέφωνο επικοινωνίας</label> <p class="form-control" id = "telnum" style="border:1px solid #eceeef;"> {{StudentDetails$.telnum}} </p></div>                
                      <div><label for="relationtostudent">Η αίτηση γίνεται από</label> <p class="form-control" id = "relationtostudent" style="border:1px solid #eceeef;"> {{StudentDetails$.relationtostudent}} </p></div>                 
                 </div>
104
<!--             </div>  -->
Open Source Developer's avatar
trans    
Open Source Developer committed
105
             </div>
Open Source Developer's avatar
paging    
Open Source Developer committed
106
107
108
109
110
111
112
113
114
115
116
117
118
119

          <br>
          <br>
         <div class="form-group" class="row">
          Βρίσκεστε στη σελίδα:
          <div class="col-1">
           <input #pageno type="text" class="form-control" placeholder=".col-1" formControlName="pageno">
          </div> 
           απο  
           <div class="col-1">
           <input #maxpage type="text" class="form-control" placeholder=".col-1" formControlName="maxpage">
           </div>   
         </div>
 
Open Source Developer's avatar
trans    
Open Source Developer committed
120
121
122
            <button type="button" class="btn-primary btn-sm pull-right" (click)="confirmStudent()">
                 Επιβεβαίωση Εγγραφής
             </button>
Open Source Developer's avatar
paging    
Open Source Developer committed
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
             <br>
             <nav aria-label="pagination">
              <ul class="pagination justify-content-center">
                <li class="page-item " >
                  <button class="page-link" (click)="prevpage(txoption)">Προηγούμενη</button>
                </li>
                <li class="page-item">
                  <button class="page-link" (click) ="nextpage(txoption,maxpage) ">Επόμενη</button>
                </li>
              </ul>
              
            </nav>
     
       

Open Source Developer's avatar
Open Source Developer committed
138
139
140
   `
})

141
@Injectable() export default class DirectorView implements OnInit, OnDestroy {
Open Source Developer's avatar
Open Source Developer committed
142

Open Source Developer's avatar
trans    
Open Source Developer committed
143
    public formGroup: FormGroup;
Open Source Developer's avatar
Open Source Developer committed
144
145
    private StudentSelected$: BehaviorSubject<any>;
    private StudentSelectedSub: Subscription;
Open Source Developer's avatar
trans    
Open Source Developer committed
146
147
    private StudentInfo$: BehaviorSubject<any>;
    private StudentInfoSub: Subscription;
Open Source Developer's avatar
paging    
Open Source Developer committed
148
149
    private StudentsSize$: BehaviorSubject<any>;
    private StudentsSizeSub: Subscription;
Open Source Developer's avatar
trans    
Open Source Developer committed
150
151
    private StudentSelectedSpecial$: BehaviorSubject<any>;
    private StudentSelectedSpecialSub: Subscription;
Open Source Developer's avatar
trans    
Open Source Developer committed
152
153
    private SubmitedDetails$: BehaviorSubject<any>;
    private SubmitedDetailsSub: Subscription;
Open Source Developer's avatar
trans    
Open Source Developer committed
154
    private retrievedStudent: BehaviorSubject<boolean>;
Open Source Developer's avatar
trans    
Open Source Developer committed
155
156
    private selectionBClass: BehaviorSubject<boolean>;
    private selectionCClass: BehaviorSubject<boolean>;
157
    private SchoolId = 147;
Open Source Developer's avatar
trans    
Open Source Developer committed
158
    private currentclass: Number;
159
    private saved: Array<number> = new Array();
Open Source Developer's avatar
paging    
Open Source Developer committed
160
161
162
    private limitdown = 0; 
    private limitup=  5;
    private pageno = 1;
Open Source Developer's avatar
trans    
Open Source Developer committed
163
    private userActive = <number>-1;
164
165
166
167
168
169
170
171
172


    constructor(private fb: FormBuilder,
        private _hds: HelperDataService,
        private activatedRoute: ActivatedRoute,
        private router: Router) {
        this.StudentSelected$ = new BehaviorSubject([{}]);
        this.StudentSelectedSpecial$ = new BehaviorSubject([{}]);
        this.StudentInfo$ = new BehaviorSubject([{}]);
Open Source Developer's avatar
paging    
Open Source Developer committed
173
        this.StudentsSize$ = new BehaviorSubject({});
Open Source Developer's avatar
trans    
Open Source Developer committed
174
        this.SubmitedDetails$ = new BehaviorSubject([{}]);
175
176
177
178
179
180
181
        this.retrievedStudent = new BehaviorSubject(false);
        this.selectionBClass = new BehaviorSubject(false);
        this.selectionCClass = new BehaviorSubject(false);
        this.formGroup = this.fb.group({
            tomeas: ['', []],
            taxi: ['', []],
            specialit: ['', []],
Open Source Developer's avatar
paging    
Open Source Developer committed
182
183
            maxpage:[{value: '', disabled: true}, []],
            pageno:[{value: '', disabled: true}, []],
184
        });
185

Open Source Developer's avatar
Open Source Developer committed
186
187
    }

188
    ngOnDestroy() {
Open Source Developer's avatar
Open Source Developer committed
189
190
        if (this.StudentSelectedSub)
            this.StudentSelectedSub.unsubscribe();
Open Source Developer's avatar
trans    
Open Source Developer committed
191
192
        if (this.StudentSelectedSpecialSub)
            this.StudentSelectedSpecialSub.unsubscribe();
Open Source Developer's avatar
trans    
Open Source Developer committed
193
194
195
        if (this.selectionBClass)
            this.selectionBClass.unsubscribe();
        if (this.selectionCClass)
196
            this.selectionCClass.unsubscribe();
197
        if (this.retrievedStudent)
Open Source Developer's avatar
Open Source Developer committed
198
            this.retrievedStudent.unsubscribe();
Open Source Developer's avatar
trans    
Open Source Developer committed
199
200
201
        if (this.SubmitedDetailsSub)
            this.SubmitedDetailsSub.unsubscribe();
        
Open Source Developer's avatar
Open Source Developer committed
202
    }
203

Open Source Developer's avatar
Open Source Developer committed
204
205
206
207
208
    ngOnInit() {

    }


209
    verifyclass(txop) {
Open Source Developer's avatar
paging    
Open Source Developer committed
210
        this.pageno = 1;
211
212
213
214
        this.retrievedStudent.next(false);
        if (txop.value === "1") {
            this.selectionBClass.next(false);
            this.selectionCClass.next(false);
Open Source Developer's avatar
trans    
Open Source Developer committed
215

216
217
218
        }
        else if (txop.value === "2") {
            this.StudentSelectedSub = this._hds.getSectorPerSchool(this.SchoolId).subscribe(data => {
Open Source Developer's avatar
trans    
Open Source Developer committed
219
                this.selectionBClass.next(true);
Open Source Developer's avatar
trans    
Open Source Developer committed
220
                this.selectionCClass.next(false);
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
                this.StudentSelected$.next(data);

            },
                error => {
                    this.StudentSelected$.next([{}]);
                    console.log("Error Getting StudentSelectedSpecial");
                },
                () => console.log("Getting StudentSelectedSpecial"));
        }
        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.StudentSelectedSpecialSub = this._hds.getSpecialityPerSchool(this.SchoolId, sectorint).subscribe(data => {
                    this.StudentSelectedSpecial$.next(data);
                },
                    error => {
                        this.StudentSelectedSpecial$.next([{}]);
                        console.log("Error Getting StudentSelectedSpecial");
                    },
                    () => console.log("Getting StudentSelectedSpecial"));
244
            }
245
246
247
248
249
250
251
252
253
254
255
256

            this.StudentSelectedSub = this._hds.getSectorPerSchool(this.SchoolId).subscribe(data => {
                this.StudentSelected$.next(data);
                this.selectionBClass.next(true);
                this.selectionCClass.next(true);
            },
                error => {
                    this.StudentSelected$.next([{}]);
                    console.log("Error Getting StudentSelected");
                },
                () => console.log("Getting StudentSelected"));
        }
Open Source Developer's avatar
trans    
Open Source Developer committed
257
258
    }

Open Source Developer's avatar
Open Source Developer committed
259

260
    checkbclass(tmop, txop) {
Open Source Developer's avatar
paging    
Open Source Developer committed
261
        this.pageno = 1;
Open Source Developer's avatar
trans    
Open Source Developer committed
262
263
        this.retrievedStudent.next(false);
        var sectorint = +this.formGroup.value.tomeas;
264
265
266
267
268
269
270
271
272
273
274
275
        console.log(sectorint, "tomeas");
        if (txop.value === "3") {
            //            this.StudentSelectedSpecial$ = new BehaviorSubject([{}]);
            this.StudentSelectedSpecialSub = this._hds.getSpecialityPerSchool(this.SchoolId, sectorint).subscribe(data => {
                this.StudentSelectedSpecial$.next(data);

            },
                error => {
                    this.StudentSelectedSpecial$.next([{}]);
                    console.log("Error Getting StudentSelectedSpecial");
                },
                () => console.log("Getting StudentSelectedSpecial"));
Open Source Developer's avatar
trans    
Open Source Developer committed
276
277
278
        }
    }

Open Source Developer's avatar
paging    
Open Source Developer committed
279
    findstudent(txop, pageno) {
280

Open Source Developer's avatar
paging    
Open Source Developer committed
281
        var tot_pages: Number;
282
283
284
285
286
287
288
289
290
291
        var sectorint = +this.formGroup.value.tomeas;
        if (txop.value === "1") {
            this.currentclass = 1;
        }
        else if (txop.value === "2") {
            this.currentclass = 2;
        }
        else if (txop.value === "3") {
            this.currentclass = 3;
        }
292

Open Source Developer's avatar
paging    
Open Source Developer committed
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
         this.formGroup.get('pageno').setValue(this.pageno); 
         if (this.pageno == 1){
            console.log(this.SchoolId, sectorint, this.currentclass,"test");            
            this.StudentsSizeSub = this._hds.getStudentPerSchool(this.SchoolId, sectorint, this.currentclass, 0, 0).subscribe(x => {
                this.StudentsSize$.next(x);
                tot_pages = x.id /5;
                if (x.id%5 >0)
                {
                    tot_pages = (x.id - (x.id%5))/5 +1;
                }  
                this.formGroup.get('maxpage').setValue(tot_pages); 
                });

        }            
     
308
309
        //            this.StudentInfo$ = new BehaviorSubject([{}]);
        //            this.StudentInfoSub = this._hds.getStudentPerSchool(this.SchoolId, sectorint, this.currentclass).subscribe(this.StudentInfo$);
Open Source Developer's avatar
paging    
Open Source Developer committed
310
        this.StudentInfoSub = this._hds.getStudentPerSchool(this.SchoolId, sectorint, this.currentclass, this.limitdown, this.limitup).subscribe(data => {
311
312
313
314
315
316
317
318
            this.StudentInfo$.next(data);
            this.retrievedStudent.next(true);
        },
            error => {
                this.StudentInfo$.next([{}]);
                console.log("Error Getting Students");
            },
            () => console.log("Getting Students"));
319

Open Source Developer's avatar
trans    
Open Source Developer committed
320
321
    }

322
    updateCheckedOptions(id, event) {
Open Source Developer's avatar
trans    
Open Source Developer committed
323

324
        let i = this.saved.length;
Open Source Developer's avatar
trans    
Open Source Developer committed
325

326

327
328
329
330
331
332
333
334
335
336
        if (event.target.checked === false) {
            var count = this.saved.length;
            for (var j = 0; j < count; j++) {
                if (this.saved[j] === id) {
                    this.saved.splice(j, 1);
                }
            }
        }
        else {
            this.saved[i] = id;
Open Source Developer's avatar
trans    
Open Source Developer committed
337
338
        }

339
    }
Open Source Developer's avatar
trans    
Open Source Developer committed
340

341
342
343
    confirmStudent() {
        this._hds.saveConfirmStudents(this.saved);
    }
Open Source Developer's avatar
trans    
Open Source Developer committed
344

345
    checkcclass() {
Open Source Developer's avatar
paging    
Open Source Developer committed
346
        this.pageno = 1;
347
348
        this.retrievedStudent.next(false);
    }
Open Source Developer's avatar
trans    
Open Source Developer committed
349

Open Source Developer's avatar
paging    
Open Source Developer committed
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
    nextpage(txop, maxpage){
     console.log(maxpage.value);   
     if (this.pageno < maxpage.value)
      {
           this.pageno = this.pageno+1;
           this.limitdown = (this.pageno-1) * 5 ;
           this.limitup = this.pageno * 5;
           this.findstudent(txop, this.pageno)
       }
    }

    prevpage(txop){
       console.log(this.pageno,"pageno");
       if (this.pageno > 1)
       {
           this.pageno = this.pageno-1;
           this.limitdown = (this.pageno-1) * 5 ;
           this.limitup = this.pageno * 5;
           this.findstudent(txop, this.pageno)
       }

    }


Open Source Developer's avatar
trans    
Open Source Developer committed
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388

  setActiveUser(ind) 
  {
      ind = +ind;
      console.log(this.userActive,"RA",ind);
      if (ind === this.userActive){
        ind = -1;
      }
      ind--;
      this.userActive = ind+1 ;
      

   }


389
}