director-classcapacity.ts 8.33 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
7
8
9
10
11
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';
import { NgRedux, select } from 'ng2-redux';
import { IAppState } from '../../store/store';
import {Router, ActivatedRoute, Params} from '@angular/router';
import { BehaviorSubject, Subscription } from 'rxjs/Rx';
import { ILoginInfo } from '../../store/logininfo/logininfo.types';
Open Source Developer's avatar
Open Source Developer committed
12
13
import { VALID_CAPACITY_PATTERN} from '../../constants';
import {maxValue} from '../../constants';
Open Source Developer's avatar
Open Source Developer committed
14
import {minValue} from '../../constants';
Open Source Developer's avatar
Open Source Developer committed
15

Open Source Developer's avatar
Open Source Developer committed
16
17
18
19

import {
    FormBuilder,
    FormGroup,
20
    FormControl,
Open Source Developer's avatar
Open Source Developer committed
21
22
23
24
25
26
    FormArray,
    Validators,
} from '@angular/forms';
@Component({
    selector: 'director-classcapacity',
    template: `
Open Source Developer's avatar
Open Source Developer committed
27
    <div class = "loading" *ngIf="(showLoader | async) === true"></div>
28
    <div style="min-height: 500px;">
Open Source Developer's avatar
Open Source Developer committed
29
    <form [formGroup]="formGroup">
30

Open Source Developer's avatar
Open Source Developer committed
31
32
       <p style="margin-top: 20px; line-height: 2em;"> Στην παρακάτω'λίστα βλέπετε τα τμήματα του σχολείου σας με την αντίστοιχη δυναμίκη τους σε αίθουσες. Παρακαλώ για να τροποποποιήσετε τη δυναμικήαυτή κάντε κλικ στον αντίστοιχο αριθμό,
       επιλέξτε τη νέα δυναμική και πατήστε το σύμβολο <i>ok</i>. Προσοχή! Κανένα τμήμα δεν πρέπει να έχει δυναμική 0.</p>
33
      <div class="row" style="margin-top: 20px; line-height: 2em;" > <b> Οι δηλώσεις σας </b></div>
Open Source Developer's avatar
Open Source Developer committed
34
      <div *ngFor="let CapacityPerCourses$  of CapacityPerCourse$ | async; let i=index; let isOdd=odd; let isEven=even" >
Open Source Developer's avatar
bug    
Open Source Developer committed
35
                <li *ngIf="(!(selectiontype | async) && (CapacityPerCourses$.class < 4)) ||((selectiontype | async) && (CapacityPerCourses$.class < 5))" class="list-group-item " [class.oddout]="isOdd" [class.evenout]="isEven" >
Open Source Developer's avatar
Open Source Developer committed
36
37
38
39
40
41
42
                <div class="row">
                <div class="col-md-5">
                   <h5 [class.changelistcolor]= "CapacityPerCourses$.capacity === 0" >{{CapacityPerCourses$.taxi}}&nbsp; <b></b></h5>
                 </div>
                 <div class="col-md-4" col-md-offset-2>
                   <label *ngIf="!isEdit" (click)="isEdit=true" (click)="setActive(i)"> {{CapacityPerCourses$.capacity}} </label>
                   <input *ngIf="isEdit && CapacityPerCourses$.globalindex === courseActive"
43
44
                     id="{{CapacityPerCourses$.globalindex}}" type="number"
                   name="{{CapacityPerCourses$.globalindex}}" value ={{CapacityPerCourses$.capacity}}
Open Source Developer's avatar
Open Source Developer committed
45
46
                   (change)="handleChange($event)">
                   </div>
47
                 <div class="col-md-1">
Open Source Developer's avatar
Open Source Developer committed
48
49
50
51
52
53
            <button *ngIf="isEdit && CapacityPerCourses$.globalindex === courseActive" type="button" class="btn-primary pull-right"
             (click)="isEdit=false" (click) ="saveCapacity(CapacityPerCourses$.newspecialit, CapacityPerCourses$.newsector, CapacityPerCourses$.class, CapacityPerCourses$.capacity)">
               <i class="fa fa-check" aria-hidden="true"></i>
             </button>
             </div>
             </div>
Open Source Developer's avatar
Open Source Developer committed
54
                </li>
55
       </div>
56

Open Source Developer's avatar
Open Source Developer committed
57
58
      </form>
    </div>
Open Source Developer's avatar
trans    
Open Source Developer committed
59

Open Source Developer's avatar
Open Source Developer committed
60

61
  <div id="checksaved" (onHidden)="onHidden('#checksaved')"
Open Source Developer's avatar
Open Source Developer committed
62
63
64
65
    class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
      <div class="modal-dialog modal-lg">
        <div class="modal-content">
          <div class="modal-header modal-header-danger">
Open Source Developer's avatar
Open Source Developer committed
66
            <h3 class="modal-title pull-left"><i class="fa fa-check-square-o"></i>&nbsp;&nbsp;Πρέπει να συπληρώσετε σωστά τη δυναμική</h3>
Open Source Developer's avatar
Open Source Developer committed
67
68
69
70
71
            <button type="button" class="close pull-right" aria-label="Close" (click)="hideModal('#checksaved')">
              <span aria-hidden="true"><i class="fa fa-times"></i></span>
            </button>
          </div>
          <div class="modal-body">
Open Source Developer's avatar
Open Source Developer committed
72
            <p>Η αποθήκευση δε μπορεί να γίνει αν δεν συμπληρώσετε έναν αριθμό μεταξυ 1 και 10!</p>
Open Source Developer's avatar
Open Source Developer committed
73
74
75
76
77
78
79
80
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default pull-left" data-dismiss="modal">Κλείσιμο</button>
          </div>
        </div>
      </div>
    </div>

Open Source Developer's avatar
Open Source Developer committed
81
82
83
   `
})

84
@Injectable() export default class DirectorClassCapacity implements OnInit, OnDestroy {
Open Source Developer's avatar
Open Source Developer committed
85
86

    public formGroup: FormGroup;
87

Open Source Developer's avatar
Open Source Developer committed
88
89
    private CapacityPerCourse$: BehaviorSubject<any>;
    private CapacityPerCourseSub: Subscription;
Open Source Developer's avatar
trans    
Open Source Developer committed
90
    private saveCapacitySub: Subscription;
Open Source Developer's avatar
Open Source Developer committed
91
92
93
94
    private newvalue:number;
    private isEdit: boolean;
    private courseActive = <number>-1;
    private showLoader: BehaviorSubject<boolean>;
Open Source Developer's avatar
trans    
Open Source Developer committed
95
96
    private School$: BehaviorSubject<any>;
    private SchoolSub: Subscription;
Open Source Developer's avatar
Open Source Developer committed
97
    private selectiontype: BehaviorSubject<boolean>;
Open Source Developer's avatar
trans    
Open Source Developer committed
98
    private SchoolId;
99
100


101

102
103
104
105
    constructor(private fb: FormBuilder,
        private _hds: HelperDataService,
        private activatedRoute: ActivatedRoute,
        private router: Router) {
106

Open Source Developer's avatar
Open Source Developer committed
107
108
        this.CapacityPerCourse$ = new BehaviorSubject([{}]);
        this.showLoader = new BehaviorSubject(false);
Open Source Developer's avatar
Open Source Developer committed
109
110
111
        this.isEdit = false;
        this.School$ = new BehaviorSubject([{}]);
        this.selectiontype = new BehaviorSubject(true);
112
        this.formGroup = this.fb.group({
113

Open Source Developer's avatar
Open Source Developer committed
114
             });
Open Source Developer's avatar
trans    
Open Source Developer committed
115
116
117

    }

Open Source Developer's avatar
Open Source Developer committed
118

119

Open Source Developer's avatar
Open Source Developer committed
120
   public showModal(popupMsgId):void {
Open Source Developer's avatar
trans    
Open Source Developer committed
121
122
123
124
125
126
127
128
129
130
131
        console.log("about to show modal");
        //(<any>$('#distributionWaitingNotice')).modal('show');
        (<any>$(popupMsgId)).modal('show');
    }

    public hideModal(popupMsgId):void {
        //(<any>$('#distributionWaitingNotice')).modal('hide');
        (<any>$(popupMsgId)).modal('hide');
    }

