Skip to content

Commit

Permalink
text variables in report header (e.g. %lastUpdate%) #145
Browse files Browse the repository at this point in the history
  • Loading branch information
Rello committed Jul 7, 2021
1 parent 990f35c commit a2e3d3d
Show file tree
Hide file tree
Showing 16 changed files with 200 additions and 48 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## 3.6.0 - 2021-07-xx

### Added

- text variables in report header (e.g. %lastUpdate%) [#145](https://github.com/rello/analytics/issues/145)
- Enable receiver of share to unshare [#171](https://github.com/rello/analytics/issues/171)
- sorting of external/unstructured data [#175](https://github.com/rello/analytics/issues/175)

Expand Down
6 changes: 3 additions & 3 deletions js/advanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ OCA.Analytics.Advanced.Dataload = {
'option': option,
},
success: function () {
OCA.Analytics.UI.notification('success', t('analytics', 'Saved'));
OCA.Analytics.Notification.notification('success', t('analytics', 'Saved'));
OCA.Analytics.Advanced.Dataload.dataloadArray.find(x => x.id === parseInt(dataloadId))['schedule'] = document.getElementById('dataloadSchedule').value;
OCA.Analytics.Advanced.Dataload.dataloadArray.find(x => x.id === parseInt(dataloadId))['name'] = document.getElementById('dataloadName').value;
OCA.Analytics.Advanced.Dataload.dataloadArray.find(x => x.id === parseInt(dataloadId))['option'] = option;
Expand Down Expand Up @@ -229,7 +229,7 @@ OCA.Analytics.Advanced.Dataload = {
);
} else {
mode = 'execute';
OCA.Analytics.UI.notification('success', t('analytics', 'Load started'));
OCA.Analytics.Notification.notification('success', t('analytics', 'Load started'));
}

$.ajax({
Expand All @@ -252,7 +252,7 @@ OCA.Analytics.Advanced.Dataload = {
} else {
messageType = 'error';
}
OCA.Analytics.UI.notification(messageType, data.insert + t('analytics', ' records inserted, ') + data.update + t('analytics', ' records updated, ') + data.error + t('analytics', ' errors'));
OCA.Analytics.Notification.notification(messageType, data.insert + t('analytics', ' records inserted, ') + data.update + t('analytics', ' records updated, ') + data.error + t('analytics', ' errors'));
}
}
});
Expand Down
16 changes: 1 addition & 15 deletions js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,20 +520,6 @@ OCA.Analytics.UI = {
OCA.Analytics.Filter.refreshFilterVisualisation();
},

notification: function (type, message) {
if (parseInt(OC.config.versionstring.substr(0, 2)) >= 17) {
if (type === 'success') {
OCP.Toast.success(message)
} else if (type === 'error') {
OCP.Toast.error(message)
} else {
OCP.Toast.info(message)
}
} else {
OC.Notification.showTemporary(message);
}
},

showElement: function (element) {
if (document.getElementById(element)) {
document.getElementById(element).hidden = false;
Expand Down Expand Up @@ -812,7 +798,7 @@ OCA.Analytics.Backend = {
} else {
OCA.Analytics.UI.showElement('noDataContainer');
if (parseInt(data.error) !== 0) {
OCA.Analytics.UI.notification('error', data.error);
OCA.Analytics.Notification.notification('error', data.error);
}
}
OCA.Analytics.UI.buildReportOptions();
Expand Down
32 changes: 22 additions & 10 deletions js/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ OCA.Analytics.Sidebar.Dataset = {
document.getElementById('sidebarDatasetName').addEventListener('change', OCA.Analytics.Sidebar.Dataset.indicateMetadataChanged);
document.getElementById('sidebarDatasetParent').addEventListener('change', OCA.Analytics.Sidebar.Dataset.indicateMetadataChanged);

document.getElementById('sidebarDatasetNameHint').addEventListener('click', OCA.Analytics.Sidebar.Dataset.handleNameHint);
document.getElementById('sidebarDatasetSubheaderHint').addEventListener('click', OCA.Analytics.Sidebar.Dataset.handleNameHint);

// get all the options for a datasource
OCA.Analytics.Sidebar.Dataset.handleDatasourceChange();

Expand Down Expand Up @@ -315,6 +318,15 @@ OCA.Analytics.Sidebar.Dataset = {
1);
},

handleNameHint: function () {
let text = t('analytics', 'Text variables can be used in title and subheader.<br>They are replaced when the report is executed.') +
'<br><br>' +
'%lastUpdate%<br>' +
'%currentDate%<br>' +
'%owner%';
OCA.Analytics.Notification.dialog(t('analytics', 'Text variables'), text, 'info');
},

buildGroupingDropdown: function () {
let tableParent = document.getElementById('sidebarDatasetParent');
tableParent.innerHTML = '';
Expand Down Expand Up @@ -566,7 +578,7 @@ OCA.Analytics.Sidebar.Share = {
textArea.select();
document.execCommand('copy');
document.body.removeChild(textArea);
OCA.Analytics.UI.notification('success', t('analytics', 'Link copied'));
OCA.Analytics.Notification.notification('success', t('analytics', 'Link copied'));
},

showShareMenu: function (evt) {
Expand Down Expand Up @@ -751,7 +763,7 @@ OCA.Analytics.Sidebar.Backend = {
OCA.Analytics.UI.resetContentArea();
OCA.Analytics.Backend.getData();
} else {
OCA.Analytics.UI.notification('success', t('analytics', 'Saved'));
OCA.Analytics.Notification.notification('success', t('analytics', 'Saved'));
}
}
}
Expand All @@ -775,13 +787,13 @@ OCA.Analytics.Sidebar.Backend = {
button.classList.remove('loading');
button.disabled = false;
if (data.error === 0) {
OCA.Analytics.UI.notification('success', data.insert + t('analytics', ' records inserted, ') + data.update + t('analytics', ' records updated'));
OCA.Analytics.Notification.notification('success', data.insert + t('analytics', ' records inserted, ') + data.update + t('analytics', ' records updated'));
if (document.getElementById('advanced').value === 'false') {
OCA.Analytics.UI.resetContentArea();
OCA.Analytics.Backend.getData();
}
} else {
OCA.Analytics.UI.notification('error', data.error);
OCA.Analytics.Notification.notification('error', data.error);
}
}
});
Expand Down Expand Up @@ -857,17 +869,17 @@ OCA.Analytics.Sidebar.Backend = {
button.classList.remove('loading');
button.disabled = false;
if (data.error === 0) {
OCA.Analytics.UI.notification('success', data.insert + t('analytics', ' records inserted, ') + data.update + t('analytics', ' records updated'));
OCA.Analytics.Notification.notification('success', data.insert + t('analytics', ' records inserted, ') + data.update + t('analytics', ' records updated'));
if (document.getElementById('advanced').value === 'false') {
OCA.Analytics.UI.resetContentArea();
OCA.Analytics.Backend.getData();
}
} else {
OCA.Analytics.UI.notification('error', data.error);
OCA.Analytics.Notification.notification('error', data.error);
}
},
error: function () {
OCA.Analytics.UI.notification('error', t('analytics', 'Technical error. Please check the logs'));
OCA.Analytics.Notification.notification('error', t('analytics', 'Technical error. Please check the logs'));
button.classList.remove('loading');
button.disabled = false;
}
Expand All @@ -891,17 +903,17 @@ OCA.Analytics.Sidebar.Backend = {
button.classList.remove('loading');
button.disabled = false;
if (data.error === 0) {
OCA.Analytics.UI.notification('success', data.insert + t('analytics', ' records inserted, ') + data.update + t('analytics', ' records updated'));
OCA.Analytics.Notification.notification('success', data.insert + t('analytics', ' records inserted, ') + data.update + t('analytics', ' records updated'));
if (document.getElementById('advanced').value === 'false') {
OCA.Analytics.UI.resetContentArea();
OCA.Analytics.Backend.getData();
}
} else {
OCA.Analytics.UI.notification('error', data.error);
OCA.Analytics.Notification.notification('error', data.error);
}
},
error: function () {
OCA.Analytics.UI.notification('error', t('analytics', 'Technical error. Please check the logs'));
OCA.Analytics.Notification.notification('error', t('analytics', 'Technical error. Please check the logs'));
button.classList.remove('loading');
button.disabled = false;
}
Expand Down
33 changes: 32 additions & 1 deletion js/userGuidance.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,37 @@ OCA.Analytics.WhatsNew = {

div.appendChild(list)
document.body.appendChild(div)
}
},
}
/**
* @namespace OCA.Analytics.Notification
*/
OCA.Analytics.Notification = {
dialog: function (title, text, type) {
OC.dialogs.message(
text,
title,
type,
OC.dialogs.OK_BUTTON,
function () {
},
true,
true
);
},

notification: function (type, message) {
if (parseInt(OC.config.versionstring.substr(0, 2)) >= 17) {
if (type === 'success') {
OCP.Toast.success(message)
} else if (type === 'error') {
OCP.Toast.error(message)
} else {
OCP.Toast.info(message)
}
} else {
OC.Notification.showTemporary(message);
}
},

}
24 changes: 13 additions & 11 deletions l10n/de.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,18 @@ OC.L10N.register(
'Primary': 'Primär',
'Secondary': 'Sekundär',
'Line': 'Linie',
'Column': 'Spalte',
'Add a report to the favorites to be shown here': 'Füge einen Bericht den Favoriten hinzu, um ihn hier zu sehen',
'Remove from favorites': 'Aus Favoriten entfernen',
'Add to favorites': 'Zu Favoriten hinzufügen',
'This report does not have any dataloads. <br>Choose a datasource from the dropdown and press "+"': 'Dieser Bericht besitzt keine Datenladungen. <br>Wähle eine Datenquelle aus dem Dropdown und drücke "+"',
'Choose a dataload from the list to change its settings': 'Wähle eine Datenladung aus der Liste um die Einstellungen zu ändern',
'Overview': 'Überblick',
'Drilldown': 'Aufriss',
'Datasource simulation': 'Datasource simulieren',
'Link copied': 'Link kopiert',
'Bar': 'Balken'
'Column': 'Spalte',
'Add a report to the favorites to be shown here': 'Füge einen Bericht den Favoriten hinzu, um ihn hier zu sehen',
'Remove from favorites': 'Aus Favoriten entfernen',
'Add to favorites': 'Zu Favoriten hinzufügen',
'This report does not have any dataloads. <br>Choose a datasource from the dropdown and press "+"': 'Dieser Bericht besitzt keine Datenladungen. <br>Wähle eine Datenquelle aus dem Dropdown und drücke "+"',
'Choose a dataload from the list to change its settings': 'Wähle eine Datenladung aus der Liste um die Einstellungen zu ändern',
'Overview': 'Überblick',
'Drilldown': 'Aufriss',
'Datasource simulation': 'Datasource simulieren',
'Link copied': 'Link kopiert',
'Bar': 'Balken',
'Text variables': 'Text Variablen',
'Text variables can be used in title and subheader.<br>They are replaced when the report is executed.': 'Text Variablen können im Berichtsnamen oder der Beschreibung verwendet werden.<br>Sie werden ersetzt, wenn der Bericht ausgeführt wird.'
},
'');
5 changes: 4 additions & 1 deletion l10n/de_DE.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ OC.L10N.register(
'Overview': 'Überblick',
'Drilldown': 'Aufriss',
'Datasource simulation': 'Datasource simulieren',
'Link copied': 'Link kopiert'
'Link copied': 'Link kopiert',
'Bar': 'Balken',
'Text variables': 'Text Variablen',
'Text variables can be used in title and subheader.<br>They are replaced when the report is executed.': 'Text Variablen können im Berichtsnamen oder der Beschreibung verwendet werden.<br>Sie werden ersetzt, wenn der Bericht ausgeführt wird.'
},
'');
5 changes: 4 additions & 1 deletion l10n/fr.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ OC.L10N.register(
'Datasource simulation': 'Simulation d\'une source de données',
'Datasource options': 'Options de la source de données',
'External URL': 'URL externe',
'Link copied': 'Lien copié'
'Link copied': 'Lien copié',
'Bar': 'Bar',
'Text variables': 'Text variables',
'Text variables can be used in title and subheader.<br>They are replaced when the report is executed.': 'Text variables can be used in title and subheader.<br>They are replaced when the report is executed.'
},
'');
5 changes: 4 additions & 1 deletion l10n/ru.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ OC.L10N.register(
'Overview': 'Обзор',
'Drilldown': 'Детализация',
'Datasource simulation': 'Симуляция источника данных',
'Link copied': 'Ссылка скопирована'
'Link copied': 'Ссылка скопирована',
'Bar': 'Bar',
'Text variables': 'Text variables',
'Text variables can be used in title and subheader.<br>They are replaced when the report is executed.': 'Text variables can be used in title and subheader.<br>They are replaced when the report is executed.'
},
'');
5 changes: 4 additions & 1 deletion l10n/ru_RU.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ OC.L10N.register(
'Overview': 'Обзор',
'Drilldown': 'Детализация',
'Datasource simulation': 'Симуляция источника данных',
'Link copied': 'Ссылка скопирована'
'Link copied': 'Ссылка скопирована',
'Bar': 'Bar',
'Text variables': 'Text variables',
'Text variables can be used in title and subheader.<br>They are replaced when the report is executed.': 'Text variables can be used in title and subheader.<br>They are replaced when the report is executed.'
},
'');
2 changes: 1 addition & 1 deletion lib/Controller/DatasetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function create($file = '')
*/
public function read(int $datasetId)
{
return $this->DatasetService->getOwnDataset($datasetId);
return $this->DatasetService->read($datasetId);
}

/**
Expand Down
30 changes: 30 additions & 0 deletions lib/Db/DatasetMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,36 @@ public function search($searchString)
return $result;
}

/**
* get the newest timestamp of the data of a dataset
* @param $datasetId
* @return int
*/
public function getLastUpdate($datasetId)
{
$sql = $this->db->getQueryBuilder();
$sql->from('analytics_facts')
->select($sql->func()->max('timestamp'))
->where($sql->expr()->eq('dataset', $sql->createNamedParameter($datasetId)));
$result = (int)$sql->execute()->fetchOne();
return $result;
}

/**
* get the report owner
* @param $datasetId
* @return int
*/
public function getOwner($datasetId)
{
$sql = $this->db->getQueryBuilder();
$sql->from(self::TABLE_NAME)
->select('user_id')
->where($sql->expr()->eq('id', $sql->createNamedParameter($datasetId)));
$result = (string)$sql->execute()->fetchOne();
return $result;
}

/**
* truncates fiels do DB-field size
*
Expand Down
13 changes: 11 additions & 2 deletions lib/Service/DatasetService.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class DatasetService
private $DataloadMapper;
private $ActivityManager;
private $rootFolder;
private $VariableService;

public function __construct(
$userId,
Expand All @@ -45,7 +46,8 @@ public function __construct(
ThresholdService $ThresholdService,
DataloadMapper $DataloadMapper,
ActivityManager $ActivityManager,
IRootFolder $rootFolder
IRootFolder $rootFolder,
VariableService $VariableService
)
{
$this->userId = $userId;
Expand All @@ -58,6 +60,7 @@ public function __construct(
$this->DataloadMapper = $DataloadMapper;
$this->ActivityManager = $ActivityManager;
$this->rootFolder = $rootFolder;
$this->VariableService = $VariableService;
}

/**
Expand Down Expand Up @@ -101,6 +104,7 @@ public function index()
$hasTag = 1;
}
$ownDataset['favorite'] = $hasTag;
$ownDataset = $this->VariableService->replaceTextVariables($ownDataset);
}

return new DataResponse($ownDatasets);
Expand All @@ -114,7 +118,11 @@ public function index()
*/
public function read(int $datasetId)
{
return $this->getOwnDataset($datasetId);
$ownDataset = $this->DatasetMapper->read($datasetId);
if (!empty($ownDataset)) {
$ownDataset['permissions'] = \OCP\Constants::PERMISSION_UPDATE;
}
return $ownDataset;
}

/**
Expand All @@ -129,6 +137,7 @@ public function getOwnDataset(int $datasetId, string $user_id = null)
$ownDataset = $this->DatasetMapper->read($datasetId, $user_id);
if (!empty($ownDataset)) {
$ownDataset['permissions'] = \OCP\Constants::PERMISSION_UPDATE;
$ownDataset = $this->VariableService->replaceTextVariables($ownDataset);
}
return $ownDataset;
}
Expand Down
Loading

0 comments on commit a2e3d3d

Please sign in to comment.