Skip to content

Commit

Permalink
MDL-50919 tags: new UI for managing tags
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy committed Sep 2, 2015
1 parent 0cf7252 commit 8e35585
Show file tree
Hide file tree
Showing 27 changed files with 1,700 additions and 271 deletions.
9 changes: 8 additions & 1 deletion lang/en/deprecated.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,11 @@ myfilesmanage,core
mypreferences,core_grades
myprofile,core
viewallmyentries,core_blog
cannotdeletepost,core_notes
cannotdeletepost,core_notes
addedotag,core_tag
newname,core_tag
tagtype_default,core_tag
tagtype_official,core_tag
thistaghasnodesc,core_tag
updated,core_tag
withselectedtags,core_tag
33 changes: 23 additions & 10 deletions lang/en/tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,19 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

$string['addedotag'] = '"{$a}" was added as an official tag.';
$string['added'] = 'Official tag(s) added';
$string['addotags'] = 'Add official tags';
$string['addtagtomyinterests'] = 'Add "{$a}" to my interests';
$string['alltagpages'] = 'All tag pages';
$string['confirmdeletetag'] = 'Are you sure you want to delete this tag?';
$string['confirmdeletetags'] = 'Are you sure you want to delete selected tags?';
$string['count'] = 'Count';
$string['delete'] = 'Delete';
$string['deleted'] = 'Deleted';
$string['deleteselected'] = 'Delete selected';
$string['deleted'] = 'Tag(s) deleted';
$string['deletedcoursetags'] = 'Deleted - Course tags';
$string['description'] = 'Description';
$string['editname'] = 'Edit tag name';
$string['edittag'] = 'Edit this tag';
$string['entertags'] = 'Enter tags separated by commas';
$string['errortagfrontpage'] = 'Tagging the site main page is not allowed';
Expand All @@ -43,6 +47,7 @@
$string['eventtagunflagged'] = 'Tag unflagged';
$string['eventtagupdated'] = 'Tag updated';
$string['flag'] = 'Flag';
$string['flagged'] = 'Tag flagged';
$string['flagasinappropriate'] = 'Flag as inappropriate';
$string['helprelatedtags'] = 'Comma separated related tags';
$string['changename'] = 'Change tag name';
Expand All @@ -52,17 +57,17 @@
$string['managetags'] = 'Manage tags';
$string['name'] = 'Tag name';
$string['namesalreadybeeingused'] = 'Tag names already being used';
$string['newname'] = 'New tag name';
$string['newnamefor'] = 'New name for tag {$a}';
$string['noresultsfor'] = 'No results for "{$a}"';
$string['officialtag'] = 'Official tag';
$string['officialtag'] = 'Official';
$string['otags'] = 'Official tags';
$string['othertags'] = 'Other tags (enter tags separated by commas)';
$string['owner'] = 'Owner';
$string['ptags'] = 'User defined tags (Comma separated)';
$string['relatedblogs'] = 'Most recent blog entries';
$string['relatedtags'] = 'Related tags';
$string['removetagfrommyinterests'] = 'Remove "{$a}" from my interests';
$string['reset'] = 'Reset';
$string['reset'] = 'Tag flag reset';
$string['resetflag'] = 'Reset flag';
$string['responsiblewillbenotified'] = 'The person responsible will be notified';
$string['rssdesc'] = 'This RSS feed was automatically generated by Moodle and contains user generated tags for courses.';
Expand All @@ -72,23 +77,31 @@
$string['searchtags'] = 'Search tags';
$string['seeallblogs'] = 'See all blog entries tagged with "{$a}"...';
$string['select'] = 'Select';
$string['selecttag'] = 'Select tag {$a}';
$string['settypedefault'] = 'Remove from official tags';
$string['settypeofficial'] = 'Make official';
$string['tag'] = 'Tag';
$string['tagdescription'] = 'Tag description';
$string['taggedwith'] = 'tagged with "{$a}"';
$string['tags'] = 'Tags';
$string['tagsaredisabled'] = 'Tags are disabled';
$string['tagtype'] = 'Tag type';
$string['tagtype_default'] = 'Default';
$string['tagtype_official'] = 'Official';
$string['thingstaggedwith'] = '"{$a->name}" is used {$a->count} times';
$string['thingtaggedwith'] = '"{$a->name}" is used once';
$string['thistaghasnodesc'] = 'This tag currently has no description.';
$string['timemodified'] = 'Modified';
$string['typechanged'] = 'Tag type changed';
$string['updated'] = 'Updated';
$string['updatetag'] = 'Update';
$string['withselectedtags'] = 'With selected tags...';
$string['page-tag-x'] = 'All tag pages';
$string['page-tag-index'] = 'Single tag page';
$string['page-tag-search'] = 'Tag search page';
$string['page-tag-manage'] = 'Manage tags page';

// Deprecated since 3.0 .

$string['addedotag'] = '"{$a}" was added as an official tag.';
$string['newname'] = 'New tag name';
$string['tagtype_default'] = 'Default';
$string['tagtype_official'] = 'Official';
$string['thistaghasnodesc'] = 'This tag currently has no description.';
$string['updated'] = 'Updated';
$string['withselectedtags'] = 'With selected tags...';
1 change: 1 addition & 0 deletions lib/amd/build/tag.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

