Skip to content

Commit

Permalink
Add a simple Admin UI to manage systemtags
Browse files Browse the repository at this point in the history
  • Loading branch information
nickvergessen committed Jul 21, 2016
1 parent dc5608d commit 14cf786
Show file tree
Hide file tree
Showing 6 changed files with 272 additions and 3 deletions.
23 changes: 23 additions & 0 deletions apps/systemtags/admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
*
* @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 <http://www.gnu.org/licenses/>.
*
*/

$template = new \OCP\Template('systemtags', 'admin');
return $template->fetchPage();
6 changes: 5 additions & 1 deletion apps/systemtags/appinfo/app.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php
/**
* @author Joas Schilling <nickvergessen@owncloud.com>
* @author Joas Schilling <coding@schilljs.com>
* @author Vincent Petry <pvince81@owncloud.com>
*
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
* @copyright Copyright (c) 2016, ownCloud, Inc.
* @license AGPL-3.0
*
Expand Down Expand Up @@ -77,6 +78,9 @@ function() {
$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(
Expand Down
4 changes: 2 additions & 2 deletions apps/systemtags/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<description>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.)</description>
<licence>AGPL</licence>
<author>Vincent Petry</author>
<author>Vincent Petry, Joas Schilling</author>
<default_enable/>
<version>0.3.0</version>
<version>1.0.0</version>
<dependencies>
<owncloud min-version="9.1" max-version="9.1" />
</dependencies>
Expand Down
146 changes: 146 additions & 0 deletions apps/systemtags/js/admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
(function() {
if (!OCA.SystemTags) {
/**
* @namespace
*/
OCA.SystemTags = {};
}

OCA.SystemTags.Admin = {

collection: null,

init: function() {
var self = this;

this.collection = new OC.SystemTags.SystemTagsCollection();
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_manager').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_manager').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_manager').attr('data-systemtag-id', tagId);
$('#systemtag_delete').removeClass('hidden');
$('#systemtag_submit').val(t('systemtags_manager', 'Update'));
} else {
$('#systemtag').select2('val', '');
$('#systemtags_manager').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) {
console.log('formatResult');
return OC.SystemTags.getDescriptiveTag(tag);
},
formatSelection: function (tag) {
OCA.SystemTags.Admin.onSelectTag(tag);
return OC.SystemTags.getDescriptiveTag(tag);
},
escapeMarkup: function(m) {
console.log('escapeMarkup');
return m;
}
}
};
})();

$(document).ready(function() {
OCA.SystemTags.Admin.init();
});

37 changes: 37 additions & 0 deletions apps/systemtags/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
*
* @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 <http://www.gnu.org/licenses/>.
*
*/

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');
}
}
59 changes: 59 additions & 0 deletions apps/systemtags/templates/admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
*
* @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 <http://www.gnu.org/licenses/>.
*
*/

vendor_script('core', 'select2/select2');
vendor_style('core', 'select2/select2');
script('core', [
'oc-backbone-webdav',
'systemtags/systemtags',
'systemtags/systemtagmodel',
'systemtags/systemtagscollection',
]);

script('systemtags_manager', 'admin');

/** @var \OCP\IL10N $l */
?>

<form id="systemtags" class="section" data-systemtag-id="">
<h2><?php p($l->t('Collaborative tags')); ?></h2>

<input type="hidden" name="systemtag" id="systemtag" placeholder="<?php p($l->t('Select tag…')); ?>" style="width: 400px;" />

<br><br>

<input type="text" id="systemtag_name" name="systemtag_name" placeholder="<?php p($l->t('Name')); ?>" style="width: 200px;">

<span id="systemtag_delete" class="hidden">
<img src="<?php p(\OCP\Template::image_path('core', 'actions/delete.svg')); ?>" alt="<?php p($l->t('Delete')); ?>">
</span>

<br>

<select id="systemtag_level">
<option value="3"><?php p($l->t('Public')); ?></option>
<option value="2"><?php p($l->t('Restricted')); ?></option>
<option value="0"><?php p($l->t('Invisible')); ?></option>
</select>

<input type="button" id="systemtag_submit" value="<?php p($l->t('Create')); ?>">
<input type="button" id="systemtag_reset" value="<?php p($l->t('Reset')); ?>">
</form>

0 comments on commit 14cf786

Please sign in to comment.