Use backbone to display taskmanager front end

This commit is contained in:
Nicolas Le Goff
2014-02-11 08:46:20 +01:00
parent fa98c42ff3
commit 7025e756bc
31 changed files with 1002 additions and 521 deletions

View File

@@ -27,6 +27,14 @@ module.exports = function(grunt) {
} }
} }
}, },
shell : {
generate_js_fixtures: {
options: {
stdout: true
},
command : 'bin/developer phraseanet:generate-js-fixtures'
}
},
bower_postinst: { bower_postinst: {
dist: { dist: {
options: { options: {
@@ -338,6 +346,7 @@ module.exports = function(grunt) {
}); });
grunt.loadNpmTasks("grunt-contrib"); grunt.loadNpmTasks("grunt-contrib");
grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks("grunt-bower-task"); grunt.loadNpmTasks("grunt-bower-task");
grunt.loadNpmTasks("grunt-bower-postinst"); grunt.loadNpmTasks("grunt-bower-postinst");
grunt.loadNpmTasks('grunt-mocha-phantomjs'); grunt.loadNpmTasks('grunt-mocha-phantomjs');
@@ -348,6 +357,7 @@ module.exports = function(grunt) {
grunt.registerTask("copy-deps", [ grunt.registerTask("copy-deps", [
"copy:deps-when" "copy:deps-when"
]); ]);
grunt.registerTask("copy-assets", [ grunt.registerTask("copy-assets", [
"copy:autobahnjs", "copy:autobahnjs",
"copy:backbone", "copy:backbone",
@@ -384,5 +394,5 @@ module.exports = function(grunt) {
"bower_postinst", "bower_postinst",
"copy-assets" "copy-assets"
]); ]);
grunt.registerTask('test', ["qunit", "mocha_phantomjs"]); grunt.registerTask('test', ["shell:generate_js_fixtures", "qunit", "mocha_phantomjs"]);
}; };

View File

@@ -16,6 +16,7 @@ use Alchemy\Phrasea\Command\Developer\Behat;
use Alchemy\Phrasea\Command\Developer\BowerInstall; use Alchemy\Phrasea\Command\Developer\BowerInstall;
use Alchemy\Phrasea\Command\Developer\ComposerInstall; use Alchemy\Phrasea\Command\Developer\ComposerInstall;
use Alchemy\Phrasea\Command\Developer\InstallAll; use Alchemy\Phrasea\Command\Developer\InstallAll;
use Alchemy\Phrasea\Command\Developer\JsFixtures;
use Alchemy\Phrasea\Command\Developer\LessCompiler; use Alchemy\Phrasea\Command\Developer\LessCompiler;
use Alchemy\Phrasea\Command\Developer\RegenerateSqliteDb; use Alchemy\Phrasea\Command\Developer\RegenerateSqliteDb;
use Alchemy\Phrasea\Command\Developer\RoutesDumper; use Alchemy\Phrasea\Command\Developer\RoutesDumper;
@@ -87,6 +88,7 @@ $cli->command(new RoutesDumper());
$cli->command(new Behat()); $cli->command(new Behat());
$cli->command(new LessCompiler()); $cli->command(new LessCompiler());
$cli->command(new Uninstaller()); $cli->command(new Uninstaller());
$cli->command(new JsFixtures());
$cli->command(new \module_console_systemTemplateGenerator('system:generate-templates')); $cli->command(new \module_console_systemTemplateGenerator('system:generate-templates'));

View File

@@ -303,6 +303,7 @@ class Application extends SilexApplication
$this->register(new SessionServiceProvider(), [ $this->register(new SessionServiceProvider(), [
'session.test' => $this->getEnvironment() === static::ENV_TEST 'session.test' => $this->getEnvironment() === static::ENV_TEST
]); ]);
$this['session.storage.handler'] = $this->share(function ($app) { $this['session.storage.handler'] = $this->share(function ($app) {
return $this['session.storage.handler.factory']->create($app['conf']); return $this['session.storage.handler.factory']->create($app['conf']);
}); });

View File

@@ -0,0 +1,129 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Command\Developer;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Command\Command;
use Alchemy\Phrasea\Exception\RuntimeException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\HttpKernel\Client;
class JsFixtures extends Command
{
public function __construct()
{
parent::__construct('phraseanet:generate-js-fixtures');
$this->setDescription('Generate JS fixtures');
}
protected function doExecute(InputInterface $input, OutputInterface $output)
{
$dbRefPath = __DIR__ . '/../../../../../tests/db-ref.sqlite';
if (!file_exists($dbRefPath)) {
throw new RuntimeException('You must generate sqlite db first, run "bin/console phraseanet:regenerate-sqlite" command.');
}
copy($dbRefPath, '/tmp/db.sqlite');
$user = $this->createUser($this->container);
$sbasId = current($this->container['phraseanet.appbox']->get_databoxes())->get_sbas_id();
try {
$this->writeResponse($output, 'GET', '/login/', '/home/login/index.html');
$this->writeResponse($output, 'GET', '/admin/fields/'.$sbasId , '/admin/fields/index.html', $user);
$this->writeResponse($output, 'GET', '/admin/task-manager/tasks', '/admin/task-manager/index.html', $user);
} catch (RuntimeException $e) {
$user->delete();
throw $e;
}
$this->copy($output, [
['source' => 'login/common/templates.html.twig', 'target' => 'home/login/templates.html'],
['source' => 'admin/fields/templates.html.twig', 'target' => 'admin/fields/templates.html'],
['source' => 'admin/task-manager/templates.html.twig', 'target' => 'admin/task-manager/templates.html'],
]);
$user->delete();
return 0;
}
private function copy(OutputInterface $output, $data)
{
foreach ($data as $paths) {
$output->writeln(sprintf("Generating %s", $this->container['root.path'] . '/www/scripts/tests/fixtures/'.$paths['target']));
$this->container['filesystem']->copy(
$this->container['root.path'] . '/templates/web/'.$paths['source'],
$this->container['root.path'] . '/www/scripts/tests/fixtures/'.$paths['target']
);
}
}
private function removeScriptTags($html)
{
return preg_replace('#<script(.*?)>(.*?)</script>#is', '', $html);
}
private function removeHeadTag($html)
{
return preg_replace('#<head>(.*?)</head>#is', '', $html);
}
private function createUser(Application $app)
{
$user = \User_Adapter::create($app, uniqid('fixturejs'), uniqid('fixturejs'), uniqid('fixturejs') . '@js.js', true);
$app['acl']->get($user)->set_admin(true);
$app['manipulator.acl']->resetAdminRights($user);
return $user;
}
private function loginUser(Application $app, \User_Adapter $user)
{
$app['authentication']->openAccount($user);
}
private function logoutUser(Application $app)
{
$app['authentication']->closeAccount();
}
private function writeResponse(OutputInterface $output, $method, $path, $to, \User_Adapter $user = null)
{
$environment = Application::ENV_TEST;
$app = require __DIR__ . '/../../Application/Root.php';
// force load of non cached template
$app['twig']->enableAutoReload();
$client = new Client($app);
$fixturePath = 'www/scripts/tests/fixtures';
$target = sprintf('%s/%s/%s', $app['root.path'],$fixturePath, $to);
$output->writeln(sprintf("Generating %s", $target));
if (null !== $user) {
$this->loginUser($app, $user);
}
$client->request($method, $path);
$response = $client->getResponse();
if (null !== $user) {
$this->logoutUser($app);
}
if (false === $response->isOk()) {
throw new RuntimeException(sprintf('Request %s %s returns %d code error', $method, $path, $response->getStatusCode()));
}
$this->container['filesystem']->mkdir(str_replace(basename($target), '', $target));
$this->container['filesystem']->dumpFile($target, $this->removeHeadTag($this->removeScriptTags($response->getContent())));
}
}

View File

@@ -42,6 +42,10 @@ class TaskManager implements ControllerProviderInterface
->get('/tasks', 'controller.admin.task:getTasks') ->get('/tasks', 'controller.admin.task:getTasks')
->bind('admin_tasks_list'); ->bind('admin_tasks_list');
$controllers
->get('/scheduler', 'controller.admin.task:getScheduler')
->bind('admin_scheduler');
$controllers $controllers
->post('/tasks/create', 'controller.admin.task:postCreateTask') ->post('/tasks/create', 'controller.admin.task:postCreateTask')
->bind('admin_tasks_task_create'); ->bind('admin_tasks_task_create');
@@ -120,11 +124,51 @@ class TaskManager implements ControllerProviderInterface
return $app->redirectPath('admin_tasks_list'); return $app->redirectPath('admin_tasks_list');
} }
public function getScheduler(Application $app, Request $request)
{
if ($request->getRequestFormat() !== "json") {
$app->abort(406, 'Only JSON format is accepted.');
}
$scheduler = array_replace($app['task-manager.live-information']->getManager(), [
'name' => $app->trans('Task Scheduler'),
'urls' => [
'start' => $app->path('admin_tasks_scheduler_start'),
'stop' => $app->path('admin_tasks_scheduler_stop'),
'log' => $app->path('admin_tasks_scheduler_log'),
]
]);
return $app->json($scheduler);
}
public function getTasks(Application $app, Request $request) public function getTasks(Application $app, Request $request)
{ {
return $app['twig']->render('admin/task-manager/list.html.twig', [ $tasks = [];
'available_jobs' => $app['task-manager.available-jobs'],
'tasks' => $app['manipulator.task']->getRepository()->findAll(), foreach ($app['manipulator.task']->getRepository()->findAll() as $task) {
$tasks[] = array_replace(
$app['task-manager.live-information']->getTask($task), [
'id' => $task->getId(),
'name' => $task->getName()
]);
}
if ($request->getRequestFormat() === "json") {
foreach ($tasks as $k => $task) {
$tasks[$k]['urls'] = $this->getTaskResourceUrls($app, $task['id']);
}
return $app->json($tasks);
}
return $app['twig']->render('admin/task-manager/index.html.twig', [
'available_jobs' => $app['task-manager.available-jobs'],
'tasks' => $tasks,
'scheduler' => array_replace(
$app['task-manager.live-information']->getManager(), [
'name' => $app->trans('Task Scheduler')
])
]); ]);
} }
@@ -239,6 +283,16 @@ class TaskManager implements ControllerProviderInterface
public function getTask(Application $app, Request $request, Task $task) public function getTask(Application $app, Request $request, Task $task)
{ {
if ('json' === $request->getContentType()) {
return $app->json(array_replace([
'id' => $task->getId(),
'name' => $task->getName(),
'urls' => $this->getTaskResourceUrls($app, $task->getId())
],
$app['task-manager.live-information']->getTask($task)
));
}
$editor = $app['task-manager.job-factory'] $editor = $app['task-manager.job-factory']
->create($task->getJobId()) ->create($task->getJobId())
->getEditor(); ->getEditor();
@@ -265,4 +319,15 @@ class TaskManager implements ControllerProviderInterface
return (Boolean) @$dom->loadXML($string); return (Boolean) @$dom->loadXML($string);
} }
private function getTaskResourceUrls(Application $app, $taskId)
{
return [
'show' => $app->path('admin_tasks_task_show', ['task' => $taskId]),
'start' => $app->path('admin_tasks_task_start', ['task' => $taskId]),
'stop' => $app->path('admin_tasks_task_stop', ['task' => $taskId]),
'delete' => $app->path('admin_tasks_task_delete', ['task' => $taskId]),
'log' => $app->path('admin_tasks_task_log', ['task' => $taskId]),
];
}
} }

View File

@@ -9,6 +9,7 @@
"jake": "latest", "jake": "latest",
"grunt-cli": "latest", "grunt-cli": "latest",
"grunt": "~0.4.1", "grunt": "~0.4.1",
"grunt-shell": "~0.6",
"grunt-contrib": "~0.4.0", "grunt-contrib": "~0.4.0",
"grunt-bower-task": "~0.3.0", "grunt-bower-task": "~0.3.0",
"grunt-bower-postinst": "~0.2.0", "grunt-bower-postinst": "~0.2.0",

View File

@@ -1,6 +1,3 @@
{# include js templates #}
{% include 'admin/fields/templates.html.twig' %}
<div id="admin-field-app" class="container-fluid"> <div id="admin-field-app" class="container-fluid">
{# sbas_id is saved in the dom and used to fetch right models and collections #} {# sbas_id is saved in the dom and used to fetch right models and collections #}
<input type="hidden" name="current_sbas_id" value="{{ sbas_id }}"> <input type="hidden" name="current_sbas_id" value="{{ sbas_id }}">
@@ -20,5 +17,8 @@
</div> </div>
</div> </div>
{# include js templates #}
{% include 'admin/fields/templates.html.twig' %}
{# bootstrap admin field backbone application #} {# bootstrap admin field backbone application #}
<script type="text/javascript" src="{{ path('minifier', { 'f' : 'assets/requirejs/require.js,/scripts/apps/admin/fields/main.js' }) }}"></script> <script type="text/javascript" src="{{ path('minifier', { 'f' : 'assets/requirejs/require.js,/scripts/apps/admin/fields/main.js' }) }}"></script>

View File

@@ -107,24 +107,27 @@
} }
function enableLink(link) { function enableLink(link) {
$(link).bind('click',function(event){ $(link).bind('click',function(event){
var dest = link.attr('href'); var dest = link.attr('href');
var method = link.attr("method");
if(dest && dest.indexOf('#') !== 0) { if(dest && dest.indexOf('#') !== 0) {
loadRightAjax(dest); loadRightAjax(dest, method || "GET");
return false; return false;
} }
}); });
} }
function loadRightAjax(url) function loadRightAjax(url, method)
{ {
$('#right-ajax').empty().addClass('loading').parent().show(); $('#right-ajax').empty().addClass('loading').parent().show();
$.get(url, function(data) {
enableFormsCallback(data); $.ajax({
type: method,
url: url,
success: function(data) {
enableFormsCallback(data);
}
}); });
} }

View File

@@ -0,0 +1,129 @@
<div class="page-header">
<h1>{{ 'Task Scheduler' | trans }}
<small style="font-size:16px;">
{% set updateTime %}
<span id="pingTime">{{ "now"|date(constant("DateTime::ISO8601")) }}</span>
{% endset %}
{% trans with {'%updateTime%' : updateTime} %}Last update on %updateTime%{% endtrans %}
</small>
</h1>
</div>
<div id="task-manager-app">
<table class="admintable">
<thead>
<tr>
<th></th>
<th>ID</th>
<th>PID</th>
<th>!</th>
<th>{{ "actual status" | trans | upper }}</th>
<th>{{ "scheduled status" | trans | upper }}</th>
<th>{{ "name" | trans | upper }}</th>
</tr>
</thead>
<tbody id="scheduler-view">
<tr>
<td class="menu">
<div class="btn-group">
<a class="btn btn-mini dropdown-toggle" data-toggle="dropdown" href="#">
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<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>
<li>
<a href="{{ path('admin_tasks_scheduler_log') }}">
{{ 'Logs' | trans }}
</a>
</li>
</ul>
</div>
</td>
<td></td>
<td>{{ scheduler["process-id"] }}</td>
<td></td>
<td>{{ scheduler["actual"] }}</td>
<td>{{ scheduler["configuration"] }}</td>
<td>{{ scheduler["name"] }}</td>
</tr>
</tbody>
<tbody id="tasks-list-view">
{% for task in tasks %}
<tr>
<td class="menu">
<div class="btn-group">
<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>{% if task["id"] != "taskmanager" %}{{ task["id"] }}{% endif %}</td>
<td>{{ task["process-id"] }}</td>
<td></td>
<td>{{ task["actual"] }}</td>
<td>{{ task["configuration"] }}</td>
<td>{{ task["name"] }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<form id="form-create-task" method="post" name="form-create-task" action="{{ path('admin_tasks_task_create') }}">
<select name="job-name">
<option value="">
{{ 'New task' | trans }}
</option>
{% for job in available_jobs %}
<option value="{{ job.getJobId() }}">{{ job.getName() }}</option>
{% endfor %}
</select>
</form>
</div>
<script type="text/javascript">
$(document).ready(function(){
$("form[name='form-create-task'] select").bind("change", function() {
$(this).closest('form').submit();
});
});
</script>
{# include js templates #}
{% include 'admin/task-manager/templates.html.twig' %}
<script type="text/javascript" src="{{ path('minifier', { 'f' : 'assets/requirejs/require.js,/scripts/apps/admin/tasks-manager/main.js' }) }}"></script>

View File

@@ -1,140 +0,0 @@
<style type="text/css">
#task-manager td,
#task-manager th {
text-align: center;
}
#task-manager td.menu {
width:40px;
}
#task-manager td.id {
width:40px;
}
#task-manager td.information {
width:30px;
}
#task-manager td.status {
width:80px;
}
#task-manager td.process-id {
width:60px;
}
#task-manager td.taskname {
text-align: left;
width:auto;
}
#task-manager td.id {
font-weight: bold;
}
</style>
<div class="page-header">
<h1>{{ 'admin::tasks: planificateur de taches' | trans }}
<small style="font-size:16px;">
{% set updateTime %}
<span id="pingTime"></span>
{% endset %}
{% trans with {'%updateTime%' : updateTime} %}Last update on %updateTime%{% endtrans %}
</small>
</h1>
</div>
<table id="task-manager" class="admintable table table-striped" cellpadding="0" cellSpacing="0">
<thead>
<tr>
<th class="menu"></th>
<th class="id">ID</th>
<th class="information">{{ 'Informations' | trans }}</th>
<th class="status">{{ 'admin::tasks: statut de la tache' | trans }}</th>
<th class="process-id">{{ 'admin::tasks: process_id de la tache' | trans }}</th>
<th class="taskname">{{ 'admin::tasks: nom de la tache' | trans }}</th>
</tr>
</thead>
<tbody>
<tr id="task_manager_status" class="even">
<td class="menu">
<div class="btn-group">
<a class="btn btn-mini dropdown-toggle" data-toggle="dropdown" href="#">
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<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>
<li>
<a href="{{ path ('admin_tasks_scheduler_log') }}">{{ 'Logs' | trans }}</a>
</li>
</ul>
</div>
</td>
<td class="id"></td>
<td class="information"></td>
<td class="status"></td>
<td class="process-id"></td>
<td class="taskname" style="font-weight:bold;">{{ 'admin::tasks: planificateur de taches' | trans }}</td>
</tr>
{% for task in tasks %}
<tr id="task_{{ task.getId() }}" class="{% if loop.index is odd %}odd{% else %}even{% endif %}">
<td class="menu">
<div class="btn-group">
<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.getId() }) }}">
{{ 'Edit' | trans }}
</a>
</li>
<li>
<a method="POST" href="{{ path('admin_tasks_task_start', { 'task' : task.getId() }) }}">
{{ 'Start' | trans }}
</a>
</li>
<li>
<a method="POST" href="{{ path('admin_tasks_task_stop', { 'task' : task.getId() }) }}">
{{ 'Stop' | trans }}
</a>
</li>
<li>
<a method="POST" href="{{ path('admin_tasks_task_delete', { 'task' : task.getId() }) }}">
{{ 'Delete' | trans }}
</a>
</li>
<li>
<a href="{{ path('admin_tasks_task_log', { 'task' : task.getId() }) }}">
{{ 'Logs' | trans }}
</a>
</li>
</ul>
</div>
</td>
<td class="id">{{ task.getID() }}</td>
<td class="information"></td>
<td class="status">{{ task.getStatus() }}</td>
<td class="process-id"></td>
<td class="taskname">{{ task.getName() }} [{{ task.getName() }}]</td>
</tr>
{% endfor %}
</tbody>
</table>
<form id="form-create-task" method="post" name="form-create-task" action="{{ path('admin_tasks_task_create') }}">
<select name="job-name">
<option value="">
{{ 'admin::tasks: Nouvelle tache' | trans }}
</option>
{% for job in available_jobs %}
<option value="{{ job.getJobId() }}">{{ job.getName() }}</option>
{% endfor %}
</select>
</form>
<script type="text/javascript">
$(document).ready(function(){
$("form[name='form-create-task'] select").bind("change", function() {
$(this).closest('form').submit();
});
});
</script>

View File

@@ -0,0 +1,75 @@
<script type="text/template" id="task_template">
<td class="menu">
<div class="btn-group">
<a class="btn btn-mini dropdown-toggle" data-toggle="dropdown" href="#">
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li>
<a href="<%- task['urls']['show'] %>">
{{ 'Edit' | trans }}
</a>
</li>
<li>
<a method="POST" href="<%- task['urls']['start'] %>">
{{ 'Start' | trans }}
</a>
</li>
<li>
<a method="POST" href="<%- task['urls']['stop'] %>">
{{ 'Stop' | trans }}
</a>
</li>
<li>
<a method="POST" href="<%- task['urls']['delete'] %>">
{{ 'Delete' | trans }}
</a>
</li>
<li>
<a href="<%- task['urls']['log'] %>">
{{ 'Logs' | trans }}
</a>
</li>
</ul>
</div>
</td>
<td class="idTask"><%- task.id %></td>
<td class="pidTask"><%- task['process-id'] %></td>
<td></td>
<td class="actualTask"><%- task.actual %></td>
<td class="confTask"><%- task.configuration %></td>
<td class="nameTask"><%- task.name %></td>
</script>
<script type="text/template" id="scheduler_template">
<td class="menu">
<div class="btn-group">
<a class="btn btn-mini dropdown-toggle" data-toggle="dropdown" href="#">
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li>
<a method="POST" href="<%- scheduler['urls']['start'] %>">
{{ 'Start' | trans }}
</a>
</li>
<li>
<a method="POST" href="<%- scheduler['urls']['stop'] %>">
{{ 'Stop' | trans }}
</a>
</li>
<li>
<a href="<%- scheduler['urls']['log'] %>">
{{ 'Logs' | trans }}
</a>
</li>
</ul>
</div>
</td>
<td></td>
<td class="pidScheduler"><%- scheduler['process-id'] %></td>
<td></td>
<td class="actualScheduler"><%- scheduler.actual %></td>
<td class="confScheduler"><%- scheduler.configuration %></td>
<td class="nameScheduler"><%- scheduler.name %></td>
</script>

