application.preview.ts 9.45 KB
Newer Older
1
import { Component, OnInit, OnDestroy } from '@angular/core';
2
import { Router } from '@angular/router';
3
import { BehaviorSubject, Subscription } from 'rxjs/Rx';
4
5
6
7
8
9
10
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
13
14
15
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
16
import { IEpalClasses } from '../../store/epalclasses/epalclasses.types';
17
import {AppSettings} from '../../app.settings';
18
19
20
21
22
23
import { REGION_SCHOOLS_INITIAL_STATE } from '../../store/regionschools/regionschools.initial-state';
import { EPALCLASSES_INITIAL_STATE } from '../../store/epalclasses/epalclasses.initial-state';
import { SECTOR_COURSES_INITIAL_STATE } from '../../store/sectorcourses/sectorcourses.initial-state';
import { SECTOR_FIELDS_INITIAL_STATE } from '../../store/sectorfields/sectorfields.initial-state';
import { STUDENT_DATA_FIELDS_INITIAL_STATE } from '../../store/studentdatafields/studentdatafields.initial-state';

24

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

26
27
28
@Component({
    selector: 'application-preview-select',
    template: `
29
        <div *ngFor="let epalclass$ of epalclasses$ | async;">
30
        <h4 style="margin-top: 20px; line-height: 2em; ">Οι επιλογές μου</h4>
31
32
33
34
        <ul class="list-group left-side-view" style="margin-bottom: 20px;">
                <li class="list-group-item active">
                    Τάξη εισαγωγής
                </li>
Open Source Developer's avatar
Open Source Developer committed
35
                <li class="list-group-item">
36
                    {{epalclass$.name  }}
Open Source Developer's avatar
Open Source Developer committed
37
                </li>
38

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

42
43
44
45
46
47
        <div *ngFor="let sectorField$ of sectorFields$ | async">
        <ul class="list-group left-side-view">
            <li class="list-group-item active" *ngIf="sectorField$.selected === true" >
                {{sectorField$.name}}
            </li>
            </ul>
48
        </div>
49

50

51
52
53
54
55
    <div *ngFor="let sector$ of sectors$  | async;">
            <ul class="list-group left-side-view" style="margin-bottom: 20px;" *ngIf="sector$.sector_selected === true">
                <li class="list-group-item active" *ngIf="sector$.sector_selected === true" >
                    {{sector$.sector_name }}
                </li>
56
        <div *ngFor="let course$ of sector$.courses;" >
57

58
                <li class="list-group-item" *ngIf="course$.selected === true">
Open Source Developer's avatar
UI    
Open Source Developer committed
59
                    {{course$.course_name   }}
60
                </li>
61
62

        </div>
63
            </ul>
64
        </div>
65

66
67
68
69
70




        <ul class="list-group left-side-view" style="margin-bottom: 20px;">
71
              <div *ngFor="let region$ of regions$ | async;">
72

73
                <div *ngFor="let epal$ of region$.epals; " >
74

75
76
77
78
                <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
79
                      {{epal$.epal_name   }}
Open Source Developer's avatar
commit    
Open Source Developer committed
80
                  </li>
81
82

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

86
                <li class="list-group-item" *ngIf="epal$.selected === true && epal$.order_id === 3">
Open Source Developer's avatar
UI    
Open Source Developer committed
87
                    Προτίμηση {{epal$.order_id}}: {{epal$.epal_name   }}
88
89
90
                </li>
              </div>
            </div>
91
<!--            <div class="btn-group inline pull-right">
92
93
              <button type="button" class="btn-primary btn-sm pull-right" (click)="defineOrder()"
              [hidden] = "numSelectedSchools <= 1 ">> Σειρά προτίμησης</button>
94
            </div> -->
95
        </ul>
96

97
98
99
100
101





102
              <div *ngFor="let studentDataField$ of studentDataFields$ | async;">
103
104
105
106
              <ul class="list-group left-side-view" style="margin-bottom: 20px;">
              <li class="list-group-item active">
                  Στοιχεία μαθητή
              </li>
107
                <li class="list-group-item">
108
                    {{studentDataField$.name  }}
109
110
                </li>
                <li class="list-group-item">
111
                    {{studentDataField$.studentsurname  }}
112
                </li>
113
                </ul>
114
            </div>
115
<!--            <div *ngFor="let selectedAmkaFill$ of selectedAmkaFills$ | async;">
116
117
118
              <li class="list-group-item">
                  AMKA μαθητή: {{selectedAmkaFill$.name}}
              </li>
119
          </div>  -->
120

121
122
123
124
  `
})

