From faf1df712410f3501f75750f2a8b9c028af261f2 Mon Sep 17 00:00:00 2001 From: "florian.azizian" <florian.azizian@maarch.org> Date: Thu, 6 Jul 2017 14:20:58 +0100 Subject: [PATCH] FEAT #5661 status administration MVC => historique --- .../app/status-administration.component.js | 6 ++--- .../app/status-administration.component.ts | 6 ++--- .../status-list-administration.component.js | 3 ++- .../status-list-administration.component.ts | 3 ++- core/Controllers/StatusController.php | 22 +++++++++++++------ rest/index.php | 4 ++-- 6 files changed, 27 insertions(+), 17 deletions(-) diff --git a/apps/maarch_entreprise/js/angular/app/status-administration.component.js b/apps/maarch_entreprise/js/angular/app/status-administration.component.js index 29df22c4fe4..2e5cb6968f3 100644 --- a/apps/maarch_entreprise/js/angular/app/status-administration.component.js +++ b/apps/maarch_entreprise/js/angular/app/status-administration.component.js @@ -38,8 +38,8 @@ var StatusAdministrationComponent = (function () { this.coreUrl = angularGlobals.coreUrl; this.prepareStatus(); this.route.params.subscribe(function (params) { - if (_this.route.toString().includes('status/new')) { - _this.http.get(_this.coreUrl + 'rest/status/new') + if (typeof params['identifier'] == "undefined") { + _this.http.get(_this.coreUrl + 'rest/administration/status/new') .map(function (res) { return res.json(); }) .subscribe(function (data) { _this.lang = data['lang']; @@ -80,7 +80,7 @@ var StatusAdministrationComponent = (function () { }; StatusAdministrationComponent.prototype.getStatusInfos = function (statusIdentifier) { var _this = this; - this.http.get(this.coreUrl + 'rest/status/' + statusIdentifier) + this.http.get(this.coreUrl + 'rest/administration/status/' + statusIdentifier) .map(function (res) { return res.json(); }) .subscribe(function (data) { _this.status = data['status'][0]; diff --git a/apps/maarch_entreprise/js/angular/app/status-administration.component.ts b/apps/maarch_entreprise/js/angular/app/status-administration.component.ts index f257d972fe2..4961d7d64af 100644 --- a/apps/maarch_entreprise/js/angular/app/status-administration.component.ts +++ b/apps/maarch_entreprise/js/angular/app/status-administration.component.ts @@ -40,8 +40,8 @@ export class StatusAdministrationComponent implements OnInit { this.prepareStatus(); this.route.params.subscribe((params) => { - if (this.route.toString().includes('status/new')){ - this.http.get(this.coreUrl + 'rest/status/new') + if (typeof params['identifier'] == "undefined"){ + this.http.get(this.coreUrl + 'rest/administration/status/new') .map(res => res.json()) .subscribe((data) => { this.lang = data['lang']; @@ -82,7 +82,7 @@ export class StatusAdministrationComponent implements OnInit { } getStatusInfos(statusIdentifier : string){ - this.http.get(this.coreUrl + 'rest/status/'+statusIdentifier) + this.http.get(this.coreUrl + 'rest/administration/status/'+statusIdentifier) .map(res => res.json()) .subscribe((data) => { this.status = data['status'][0]; diff --git a/apps/maarch_entreprise/js/angular/app/status-list-administration.component.js b/apps/maarch_entreprise/js/angular/app/status-list-administration.component.js index 82d8e21e921..5230f002d81 100644 --- a/apps/maarch_entreprise/js/angular/app/status-list-administration.component.js +++ b/apps/maarch_entreprise/js/angular/app/status-list-administration.component.js @@ -54,7 +54,8 @@ var StatusListAdministrationComponent = (function () { "order": [[2, "asc"]], "columnDefs": [ { "orderable": false, "targets": [0, 3] } - ] + ], + "stateSave": true }); $j('.dataTables_filter input').attr("placeholder", _this.lang.search); $j('dataTables_filter input').addClass('form-control'); diff --git a/apps/maarch_entreprise/js/angular/app/status-list-administration.component.ts b/apps/maarch_entreprise/js/angular/app/status-list-administration.component.ts index bfbcc6534a0..f20bf156a0c 100644 --- a/apps/maarch_entreprise/js/angular/app/status-list-administration.component.ts +++ b/apps/maarch_entreprise/js/angular/app/status-list-administration.component.ts @@ -61,7 +61,8 @@ export class StatusListAdministrationComponent implements OnInit { "order": [[ 2, "asc" ]], "columnDefs": [ { "orderable": false, "targets": [0,3] } - ] + ], + "stateSave": true }); $j('.dataTables_filter input').attr("placeholder", this.lang.search); $j('dataTables_filter input').addClass('form-control'); diff --git a/core/Controllers/StatusController.php b/core/Controllers/StatusController.php index 9e9752c1181..9c788124090 100644 --- a/core/Controllers/StatusController.php +++ b/core/Controllers/StatusController.php @@ -86,9 +86,19 @@ class StatusController } if (StatusModel::create($aArgs)) { - return $response->withJson([ + $return = [ StatusModel::getById(['id' => $aArgs['id']]) + ]; + + HistoryController::add([ + 'table_name' => 'status', + 'record_id' => $return[0][0]['id'], + 'event_type' => 'ADD', + 'event_id' => 'statusup', + 'info' => _STATUS_ADDED . ' : ' . $return[0][0]['id'] ]); + + return $response->withJson($return); } else { return $response->withStatus(500)->withJson(['errors' => _NOT_CREATE]); } @@ -185,9 +195,8 @@ class StatusController if(!Validator::notEmpty()->validate($request['id'])){ array_push($errors, _ID . ' ' . _EMPTY); } else if ($mode == 'create') { - $obj = StatusModel::getById([ - 'id' => $request['id'] - ]); + $obj = StatusModel::getById(['id' => $request['id']]); + if (!empty($obj)) { array_push( $errors, @@ -195,9 +204,8 @@ class StatusController ); } } elseif ($mode == 'update') { - $obj = StatusModel::getByIdentifier([ - 'identifier' => $request['identifier'] - ]); + $obj = StatusModel::getByIdentifier(['identifier' => $request['identifier']]); + if (empty($obj)) { array_push( $errors, diff --git a/rest/index.php b/rest/index.php index e77c3c720a6..e5849fb0727 100644 --- a/rest/index.php +++ b/rest/index.php @@ -107,8 +107,8 @@ $app->get('/administration/users/{id}', \Core\Controllers\UserController::class //status $app->get('/administration/status', \Core\Controllers\StatusController::class . ':getList'); -$app->get('/status/new', \Core\Controllers\StatusController::class . ':getNewInformations'); -$app->get('/status/{identifier}', \Core\Controllers\StatusController::class . ':getByIdentifier'); +$app->get('/administration/status/new', \Core\Controllers\StatusController::class . ':getNewInformations'); +$app->get('/administration/status/{identifier}', \Core\Controllers\StatusController::class . ':getByIdentifier'); $app->post('/status', \Core\Controllers\StatusController::class . ':create'); $app->put('/status/{identifier}', \Core\Controllers\StatusController::class . ':update'); $app->delete('/status/{identifier}', \Core\Controllers\StatusController::class . ':delete'); -- GitLab