View File

@@ -148,6 +148,7 @@
<style type="text/css"> <style type="text/css">
#galleria { #galleria {
height: 400px; height: 400px;
}
</style> </style>
{% endif %} {% endif %}
{% endblock %} {% endblock %}

View File

@@ -19,6 +19,20 @@ class TaskManagerTest extends \PhraseanetAuthenticatedWebTestCase
$this->assertTrue(self::$DI['client']->getResponse()->isOk()); $this->assertTrue(self::$DI['client']->getResponse()->isOk());
} }
public function testRootListTasksJson()
{
self::$DI['client']->request('GET', '/admin/task-manager/tasks', [], [], ["HTTP_CONTENT_TYPE" => "application/json", "HTTP_ACCEPT" => "application/json"]);
$this->assertEquals(200, self::$DI['client']->getResponse()->getStatusCode());
$tasks = json_decode(self::$DI['client']->getResponse()->getContent());
foreach ($tasks as $task) {
$this->assertObjectHasAttribute('id', $task);
$this->assertObjectHasAttribute('name', $task);
$this->assertObjectHasAttribute('configuration', $task);
$this->assertObjectHasAttribute('actual', $task);
$this->assertObjectHasAttribute('urls', $task);
}
}
public function testRootPostCreateTask() public function testRootPostCreateTask()
{ {
$parameters = [ $parameters = [
@@ -155,6 +169,35 @@ class TaskManagerTest extends \PhraseanetAuthenticatedWebTestCase
$this->assertEquals(200, self::$DI['client']->getResponse()->getStatusCode()); $this->assertEquals(200, self::$DI['client']->getResponse()->getStatusCode());
} }
public function testGetTaskJson()
{
self::$DI['client']->request('GET', '/admin/task-manager/task/1', [], [], ["HTTP_CONTENT_TYPE" => "application/json", "HTTP_ACCEPT" => "application/json"]);
$this->assertEquals(200, self::$DI['client']->getResponse()->getStatusCode());
$json = json_decode(self::$DI['client']->getResponse()->getContent());
$this->assertObjectHasAttribute('id', $json);
$this->assertObjectHasAttribute('name', $json);
$this->assertObjectHasAttribute('configuration', $json);
$this->assertObjectHasAttribute('actual', $json);
$this->assertObjectHasAttribute('urls', $json);
}
public function testGetSchedulerJson()
{
self::$DI['client']->request('GET', '/admin/task-manager/scheduler', [], [], ["HTTP_CONTENT_TYPE" => "application/json", "HTTP_ACCEPT" => "application/json"]);
$this->assertEquals(200, self::$DI['client']->getResponse()->getStatusCode());
$json = json_decode(self::$DI['client']->getResponse()->getContent());
$this->assertObjectHasAttribute('name', $json);
$this->assertObjectHasAttribute('configuration', $json);
$this->assertObjectHasAttribute('actual', $json);
$this->assertObjectHasAttribute('urls', $json);
}
public function testGetSchedulerJsonBadRequest()
{
self::$DI['client']->request('GET', '/admin/task-manager/scheduler');
$this->assertEquals(406, self::$DI['client']->getResponse()->getStatusCode());
}
public function testGetInvalidTask() public function testGetInvalidTask()
{ {
self::$DI['client']->request('GET', '/admin/task-manager/task/50'); self::$DI['client']->request('GET', '/admin/task-manager/task/50');

View File

@@ -0,0 +1,69 @@
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
define([
"jquery",
"underscore",
"backbone",
"models/scheduler",
"apps/admin/tasks-manager/views/scheduler",
"apps/admin/tasks-manager/views/tasks",
"apps/admin/tasks-manager/views/ping",
"apps/admin/tasks-manager/collections/tasks"
], function ($, _, Backbone, Scheduler, SchedulerView, TasksView, PingView, TasksCollection) {
var create = function() {
window.TaskManagerApp = {
$scope: $("#task-manager-app"),
$tasksListView : $("#tasks-list-view", this.$scope),
$schedulerView : $("#scheduler-view", this.$scope),
$pingView : $("#pingTime", this.$scope)
};
TaskManagerApp.tasksCollection = new TasksCollection();
TaskManagerApp.Scheduler = new Scheduler();
TaskManagerApp.pingView = new PingView({
el: TaskManagerApp.$pingView
});
}
var load = function() {
// fetch objects
$.when.apply($, [
TaskManagerApp.tasksCollection.fetch(),
TaskManagerApp.Scheduler.fetch()
]).done(
function () {
TaskManagerApp.schedulerView = new SchedulerView({
model: TaskManagerApp.Scheduler,
el: TaskManagerApp.$schedulerView
});
TaskManagerApp.tasksView = new TasksView({
collection: TaskManagerApp.tasksCollection,
el: TaskManagerApp.$tasksListView
});
// render views
TaskManagerApp.tasksView.render();
TaskManagerApp.schedulerView.render();
}
);
};
var initialize = function () {
create();
load();
};
return {
create: create,
load: load,
initialize: initialize
};
});

View File

@@ -0,0 +1,23 @@
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
define([
"underscore",
"backbone",
"models/task"
], function (_, Backbone, TaskModel) {
var TaskCollection = Backbone.Collection.extend({
model: TaskModel,
url: function () {
return "/admin/task-manager/tasks";
}
});
return TaskCollection;
});

View File

@@ -0,0 +1,32 @@
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
// configure AMD loading
require.config({
baseUrl: "/scripts",
paths: {
jquery: "../assets/jquery/jquery",
jqueryui: "../assets/jquery.ui/jquery-ui",
underscore: "../assets/underscore-amd/underscore",
backbone: "../assets/backbone-amd/backbone",
i18n: "../assets/i18next/i18next.amd-1.6.3",
bootstrap: "../assets/bootstrap/js/bootstrap.min"
},
shim: {
bootstrap: ["jquery"],
jqueryui: {
deps: [ "jquery" ]
}
}
});
// launch application
require(["apps/admin/tasks-manager/app"], function (App) {
App.initialize();
});

View File

@@ -0,0 +1,26 @@
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
define([
"jquery",
"underscore",
"backbone"
], function ($, _, Backbone) {
var PingView = Backbone.View.extend({
render: function () {
var date = new Date();
this.$el.html(date.toISOString());
return this;
}
});
return PingView;
});

View File

@@ -0,0 +1,62 @@
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
define([
"jquery",
"underscore",
"backbone"
], function ($, _, Backbone) {
var SchedulerView = Backbone.View.extend({
initialize: function () {
this.template = _.template($('#scheduler_template').html());
// render only parts of the model
this.model.on('change:configuration', this.renderConfiguration, this);
this.model.on('change:actual', this.renderActual, this);
this.model.on('change:process-id', this.renderPid, this);
this.model.on('change:name', this.renderName, this);
},
events: {
"click a": "clickAction"
},
tagName: "tr",
render: function () {
this.$el.empty();
this.$el.html(this.template({'scheduler':this.model.toJSON()}));
return this;
},
renderConfiguration: function () {
$(".confScheduler", this.$el).html(this.model.get("configuration"));
return this;
},
renderActual: function () {
$(".actualScheduler", this.$el).html(this.model.get("actual"));
return this;
},
renderPid: function () {
$(".pidScheduler", this.$el).html(this.model.get("process-id"));
return this;
},
renderName: function () {
$(".nameScheduler", this.$el).html(this.model.get("name"));
return this;
},
clickAction: function(e) {
e.preventDefault();
var link = $(e.target);
var url = link.attr('href');
if(url && url.indexOf('#') !== 0) {
// This is defined in admin/index.html.twig
window.loadRightAjax(url, link.attr("method") || "GET");
}
}
});
return SchedulerView;
});

View File

@@ -0,0 +1,66 @@
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
define([
"jquery",
"underscore",
"backbone"
], function ($, _, Backbone) {
var TaskView = Backbone.View.extend({
initialize: function () {
this.template = _.template($('#task_template').html());
// render only parts of the model
this.model.on('change:id', this.renderId, this);
this.model.on('change:configuration', this.renderConfiguration, this);
this.model.on('change:actual', this.renderActual, this);
this.model.on('change:process-id', this.renderPid, this);
this.model.on('change:name', this.renderName, this);
},
events: {
"click a": "clickAction"
},
tagName: "tr",
render: function () {
this.$el.html(this.template({'task':this.model.toJSON()}));
return this;
},
renderId: function () {
$(".idTask", this.$el).html(this.model.get("id"));
return this;
},
renderConfiguration: function () {
$(".confTask", this.$el).html(this.model.get("configuration"));
return this;
},
renderActual: function () {
$(".actualTask", this.$el).html(this.model.get("actual"));
return this;
},
renderPid: function () {
$(".pidTask", this.$el).html(this.model.get("process-id"));
return this;
},
renderName: function () {
$(".nameTask", this.$el).html(this.model.get("name"));
return this;
},
clickAction: function(e) {
e.preventDefault();
var link = $(e.target);
var url = link.attr('href');
if(url && url.indexOf('#') !== 0) {
// This is defined in admin/index.html.twig
window.loadRightAjax(url, link.attr("method") || "GET");
}
}
});
return TaskView;
});

View File

@@ -0,0 +1,70 @@
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
define([
"jquery",
"jqueryui",
"underscore",
"backbone",
"i18n",
"apps/admin/tasks-manager/views/task"
], function ($, jqueryui, _, Backbone, i18n, TaskView) {
var TasksView = Backbone.View.extend({
initialize: function() {
this._taskViews = [];
this._rendered = false;
this.collection.bind('add', this._addOne, this);
this.collection.bind('remove', this._removeOne, this);
},
render: function () {
var $this = this;
$this.$el.empty();
$this.collection.each(function(model) {
$this._appendDom($this._createView(model));
});
$this._rendered = true;
return $this;
},
_addOne: function (task) {
var view = this._createView(task);
if (this._rendered) {
this._appendDom(view);
}
},
_createView: function (task) {
var view = new TaskView({ model: task });
this._taskViews.push(view);
return view;
},
_deleteView: function (task) {
var view = _(this._taskViews).select(function(taskView) {
return taskView.model === task;
})[0];
this._taskViews = _(this._taskViews).without(view);
return view;
},
_removeOne: function (task) {
var view = this._deleteView(task);
if (this._rendered) {
this._removeDom(view);
}
},
_appendDom: function(view) {
this.$el.append(view.render().el);
},
_removeDom: function(view) {
view.$el.remove();
}
});
return TasksView;
});

View File

@@ -0,0 +1,34 @@
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
define([
"underscore",
"backbone"
], function (_, Backbone) {
var TaskModel = Backbone.Model.extend({
sync: function(method, model, options) {
var options = options || {};
options.Accept = 'application/json';
return Backbone.sync(method, model, options);
},
urlRoot: function () {
return "/admin/task-manager/scheduler";
},
defaults: {
"name" : null,
"configuration": null,
"actual": null,
"process-id": null
}
});
// Return the model for the module
return TaskModel;
});

View File

@@ -0,0 +1,34 @@
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
define([
"underscore",
"backbone"
], function (_, Backbone) {
var TaskModel = Backbone.Model.extend({
sync: function(method, model, options) {
var options = options || {};
options.Accept = 'application/json';
return Backbone.sync(method, model, options);
},
urlRoot: function () {
return "/admin/task-manager/" + this.get("id");
},
defaults: {
"id" : null,
"name" : null,
"configuration": null,
"actual": null,
"process-id": null
}
});
// Return the model for the module
return TaskModel;
});

View File

@@ -1,18 +0,0 @@
<div id="admin-field-app" class="container-fluid">
{# sbas_id is saved in the dom and used to fetch right models and collections #}
<input type="hidden" name="current_sbas_id" value="{{ sbas_id }}">
<div class="row-fluid row-top">
<div class="span4 save-block">
{# set loading state, this will be removed once backbone application is fully loaded #}
<img src="/skins/icons/loaderFFF.gif"/>
{% trans %}Loading database documentary fields ...{% endtrans %}
</div>
<div class="span8">
<div class="block-alert"></div>
</div>
</div>
<div class="row-fluid row-bottom hidden">
<div class="left-block span4"></div>
<div class="right-block span8"></div>
</div>
</div>

View File

@@ -1,265 +0,0 @@
<script type="text/template" id="alert_template">
<button type="button" class="close" data-dismiss="alert">&times;</button>
<%= msg %>
</script>
<script type="text/template" id="save_template">
<button type="button" class="btn btn-large btn-success save-all">
<i class="icon-hdd icon-white"></i> {% trans %}Save all changes{% endtrans %}
</button>
</script>
<script type="text/template" id="modal_template">
<div class="modal-body">
<p><%= msg %></p>
</div>
<div class="modal-footer">
<button type="button" data-dismiss="modal" class="btn cancel">{% trans %}Close{% endtrans %}</button>
<button type="button" class="btn btn-primary confirm">{% trans %}Ok{% endtrans %}</button>
</div>
</script>
<script type="text/template" id="item_list_view_template">
<div class="row-fluid">
<div class="span12">
<div class="create-subview"></div>
<div class="sidebar-search-block">
<input class="input-block-level" type="text" id="live_search" placeholder="{% trans %}Live search{% endtrans %}"/>
</div>
</div>
</div>
<div class="row-fluid">
<div class="span12 list-block">
<ul id="collection-fields" class="unstyled"></ul>
</div>
</div>
</script>
<script type="text/template" id="create_template">
<div class="row-fluid">
<div class="span12">
<div class="sidebar-add-block">
<button type="button" class="btn btn-success btn-add-field"><i class="icon-plus icon-white"></i>{% trans %}Add new field{% endtrans %}</button>
</div>
<div class="well well-small add-field-block" style="display:none">
<h3>{% trans %}Add a new field{% endtrans %}</h3>
<form class="form-horizontal">
<div class="control-group">
<label class="control-label" for="new-name"">{% trans %}Label{% endtrans %}</label>
<div class="controls">
<input type="text" id="new-name" class="input-block-level" placeholder="">
<span class="help-block"></span>
</div>
</div>
<div class="control-group">
<label class="control-label" for="new-source">{% trans %}Source{% endtrans %}</label>
<div class="controls">
<input type="text" id="new-source" class="input-block-level" placeholder="">
<span class="help-block"></span>
</div>
</div>
<div class="control-group">
<div class="controls">
<label class="checkbox">
<input id="new-multivalued" type="checkbox">{% trans %}Multivalued{% endtrans %}
</label>
<button type="button" class="btn btn-success btn-submit-field"><i class="icon-ok icon-white"></i>{% trans %}Add{% endtrans %}</button>
<button type="button" class="btn btn-cancel-field">{% trans %}Cancel{% endtrans %}</button>
</div>
</div>
</form>
</div>
</div>
</div>
</script>
<script type="text/template" id="edit_template">
<div class="edit-block">
<table>
<tr class="edit-order">
<td>{% trans %}Order{% endtrans %}</td>
<td><%= field.sorter %></td>
<td><button type="button" class="btn btn-danger delete-field pull-right"><i class="icon-trash icon-white"></i>delete</button></td>
</tr>
<tr class="edit-name ">
<td colspan="2" class="control-group <%= modelErrors && modelErrors.has('name') ? 'error' : '' %>">
<input id="name" type="text" value="<%= field.name %>" class="input-block-level">
<span class="help-block">
<% if(modelErrors && modelErrors.get('name')) { %>
<%= modelErrors.get('name').message %>
<% } %>
</span>
</td>
</tr>
<tr>
<td>{% trans %}Source{% endtrans %}</td>
<td class="control-group <%= modelErrors && modelErrors.has('tag') ? 'error' : '' %>">
<input id="tag" val="<%= field.tag %>" class="input-block-level"/>
<span class="help-block">
<% if(modelErrors && modelErrors.get('tag')) { %>
<%= modelErrors.get('tag').message %>
<% } %>
</span>
</td>
</tr>
<tr>
<td>{% trans %}DCES{% endtrans %}</td>
<td class="dc-fields-subview"></td>
</tr>
<tr>
<td colspan="2" class="dces-help-block info"></td>
</tr>
<tr>
<td colspan="2">
<% if(field.multi == true) { %>
<i class='icon-ok'></i>
<% } else { %>
<i class='icon-remove'></i>
<% } %> {% trans %}Multivalued{% endtrans %}
</td>
</tr>
</table>
<div class="edit-form">
<h4>{% trans %}Advanced field parameters{% endtrans %}</h4>
<table>
<tr>
<td><label for="tbranch">{% trans %}Thesaurus branch{% endtrans %}</label></td>
<td><input id="tbranch" type="text" value="<%= field.tbranch %>"/></td>
</tr>
<tr>
<td><label for="type">{% trans %}Type{% endtrans %}</label></td>
<td>
<select id="type">
<option <%= field.type == '' ? 'selected' : '' %> value=""></option>
<option <%= field.type == 'string' ? 'selected' : '' %> value="string">string</option>
<option <%= field.type == 'text' ? 'selected' : '' %> value="text">text</option>
<option <%= field.type == 'number' ? 'selected' : '' %> value="number">number</option>
<option <%= field.type == 'date' ? 'selected' : '' %> value="date">date</option>
</select>
</td>
</tr>
<tr>
<td><label for="vocabulary-type">{% trans %}Vocabulary type{% endtrans %}</label></td>
<td>
<select id="vocabulary-type">
<option <%= field['vocabulary-type'] == null ? 'selected' : '' %> value=''></option>
<% _.each(vocabularyTypes, function(vocab) { %>
<option <%= field['vocabulary-type'] == vocab.type ? 'selected' : '' %> value="<%= vocab.type %>"><%= vocab.name %></option>
<% }); %>
</select>
</td>
</tr>
<tr>
<td colspan="2">
<% if(field['vocabulary-type'] != null && field['vocabulary-type'] != '') { %>
<label for="vocabulary-restricted" class="checkbox">
<input id="vocabulary-restricted" type="checkbox" <%= field["vocabulary-restricted"] ? "checked='checked'" : "" %> />
{% trans %}Limited vocabulary{% endtrans %}
</label>
<% } %>
</td>
</tr>
<tr>
<td colspan="2">
<label for="business" class="checkbox">
<input id="business" type="checkbox" <%= field.business ? "checked='checked'" : "" %> />
{% trans %}Business Fields{% endtrans %}
</label>
</td>
</tr>
<tr>
<td><label for="separator">{% trans %}Separator{% endtrans %}</label></td>
<td><input id="separator" type="text" value="<%= field.separator %>" /></td>
</tr>
</table>
<h4>{% trans %}Display & action settings{% endtrans %}</h4>
<table>
<tr>
<td>
<label for="required" class="checkbox">
<input id="required" type="checkbox" <%= field.required ? "checked='checked'" : "" %> />
{% trans %}Mandatory{% endtrans %}
</label>
</td>
</tr>
<tr>
<td>
<label for="indexable" class="checkbox">
<input id="indexable" type="checkbox" <%= field.indexable ? "checked='checked'" : "" %> />
{% trans %}Indexable{% endtrans %}
</label>
</td>
</tr>
<tr>
<td>
<label for="readonly" class="checkbox">
<input id="readonly" type="checkbox" <%= field.readonly ? "checked='checked'" : "" %> />
{% trans %}Read-only{% endtrans %}
</label>
</td>
</tr>
<tr>
<td>
<label for="report" class="checkbox">
<input id="report" type="checkbox" <%= field.report ? "checked='checked'" : "" %> />
{% trans %}Report{% endtrans %}
</label>
</td>
</tr>
<tr>
<td><label for="thumbtitle">{% trans %}Display thumbnails{% endtrans %}</label></td>
<td>
<select id="thumbtitle">
<option value="1" <%= field.thumbtitle == "1" ? "selected" : "" %> >{% trans 'Tous' %}</option>
<option value="0" <%= field.thumbtitle == "0" ? "selected" : "" %> >{% trans 'Aucun' %}</option>
<option value="fr" <%= field.thumbtitle == "fr" ? "selected" : "" %> >{% trans 'Francais' %}</option>
<option value="nl" <%= field.thumbtitle == "nl" ? "selected" : "" %> >{% trans 'Dutch' %}</option>
<option value="de" <%= field.thumbtitle == "de" ? "selected" : "" %> >{% trans 'Allemand' %}</option>
<option value="en" <%= field.thumbtitle == "en" ? "selected" : "" %> >{% trans 'Anglais' %}</option>
<option value="ar" <%= field.thumbtitle == "ar" ? "selected" : "" %> >{% trans 'Arabe' %}</option>
</select>
</td>
</tr>
</table>
</div>
</div>
</script>
<script type="text/template" id="list_row_template">
<table>
<tr>
<td class="handle">
<i class="icon-move"></i>
</td>
<td rowspan="2" class="trigger-click">
<div class="field-name"><%= name %></div>
<div class="field-tag"><%= tag %></div>
</td>
<td rowspan="2" class="chip trigger-click">
<i class="icon-chevron-right"></i>
</td>
</tr>
<tr>
<td class="position">
<%= position %>
</td>
</tr>
</table>
</script>
<script type="text/template" id="dc_fields_template">
<select id="dces-element" class="input-block-level">
<option <%= field['dces-element'] == null ? 'selected' : '' %> value=''></option>
<% _.each(dces_elements, function(el) { %>
<option <%= field['dces-element'] == el.label ? 'selected' : '' %> value="<%= el.label %>">DC:<%= el.label %></option>
<% }); %>
</select>
</script>
<script type="text/template" id="field_error_template">
<% if(messages.length > 0) { %>
<div class="well well-small">
<i class="icon-exclamation-sign"></i> {% trans %}Current configuration contains some errors{% endtrans %}
</div>
<% } %>
</script>

View File

@@ -1,55 +0,0 @@
<form novalidate="" name="loginForm" method="POST" action="#">
<div class="row-fluid">
<div class="span12">
<label for="login" class="required">Login</label>
<table class="input-table">
<tbody><tr>
<td class="icon">
<i class="icon-envelope icon-white"></i>
</td>
<td class="input">
<input type="text" id="login" name="login" required="required" class="input-block-level">
</td>
</tr>
</tbody></table>
<div class="error-view"></div>
</div>
</div>
<div class="row-fluid">
<div class="span12">
<label for="password" class="required">Password</label>
<table class="input-table">
<tbody><tr>
<td class="icon">
<i class="icon-lock icon-white"></i>
</td>
<td class="input">
<input type="password" id="password" name="password" required="required" class="input-block-level">
</td>
</tr>
</tbody></table>
<div class="error-view"></div>
</div>
</div>
<div class="text-right">
<a class="forget-password-link" href="/login/forgot-password/">Forgot password?</a>
</div>
<div class="row-fluid">
<div class="span12">
<button type="submit" class="btn btn-success btn-trigger">
Connection
</button>
</div>
</div>
<div class="row-fluid">
<div class="span12">
<label for="remember-me" class="checkbox">
<input type="checkbox" id="remember-me" name="remember-me" checked="checked" value="1">
Remember me
</label>
<div class="error-view"></div>
</div>
</div>
<input type="hidden" id="redirect" name="redirect"><input type="hidden" id="_token" name="_token" value="76b1bdee87734050bb1ab237c162f1211eda0622">
</form>

View File

@@ -1,23 +0,0 @@
<script type="text/template" id="field_errors">
<div class="hidden-phone popover bottom field-error">
<div class="arrow"></div>
<div class="popover-content">
<table>
<tr>
<td style="width:35px;"><i class="icon-warning-sign icon-white"></i></td>
<td>
<% _.each(errors, function(error) { %>
<div><%= error.message %></div>
<% }); %>
</td>
</tr>
</table>
</div>
</div>
<span class="visible-phone text-error help-block help-block-error">
<% _.each(errors, function(error) { %>
<td> <%= error.message %></td>
<% }); %>
</span>
</script>

View File

@@ -14,6 +14,7 @@
require([ require([
'tests/baseTest', 'tests/baseTest',
'specs/admin/fields', 'specs/admin/fields',
'specs/admin/taskmanager',
'specs/login/home', 'specs/login/home',
'specs/models', 'specs/models',
'specs/validator' 'specs/validator'

View File

@@ -4,7 +4,6 @@ require.config({
specs: "tests/specs", specs: "tests/specs",
chai: "../assets/chai/chai", chai: "../assets/chai/chai",
fixtures: "../assets/js-fixtures/fixtures", fixtures: "../assets/js-fixtures/fixtures",
app: "apps/admin/fields/app",
jquery: "../assets/jquery/jquery", jquery: "../assets/jquery/jquery",
jqueryui: "../assets/jquery.ui/jquery-ui", jqueryui: "../assets/jquery.ui/jquery-ui",
underscore: "../assets/underscore-amd/underscore", underscore: "../assets/underscore-amd/underscore",

View File

@@ -2,7 +2,7 @@ define([
'chai', 'chai',
'fixtures', 'fixtures',
'jquery', 'jquery',
'app', 'apps/admin/fields/app',
'models/field', 'models/field',
'apps/admin/fields/collections/fields', 'apps/admin/fields/collections/fields',
'apps/admin/fields/collections/dcFields', 'apps/admin/fields/collections/dcFields',
@@ -20,13 +20,16 @@ define([
var assert = chai.assert; var assert = chai.assert;
var should = chai.should(); var should = chai.should();
// load fixtures in dom // Note: fixture are loaded into scripts/tests/fixtures directory using
// bin/developer phraseanet:regenerate-js-fixtures
fixtures.path = 'fixtures'; fixtures.path = 'fixtures';
$("body").append(fixtures.read('admin/fields/dom', 'admin/fields/templates')); $("body").append(fixtures.read('admin/fields/index.html', 'admin/fields/templates.html'));
var sbasId = 1; var sbasId = 1;
App.create(); App.create();
AdminFieldApp.languages = {"de":"Deutsch","en":"English","fr":"Francais","nl":"Dutch"};
describe("Admin field", function () { describe("Admin field", function () {
describe("Initialization", function () { describe("Initialization", function () {
it("should create a global variable", function () { it("should create a global variable", function () {

View File

@@ -0,0 +1,103 @@
define([
'chai',
'fixtures',
'jquery',
'apps/admin/tasks-manager/app',
'models/task',
'apps/admin/tasks-manager/collections/tasks',
'apps/admin/tasks-manager/views/ping',
'apps/admin/tasks-manager/views/task',
'apps/admin/tasks-manager/views/tasks'
], function (chai, fixtures, $, App, TaskModel, TaskCollection, PingView, TaskView, TasksView) {
var expect = chai.expect;
var assert = chai.assert;
var should = chai.should();
// Note: fixture are loaded into scripts/tests/fixtures directory using
// bin/developer phraseanet:regenerate-js-fixtures
fixtures.path = 'fixtures';
$("body").append(fixtures.read('admin/task-manager/templates.html', 'admin/task-manager/index.html'));
App.create();
describe("Admin task manager", function () {
describe("Initialization", function () {
it("should create a global variable", function () {
should.exist(TaskManagerApp);
});
});
describe("Views", function () {
describe("TaskView", function () {
beforeEach(function () {
this.view = new TaskView({
model: new TaskModel({
"name":"Task", "configuration":"start", "actual": "stopped", "id":1, "urls" : []
})
});
});
it("render() should return the view object", function () {
this.view.render().should.equal(this.view);
this.view.renderId().should.equal(this.view);
this.view.renderConfiguration().should.equal(this.view);
this.view.renderActual().should.equal(this.view);
this.view.renderPid().should.equal(this.view);
this.view.renderName().should.equal(this.view);
});
it("should render as a TR element", function () {
this.view.render().el.nodeName.should.equal("TR");
});
});
describe("Empty Tasks item views", function () {
beforeEach(function () {
this.collection = new TaskCollection([]);
this.view = new TasksView({
collection: this.collection,
el: AdminFieldApp.$tasksListView
});
});
it("should include list items for all models in collection", function () {
this.view.render();
this.view.$el.find("tr").length.should.equal(0);
});
});
describe("Tasks Item Views", function () {
beforeEach(function () {
this.collection = new TaskCollection([
{"name" : "task", "actual":"stopped", "configuration": "start", "urls" : []},
{"name" : "task2", "actual":"stopped", "configuration": "start", "urls" : []}
]);
this.view = new TasksView({
collection: this.collection,
el: AdminFieldApp.$tasksListView
});
});
it("render() should return the view object", function () {
this.view.render().should.equal(this.view);
});
it("should include list items for all models in collection", function () {
this.view.render();
this.view.$el.find("tr").length.should.equal(2);
});
});
describe("Ping View", function () {
beforeEach(function () {
this.view = new PingView();
});
it("render() should return the view object", function () {
this.view.render().should.equal(this.view);
});
});
});
});
});

View File

@@ -9,9 +9,10 @@ define([
var expect = chai.expect; var expect = chai.expect;
var assert = chai.assert; var assert = chai.assert;
var should = chai.should(); var should = chai.should();
// Note: fixture are loaded into scripts/tests/fixtures directory using
// bin/developer phraseanet:regenerate-js-fixtures
fixtures.path = 'fixtures'; fixtures.path = 'fixtures';
$("body").append(fixtures.read('home/login/form', 'home/login/templates')); $("body").append(fixtures.read('home/login/index.html', 'home/login/templates.html'));
describe("Login Home", function () { describe("Login Home", function () {
describe("Form View", function () { describe("Form View", function () {