updated Submit Component

parent 01197359
langcode: el
status: true
dependencies:
module:
- basic_auth
- epal
- hal
- serialization
- user
id: entity.epal_class_limits
plugin_id: 'entity:epal_class_limits'
granularity: method
configuration:
GET:
supported_formats:
- hal_json
- json
- xml
supported_auth:
- basic_auth
- cookie
POST:
supported_formats:
- hal_json
- json
- xml
supported_auth:
- basic_auth
- cookie
DELETE:
supported_formats:
- hal_json
- json
- xml
supported_auth:
- basic_auth
- cookie
PATCH:
supported_formats:
- hal_json
- json
- xml
supported_auth:
- basic_auth
- cookie
langcode: el
status: true
dependencies:
module:
- basic_auth
- epal
- hal
- serialization
- user
id: entity.epal_criteria
plugin_id: 'entity:epal_criteria'
granularity: method
configuration:
GET:
supported_formats:
- hal_json
- json
- xml
supported_auth:
- basic_auth
- cookie
POST:
supported_formats:
- hal_json
- json
- xml
supported_auth:
- basic_auth
- cookie
DELETE:
supported_formats:
- hal_json
- json
- xml
supported_auth:
- basic_auth
- cookie
PATCH:
supported_formats:
- hal_json
- json
- xml
supported_auth:
- basic_auth
- cookie
langcode: el
status: true
dependencies:
module:
- basic_auth
- epal
- hal
- serialization
- user
id: entity.epal_student_moria
plugin_id: 'entity:epal_student_moria'
granularity: method
configuration:
GET:
supported_formats:
- hal_json
- json
- xml
supported_auth:
- basic_auth
- cookie
POST:
supported_formats:
- hal_json
- json
- xml
supported_auth:
- basic_auth
- cookie
DELETE:
supported_formats:
- hal_json
- json
- xml
supported_auth:
- basic_auth
- cookie
PATCH:
supported_formats:
- hal_json
- json
- xml
supported_auth:
- basic_auth
- cookie
langcode: el
status: true
dependencies:
module:
- basic_auth
- epal
- hal
- serialization
- user
id: entity.epal_student_sector_field
plugin_id: 'entity:epal_student_sector_field'
granularity: method
configuration:
GET:
supported_formats:
- hal_json
- json
- xml
supported_auth:
- basic_auth
- cookie
POST:
supported_formats:
- hal_json
- json
- xml
supported_auth:
- basic_auth
- cookie
DELETE:
supported_formats:
- hal_json
- json
- xml
supported_auth:
- basic_auth
- cookie
PATCH:
supported_formats:
- hal_json
- json
- xml
supported_auth:
- basic_auth
- cookie
langcode: el
status: true
dependencies: { }
id: applicant
label: applicant
weight: 3
is_admin: null
permissions:
- 'add epal student class entities'
- 'add epal student entities'
- 'add epal student course field entities'
- 'add epal student epal chosen entities'
- 'add epal student sector field entities'
- 'add epal users entities'
- 'delete epal student class entities'
- 'delete epal student entities'
- 'delete epal student course field entities'
- 'delete epal student epal chosen entities'
- 'delete epal student sector field entities'
- 'delete epal users entities'
- 'edit epal student class entities'
- 'edit epal student entities'
- 'edit epal student course field entities'
- 'edit epal student epal chosen entities'
- 'edit epal student sector field entities'
- 'edit epal users entities'
- 'view published epal student class entities'
- 'view published epal student entities'
- 'view published epal student course field entities'
- 'view published epal student epal chosen entities'
- 'view published epal student sector field entities'
- 'view published epal users entities'
- 'view unpublished epal student class entities'
- 'view unpublished epal student entities'
- 'view unpublished epal student course field entities'
- 'view unpublished epal student epal chosen entities'
- 'view unpublished epal student sector field entities'
- 'view unpublished epal users entities'
- 'view published eepal admin area entities'
- 'view published eepal prefecture entities'
- 'view published eepal region entities'
- 'view published eepal school entities'
- 'view published eepal sectors entities'
- 'view published eepal sectors in epal entities'
- 'view published eepal specialties in epal entities'
- 'view published eepal specialty entities'
- 'view unpublished eepal admin area entities'
- 'view unpublished eepal prefecture entities'
- 'view unpublished eepal region entities'
- 'view unpublished eepal school entities'
- 'view unpublished eepal sectors entities'
- 'view unpublished eepal sectors in epal entities'
- 'view unpublished eepal specialties in epal entities'
- 'view unpublished eepal specialty entities'
- 'access content'
......@@ -48,7 +48,7 @@ export default class Form3 {
constructor(private http: Http) {
this.student = new Student(1, '', '', '', '', '','','','');
this.student = new Student(1, '', '', '', '', '','','','','');
//this.student = new Student(1, 1, '', '');
}
......
<div class="row equal">
<div class="col-md-12">
<form novalidate (ngSubmit)="onSubmit(studentDataGroup)" [formGroup]="studentDataGroup">
<form novalidate (ngSubmit)="onSubmit(studentDataGroup)" [formGroup]="studentDataGroup"
method = "POST" action="http://localhost/drupal-8.2.5/epal/appsubmit" #form>
<form [formGroup]="applicantDataGroup">
<table>
......@@ -180,6 +181,7 @@
<i class="fa fa-forward"></i>
</button>
</div>
</div>
</form>
......
......@@ -6,103 +6,209 @@ import { Injectable } from "@angular/core";
import { NgRedux, select } from 'ng2-redux';
import { IAppState } from '../../store/store';
//import { StudentDataFieldsActions } from '../../actions/studentdatafields.actions';
//import { IStudentDataFields } from '../../store/studentdatafields/studentdatafields.types';
import { StudentEpalChosen, StudentCourseChosen } from '../students/student';
import { IStudentDataFields } from '../../store/studentdatafields/studentdatafields.types';
//import { RegionSchoolsActions } from '../../actions/regionschools.actions';
import { IRegions } from '../../store/regionschools/regionschools.types';
//import { CriteriaActions } from '../../actions/criteria.actions';
import { ICriter } from '../../store/criteria/criteria.types';
import { ISectors } from '../../store/sectorcourses/sectorcourses.types';
import { ISectorFields } from '../../store/sectorfields/sectorfields.types';
import { IEpalClasses } from '../../store/epalclasses/epalclasses.types';
import { ILoginInfo } from '../../store/logininfo/logininfo.types';
import { Student, StudentEpalChosen, StudentCourseChosen, StudentSectorChosen, StudentCriteriaChosen } from '../students/student';
import {AppSettings} from '../../app.settings';
@Component({
selector: 'application-submit',
template: `
<application-preview-select></application-preview-select>
<div *ngFor="let loginInfoToken$ of loginInfo$ | async;"> </div>
<div *ngFor="let studentDataField$ of studentDataFields$ | async; "> </div>
<div *ngFor="let region$ of regions$ | async;">
<div *ngFor="let epal$ of region$.epals "> </div> </div>
<div *ngFor="let criter$ of criteria$ | async; let i=index"> </div>
<div *ngFor="let sector$ of sectors$ | async;">
<div *ngFor="let course$ of sector$.courses;"> </div> </div>
<div *ngFor="let sectorField$ of sectorFields$ | async;"></div>
<div *ngFor="let epalclass$ of epalclasses$ | async;"> </div>
<button type="button" class="btn-primary btn-lg pull-center" (click)="submitNow()">Υποβολή</button>
`
})
@Injectable() export default class ApplicationSubmit implements OnInit {
//private student;
private studentepalchosen;
private studentcoursechosen;
//private studentepalchosen;
//private studentcoursechosen;
//private studentsectorchosen;
//private studentcriteriachosen;
private authToken;
private student;
private epalSelected: Array<number> = new Array();
private epalSelectedOrder: Array<number> = new Array();
private studentCriteria: Array<number> = new Array();
private courseSelected;
private sectorSelected;
private classSelected;
private studentDataFields$: Observable<IStudentDataFields>;
private regions$: Observable<IRegions>;
private criteria$: Observable<ICriter>;
private sectors$: Observable<ISectors>;
private sectorFields$: Observable<ISectorFields>;
private epalclasses$: Observable<IEpalClasses>;
private loginInfo$: Observable<ILoginInfo>;
constructor(private _ngRedux: NgRedux<IAppState>,
private router: Router,
private http: Http
) {
//this.student = new Student(1, '', '', '', '', '', '', '','');
this.studentepalchosen = new StudentEpalChosen(-1 ,-1 ,-1);
this.studentcoursechosen = new StudentCourseChosen(-1 ,-1);
};
ngOnInit() {
this.loginInfo$ = this._ngRedux.select(state => {
if (state.loginInfo.size > 0) {
state.loginInfo.reduce(({}, loginInfoToken) => {
this.authToken = loginInfoToken.auth_token;
return loginInfoToken;
}, {});
}
return state.loginInfo;
});
};
this.epalclasses$ = this._ngRedux.select(state => {
if (state.epalclasses.size > 0) {
state.epalclasses.reduce(({}, epalclass) => {
this.classSelected = epalclass.name;
console.log("Hey!");
console.log(this.classSelected);
return epalclass;
}, {});
}
return state.epalclasses;
});
submitNow() {
//Get Student Data - use Observable ???
/*
this.studentDataFields$ = this._ngRedux.select(state => {
state.studentDataFields.reduce(({}, studentDataField) =>{
this.studentDataFields$ = this._ngRedux.select(state => {
if (state.studentDataFields.size > 0) {
state.studentDataFields.reduce(({}, studentDataField) => {
this.student = studentDataField;
return studentDataField;
}, {});
return state.studentDataFields;
});
*/
}
return state.studentDataFields;
});
this.regions$ = this._ngRedux.select(state => {
state.regions.reduce((prevRegion, region) =>{
region.epals.reduce((prevEpal, epal) =>{
if (epal.selected === true) {
this.epalSelected.push(Number(epal.epal_id));
this.epalSelectedOrder.push(epal.order_id);
}
return epal;
}, {});
return region;
}, {});
return state.regions;
});
//Get Data - sync methods
const { studentDataFields } = this._ngRedux.getState();
const { epalclasses } = this._ngRedux.getState();
const { regions } = this._ngRedux.getState();
const { amkafills } = this._ngRedux.getState();
const { sectors } = this._ngRedux.getState();
this.criteria$ = this._ngRedux.select(state => {
if (state.criter.size > 0) {
state.criter.reduce(({}, criteria) => {
if (criteria.orphanmono === true)
this.studentCriteria.push(6);
else if (criteria.orphantwice === true)
this.studentCriteria.push(1);
if (criteria.threechildren === true)
this.studentCriteria.push(11);
else if (criteria.manychildren === true)
this.studentCriteria.push(2);
if (criteria.twins === true)
this.studentCriteria.push(3);
if (criteria.disability === true)
this.studentCriteria.push(5);
if (criteria.studies === true)
this.studentCriteria.push(4);
if (criteria.income === '<= 3000 Ευρώ')
this.studentCriteria.push(7);
else if (criteria.income === '<= 6000 Ευρώ')
this.studentCriteria.push(8);
else if (criteria.income === '<= 9000 Ευρώ')
this.studentCriteria.push(9);
console.log("Criteria");
console.log(this.studentCriteria);
//αποστολή στοιχείων μαθητή στο entity: epal_student
let studentObj = studentDataFields["_tail"]["array"][0];
studentObj.studentamka = amkafills["_tail"]["array"][0]["name"];
studentObj.currentclass = epalclasses["_tail"]["array"][0]["name"];
this.submitRecord("epal_student", studentObj);
/*Τα επόμενα να πρχωρήσουν προς εκτέλεση, αφού γυρίσει ΕΠΙΤΥΧΩΣ η (ασύγχρονη) subitRecord για το entity: epalstudent
//αποστολή επιλογών για σχολεία στο entity: epal_student_epal_chosen
for (let l=0; l<regions.size; l++) {
for (let m=0; m < regions["_tail"]["array"][l]["epals"].length; m++) {
if (regions["_tail"]["array"][l]["epals"][m]["selected"] === true) {
this.studentepalchosen.student_id = studentObj.epaluser_id;
this.studentepalchosen.epal_id = regions["_tail"]["array"][l]["epals"][m]["epal_id"];
this.studentepalchosen.choice_no = regions["_tail"]["array"][l]["epals"][m]["order_id"];
this.submitRecord("epal_student_epal_chosen", this.studentepalchosen);
}
}
return criteria;
}, {});
}
return state.criter;
});
//αποστολή επιλογής για ειδικότητα στο entity: epal_student_course_field
//αφορά μόνο τους μαθητές της Γ' Λυκείου
if (studentObj.currentclass === "Γ' Λυκείου") {
this.studentcoursechosen.student_id = studentObj.epaluser_id;
for (let l=0; l<sectors.size; l++) {
for (let m=0; m < sectors["_tail"]["array"][l]["courses"].length; m++) {
if (sectors["_tail"]["array"][l]["courses"][m]["selected"] === true) {
this.studentcoursechosen.coursefield_id = sectors["_tail"]["array"][l]["courses"][m]["course_id"];
this.submitRecord("epal_student_course_field", this.studentcoursechosen);
//μοναδική επιλογή: φύγε από το loop
break;
}
}
this.sectors$ = this._ngRedux.select(state => {
state.sectors.reduce((prevSector, sector) =>{
sector.courses.reduce((prevCourse, course) =>{
if (course.selected === true) {
this.courseSelected = course.course_id
}
return course;
}, {});
return sector;
}, {});
return state.sectors;
});
this.sectorFields$ = this._ngRedux.select(state => {
state.sectorFields.reduce(({}, sectorField) =>{
if (sectorField.selected === true) {
this.sectorSelected = sectorField.id
}
}
return sectorField;
}, {});
return state.sectorFields;
});
//αποστολή επιλογής για τομέα στο entity: epal_student_sector_field <-- ΔΕΝ ΤΟ ΕΧΩ ΦΤΙΑΞΕΙ ΑΚΟΜΑ!
//αφορά μόνο τους μαθητές της B' Λυκείου
*/
};
submitNow() {
//αποστολή στοιχείων μαθητή στο entity: epal_student
let aitisiObj: Array<Student | StudentEpalChosen[] | StudentCriteriaChosen[] | StudentCourseChosen | StudentSectorChosen > = [];
let epalObj: Array<StudentEpalChosen> = [];
let criteriaObj: Array<StudentCriteriaChosen> = [];
//aitisiObj[0] = studentDataFields["_tail"]["array"][0];
aitisiObj[0] = this.student;
aitisiObj[0]['currentclass'] = this.classSelected;
//aitisiObj[0]['studentamka'] = ...;
for (let i=0; i < this.epalSelected.length; i++)
epalObj[i] =new StudentEpalChosen(null, this.epalSelected[i] , this.epalSelectedOrder[i]);
aitisiObj['1'] = epalObj;
for (let i=0; i < this.studentCriteria.length; i++)
criteriaObj[i] =new StudentCriteriaChosen(null, null, this.studentCriteria[i]);
aitisiObj['2'] = criteriaObj;
if (aitisiObj[0]['currentclass'] === "Β' Λυκείου" )
aitisiObj['3'] = new StudentSectorChosen(null, this.sectorSelected);
else if (aitisiObj[0]['currentclass'] === "Γ' Λυκείου" )
aitisiObj['3'] = new StudentCourseChosen(null, this.courseSelected);
console.log(aitisiObj);
this.submitRecord(aitisiObj);
}
submitRecord(entityName, record) {
submitRecord_ver1(entityName, record) {
let headers = new Headers({
"Authorization": "Basic bmthdHNhb3Vub3M6emVtcmFpbWU=",
"Accept": "*/*",
"Access-Control-Allow-Credentials": "true",
"Content-Type": "application/json",
// "Content-Type": "text/plain", // try to skip preflight
"X-CSRF-Token": "LU92FaWYfImfZxfldkF5eVnssdHoV7Aa9fg8K1bWYUc"
"X-CSRF-Token": "Me9oRh6jrAOAJ2rsnu_3lOLxqA_WMoJLeJ7dhe4HTBA"
});
let options = new RequestOptions({ headers: headers, withCredentials: true });
......@@ -117,4 +223,62 @@ import {AppSettings} from '../../app.settings';
}
submitRecord(record) {
console.log("Here...");
console.log(this.authToken);
let auth_str = this.authToken + ":" + this.authToken;
let auth_str2 = "nkatsaounos" + ":" + "zemraime";
console.log(auth_str);
console.log(auth_str2);
let s = btoa(auth_str);
let s2 = btoa(auth_str2);
console.log(s);
console.log(s2);
this.authToken = auth_str2;
let headers = new Headers({
"Authorization": "Basic " + btoa(this.authToken),
"Accept": "*/*",
"Access-Control-Allow-Credentials": "true",
"Content-Type": "application/json",
"X-CSRF-Token": "Pz3psGTGpc-EGNLm3tgzCpqEMg3HW0fCKf8xOnQLAsc"
});
console.log(headers);
//let headers = new Headers({
// "Authorization": "Basic bmthdHNhb3Vub3M6emVtcmFpbWU=",
// "Accept": "*/*",
// "Access-Control-Allow-Credentials": "true",
// "Content-Type": "application/json",
// "X-CSRF-Token": "Pz3psGTGpc-EGNLm3tgzCpqEMg3HW0fCKf8xOnQLAsc"
//});
let options = new RequestOptions({ headers: headers, method: "post", withCredentials: true });
//let connectionString = `${AppSettings.API_ENDPOINT}/epal/appsubmit`;
let connectionString = `${AppSettings.API_ENDPOINT}/epal/appsubmit`;
//this.http.post(`${AppSettings.API_ENDPOINT}/entity/epal_student`, this.student, options)
//this.http.post(connectionString, { "search": "person" }, options)
this.http.post(connectionString, record, options)
// Call map on the response observable to get the parsed people object
.map((res: Response) => res.json())
.subscribe(success => {alert("Επιτυχές post στο route υποβολής " ); console.log("success post"); }, // put the data returned from the server in our variable
error => {alert("Αποτυχές post στο route υποβολής " ); console.log("Error HTTP POST Service")}, // in case of failure show this message
() => console.log("write this message anyway"));//run this code in all cases);
}
}
//Get Data - sync methods
/*
const { studentDataFields } = this._ngRedux.getState();
const { epalclasses } = this._ngRedux.getState();
const { regions } = this._ngRedux.getState();
const { amkafills } = this._ngRedux.getState();
const { sectors } = this._ngRedux.getState();
*/
......@@ -105,6 +105,10 @@ import {AppSettings} from '../../app.settings';
this._cfa.saveEpalClassesSelected(this.formGroup.value);
this._sfa.getSectorFields(true);
this._rsa.getRegionSchools(1,"-1", true);
console.log("Here I am!");
//this._rsa.saveRegionSchoolsOrder(true);
this._csa.getSectorCourses(true);
}
......
......@@ -11,6 +11,7 @@ export class Student {
public regionarea: string,
public certificatetype: string,
public relationtostudent: string,
public studentamka: string,
public currentclass: string,
){}
}
......@@ -31,3 +32,35 @@ export class StudentCourseChosen {
public coursefield_id: number,
) {}
}
export class StudentSectorChosen {
constructor(
public student_id: number,
public sectorfield_id: number,
) {}
}
export class StudentCriteriaChosen {
constructor(
public student_id: number,
public income: number,
public criterio_id: number,
) {}
}
/*
export class StudentCriteria {
constructor(
public student_id: number,
public orphanmono: boolean,
public orphantwice: boolean,
public threechildren: boolean,
public manychildren: boolean,
public twins: boolean,
public disability: boolean,
public studies: boolean,
public income: number,
) {}
}
*/
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