application.preview.ts 11.1 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
41
       <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>


42
43
44
45
46
47
48
49
50
51
52
53
54
        <div class="row">
        <div class="btn-group inline pull-center">
            <button type="button" class="btn-primary btn-md pull-center" (click)="defineSector()">
            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>
55
56
57
58
59
60
61
62
63
64

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


65
66
67
68
        </ul>

        <div class="row">
        <div class="btn-group inline pull-center">
69
            <button type="button" class="btn-primary btn-md pull-center" (click)="defineCourse()" >
70
71
72
73
            Η ειδικότητά μου<span class="glyphicon glyphicon-menu-right"></span>
            </button>
        </div>
        </div>
74
        <!--
75
76
77
78
79
80
81
        <div class="row">
        <div class="btn-group inline pull-right">
            <button class="btn-primary btn-md pull-right my-btn"  type="button" (click)="defineCourse()" [hidden] = "numSelectedCourses === 0" >
            Επαναφορά<span class="glyphicon glyphicon-menu-right"></span>
            </button>
        </div>
        </div>
82
        -->
83

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

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

<!--
        <ul class="list-group" style="margin-bottom: 20px;">
              <div *ngFor="let selectedAmkaFill$ of selectedAmkaFills$ | async;">
                <li class="list-group-item">
                    AMKA μαθητή: {{selectedAmkaFill$.name}}
                </li>
145
146
            </div>
        </ul>
147
  -->
148
149
150
151
152
153
154
155
  `
})

@Injectable() export default class ApplicationPreview implements OnInit {
    private sectors$: Observable<ISectors>;
    private regions$: Observable<IRegions>;
    private sectorFields$: Observable<ISectorFields>;
    private studentDataFields$: Observable<IStudentDataFields>;
156
    private selectedAmkaFills$: Observable<IAmkaFills>;
Open Source Developer's avatar
Open Source Developer committed
157
158
    private epalclasses$: Observable<IEpalClasses>;

159

160
161
    private courseActive = "-1";
    private numSelectedSchools = <number>0;
162
    //private numSelectedCourses = <number>0;
163

164
    /*
165
166
167
168
    constructor(private _rsa: SectorCoursesActions,
                private _rsb: RegionSchoolsActions,
                private _rsc: SectorFieldsActions,
                private _rsd: StudentDataFieldsActions,
169
                private _rse: AmkaFillsActions,
Open Source Developer's avatar
Open Source Developer committed
170
                private _rcd: EpalClassesActions,
171
172
173
174
                private _ngRedux: NgRedux<IAppState>,
                private router: Router
            ) {
    };
175
176
177
178
179
180
    */

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

    ngOnInit() {
183
        this.courseActive = this.getCourseActive();
184
        this.sectors$ = this._ngRedux.select(state => {
185
            //let numsel = 0;
186
            state.sectors.reduce((prevSector, sector) =>{
187
                //if (sector.sector_selected)
188
                sector.courses.reduce((prevCourse, course) =>{
189
190
191
                  //if (course.selected === true)  {
                  //  numsel++;
                  //}
192
193
194
195
                    return course;
                }, {});
                return sector;
            }, {});
196
            //this.numSelectedCourses = numsel;
197
198
199
200
            return state.sectors;
        });

        this.regions$ = this._ngRedux.select(state => {
201
202
              let numsel = 0;
              state.regions.reduce((prevRegion, region) =>{
203
204
                  region.epals.reduce((prevEpal, epal) =>{
                    if (epal.selected === true)
205
                        numsel++;
206
                    return epal;
207
208
209
210
211
212
                  }, {});
                  return region;
              }, {});
              this.numSelectedSchools = numsel;
              return state.regions;
          });
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227

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

228
229
230
231
232
233
        this.selectedAmkaFills$ = this._ngRedux.select(state => {
            state.amkafills.reduce(({}, selectedAmkaFill) =>{
                return selectedAmkaFill;
            }, {});
            return state.amkafills;
        });
Open Source Developer's avatar
Open Source Developer committed
234

235
       this.epalclasses$ = this._ngRedux.select(state => {
Open Source Developer's avatar
Open Source Developer committed
236
237
238
239
240
241
242
            state.epalclasses.reduce(({}, epalclass) =>{
                return epalclass;
            }, {});
            return state.epalclasses;
        });


243
244
245
246
247
    }

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

249
250
251
252
253
254
    defineSchools() {
        this.router.navigate(['/region-schools-select']);
    }
    definePersonalData() {
        this.router.navigate(['/student-application-form-main']);
    }
Open Source Developer's avatar
Open Source Developer committed
255
256
257
258
    defineClass() {
        this.router.navigate(['/epal-class-select']);
    }

259

260
261
262
263
264
265
266
267
268
269
270
    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"];
    }

/*
271
    defineCourse() {
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
      this._rsb.getRegionSchools("-1", true);
      this.regions$ = this._ngRedux.select(state => {
          let numsel = 0;
          state.regions.reduce((prevRegion, region) =>{
              region.epals.reduce((prevSchool, school) =>{
                if (school.selected === true)
                    numsel++;
                return school;
              }, {});
              return region;
          }, {});
          this.numSelectedSchools = numsel;
          return state.regions;
      });

      this._rsa.getSectorCourses(true);
      this.sectors$ = this._ngRedux.select(state => {
          state.sectors.reduce((prevSector, sector) =>{
              sector.courses.reduce((prevCourse, course) =>{
                  return course;
              }, {});
              return sector;
          }, {});
          return state.sectors;
      });

      this.router.navigate(['/sectorcourses-fields-select']);

300
    }
301
  */
302

303
304
305
  defineCourse() {
      this.router.navigate(['/sectorcourses-fields-select']);
  }
306

307
}