update backend code for PHRAS-1783

This commit is contained in:
Mike Ng
2018-02-19 16:07:54 +04:00
parent d45c55858f
commit 0c55bc7e09
4 changed files with 28 additions and 128 deletions

View File

@@ -86,10 +86,6 @@ class TaskManagerController extends Controller
public function getLiveInformation(Request $request) public function getLiveInformation(Request $request)
{ {
if (false === $this->app['phraseanet.configuration']['main']['task-manager']['enabled']) {
throw new RuntimeException('The use of the task manager is disabled on this instance.');
}
if ($request->getRequestFormat() !== "json") { if ($request->getRequestFormat() !== "json") {
$this->app->abort(406, 'Only JSON format is accepted.'); $this->app->abort(406, 'Only JSON format is accepted.');
} }
@@ -108,23 +104,28 @@ class TaskManagerController extends Controller
public function getScheduler(Request $request) public function getScheduler(Request $request)
{ {
if (false === $this->app['phraseanet.configuration']['main']['task-manager']['enabled']) {
throw new RuntimeException('The use of the task manager is disabled on this instance.');
}
if ($request->getRequestFormat() !== "json") { if ($request->getRequestFormat() !== "json") {
$this->app->abort(406, 'Only JSON format is accepted.'); $this->app->abort(406, 'Only JSON format is accepted.');
} }
$ret = [
return $this->app->json([
'name' => $this->app->trans('Task Scheduler'), 'name' => $this->app->trans('Task Scheduler'),
'configuration' => $this->app['task-manager.status']->getStatus(), 'configuration' => $this->app['task-manager.status']->getStatus(),
'urls' => [ ];
if (($this->app['phraseanet.configuration']['main']['task-manager']['enabled'] === true)) {
$ret['urls'] = [
'start' => $this->app->path('admin_tasks_scheduler_start'), 'start' => $this->app->path('admin_tasks_scheduler_start'),
'stop' => $this->app->path('admin_tasks_scheduler_stop'), 'stop' => $this->app->path('admin_tasks_scheduler_stop'),
'log' => $this->app->path('admin_tasks_scheduler_log'),
];
}
else {
$ret['urls'] = [
'log' => $this->app->path('admin_tasks_scheduler_log'), 'log' => $this->app->path('admin_tasks_scheduler_log'),
] ];
]); }
return $this->app->json($ret);
} }
public function getTasks(Request $request) public function getTasks(Request $request)
@@ -212,10 +213,6 @@ class TaskManagerController extends Controller
public function postTaskDelete(Task $task) public function postTaskDelete(Task $task)
{ {
if (false === $this->app['phraseanet.configuration']['main']['task-manager']['enabled']) {
throw new RuntimeException('The use of the task manager is disabled on this instance.');
}
$this->getTaskManipulator()->delete($task); $this->getTaskManipulator()->delete($task);
return $this->app->redirectPath('admin_tasks_list'); return $this->app->redirectPath('admin_tasks_list');
@@ -223,10 +220,6 @@ class TaskManagerController extends Controller
public function postStartTask(Task $task) public function postStartTask(Task $task)
{ {
if (false === $this->app['phraseanet.configuration']['main']['task-manager']['enabled']) {
throw new RuntimeException('The use of the task manager is disabled on this instance.');
}
$this->getTaskManipulator()->start($task); $this->getTaskManipulator()->start($task);
return $this->app->redirectPath('admin_tasks_list'); return $this->app->redirectPath('admin_tasks_list');
@@ -234,10 +227,6 @@ class TaskManagerController extends Controller
public function postStopTask(Task $task) public function postStopTask(Task $task)
{ {
if (false === $this->app['phraseanet.configuration']['main']['task-manager']['enabled']) {
throw new RuntimeException('The use of the task manager is disabled on this instance.');
}
$this->getTaskManipulator()->stop($task); $this->getTaskManipulator()->stop($task);
return $this->app->redirectPath('admin_tasks_list'); return $this->app->redirectPath('admin_tasks_list');
@@ -252,10 +241,6 @@ class TaskManagerController extends Controller
public function postSaveTask(Request $request, Task $task) public function postSaveTask(Request $request, Task $task)
{ {
if (false === $this->app['phraseanet.configuration']['main']['task-manager']['enabled']) {
throw new RuntimeException('The use of the task manager is disabled on this instance.');
}
if (!$this->doValidateXML($request->request->get('settings'))) { if (!$this->doValidateXML($request->request->get('settings'))) {
return $this->app->json(['success' => false, 'message' => sprintf('Unable to load XML %s', $request->request->get('xml'))]); return $this->app->json(['success' => false, 'message' => sprintf('Unable to load XML %s', $request->request->get('xml'))]);
} }
@@ -292,10 +277,6 @@ class TaskManagerController extends Controller
public function getTask(Request $request, Task $task) public function getTask(Request $request, Task $task)
{ {
if (false === $this->app['phraseanet.configuration']['main']['task-manager']['enabled']) {
throw new RuntimeException('The use of the task manager is disabled on this instance.');
}
if ('json' === $request->getContentType()) { if ('json' === $request->getContentType()) {
return $this->app->json(array_replace([ return $this->app->json(array_replace([
'id' => $task->getId(), 'id' => $task->getId(),
@@ -322,10 +303,6 @@ class TaskManagerController extends Controller
public function validateXML(Request $request) public function validateXML(Request $request)
{ {
if (false === $this->app['phraseanet.configuration']['main']['task-manager']['enabled']) {
throw new RuntimeException('The use of the task manager is disabled on this instance.');
}
return $this->app->json(['success' => $this->doValidateXML($request->getContent())]); return $this->app->json(['success' => $this->doValidateXML($request->getContent())]);
} }

View File

@@ -28,86 +28,8 @@
</tr> </tr>
</thead> </thead>
<tbody class="scheduler-view"> <tbody class="scheduler-view">
<tr>
<td class="menu">
<div class="btn-group dropdown">
<a class="btn btn-mini dropdown-toggle" data-toggle="dropdown" href="#">
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
{% if app['phraseanet.configuration']['main']['task-manager']['enabled'] %}
<li>
<a method="POST" href="{{ path('admin_tasks_scheduler_start') }}">
{{ 'Start' | trans }}
</a>
</li>
<li>
<a method="POST" href="{{ path('admin_tasks_scheduler_stop') }}">
{{ 'Stop' | trans }}
</a>
</li>
{% endif %}
<li>
<a href="{{ path('admin_tasks_scheduler_log') }}">
{{ 'Logs' | trans }}
</a>
</li>
</ul>
</div>
</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td>{{ scheduler["status"] }}</td>
<td>{{ scheduler["name"] }}</td>
</tr>
</tbody> </tbody>
<tbody class="tasks-list-view"> <tbody class="tasks-list-view">
{% for task in tasks %}
<tr>
<td class="menu">
<div class="btn-group dropdown">
<a class="btn btn-mini dropdown-toggle" data-toggle="dropdown" href="#">
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li>
<a href="{{ path('admin_tasks_task_show', {"task" : task["id"] }) }}">
{{ 'Edit' | trans }}
</a>
</li>
<li>
<a method="POST" href="{{ path('admin_tasks_task_start', {"task" : task["id"] }) }}">
{{ 'Start' | trans }}
</a>
</li>
<li>
<a method="POST" href="{{ path('admin_tasks_task_stop', {"task" : task["id"] }) }}">
{{ 'Stop' | trans }}
</a>
</li>
<li>
<a method="POST" href="{{ path('admin_tasks_task_delete', {"task" : task["id"] }) }}">
{{ 'Delete' | trans }}
</a>
</li>
<li>
<a href="{{ path('admin_tasks_task_log', {"task" : task["id"] }) }}">
{{ 'Logs' | trans }}
</a>
</li>
</ul>
</div>
</td>
<td>{{ task["id"] }}</td>
<td></td>
<td></td>
<td></td>
<td>{{ task["status"] }}</td>
<td>{{ task["name"] }}</td>
</tr>
{% endfor %}
</tbody> </tbody>
</table> </table>
<form id="form-create-task" method="post" name="form-create-task" action="{{ path('admin_tasks_task_create') }}"> <form id="form-create-task" method="post" name="form-create-task" action="{{ path('admin_tasks_task_create') }}">
@@ -124,7 +46,6 @@
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function(){ $(document).ready(function(){
$('.dropdown-toggle').dropdown();
$("form[name='form-create-task'] select").bind("change", function() { $("form[name='form-create-task'] select").bind("change", function() {
$(this).closest('form').submit(); $(this).closest('form').submit();
}); });

View File

@@ -48,16 +48,18 @@
<span class="caret"></span> <span class="caret"></span>
</a> </a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li> {% if app['phraseanet.configuration']['main']['task-manager']['enabled'] %}
<a method="POST" href="<%- scheduler['urls']['start'] %>"> <li>
{{ 'Start' | trans }} <a method="POST" href="<%- scheduler['urls']['start'] %>">
</a> {{ 'Start' | trans }}
</li> </a>
<li> </li>
<a method="POST" href="<%- scheduler['urls']['stop'] %>"> <li>
{{ 'Stop' | trans }} <a method="POST" href="<%- scheduler['urls']['stop'] %>">
</a> {{ 'Stop' | trans }}
</li> </a>
</li>
{% endif %}
<li> <li>
<a href="<%- scheduler['urls']['log'] %>"> <a href="<%- scheduler['urls']['log'] %>">
{{ 'Logs' | trans }} {{ 'Logs' | trans }}

View File

@@ -36,7 +36,7 @@ define([
tasksCollection: TaskManagerApp.tasksCollection, tasksCollection: TaskManagerApp.tasksCollection,
scheduler: TaskManagerApp.Scheduler scheduler: TaskManagerApp.Scheduler
}); });
} };
var load = function() { var load = function() {
TaskManagerApp.refreshView.refreshAction(); TaskManagerApp.refreshView.refreshAction();