Merge branch 'component_updates' into 'develop'

Component updates

See merge request !86
parents ffcf0931 31a930eb
......@@ -164,6 +164,14 @@ epal.ministry.report-all-stat:
_controller: '\Drupal\epal\Controller\ReportsCreator::makeReportAllStat'
requirements:
_user_is_logged_in: 'TRUE'
epal.ministry.retrieve-registry-id:
path: '/ministry/retrieve-registry-id'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\ReportsCreator::retrieveUserRegistryNo'
requirements:
_user_is_logged_in: 'TRUE'
epal.ministry.massive_mail:
path: '/ministry/send-massive-mail'
options:
......@@ -203,4 +211,4 @@ findcapacity:
defaults:
_controller: '\Drupal\epal\Controller\DirectorView::findCapacity'
requirements:
_user_is_logged_in: 'TRUE'
\ No newline at end of file
_user_is_logged_in: 'TRUE'
......@@ -128,7 +128,9 @@ class ApplicationSubmit extends ControllerBase {
//insert records in entity: epal_student_course_field (αφορά μαθητές Γ' Λυκείου)
// or: epal_student_sector_field (αφορά μαθητές Β' Λυκείου)
if ($applicationForm[0][currentclass] === "Γ' Λυκείου") {
//if ($applicationForm[0][currentclass] === "Γ' Λυκείου") {
if ($applicationForm[0][currentclass] === "3") {
//$course = array('name
$course = array(
//'name' => $aitisi[3][name],
......@@ -142,7 +144,8 @@ class ApplicationSubmit extends ControllerBase {
$entity_storage_course->save($entity_object);
}
else if ($applicationForm[0][currentclass] === "Β' Λυκείου") {
//else if ($applicationForm[0][currentclass] === "Β' Λυκείου") {
else if ($applicationForm[0][currentclass] === "2") {
$sector = array(
//'name' => $applicationForm[3][name],
'student_id' => $created_student_id,
......
<?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 CreateDemoData 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('epal');
}
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 make_seed() {
list($usec, $sec) = explode(' ', microtime());
return $sec + $usec * 1000000;
}
public function UniqueRandNum($min, $max, $quantity) {
$numbers = range($min, $max);
shuffle($numbers);
return array_slice($numbers, 0, $quantity);
}
public function createData() {
$transaction = $this->connection->startTransaction();
try {
//insert demo records in entity: epal_student
$entity_manager = \Drupal::entityTypeManager();
$epaluserid = \Drupal::currentUser()->id();
for ($i = 1; $i <= 1000; $i++) {
//srand($this->make_seed());
$curclass = rand(1,3);
//$curclass = 2;
//$currentepal = rand(137,165);
$currentepal = rand(5,399);
$student = array(
//'epaluser_id' => $aitisi[0][epaluser_id],
'epaluser_id' => $epaluserid,
'name' => "firstname" . $i,
'studentsurname' => "surname" . $i,
//'birthdate' => $aitisi[0][birthdate],
'birthdate' => '01/01/1970',
//'fatherfirstname' => $aitisi[0][fatherfirstname],
'fatherfirstname' => "fatherfirstname" . $i,
//'fathersurname' => $aitisi[0][fathersurname],
'fathersurname' => "fathersurname" . $i,
//'motherfirstname' => $aitisi[0][motherfirstname],
'motherfirstname' => "motherfirstname" . $i,
//'mothersurname' => $aitisi[0][mothersurname],
'mothersurname' => "mothersurname" . $i,
//'studentamka' => $aitisi[0][studentamka],
//'regionaddress' => $aitisi[0][regionaddress],
'regionaddress' => "regionaddress" . $i,
//'regionarea' => $aitisi[0][regionarea],
'regionarea' => "regionarea" . $i,
//'regiontk' => $aitisi[0][regiontk],
'regiontk' => "tk" . $i,
//'certificatetype' => $aitisi[0][certificatetype],
'certificatetype' => 'Απολυτήριο Γυμνασίου',
//'lastam' => $aitisi[0][lastam],
'currentclass' => $curclass,
'currentepal' => $currentepal,
//'currentsector' => $aitisi[0][currentsector],
//'relationtostudent' => $aitisi[0][relationtostudent],
'relationtostudent' => 'Μαθητής',
//'telnum' => $aitisi[0][telnum],
'telnum' => '6944123456',
'points' => rand(0,20)
);
$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_course_field (αφορά μαθητές Γ' Λυκείου)
// or: epal_student_sector_field (αφορά μαθητές Β' Λυκείου)
$availableSchools = array();
if ($curclass === 3) {
do {
$coursefield_id = rand(1,54);
$course = array(
'student_id' => $created_student_id,
'coursefield_id' => $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);
//εύρεση ΕΠΑΛ που διαθέτουν την αντίστοιχη ειδικότητα
print_r("<br> EIDIKOTHTA: " . $coursefield_id);
$eepalSpecialtiesInEpal_storage = $this->entityTypeManager->getStorage('eepal_specialties_in_epal');
//$eepalSpecialtiesInEpal = $eepalSpecialtiesInEpal_storage->loadByProperties(array('specialty_id' => $coursefield_id) );
$ids = $eepalSpecialtiesInEpal_storage->getQuery()
->condition('specialty_id', $coursefield_id, "=")
//->condition('epal_id', 137, ">=")
//->condition('epal_id', 165, "<=")
->execute();
$eepalSpecialtiesInEpal = $eepalSpecialtiesInEpal_storage->loadMultiple($ids);
print_r("<br> NUM_SCHOOLS: " . sizeof($eepalSpecialtiesInEpal));
foreach ($eepalSpecialtiesInEpal as $eepalSpecialInEp) {
array_push($availableSchools, $eepalSpecialInEp->epal_id->getString());
}
if (sizeof($availableSchools) != 0)
$entity_storage_course->save($entity_object);
} //end do
while (sizeof($availableSchools) == 0);
$entity_storage_course->resetCache();
$eepalSpecialtiesInEpal_storage->resetCache();
}
else if ($curclass === 2) {
do {
$sectorfield_id = rand(1,9);
$sector = array(
'student_id' => $created_student_id,
'sectorfield_id' => $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);
//εύρεση ΕΠΑΛ που διαθέτουν τον αντίστοιχο τομέα
print_r("<br> TOMEAS: " . $sectorfield_id);
$eepalSectorsInEpal_storage = $this->entityTypeManager->getStorage('eepal_sectors_in_epal');
$ids = $eepalSectorsInEpal_storage->getQuery()
->condition('sector_id', $sectorfield_id, "=")
//->condition('epal_id', 137, ">=")
//->condition('epal_id', 165, "<=")
->execute();
$eepalSectorsInEpal = $eepalSectorsInEpal_storage->loadMultiple($ids);
print_r("<br> NUM_SCHOOLS: " . sizeof($eepalSectorsInEpal));
foreach ($eepalSectorsInEpal as $eepalSecInEp) {
array_push($availableSchools, $eepalSecInEp->epal_id->getString());
}
if (sizeof($availableSchools) != 0)
$entity_storage_sector->save($entity_object);
} //end do
while (sizeof($availableSchools) == 0);
$entity_storage_sector->resetCache();
$eepalSectorsInEpal_storage->resetCache();
}
else if ($curclass === 1) {
print_r("<br> CLASS A: ");
//$school_id_start = 137;
$school_id_start = 5;
//for ($l=0; $l < 29; $l++)
for ($l=0; $l < 395; $l++)
array_push($availableSchools, $school_id_start + $l);
}
$numEpalsChosen = rand(1,3);
if ($numEpalsChosen > sizeof($availableSchools))
$numEpalsChosen = sizeof($availableSchools);
print_r("<br> NUM_EPAL_CHOSEN " . $numEpalsChosen);
$epal_id_index = $this->UniqueRandNum(0,sizeof($availableSchools)-1,$numEpalsChosen);
for ($j=0; $j < $numEpalsChosen; $j++) {
print_r("<br> EPAL_CHOSEN_ID: " . $epal_id_index[$j]);
print_r("<br> EPAL_CHOSEN_REAL_ID: " . $availableSchools[$epal_id_index[$j]]);
}
for ($j = 0; $j < $numEpalsChosen ; $j++) {
$epalchosen = array(
'student_id' => $created_student_id,
'epal_id' => $availableSchools[$epal_id_index[$j]],
'choice_no' => $j+1
);
$entity_storage_epalchosen = $entity_manager->getStorage('epal_student_epal_chosen');
$entity_object = $entity_storage_epalchosen->create($epalchosen);
$entity_storage_epalchosen->save($entity_object);
}
$entity_storage_epalchosen->resetCache();
$entity_storage_student->resetCache();
/*
//TO BE CONSIDERED
if ($curclass === 2 || $curclass === 3) {
//33% των μαθητών της Β' και Γ' Λυκείου δηλώνουν προτίμηση στο σχολείο που ήδη φοιτούν
if (rand(1,3) === 1) {
$epal_id[0] = $currentepal;
}
}
*/
}
}
catch (\Exception $e) {
$this->logger->warning($e->getMessage());
$returnmsg = "Αποτυχία καταχώρησης demo data!";
$response = new JsonResponse([$returnmsg]);
// $transaction->rollback();
return $response;
}
$response = new JsonResponse(['hello' => 'world']);
$response->headers->set('X-AUTH-TOKEN', 'HELLOTOKEN');
return $response;
}
}
......@@ -163,7 +163,7 @@ class ReportsCreator extends ControllerBase {
$roles = $user->getRoles();
$validRole = false;
foreach ($roles as $role)
if ($role === "ministry") {
if ($role === "ministry" || $role === "regioneduadmin" || $role === "eduadmin") {
$validRole = true;
break;
}
......@@ -172,6 +172,12 @@ class ReportsCreator extends ControllerBase {
'message' => t("User Invalid Role"),
], Response::HTTP_FORBIDDEN);
}
/*
if ($role === "regioneduadmin") {
//ΑΝΑΚΤΗΣΗ ID της ΠΔΕ
$regionId = 1;
}
*/
$list = array();
......@@ -310,7 +316,7 @@ class ReportsCreator extends ControllerBase {
$roles = $user->getRoles();
$validRole = false;
foreach ($roles as $role)
if ($role === "ministry") {
if ($role === "ministry" || $role === "regioneduadmin" || $role === "eduadmin") {
$validRole = true;
break;
}
......@@ -519,6 +525,57 @@ class ReportsCreator extends ControllerBase {
}
public function retrieveUserRegistryNo(Request $request) {
try {
if (!$request->isMethod('GET')) {
return $this->respondWithStatus([
"message" => t("Method Not Allowed")
], Response::HTTP_METHOD_NOT_ALLOWED);
}
//user validation
$authToken = $request->headers->get('PHP_AUTH_USER');
$users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
$user = reset($users);
if (!$user) {
return $this->respondWithStatus([
'message' => t("User not found"),
], Response::HTTP_FORBIDDEN);
}
//user role validation
$roles = $user->getRoles();
$validRole = false;
foreach ($roles as $role)
if ( $role === "regioneduadmin") {
$validRole = true;
break;
}
if (!$validRole) {
return $this->respondWithStatus([
'message' => t("User Invalid Role"),
], Response::HTTP_FORBIDDEN);
}
return $this->respondWithStatus([
'message' => t("retrieve ID successful"),
'id' => $user->init->value,
], Response::HTTP_OK);
}
catch (\Exception $e) {
$this->logger->warning($e->getMessage());
return $this->respondWithStatus([
"message" => t("An unexpected problem occured in retrievePDEId Method")
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
public function retrieveUpLimit() {
//βρες ανώτατο επιτρεπόμενο όριο μαθητών
......@@ -548,4 +605,6 @@ class ReportsCreator extends ControllerBase {
}
CREATE UNIQUE INDEX uidx_region_regno ON eepal_region_field_data(registry_no);
CREATE UNIQUE INDEX uidx_adminarea_regno ON eepal_admin_area_field_data(registry_no);
\ No newline at end of file
......@@ -10,6 +10,7 @@ import { Router, ActivatedRoute, Params} from '@angular/router';
import { BehaviorSubject, Subscription } from 'rxjs/Rx';
import { ILoginInfo } from '../../store/logininfo/logininfo.types';
import { LOGININFO_INITIAL_STATE } from '../../store/logininfo/logininfo.initial-state';
import { PDE_ROLE, DIDE_ROLE } from '../../constants';
import {
FormBuilder,
......@@ -38,7 +39,7 @@ import { API_ENDPOINT } from '../../app.settings';
<br><br>
<button type="button" class="btn btn-alert" (click)="nav_to_reportpath(2)" [hidden]="minedu_userName == ''" >
<i class="fa fa-file-text"></i>
Συνολική Πληρότητα σχολικών μονάδων ΕΠΑΛ ανά τάξη
Συνολική Πληρότητα σχολικών μονάδων ΕΠΑΛ ανά τάξη
</button>
<br><br>
<button type="button" class="btn btn-alert" (click)="nav_to_reportpath(3)" [hidden]="minedu_userName == ''" >
......@@ -87,7 +88,14 @@ import { API_ENDPOINT } from '../../app.settings';
state.loginInfo.reduce(({}, loginInfoToken) => {
this.minedu_userName = loginInfoToken.minedu_username;
this.minedu_userPassword = loginInfoToken.minedu_userpassword;
return loginInfoToken;
console.log("Role:");
console.log(loginInfoToken.auth_role);
if (loginInfoToken.auth_role == PDE_ROLE || loginInfoToken.auth_role == DIDE_ROLE) {
console.log("inside..");
this.minedu_userName = loginInfoToken.auth_token;
this.minedu_userPassword = loginInfoToken.auth_token;
}
return loginInfoToken;
}, {});
}
return state.loginInfo;
......
......@@ -12,6 +12,7 @@ import { ILoginInfo } from '../../store/logininfo/logininfo.types';
import { Ng2SmartTableModule, LocalDataSource } from 'ng2-smart-table';
import {reportsSchema, TableColumn} from './reports-schema';
import { LOGININFO_INITIAL_STATE } from '../../store/logininfo/logininfo.initial-state';
import { PDE_ROLE, DIDE_ROLE } from '../../constants';
import {csvCreator} from './csv-creator';
import {
......@@ -31,11 +32,10 @@ import { API_ENDPOINT } from '../../app.settings';
<div>
<!--
<div
class = "loading" *ngIf="validCreator == 0" >
</div>
-->
<form [formGroup]="formGroup" #form>
......@@ -45,8 +45,8 @@ import { API_ENDPOINT } from '../../app.settings';
> Φίλτρο Επιλογής Περιφ/κής Δ/νσης - Δ/νσης Εκπ/σης - Σχολείου
</button>
<div class="col-md-11 offset-md-1">
<label *ngIf = "enableRegionFilter"> Περιφερειακή Διεύθυνση </label>
<select #regsel class="form-control" (change)="checkregion(regsel)" *ngIf = "enableRegionFilter" formControlName="region">
<label *ngIf = "enableRegionFilter && userLoggedIn == 'supervisor'"> Περιφερειακή Διεύθυνση </label>
<select #regsel class="form-control" (change)="checkregion(regsel)" *ngIf = "enableRegionFilter" [value] = "regionSelected" [hidden] = "userLoggedIn != 'supervisor'" formControlName="region">
<option value="0"></option>
<option *ngFor="let RegionSelection$ of RegionSelections$ | async; let i=index" [value] = "RegionSelection$.id"> {{RegionSelection$.name}} </option>
</select>
......@@ -133,12 +133,14 @@ import { API_ENDPOINT } from '../../app.settings';
private SchoolSelections$: BehaviorSubject<any>;
private SectorSelections$: BehaviorSubject<any>;
private CourseSelections$: BehaviorSubject<any>;
private RegionRetrieve$: BehaviorSubject<any>;
private generalReportSub: Subscription;
private RegionSelectionsSub: Subscription;
private AdminAreaSelectionsSub: Subscription;
private SchoolSelectionsSub: Subscription;
private SectorSelectionsSub: Subscription;
private CourseSelectionsSub: Subscription;
private RegionRetrieveSub: Subscription;
private apiEndPoint = API_ENDPOINT;
private minedu_userName: string;
private minedu_userPassword: string;
......@@ -158,6 +160,7 @@ import { API_ENDPOINT } from '../../app.settings';
private courseSelected: number;
private enableRegionFilter: boolean;
private enableCourseFilter: boolean;
private userLoggedIn: string;
columnMap: Map<string,TableColumn> = new Map<string,TableColumn>();
@Input() settings: any;
......@@ -191,6 +194,7 @@ import { API_ENDPOINT } from '../../app.settings';
this.SchoolSelections$ = new BehaviorSubject([{}]);
this.SectorSelections$ = new BehaviorSubject([{}]);
this.CourseSelections$ = new BehaviorSubject([{}]);
this.RegionRetrieve$ = new BehaviorSubject([{}]);
this.minedu_userName = '';
this.validCreator = -1;
this.showAdminList = new BehaviorSubject(false);
......@@ -214,7 +218,35 @@ import { API_ENDPOINT } from '../../app.settings';
state.loginInfo.reduce(({}, loginInfoToken) => {
this.minedu_userName = loginInfoToken.minedu_username;
this.minedu_userPassword = loginInfoToken.minedu_userpassword;
return loginInfoToken;
this.userLoggedIn = loginInfoToken.auth_role;
if (loginInfoToken.auth_role == PDE_ROLE || loginInfoToken.auth_role == DIDE_ROLE) {
console.log("inside..");
this.minedu_userName = loginInfoToken.auth_token;
this.minedu_userPassword = loginInfoToken.auth_token;
if (loginInfoToken.auth_role == PDE_ROLE) {
//CALL CONTROLLER THAT RETURNS ID OF PDE
this.RegionRetrieveSub = this._hds.getUserRegistryNo(this.minedu_userName, this.minedu_userPassword).subscribe(data => {
this.RegionRetrieve$.next(data);
this.data = data;
},
error => {
this.RegionRetrieve$.next([{}]);
console.log("Error Getting getRegionId");
},
() => {
this.regionSelected = this.data['id'];
console.log("Success Getting getRegionId");
this.showAdminList.next(true);
this.checkregion(this. regionSelected);
}
);
}
}
return loginInfoToken;
}, {});
}
return state.loginInfo;
......@@ -253,6 +285,8 @@ import { API_ENDPOINT } from '../../app.settings';
this.showSectorList.unsubscribe();
if (this.showCourseList)
this.showCourseList.unsubscribe();
if (this.RegionRetrieveSub)
this.RegionRetrieveSub.unsubscribe();
}
......@@ -346,13 +380,14 @@ toggleCourseFilter() {
checkregion(regionId) {
this.regionSelected = regionId.value;
if (typeof regionId.value != "undefined")
this.regionSelected = regionId.value;
this.adminAreaSelected = 0;
this.schSelected = 0;
//if (regionId.value != 0) {
this.AdminAreaSelectionsSub = this._hds.getAdminAreas(this.minedu_userName, this.minedu_userPassword, regionId.value).subscribe(data => {
this.AdminAreaSelectionsSub = this._hds.getAdminAreas(this.minedu_userName, this.minedu_userPassword, this.regionSelected).subscribe(data => {
this.AdminAreaSelections$.next(data);
},
error => {
......@@ -365,7 +400,7 @@ checkregion(regionId) {
}
);
this.SchoolSelectionsSub = this._hds.getSchoolsPerRegion(this.minedu_userName, this.minedu_userPassword, regionId.value).subscribe(data => {
this.SchoolSelectionsSub = this._hds.getSchoolsPerRegion(this.minedu_userName, this.minedu_userPassword, this.regionSelected).subscribe(data => {
this.SchoolSelections$.next(data);
},
error => {
......
......@@ -44,13 +44,12 @@
</li>
</div>
<!--
<div *ngIf="(loginInfo$ | async).size > 0" class="nav-item" >
<li *ngIf="authRole=='pde'" class="nav-item" >
<a class="nav-link" [routerLink]="['/school/perfecture-view']" [routerLinkActive]="['active']"><b>Αναφορές</b></a>
<a class="nav-link" [routerLink]="['/ministry/minister-reports']" [routerLinkActive]="['active']"><b>Αναφορές</b></a>
</li>
</div>
-->
</div>
</ul>
......
......@@ -197,10 +197,15 @@ import {AppSettings} from '../../app.settings';
criteriaObj[i] =new StudentCriteriaChosen(null, null, this.studentCriteria[i]);
aitisiObj['2'] = criteriaObj;
if (aitisiObj[0]['currentclass'] === "Β' Λυκείου" )
console.log("Debugging..");
console.log(aitisiObj[0]['currentclass']);
//if (aitisiObj[0]['currentclass'] === "Β' Λυκείου" )
if (aitisiObj[0]['currentclass'] === "2" )
aitisiObj['3'] = new StudentSectorChosen(null, this.sectorSelected);
else if (aitisiObj[0]['currentclass'] === "Γ' Λυκείου" )
//else if (aitisiObj[0]['currentclass'] === "Γ' Λυκείου" )
else if (aitisiObj[0]['currentclass'] === "3" ) {
aitisiObj['3'] = new StudentCourseChosen(null, this.courseSelected);
}
//console.log(aitisiObj);
......
......@@ -44,6 +44,9 @@ export class HelperDataService implements OnInit, OnDestroy {
this.authRole = loginInfoToken.auth_role;
//this.minedu_userName = loginInfoToken.minedu_username;
//this.minedu_userPassword = loginInfoToken.minedu_userpassword;
console.log("Auth details..");
console.log(this.authToken);
console.log(this.authRole);
return loginInfoToken;
}, {});
}
......@@ -839,6 +842,23 @@ getSchoolsPerAdminArea(username, userpassword, adminid) {
.map(response => response.json());
}
getUserRegistryNo(username, userpassword) {
let headers = new Headers({
"Content-Type": "application/json",
});
this.createMinistryAuthorizationHeader(headers, username, userpassword );
let options = new RequestOptions({ headers: headers });
//console.log("Test");
return this.http.get(`${AppSettings.API_ENDPOINT}/ministry/retrieve-registry-id` , options)
.map(response => response.json());
}
getSectors(username, userpassword, classid) {
let headers = new Headers({
......@@ -888,7 +908,7 @@ getCourses(username, userpassword, sectorid) {
getCapacityPerSchool(taxi, tomeas, specialit, schoolid) {
this.loginInfo$.getValue().forEach(loginInfoToken => {
this.authToken = loginInfoToken.auth_token;
this.authRole = loginInfoToken.auth_role;
......
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