Commit 6456d772 authored by Νίκος Κατσαούνος's avatar Νίκος Κατσαούνος

add Drupal Controller for submitting application data, updated...

add Drupal Controller for submitting application data, updated ApplicationSubmit Angular Component, updated StudentApplicationForm component, updated fields restrictions in epal module
parents 2102c54d 0e8caf80
dist/*
source/app.settings.ts
node_modules/*
!drupal/
drupal/*
......
......@@ -28,3 +28,12 @@ current_user:
_controller: '\Drupal\epal\Controller\CurrentUser::content'
requirements:
_access: 'TRUE'
epal.application_submit:
path: '/epal/appsubmit'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\ApplicationSubmit::appSubmit'
requirements:
_user_is_logged_in: 'TRUE'
<?php
/**
* @file
* Contains \Drupal\query_example\Controller\QueryExampleController.
*/
namespace Drupal\epal\Controller;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Drupal\Core\Database\Connection;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
class ApplicationSubmit extends ControllerBase {
protected $entity_query;
protected $entityTypeManager;
protected $logger;
protected $connection;
public function __construct(
EntityTypeManagerInterface $entityTypeManager,
QueryFactory $entity_query,
Connection $connection,
LoggerChannelFactoryInterface $loggerChannel)
{
$this->entityTypeManager = $entityTypeManager;
$this->entity_query = $entity_query;
$this->connection = $connection;
$this->logger = $loggerChannel->get('oauthost');
}
public static function create(ContainerInterface $container)
{
return new static(
$container->get('entity.manager'),
$container->get('entity.query'),
$container->get('database'),
$container->get('logger.factory')
);
}
public function appSubmitWORK() {
$db = \Drupal\Core\Database\Database::getConnection();
$transaction = $db->startTransaction();
try {
$student = array('epaluser_id'=> 1, 'name'=> 'ΝΙΚΟΣ', 'studentsurname'=>'ΚΑΤΣΑ', 'status'=> 1);
$entity_manager = \Drupal::entityManager();
$entity_storage_student = $entity_manager->getStorage('epal_student');
$entity_storage_eidikotita = $entity_manager->getStorage('epal_student_course_field');
$entity_object = $entity_storage_student->create($student);
$entity_storage_student->save($entity_object);
$created_student_id = $entity_object->id();
$eidikotita = array('name'=>'record1', 'student_id' => 1, 'coursefield_id' => 4, 'status'=> 1 );
$entity_object = $entity_storage_eidikotita->create($eidikotita);
$entity_storage_eidikotita->save($entity_object);
$created_eidikotites_id = $entity_object->id();
}
catch (\Exception $e) {
$transaction->rollback();
}
}
public function appSubmit2() {
$db = \Drupal\Core\Database\Database::getConnection();
$transaction = $db->startTransaction();
try {
$student = array('epaluser_id'=> 1, 'name'=> 'ΝΙΚΟΣ', 'studentsurname'=>'ΚΑΤΣΑ', 'status'=> 1);
$entity_manager = \Drupal::entityManager();
$entity_storage_student = $entity_manager->getStorage('epal_student');
$entity_storage_course = $entity_manager->getStorage('epal_student_course_field');
$entity_object = $entity_storage_student->create($student);
$entity_storage_student->save($entity_object);
$created_student_id = $entity_object->id();
$course = array('name'=>'record1', 'student_id' => 1, 'coursefield_id' => 4, 'status'=> 1 );
$entity_object = $entity_storage_course->create($course);
$entity_storage_course->save($entity_object);
}
catch (\Exception $e) {
$transaction->rollback();
}
}
public function appSubmit() {
$aitisi = array();
$content = \Drupal::request()->getContent();
if (!empty($content)) {
$aitisi = json_decode($content, TRUE);
//$aitisi[0] --> student data, $aitisi[1][] --> epals chosen, $aitisi[2][] --> criteria, $aitisi[3] --> sector or course chosen
}
$db = \Drupal\Core\Database\Database::getConnection();
$transaction = $db->startTransaction();
try {
//insert records in entity: epal_student
$entity_manager = \Drupal::entityTypeManager();
$epaluserid = \Drupal::currentUser()->id();
$student = array(
//'epaluser_id' => $aitisi[0][epaluser_id],
'epaluser_id' => $epaluserid,
'name' => $aitisi[0][name],
'studentsurname' => $aitisi[0][studentsurname],
//'birthdate' => $aitisi[0][birthdate],
//'fatherfirstname' => $aitisi[0][fatherfirstname],
//'fathersurname' => $aitisi[0][fathersurname],
//'motherfirstname' => $aitisi[0][motherfirstname],
//'mothersurname' => $aitisi[0][mothersurname],
'studentamka' => $aitisi[0][studentamka],
'regionaddress' => $aitisi[0][regionaddress],
'regionarea' => $aitisi[0][regionarea],
'regiontk' => $aitisi[0][regiontk],
'certificatetype' => $aitisi[0][certificatetype],
//'lastam' => $aitisi[0][lastam],
'currentclass' => $aitisi[0][currentclass],
//'currentepal' => $aitisi[0][currentepal],
//'currentsector' => $aitisi[0][currentsector],
'relationtostudent' => $aitisi[0][relationtostudent],
'telnum' => $aitisi[0][telnum]
);
$entity_storage_student = $entity_manager->getStorage('epal_student');
$entity_object = $entity_storage_student->create($student);
$entity_storage_student->save($entity_object);
$created_student_id = $entity_object->id();
//insert records in entity: epal_student_epal_chosen
for ($i = 0; $i < sizeof($aitisi[1]); $i++) {
$epalchosen = array(
//'name' => $aitisi[1][$i][name],
'student_id' => $created_student_id,
'epal_id' => $aitisi[1][$i][epal_id],
'choice_no' => $aitisi[1][$i][choice_no]
//'points_for_order' => $aitisi[1][$i][points_for_order],
//'distance_from_epal' => $aitisi[1][$i][distance_from_epal],
//'points_for_distance' => $aitisi[1][$i][points_for_distance],
);
$entity_storage_epalchosen = $entity_manager->getStorage('epal_student_epal_chosen');
$entity_object = $entity_storage_epalchosen->create($epalchosen);
$entity_storage_epalchosen->save($entity_object);
}
//insert records in entity: epal_student_moria
for ($i = 0; $i < sizeof($aitisi[2]); $i++) {
$criteria = array(
//'name' => $aitisi[2][$i][name],
'student_id' => $created_student_id,
'income' => $aitisi[2][$i][income],
'criterio_id' => $aitisi[2][$i][criterio_id],
//'moria' => $aitisi[2][$i][moria],
);
$entity_storage_criteria = $entity_manager->getStorage('epal_student_moria');
$entity_object = $entity_storage_criteria->create($criteria);
$entity_storage_criteria->save($entity_object);
}
//insert records in entity: epal_student_course_field (αφορά μαθητές Γ' Λυκείου)
// or: epal_student_sector_field (αφορά μαθητές Β' Λυκείου)
if ($aitisi[0][currentclass] === "Γ' Λυκείου") {
//$course = array('name'=>'record1', 'student_id' => 1, 'coursefield_id' => 4, 'status'=> 1 );
$course = array(
//'name' => $aitisi[3][name],
//'student_id' => $aitis[3][student_i],
'student_id' => $created_student_id,
'coursefield_id' => $aitisi[3][coursefield_id]
);
$entity_storage_course = $entity_manager->getStorage('epal_student_course_field');
$entity_object = $entity_storage_course->create($course);
$entity_storage_course->save($entity_object);
}
else if ($aitisi[0][currentclass] === "Β' Λυκείου") {
$sector = array(
//'name' => $aitisi[3][name],
'student_id' => $created_student_id,
//'student_id' => $aitis[3][student_i],
'sectorfield_id' => $aitisi[3][sectorfield_id]
);
$entity_storage_sector = $entity_manager->getStorage('epal_student_sector_field');
$entity_object = $entity_storage_sector->create($sector);
$entity_storage_sector->save($entity_object);
}
$returnmsg = "Επιτυχής καταχώρηση στοιχείων αίτησης!";
$response = new JsonResponse([$returnmsg]);
return $response;
}
catch (\Exception $e) {
$this->logger->warning($e->getMessage());
$transaction->rollback();
$returnmsg = "Αποτυχία καταχώρησης στοιχείων αίτησης!";
$response = new JsonResponse([$returnmsg]);
return $response;
}
}
}
......@@ -180,7 +180,7 @@ class EpalCriteria extends ContentEntityBase implements EpalCriteriaInterface {
'max_length' => 100,
'text_processing' => 0,
))
->setDefaultValue('')
->setRequired(true)
->setDisplayOptions('view', array(
'label' => 'above',
'type' => 'string',
......
......@@ -43,8 +43,8 @@ use Drupal\user\UserInterface;
* "uid" = "user_id",
* "langcode" = "langcode",
* "status" = "status",
* "minno" = "minno",
* "maxno" = "maxno",
* "student_id" = "student_id",
* "epal_id" = "epal_id",
* },
* links = {
* "canonical" = "/admin/epal/epal_student_class/{epal_student_class}",
......
......@@ -43,7 +43,7 @@ use Drupal\user\UserInterface;
* "langcode" = "langcode",
* "status" = "status",
* "student_id" = "student_id",
* "courseField_id" = "courseField_id",
* "coursefield_id" = "coursefield_id",
* },
* links = {
* "canonical" = "/admin/structure/epal_student_course_field/{epal_student_course_field}",
......
......@@ -42,6 +42,8 @@ use Drupal\user\UserInterface;
* "uid" = "user_id",
* "langcode" = "langcode",
* "status" = "status",
* "student_id" = "student_id",
* "criterio_id" = "criterio_id",
* },
* links = {
* "canonical" = "/admin/structure/epal_student_moria/{epal_student_moria}",
......
......@@ -42,6 +42,8 @@ use Drupal\user\UserInterface;
* "uid" = "user_id",
* "langcode" = "langcode",
* "status" = "status",
* "student_id" = "student_id",
* "sectorfield_id" = "sectorfield_id",
* },
* links = {
* "canonical" = "/admin/structure/epal_student_sector_field/{epal_student_sector_field}",
......
.main-wrapper {
background: #FFF none repeat-y 0 0;
background: #FFF none repeat-y 0 0;
min-height: calc(100vh - 220px);
#content {
zoom: 1;
......@@ -39,7 +39,7 @@
}
.left-choices {
h4{
h4{
font-weight: bold;
font-size: 1rem;
......@@ -51,9 +51,9 @@
border: none!important;
width: 200px;
padding:5px 10px;
}
}
......@@ -75,13 +75,13 @@
li.list-group-item{
color: black;
background-color: white;
// background-color: white;
border: none!important;
padding: 0.3rem 0.3rem!important;
h5{
font-size: 1rem;
}
}
......@@ -92,11 +92,11 @@
@include media-breakpoint-up(md) {
@include media-breakpoint-up(md) {
.main-wrapper {
#content {
padding: 0 10px 10px;
box-shadow: 0 0 20px #888888;
}
}
}
\ No newline at end of file
}
import { LOGININFO_SAVE } from '../constants';
import { LOGININFO_SAVE, LOGININFO_INIT } from '../constants';
import { Injectable } from '@angular/core';
import { NgRedux } from 'ng2-redux';
import { IAppState } from '../store';
......@@ -19,4 +19,12 @@ export class LoginInfoActions {
});
};
initLoginInfo = () => {
return this._ngRedux.dispatch({
type: LOGININFO_INIT,
payload: {
}
});
};
}
import { REGIONSCHOOLS_RECEIVED, REGIONSCHOOLS_SELECTED_SAVE, REGIONSCHOOLS_ORDER_SAVE } from '../constants';
import { REGIONSCHOOLS_RECEIVED, REGIONSCHOOLS_SELECTED_SAVE, REGIONSCHOOLS_ORDER_SAVE, REGIONSCHOOLS_INIT } from '../constants';
import { Injectable } from '@angular/core';
import { NgRedux } from 'ng2-redux';
import { IAppState } from '../store';
......@@ -25,6 +25,14 @@ export class RegionSchoolsActions {
}
};
initRegionSchools = () => {
return this._ngRedux.dispatch({
type: REGIONSCHOOLS_INIT,
payload: {
}
});
};
/*
getRegionSchools_Reload = (courseActive) => {
const { regions } = this._ngRedux.getState();
......
import { SECTORCOURSES_RECEIVED, SECTORCOURSES_SELECTED_SAVE } from '../constants';
import { SECTORCOURSES_RECEIVED, SECTORCOURSES_SELECTED_SAVE, SECTORCOURSES_INIT } from '../constants';
import { Injectable } from '@angular/core';
import { NgRedux } from 'ng2-redux';
import { IAppState } from '../store';
......@@ -25,6 +25,14 @@ export class SectorCoursesActions {
}
};
initSectorCourses = () => {
return this._ngRedux.dispatch({
type: SECTORCOURSES_INIT,
payload: {
}
});
};
/*
getSectorCourses_Reload = () => {
const { sectors } = this._ngRedux.getState();
......
import { SECTORFIELDS_RECEIVED, SECTORFIELDS_SELECTED_SAVE } from '../constants';
import { SECTORFIELDS_RECEIVED, SECTORFIELDS_SELECTED_SAVE, SECTORFIELDS_INIT } from '../constants';
import { Injectable } from '@angular/core';
import { NgRedux } from 'ng2-redux';
import { IAppState } from '../store';
......@@ -6,32 +6,41 @@ import { HelperDataService } from '../services/helper-data-service';
@Injectable()
export class SectorFieldsActions {
constructor(
private _ngRedux: NgRedux<IAppState>,
private _hds: HelperDataService) {}
constructor(
private _ngRedux: NgRedux<IAppState>,
private _hds: HelperDataService) { }
getSectorFields = (reload) => {
const { sectorFields } = this._ngRedux.getState();
//if (sectorFields.size === 0) {
if (reload === true || (reload === false && sectorFields.size === 0)) {
return this._hds.getSectorFields().then(sectorFields => {
return this._ngRedux.dispatch({
type: SECTORFIELDS_RECEIVED,
payload: {
sectorFields
}
getSectorFields = (reload) => {
const { sectorFields } = this._ngRedux.getState();
//if (sectorFields.size === 0) {
if (reload === true || (reload === false && sectorFields.size === 0)) {
return this._hds.getSectorFields().then(sectorFields => {
return this._ngRedux.dispatch({
type: SECTORFIELDS_RECEIVED,
payload: {
sectorFields
}
});
});
}
};
initSectorFields = () => {
return this._ngRedux.dispatch({
type: SECTORFIELDS_INIT,
payload: {
}
});
}
};
};
saveSectorFieldsSelected = (sectorFieldsSelected) => {
return this._ngRedux.dispatch({
type: SECTORFIELDS_SELECTED_SAVE,
payload: {
sectorFieldsSelected
}
});
};
saveSectorFieldsSelected = (sectorFieldsSelected) => {
return this._ngRedux.dispatch({
type: SECTORFIELDS_SELECTED_SAVE,
payload: {
sectorFieldsSelected
}
});
};
}
export const API_ENDPOINT = '';
export class AppSettings {
public static get API_ENDPOINT(): string {
return '';
}
}
export const API_ENDPOINT = 'http://localhost/drupal-8.2.5';
export class AppSettings {
public static get API_ENDPOINT(): string {
return 'http://localhost/drupal-8.2.5';
// return 'http://localhost/angular/eepal-front/drupal';
......
......@@ -11,15 +11,17 @@ import {
FormControl,
FormArray
} from '@angular/forms';
import { AppSettings } from '../app.settings';
import { API_ENDPOINT } from '../app.settings';
@Component({
selector: 'home',
template: `
<div>
<form [formGroup]="formGroup" method = "POST" action="http://localhost/drupal-8.2.5/oauth/login" #form>
<form [formGroup]="formGroup" method = "POST" action="{{apiEndPoint}}/oauth/login" #form>
<!-- <input type="hidden" name="X-oauth-enabled" value="true"> -->
<div *ngFor="let loginInfoToken$ of loginInfo$ | async; let i=index">
<div class="row">
<div *ngFor="let loginInfoToken$ of loginInfo$ | async; let i=index"></div>
<!-- <div class="row">
<div class="col-md-6">
{{loginInfoToken$.auth_token}}
</div>
......@@ -27,15 +29,16 @@ import { AppSettings } from '../app.settings';
{{loginInfoToken$.auth_role}}
</div>
</div>
</div>
<div class="row">
</div> -->
<div class="row" style="min-height: 300px; margin-top: 100px;">
<div *ngIf="!authToken" class="col-md-7 col-md-offset-5">
<button type="submit" class="btn-primary btn-lg pull-center" (click)="form.submit()">
<div *ngIf="!authToken" class="col-md-8 offset-md-4">
<button type="submit" class="btn-primary btn-lg" (click)="form.submit()">
Είσοδος μέσω TaxisNet<span class="glyphicon glyphicon-menu-right"></span>
</button>
</div>
</div>
<!--
<div class="row">
<div *ngIf="authToken" class="col-md-7 col-md-offset-5">
<h3>Καλώς ήρθατε</h3>
......@@ -49,6 +52,7 @@ import { AppSettings } from '../app.settings';
</button>
</div>
</div>
-->
</form>
</div>
`
......@@ -58,16 +62,19 @@ export default class Home implements OnInit {
private authToken: string;
private authRole: string;
private loginInfo$: Observable<ILoginInfo>;
private apiEndPoint = API_ENDPOINT;
constructor(private fb: FormBuilder,
private _ata: LoginInfoActions,
private _ngRedux: NgRedux<IAppState>,
private activatedRoute: ActivatedRoute
private activatedRoute: ActivatedRoute,
private router: Router
) {
this.authToken = '';
this.authRole = '';
this.formGroup = this.fb.group({
Username: [],
Paswd: []
// Username: [],
// Paswd: []
});
};
......@@ -77,16 +84,21 @@ export default class Home implements OnInit {
state.loginInfo.reduce(({}, loginInfoToken) => {
this.authToken = loginInfoToken.auth_token;
this.authRole = loginInfoToken.auth_role;
if (this.authToken && this.authToken.length > 0)
this.router.navigate(['/epal-class-select']);
return loginInfoToken;
}, {});
}
return state.loginInfo;
});
// subscribe to router event
this.activatedRoute.queryParams.subscribe((params: Params) => {
this.authToken = params['auth_token'];
this.authRole = params['auth_role'];
if (params) {
this.authToken = params['auth_token'];
this.authRole = params['auth_role'];
}
if (this.authToken && this.authRole)
this._ata.saveLoginInfo({ auth_token: this.authToken, auth_role: this.authRole });
// console.log(this.authToken);
......
......@@ -8,8 +8,15 @@
<img src="../myschool/assets/images/myschool_logo.png" alt="Αρχική" />
</a>
<div class="collapse navbar-collapse flex-row-reverse" id="navbarNav">
<div *ngFor="let loginInfoToken$ of loginInfo$ | async; let i=index"></div>
<ul class="navbar-nav">
<b>Όνομα Χρήστη:</b> {{this.cuser}}
&nbsp;&nbsp;
<div *ngIf="authToken">
<button type="button" class="btn-primary btn-sm pull-right" (click)="oauthSignOut()">
<i class="fa fa-sign-out"></i>
</button>
</div>
<!--
<li class="nav-item" [ngClass]="{active: path=='application-preview'}">
......
import {Component, OnInit} from '@angular/core';
import {Router} from '@angular/router';
import { Injectable } from "@angular/core";
import { HelperDataService } from '../../services/helper-data-service';
import { Observable } from 'rxjs/Rx';
import { LoginInfoActions } from '../../actions/logininfo.actions';
import { ILoginInfo } from '../../store/logininfo/logininfo.types';
import { NgRedux, select } from 'ng2-redux';
import { IAppState } from '../../store/store';
@Component({
selector: 'reg-navbar',
......@@ -8,22 +14,46 @@ import { HelperDataService } from '../../services/helper-data-service';
})
@Injectable() export default class NavbarComponent implements OnInit{
private authToken: string;
private authRole: string;
private loginInfo$: Observable<ILoginInfo>;
public cuser :any;
public cuser :any;
constructor( private _ata: LoginInfoActions,
private _hds: HelperDataService,
private _ngRedux: NgRedux<IAppState>,
private router: Router
) {
this.authToken = '';
this.authRole = '';
constructor( private _hds: HelperDataService) {
};
ngOnInit() {
this.loginInfo$ = this._ngRedux.select(state => {
if (state.loginInfo.size > 0) {
state.loginInfo.reduce(({}, loginInfoToken) => {
this.authToken = loginInfoToken.auth_token;
this.authRole = loginInfoToken.auth_role;
return loginInfoToken;
}, {});
}
return state.loginInfo;
});
this._hds.getCurrentUser().then( cuser => this.cuser= cuser );
}
oauthSignOut() {
this._hds.signOut().then(data => {
this._ata.initLoginInfo();
this.authToken = '';
this.authRole = '';
this.router.navigate(['/']);
});
}
......
<div class="row equal">
<div class="col-md-12">
<form novalidate (ngSubmit)="onSubmit(studentDataGroup)" [formGroup]="studentDataGroup"
method = "POST" action="http://localhost/drupal-8.2.5/epal/appsubmit" #form>
<form novalidate [formGroup]="studentDataGroup" #form>
<form [formGroup]="applicantDataGroup">
<table>