updated Criteria Component

parent 6456d772
import { CRITERIA_SAVE} from '../constants'; import { CRITERIA_RECEIVED, CRITERIA_SAVE} 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';
@Injectable() @Injectable()
export class CriteriaActions { export class CriteriaActions {
constructor( constructor(
private _ngRedux: NgRedux<IAppState>) {} private _ngRedux: NgRedux<IAppState>,
private _hds: HelperDataService) {}
getCriteria = (reload) => {
const { criter } = this._ngRedux.getState();
//if (sectorFields.size === 0) {
if (reload === true || (reload === false && criter.size === 0)) {
return this._hds.getCriteria().then(criteria => {
return this._ngRedux.dispatch({
type: CRITERIA_RECEIVED,
payload: {
criteria
}
});
});
}
};
saveCriteria = (criter) => { saveCriteria = (criter) => {
return this._ngRedux.dispatch({ return this._ngRedux.dispatch({
......
...@@ -112,31 +112,45 @@ ...@@ -112,31 +112,45 @@
<form novalidate (ngSubmit)="onSubmit(studentCriteriaGroup)" [formGroup]="studentCriteriaGroup"> <form novalidate (ngSubmit)="onSubmit(studentCriteriaGroup)" [formGroup]="studentCriteriaGroup">
<div *ngFor="let criter$ of criteria$ | async; let i=index"> </div>
<!--
<fieldset class="group"> <fieldset class="group">
-->
<legend>Εισοδηματικά κριτήρια</legend> <legend>Εισοδηματικά κριτήρια</legend>
<select #cblsttest class="form-control" (change)="checkstatus(cblsttest)" formControlName="incometest">
<option *ngFor="let criter$ of criteria$ | async; let i=index" >
<div *ngIf="criter$.name === 'Εισόδημα' && criter$.name !== 'Απόσταση'">
{{criter$.name}} </div></option>
</select>
<div class="form-group"> <div class="form-group">
<label for="income">Το κατά κεφαλήν εισόδημα στο προηγούμενο φορολογικό έτος είναι:</label><br/> <label for="income">Το κατά κεφαλήν εισόδημα στο προηγούμενο φορολογικό έτος είναι:</label><br/>
<select class="form-control" (change)="checkstatus()" formControlName="income"> <select #cblst class="form-control" (change)="checkstatus(cblst)" formControlName="income">
<option value="noincomecriterio">Παρακαλώ επιλέξτε..</option> <option value="noincomecriterio" [selected] = "selectionIncomeId === 0" >Παρακαλώ επιλέξτε..</option>
<option value="<= 3000 Ευρώ">μικρότερο ή ίσο των 3000 Ευρώ</option> <option value="<= 3000 Ευρώ" [selected] = "selectionIncomeId === 8" >μικρότερο ή ίσο των 3000 Ευρώ</option>
<option value="<= 6000 Ευρώ">μικρότερο ή ίσο των 6000 Ευρώ</option> <option value="<= 6000 Ευρώ" [selected] = "selectionIncomeId === 9" >μικρότερο ή ίσο των 6000 Ευρώ</option>
<option value="<= 9000 Ευρώ">μικρότερο ή ίσο των 9000 Ευρώ</option> <option value="<= 9000 Ευρώ" [selected] = "selectionIncomeId === 10" >μικρότερο ή ίσο των 9000 Ευρώ</option>
<option value="> 9000 Ευρώ">μεγαλύτερο των 9000 Ευρώ</option> <option value="> 9000 Ευρώ" [selected] = "selectionIncomeId === 11" >μεγαλύτερο των 9000 Ευρώ</option>
</select> </select>
<!-- studentCriteriaGroup.get('income').dirty && -->
<div class="alert alert-danger" *ngIf=" studentCriteriaGroup.get('income').hasError('status')"> <div class="alert alert-danger" *ngIf=" studentCriteriaGroup.get('income').hasError('status')">
Η επιλογή από αυτή τη λίστα είναι απαραίτητη! Η επιλογή από αυτή τη λίστα είναι απαραίτητη!
</div> </div>
</div> </div>
<div formArrayName="formArray">
<div *ngFor="let criter$ of criteria$ | async; let i=index"> </div>
<legend>Κοινωνικά κριτήρια</legend> <legend>Κοινωνικά κριτήρια</legend>
<p style="margin-top: 15px; line-height: 1.5em;">Επιλέξτε όσα από τα παρακάτω κριτήρια πληρούνται για εσάς. <p style="margin-top: 15px; line-height: 1.5em;">Επιλέξτε όσα από τα παρακάτω κριτήρια πληρούνται για εσάς.
Οι επιλογές σας επέχουν θέση υπέυθυνης δήλωσης. Οι επιλογές σας επέχουν θέση υπέυθυνης δήλωσης.
Θα πρέπει να προσκομίσετε τα αντίστοιχα δικαιολογητικά στο σχολείο εγγραφής σας, όταν σας ζητηθεί. Θα πρέπει να προσκομίσετε τα αντίστοιχα δικαιολογητικά στο σχολείο εγγραφής σας, όταν σας ζητηθεί.
</p> </p>
<!--
<div class="row"> <div class="row">
<div class="col-md-1"> <input #cborphanmono type="checkbox" (change)="checkorphan('mono', cborphanmono)" formControlName="orphanmono" ></div> <div class="col-md-1"> <input #cborphanmono type="checkbox" (change)="checkorphan('mono', cborphanmono)" formControlName="orphanmono" ></div>
<div class="col-md-11 pull-left">Ορφανός από τον ένα γονέα</div> <div class="col-md-11 pull-left">Ορφανός από τον ένα γονέα</div>
...@@ -165,7 +179,33 @@ ...@@ -165,7 +179,33 @@
<div class="col-md-1"> <input type="checkbox" (change)="checkstatus()" formControlName="studies"></div> <div class="col-md-1"> <input type="checkbox" (change)="checkstatus()" formControlName="studies"></div>
<div class="col-md-11 pull-left">Αδελφός,-ή που σπουδάζει σε άλλη πόλη</div> <div class="col-md-11 pull-left">Αδελφός,-ή που σπουδάζει σε άλλη πόλη</div>
</div> </div>
-->
<div *ngFor="let criter$ of criteria$ | async; let i=index">
<div class="row" *ngIf="criter$.name !== 'Εισόδημα' && criter$.name !== 'Απόσταση'">
<div class="col-md-1">
<input #cb type="checkbox" (change)="checkcriteria(cb, criter$.mutual_disabled_id)" formControlName={{i}}>
</div>
<div class="col-md-11 pull-left">
{{criter$.name}}
</div>
</div>
</div>
<div class="row">
</div>
<!--
</fieldset> </fieldset>
-->
</div>
</form> </form>
......
...@@ -14,6 +14,7 @@ import { ...@@ -14,6 +14,7 @@ import {
FormBuilder, FormBuilder,
FormGroup, FormGroup,
FormControl, FormControl,
FormArray,
Validators, Validators,
} from '@angular/forms'; } from '@angular/forms';
...@@ -30,6 +31,9 @@ import { ...@@ -30,6 +31,9 @@ import {
public studentDataGroup: FormGroup; public studentDataGroup: FormGroup;
public applicantDataGroup: FormGroup; public applicantDataGroup: FormGroup;
public studentCriteriaGroup: FormGroup; public studentCriteriaGroup: FormGroup;
private rss = new FormArray([]);
private selectionIncomeId = <number>0;
//public orphanmode = <number>0; //public orphanmode = <number>0;
//public childrenmode = <number>0; //public childrenmode = <number>0;
...@@ -45,8 +49,8 @@ import { ...@@ -45,8 +49,8 @@ import {
regionaddress: ['ΓΙΑΝΝΙΤΣΩΝ 5', [Validators.pattern(VALID_ADDRESS_PATTERN),Validators.required]], regionaddress: ['ΓΙΑΝΝΙΤΣΩΝ 5', [Validators.pattern(VALID_ADDRESS_PATTERN),Validators.required]],
regiontk: ['26334', [Validators.pattern(VALID_ADDRESSTK_PATTERN),Validators.required]], regiontk: ['26334', [Validators.pattern(VALID_ADDRESSTK_PATTERN),Validators.required]],
regionarea: ['ΠΑΤΡΑ', [Validators.pattern(VALID_NAMES_PATTERN),Validators.required]], regionarea: ['ΠΑΤΡΑ', [Validators.pattern(VALID_NAMES_PATTERN),Validators.required]],
certificatetype: ['Απολυτήριο Λυκείου', this.checkChoice], certificatetype: ['Απολυτήριο Λυκείου', checkChoice],
relationtostudent: ['Μαθητής', this.checkChoice], relationtostudent: ['Μαθητής', checkChoice],
telnum: ['2610789789', [Validators.pattern(VALID_DIGITS_PATTERN),Validators.required]], telnum: ['2610789789', [Validators.pattern(VALID_DIGITS_PATTERN),Validators.required]],
}); });
...@@ -55,6 +59,7 @@ import { ...@@ -55,6 +59,7 @@ import {
guardiansurname: ['ΚΑΤΣΑΟΥΝΟΣ', [Validators.pattern(VALID_NAMES_PATTERN),Validators.required]], guardiansurname: ['ΚΑΤΣΑΟΥΝΟΣ', [Validators.pattern(VALID_NAMES_PATTERN),Validators.required]],
}); });
/*
this.studentCriteriaGroup = this.fb.group({ this.studentCriteriaGroup = this.fb.group({
orphanmono: false, orphanmono: false,
orphantwice: false, orphantwice: false,
...@@ -63,9 +68,15 @@ import { ...@@ -63,9 +68,15 @@ import {
twins: false, twins: false,
disability: false, disability: false,
studies: false, studies: false,
income: ['noincomecriterio', this.checkChoice ], income: ['noincomecriterio', checkChoice ],
});
*/
this.studentCriteriaGroup = this.fb.group({
formArray: this.rss,
income: ['noincomecriterio', checkChoice ],
incometest: ['noincomecriterio', checkChoice ],
}); });
}; };
ngOnInit() { ngOnInit() {
...@@ -80,10 +91,16 @@ import { ...@@ -80,10 +91,16 @@ import {
return state.studentDataFields; return state.studentDataFields;
}); });
this._sdfb.getCriteria(true);
this.criteria$ = this._ngRedux.select(state => { this.criteria$ = this._ngRedux.select(state => {
if (state.criter.size > 0) { if (state.criter.size > 0) {
state.criter.reduce(({}, criteria) => { state.criter.reduce(({}, criteria) => {
this.studentCriteriaGroup.setValue(criteria); //this.studentCriteriaGroup.setValue(criteria);
if (criteria.selected === true && (criteria.id === "8" || criteria.id === "9" || criteria.id === "10" || criteria.id === "11" ))
this.selectionIncomeId = Number(criteria.id);
console.log("Yes");
console.log(this.selectionIncomeId);
this.rss.push( new FormControl(criteria.selected, []));
return criteria; return criteria;
}, {}); }, {});
} }
...@@ -112,6 +129,13 @@ import { ...@@ -112,6 +129,13 @@ import {
submitSelected() { submitSelected() {
this._sdfa.saveStudentDataFields([this.studentDataGroup.value]); this._sdfa.saveStudentDataFields([this.studentDataGroup.value]);
this.studentCriteriaGroup.controls['formArray']['controls'][7].setValue(false);
this.studentCriteriaGroup.controls['formArray']['controls'][8].setValue(false);
this.studentCriteriaGroup.controls['formArray']['controls'][9].setValue(false);
this.studentCriteriaGroup.controls['formArray']['controls'][10].setValue(false);
this.studentCriteriaGroup.controls['formArray']['controls'][this.selectionIncomeId-1].setValue(true);
this._sdfb.saveCriteria([this.studentCriteriaGroup.value.formArray]);
this.router.navigate(['/application-submit']); this.router.navigate(['/application-submit']);
} }
...@@ -139,20 +163,52 @@ import { ...@@ -139,20 +163,52 @@ import {
//console.log(this.studentCriteriaGroup.value); //console.log(this.studentCriteriaGroup.value);
} }
checkstatus() { checkcriteria(cb, mutual_disabled) {
//this.studentCriteriaGroup.controls[name].setValue(cb.checked); if (mutual_disabled !== "-1" && cb.checked === true) {
//console.log("after check"); this.studentCriteriaGroup.controls['formArray']['controls'][mutual_disabled-1].setValue(false);
//console.log(this.studentCriteriaGroup.value); }
this._sdfb.saveCriteria([this.studentCriteriaGroup.value]); //this._sdfb.saveCriteria([this.studentCriteriaGroup.value.formArray]);
} }
checkChoice(c: FormControl) {
console.log(c.value);
if (c.value === "noincomecriterio") checkstatus(cb) {
return {status: true} console.log("Hey");
else console.log(this.studentCriteriaGroup.value.income);
// Null means valid, believe it or not //this._sdfb.saveCriteria([this.studentCriteriaGroup.value.income]);
return null;
console.log("OK");
console.log(cb.value);
if (cb.value === "<= 3000 Ευρώ")
this.selectionIncomeId = 8;
else if (cb.value === "<= 6000 Ευρώ")
this.selectionIncomeId = 9;
else if (cb.value === "<= 9000 Ευρώ")
this.selectionIncomeId = 10;
else if (cb.value === "> 9000 Ευρώ")
this.selectionIncomeId = 11;
//this.studentCriteriaGroup.value[9] = true;
//this.studentCriteriaGroup.value[9] = false;
console.log(this.studentCriteriaGroup.value.formArray);
console.log(this.studentCriteriaGroup.value);
//this._sdfb.saveCriteria([this.studentCriteriaGroup.value.formArray]);
} }
}
function checkChoice(c: FormControl) {
console.log(c.value);
if (c.value === "noincomecriterio")
return {status: true}
else
// Null means valid, believe it or not
return null;
} }
...@@ -127,6 +127,21 @@ import {AppSettings} from '../../app.settings'; ...@@ -127,6 +127,21 @@ import {AppSettings} from '../../app.settings';
}); });
this.showLoaderSchools$ = this.regions$.map(regions => regions.size === 0); this.showLoaderSchools$ = this.regions$.map(regions => regions.size === 0);
this.criteria$ = this._ngRedux.select(state => {
if (state.criter.size > 0) {
state.criter.reduce(({}, criteria) => {
//code to be replaced in next version
if (criteria.selected === true && Number(criteria.id) !== 11)
this.studentCriteria.push(Number(criteria.id));
return criteria;
}, {});
}
return state.criter;
});
this.showLoaderCriteria$ = this.criteria$.map(criter => criter.size === 0);
/*
this.criteria$ = this._ngRedux.select(state => { this.criteria$ = this._ngRedux.select(state => {
if (state.criter.size > 0) { if (state.criter.size > 0) {
state.criter.reduce(({}, criteria) => { state.criter.reduce(({}, criteria) => {
...@@ -158,6 +173,7 @@ import {AppSettings} from '../../app.settings'; ...@@ -158,6 +173,7 @@ import {AppSettings} from '../../app.settings';
return state.criter; return state.criter;
}); });
this.showLoaderCriteria$ = this.criteria$.map(criter => criter.size === 0); this.showLoaderCriteria$ = this.criteria$.map(criter => criter.size === 0);
*/
this.sectors$ = this._ngRedux.select(state => { this.sectors$ = this._ngRedux.select(state => {
state.sectors.reduce((prevSector, sector) =>{ state.sectors.reduce((prevSector, sector) =>{
......
...@@ -23,6 +23,7 @@ export const AMKAFILL_SAVE = 'AMKAFILL_SAVE'; ...@@ -23,6 +23,7 @@ export const AMKAFILL_SAVE = 'AMKAFILL_SAVE';
export const LOGININFO_SAVE = 'LOGININFO_SAVE'; export const LOGININFO_SAVE = 'LOGININFO_SAVE';
export const LOGININFO_INIT = 'LOGININFO_INIT'; export const LOGININFO_INIT = 'LOGININFO_INIT';
export const CRITERIA_RECEIVED = 'CRITERIA_RECEIVED';
export const CRITERIA_SAVE = 'CRITERIA_SAVE'; export const CRITERIA_SAVE = 'CRITERIA_SAVE';
//export const VALID_NAMES_PATTERN = '[Α-ΩΆΈΉΊΎΌΏα-ωάέήίύόώ ]*$'; //export const VALID_NAMES_PATTERN = '[Α-ΩΆΈΉΊΎΌΏα-ωάέήίύόώ ]*$';
......
...@@ -229,7 +229,30 @@ export class HelperDataService { ...@@ -229,7 +229,30 @@ export class HelperDataService {
return rsa; return rsa;
} }
getCriteria() {
this.loginInfo$.forEach(loginInfoToken => {
console.log(loginInfoToken.get(0));
this.authToken = loginInfoToken.get(0).auth_token;
});
let headers = new Headers({
"Content-Type": "application/json",
"X-CSRF-Token": "LU92FaWYfImfZxfldkF5eVnssdHoV7Aa9fg8K1bWYUc",
});
this.createAuthorizationHeader(headers);
let options = new RequestOptions({ headers: headers });
return new Promise((resolve, reject) => {
this.http.get(`${AppSettings.API_ENDPOINT}/criteria/list`, options)
.map(response => <ISectorField[]>response.json())
.subscribe(data => {
resolve(data);
}, // put the data returned from the server in our variable
error => {
console.log("Error HTTP GET Service"); // in case of failure show this message
reject("Error HTTP GET Service");
},
() => console.log("Sector Fields Received"));//run this code in all cases); */
});
};
getCurrentUser() { getCurrentUser() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
......
...@@ -3,17 +3,26 @@ import { INITIAL_STATE } from './criteria.initial-state'; ...@@ -3,17 +3,26 @@ import { INITIAL_STATE } from './criteria.initial-state';
import { Seq } from 'immutable'; import { Seq } from 'immutable';
import { import {
CRITERIA_RECEIVED,
CRITERIA_SAVE CRITERIA_SAVE
} from '../../constants'; } from '../../constants';
export function criteriaReducer(state: ICriter = INITIAL_STATE, action): ICriter { export function criteriaReducer(state: ICriter = INITIAL_STATE, action): ICriter {
switch (action.type) { switch (action.type) {
case CRITERIA_RECEIVED:
let newCriter = Array<ICriteria>();
let i=0;
action.payload.criteria.forEach(criteria => {
newCriter.push(<ICriteria>{id: criteria.id, name: criteria.name, mutual_disabled_id: criteria.mutual_disabled_id, selected: false});
i++;
});
return Seq(newCriter).map(n => n).toList();
case CRITERIA_SAVE: case CRITERIA_SAVE:
let criter = Array<ICriteria>(); let criter = Array<ICriteria>();
let ind=0; let ind=0;
state.forEach(criteria => {
action.payload.criter.forEach(criteria => { criter.push(<ICriteria>{id: criteria.id, name: criteria.name, mutual_disabled_id: criteria.mutual_disabled_id, selected: action.payload.criter[0][ind]});
criter.push(<ICriteria>criteria);
ind++; ind++;
}); });
...@@ -21,3 +30,14 @@ export function criteriaReducer(state: ICriter = INITIAL_STATE, action): ICriter ...@@ -21,3 +30,14 @@ export function criteriaReducer(state: ICriter = INITIAL_STATE, action): ICriter
default: return state; default: return state;
} }
}; };
/*
case COURSEFIELDS_SELECTED_SAVE:
let selectedCourseFields = Array<ICourseField>();
let ind=0;
state.forEach(courseField => {
selectedCourseFields.push(<ICourseField>{id: courseField.id, name: courseField.name, selected: action.payload.courseFieldsSelected[ind]});
ind++;
});
return Seq(selectedCourseFields).map(n => n).toList();
default: return state;
*/
...@@ -3,10 +3,16 @@ import { ICriteria, ICriter } from './criteria.types'; ...@@ -3,10 +3,16 @@ import { ICriteria, ICriter } from './criteria.types';
export function deimmutifyCriteria(state: ICriter): ICriteria[] { export function deimmutifyCriteria(state: ICriter): ICriteria[] {
let fetchedCriteria = new Array(); let fetchedCriteria = new Array();
/*
state.forEach(criteria => { state.forEach(criteria => {
fetchedCriteria.push(<ICriteria>{orphanmono: criteria.orphanmono, orphantwice: criteria.orphantwice, threechildren: criteria.threechildren, fetchedCriteria.push(<ICriteria>{orphanmono: criteria.orphanmono, orphantwice: criteria.orphantwice, threechildren: criteria.threechildren,
manychildren: criteria.manychildren, twins: criteria.twins, disability: criteria.disability, studies: criteria.studies, income: criteria.income, manychildren: criteria.manychildren, twins: criteria.twins, disability: criteria.disability, studies: criteria.studies, income: criteria.income,
}); });
}); });
*/
state.forEach(criteria => {
fetchedCriteria.push(<ICriteria>{id: criteria.id, name: criteria.name, mutual_disabled_id: criteria.mutual_disabled_id, selected: criteria.selected,
});
});
return fetchedCriteria; return fetchedCriteria;
}; };
import { List } from 'immutable'; import { List } from 'immutable';
export interface ICriteria { export interface ICriteria {
/*
orphanmono: boolean; orphanmono: boolean;
orphantwice: boolean; orphantwice: boolean;
threechildren: boolean; threechildren: boolean;
...@@ -9,6 +10,13 @@ export interface ICriteria { ...@@ -9,6 +10,13 @@ export interface ICriteria {
disability: boolean; disability: boolean;
studies: boolean; studies: boolean;
income: string; income: string;
*/
id: string;
name: string;
mutual_disabled_id: string,
//globalIndex: number;
selected: boolean;
} }
export type ICriter = List<ICriteria>; export type ICriter = List<ICriteria>;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment