From cba370634f521d9bd186a47378299a1d17aa0e69 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 21 Jul 2016 10:51:42 +0200 Subject: [PATCH] Add a simple Admin UI to manage systemtags --- apps/systemtags/admin.php | 23 +++ apps/systemtags/appinfo/app.php | 3 + apps/systemtags/appinfo/info.xml | 2 +- apps/systemtags/js/admin.js | 164 ++++++++++++++++++++ apps/systemtags/lib/AppInfo/Application.php | 37 +++++ apps/systemtags/templates/admin.php | 59 +++++++ 6 files changed, 287 insertions(+), 1 deletion(-) create mode 100644 apps/systemtags/admin.php create mode 100644 apps/systemtags/js/admin.js create mode 100644 apps/systemtags/lib/AppInfo/Application.php create mode 100644 apps/systemtags/templates/admin.php diff --git a/apps/systemtags/admin.php b/apps/systemtags/admin.php new file mode 100644 index 0000000000..45ea577e8a --- /dev/null +++ b/apps/systemtags/admin.php @@ -0,0 +1,23 @@ + + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +$template = new \OCP\Template('systemtags', 'admin'); +return $template->fetchPage(); diff --git a/apps/systemtags/appinfo/app.php b/apps/systemtags/appinfo/app.php index af91e5fdbc..5a365c4ef1 100644 --- a/apps/systemtags/appinfo/app.php +++ b/apps/systemtags/appinfo/app.php @@ -78,6 +78,9 @@ $mapperListener = function(MapperEvent $event) use ($activityManager) { $eventDispatcher->addListener(MapperEvent::EVENT_ASSIGN, $mapperListener); $eventDispatcher->addListener(MapperEvent::EVENT_UNASSIGN, $mapperListener); +$app = new \OCA\SystemTags\AppInfo\Application(); +$app->registerAdminPage(); + $l = \OC::$server->getL10N('systemtags'); \OCA\Files\App::getNavigationManager()->add( diff --git a/apps/systemtags/appinfo/info.xml b/apps/systemtags/appinfo/info.xml index b593b1134b..4e0a736c57 100644 --- a/apps/systemtags/appinfo/info.xml +++ b/apps/systemtags/appinfo/info.xml @@ -5,7 +5,7 @@ Collaborative tagging functionality which shares tags among users. Great for teams. (If you are a provider with a multi-tenancy installation, it is advised to deactivate this app as tags are shared.) AGPL - Vincent Petry + Vincent Petry, Joas Schilling 0.3.0 diff --git a/apps/systemtags/js/admin.js b/apps/systemtags/js/admin.js new file mode 100644 index 0000000000..ed21f82f3b --- /dev/null +++ b/apps/systemtags/js/admin.js @@ -0,0 +1,164 @@ +/** + * @copyright Copyright (c) 2016 Joas Schilling + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +(function() { + if (!OCA.SystemTags) { + /** + * @namespace + */ + OCA.SystemTags = {}; + } + + OCA.SystemTags.Admin = { + + collection: null, + + init: function() { + var self = this; + + this.collection = OC.SystemTags.collection; + this.collection.fetch({ + success: function() { + $('#systemtag').select2(_.extend(self.select2)); + } + }); + + $('#systemtag_submit').on('click', _.bind(this._onClickSubmit, this)); + $('#systemtag_delete').on('click', _.bind(this._onClickDelete, this)); + $('#systemtag_reset').on('click', _.bind(this._onClickReset, this)); + }, + + /** + * Selecting a systemtag in select2 + * + * @param {OC.SystemTags.SystemTagModel} tag + */ + onSelectTag: function (tag) { + var level = 0; + if (tag.get('userVisible')) { + level += 2; + if (tag.get('userAssignable')) { + level += 1; + } + } + + $('#systemtag_name').val(tag.get('name')); + $('#systemtag_level').val(level); + + this._prepareForm(tag.get('id')); + }, + + /** + * Clicking the "Create"/"Update" button + */ + _onClickSubmit: function () { + var level = parseInt($('#systemtag_level').val(), 10), + tagId = $('#systemtags').attr('data-systemtag-id'); + var data = { + name: $('#systemtag_name').val(), + userVisible: level === 2 || level === 3, + userAssignable: level === 3 + }; + + if (tagId) { + var model = this.collection.get(tagId); + model.save(data); + } else { + this.collection.create(data); + } + + this._onClickReset(); + }, + + /** + * Clicking the "Delete" button + */ + _onClickDelete: function () { + var tagId = $('#systemtags').attr('data-systemtag-id'); + var model = this.collection.get(tagId); + model.destroy(); + + this._onClickReset(); + }, + + /** + * Clicking the "Reset" button + */ + _onClickReset: function () { + $('#systemtag_name').val(''); + $('#systemtag_level').val(3); + this._prepareForm(0); + }, + + /** + * Prepare the form for create/update + * + * @param {int} tagId + */ + _prepareForm: function (tagId) { + if (tagId > 0) { + $('#systemtags').attr('data-systemtag-id', tagId); + $('#systemtag_delete').removeClass('hidden'); + $('#systemtag_submit').val(t('systemtags_manager', 'Update')); + } else { + $('#systemtag').select2('val', ''); + $('#systemtags').attr('data-systemtag-id', ''); + $('#systemtag_delete').addClass('hidden'); + $('#systemtag_submit').val(t('systemtags_manager', 'Create')); + } + }, + + /** + * Select2 options for the SystemTag dropdown + */ + select2: { + allowClear: false, + multiple: false, + placeholder: t('systemtags_manager', 'Select tag…'), + query: _.debounce(function(query) { + query.callback({ + results: OCA.SystemTags.Admin.collection.filterByName(query.term) + }); + }, 100, true), + id: function(element) { + return element; + }, + initSelection: function(element, callback) { + var selection = ($(element).val() || []).split('|').sort(); + callback(selection); + }, + formatResult: function (tag) { + return OC.SystemTags.getDescriptiveTag(tag); + }, + formatSelection: function (tag) { + OCA.SystemTags.Admin.onSelectTag(tag); + return OC.SystemTags.getDescriptiveTag(tag); + }, + escapeMarkup: function(m) { + return m; + } + } + }; +})(); + +$(document).ready(function() { + OCA.SystemTags.Admin.init(); +}); + diff --git a/apps/systemtags/lib/AppInfo/Application.php b/apps/systemtags/lib/AppInfo/Application.php new file mode 100644 index 0000000000..7cd49d6424 --- /dev/null +++ b/apps/systemtags/lib/AppInfo/Application.php @@ -0,0 +1,37 @@ + + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCA\SystemTags\AppInfo; + +use OCP\AppFramework\App; + +class Application extends App { + public function __construct() { + parent::__construct('systemtags'); + } + + /** + * Register admin settings + */ + public function registerAdminPage() { + \OCP\App::registerAdmin($this->getContainer()->getAppName(), 'admin'); + } +} diff --git a/apps/systemtags/templates/admin.php b/apps/systemtags/templates/admin.php new file mode 100644 index 0000000000..883e998ed6 --- /dev/null +++ b/apps/systemtags/templates/admin.php @@ -0,0 +1,59 @@ + + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +vendor_script('core', 'select2/select2'); +vendor_style('core', 'select2/select2'); +script('core', [ + 'oc-backbone-webdav', + 'systemtags/systemtags', + 'systemtags/systemtagmodel', + 'systemtags/systemtagscollection', +]); + +script('systemtags', 'admin'); + +/** @var \OCP\IL10N $l */ +?> + +
+

t('Collaborative tags')); ?>

+ + + +

+ + + + + +
+ + + + + +