director-view.ts 5.35 KB
Newer Older
Open Source Developer's avatar
trans  
Open Source Developer committed
1
import { Component, OnInit, OnDestroy,ElementRef, NgZone, 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
        <form [formGroup]="formGroup">
Open Source Developer's avatar
transf  
Open Source Developer committed
25
            <div class="form-group" >
Open Source Developer's avatar
trans  
Open Source Developer committed
26
              <label for="name">Τάξη</label><br/>
Open Source Developer's avatar
trans  
Open Source Developer committed
27
                    <select #txoption [(ngModel)]="taxi" [ngModelOptions]="{standalone: true}" (change)="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
transf  
Open Source Developer committed
33
            <div>
Open Source Developer's avatar
trans  
Open Source Developer committed
34
            <div class="form-group" *ngIf="StudentSelected$ != {} || (verificationCodeVerified | 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: true}"  (change) ="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
tran  
Open Source Developer committed
38
                    </select>
Open Source Developer's avatar
transf  
Open Source Developer committed
39
             <div>
Open Source Developer's avatar
trans  
Open Source Developer committed
40 41 42 43 44 45 46 47 48 49 50

            <div class="form-group" *ngIf="StudentSelectedSpecial$ != {}">
                    <label for="special">Ειδικότητα</label><br/>
                     <select #spop [(ngModel)]="specialit" [ngModelOptions]="{standalone: true}"  >
                      <option *ngFor="let SpecialSelection$  of StudentSelectedSpecial$ | async" [ngValue]="SpecialSelection$.id">{{SpecialSelection$.specialty_id}}</option>
                    </select>
             <div>
             <button type="button" class="btn-primary btn-sm pull-right" (click)="findstudent()">
                Αναζήτηση
             </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
    private verificationCodeVerified: BehaviorSubject<boolean>;
Open Source Developer's avatar
trans  
Open Source Developer committed
63
    public bClassEnabled: boolean;
Open Source Developer's avatar
transf  
Open Source Developer committed
64
    public gClassEnabled: 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 69 70 71 72
    constructor(  private zone: NgZone,
                  private fb: FormBuilder,
                  private _hds: HelperDataService, 
                  private activatedRoute: ActivatedRoute,
                  private router: Router )
Open Source Developer's avatar
Open Source Developer committed
73 74
    {
       this.StudentSelected$ = new BehaviorSubject([{}]);
Open Source Developer's avatar
trans  
Open Source Developer committed
75
       this.StudentSelectedSpecial$ = new BehaviorSubject([{}]);
Open Source Developer's avatar
trans  
Open Source Developer committed
76
       this.verificationCodeVerified = new BehaviorSubject(false);
Open Source Developer's avatar
trans  
Open Source Developer committed
77
       this.formGroup = this.fb.group({
Open Source Developer's avatar
transf  
Open Source Developer committed
78
                taxi:[],
Open Source Developer's avatar
trans  
Open Source Developer committed
79 80
                tomeas: [],
                specialit :[]
Open Source Developer's avatar
trans  
Open Source Developer committed
81
                 });
Open Source Developer's avatar
Open Source Developer committed
82 83 84 85 86 87
    }

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

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

    }
Open Source Developer's avatar
tran  
Open Source Developer committed
93
 
Open Source Developer's avatar
Open Source Developer committed
94 95
    ngOnInit() {
     
Open Source Developer's avatar
transf  
Open Source Developer committed
96 97
       this.bClassEnabled = false;    
       this.gClassEnabled = false;   
Open Source Developer's avatar
trans  
Open Source Developer committed
98
       
Open Source Developer's avatar
trans  
Open Source Developer committed
99 100 101


           
Open Source Developer's avatar
transf  
Open Source Developer committed
102
       console.log(this.StudentSelected$);        
Open Source Developer's avatar
Open Source Developer committed
103 104 105 106

    }


Open Source Developer's avatar
trans  
Open Source Developer committed
107
    verifyclass(txop)
Open Source Developer's avatar
trans  
Open Source Developer committed
108
    {
Open Source Developer's avatar
trans  
Open Source Developer committed
109 110
            console.log(txop.value);
            if (txop.value === "1")
Open Source Developer's avatar
trans  
Open Source Developer committed
111 112 113 114
                 {
                this.zone.run(()=>this.verificationCodeVerified.next(false));

                this.bClassEnabled = false;
Open Source Developer's avatar
transf  
Open Source Developer committed
115 116
                  this.gClassEnabled = false;
            }
Open Source Developer's avatar
trans  
Open Source Developer committed
117
            else if (txop.value === "2")
Open Source Developer's avatar
transf  
Open Source Developer committed
118
            {
Open Source Developer's avatar
trans  
Open Source Developer committed
119 120
                this.verificationCodeVerified.next(true);
                this.StudentSelectedSub = this._hds.getSectorPerSchool(this.SchoolId).subscribe(this.StudentSelected$);
Open Source Developer's avatar
trans  
Open Source Developer committed
121
                console.log(txop.value,"aaaaaa");
Open Source Developer's avatar
transf  
Open Source Developer committed
122 123 124
                this.bClassEnabled = true;
                this.gClassEnabled = false;
            }
Open Source Developer's avatar
trans  
Open Source Developer committed
125
            else if (txop.value === "3")
Open Source Developer's avatar
transf  
Open Source Developer committed
126 127 128
            {   this.bClassEnabled = true;
                this.gClassEnabled = true;
            }            
Open Source Developer's avatar
trans  
Open Source Developer committed
129 130
    }

Open Source Developer's avatar
Open Source Developer committed
131

Open Source Developer's avatar
trans  
Open Source Developer committed
132 133 134 135
    checkbclass(tmop,txop)
    {
        const [id, sector] = tmop.value.split(': ');
        var sectorint = +sector; 
Open Source Developer's avatar
trans  
Open Source Developer committed
136
        console.log(sectorint);
Open Source Developer's avatar
trans  
Open Source Developer committed
137 138
        if (txop.value === "3")
        {
Open Source Developer's avatar
trans  
Open Source Developer committed
139

Open Source Developer's avatar
trans  
Open Source Developer committed
140
            this.StudentSelectedSpecialSub = this._hds.getSpecialityPerSchool(this.SchoolId, sectorint).subscribe(this.StudentSelectedSpecial$);        
Open Source Developer's avatar
trans  
Open Source Developer committed
141
            this.findstudent(sectorint);         
Open Source Developer's avatar
trans  
Open Source Developer committed
142 143 144
        }
    }

Open Source Developer's avatar
trans  
Open Source Developer committed
145
    findstudent(sectorint)
Open Source Developer's avatar
trans  
Open Source Developer committed
146
    {
Open Source Developer's avatar
trans  
Open Source Developer committed
147
       
Open Source Developer's avatar
trans  
Open Source Developer committed
148 149 150 151 152 153 154 155
        {
            this.StudentSelectedSpecialSub = this._hds.getStudentPerSchool(this.SchoolId, sectorint).subscribe(this.StudentSelectedSpecial$);        
        }
    }




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