Merge branch 'component_updates' into 'develop'

Updated SubmittedApplications Controller in order to support app deletions from …

See merge request !226
parents 67978471 ff000f88
......@@ -191,29 +191,35 @@ epal.ministry.retrieve-registry-id:
requirements:
_user_is_logged_in: 'TRUE'
epal.ministry.massive_mail_unallocated:
path: '/ministry/send-unallocated-massive-mail'
path: '/ministry/send-unallocated-massive-mail/{period}'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\InformUnlocatedStudents::sendMailToUnallocatedStudents'
period: 2
requirements:
_user_is_logged_in: 'TRUE'
period: ^[0,1,2]$
epal.ministry.massive_mail_unallocated_smallclass:
path: '/ministry/send-unallocated-sc-massive-mail'
path: '/ministry/send-unallocated-sc-massive-mail/{period}'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\InformUnlocatedStudents::sendMailToUnallocatedStudentsSC'
period: 2
requirements:
_user_is_logged_in: 'TRUE'
period: ^[0,1,2]$
epal.ministry.massive_mail_located:
path: '/ministry/send-located-massive-mail'
path: '/ministry/send-located-massive-mail/{period}'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\InformUnlocatedStudents::sendMailToLocatedStudents'
period: 2
requirements:
_user_is_logged_in: 'TRUE'
period: ^[0,1,2]$
epal.ministry.retrievesettings:
path: '/ministry/retrieve-settings'
options:
......@@ -326,3 +332,11 @@ epal.totalstudents:
_controller: '\Drupal\epal\Controller\HelpDesk::findTotalStudents'
requirements:
_user_is_logged_in: 'TRUE'
epal.application_delete_director:
path: '/epal/application/deleteFromDirector'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\SubmitedApplications::deleteApplicationFromDirector'
requirements:
_user_is_logged_in: 'TRUE'
......@@ -668,6 +668,132 @@ class SubmitedApplications extends ControllerBase
}
public function deleteApplicationFromDirector(Request $request)
{
if (!$request->isMethod('POST')) {
return $this->respondWithStatus([
"error_code" => 2001
], Response::HTTP_METHOD_NOT_ALLOWED);
}
$authToken = $request->headers->get('PHP_AUTH_USER');
$users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
$user = reset($users);
if ($user) {
$epalId = $user->init->value;
$schools = $this->entityTypeManager->getStorage('eepal_school')->loadByProperties(array('id' => $epalId));
$school = reset($schools);
if (!$school) {
$this->logger->warning('no access to this school='.$user->id());
return $this->respondWithStatus([
"message" => "No access to this school"
], Response::HTTP_FORBIDDEN);
}
$userRoles = $user->getRoles();
$userRole = '';
foreach ($userRoles as $tmpRole) {
if ($tmpRole === 'epal') {
$userRole = $tmpRole;
}
}
if ($userRole === '') {
return $this->respondWithStatus([
'error_code' => 4003,
], Response::HTTP_FORBIDDEN);
} elseif ($userRole === 'epal') {
$content = $request->getContent();
$applicationId = 0;
if (!empty($content)) {
$postArr = json_decode($content, TRUE);
$applicationId = $postArr['applicationId'];
}
else {
return $this->respondWithStatus([
"error_code" => 5002
], Response::HTTP_BAD_REQUEST);
}
$transaction = $this->connection->startTransaction();
try {
//ανάκτηση τιμής από ρυθμίσεις διαχειριστή για lock_school_students_view
$config_storage = $this->entityTypeManager->getStorage('epal_config');
$epalConfigs = $config_storage->loadByProperties(array('name' => 'epal_config'));
$epalConfig = reset($epalConfigs);
if (!$epalConfig) {
return $this->respondWithStatus([
'message' => t("EpalConfig Enity not found"),
], Response::HTTP_FORBIDDEN);
}
else if ($epalConfig->lock_school_students_view->value) {
return $this->respondWithStatus([
"error_code" => 3002
], Response::HTTP_FORBIDDEN);
}
//$userid = $epalUser->id();
$epalStudents = $this->entityTypeManager->getStorage('epal_student')->loadByProperties(array( 'id' => $applicationId));
$epalStudent = reset($epalStudents);
if ($epalStudent) {
$epalStudentClasses = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('student_id' => $applicationId));
$epalStudentClass = reset($epalStudentClasses);
if ($epalStudentClass) {
if ($epalStudentClass->directorconfirm->value === "1") {
return $this->respondWithStatus([
"error_code" => -1
], Response::HTTP_FORBIDDEN);
}
}
$delQuery = $this->connection->delete('epal_student_epal_chosen');
$delQuery->condition('student_id', $applicationId);
$delQuery->execute();
$delQuery = $this->connection->delete('epal_student_sector_field');
$delQuery->condition('student_id', $applicationId);
$delQuery->execute();
$delQuery = $this->connection->delete('epal_student_course_field');
$delQuery->condition('student_id', $applicationId);
$delQuery->execute();
$delQuery = $this->connection->delete('epal_student_class');
$delQuery->condition('student_id', $applicationId);
$delQuery->execute();
$epalStudent->delete();
return $this->respondWithStatus([
'error_code' => 0,
], Response::HTTP_OK);
} else {
return $this->respondWithStatus([
'message' => t('EPAL student not found'),
], Response::HTTP_FORBIDDEN);
}
} catch (\Exception $e) {
$this->logger->warning($e->getMessage());
$transaction->rollback();
return $this->respondWithStatus([
'error_code' => 5001,
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
}
}
private function respondWithStatus($arr, $s)
{
$res = new JsonResponse($arr);
......
import { Component, OnInit, OnDestroy, ElementRef, ViewChild} from "@angular/core";
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 { 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 { 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';
......@@ -20,8 +20,6 @@ import { API_ENDPOINT } from '../../app.settings';
class = "loading" *ngIf="successSending == -2" >
</div>
<div style="min-height: 400px;">
<div id="emaiSentNotice" (onHidden)="onHidden()" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
......@@ -43,24 +41,67 @@ import { API_ENDPOINT } from '../../app.settings';
<h5> >Αποστολή ειδοποιήσεων <br></h5>
<br><br>
<div class="row" style="margin: 2em 0 2em 0;">
<div class="col-md-12">
<button type="submit" class="btn btn-lg btn-block" *ngIf="(loginInfo$ | async).size !== 0" (click)="informUnlocatedStudents(1)" [disabled] = "!applicantsResultsDisabled" >
Αποστολή e-mail στους μαθητές που ΔΕΝ τοποθετήθηκαν<span class="glyphicon glyphicon-menu-right"></span>
<h3>Αποστολή e-mail στους μαθητές που ΔΕΝ τοποθετήθηκαν</h3>
</div>
<div class="col-md-4">
<button type="submit" class="btn btn-lg btn-block" *ngIf="(loginInfo$ | async).size !== 0" (click)="informUnlocatedStudents(1, 0)" [disabled] = "!applicantsResultsDisabled" >
Α' Περίοδος
</button>
</div>
<br>
<div class="col-md-12">
<button type="submit" class="btn btn-lg btn-block" *ngIf="(loginInfo$ | async).size !== 0" (click)="informUnlocatedStudents(2)" [disabled] = "!applicantsResultsDisabled" >
Αποστολή e-mail στους μαθητές που τοποθετήθηκαν προσωρινά σε ολιγομελή τμήματα<span class="glyphicon glyphicon-menu-right"></span>
<div class="col-md-4">
<button type="submit" class="btn btn-lg btn-block" *ngIf="(loginInfo$ | async).size !== 0" (click)="informUnlocatedStudents(1, 1)" [disabled] = "!applicantsResultsDisabled" >
B' Περίοδος
</button>
</div>
<br>
<div class="col-md-4">
<button type="submit" class="btn btn-lg btn-block" *ngIf="(loginInfo$ | async).size !== 0" (click)="informUnlocatedStudents(1, 2)" [disabled] = "!applicantsResultsDisabled" >
Α' και Β' Περίοδος
</button>
</div>
</div>
<div class="row" style="margin: 2em 0 2em 0;">
<div class="col-md-12">
<button type="submit" class="btn btn-lg btn-block" *ngIf="(loginInfo$ | async).size !== 0" (click)="informUnlocatedStudents(3)" [disabled] = "!applicantsResultsDisabled">
Αποστολή e-mail στους μαθητές που τοποθετήθηκαν<span class="glyphicon glyphicon-menu-right"></span>
<h3>Αποστολή e-mail στους μαθητές που τοποθετήθηκαν προσωρινά σε ολιγομελή τμήματα</h3>
</div>
<div class="col-md-4">
<button type="submit" class="btn btn-lg btn-block" *ngIf="(loginInfo$ | async).size !== 0" (click)="informUnlocatedStudents(2, 0)" [disabled] = "!applicantsResultsDisabled" >
Α' Περίοδος
</button>
</div>
<div class="col-md-4">
<button type="submit" class="btn btn-lg btn-block" *ngIf="(loginInfo$ | async).size !== 0" (click)="informUnlocatedStudents(2, 1)" [disabled] = "!applicantsResultsDisabled" >
B' Περίοδος
</button>
</div>
<div class="col-md-4">
<button type="submit" class="btn btn-lg btn-block" *ngIf="(loginInfo$ | async).size !== 0" (click)="informUnlocatedStudents(2, 2)" [disabled] = "!applicantsResultsDisabled" >
Α' και Β' Περίοδος
</button>
</div>
</div>
<div class="row" style="margin: 2em 0 2em 0;">
<div class="col-md-12">
<h3>Αποστολή e-mail στους μαθητές που τοποθετήθηκαν</h3>
</div>
<div class="col-md-4">
<button type="submit" class="btn btn-lg btn-block" *ngIf="(loginInfo$ | async).size !== 0" (click)="informUnlocatedStudents(3, 0)" [disabled] = "!applicantsResultsDisabled" >
Α' Περίοδος
</button>
</div>
<div class="col-md-4">
<button type="submit" class="btn btn-lg btn-block" *ngIf="(loginInfo$ | async).size !== 0" (click)="informUnlocatedStudents(3, 1)" [disabled] = "!applicantsResultsDisabled" >
B' Περίοδος
</button>
</div>
<div class="col-md-4">
<button type="submit" class="btn btn-lg btn-block" *ngIf="(loginInfo$ | async).size !== 0" (click)="informUnlocatedStudents(3, 2)" [disabled] = "!applicantsResultsDisabled" >
Α' και Β' Περίοδος
</button>
</div>
</div>
`
......@@ -103,7 +144,7 @@ import { API_ENDPOINT } from '../../app.settings';
this.loginInfoSub = this._ngRedux.select(state => {
if (state.loginInfo.size > 0) {
state.loginInfo.reduce(({}, loginInfoToken) => {
state.loginInfo.reduce(({ }, loginInfoToken) => {
this.minedu_userName = loginInfoToken.minedu_username;
this.minedu_userPassword = loginInfoToken.minedu_userpassword;
return loginInfoToken;
......@@ -150,13 +191,14 @@ import { API_ENDPOINT } from '../../app.settings';
//this.isModalShown.next(false);
}
informUnlocatedStudents(unallocated) {
informUnlocatedStudents(unallocated, period) {
this.successSending = -2;
this.numSuccessMails = 0;
this.numFailMails = 0;
this._hds.informUnlocatedStudents(this.minedu_userName, this.minedu_userPassword, unallocated).subscribe(data => {
this._hds.informUnlocatedStudents(this.minedu_userName, this.minedu_userPassword, unallocated, period)
.subscribe(data => {
this.numSuccessMails = data.num_success_mail;
this.numFailMails = data.num_fail_mail;
this.successSending = 1;
......@@ -184,8 +226,8 @@ import { API_ENDPOINT } from '../../app.settings';
}
retrieveSettings() {
this.settingsSub = this._hds.retrieveAdminSettings(this.minedu_userName, this.minedu_userPassword).subscribe(data => {
this.settingsSub = this._hds.retrieveAdminSettings(this.minedu_userName, this.minedu_userPassword)
.subscribe(data => {
this.settings$.next(data);
this.applicantsResultsDisabled = Boolean(Number(this.settings$.value['applicantsResultsDisabled']));
......
......@@ -662,7 +662,7 @@ export class HelperDataService implements OnInit, OnDestroy {
}
informUnlocatedStudents(username, userpassword, unallocated) {
informUnlocatedStudents(username, userpassword, unallocated, period) {
let headers = new Headers({
"Content-Type": "application/json",
......@@ -671,12 +671,13 @@ export class HelperDataService implements OnInit, OnDestroy {
let options = new RequestOptions({ headers: headers });
let route = "";
if (unallocated == 1)
route = "ministry/send-unallocated-massive-mail";
else if (unallocated == 2)
route = "ministry/send-unallocated-sc-massive-mail";
else if (unallocated == 3)
route = "ministry/send-located-massive-mail";
if (unallocated == 1) {
route = "ministry/send-unallocated-massive-mail/" + period;
} else if (unallocated == 2) {
route = "ministry/send-unallocated-sc-massive-mail/" + period;
} else if (unallocated == 3) {
route = "ministry/send-located-massive-mail/" + period;
}
return this.http.get(`${AppSettings.API_ENDPOINT}/` + route, options)
.map(response => response.json());
......
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