    public onHidden(popupMsgId):void {
132

Open Source Developer's avatar
Open Source Developer committed
133
134
    }

Open Source Developer's avatar
Open Source Developer committed
135

136
    ngOnDestroy() {
137

Open Source Developer's avatar
Open Source Developer committed
138
    }
139

Open Source Developer's avatar
Open Source Developer committed
140
    ngOnInit() {
Open Source Developer's avatar
Open Source Developer committed
141
142
                 (<any>$('#checksaved')).appendTo("body");
                  this.SchoolSub = this._hds.gettypeofschool().subscribe(x => {
143
                  this.School$.next(x);
Open Source Developer's avatar
Open Source Developer committed
144
145
146
147
148
                  console.log(x[0].type, "schoolid!");
                   this.SchoolId = x[0].type;
                   if (this.SchoolId == 'ΗΜΕΡΗΣΙΟ'){
                       this.selectiontype.next(false);
                   }
Open Source Developer's avatar
trans    
Open Source Developer committed
149
150
151
152
153
154
155
156

                  },
                  error => {
                      this.School$.next([{}]);
                      console.log("Error Getting School");
                  },
                  () => console.log("Getting School "));

Open Source Developer's avatar
Open Source Developer committed
157

158

Open Source Developer's avatar
Open Source Developer committed
159
                  this.CapacityPerCourseSub = this._hds.FindCapacityPerSchool().subscribe(x => {
160
161
                  this.CapacityPerCourse$.next(x);

Open Source Developer's avatar
Open Source Developer committed
162
163
164
165
166
167
168
169
170
171
172
                  },
                  error => {
                      this.CapacityPerCourse$.next([{}]);
                      console.log("Error Getting Capacity perSchool");
                  },
                  () => console.log("Getting School "));





Open Source Developer's avatar
Open Source Developer committed
173
174
175
    }


Open Source Developer's avatar
Open Source Developer committed
176
177
    handleChange ( e: Event) {
        this.newvalue = e.target['value'];
Open Source Developer's avatar
Open Source Developer committed
178
179
    }

Open Source Developer's avatar
Open Source Developer committed
180
   saveCapacity(spec,sect,taxi,oldvalue){
Open Source Developer's avatar
Open Source Developer committed
181

Open Source Developer's avatar
Open Source Developer committed
182
183
184
185
186
     console.log(taxi, sect, spec);
     console.log(this.newvalue,"newvalue", oldvalue);
         if (this.newvalue!= null)
         {
          if (this.newvalue <=0 || this.newvalue >10)
Open Source Developer's avatar
Open Source Developer committed
187
188
          {
              this.showModal("#checksaved");
189
190
          }
          else
Open Source Developer's avatar
Open Source Developer committed
191
192
193
          {
          this.showLoader.next(true);
         this.saveCapacitySub = this._hds.saveCapacity(taxi, sect, spec, this.newvalue).subscribe(data => {
Open Source Developer's avatar
Open Source Developer committed
194
                 this.showLoader.next(false);
195
196

                this.CapacityPerCourseSub = this._hds.FindCapacityPerSchool().subscribe(x => {
197
                  this.CapacityPerCourse$.next(x);
198
199
200
201
202
203
                  },
                  error => {
                      this.CapacityPerCourse$.next([{}]);
                      console.log("Error Getting Capacity perSchool");
                  },
                  () => console.log("Getting School "));
Open Source Developer's avatar
trans    
Open Source Developer committed
204
205
                 },
                error => {
206

Open Source Developer's avatar
trans    
Open Source Developer committed
207
208
                    console.log("Error Saving Capacity");
                },
Open Source Developer's avatar
Open Source Developer committed
209
210
                () =>{
                 console.log("Saved Capacity");
Open Source Developer's avatar
Open Source Developer committed
211
                    });
Open Source Developer's avatar
Open Source Developer committed
212
213
214


             }
215

Open Source Developer's avatar
Open Source Developer committed
216
           }
Open Source Developer's avatar
Open Source Developer committed
217
        }
Open Source Developer's avatar
Open Source Developer committed
218

219

Open Source Developer's avatar
Open Source Developer committed
220
  setActive(ind) {
221

Open Source Developer's avatar
Open Source Developer committed
222
223
224
225
      this.courseActive = ind;
      console.log(this.courseActive, ind, "ind");
    }

226

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

228
}