director-view.ts 7.86 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
trans  
Open Source Developer committed
23 24 25 26 27 28 29 30
  <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>
31
      </div>
Open Source Developer's avatar
trans  
Open Source Developer committed
32
      <div class="form-group">
Open Source Developer's avatar
trans  
Open Source Developer committed
33 34

            <select #tmop class="form-control" *ngIf="(selectionBClass | async)" (change)="checkbclass(tmop,txoption)" formControlName="tomeas">
Open Source Developer's avatar
trans  
Open Source Developer committed
35
              <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
36 37 38
            </select>
      </div>
      <div class="form-group">
Open Source Developer's avatar
trans  
Open Source Developer committed
39 40
            <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
41 42
            </select>
      </div>
Open Source Developer's avatar
trans  
Open Source Developer committed
43
            <button type="button" class="btn-primary btn-sm pull-right" (click)="findstudent(txoption)">
Open Source Developer's avatar
trans  
Open Source Developer committed
44 45
                Αναζήτηση
             </button>
Open Source Developer's avatar
trans  
Open Source Developer committed
46
             <div *ngIf="(retrievedStudent | async)">
Open Source Developer's avatar
trans  
Open Source Developer committed
47
              <div *ngFor="let StudentDetails$  of StudentInfo$ | async">
Open Source Developer's avatar
Open Source Developer committed
48 49
                <br>
                <br>
Open Source Developer's avatar
trans  
Open Source Developer committed
50 51 52 53 54 55 56
                 Όνομα:         {{StudentDetails$.name}} <br>
                 Επώνυμο:       {{StudentDetails$.studentsurname}}<br>
                 Όνομα Πατέρα:  {{StudentDetails$.fatherfirstname}}<br>
                 Επώνυμο Πατέρα:{{StudentDetails$.fathersurname}}<br>
                 Όνομα Μητέρας: {{StudentDetails$.motherfirstname}}<br>
                 Επώνυμο Μητέρας:{{StudentDetails$.mothersurname}}<br>
                 Ημερομηνία Γέννησης: {{StudentDetails$.birthdate}}<br>
57 58

                 <strong>Επιβεβαίωση Εγγραφής: </strong>
Open Source Developer's avatar
Open Source Developer committed
59
                 <input #cb class="pull-right" type="checkbox" name="{{ StudentDetails$.id }}" (change)="updateCheckedOptions(StudentDetails$.id, $event)" >
60

Open Source Developer's avatar
trans  
Open Source Developer committed
61 62 63 64 65
             </div>
             </div>
            <button type="button" class="btn-primary btn-sm pull-right" (click)="confirmStudent()">
                 Επιβεβαίωση Εγγραφής
             </button>
Open Source Developer's avatar
Open Source Developer committed
66 67 68 69 70
   `
})

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

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

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

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

Open Source Developer's avatar
Open Source Developer committed
103 104 105 106 107 108
    }

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

Open Source Developer's avatar
Open Source Developer committed
119 120 121 122 123
    ngOnInit() {

    }


Open Source Developer's avatar
trans  
Open Source Developer committed
124
    verifyclass(txop)
Open Source Developer's avatar
trans  
Open Source Developer committed
125
    {
Open Source Developer's avatar
trans  
Open Source Developer committed
126
            this.retrievedStudent.next(false);
Open Source Developer's avatar
trans  
Open Source Developer committed
127
            if (txop.value === "1")
Open Source Developer's avatar
trans  
Open Source Developer committed
128 129 130
            {
                this.selectionBClass.next(false);
                this.selectionCClass.next(false);
Open Source Developer's avatar
trans  
Open Source Developer committed
131

Open Source Developer's avatar
transf  
Open Source Developer committed
132
            }
Open Source Developer's avatar
trans  
Open Source Developer committed
133
            else if (txop.value === "2")
Open Source Developer's avatar
transf  
Open Source Developer committed
134
            {
Open Source Developer's avatar
trans  
Open Source Developer committed
135
                this.selectionBClass.next(true);
Open Source Developer's avatar
trans  
Open Source Developer committed
136
                this.selectionCClass.next(false);
137

Open Source Developer's avatar
trans  
Open Source Developer committed
138
                this.StudentSelectedSub = this._hds.getSectorPerSchool(this.SchoolId).subscribe(this.StudentSelected$);
Open Source Developer's avatar
transf  
Open Source Developer committed
139
            }
Open Source Developer's avatar
trans  
Open Source Developer committed
140
            else if (txop.value === "3")
141
            {
Open Source Developer's avatar
Open Source Developer committed
142 143 144 145 146
              var sectorint = +this.formGroup.value.tomeas;
              console.log(sectorint,"test");
              if (this.formGroup.value.tomeas != '')
              {
                  var sectorint = +this.formGroup.value.tomeas;
147 148

                  this.StudentSelectedSpecialSub = this._hds.getSpecialityPerSchool(this.SchoolId, sectorint).subscribe(this.StudentSelectedSpecial$);
Open Source Developer's avatar
Open Source Developer committed
149
              }
Open Source Developer's avatar
trans  
Open Source Developer committed
150
              this.selectionBClass.next(true);
151
              this.selectionCClass.next(true);
Open Source Developer's avatar
trans  
Open Source Developer committed
152
              this.StudentSelectedSub = this._hds.getSectorPerSchool(this.SchoolId).subscribe(this.StudentSelected$);
153
            }
Open Source Developer's avatar
trans  
Open Source Developer committed
154 155
    }

Open Source Developer's avatar
Open Source Developer committed
156

Open Source Developer's avatar
trans  
Open Source Developer committed
157
    checkbclass(tmop,txop)
Open Source Developer's avatar
trans  
Open Source Developer committed
158
    {
Open Source Developer's avatar
trans  
Open Source Developer committed
159 160 161
        this.retrievedStudent.next(false);
        var sectorint = +this.formGroup.value.tomeas;
        console.log(sectorint,"tomeas");
Open Source Developer's avatar
trans  
Open Source Developer committed
162 163
        if (txop.value === "3")
        {
Open Source Developer's avatar
trans  
Open Source Developer committed
164
            this.StudentSelectedSpecial$ = new BehaviorSubject([{}]);
165
            this.StudentSelectedSpecialSub = this._hds.getSpecialityPerSchool(this.SchoolId, sectorint).subscribe(this.StudentSelectedSpecial$);
Open Source Developer's avatar
trans  
Open Source Developer committed
166 167 168
        }
    }

Open Source Developer's avatar
trans  
Open Source Developer committed
169
    findstudent(txop)
Open Source Developer's avatar
trans  
Open Source Developer committed
170
    {
171

Open Source Developer's avatar
trans  
Open Source Developer committed
172 173 174 175 176 177 178 179 180 181
            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")
182
            {
Open Source Developer's avatar
trans  
Open Source Developer committed
183
              this.currentclass = 3;
184
            }
Open Source Developer's avatar
trans  
Open Source Developer committed
185
            this.retrievedStudent.next(true);
Open Source Developer's avatar
Open Source Developer committed
186
            this.StudentInfo$ = new BehaviorSubject(false);
187 188 189 190
            this.StudentInfoSub = this._hds.getStudentPerSchool(this.SchoolId, sectorint, this.currentclass).subscribe(this.StudentInfo$);



Open Source Developer's avatar
trans  
Open Source Developer committed
191 192
    }

Open Source Developer's avatar
trans  
Open Source Developer committed
193 194 195 196 197
updateCheckedOptions(id, event)
{

    let i = this.saved.length;

198 199

    if (event.target.checked === false)
Open Source Developer's avatar
trans  
Open Source Developer committed
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
    {
      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
216

Open Source Developer's avatar
trans  
Open Source Developer committed
217 218
confirmStudent()
{
Open Source Developer's avatar
trans  
Open Source Developer committed
219
   this._hds.saveConfirmStudents(this.saved);
Open Source Developer's avatar
trans  
Open Source Developer committed
220
}
Open Source Developer's avatar
trans  
Open Source Developer committed
221

Open Source Developer's avatar
trans  
Open Source Developer committed
222 223 224 225
checkcclass()
{
  this.retrievedStudent.next(false);
}
Open Source Developer's avatar
trans  
Open Source Developer committed
226

227
}