director-classcapacity.ts 6.79 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
import { ActivatedRoute, Router } from "@angular/router";
4
import { BehaviorSubject, Subscription } from "rxjs/Rx";
Open Source Developer's avatar
Open Source Developer committed
5

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

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

15

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

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

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

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

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

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

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

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

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

86
    constructor(
87 88
        private _hds: HelperDataService,
        private activatedRoute: ActivatedRoute,
89 90
        private router: Router
    ) {
Open Source Developer's avatar
Open Source Developer committed
91 92
        this.CapacityPerCourse$ = new BehaviorSubject([{}]);
        this.showLoader = new BehaviorSubject(false);
Open Source Developer's avatar
Open Source Developer committed
93
        this.isEdit = false;
Open Source Developer's avatar
trans  
Open Source Developer committed
94 95
    }

96
    public showModal(popupMsgId): void {
97
        (<any>$(popupMsgId)).modal("show");
Open Source Developer's avatar
trans  
Open Source Developer committed
98 99
    }

100
    public hideModal(popupMsgId): void {
101
        (<any>$(popupMsgId)).modal("hide");
Open Source Developer's avatar
trans  
Open Source Developer committed
102 103
    }

104
    public onHidden(popupMsgId): void {
105

Open Source Developer's avatar
Open Source Developer committed
106 107
    }

108
    ngOnDestroy() {
109

Open Source Developer's avatar
Open Source Developer committed
110
    }
111

Open Source Developer's avatar
Open Source Developer committed
112
    ngOnInit() {
113
        (<any>$("#checksaved1")).appendTo("body");
Open Source Developer's avatar
Open Source Developer committed
114

115 116
        this.CapacityPerCourseSub = this._hds.FindCapacityPerSchool().subscribe(x => {
            this.CapacityPerCourse$.next(x);
Open Source Developer's avatar
Open Source Developer committed
117

118 119 120 121 122
        },
            error => {
                this.CapacityPerCourse$.next([{}]);
                console.log("Error Getting Capacity perSchool");
            });
Open Source Developer's avatar
Open Source Developer committed
123 124
    }

125
    handleChange(e: Event) {
126
        this.newvalue = e.target["value"];
Open Source Developer's avatar
Open Source Developer committed
127 128
    }

129 130 131 132 133 134 135 136 137 138 139
    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
140
                    this.showLoader.next(false);
141
                    this.CapacityPerCourse$.next(std);
Open Source Developer's avatar
trans  
Open Source Developer committed
142
                },
143 144 145 146 147
                    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
148
                    });
149
            }
Open Source Developer's avatar
Open Source Developer committed
150
        }
151 152 153 154 155
        else {
            if (oldvalue === null)
                this.showModal("#checksaved1");
        }
    }
Open Source Developer's avatar
Open Source Developer committed
156

157 158
    setActive(ind) {
        this.courseActive = ind;
Open Source Developer's avatar
Open Source Developer committed
159 160
    }

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

162 163 164 165 166 167
    modifycapc(ind, e: Event) {
        this.isEdit = true;
        this.setActive(ind);
        this.handleChange(e);
    }

168
}