203 changes: 203 additions & 0 deletions lib/amd/src/tag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* AJAX helper for the tag management page.
*
* @module core/tag
* @package core_tag
* @copyright 2015 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since 3.0
*/
define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str', 'core/config'],
function($, ajax, templates, notification, str, cfg) {
return /** @alias module:core/tag */ {

/**
* Initialises handlers for AJAX methods.
*
* @method init
*/
init_manage_page: function() {

var update_modified = function(el) {
var row = el.closest('tr').get(0);
if (row) {
var td = $(row).find('td.col-timemodified').get(0);
str.get_string('now').done(function(s) {
$(td).html(s);
});
}
};

// Click handler for changing tag type.
$('.tag-management-table').delegate('.tagtype', 'click', function(e) {
e.preventDefault();
var target = $( this ),
tagid = target.attr('data-id'),
currentvalue = target.attr('data-value'),
official = (currentvalue === "1") ? 0 : 1;

ajax.call([{
methodname: 'core_tag_update_tags',
args: { tags : [ { id : tagid , official : official } ] },
done: function(data) {
if (data.tags[0] !== undefined) {
templates.render('core_tag/tagtype', data.tags[0]).done(function(html) {
update_modified(target);
var parent = target.parent();
target.replaceWith(html);
parent.find('.tagtype').get(0).focus();
});
}
}
}]);
});

// Click handler for flagging/resetting tag flag.
$('.tag-management-table').delegate('.tagflag', 'click', function(e) {
e.preventDefault();
var target = $( this ),
tagid = target.attr('data-id'),
currentvalue = target.attr('data-value'),
flag = (currentvalue === "0") ? 1 : 0;

ajax.call([{
methodname: 'core_tag_update_tags',
args: { tags : [ { id : tagid , flag : flag } ] },
done: function(data) {
if (data.tags[0] !== undefined) {
var row = target.closest('tr').get(0);
if (row) {
if (data.tags[0].flag) {
$(row).addClass('flagged-tag');
} else {
$(row).removeClass('flagged-tag');
}
}
templates.render('core_tag/tagflag', data.tags[0]).done(function(html) {
update_modified(target);
var parent = target.parent();
target.replaceWith(html);
parent.find('.tagflag').get(0).focus();
});
}
}
}]);
});

// Confirmation for single tag delete link.
$('.tag-management-table').delegate('a.tagdelete', 'click', function(e) {
e.preventDefault();
var href = $(this).attr('href');
str.get_strings([
{key : 'delete'},
{key : 'confirmdeletetag', component : 'tag'},
{key : 'yes'},
{key : 'no'},
]).done(function(s) {
notification.confirm(s[0], s[1], s[2], s[3], function() {
window.location.href = href;
});
}
);
});

// Confirmation for bulk tag delete button.
$("#tag-management-delete").click(function(e){
var form = $(this).closest('form').get(0),
cnt = $(form).find("input[type=checkbox]:checked").length;
if (!cnt) {
return false;
}
e.preventDefault();
str.get_strings([
{key : 'delete'},
{key : 'confirmdeletetags', component : 'tag'},
{key : 'yes'},
{key : 'no'},
]).done(function(s) {
notification.confirm(s[0], s[1], s[2], s[3], function() {
form.submit();
});
}
);
});

// Edit tag name.
$('.tag-management-table').delegate('.tagnameedit', 'click keypress', function(e) {
if (e.type === 'keypress' && e.keyCode !== 13) {
return;
}
e.stopImmediatePropagation();
e.preventDefault();
var target = $(this),
tdelement = $( target.closest('td').get(0) ),
inputelement = $( tdelement.find('input').get(0) ),
tagid = target.attr('data-id');

var change_name = function(tagid, newname) {
ajax.call([{
methodname: 'core_tag_update_tags',
args: { tags : [ { id : tagid , rawname : newname } ] },
done: function(data) {
if (data.tags[0] !== undefined) {
templates.render('core_tag/tagname', data.tags[0]).done(function(html) {
update_modified(tdelement);
tdelement.html(html);
$(tdelement.find('.tagnameedit').get(0)).focus();
});
} else if (data.warnings[0] !== undefined) {
str.get_string('error').done(function(s) {
notification.alert(s, data.warnings[0].message);
});
}
}
}]); };

var turn_editing_off = function() {
$('.tag-management-table td.tageditingon').each(function() {
var td = $( this ),
input = $( td.find('input').get(0) );
input.off();
td.removeClass('tageditingon');
// Reset input value to the one that was there before editing.
input.val(td.attr('data-value'));
});
};

// Turn editing on for the current element and register handler for Enter/Esc keys.
turn_editing_off();
tdelement.addClass('tageditingon');
tdelement.attr('data-value', inputelement.val());
inputelement.select();
inputelement.on('keypress focusout', function(e) {
if (cfg.behatsiterunning && e.type === 'focusout') {
// Behat triggers focusout too often.
return;
}
if (e.type === 'keypress' && e.keyCode === 13) {
change_name(tagid, inputelement.val());
turn_editing_off();
}
if ((e.type === 'keypress' && e.keyCode === 27) || e.type === 'focusout') {
turn_editing_off();
}
});
});
}
};
});
9 changes: 9 additions & 0 deletions lib/db/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,15 @@
'type' => 'read',
'capabilities' => 'moodle/rating:view'
),

// Tag functions.
'core_tag_update_tags' => array(
'classname' => 'core_tag_external',
'methodname' => 'update_tags',
'description' => 'Updates tags',
'type' => 'write',
),

);

$services = array(
Expand Down
2 changes: 1 addition & 1 deletion mod/wiki/tests/behat/edit_tags.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@mod @mod_wiki
@mod @mod_wiki @core_tag
Feature: Edited wiki pages handle tags correctly
In order to get wiki pages properly labelled
As a user
Expand Down
Binary file added pix/i/checked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions pix/i/checked.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pix/i/unchecked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions pix/i/unchecked.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 8e35585

Please sign in to comment.