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
21
22
23
24
25
import {AppSettings} from '../../app.settings';

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

Open Source Developer's avatar
Open Source Developer committed
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
       <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">
                    Τάξη εισαγωγής: {{epalclass$.name}}
                </li>
            </div>
        </ul>

41
42
        <div class="row">
        <div class="btn-group inline pull-center">
43
            <button type="button" class="btn-primary btn-md pull-center" (click)="defineSector()" [hidden] = "classSelected === 1" [disabled] = "classSelected === 3">
44
45
46
47
48
49
50
51
52
53
            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" >
                    {{sectorField$.name}}
                </li>
            </div>
54
55
56
57
58
59

            <div *ngFor="let sector$ of sectors$  | async;">
                <li class="list-group-item" *ngIf="sector$.sector_selected === true" >
                    {{sector$.sector_name}}
                </li>
            </div>
60
61
62
63
        </ul>

        <div class="row">
        <div class="btn-group inline pull-center">
64
            <button type="button" class="btn-primary btn-md pull-center" (click)="defineCourse()" [hidden] = "classSelected !== 3">
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
            Η ειδικότητά μου<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">
                    {{course$.course_name}}
                </li>
            </div>
            </div>
        </ul>

        <div class="row">
        <div class="btn-group inline pull-center">
81
            <button type="button" id = "butsch" class="btn-primary btn-md pull-center" (click)="defineSchools()" [disabled] = "numSelectedSchools === 0 ">
82
83
84
85
86
87
88
            Τα σχολεία μου<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; " >
89
90
91
92
                <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
commit    
Open Source Developer committed
93
94
95
                      {{epal$.epal_name}}
                  </li>
                </div>
96
            </div>
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115

            <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">
                    Προτίμηση {{epal$.order_id}}: {{epal$.epal_name}}
                </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">
                    Προτίμηση {{epal$.order_id}}: {{epal$.epal_name}}
                </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>
116
        </ul>
117

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

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

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

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

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

        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;
        });

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

219
       this.epalclasses$ = this._ngRedux.select(state => {
Open Source Developer's avatar
Open Source Developer committed
220
            state.epalclasses.reduce(({}, epalclass) =>{
221
222
223
224
225
226
227
              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
228
229
230
231
            }, {});
            return state.epalclasses;
        });

232
233
234
235
236
    }

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

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

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

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

250
251
252
253
254
255
256
257
258
259
    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"];
    }

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

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

268
}