diff --git a/css/dashboard.scss b/css/dashboard.scss index 3e52359b..09612b97 100644 --- a/css/dashboard.scss +++ b/css/dashboard.scss @@ -6,4 +6,36 @@ * * @author Marcel Scherello * @copyright 2020 Marcel Scherello - */ \ No newline at end of file + */ + + .icon-analytics { + background-image: url(./../../apps/analytics/img/app-dark.svg); + } + + body.dark .icon-analytics { + background-image: url(./../../apps/analyticsimg/app.svg); + } + + // Dashboard Widget Section + + .analyticsWidgetItem { + padding: 10px; + border-radius: 9px; + margin-bottom: 10px; + background-color: white; + height: 60px; + } + + .analyticsWidgetReport { + } + + .analyticsWidgetSmall { + text-align: right; + font-size: x-small; + line-height: 10px; + } + .analyticsWidgetValue { + text-align: right; + line-height: 30px; + font-size: x-large; + } diff --git a/js/dashboard.js b/js/dashboard.js index 3eefc488..2f4d4b29 100644 --- a/js/dashboard.js +++ b/js/dashboard.js @@ -11,7 +11,111 @@ 'use strict'; document.addEventListener('DOMContentLoaded', function () { - alert('test'); - OCA.Dashboard.register('github', (el, {widget}) => { - }) -}) \ No newline at end of file + + OCA.Dashboard.register('analytics', (el) => { + el.innerHTML = ''; + }); + OCA.Analytics.Dashboard.getData(20); + OCA.Analytics.Dashboard.getData(155); + OCA.Analytics.Dashboard.getData(103); + +}) + +if (!OCA.Analytics) { + /** + * @namespace + */ + OCA.Analytics = {}; +} +/** + * @namespace OCA.Analytics.Dashboard + */ +OCA.Analytics.Dashboard = { + getData: function (datasetId) { + const url = OC.generateUrl('apps/analytics/data/' + datasetId, true); + + let xhr = new XMLHttpRequest(); + xhr.open('GET', url); + xhr.setRequestHeader('requesttoken', OC.requestToken); + xhr.setRequestHeader('OCS-APIREQUEST', 'true'); + + xhr.onreadystatechange = function () { + if (xhr.readyState === 4) { + let jsondata = JSON.parse(xhr.response); + OCA.Analytics.Dashboard.createWidgetContent(jsondata); + } + }; + xhr.send(); + }, + + createWidgetContent: function (jsondata) { + let report = jsondata['options']['name']; + let subheader = jsondata['options']['subheader']; + let data = jsondata['data'][jsondata['data'].length - 1]; + let kpi = data[0]; + let value = data[data.length - 1]; + + let li = OCA.Analytics.Dashboard.buildWidgetKpiRow(report, kpi, value, jsondata.thresholds); + document.getElementById('ilAnalyticsFavorites').insertAdjacentHTML('afterend', li); + }, + + buildWidgetKpiRow: function (report, kpi, value, thresholds) { + let thresholdColor = OCA.Analytics.Dashboard.validateThreshold(kpi, value, thresholds) + return `
  • +
    +
    +
    ${report}
    +
    +
    +
    +
    +
    ${parseFloat(value)}
    +
    ${kpi}
    +
    +
    +
  • `; + }, + + validateThreshold: function (kpi, value, thresholds) { + const operators = { + '=': function (a, b) { + return a === b + }, + '<': function (a, b) { + return a < b + }, + '>': function (a, b) { + return a > b + }, + '<=': function (a, b) { + return a <= b + }, + '>=': function (a, b) { + return a >= b + }, + '!=': function (a, b) { + return a !== b + }, + }; + let thresholdColor; + + thresholds = thresholds.filter(p => p.dimension1 === kpi || p.dimension1 === '*'); + + for (let threshold of thresholds) { + const comparison = operators[threshold['option']](parseFloat(value), parseFloat(threshold['value'])); + threshold['severity'] = parseInt(threshold['severity']); + if (comparison === true) { + if (threshold['severity'] === 2) { + thresholdColor = 'style="color: red;"'; + } else if (threshold['severity'] === 3) { + thresholdColor = 'style="color: orange;"'; + } else if (threshold['severity'] === 4) { + thresholdColor = 'style="color: green;"'; + } + } + } + + return thresholdColor; + }, + +} \ No newline at end of file diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 4e272613..3cf6ef21 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -16,7 +16,7 @@ use OCA\Analytics\Notification\Notifier; use OCP\AppFramework\App; use OCP\AppFramework\QueryException; -use OCP\Dashboard\RegisterPanelEvent; +use OCP\Dashboard\RegisterWidgetEvent; use OCP\EventDispatcher\IEventDispatcher; use OCP\Util; @@ -33,9 +33,9 @@ public function __construct(array $urlParams = []) if ($version >= 20) { /** @var IEventDispatcher $dispatcher */ $dispatcher = $container->getServer()->query(IEventDispatcher::class); - $dispatcher->addListener(RegisterPanelEvent::class, function (RegisterPanelEvent $event) use ($container) { + $dispatcher->addListener(RegisterWidgetEvent::class, function (RegisterWidgetEvent $event) use ($container) { // \OCP\Util::addScript('analytics', 'dashboard'); - $event->registerPanel(Widget::class); + $event->registerWidget(Widget::class); }); } diff --git a/lib/Dashboard/Widget.php b/lib/Dashboard/Widget.php index a2e36819..0d4d91e4 100644 --- a/lib/Dashboard/Widget.php +++ b/lib/Dashboard/Widget.php @@ -11,21 +11,25 @@ namespace OCA\Analytics\Dashboard; -use OCP\Dashboard\IPanel; use OCP\Dashboard\IWidget; use OCP\IL10N; +use OCP\IURLGenerator; use OCP\Util; -class Widget implements IPanel +class Widget implements IWidget { + /** @var IURLGenerator */ + private $url; /** @var IL10N */ private $l10n; public function __construct( + IURLGenerator $url, IL10N $l10n ) { + $this->url = $url; $this->l10n = $l10n; } @@ -58,7 +62,7 @@ public function getOrder(): int */ public function getIconClass(): string { - return 'icon-github'; + return 'icon-analytics'; } /** @@ -66,7 +70,7 @@ public function getIconClass(): string */ public function getUrl(): ?string { - return \OC::$server->getURLGenerator()->linkToRoute('settings.PersonalSettings.index', ['section' => 'linked-accounts']); + return $this->url->linkToRouteAbsolute('analytics.Page.main'); } /** diff --git a/lib/Datasource/GithubService.php b/lib/Datasource/GithubService.php index 92143395..c8d337a8 100644 --- a/lib/Datasource/GithubService.php +++ b/lib/Datasource/GithubService.php @@ -71,6 +71,10 @@ public function read($option) $header[0] = 'Version'; $header[1] = 'Count'; + + usort($data, function ($a, $b) { + return $a[0] <=> $b[0]; + }); return [ 'header' => $header, 'data' => $data, diff --git a/templates/part.templates.php b/templates/part.templates.php index ab257be8..45d6a9b1 100644 --- a/templates/part.templates.php +++ b/templates/part.templates.php @@ -199,9 +199,9 @@
    -
    t('Value')); ?>
    -
    +
    t('Severity')); ?>