director-view.ts 7.03 KB
Newer Older
Open Source Developer's avatar
trans  
Open Source Developer committed
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
transf  
Open Source Developer committed
23

Open Source Developer's avatar
trans  
Open Source Developer committed
24
         
Open Source Developer's avatar
trans  
Open Source Developer committed
25 26 27
            
              <label for="taxi">Τάξη</label><br/>
                    <select #txoption [(ngModel)]="taxi" [ngModelOptions]="{standalone: false}" (ngModelChange)="verifyclass(txoption)" >
Open Source Developer's avatar
transf  
Open Source Developer committed
28 29 30
                        <option value="1" >Α' Λυκείου</option>
                        <option value="2" >Β' Λυκείου</option>
                        <option value="3" >Γ' Λυκείου</option>
Open Source Developer's avatar
trans  
Open Source Developer committed
31
                    </select>
Open Source Developer's avatar
trans  
Open Source Developer committed
32
 
Open Source Developer's avatar
trans  
Open Source Developer committed
33 34
            
            <div  *ngIf="StudentSelected$ != {} || (selectionBClass | async)"  >
Open Source Developer's avatar
transf  
Open Source Developer committed
35
                    <label for="tomeas">Τομέας</label><br/>
Open Source Developer's avatar
trans  
Open Source Developer committed
36
                     <select #tmop [(ngModel)]="tomeas" [ngModelOptions]="{standalone: false}"  (ngModelChange) ="checkbclass(tmop,txoption)" >
Open Source Developer's avatar
transf  
Open Source Developer committed
37
                      <option *ngFor="let SectorSelection$  of StudentSelected$ | async" [ngValue]="SectorSelection$.id">{{SectorSelection$.sector_id}}</option>
Open Source Developer's avatar
trans  
Open Source Developer committed
38

Open Source Developer's avatar
tran  
Open Source Developer committed
39
                    </select>
Open Source Developer's avatar
transf  
Open Source Developer committed
40
             <div>
Open Source Developer's avatar
trans  
Open Source Developer committed
41

Open Source Developer's avatar
trans  
Open Source Developer committed
42
            <div  *ngIf="StudentSelectedSpecial$ != {} || (selectionCClass | async)">
Open Source Developer's avatar
trans  
Open Source Developer committed
43
                    <label for="special">Ειδικότητα</label><br/>
Open Source Developer's avatar
trans  
Open Source Developer committed
44
                     <select #spop [(ngModel)]="specialit" [ngModelOptions]="{standalone: false}"  >
Open Source Developer's avatar
trans  
Open Source Developer committed
45 46 47
                      <option *ngFor="let SpecialSelection$  of StudentSelectedSpecial$ | async" [ngValue]="SpecialSelection$.id">{{SpecialSelection$.specialty_id}}</option>
                    </select>
             <div>
Open Source Developer's avatar
trans  
Open Source Developer committed
48
             <button type="button" class="btn-primary btn-sm pull-right" (click)="findstudent(tmop,txoption)">
Open Source Developer's avatar
trans  
Open Source Developer committed
49 50
                Αναζήτηση
             </button>
Open Source Developer's avatar
trans  
Open Source Developer committed
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
             <div *ngIf="StudentInfo$ != {} || (retrievedStudent | async)">
              <div *ngFor="let StudentDetails$  of StudentInfo$ | async">
                 Όνομα:         {{StudentDetails$.name}} <br>
                 Επώνυμο:       {{StudentDetails$.studentsurname}}<br>
                 Όνομα Πατέρα:  {{StudentDetails$.fatherfirstname}}<br>
                 Επώνυμο Πατέρα:{{StudentDetails$.fathersurname}}<br>
                 Όνομα Μητέρας: {{StudentDetails$.motherfirstname}}<br>
                 Επώνυμο Μητέρας:{{StudentDetails$.mothersurname}}<br>
                 Ημερομηνία Γέννησης: {{StudentDetails$.birthdate}}<br>
                 <br>
                 <input #cb type="checkbox" name="{{ StudentDetails$.id }}" (change)="updateCheckedOptions(StudentDetails$.id, $event)" >
                 
             </div>
             </div>
            <button type="button" class="btn-primary btn-sm pull-right" (click)="confirmStudent()">
                 Επιβεβαίωση Εγγραφής
             </button>
         
Open Source Developer's avatar
transf  
Open Source Developer committed
69
              
Open Source Developer's avatar
Open Source Developer committed
70 71 72 73 74
   `
})

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

Open Source Developer's avatar
trans  
Open Source Developer committed
75
    public formGroup: FormGroup;
Open Source Developer's avatar
Open Source Developer committed
76 77
    private StudentSelected$: BehaviorSubject<any>;
    private StudentSelectedSub: Subscription;
Open Source Developer's avatar
trans  
Open Source Developer committed
78 79
    private StudentInfo$: BehaviorSubject<any>;
    private StudentInfoSub: Subscription;
Open Source Developer's avatar
trans  
Open Source Developer committed
80 81
    private StudentSelectedSpecial$: BehaviorSubject<any>;
    private StudentSelectedSpecialSub: Subscription;
Open Source Developer's avatar
trans  
Open Source Developer committed
82
    private retrievedStudent: BehaviorSubject<boolean>;
Open Source Developer's avatar
trans  
Open Source Developer committed
83 84
    private selectionBClass: BehaviorSubject<boolean>;
    private selectionCClass: BehaviorSubject<boolean>;
Open Source Developer's avatar
trans  
Open Source Developer committed
85
    private SchoolId = 147 ;
Open Source Developer's avatar
trans  
Open Source Developer committed
86
    private saved :Array<number> = new Array();
Open Source Developer's avatar
trans  
Open Source Developer committed
87

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

Open Source Developer's avatar
trans  
Open Source Developer committed
89
    constructor(  private fb: FormBuilder,
Open Source Developer's avatar
trans  
Open Source Developer committed
90 91 92
                  private _hds: HelperDataService, 
                  private activatedRoute: ActivatedRoute,
                  private router: Router )
Open Source Developer's avatar
Open Source Developer committed
93 94
    {
       this.StudentSelected$ = new BehaviorSubject([{}]);
Open Source Developer's avatar
trans  
Open Source Developer committed
95
       this.StudentSelectedSpecial$ = new BehaviorSubject([{}]);
Open Source Developer's avatar
trans  
Open Source Developer committed
96 97
       this.StudentInfo$ = new BehaviorSubject([{}]);
       this.retrievedStudent = new BehaviorSubject(false);
Open Source Developer's avatar
trans  
Open Source Developer committed
98 99
       this.selectionBClass = new BehaviorSubject(false);
       this.selectionCClass = new BehaviorSubject(false);
Open Source Developer's avatar
trans  
Open Source Developer committed
100
       
Open Source Developer's avatar
Open Source Developer committed
101 102 103 104 105 106
    }

    ngOnDestroy()
    {
        if (this.StudentSelectedSub)
            this.StudentSelectedSub.unsubscribe();
Open Source Developer's avatar
trans  
Open Source Developer committed
107 108
        if (this.StudentSelectedSpecialSub)
            this.StudentSelectedSpecialSub.unsubscribe();
Open Source Developer's avatar
trans  
Open Source Developer committed
109 110 111 112
        if (this.selectionBClass)
            this.selectionBClass.unsubscribe();
        if (this.selectionCClass)
            this.selectionCClass.unsubscribe();  
Open Source Developer's avatar
trans  
Open Source Developer committed
113

Open Source Developer's avatar
Open Source Developer committed
114 115

    }
Open Source Developer's avatar
tran  
Open Source Developer committed
116
 
Open Source Developer's avatar
Open Source Developer committed
117 118 119 120 121 122
    ngOnInit() {
     

    }


Open Source Developer's avatar
trans  
Open Source Developer committed
123
    verifyclass(txop)
Open Source Developer's avatar
trans  
Open Source Developer committed
124
    {
Open Source Developer's avatar
trans  
Open Source Developer committed
125 126
            console.log(txop.value);
            if (txop.value === "1")
Open Source Developer's avatar
trans  
Open Source Developer committed
127 128 129
            {
                this.selectionBClass.next(false);
                this.selectionCClass.next(false);
Open Source Developer's avatar
transf  
Open Source Developer committed
130
            }
Open Source Developer's avatar
trans  
Open Source Developer committed
131
            else if (txop.value === "2")
Open Source Developer's avatar
transf  
Open Source Developer committed
132
            {
Open Source Developer's avatar
trans  
Open Source Developer committed
133
                this.selectionBClass.next(true);
Open Source Developer's avatar
trans  
Open Source Developer committed
134
                this.StudentSelectedSub = this._hds.getSectorPerSchool(this.SchoolId).subscribe(this.StudentSelected$);
Open Source Developer's avatar
trans  
Open Source Developer committed
135
                
Open Source Developer's avatar
transf  
Open Source Developer committed
136
            }
Open Source Developer's avatar
trans  
Open Source Developer committed
137
            else if (txop.value === "3")
Open Source Developer's avatar
trans  
Open Source Developer committed
138 139 140 141
            {   
              this.selectionBClass.next(true);
              this.selectionCClass.next(true);              
              this.StudentSelectedSub = this._hds.getSectorPerSchool(this.SchoolId).subscribe(this.StudentSelected$);
Open Source Developer's avatar
transf  
Open Source Developer committed
142
            }            
Open Source Developer's avatar
trans  
Open Source Developer committed
143 144
    }

Open Source Developer's avatar
Open Source Developer committed
145

Open Source Developer's avatar
trans  
Open Source Developer committed
146 147 148 149
    checkbclass(tmop,txop)
    {
        const [id, sector] = tmop.value.split(': ');
        var sectorint = +sector; 
Open Source Developer's avatar
trans  
Open Source Developer committed
150
        console.log(sectorint);
Open Source Developer's avatar
trans  
Open Source Developer committed
151 152 153 154 155 156
        if (txop.value === "3")
        {
            this.StudentSelectedSpecialSub = this._hds.getSpecialityPerSchool(this.SchoolId, sectorint).subscribe(this.StudentSelectedSpecial$);        
        }
    }

Open Source Developer's avatar
trans  
Open Source Developer committed
157
    findstudent(tmop,txop)
Open Source Developer's avatar
trans  
Open Source Developer committed
158
    {
Open Source Developer's avatar
trans  
Open Source Developer committed
159
       
Open Source Developer's avatar
trans  
Open Source Developer committed
160 161 162
            const [id, sector] = tmop.value.split(': ');
            var sectorint = +sector; 
            console.log(sectorint,"aaaaaa");
Open Source Developer's avatar
trans  
Open Source Developer committed
163 164
            this.StudentInfoSub = this._hds.getStudentPerSchool(this.SchoolId, sectorint).subscribe(this.StudentInfo$);        
            this.retrievedStudent.next(true);
Open Source Developer's avatar
trans  
Open Source Developer committed
165
        
Open Source Developer's avatar
trans  
Open Source Developer committed
166 167
    }

Open Source Developer's avatar
trans  
Open Source Developer committed
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
updateCheckedOptions(id, event)
{

    let i = this.saved.length;

       
    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
191

Open Source Developer's avatar
trans  
Open Source Developer committed
192 193 194 195 196
confirmStudent()
{
    
     this._hds.saveConfirmStudents(this.saved);
}
Open Source Developer's avatar
trans  
Open Source Developer committed
197 198


Open Source Developer's avatar
Open Source Developer committed
199
}