application.preview.ts 10.7 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { Observable } from 'rxjs/Rx';
import { Injectable } from "@angular/core";
import { NgRedux, select } from 'ng2-redux';
import { IAppState } from '../../store/store';
import { SectorFieldsActions } from '../../actions/sectorfields.actions';
import { SectorCoursesActions } from '../../actions/sectorcourses.actions';
import { RegionSchoolsActions } from '../../actions/regionschools.actions';
import { StudentDataFieldsActions } from '../../actions/studentdatafields.actions';
Open Source Developer's avatar
Open Source Developer committed
11
import { EpalClassesActions } from '../../actions/epalclass.actions';
12
import { AmkaFillsActions } from '../../actions/amkafill.actions';
13
14
15
16
import { ISectorFields } from '../../store/sectorfields/sectorfields.types';
import { ISectors } from '../../store/sectorcourses/sectorcourses.types';
import { IRegions } from '../../store/regionschools/regionschools.types';
import { IStudentDataFields } from '../../store/studentdatafields/studentdatafields.types';
Open Source Developer's avatar
Open Source Developer committed
17
import { IEpalClasses } from '../../store/epalclasses/epalclasses.types';
18
import { IAmkaFills } from '../../store/amkafill/amkafills.types';
19
20
import {AppSettings} from '../../app.settings';

Open Source Developer's avatar
UI    
Open Source Developer committed
21

22
23
24
25
26
@Component({
    selector: 'application-preview-select',
    template: `
        <h4 style="margin-top: 20px; line-height: 2em; ">Οι επιλογές μου</h4>

Open Source Developer's avatar
Open Source Developer committed
27
28
29
30
31
32
33
34
35
36
       <div class="row">
        <div class="btn-group inline pull-center">
            <button type="button" class="btn-primary btn-md pull-center" (click)="defineClass()">
            Η τάξη μου<span class="glyphicon glyphicon-menu-right"></span>
            </button>
        </div>
        </div>
        <ul class="list-group" style="margin-bottom: 20px;">
            <div *ngFor="let epalclass$ of epalclasses$ | async;">
                <li class="list-group-item">
Open Source Developer's avatar
UI    
Open Source Developer committed
37
                    Τάξη εισαγωγής: {{epalclass$.name  }}
Open Source Developer's avatar
Open Source Developer committed
38
39
40
41
                </li>
            </div>
        </ul>

42
43
        <div class="row">
        <div class="btn-group inline pull-center">
44
            <button type="button" class="btn-primary btn-md pull-center" (click)="defineSector()" [hidden] = "classSelected === 1" [disabled] = "classSelected === 3">
45
46
47
48
49
50
51
            O τομέας μου<span class="glyphicon glyphicon-menu-right"></span>
            </button>
        </div>
        </div>
        <ul class="list-group" style="margin-bottom: 20px;">
            <div *ngFor="let sectorField$ of sectorFields$ | async;">
                <li class="list-group-item" *ngIf="sectorField$.selected === true" >
Open Source Developer's avatar
UI    
Open Source Developer committed
52
                    {{sectorField$.name   }}
53
54
                </li>
            </div>
55
56
57

            <div *ngFor="let sector$ of sectors$  | async;">
                <li class="list-group-item" *ngIf="sector$.sector_selected === true" >
Open Source Developer's avatar
UI    
Open Source Developer committed
58
                    {{sector$.sector_name }}
59
60
                </li>
            </div>
61
62
63
64
        </ul>

        <div class="row">
        <div class="btn-group inline pull-center">
65
            <button type="button" class="btn-primary btn-md pull-center" (click)="defineCourse()" [hidden] = "classSelected !== 3">
66
67
68
69
70
71
72
73
            Η ειδικότητά μου<span class="glyphicon glyphicon-menu-right"></span>
            </button>
        </div>
        </div>
        <ul class="list-group" style="margin-bottom: 20px;">
              <div *ngFor="let sector$ of sectors$ | async;">
                <div *ngFor="let course$ of sector$.courses;" >
                <li class="list-group-item" *ngIf="course$.selected === true">
Open Source Developer's avatar
UI    
Open Source Developer committed
74
                    {{course$.course_name   }}
75
76
77
78
79
80
81
                </li>
            </div>
            </div>
        </ul>

        <div class="row">
        <div class="btn-group inline pull-center">
82
            <button type="button" id = "butsch" class="btn-primary btn-md pull-center" (click)="defineSchools()" [disabled] = "numSelectedSchools === 0 ">
83
84
85
86
87
88
89
            Τα σχολεία μου<span class="glyphicon glyphicon-menu-right"></span>
            </button>
        </div>
        </div>
        <ul class="list-group" style="margin-bottom: 20px;">
              <div *ngFor="let region$ of regions$ | async;">
                <div *ngFor="let epal$ of region$.epals; " >
90
91
92
93
                <li class="list-group-item" *ngIf="epal$.selected === true && epal$.order_id === 1">
                    Προτίμηση {{epal$.order_id}}: {{epal$.epal_name}}
                </li>
                  <li class="list-group-item" *ngIf="epal$.selected === true && epal$.order_id === 0">
Open Source Developer's avatar
UI    
Open Source Developer committed
94
                      {{epal$.epal_name   }}
Open Source Developer's avatar
commit    
Open Source Developer committed
95
96
                  </li>
                </div>
97
            </div>
98
99
100
101

            <div *ngFor="let region$ of regions$ | async;">
              <div *ngFor="let epal$ of region$.epals; " >
                <li class="list-group-item" *ngIf="epal$.selected === true && epal$.order_id === 2">
Open Source Developer's avatar
UI    
Open Source Developer committed
102
                    Προτίμηση {{epal$.order_id}}: {{epal$.epal_name   }}
103
104
105
106
107
108
                </li>
              </div>
            </div>
            <div *ngFor="let region$ of regions$ | async;">
              <div *ngFor="let epal$ of region$.epals; " >
                <li class="list-group-item" *ngIf="epal$.selected === true && epal$.order_id === 3">
Open Source Developer's avatar
UI    
Open Source Developer committed
109
                    Προτίμηση {{epal$.order_id}}: {{epal$.epal_name   }}
110
111
112
113
114
115
116
                </li>
              </div>
            </div>
            <div class="btn-group inline pull-right">
              <button type="button" class="btn-primary btn-sm pull-right" (click)="defineOrder()"
              [hidden] = "numSelectedSchools <= 1 ">> Σειρά προτίμησης</button>
            </div>
117
        </ul>
118

119
        <div class="row">
Open Source Developer's avatar
commit    
Open Source Developer committed
120
          <div class="btn-group inline pull-center">
121
122
              <button type="button" class="btn-primary btn-md pull-center" (click)="definePersonalData()"
              [disabled] = "numSelectedOrder === 0">
Open Source Developer's avatar
commit    
Open Source Developer committed
123
124
125
126
              Τα στοιχεία μου<span class="glyphicon glyphicon-menu-right"></span>
              </button>
          </div>
         </div>
127
128
129
        <ul class="list-group" style="margin-bottom: 20px;">
              <div *ngFor="let studentDataField$ of studentDataFields$ | async;">
                <li class="list-group-item">
Open Source Developer's avatar
UI    
Open Source Developer committed
130
                    Όνομα μαθητή: {{studentDataField$.name   }}
131
132
                </li>
                <li class="list-group-item">
Open Source Developer's avatar
UI    
Open Source Developer committed
133
                    Επώνυμο μαθητή: {{studentDataField$.studentsurname   }}
134
                </li>
135
136
137
138
139
140
141
            </div>
            <div *ngFor="let selectedAmkaFill$ of selectedAmkaFills$ | async;">
              <li class="list-group-item">
                  AMKA μαθητή: {{selectedAmkaFill$.name}}
              </li>
          </div>
        </ul>
142
143
144
145
146
147
148
149
  `
})

@Injectable() export default class ApplicationPreview implements OnInit {
    private sectors$: Observable<ISectors>;
    private regions$: Observable<IRegions>;
    private sectorFields$: Observable<ISectorFields>;
    private studentDataFields$: Observable<IStudentDataFields>;
150
    private selectedAmkaFills$: Observable<IAmkaFills>;
Open Source Developer's avatar
Open Source Developer committed
151
    private epalclasses$: Observable<IEpalClasses>;
152
153
    private courseActive = "-1";
    private numSelectedSchools = <number>0;
154
155
    private numSelectedOrder = <number>0;
    private classSelected = 0;
156
157
158
159
160

