added ReportsCreator Controller, added MinisterReports Component

parent 56c4bfb5
......@@ -145,6 +145,14 @@ epal.ministry.general_report:
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\Distribution::makegGeneralReport'
_controller: '\Drupal\epal\Controller\ReportsCreator::makegGeneralReport'
requirements:
_user_is_logged_in: 'TRUE'
epal.ministry.report1:
path: '/ministry/report-completeness'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\ReportsCreator::makeReportCompleteness'
requirements:
_user_is_logged_in: 'TRUE'
......@@ -46,7 +46,7 @@ class MinistryLogin extends ControllerBase
public function loginGo(Request $request)
{
try {
if (!$request->isMethod('POST')) {
......@@ -87,9 +87,9 @@ class MinistryLogin extends ControllerBase
$postData = json_decode($content);
//return new RedirectResponse("/drupal-8.2.6/eepal/dist/" . '?auth_token=' . $postData->username .'&auth_role=supervisor', 302, []);
return $this->respondWithStatus([
'auth_token' => $postData->username,
'userpassword' => $postData->userpassword,
'auth_role' => $currentRoleName,
//'auth_token' => $postData->username,
//'userpassword' => $postData->userpassword,
//'auth_role' => $currentRoleName,
], Response::HTTP_OK);
}
else {
......
<?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\Database;
use Drupal\Core\Database\Connection;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
//use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\TypedData\Plugin\DataType\TimeStamp;
use Drupal\Core\Language\LanguageManagerInterface;
class ReportsCreator extends ControllerBase {
protected $entity_query;
protected $entityTypeManager;
protected $logger;
protected $connection;
protected $language;
protected $currentuser;
protected $pendingStudents = array();
protected $choice_id = 1;
protected $globalCounterId = 1;
public function __construct(
EntityTypeManagerInterface $entityTypeManager,
QueryFactory $entity_query,
Connection $connection,
LoggerChannelFactoryInterface $loggerChannel)
{
$this->entityTypeManager = $entityTypeManager;
$this->entity_query = $entity_query;
$connection = Database::getConnection();
$this->connection = $connection;
$language = \Drupal::languageManager()->getCurrentLanguage()->getId();
$this->language = $language;
$currentuser = \Drupal::currentUser()->id();
$this->currentuser = $currentuser;
$this->logger = $loggerChannel->get('epal');
}
public static function create(ContainerInterface $container)
{
return new static(
$container->get('entity_type.manager'),
$container->get('entity.query'),
$container->get('database'),
$container->get('logger.factory')
);
}
public function makegGeneralReport(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 === "ministry") {
$validRole = true;
break;
}
if (!$validRole) {
return $this->respondWithStatus([
'message' => t("User Invalid Role"),
], Response::HTTP_FORBIDDEN);
}
//υπολογισμός αριθμού αιτήσεων
$sCon = $this->connection->select('epal_student', 'eStudent')
->fields('eStudent', array('id'));
$numTotal = $sCon->countQuery()->execute()->fetchField();
//υπολογισμός αριθμού αιτήσεων που ικανοποιήθηκαν στην i προτίμηση
$numData = array();
for ($i=0; $i < 3; $i++) {
$sCon = $this->connection->select('epal_student_class', 'eStudent')
->fields('eStudent', array('id', 'distribution_id'))
->condition('eStudent.distribution_id', $i+1, '=');
array_push($numData, $sCon->countQuery()->execute()->fetchField());
}
// υπολογισμός αριθμού αιτήσεων που ΔΕΝ ικανοποιήθηκαν
//Σημείωση: υπολογισμός με queries στη βάση
$sCon = $this->connection->select('epal_student_class', 'eStudent')
->fields('eStudent', array('id'));
$epalStudents = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ);
$studentIds = array();
foreach ($epalStudents as $epalStudent)
array_push($studentIds, $epalStudent->id);
$sCon = $this->connection->select('epal_student', 'eStudent')
->fields('eStudent', array('id'))
->condition('eStudent.id', $studentIds, 'NOT IN');
$numNoAllocated = $sCon->countQuery()->execute()->fetchField();
/*
$list[] = array(
'num_applications' => $numTotal,
'numchoice1' => $numData[0],
'numchoice2' => $numData[1],
'numchoice3' => $numData[2],
'num_noallocated' => $numNoAllocated,
);
*/
$list = array();
//$record = new generalReportSchema;
//$record->name = "nikos";
//$record->numStudents = 20;
array_push($list,(object) array('name' => "Αριθμός Αιτήσεων", 'numStudents' => $numTotal));
array_push($list,(object) array('name' => "Αριθμός μαθητών που τοποθετήθηκαν στην πρώτη τους προτίμηση", 'numStudents' => $numData[0]));
array_push($list,(object) array('name' => "Αριθμός μαθητών που τοποθετήθηκαν στην δεύτερή τους προτίμηση", 'numStudents' => $numData[1]));
array_push($list,(object) array('name' => "Αριθμός μαθητών που τοποθετήθηκαν στην τρίτη τους προτίμηση", 'numStudents' => $numData[2]));
array_push($list,(object) array('name' => "Αριθμός μαθητών που δεν τοποθετήθηκαν σε καμμία τους προτίμηση", 'numStudents' => $numNoAllocated));
return $this->respondWithStatus(
$list
, Response::HTTP_OK);
} //end try
catch (\Exception $e) {
$this->logger->warning($e->getMessage());
return $this->respondWithStatus([
"message" => t("An unexpected problem occured during DELETE proccess in makeSelectionOfStudents Method of Distribution")
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
public function makeReportCompleteness(Request $request) {
//$this->checkAuthorization($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 === "ministry") {
$validRole = true;
break;
}
if (!$validRole) {
return $this->respondWithStatus([
'message' => t("User Invalid Role"),
], Response::HTTP_FORBIDDEN);
}
$list = array();
//βρες όλα τα σχολεία
$sCon = $this->connection->select('eepal_school_field_data', 'eSchool')
->fields('eSchool', array('id', 'name', 'capacity_class_a'));
$epalSchools = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ);
//βρες ανώτατο επιτρεπόμενο όριο μαθητών
$sCon = $this->connection->select('epal_class_limits', 'eSchool')
->fields('eSchool', array('name', 'limit_up'))
->condition('eSchool.name', 'Α' , '=');
$epalLimitUps = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ);
$epalLimitUp = reset($epalLimitUps);
$limitUp = $epalLimitUp->limit_up;
foreach ($epalSchools as $epalSchool) {
//βρες μέγιστη χωρητικότητα για κάθε τάξη
$capacity = array();
//χωρητικότητα για Α' τάξη
array_push($capacity, $epalSchool->capacity_class_a * $limitUp );
//χωρητικότητα για Β' τάξη
$sCon = $this->connection->select('eepal_sectors_in_epal_field_data', 'eSchool')
->fields('eSchool', array('id', 'capacity_class_sector'))
->condition('eSchool.epal_id', $epalSchool->id , '=');
$sectorsInEpals = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ);
$numClassSectors = 0;
foreach ($sectorsInEpals as $sectorsInEpal)
$numClassSectors += $sectorsInEpal->capacity_class_sector;
array_push($capacity, $numClassSectors * $limitUp);
//χωρητικότητα για Γ' τάξη
$sCon = $this->connection->select('eepal_specialties_in_epal_field_data', 'eSchool')
->fields('eSchool', array('id', 'capacity_class_specialty'))
->condition('eSchool.epal_id', $epalSchool->id , '=');
$specialtiesInEpals = $sCon->execute()->fetchAll(\PDO::FETCH_OBJ);
$numClassSpecialties = 0;
foreach ($specialtiesInEpals as $specialtiesInEpal)
$numClassSpecialties += $specialtiesInEpal->capacity_class_specialty;
array_push($capacity, $numClassSpecialties * $limitUp);
//χωρητικότητα για όλο το σχολείο
$capacityTotal = array_sum($capacity);
//βρες αριθμό μαθητών γισ κάθε τάξη
$num = array();
$perc = array();
for ( $classId = 1; $classId <= 3; $classId++) {
$sCon = $this->connection->select('epal_student_class', 'eStudent')
->fields('eStudent', array('id', 'epal_id', 'currentclass'))
->condition('eStudent.epal_id', $epalSchool->id , '=')
->condition('eStudent.currentclass', $classId , '=');
array_push( $num, $sCon->countQuery()->execute()->fetchField() );
//βρες ποσοστά συμπλήρωσης
array_push( $perc, number_format($num[$classId-1] / $capacity[$classId-1] * 100 , 1) . "%");
}
$percTotal = number_format (array_sum($num) / array_sum($capacity) * 100, 1) . "%";;
//αποστολή αποτελεσμάτων / στατιστικών
if ($num[0] !== "0" || $num[1] !== "0" || $num[2] !== "0")
/*
array_push($list,(object) array(
'name' => $epalSchool->name, 'numStudents' => $num[0] + $num[1] + $num[2], 'capacityTotal' => $capacityTotal, 'percTotal' => $percTotal,
'numStudentsA' => $num[0], 'capacityA' => $capacity[0], 'percA' => $perc[0],
'numStudentsB' => $num[1], 'capacityB' => $capacity[1], 'percB' => $perc[1],
'numStudentsC' => $num[2], 'capacityC' => $capacity[2], 'percC' => $perc[2])
);
*/
array_push($list,(object) array(
'name' => $epalSchool->name, 'percTotal' => $percTotal,
'percA' => $perc[0],
'percB' => $perc[1],
'percC' => $perc[2])
);
}
return $this->respondWithStatus(
$list
, Response::HTTP_OK);
} //end try
catch (\Exception $e) {
$this->logger->warning($e->getMessage());
return $this->respondWithStatus([
"message" => t("An unexpected problem occured in makeReportCompleteness Method")
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
public function checkAuthorization(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 === "ministr") {
$validRole = true;
break;
}
if (!$validRole) {
return $this->respondWithStatus([
'message' => t("User Invalid Role"),
], Response::HTTP_FORBIDDEN);
}
} //end try
catch (\Exception $e) {
$this->logger->warning($e->getMessage());
return $this->respondWithStatus([
"message" => t("An unexpected problem occured in checkAuthorization Method")
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
private function respondWithStatus($arr, $s) {
$res = new JsonResponse($arr);
$res->setStatusCode($s);
return $res;
}
}
......@@ -34,7 +34,7 @@ import StudentAuthGuard from './guards/student.auth.guard';
import { ACTION_PROVIDERS } from './actions';
import Home from './components/home';
import { Ng2SmartTableModule } from 'ng2-smart-table';
import { Ng2SmartTableModule, LocalDataSource } from 'ng2-smart-table';
import HeaderComponent from './components/header/header.component';
import NavbarComponent from './components/navbar/navbar.component';
......
......@@ -27,4 +27,4 @@
</div>
</div>
</div>
</div>
\ No newline at end of file
</div>
import { Component, OnInit, OnDestroy, ElementRef, ViewChild} from "@angular/core";
import { Injectable } from "@angular/core";
import { AppSettings } from '../../app.settings';
import { HelperDataService } from '../../services/helper-data-service';
import { Observable} from "rxjs/Observable";
import { Http, Headers, RequestOptions} from '@angular/http';
import { NgRedux, select } from 'ng2-redux';
import { IAppState } from '../../store/store';
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 {
FormBuilder,
FormGroup,
FormControl,
FormArray,
} from '@angular/forms';
import { API_ENDPOINT } from '../../app.settings';
@Component({
selector: 'minister-informstudents',
template: `
`
})
@Injectable() export default class InformStudents implements OnInit, OnDestroy {
public formGroup: FormGroup;
//private loginInfo$: Observable<ILoginInfo>;
loginInfo$: BehaviorSubject<ILoginInfo>;
loginInfoSub: Subscription;
private apiEndPoint = API_ENDPOINT;
private minedu_userName: string;
private minedu_userPassword: string;
constructor(private fb: FormBuilder,
// private _ata: LoginInfoActions,
private _ngRedux: NgRedux<IAppState>,
private _hds: HelperDataService,
private activatedRoute: ActivatedRoute,
private router: Router) {
this.formGroup = this.fb.group({
});
this.loginInfo$ = new BehaviorSubject(LOGININFO_INITIAL_STATE);
}
ngOnDestroy() {
if (this.loginInfoSub) this.loginInfoSub.unsubscribe();
this.loginInfo$.unsubscribe();
}
ngOnInit() {
this.loginInfoSub = this._ngRedux.select(state => {
if (state.loginInfo.size > 0) {
state.loginInfo.reduce(({}, loginInfoToken) => {
this.minedu_userName = loginInfoToken.minedu_username;
this.minedu_userPassword = loginInfoToken.minedu_userpassword;
return loginInfoToken;
}, {});
}
return state.loginInfo;
}).subscribe(this.loginInfo$);
}
}
import { Component, OnInit, OnDestroy, ElementRef, ViewChild} from "@angular/core";
import { Component, OnInit, OnDestroy, ElementRef, ViewChild, Input} from "@angular/core";
import { Injectable } from "@angular/core";
import { AppSettings } from '../../app.settings';
import { HelperDataService } from '../../services/helper-data-service';
......@@ -9,42 +9,79 @@ import { IAppState } from '../../store/store';
import { Router, ActivatedRoute, Params} from '@angular/router';
import { BehaviorSubject, Subscription } from 'rxjs/Rx';
import { ILoginInfo } from '../../store/logininfo/logininfo.types';
import { Ng2SmartTableModule, LocalDataSource } from 'ng2-smart-table';
import { LOGININFO_INITIAL_STATE } from '../../store/logininfo/logininfo.initial-state';
import {reportsSchema, TableColumn} from './reports-schema';
//import * as _ from '..';
/*
import {
FormBuilder,
FormGroup,
FormControl,
FormArray,
Validators,
} from '@angular/forms';
*/
import { API_ENDPOINT } from '../../app.settings';
/*
class TableColumn {
field: string;
title: string;
type: string;
isDisplay: boolean;
isExport: boolean;
valuePrepareFunction: Function;
}
*/
@Component({
selector: 'minister-reports',
template: `
<div>
<!--<form [formGroup]="formGroup" #form>-->
<div>
<form [formGroup]="formGroup" #form>
<!--<button type="submit" class="btn-primary btn-md" (click)="form.submit()" >-->
<button type="submit" class="btn btn-default btn-block" (click)="reportGeneral()" >
<div
class = "loading" *ngIf="!validCreator && reportId" >
</div>
<button type="submit" class="btn btn-default btn-block" (click)="createReport('/ministry/general-report/')" [hidden]="minedu_userName == ''" >
Συγκεντρωτικά Αποτελέσματα Κατανομής
</button>
<div *ngFor="let generalReports$ of generalReport$ | async; let i=index">
<div *ngIf="showMessage">
<br>
Αριθμός Αιτήσεων: {{generalReports$.num_applications}}<br>
Αριθμός μαθητών που τοποθετήθηκαν στην πρώτη τους προτίμηση: {{generalReports$.numchoice1}}<br>
Αριθμός μαθητών που τοποθετήθηκαν στη δεύτερή τους προτίμηση: {{generalReports$.numchoice2}}<br>
Αριθμός μαθητών που τοποθετήθηκαν στην τρίτη τους προτίμηση: {{generalReports$.numchoice3}}<br>
Αριθμός μαθητών που δεν τοποθετήθηκαν σε καμμία τους προτίμηση: {{generalReports$.num_noallocated}}<br>
</div>
<button type="submit" class="btn btn-default btn-block" (click)="createReport('/ministry/report-completeness/')" [hidden]="minedu_userName == ''" >
Κατανομή Μαθητών ανά Σχολείο
</button>
<!--<div *ngFor="let generalReports$ of generalReport$ | async; let i=index">-->
<div *ngIf="validCreator ">
<input #search class="search" type="text" placeholder="Αναζήτηση..." (keydown.enter)="onSearch(search.value)">
<div class="smart-table-container" reportScroll>
<ng2-smart-table [settings]="settings" [source]="source"></ng2-smart-table>
</div>
</div>
</form>
<!--
<div *ngIf="validCreator && reportId == 2">
<div class="smart-table-container" reportScroll>
<ng2-smart-table [settings]="settings" [source]="source"></ng2-smart-table>
</div>
</div>-->
<button type="submit" class="alert alert-info" (click)="export2Csv()" [hidden]="!validCreator" >
Εξαγωγή σε csv
</button>
<!--</form>-->
</div>
`
......@@ -52,7 +89,7 @@ import { API_ENDPOINT } from '../../app.settings';
@Injectable() export default class MinisterReports implements OnInit, OnDestroy {
public formGroup: FormGroup;
//public formGroup: FormGroup;
loginInfo$: BehaviorSubject<ILoginInfo>;
loginInfoSub: Subscription;
private generalReport$: BehaviorSubject<any>;
......@@ -61,23 +98,110 @@ import { API_ENDPOINT } from '../../app.settings';
private minedu_userName: string;
private minedu_userPassword: string;
private distStatus = "READY";
private data: string;
private showMessage: