application.preview.ts 10.3 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
@Component({
    selector: 'application-preview-select',
    template: `
25
        <div *ngFor="let epalclass$ of epalclasses$ | async;">
26
        <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
       <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;">
35

Open Source Developer's avatar
Open Source Developer committed
36
                <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
                </li>
39

Open Source Developer's avatar
Open Source Developer committed
40
        </ul>
41
        </div>
Open Source Developer's avatar
Open Source Developer committed
42

43
44
    <div *ngFor="let sector$ of sectors$  | async;">
        <div *ngFor="let sectorField$ of sectorFields$ | async;">
45
46
        <div class="row">
        <div class="btn-group inline pull-center">
47
            <button type="button" class="btn-primary btn-md pull-center" [hidden] = "classSelected === 1" [disabled] = "classSelected === 3">
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;">
                <li class="list-group-item" *ngIf="sectorField$.selected === true" >
Open Source Developer's avatar
UI    
Open Source Developer committed
54
                    {{sectorField$.name   }}
55
                </li>
56
                <li class="list-group-item" *ngIf="sector$.sector_selected === true" >
Open Source Developer's avatar
UI    
Open Source Developer committed
57
                    {{sector$.sector_name }}
58
                </li>
59
        </ul>
60
        </div>
61

62
63

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

76
        </ul>
77
78
        </div>
        </div>
79

80
        <div *ngIf="regions$.size > 0 | async">
81
82
        <div class="row">
        <div class="btn-group inline pull-center">
83
            <button type="button" id = "butsch" class="btn-primary btn-md pull-center" [disabled] = "numSelectedSchools === 0 ">
84
85
86
87
88
89
90
            Τα σχολεία μου<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; " >
91
92
93
94
                <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
95
                      {{epal$.epal_name   }}
Open Source Developer's avatar
commit    
Open Source Developer committed
96
                  </li>
97
98

                <li class="list-group-item" *ngIf="epal$.selected === true && epal$.order_id === 2">
Open Source Developer's avatar
UI    
Open Source Developer committed
99
                    Προτίμηση {{epal$.order_id}}: {{epal$.epal_name   }}
100
                </li>
101

102
                <li class="list-group-item" *ngIf="epal$.selected === true && epal$.order_id === 3">
Open Source Developer's avatar
UI    
Open Source Developer committed
103
                    Προτίμηση {{epal$.order_id}}: {{epal$.epal_name   }}
104
105
106
107
108
109
110
                </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>
111
        </ul>
112
        </div>
113

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

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

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

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

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

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

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

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

230
231
232
233
234
    }

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

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

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

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

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

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

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

266
}