director-view.ts 5.28 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 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
transf  
Open Source Developer committed
51
              
Open Source Developer's avatar
Open Source Developer committed
52 53 54 55 56
   `
})

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

Open Source Developer's avatar
trans  
Open Source Developer committed
57
    public formGroup: FormGroup;
Open Source Developer's avatar
Open Source Developer committed
58 59
    private StudentSelected$: BehaviorSubject<any>;
    private StudentSelectedSub: Subscription;
Open Source Developer's avatar
trans  
Open Source Developer committed
60 61
    private StudentSelectedSpecial$: BehaviorSubject<any>;
    private StudentSelectedSpecialSub: Subscription;
Open Source Developer's avatar
trans  
Open Source Developer committed
62 63 64
    private selectionAClass: BehaviorSubject<boolean>;
    private selectionBClass: BehaviorSubject<boolean>;
    private selectionCClass: BehaviorSubject<boolean>;
Open Source Developer's avatar
trans  
Open Source Developer committed
65 66
    private SchoolId = 147 ;

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

Open Source Developer's avatar
trans  
Open Source Developer committed
68
    constructor(  private fb: FormBuilder,
Open Source Developer's avatar
trans  
Open Source Developer committed
69 70 71
                  private _hds: HelperDataService, 
                  private activatedRoute: ActivatedRoute,
                  private router: Router )
Open Source Developer's avatar
Open Source Developer committed
72 73
    {
       this.StudentSelected$ = new BehaviorSubject([{}]);
Open Source Developer's avatar
trans  
Open Source Developer committed
74
       this.StudentSelectedSpecial$ = new BehaviorSubject([{}]);
Open Source Developer's avatar
trans  
Open Source Developer committed
75 76 77
       this.selectionAClass = new BehaviorSubject(false);
       this.selectionBClass = new BehaviorSubject(false);
       this.selectionCClass = new BehaviorSubject(false);
Open Source Developer's avatar
trans  
Open Source Developer committed
78
       this.formGroup = this.fb.group({
Open Source Developer's avatar
transf  
Open Source Developer committed
79
                taxi:[],
Open Source Developer's avatar
trans  
Open Source Developer committed
80 81
                tomeas: [],
                specialit :[]
Open Source Developer's avatar
trans  
Open Source Developer committed
82
                 });
Open Source Developer's avatar
Open Source Developer committed
83 84 85 86 87 88
    }

    ngOnDestroy()
    {
        if (this.StudentSelectedSub)
            this.StudentSelectedSub.unsubscribe();
Open Source Developer's avatar
trans  
Open Source Developer committed
89 90 91
        if (this.StudentSelectedSpecialSub)
            this.StudentSelectedSpecialSub.unsubscribe();

Open Source Developer's avatar
Open Source Developer committed
92 93

    }
Open Source Developer's avatar
tran  
Open Source Developer committed
94
 
Open Source Developer's avatar
Open Source Developer committed
95 96 97 98 99 100
    ngOnInit() {
     

    }


Open Source Developer's avatar
trans  
Open Source Developer committed
101
    verifyclass(txop)
Open Source Developer's avatar
trans  
Open Source Developer committed
102
    {
Open Source Developer's avatar
trans  
Open Source Developer committed
103 104
            console.log(txop.value);
            if (txop.value === "1")
Open Source Developer's avatar
trans  
Open Source Developer committed
105 106 107
            {
                this.selectionBClass.next(false);
                this.selectionCClass.next(false);
Open Source Developer's avatar
transf  
Open Source Developer committed
108
            }
Open Source Developer's avatar
trans  
Open Source Developer committed
109
            else if (txop.value === "2")
Open Source Developer's avatar
transf  
Open Source Developer committed
110
            {
Open Source Developer's avatar
trans  
Open Source Developer committed
111
                this.selectionBClass.next(true);
Open Source Developer's avatar
trans  
Open Source Developer committed
112
                this.StudentSelectedSub = this._hds.getSectorPerSchool(this.SchoolId).subscribe(this.StudentSelected$);
Open Source Developer's avatar
trans  
Open Source Developer committed
113
                
Open Source Developer's avatar
transf  
Open Source Developer committed
114
            }
Open Source Developer's avatar
trans  
Open Source Developer committed
115
            else if (txop.value === "3")
Open Source Developer's avatar
trans  
Open Source Developer committed
116 117 118 119
            {   
              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
120
            }            
Open Source Developer's avatar
trans  
Open Source Developer committed
121 122
    }

Open Source Developer's avatar
Open Source Developer committed
123

Open Source Developer's avatar
trans  
Open Source Developer committed
124 125 126 127
    checkbclass(tmop,txop)
    {
        const [id, sector] = tmop.value.split(': ');
        var sectorint = +sector; 
Open Source Developer's avatar
trans  
Open Source Developer committed
128
        console.log(sectorint);
Open Source Developer's avatar
trans  
Open Source Developer committed
129 130 131 132 133 134
        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
135
    findstudent(tmop,txop)
Open Source Developer's avatar
trans  
Open Source Developer committed
136
    {
Open Source Developer's avatar
trans  
Open Source Developer committed
137
       
Open Source Developer's avatar
trans  
Open Source Developer committed
138 139 140
            const [id, sector] = tmop.value.split(': ');
            var sectorint = +sector; 
            console.log(sectorint,"aaaaaa");
Open Source Developer's avatar
trans  
Open Source Developer committed
141
            this.StudentSelectedSpecialSub = this._hds.getStudentPerSchool(this.SchoolId, sectorint).subscribe(this.StudentSelectedSpecial$);        
Open Source Developer's avatar
trans  
Open Source Developer committed
142
        
Open Source Developer's avatar
trans  
Open Source Developer committed
143 144 145 146 147
    }




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