@Injectable() export default class ApplicationPreview implements OnInit {
125
126
127
128
129
130
131
132
133
134
    private sectors$: BehaviorSubject<ISectors>;
    private regions$: BehaviorSubject<IRegions>;
    private sectorFields$: BehaviorSubject<ISectorFields>;
    private studentDataFields$: BehaviorSubject<IStudentDataFields>;
    private epalclasses$: BehaviorSubject<IEpalClasses>;
    private sectorsSub: Subscription;
    private regionsSub: Subscription;
    private sectorFieldsSub: Subscription;
    private studentDataFieldsSub: Subscription;
    private epalclassesSub: Subscription;
135
136
    private courseActive = "-1";
    private numSelectedSchools = <number>0;
137
138
    private numSelectedOrder = <number>0;
    private classSelected = 0;
139
140

    constructor(private _ngRedux: NgRedux<IAppState>,
141
142
        private router: Router
    ) {
143
144
145
146
147
148

        this.regions$ = new BehaviorSubject(REGION_SCHOOLS_INITIAL_STATE);
        this.epalclasses$ = new BehaviorSubject(EPALCLASSES_INITIAL_STATE);
        this.sectors$ = new BehaviorSubject(SECTOR_COURSES_INITIAL_STATE);
        this.sectorFields$ = new BehaviorSubject(SECTOR_FIELDS_INITIAL_STATE);
        this.studentDataFields$ = new BehaviorSubject(STUDENT_DATA_FIELDS_INITIAL_STATE);
149
    };
150
151

    ngOnInit() {
152
        this.sectorsSub = this._ngRedux.select(state => {
153
154
            state.sectors.reduce((prevSector, sector) => {
                sector.courses.reduce((prevCourse, course) => {
155
156
157
158
                    if (course.selected === true) {
                        this.courseActive = course.course_id;
                    }

159
160
161
162
                    return course;
                }, {});
                return sector;
            }, {});
163
            //this.numSelectedCourses = numsel;
164
            return state.sectors;
165
        }).subscribe(this.sectors$);
166

167
        this.regionsSub = this._ngRedux.select(state => {
168
169
170
            let numsel = 0, numsel2 = 0;
            state.regions.reduce((prevRegion, region) => {
                region.epals.reduce((prevEpal, epal) => {
171
                    if (epal.selected === true) {
172
                        numsel++;
173
174
175
176
                    }
                    if (epal.order_id !== 0) {
                        numsel2++;
                    }
177
                    return epal;
178
179
180
181
182
183
                }, {});
                return region;
            }, {});
            this.numSelectedSchools = numsel;
            this.numSelectedOrder = numsel2;
            return state.regions;
184
        }).subscribe(this.regions$);
185

186
        this.sectorFieldsSub = this._ngRedux.select(state => {
187
            state.sectorFields.reduce(({}, sectorField) => {
188
189
190
                return sectorField;
            }, {});
            return state.sectorFields;
191
        }).subscribe(this.sectorFields$);
192

193
        this.studentDataFieldsSub = this._ngRedux.select(state => {
194
            state.studentDataFields.reduce(({}, studentDataField) => {
195
196
197
                return studentDataField;
            }, {});
            return state.studentDataFields;
198
        }).subscribe(this.studentDataFields$);
199

200
/*        this.selectedAmkaFills$ = this._ngRedux.select(state => {
201
            state.amkafills.reduce(({}, selectedAmkaFill) => {
202
203
204
                return selectedAmkaFill;
            }, {});
            return state.amkafills;
205
        }); */
Open Source Developer's avatar
Open Source Developer committed
206

207
        this._ngRedux.select(state => {
208
209
210
211
212
213
            state.epalclasses.reduce(({}, epalclass) => {
                if (epalclass.name === "Α' Λυκείου")
                    this.classSelected = 1;
                else if (epalclass.name === "Β' Λυκείου")
                    this.classSelected = 2;
                else if (epalclass.name === "Γ' Λυκείου")
214
                    this.classSelected = 3;
215
                return epalclass;
Open Source Developer's avatar
Open Source Developer committed
216
217
            }, {});
            return state.epalclasses;
218
        }).subscribe(this.epalclasses$);
Open Source Developer's avatar
Open Source Developer committed
219

220
221
    }

222
223
224
225
226
227
    ngOnDestroy() {
        this.regionsSub.unsubscribe();
        this.epalclassesSub.unsubscribe();
        this.sectorsSub.unsubscribe();
        this.sectorFieldsSub.unsubscribe();
        this.studentDataFieldsSub.unsubscribe();
228
229
230
231
232
        this.regions$.unsubscribe();
        this.epalclasses$.unsubscribe();
        this.sectors$.unsubscribe();
        this.sectorFields$.unsubscribe();
        this.studentDataFields$.unsubscribe();
233
    }
234

235
236
237
238
239
    showValues() {
        console.log(this.epalclasses$);
        console.log(this.studentDataFields$);
        console.log(this.regions$);
        console.log(this.sectors$);
240
    }
241

242
}