diff --git a/backend/lib/Controller/AggregatorController.php b/backend/lib/Controller/AggregatorController.php index cc749b1..dd45e68 100644 --- a/backend/lib/Controller/AggregatorController.php +++ b/backend/lib/Controller/AggregatorController.php @@ -44,7 +44,7 @@ class AggregatorController extends EntityController { return $aggregator; } else { - throw new \Exception($identifier . ' is not a group uuid'); + throw new \Exception($identifier . ' is not a group'); } } diff --git a/backend/lib/Controller/ChannelController.php b/backend/lib/Controller/ChannelController.php index fa6dd75..6543603 100644 --- a/backend/lib/Controller/ChannelController.php +++ b/backend/lib/Controller/ChannelController.php @@ -44,7 +44,7 @@ class ChannelController extends EntityController { return $channel; } else { - throw new \Exception($identifier . ' is not a channel uuid'); + throw new \Exception($identifier . ' is not a channel'); } } diff --git a/backend/lib/View/JSON.php b/backend/lib/View/JSON.php index 0333b34..c1137d6 100644 --- a/backend/lib/View/JSON.php +++ b/backend/lib/View/JSON.php @@ -23,8 +23,8 @@ namespace Volkszaehler\View; +use Doctrine\ORM\Query\AST\Functions; use Volkszaehler\Interpreter; - use Volkszaehler\View\HTTP; use Volkszaehler\Util; use Volkszaehler\Model; @@ -67,7 +67,7 @@ class JSON extends View { $json = $this->json->encode((Util\Debug::isActivated()) ? JSON_PRETTY : 0); if ($this->padding) { - $json = 'if (self.' . $this->padding . ') { ' . $this->padding . '(' . $json . '); }'; + $json = 'if (' . $this->padding . ') { ' . $this->padding . '(' . $json . '); }'; } $this->response->setHeader('Content-type', 'application/json'); @@ -79,18 +79,13 @@ class JSON extends View { * * @param Model\Channel $channel */ - protected function addChannel(Model\Channel $channel) { - $this->json['channel'] = self::convertEntity($channel); - } - - /** - * Add aggregator to output queue - * - * @param Model\Aggregator $aggregator - * @param boolean $recursive - */ - protected function addAggregator(Model\Aggregator $aggregator, $recursive = FALSE) { - $this->json['group'] = self::convertAggregator($aggregator, $recursive); + protected function addEntity(Model\Entity $entity) { + if ($entity instanceof Model\Aggregator) { + $this->json['entity'] = self::convertAggregator($entity); + } + else { + $this->json['entity'] = self::convertEntity($entity); + } } /** @@ -198,12 +193,11 @@ class JSON extends View { $jsonAggregator = self::convertEntity($aggregator); foreach ($aggregator->getChildren() as $entity) { - if ($entity instanceof Model\Channel) { - $jsonAggregator['channels'][] = self::convertEntity($entity); + $jsonAggregator['children'][] = self::convertEntity($entity); } elseif ($entity instanceof Model\Aggregator) { - $jsonAggregator['groups'][] = self::convertAggregator($entity); + $jsonAggregator['children'][] = self::convertAggregator($entity); } } diff --git a/backend/lib/View/View.php b/backend/lib/View/View.php index 1d6c5db..fc909ce 100644 --- a/backend/lib/View/View.php +++ b/backend/lib/View/View.php @@ -110,11 +110,8 @@ abstract class View { if ($data instanceof Interpreter\InterpreterInterface) { $this->addData($data); } - elseif ($data instanceof Model\Channel) { - $this->addChannel($data); - } - elseif ($data instanceof Model\Aggregator) { - $this->addAggregator($data); + elseif ($data instanceof Model\Entity) { + $this->addEntity($data); } elseif ($data instanceof \Exception) { $this->addException($data); @@ -131,8 +128,7 @@ abstract class View { protected abstract function render(); protected abstract function addData(Interpreter\InterpreterInterface $data); - protected abstract function addChannel(Model\Channel $channel); - protected abstract function addAggregator(Model\Aggregator $aggregator); + protected abstract function addEntity(Model\Entity $entity); protected abstract function addException(\Exception $exception); protected abstract function addDebug(Util\Debug $debug); } diff --git a/frontend/images/add.png b/frontend/images/add.png new file mode 100644 index 0000000..6332fef Binary files /dev/null and b/frontend/images/add.png differ diff --git a/frontend/images/arrow_refresh.png b/frontend/images/arrow_refresh.png new file mode 100644 index 0000000..0de2656 Binary files /dev/null and b/frontend/images/arrow_refresh.png differ diff --git a/frontend/images/chart_curve.png b/frontend/images/chart_curve.png new file mode 100644 index 0000000..01e933a Binary files /dev/null and b/frontend/images/chart_curve.png differ diff --git a/frontend/images/chart_line.png b/frontend/images/chart_line.png new file mode 100644 index 0000000..85020f3 Binary files /dev/null and b/frontend/images/chart_line.png differ diff --git a/frontend/images/control_end_blue.png b/frontend/images/control_end_blue.png new file mode 100644 index 0000000..7207935 Binary files /dev/null and b/frontend/images/control_end_blue.png differ diff --git a/frontend/images/control_fastforward_blue.png b/frontend/images/control_fastforward_blue.png new file mode 100644 index 0000000..4a2f9d4 Binary files /dev/null and b/frontend/images/control_fastforward_blue.png differ diff --git a/frontend/images/control_rewind_blue.png b/frontend/images/control_rewind_blue.png new file mode 100644 index 0000000..15d1584 Binary files /dev/null and b/frontend/images/control_rewind_blue.png differ diff --git a/frontend/images/control_start_blue.png b/frontend/images/control_start_blue.png new file mode 100644 index 0000000..6f11fcb Binary files /dev/null and b/frontend/images/control_start_blue.png differ diff --git a/frontend/images/cookie.png b/frontend/images/cookie.png new file mode 100644 index 0000000..c84714b Binary files /dev/null and b/frontend/images/cookie.png differ diff --git a/frontend/images/delete.png b/frontend/images/delete.png new file mode 100644 index 0000000..08f2493 Binary files /dev/null and b/frontend/images/delete.png differ diff --git a/frontend/images/folder.png b/frontend/images/folder.png new file mode 100644 index 0000000..784e8fa Binary files /dev/null and b/frontend/images/folder.png differ diff --git a/frontend/images/server.png b/frontend/images/server.png new file mode 100644 index 0000000..720a237 Binary files /dev/null and b/frontend/images/server.png differ diff --git a/frontend/images/shading.png b/frontend/images/shading.png new file mode 100644 index 0000000..09275f9 Binary files /dev/null and b/frontend/images/shading.png differ diff --git a/frontend/index.html b/frontend/index.html index 37a1eb8..dc49af7 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -18,6 +18,7 @@ + @@ -29,38 +30,50 @@ -
+
- - - + + +
+ + +

Kanäle

- +
+
- - + +
UUIDTitleTitel Typ OperationenAnzeige
+
+

Optionen

- + + + +
+ diff --git a/frontend/javascripts/functions.js b/frontend/javascripts/functions.js index a11d311..095450b 100644 --- a/frontend/javascripts/functions.js +++ b/frontend/javascripts/functions.js @@ -32,9 +32,9 @@ /** * Refresh plot with new data */ -function refresh() { - if ($('[name=refresh]').attr('checked')) { - getData(); +function refreshWindow() { + if ($('input[name=refresh]').attr('checked')) { + loadData(); } } @@ -53,24 +53,25 @@ function moveWindow(mode) { myWindowEnd += delta; } - getData(); + loadData(); } -function getData() { - // load json data with given time window - $.getJSON(backendUrl + '/data/' + myUUID + '.json', { from: myWindowStart, to: myWindowEnd, tuples: 500 }, function(data){ - json = data; - showChart(); +//load json data with given time window +function loadData() { + eachRecursive(entities, function(entity, parent) { + if (entity.active && entity.type != 'group') { + $.getJSON(backendUrl + '/data/' + entity.uuid + '.json', { from: myWindowStart, to: myWindowEnd, tuples: tuples }, ajaxWait(function(json) { + entity.data = json.data[0]; // TODO filter for correct uuid + }, showChart, 'data')); + } }); - - return false; } function showChart() { var jqData = new Array(); - $.each(json.data, function(index, value) { - jqData.push(value.tuples); + eachRecursive(entities, function(entity, parent) { + jqData.push(entity.data.tuples); }); // TODO read docs @@ -86,11 +87,13 @@ function showChart() { */ /** - * Get all entity infomration from backend + * Get all entity information from backend */ -function loadEntities() { +function loadEntities(uuids) { $.each(uuids, function(index, value) { - $.getJSON(backendUrl + '/entity/' + value + '.json', ajaxWait(showEntities, 'enities')); + $.getJSON(backendUrl + '/entity/' + value + '.json', ajaxWait(function(json) { + entities.push(json.entity); + }, showEntities, 'information')); }); } @@ -98,72 +101,101 @@ function loadEntities() { * Create nested entity list * @param data */ -function showEntities(data) { +function showEntities() { $('#entities tbody').empty(); - $.each(data, function(index, value) { - var entity = (value.group) ? value.group : value.channel; + var i = 0; + + eachRecursive(entities, function(entity, parent) { + entity.active = true; // TODO active by default or via backend property? + entity.color = colors[i++%colors.length]; - showEntity(entity); + $('#entities tbody').append( + $('') + .addClass((parent) ? 'child-of-entity-' + parent.uuid : '') + .attr('id', 'entity-' + entity.uuid) + .append( + $('').append( + $('') + .addClass((entity.type == 'group') ? 'group' : 'channel') + .attr('title', entity.uuid) + .text(entity.title) + ) + ) + .append($('').text(entity.type)) + .append($('') // operations + .append($('') + .attr('type', 'image') + .attr('src', 'images/delete.png') + .attr('alt', 'delete') + .bind('click', entity, function(event) { alert('delete: ' + event.data.uuid); }) + ) + ) + .append($('') + .append($('
') + .css('background-color', entity.color) + .addClass('indicator') + .append($('') + .attr('type', 'checkbox') + .attr('checked', entity.active) + .bind('change', entity, function(event) { + event.data.active = $(this).attr('checked'); + loadData(); + }) + ) + ) + ) + ); }); - $('#entities').treeTable(); -} - -/** - * Create nested entity list (recursive) - * @param entity - * @param parent - */ -function showEntity(entity, parent) { - $('#entities tbody').append( - $('') - .attr('class', (parent) ? 'child-of-entity-' + parent.uuid : '') - .attr('id', 'entity-' + entity.uuid) - .append($('').text(entity.uuid)) - .append($('').text(entity.title)) - .append($('').text(entity.type)) - ); - - var entities = new Array(); - if (entity.channels) { - $.merge(entities, entity.channels); - } - if (entity.groups) { - $.merge(entities, entity.groups); - } + // http://ludo.cubicphuse.nl/jquery-plugins/treeTable/doc/index.html + $('#entities table').treeTable(); - $.each(entities, function(index, value) { - showEntity(value, entity); - }); + // load data and show plot + loadData(); } /* * General helper functions */ -function ajaxWait(callback, identifier) { - if (!identifier) { - var identifier = 0; - } - - if (!ajaxWait.counter || !ajaxWait.data) { - ajaxWait.counter = new Array(); - ajaxWait.data = new Array(); - } - - if (!ajaxWait.counter[identifier] || !ajaxWait.data[identifier]) { - ajaxWait.counter[identifier] = 0; - ajaxWait.data[identifier] = new Array; - } +function ajaxWait(callback, finished, identifier) { + if (!ajaxWait.counter) { ajaxWait.counter = new Array(); } + if (!ajaxWait.counter[identifier]) { ajaxWait.counter[identifier] = 0; } ajaxWait.counter[identifier]++; return function (data, textStatus) { - ajaxWait.data[identifier].push(data); + callback(data, textStatus); if (!--ajaxWait.counter[identifier]) { - callback(ajaxWait.data[identifier]); + finished(); } }; -} \ No newline at end of file +} + +function eachRecursive(array, callback, parent) { + $.each(array, function(index, value) { + callback(value, parent); + + if (value.children) { // has children? + eachRecursive(value.children, callback, value); // call recursive + } + }); +} + +Array.prototype.contains = function(needle) { + for (var i=0; i