remove redundant redux actions from components, added validation patterns /...

remove redundant redux actions from components, added validation patterns / enable form validation in application.form.main component, updated sector.courses component
parent eda0c210
...@@ -2,8 +2,7 @@ import { STUDENTDATAFIELDS_SAVE, STUDENTDATAFIELDS_RECEIVED } from '../constants ...@@ -2,8 +2,7 @@ import { STUDENTDATAFIELDS_SAVE, STUDENTDATAFIELDS_RECEIVED } from '../constants
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { NgRedux } from 'ng2-redux'; import { NgRedux } from 'ng2-redux';
import { IAppState } from '../store'; import { IAppState } from '../store';
//import { HelperDataService } from '../services/helper-data-service'; //import { UserDataService } from '../services/user-data-service';
import { UserDataService } from '../services/user-data-service';
@Injectable() @Injectable()
......
export class AppSettings { export class AppSettings {
public static get API_ENDPOINT(): string { public static get API_ENDPOINT(): string {
return 'http://localhost/dist'; // return 'http://localhost/dist';
// return 'http://localhost/drupal-8.2.5'; return 'http://localhost/drupal-8.2.5';
// return 'http://eepal.dev/drupal'; // return 'http://eepal.dev/drupal';
// return 'http://eduslim2.minedu.gov.gr/drupal'; // return 'http://eduslim2.minedu.gov.gr/drupal';
} }
......
...@@ -27,7 +27,7 @@ import { APP_ROUTER_PROVIDERS, APP_DECLARATIONS } from './app.routes'; ...@@ -27,7 +27,7 @@ import { APP_ROUTER_PROVIDERS, APP_DECLARATIONS } from './app.routes';
/* Here we import services */ /* Here we import services */
import {HelperDataService} from './services/helper-data-service'; import {HelperDataService} from './services/helper-data-service';
import {UserDataService} from './services/user-data-service'; //import {UserDataService} from './services/user-data-service';
import { ACTION_PROVIDERS } from './actions'; import { ACTION_PROVIDERS } from './actions';
import Home from './components/home'; import Home from './components/home';
...@@ -69,9 +69,9 @@ class MyLocalization extends NgLocalization { ...@@ -69,9 +69,9 @@ class MyLocalization extends NgLocalization {
{ provide: NgLocalization, useClass: MyLocalization }, { provide: NgLocalization, useClass: MyLocalization },
DevToolsExtension, DevToolsExtension,
ACTION_PROVIDERS, ACTION_PROVIDERS,
// Service1, again services here //Service1, again services here
HelperDataService, HelperDataService,
UserDataService, //UserDataService,
] ]
}) })
class AppModule {} class AppModule {}
......
<div class="row equal"> <div class="row equal">
<div class="col-md-8"> <div class="col-md-8">
<form novalidate [formGroup]="studentDataGroup"> <form novalidate (ngSubmit)="onSubmit(studentDataGroup)" [formGroup]="studentDataGroup">
<div *ngFor="let studentDataField$ of studentDataFields$ | async; "> </div> <div *ngFor="let studentDataField$ of studentDataFields$ | async; "> </div>
<div class="form-group"> <div class="form-group">
<label for="studentAmka">ΑΜΚΑ μαθητή</label><input class="form-control" type="text" formControlName="studentAmka"> <label for="studentAmka">ΑΜΚΑ μαθητή</label><input class="form-control" type="text" formControlName="studentAmka">
</div> </div>
<div class="alert alert-danger" *ngIf="studentDataGroup.get('studentAmka').touched && studentDataGroup.get('studentAmka').hasError('required')">
Το πεδίο δεν μπορεί να αφεθεί κενό!
</div>
<div class="alert alert-danger" *ngIf="studentDataGroup.get('studentAmka').dirty && studentDataGroup.get('studentAmka').hasError('pattern')">
Επιτρέπονται μόνο ψηφία σε αυτό το πεδίο!
</div>
<div class="form-group"> <div class="form-group">
<label for="studentFirstname">Όνομα μαθητή</label><input class="form-control" type="text" formControlName="studentFirstname"> <label for="studentFirstname">Όνομα μαθητή</label><input class="form-control" type="text" formControlName="studentFirstname">
...@@ -13,7 +19,7 @@ ...@@ -13,7 +19,7 @@
<div class="alert alert-danger" *ngIf="studentDataGroup.get('studentFirstname').touched && studentDataGroup.get('studentFirstname').hasError('required')"> <div class="alert alert-danger" *ngIf="studentDataGroup.get('studentFirstname').touched && studentDataGroup.get('studentFirstname').hasError('required')">
Το πεδίο δεν μπορεί να αφεθεί κενό! Το πεδίο δεν μπορεί να αφεθεί κενό!
</div> </div>
<div class="alert alert-danger" *ngIf="studentDataGroup.get('studentFirstname').touched && studentDataGroup.get('studentFirstname').hasError('pattern')"> <div class="alert alert-danger" *ngIf="studentDataGroup.get('studentFirstname').dirty && studentDataGroup.get('studentFirstname').hasError('pattern')">
Δεν επιτρέπονται ψηφία ή άλλοι μη έγκυροι χαρακτήρες σε αυτό το πεδίο! Δεν επιτρέπονται ψηφία ή άλλοι μη έγκυροι χαρακτήρες σε αυτό το πεδίο!
</div> </div>
...@@ -23,7 +29,7 @@ ...@@ -23,7 +29,7 @@
<div class="alert alert-danger" *ngIf="studentDataGroup.get('studentSurname').touched && studentDataGroup.get('studentSurname').hasError('required')"> <div class="alert alert-danger" *ngIf="studentDataGroup.get('studentSurname').touched && studentDataGroup.get('studentSurname').hasError('required')">
Το πεδίο δεν μπορεί να αφεθεί κενό! Το πεδίο δεν μπορεί να αφεθεί κενό!
</div> </div>
<div class="alert alert-danger" *ngIf="studentDataGroup.get('studentSurname').touched && studentDataGroup.get('studentSurname').hasError('pattern')"> <div class="alert alert-danger" *ngIf="studentDataGroup.get('studentSurname').dirty && studentDataGroup.get('studentSurname').hasError('pattern')">
Δεν επιτρέπονται ψηφία ή άλλοι μη έγκυροι χαρακτήρες σε αυτό το πεδίο! Δεν επιτρέπονται ψηφία ή άλλοι μη έγκυροι χαρακτήρες σε αυτό το πεδίο!
</div> </div>
...@@ -33,7 +39,7 @@ ...@@ -33,7 +39,7 @@
<div class="alert alert-danger" *ngIf="studentDataGroup.get('guardianFirstname').touched && studentDataGroup.get('guardianFirstname').hasError('required')"> <div class="alert alert-danger" *ngIf="studentDataGroup.get('guardianFirstname').touched && studentDataGroup.get('guardianFirstname').hasError('required')">
Το πεδίο δεν μπορεί να αφεθεί κενό! Το πεδίο δεν μπορεί να αφεθεί κενό!
</div> </div>
<div class="alert alert-danger" *ngIf="studentDataGroup.get('guardianFirstname').touched && studentDataGroup.get('guardianFirstname').hasError('pattern')"> <div class="alert alert-danger" *ngIf="studentDataGroup.get('guardianFirstname').dirty && studentDataGroup.get('guardianFirstname').hasError('pattern')">
Δεν επιτρέπονται ψηφία ή άλλοι μη έγκυροι χαρακτήρες σε αυτό το πεδίο! Δεν επιτρέπονται ψηφία ή άλλοι μη έγκυροι χαρακτήρες σε αυτό το πεδίο!
</div> </div>
...@@ -44,7 +50,7 @@ ...@@ -44,7 +50,7 @@
<div class="alert alert-danger" *ngIf="studentDataGroup.get('guardianSurname').touched && studentDataGroup.get('guardianSurname').hasError('required')"> <div class="alert alert-danger" *ngIf="studentDataGroup.get('guardianSurname').touched && studentDataGroup.get('guardianSurname').hasError('required')">
Το πεδίο δεν μπορεί να αφεθεί κενό! Το πεδίο δεν μπορεί να αφεθεί κενό!
</div> </div>
<div class="alert alert-danger" *ngIf="studentDataGroup.get('guardianSurname').touched && studentDataGroup.get('guardianSurname').hasError('pattern')"> <div class="alert alert-danger" *ngIf="studentDataGroup.get('guardianSurname').dirty && studentDataGroup.get('guardianSurname').hasError('pattern')">
Δεν επιτρέπονται ψηφία ή άλλοι μη έγκυροι χαρακτήρες σε αυτό το πεδίο! Δεν επιτρέπονται ψηφία ή άλλοι μη έγκυροι χαρακτήρες σε αυτό το πεδίο!
</div> </div>
...@@ -54,16 +60,34 @@ ...@@ -54,16 +60,34 @@
<div class="form-group"> <div class="form-group">
<label for="regionAddress">Διεύθυνση κατοικίας</label><input class="form-control" type="text" formControlName="regionAddress"> <label for="regionAddress">Διεύθυνση κατοικίας</label><input class="form-control" type="text" formControlName="regionAddress">
</div> </div>
<div class="alert alert-danger" *ngIf="studentDataGroup.get('regionAddress').touched && studentDataGroup.get('regionAddress').hasError('required')">
Το πεδίο δεν μπορεί να αφεθεί κενό!
</div>
<div class="alert alert-danger" *ngIf="studentDataGroup.get('regionAddress').dirty && studentDataGroup.get('regionAddress').hasError('pattern')">
Δεν επιτρέπονται μη έγκυροι χαρακτήρες σε αυτό το πεδίο!
</div>
</td> </td>
<td> <td>
<div class="form-group"> <div class="form-group">
<label for="regionTK">TK </label><input class="form-control" type="text" formControlName="regionTK"> <label for="regionTK">TK </label><input class="form-control" type="text" formControlName="regionTK">
</div> </div>
<div class="alert alert-danger" *ngIf="studentDataGroup.get('regionTK').touched && studentDataGroup.get('regionTK').hasError('required')">
Το πεδίο δεν μπορεί να αφεθεί κενό!
</div>
<div class="alert alert-danger" *ngIf="studentDataGroup.get('regionTK').dirty && studentDataGroup.get('regionTK').hasError('pattern')">
Δεν επιτρέπονται γράμματα αλφαβήτου ή μη έγκυροι χαρακτήρες σε αυτό το πεδίο!
</div>
</td> </td>
<td> <td>
<div class="form-group"> <div class="form-group">
<label for="regionArea">Πόλη/Περιοχή</label><input class="form-control" type="text" formControlName="regionArea"> <label for="regionArea">Πόλη/Περιοχή</label><input class="form-control" type="text" formControlName="regionArea">
</div> </div>
<div class="alert alert-danger" *ngIf="studentDataGroup.get('regionArea').touched && studentDataGroup.get('regionArea').hasError('required')">
Το πεδίο δεν μπορεί να αφεθεί κενό!
</div>
<div class="alert alert-danger" *ngIf="studentDataGroup.get('regionArea').dirty && studentDataGroup.get('regionArea').hasError('pattern')">
Δεν επιτρέπονται μη έγκυροι χαρακτήρες σε αυτό το πεδίο!
</div>
</td> </td>
</tr> </tr>
</table> </table>
...@@ -76,7 +100,7 @@ ...@@ -76,7 +100,7 @@
<option value="Απολυτήριο Λυκείου">Απολυτήριο Λυκείου</option> <option value="Απολυτήριο Λυκείου">Απολυτήριο Λυκείου</option>
</select> </select>
</div> </div>
<div class="alert alert-danger" *ngIf="studentDataGroup.get('certificateType').touched && studentDataGroup.get('certificateType').hasError('required')"> <div class="alert alert-danger" *ngIf="studentDataGroup.get('certificateType').dirty && studentDataGroup.get('certificateType').hasError('required')">
Η επιλογή από αυτή τη λίστα είναι απαραίτητη! Η επιλογή από αυτή τη λίστα είναι απαραίτητη!
</div> </div>
...@@ -87,7 +111,7 @@ ...@@ -87,7 +111,7 @@
<option value="Γονέας/Κηδεμόνας">Γονέας/Κηδεμόνας</option> <option value="Γονέας/Κηδεμόνας">Γονέας/Κηδεμόνας</option>
<option value="Μαθητής">Μαθητής</option> <option value="Μαθητής">Μαθητής</option>
</select> </select>
<div class="alert alert-danger" *ngIf="studentDataGroup.get('relationToStudent').touched && studentDataGroup.get('relationToStudent').hasError('required')"> <div class="alert alert-danger" *ngIf="studentDataGroup.get('relationToStudent').dirty && studentDataGroup.get('relationToStudent').hasError('required')">
Η επιλογή από αυτή τη λίστα είναι απαραίτητη! Η επιλογή από αυτή τη λίστα είναι απαραίτητη!
</div> </div>
</div> </div>
...@@ -99,7 +123,7 @@ ...@@ -99,7 +123,7 @@
</button> </button>
</div> </div>
<div class="col-md-2"> <div class="col-md-2">
<button type="button" class="btn-primary btn-lg pull-center" (click)="submitSelected()"> <button type="button" class="btn-primary btn-lg pull-center" (click)="submitSelected()" [disabled]="studentDataGroup.invalid">
Αποστολή<span class="glyphicon glyphicon-menu-right"></span> Αποστολή<span class="glyphicon glyphicon-menu-right"></span>
</button> </button>
</div> </div>
......
...@@ -8,7 +8,7 @@ import { NgRedux, select } from 'ng2-redux'; ...@@ -8,7 +8,7 @@ import { NgRedux, select } from 'ng2-redux';
import { IStudentDataFields } from '../../store/studentdatafields/studentdatafields.types'; import { IStudentDataFields } from '../../store/studentdatafields/studentdatafields.types';
import { ICourseFields } from '../../store/coursefields/coursefields.types'; import { ICourseFields } from '../../store/coursefields/coursefields.types';
import { IAppState } from '../../store/store'; import { IAppState } from '../../store/store';
import { VALID_NAMES_PATTERN } from '../../constants'; import { VALID_NAMES_PATTERN, VALID_ADDRESS_PATTERN, VALID_ADDRESSTK_PATTERN, VALID_AMKA_PATTERN } from '../../constants';
import { import {
FormBuilder, FormBuilder,
...@@ -34,6 +34,7 @@ import { ...@@ -34,6 +34,7 @@ import {
private _ngRedux: NgRedux<IAppState>, private _ngRedux: NgRedux<IAppState>,
private router: Router) { private router: Router) {
this.studentDataGroup = this.fb.group({ this.studentDataGroup = this.fb.group({
/*
studentAmka: ['12346', Validators.required], studentAmka: ['12346', Validators.required],
studentFirstname: ['ΝΙΚΟΣ', [Validators.pattern(VALID_NAMES_PATTERN),Validators.required]], studentFirstname: ['ΝΙΚΟΣ', [Validators.pattern(VALID_NAMES_PATTERN),Validators.required]],
studentSurname: ['ΚΑΤΣΑΟΥΝΟΣ', [Validators.pattern(VALID_NAMES_PATTERN),Validators.required]], studentSurname: ['ΚΑΤΣΑΟΥΝΟΣ', [Validators.pattern(VALID_NAMES_PATTERN),Validators.required]],
...@@ -44,6 +45,17 @@ import { ...@@ -44,6 +45,17 @@ import {
regionArea: ['ΠΑΤΡΑ', [Validators.pattern(VALID_NAMES_PATTERN),Validators.required]], regionArea: ['ΠΑΤΡΑ', [Validators.pattern(VALID_NAMES_PATTERN),Validators.required]],
certificateType: ['Απολυτήριο Λυκείου', Validators.required], certificateType: ['Απολυτήριο Λυκείου', Validators.required],
relationToStudent: ['Μαθητής', Validators.required], relationToStudent: ['Μαθητής', Validators.required],
*/
studentAmka: ['12346', [Validators.pattern(VALID_AMKA_PATTERN),Validators.required]],
studentFirstname: ['ΝΙΚΟΣ', [Validators.pattern(VALID_NAMES_PATTERN),Validators.required]],
studentSurname: ['ΚΑΤΣΑΟΥΝΟΣ', [Validators.pattern(VALID_NAMES_PATTERN),Validators.required]],
guardianFirstname: ['ΑΝΑΣΤΑΣΙΟΣ', [Validators.pattern(VALID_NAMES_PATTERN),Validators.required]],
guardianSurname: ['ΚΑΤΣΑΟΥΝΟΣ', [Validators.pattern(VALID_NAMES_PATTERN),Validators.required]],
regionAddress: ['ΓΙΑΝΝΙΤΣΩΝ 5', [Validators.pattern(VALID_ADDRESS_PATTERN),Validators.required]],
regionTK: ['26334', [Validators.pattern(VALID_ADDRESSTK_PATTERN),Validators.required]],
regionArea: ['ΠΑΤΡΑ', [Validators.pattern(VALID_NAMES_PATTERN),Validators.required]],
certificateType: ['Απολυτήριο Λυκείου', Validators.required],
relationToStudent: ['Μαθητής', Validators.required],
}); });
}; };
...@@ -57,13 +69,6 @@ import { ...@@ -57,13 +69,6 @@ import {
} }
return state.studentDataFields; return state.studentDataFields;
}); });
this.courseFields$ = this._ngRedux.select(state => {
state.courseFields.reduce(({}, courseField) =>{
return courseField;
}, {});
return state.courseFields;
});
} }
saveSelected() { saveSelected() {
......
...@@ -36,11 +36,22 @@ import {AppSettings} from '../../app.settings'; ...@@ -36,11 +36,22 @@ import {AppSettings} from '../../app.settings';
<div class="row"> <div class="row">
<div class="btn-group inline pull-center"> <div class="btn-group inline pull-center">
<button type="button" class="btn-primary btn-md pull-center" [disabled] = true> <button type="button" class="btn-primary btn-md pull-center" (click)="defineCourse()" >
Η ειδικότητά μου<span class="glyphicon glyphicon-menu-right"></span> Η ειδικότητά μου<span class="glyphicon glyphicon-menu-right"></span>
</button> </button>
</div> </div>
</div> </div>
<!--
<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>
-->
<ul class="list-group" style="margin-bottom: 20px;"> <ul class="list-group" style="margin-bottom: 20px;">
<div *ngFor="let sector$ of sectors$ | async;"> <div *ngFor="let sector$ of sectors$ | async;">
<div *ngFor="let course$ of sector$.courses;" > <div *ngFor="let course$ of sector$.courses;" >
...@@ -51,14 +62,6 @@ import {AppSettings} from '../../app.settings'; ...@@ -51,14 +62,6 @@ import {AppSettings} from '../../app.settings';
</div> </div>
</ul> </ul>
<div class="row">
<div class="btn-group inline pull-right">
<button class="btn-primary btn-md pull-center my-btn" type="button" (click)="defineCourse()" [hidden] = "numSelectedSchools === 0" >
Επαναφορά<span class="glyphicon glyphicon-menu-right"></span>
</button>
</div>
</div>
<div class="row"> <div class="row">
<div class="btn-group inline pull-center"> <div class="btn-group inline pull-center">
<button type="button" id = "butsch" class="btn-primary btn-md pull-center" (click)="defineSchools()" [disabled] = "numSelectedSchools === 0 "> <button type="button" id = "butsch" class="btn-primary btn-md pull-center" (click)="defineSchools()" [disabled] = "numSelectedSchools === 0 ">
...@@ -106,8 +109,7 @@ import {AppSettings} from '../../app.settings'; ...@@ -106,8 +109,7 @@ import {AppSettings} from '../../app.settings';
private studentDataFields$: Observable<IStudentDataFields>; private studentDataFields$: Observable<IStudentDataFields>;
private courseActive = "-1"; private courseActive = "-1";
private numSelectedSchools = <number>0; private numSelectedSchools = <number>0;
private numSelectedCourses = <number>0; //private numSelectedCourses = <number>0;
constructor(private _rsa: SectorCoursesActions, constructor(private _rsa: SectorCoursesActions,
private _rsb: RegionSchoolsActions, private _rsb: RegionSchoolsActions,
...@@ -120,38 +122,28 @@ import {AppSettings} from '../../app.settings'; ...@@ -120,38 +122,28 @@ import {AppSettings} from '../../app.settings';
ngOnInit() { ngOnInit() {
this.courseActive = this.getCourseActive(); this.courseActive = this.getCourseActive();
this._rsa.getSectorCourses(false);
this.sectors$ = this._ngRedux.select(state => { this.sectors$ = this._ngRedux.select(state => {
let numsel = 0; //let numsel = 0;
state.sectors.reduce((prevSector, sector) =>{ state.sectors.reduce((prevSector, sector) =>{
sector.courses.reduce((prevCourse, course) =>{ sector.courses.reduce((prevCourse, course) =>{
if (course.selected === true) { //if (course.selected === true) {
numsel++; // numsel++;
//this.numSelectedCourses //}
}
return course; return course;
}, {}); }, {});
return sector; return sector;
}, {}); }, {});
this.numSelectedCourses = numsel; //this.numSelectedCourses = numsel;
return state.sectors; return state.sectors;
}); });
//WORKED STRANGELY BEFORE..
/*
this.courseActive = this.getCourseActive();
this._rsb.getRegionSchools(this.courseActive);
*/
this._rsb.getRegionSchools(this.courseActive, false);
this.regions$ = this._ngRedux.select(state => { this.regions$ = this._ngRedux.select(state => {
let numsel = 0; let numsel = 0;
state.regions.reduce((prevRegion, region) =>{ state.regions.reduce((prevRegion, region) =>{
region.epals.reduce((prevSchool, school) =>{ region.epals.reduce((prevEpal, epal) =>{
if (school.selected === true) if (epal.selected === true)
numsel++; numsel++;
return school; return epal;
}, {}); }, {});
return region; return region;
}, {}); }, {});
...@@ -159,7 +151,6 @@ import {AppSettings} from '../../app.settings'; ...@@ -159,7 +151,6 @@ import {AppSettings} from '../../app.settings';
return state.regions; return state.regions;
}); });
this._rsc.getSectorFields();
this.sectorFields$ = this._ngRedux.select(state => { this.sectorFields$ = this._ngRedux.select(state => {
state.sectorFields.reduce(({}, sectorField) =>{ state.sectorFields.reduce(({}, sectorField) =>{
return sectorField; return sectorField;
...@@ -180,8 +171,25 @@ import {AppSettings} from '../../app.settings'; ...@@ -180,8 +171,25 @@ import {AppSettings} from '../../app.settings';
this.router.navigate(['/sector-fields-select']); this.router.navigate(['/sector-fields-select']);
} }
defineSchools() {
this.router.navigate(['/region-schools-select']);
}
definePersonalData() {
this.router.navigate(['/student-application-form-main']);
}
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"];
}
/*
defineCourse() { defineCourse() {
//this._rsb.getRegionSchools_Reload("-1");
this._rsb.getRegionSchools("-1", true); this._rsb.getRegionSchools("-1", true);
this.regions$ = this._ngRedux.select(state => { this.regions$ = this._ngRedux.select(state => {
let numsel = 0; let numsel = 0;
...@@ -197,8 +205,6 @@ import {AppSettings} from '../../app.settings'; ...@@ -197,8 +205,6 @@ import {AppSettings} from '../../app.settings';
return state.regions; return state.regions;
}); });
//this._rsa.getSectorCourses_Reload();
this._rsa.getSectorCourses(true); this._rsa.getSectorCourses(true);
this.sectors$ = this._ngRedux.select(state => { this.sectors$ = this._ngRedux.select(state => {
state.sectors.reduce((prevSector, sector) =>{ state.sectors.reduce((prevSector, sector) =>{
...@@ -213,26 +219,10 @@ import {AppSettings} from '../../app.settings'; ...@@ -213,26 +219,10 @@ import {AppSettings} from '../../app.settings';
this.router.navigate(['/sectorcourses-fields-select']); this.router.navigate(['/sectorcourses-fields-select']);
} }
*/
defineSchools() { defineCourse() {
this.router.navigate(['/region-schools-select']); this.router.navigate(['/sectorcourses-fields-select']);
} }
definePersonalData() {
this.router.navigate(['/student-application-form-main']);
}
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"];
}
} }
...@@ -90,8 +90,8 @@ import {AppSettings} from '../../app.settings'; ...@@ -90,8 +90,8 @@ import {AppSettings} from '../../app.settings';
}; };
ngOnInit() { ngOnInit() {
this.courseActive = this.getCourseActive();
this.courseActive = this.getCourseActive();
this._rsa.getRegionSchools(this.courseActive, false); this._rsa.getRegionSchools(this.courseActive, false);
this.regions$ = this._ngRedux.select(state => { this.regions$ = this._ngRedux.select(state => {
...@@ -99,8 +99,10 @@ import {AppSettings} from '../../app.settings'; ...@@ -99,8 +99,10 @@ import {AppSettings} from '../../app.settings';
state.regions.reduce((prevRegion, region) =>{ state.regions.reduce((prevRegion, region) =>{
region.epals.reduce((prevEpal, epal) =>{ region.epals.reduce((prevEpal, epal) =>{
this.rss.push( new FormControl(epal.selected, [])); this.rss.push( new FormControl(epal.selected, []));
if (epal.selected === true) if (epal.selected === true) {
numsel++; numsel++;
console.log(epal.epal_name);
}
return epal; return epal;
}, {}); }, {});
return region; return region;
......
...@@ -3,8 +3,10 @@ import { Router } from '@angular/router'; ...@@ -3,8 +3,10 @@ import { Router } from '@angular/router';
import { Observable } from 'rxjs/Rx'; import { Observable } from 'rxjs/Rx';
import { Injectable } from "@angular/core"; import { Injectable } from "@angular/core";
import { SectorCoursesActions } from '../../actions/sectorcourses.actions'; import { SectorCoursesActions } from '../../actions/sectorcourses.actions';
import { NgRedux, select } from 'ng2-redux';
import { ISectors } from '../../store/sectorcourses/sectorcourses.types'; import { ISectors } from '../../store/sectorcourses/sectorcourses.types';
import { RegionSchoolsActions } from '../../actions/regionschools.actions';
import { IRegions } from '../../store/regionschools/regionschools.types';
import { NgRedux, select } from 'ng2-redux';
import { IAppState } from '../../store/store'; import { IAppState } from '../../store/store';
import { import {
...@@ -27,7 +29,6 @@ import {AppSettings} from '../../app.settings'; ...@@ -27,7 +29,6 @@ import {AppSettings} from '../../app.settings';
<li class="list-group-item" (click)="setActiveSector(i)" [style.background-color]="toggleBackgroundColor(i)"> <li class="list-group-item" (click)="setActiveSector(i)" [style.background-color]="toggleBackgroundColor(i)">
<h5>{{sector$.sector_name}}</h5> <h5>{{sector$.sector_name}}</h5>
</li> </li>
<div *ngFor="let course$ of sector$.courses; let j=index;" [hidden]="i !== sectorActive"> <div *ngFor="let course$ of sector$.courses; let j=index;" [hidden]="i !== sectorActive">
<li class="list-group-item" > <li class="list-group-item" >
<div class="row"> <div class="row">
...@@ -65,15 +66,16 @@ import {AppSettings} from '../../app.settings'; ...@@ -65,15 +66,16 @@ import {AppSettings} from '../../app.settings';
}) })
@Injectable() export default class SectorCoursesSelect implements OnInit { @Injectable() export default class SectorCoursesSelect implements OnInit {
private sectors$: Observable<ISectors>; private sectors$: Observable<ISectors>;
private regions$: Observable<IRegions>;
private formGroup: FormGroup; private formGroup: FormGroup;
private rss = new FormArray([]); private rss = new FormArray([]);
private sectorActive = <number>-1; private sectorActive = <number>-1;
private idx = <number>-1; private idx = <number>-1;
private sectorsList: Array<boolean> = new Array(); private sectorsList: Array<boolean> = new Array();
//private sectorsList = new Array([]);
constructor(private fb: FormBuilder, constructor(private fb: FormBuilder,
private _rsa: SectorCoursesActions, private _rsa: SectorCoursesActions,
private _rsr: RegionSchoolsActions,
private _ngRedux: NgRedux<IAppState>, private _ngRedux: NgRedux<IAppState>,
private router: Router private router: Router
) { ) {
...@@ -83,9 +85,11 @@ import {AppSettings} from '../../app.settings'; ...@@ -83,9 +85,11 @@ import {AppSettings} from '../../app.settings';
};