director-classcapacity.ts 6.98 KB
Newer Older
1
import { Component, OnDestroy, OnInit } from "@angular/core";
Open Source Developer's avatar
Open Source Developer committed
2
import { Injectable } from "@angular/core";
3 4
import { FormBuilder, FormGroup } from "@angular/forms";
import { ActivatedRoute, Router } from "@angular/router";
5
import { BehaviorSubject, Subscription } from "rxjs/Rx";
Open Source Developer's avatar
Open Source Developer committed
6

7
import { HelperDataService } from "../../services/helper-data-service";
Open Source Developer's avatar
Open Source Developer committed
8 9

@Component({
10
    selector: "director-classcapacity",
Open Source Developer's avatar
Open Source Developer committed
11
    template: `
Open Source Developer's avatar
Open Source Developer committed
12
    <div class = "loading" *ngIf="(showLoader | async) === true"></div>
13
    <div style="min-height: 500px;">
Open Source Developer's avatar
Open Source Developer committed
14
    <form [formGroup]="formGroup">
15

16

Open Source Developer's avatar
UI  
Open Source Developer committed
17
       <p style="margin-top: 20px; line-height: 2em;"> Στην παρακάτω λίστα βλέπετε τα τμήματα του σχολείου σας με την αντίστοιχη δυναμίκη τους σε αίθουσες. Παρακαλώ για να τροποποποιήσετε τη δυναμικήαυτή κάντε κλικ στον αντίστοιχο σύμβολο,
Open Source Developer's avatar
Open Source Developer committed
18
       επιλέξτε τη νέα δυναμική και πατήστε το σύμβολο <i>ok</i>. Προσοχή! Κανένα τμήμα δεν πρέπει να έχει δυναμική 0.</p>
19
      <div class="row" style="margin-top: 20px; line-height: 2em;" > <b> Οι δηλώσεις σας </b></div>
Open Source Developer's avatar
Open Source Developer committed
20
      <div *ngFor="let CapacityPerCourses$  of CapacityPerCourse$ | async; let i=index; let isOdd=odd; let isEven=even" >
Open Source Developer's avatar
Open Source Developer committed
21
                <li class="list-group-item " [class.oddout]="isOdd" [class.evenout]="isEven" >
Open Source Developer's avatar
Open Source Developer committed
22 23
                <div class="row">
                <div class="col-md-5">
Open Source Developer's avatar
UI  
Open Source Developer committed
24
                   <h5 [class.changelistcolor]= "CapacityPerCourses$.capacity === null" >{{CapacityPerCourses$.taxi}}&nbsp; <b></b></h5>
Open Source Developer's avatar
Open Source Developer committed
25
                 </div>
Open Source Developer's avatar
UI  
Open Source Developer committed
26 27 28 29
                 <div class="col-md-4" col-md-offset-1>
                  <label style="font-weight:bold!important" *ngIf="!isEdit || CapacityPerCourses$.globalindex !== courseActive" > {{CapacityPerCourses$.capacity}} </label>

                   <i *ngIf="!isEdit || CapacityPerCourses$.globalindex !== courseActive" (click)= "modifycapc(i,$event)" class="fa fa-pencil isclickable pull-right" style="font-size: 1.5em;"></i>
30

Open Source Developer's avatar
Open Source Developer committed
31
                   <input *ngIf="isEdit && CapacityPerCourses$.globalindex === courseActive"
Open Source Developer's avatar
Open Source Developer committed
32

33
                     id="{{CapacityPerCourses$.globalindex}}" type="number"
Open Source Developer's avatar
UI  
Open Source Developer committed
34
                   name="{{CapacityPerCourses$.globalindex}}" value ={{CapacityPerCourses$.capacity}}               (change)="handleChange($event)">
Open Source Developer's avatar
Open Source Developer committed
35
                   </div>
36 37

                 <div class="col-md-1">
Open Source Developer's avatar
UI  
Open Source Developer committed
38 39
            <i *ngIf="isEdit && CapacityPerCourses$.globalindex === courseActive" (click)= "isEdit = false" class="fa fa-ban isclickable" style="font-size: 1.5em;"></i>
            </div>
40
            <div class="col-md-2">
Open Source Developer's avatar
Open Source Developer committed
41

Open Source Developer's avatar
Open Source Developer committed
42
            <button *ngIf="isEdit && CapacityPerCourses$.globalindex === courseActive" type="button" class="btn-primary pull-right"
Open Source Developer's avatar
UI  
Open Source Developer committed
43
             (click)="isEdit=false" (click) ="saveCapacity(CapacityPerCourses$.newspecialit, CapacityPerCourses$.newsector, CapacityPerCourses$.class, CapacityPerCourses$.capacity, CapacityPerCourses$.globalindex )">
Open Source Developer's avatar
Open Source Developer committed
44 45 46 47
               <i class="fa fa-check" aria-hidden="true"></i>
             </button>
             </div>
             </div>
Open Source Developer's avatar
Open Source Developer committed
48
                </li>
49
       </div>
50

Open Source Developer's avatar
Open Source Developer committed
51 52
      </form>
    </div>
Open Source Developer's avatar
trans  
Open Source Developer committed
53

Open Source Developer's avatar
pull  
Open Source Developer committed
54
  <div id="checksaved1" (onHidden)="onHidden('#checksaved1')"
Open Source Developer's avatar
Open Source Developer committed
55 56 57 58
    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
59
            <h3 class="modal-title pull-left"><i class="fa fa-check-square-o"></i>&nbsp;&nbsp;Πρέπει να συπληρώσετε σωστά τη δυναμική</h3>
Open Source Developer's avatar
pull  
Open Source Developer committed
60
            <button type="button" class="close pull-right" aria-label="Close" (click)="hideModal('#checksaved1')">
Open Source Developer's avatar
Open Source Developer committed
61 62 63 64
              <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
65
            <p>Η αποθήκευση δε μπορεί να γίνει αν δεν συμπληρώσετε έναν αριθμό μεταξυ 1 και 10!</p>
Open Source Developer's avatar
Open Source Developer committed
66 67 68 69 70 71 72 73
          </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
74 75 76
   `
})

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

79
    private formGroup: FormGroup;
80

Open Source Developer's avatar
Open Source Developer committed
81 82
    private CapacityPerCourse$: BehaviorSubject<any>;
    private CapacityPerCourseSub: Subscription;
Open Source Developer's avatar
trans  
Open Source Developer committed
83
    private saveCapacitySub: Subscription;
84
    private newvalue: number;
Open Source Developer's avatar
Open Source Developer committed
85 86 87
    private isEdit: boolean;
    private courseActive = <number>-1;
    private showLoader: BehaviorSubject<boolean>;
88

89 90 91 92
    constructor(private fb: FormBuilder,
        private _hds: HelperDataService,
        private activatedRoute: ActivatedRoute,
        private router: Router) {
93

Open Source Developer's avatar
Open Source Developer committed
94 95
        this.CapacityPerCourse$ = new BehaviorSubject([{}]);
        this.showLoader = new BehaviorSubject(false);
Open Source Developer's avatar
Open Source Developer committed
96
        this.isEdit = false;
97

98
        this.formGroup = this.fb.group({
99

100
        });
Open Source Developer's avatar
trans  
Open Source Developer committed
101 102 103

    }

104
    public showModal(popupMsgId): void {
105
        (<any>$(popupMsgId)).modal("show");
Open Source Developer's avatar
trans  
Open Source Developer committed
106 107
    }

108
    public hideModal(popupMsgId): void {
109
        (<any>$(popupMsgId)).modal("hide");
Open Source Developer's avatar
trans  
Open Source Developer committed
110 111
    }

112
    public onHidden(popupMsgId): void {
113

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

116
    ngOnDestroy() {
117

Open Source Developer's avatar
Open Source Developer committed
118
    }
119

Open Source Developer's avatar
Open Source Developer committed
120
    ngOnInit() {
121
        (<any>$("#checksaved1")).appendTo("body");
Open Source Developer's avatar
Open Source Developer committed
122

123 124
        this.CapacityPerCourseSub = this._hds.FindCapacityPerSchool().subscribe(x => {
            this.CapacityPerCourse$.next(x);
Open Source Developer's avatar
Open Source Developer committed
125

126 127 128 129 130
        },
            error => {
                this.CapacityPerCourse$.next([{}]);
                console.log("Error Getting Capacity perSchool");
            });
Open Source Developer's avatar
Open Source Developer committed
131 132
    }

133
    handleChange(e: Event) {
134
        this.newvalue = e.target["value"];
Open Source Developer's avatar
Open Source Developer committed
135 136
    }

137 138 139 140 141 142 143 144 145 146 147
    saveCapacity(spec, sect, taxi, oldvalue, ind) {
        if (this.newvalue != null) {
            if (this.newvalue <= 0 || this.newvalue > 10) {
                this.showModal("#checksaved1");
            }
            else {
                this.showLoader.next(true);

                let std = this.CapacityPerCourse$.getValue();
                std[ind].capacity = this.newvalue;
                this.saveCapacitySub = this._hds.saveCapacity(taxi, sect, spec, this.newvalue).subscribe(data => {
Open Source Developer's avatar
Open Source Developer committed
148
                    this.showLoader.next(false);
149
                    this.CapacityPerCourse$.next(std);
Open Source Developer's avatar
trans  
Open Source Developer committed
150
                },
151 152 153 154 155
                    error => {
                        std[ind].capacity = oldvalue;
                        this.CapacityPerCourse$.next(std);
                        this.showLoader.next(false);
                        console.log("Error Saving Capacity");
Open Source Developer's avatar
Open Source Developer committed
156
                    });
157
            }
Open Source Developer's avatar
Open Source Developer committed
158
        }
159 160 161 162 163
        else {
            if (oldvalue === null)
                this.showModal("#checksaved1");
        }
    }
Open Source Developer's avatar
Open Source Developer committed
164

165 166
    setActive(ind) {
        this.courseActive = ind;
Open Source Developer's avatar
Open Source Developer committed
167 168
    }

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

170 171 172 173 174 175
    modifycapc(ind, e: Event) {
        this.isEdit = true;
        this.setActive(ind);
        this.handleChange(e);
    }

176
}