    constructor(private _ngRedux: NgRedux<IAppState>,
                private router: Router
            ) {
    };
161
162

    ngOnInit() {
163
        this.courseActive = this.getCourseActive();
164
        this.sectors$ = this._ngRedux.select(state => {
165
            //let numsel = 0;
166
            state.sectors.reduce((prevSector, sector) =>{
167
                //if (sector.sector_selected)
168
                sector.courses.reduce((prevCourse, course) =>{
169
170
171
                  //if (course.selected === true)  {
                  //  numsel++;
                  //}
172
173
174
175
                    return course;
                }, {});
                return sector;
            }, {});
176
            //this.numSelectedCourses = numsel;
177
178
179
180
            return state.sectors;
        });

        this.regions$ = this._ngRedux.select(state => {
181
              let numsel = 0, numsel2 = 0;
182
              state.regions.reduce((prevRegion, region) =>{
183
                  region.epals.reduce((prevEpal, epal) =>{
184
                    if (epal.selected === true) {
185
                        numsel++;
186
187
188
189
                    }
                    if (epal.order_id !== 0) {
                        numsel2++;
                    }
190
                    return epal;
191
192
193
194
                  }, {});
                  return region;
              }, {});
              this.numSelectedSchools = numsel;
195
              this.numSelectedOrder = numsel2;
196
197
              return state.regions;
          });
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212

        this.sectorFields$ = this._ngRedux.select(state => {
            state.sectorFields.reduce(({}, sectorField) =>{
                return sectorField;
            }, {});
            return state.sectorFields;
        });

        this.studentDataFields$ = this._ngRedux.select(state => {
            state.studentDataFields.reduce(({}, studentDataField) =>{
                return studentDataField;
            }, {});
            return state.studentDataFields;
        });

213
214
215
216
217
218
        this.selectedAmkaFills$ = this._ngRedux.select(state => {
            state.amkafills.reduce(({}, selectedAmkaFill) =>{
                return selectedAmkaFill;
            }, {});
            return state.amkafills;
        });
Open Source Developer's avatar
Open Source Developer committed
219

220
       this.epalclasses$ = this._ngRedux.select(state => {
Open Source Developer's avatar
Open Source Developer committed
221
            state.epalclasses.reduce(({}, epalclass) =>{
222
223
224
225
226
227
228
              if (epalclass.name === "Α' Λυκείου")
                this.classSelected = 1;
              else if (epalclass.name === "Β' Λυκείου")
                  this.classSelected = 2;
              else if (epalclass.name === "Γ' Λυκείου")
                    this.classSelected = 3;
              return epalclass;
Open Source Developer's avatar
Open Source Developer committed
229
230
231
232
            }, {});
            return state.epalclasses;
        });

233
234
235
236
237
    }

    defineSector() {
        this.router.navigate(['/sector-fields-select']);
    }
238

239
240
241
    defineSchools() {
        this.router.navigate(['/region-schools-select']);
    }
242

243
244
245
    definePersonalData() {
        this.router.navigate(['/student-application-form-main']);
    }
246

Open Source Developer's avatar
Open Source Developer committed
247
248
249
250
    defineClass() {
        this.router.navigate(['/epal-class-select']);
    }

251
252
253
254
255
256
257
258
259
260
    getCourseActive() {
        const { sectors } = this._ngRedux.getState();
        let l,m;
        for ( l=0; l<sectors.size; l++)
          if (sectors["_tail"]["array"][l]["sector_selected"] === true)
            for ( m=0; m < sectors["_tail"]["array"][l]["courses"].length; m++)
              if (sectors["_tail"]["array"][l]["courses"][m]["selected"] === true)
                 return sectors["_tail"]["array"][l]["courses"][m]["course_id"];
    }

261
    defineCourse() {
262
        this.router.navigate(['/sectorcourses-fields-select']);
263
    }
264

265
266
267
    defineOrder() {
      this.router.navigate(['/schools-order-select']);
    }
268

269
}