merge-undomerge

parent cf0ca1e1
......@@ -252,6 +252,14 @@ public function findGroupsForMerging(Request $request,$firstid, $classId, $secto
$users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
$user = reset($users);
if ($user) {
$userRoles = $user->getRoles();
$userRole = '';
foreach ($userRoles as $tmpRole) {
if ( ($tmpRole === 'regioneduadmin') || ($tmpRole === 'eduadmin')) {
$userRole = $tmpRole;
}
}
$postData = null;
if ($content = $request->getContent())
{
......@@ -273,13 +281,19 @@ public function findGroupsForMerging(Request $request,$firstid, $classId, $secto
}
//$recordsformerges = reset($recordsformerge)
if ($recordsformerge)
{
foreach ($recordsformerge as $recordsformerges)
{
$recordsformerges->set('initial_epal_id', $secondid);
{
$secondmerge = $recordsformerges -> getepalid() ;
if (($secondmerge == '0') || ($secondmerge == null))
{
$recordsformerges->set('initial_epal_id', $secondid);
$recordsformerges->set('merging_role', $userRole);
}
$recordsformerges->set('epal_id', $firstid);
$recordsformerges->save();
}
......@@ -288,21 +302,21 @@ public function findGroupsForMerging(Request $request,$firstid, $classId, $secto
} else {
return $this->respondWithStatus([
'error_code' => '1001'.$firstid.$secondid."//".$speciality."///".$classId,
'error_code' => '1001',
], Response::HTTP_FORBIDDEN);
}
return $this->respondWithStatus([
'error_code' => '0'.$firstid.$secondid,
'error_code' => '0',
], Response::HTTP_OK);
} else {
return $this->respondWithStatus([
'error_code' => '1002'.$firstid.$secondid,
'error_code' => '1002',
], Response::HTTP_BAD_REQUEST);
}
} else {
return $this->respondWithStatus([
'error_code' => '1003'.$firstid.$secondid,
'error_code' => '1003',
], Response::HTTP_FORBIDDEN);
}
}
......@@ -576,6 +590,16 @@ public function findMergingSchoolsforUndo(Request $request, $classId, $sector, $
$users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
$user = reset($users);
if ($user) {
$userRoles = $user->getRoles();
$userRole = '';
foreach ($userRoles as $tmpRole) {
if ( ($tmpRole === 'regioneduadmin') || ($tmpRole === 'eduadmin')) {
$userRole = $tmpRole;
}
}
$postData = null;
if ($content = $request->getContent())
{
......@@ -583,6 +607,7 @@ public function findMergingSchoolsforUndo(Request $request, $classId, $sector, $
$firstid = $postData->firstid;
$secondid = $postData->secondid;
if ($classId == 1){
$recordsforundomerge = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('initial_epal_id' => $firstid, 'specialization_id' => -1));
}
......@@ -600,12 +625,24 @@ public function findMergingSchoolsforUndo(Request $request, $classId, $sector, $
if ($recordsforundomerge)
{
foreach ($recordsforundomerge as $recordsforundomerges)
{
$recordsforundomerges->set('initial_epal_id', 0);
$recordsforundomerges->set('epal_id', $firstid);
$recordsforundomerges->save();
$merging_role = reset($recordsforundomerge);
$role_forundomerge = $merging_role -> merging_role -> value;
if (( $role_forundomerge == 'regioneduadmin') && ($userRole == 'eduadmin'))
{
return $this->respondWithStatus([
'error_code' => '2500',
], Response::HTTP_FORBIDDEN);
}
else
{
foreach ($recordsforundomerge as $recordsforundomerges)
{
$recordsforundomerges->set('initial_epal_id', 0);
$recordsforundomerges->set('epal_id', $firstid);
$recordsforundomerges->set('merging_role', null);
$recordsforundomerges->save();
}
}
} else {
return $this->respondWithStatus([
......@@ -613,7 +650,7 @@ public function findMergingSchoolsforUndo(Request $request, $classId, $sector, $
], Response::HTTP_FORBIDDEN);
}
return $this->respondWithStatus([
'error_code' => '0',
'error_code' => '0' ,
], Response::HTTP_OK);
} else {
return $this->respondWithStatus([
......
......@@ -179,7 +179,8 @@ class EpalStudentClass extends ContentEntityBase implements EpalStudentClassInte
public function getepalid() {
return $this->get('epal_id')->target_id;
return $this->get('initial_epal_id')->target_id;
// return $this->get('initial_epal_id')->id();
}
......@@ -481,6 +482,27 @@ class EpalStudentClass extends ContentEntityBase implements EpalStudentClassInte
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['merging_role'] = BaseFieldDefinition::create('string')
->setLabel(t('Ο ρόλος του χρήστη που κάνει συγχώνευση'))
->setDescription(t('Ρόλος του χρήστη που κάνει συγχώνευση'))
->setSettings(array(
'max_length' => 50,
'text_processing' => 0,
))
->setDefaultValue('')
->setDisplayOptions('view', array(
'label' => 'above',
'type' => 'string',
'weight' => -4,
))
->setDisplayOptions('form', array(
'type' => 'string_textfield',
'weight' => -4,
))
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
return $fields;
}
......
......@@ -30,6 +30,29 @@ import { HelperDataService } from "../../services/helper-data-service";
</div>
<div id="UndoMergeError" (onHidden)="onHidden()" class="modal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header modal-header-danger">
<h3 class="modal-title pull-left"><i class="fa fa-ban"></i>&nbsp;&nbsp;Αποτυχία Αναίρεσης Συνένωσης</h3>
<button type="button" class="close pull-right" aria-label="Close" (click)="hideModal()">
<span aria-hidden="true"><i class="fa fa-times"></i></span>
</button>
</div>
<div class="modal-body">
<p>Δεν έχετε δικαίωμα να αναιρέσετε τη συγκεκριμένη συνένωση!</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default pull-right" data-dismiss="modal" (click)="hideErrorModal()">Κλείσιμο</button>
</div>
</div>
</div>
</div>
<div class = "loading" *ngIf="(showLoader | async) === true"></div>
......@@ -267,15 +290,27 @@ import { HelperDataService } from "../../services/helper-data-service";
(<any>$("#undoMergeConfirm")).modal("hide");
}
public showErrorModal(): void {
(<any>jQuery("#UndoMergeError")).modal("show");
}
public hideErrorModal(): void {
(<any>jQuery("#UndoMergeError")).modal("hide");
}
ngOnDestroy()
{
(<any>$("#undoMergeConfirm")).remove();
(<any>jQuery("#UndoMergeError")).remove();
}
ngOnInit() {
this.findsectors();
this.retrievedSch.next(false);
(<any>$("#undoMergeConfirm")).appendTo("body");
(<any>$("#undoMergeConfirm")).appendTo("body");
(<any>jQuery("#UndoMergeError")).appendTo("body");
}
......@@ -437,7 +472,8 @@ import { HelperDataService } from "../../services/helper-data-service";
})
.catch(err => {
this.showLoader.next(false);
console.log("err");
this.showErrorModal();
console.log("error undoMerge");
});
}
......
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