Skip to content

Commit

Permalink
MDL-51260 core_tag: Use new tag autocomplete for related tags
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy authored and Damyon Wiese committed Oct 15, 2015
1 parent bb6ca6f commit a27c42e
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 174 deletions.
18 changes: 18 additions & 0 deletions lib/deprecatedlib.php
Expand Up @@ -2723,3 +2723,21 @@ function coursetag_delete_course_tags($courseid, $showfeedback=false) {
echo $OUTPUT->notification(get_string('deletedcoursetags', 'tag'), 'notifysuccess');
}
}

/**
* Function that returns tags that start with some text, for use by the autocomplete feature
*
* @package core_tag
* @deprecated since 3.0
* @access private
* @param string $text string that the tag names will be matched against
* @return mixed an array of objects, or false if no records were found or an error occured.
*/
function tag_autocomplete($text) {
debugging('Function tag_autocomplete() is deprecated without replacement. ' .
'New form element "tags" does proper autocomplete.', DEBUG_DEVELOPER);
global $DB;
return $DB->get_records_sql("SELECT tg.id, tg.name, tg.rawname
FROM {tag} tg
WHERE tg.name LIKE ?", array(core_text::strtolower($text)."%"));
}
7 changes: 2 additions & 5 deletions tag/edit.php
Expand Up @@ -59,7 +59,7 @@
$tagname = tag_display_name($tag);

// set the relatedtags field of the $tag object that will be passed to the form
$tag->relatedtags = tag_get_related_tags_csv(tag_get_related_tags($tag->id, TAG_RELATED_MANUAL), TAG_RETURN_TEXT);
$tag->relatedtags = tag_get_tags_array('tag', $tag->id);

$options = new stdClass();
$options->smiley = false;
Expand Down Expand Up @@ -141,7 +141,7 @@
}

//updated related tags
tag_set('tag', $tagnew->id, explode(',', trim($tagnew->relatedtags)), 'core', $systemcontext->id);
tag_set('tag', $tagnew->id, $tagnew->relatedtags, 'core', $systemcontext->id);
//print_object($tagnew); die();

$tagname = isset($tagnew->rawname) ? $tagnew->rawname : $tag->rawname;
Expand All @@ -164,7 +164,4 @@

$tagform->display();

$PAGE->requires->js('/tag/tag.js');
$PAGE->requires->js_function_call('init_tag_autocomplete', null, true);

echo $OUTPUT->footer();
6 changes: 1 addition & 5 deletions tag/edit_form.php
Expand Up @@ -68,11 +68,7 @@ function definition () {
$mform->addElement('checkbox', 'tagtype', get_string('officialtag', 'tag'));
}

$mform->addElement('html', '<br/><div id="relatedtags-autocomplete-container">');
$mform->addElement('textarea', 'relatedtags', get_string('relatedtags','tag'), 'cols="50" rows="3"');
$mform->setType('relatedtags', PARAM_TAGLIST);
$mform->addElement('html', '<div id="relatedtags-autocomplete"></div>');
$mform->addElement('html', '</div>');
$mform->addElement('tags', 'relatedtags', get_string('relatedtags','tag'));

$this->add_action_buttons(true, get_string('updatetag', 'tag'));

Expand Down
15 changes: 0 additions & 15 deletions tag/lib.php
Expand Up @@ -1045,21 +1045,6 @@ function tag_assign($record_type, $record_id, $tagid, $ordering, $userid = 0, $c
return true;
}

/**
* Function that returns tags that start with some text, for use by the autocomplete feature
*
* @package core_tag
* @access private
* @param string $text string that the tag names will be matched against
* @return mixed an array of objects, or false if no records were found or an error occured.
*/
function tag_autocomplete($text) {
global $DB;
return $DB->get_records_sql("SELECT tg.id, tg.name, tg.rawname
FROM {tag} tg
WHERE tg.name LIKE ?", array(core_text::strtolower($text)."%"));
}

/**
* Clean up the tag tables, making sure all tagged object still exists.
*
Expand Down
30 changes: 0 additions & 30 deletions tag/tag.js

This file was deleted.

58 changes: 0 additions & 58 deletions tag/tag_autocomplete.php

This file was deleted.

6 changes: 4 additions & 2 deletions tag/tests/behat/edit_tag.feature
Expand Up @@ -21,6 +21,7 @@ Feature: Users can edit tags to add description or rename
| name | tagtype |
| Neverusedtag | official |

@javascript
Scenario: User with tag editing capability can change tag description
Given I log in as "admin"
And I set the following system permissions of "Tag editor" role:
Expand All @@ -45,6 +46,7 @@ Feature: Users can edit tags to add description or rename
And I should see "Related tags: Dog, Turtle, Fish"
And I log out

@javascript
Scenario: Manager can change tag description, related tags and rename the tag from tag view page
When I log in as "manager1"
And I navigate to "Participants" node in "Site pages"
Expand All @@ -61,8 +63,7 @@ Feature: Users can edit tags to add description or rename
And "Description of tag 1" "text" should exist in the "#tag-description" "css_element"
And I should see "Related tags: Dog, Turtle, Fish"
And I follow "Edit this tag"
And I set the following fields to these values:
| Related tags | Turtle, Fish |
And I click on "× Dog" "text"
And I press "Update"
Then "Kitten" "text" should exist in the ".breadcrumb-nav" "css_element"
And "Description of tag 1" "text" should exist in the "#tag-description" "css_element"
Expand Down Expand Up @@ -91,6 +92,7 @@ Feature: Users can edit tags to add description or rename
And "KITTEN" "text" should exist in the ".breadcrumb-nav" "css_element"
And I log out

@javascript
Scenario: Manager can change tag description and rename the tag from tag manage page
When I log in as "manager1"
And I navigate to "Manage tags" node in "Site administration > Appearance"
Expand Down
8 changes: 0 additions & 8 deletions theme/base/style/core.css
Expand Up @@ -770,14 +770,6 @@ tr.flagged-tag a {color:#FF0000;}
.tag-management-table tr:hover td .tagnameedit img,
.tag-management-table tr td .tagnameedit:focus img {opacity: 1;}
.tag-management-table tr:hover td.tageditingon .tagnameedit img {opacity: 0.2;}
#relatedtags-autocomplete-container {margin-left:auto;margin-right:auto;min-height:4.6em;width:100%;}
#relatedtags-autocomplete {position:relative;display:block;width:60%;margin-left:auto;margin-right:auto;}
#relatedtags-autocomplete .yui-ac-content {position:absolute;width:420px;left:20%;border:1px solid #404040;background:#fff;overflow:hidden;z-index:9050;}
#relatedtags-autocomplete .ysearchquery {position:absolute;right:10px;color:#808080;z-index:10;}
#relatedtags-autocomplete .yui-ac-shadow {position:absolute;margin:.3em;width:100%;background:#a0a0a0;z-index:9049;}
#relatedtags-autocomplete ul {padding:0;width:100%;margin:0;list-style-type:none;}
#relatedtags-autocomplete li {padding:0 5px;cursor:default;white-space:nowrap;}
#relatedtags-autocomplete li.yui-ac-highlight{background:#FFFFCC;}
h2.tag-heading,
div#tag-description,
div#tag-blogs,
Expand Down
50 changes: 0 additions & 50 deletions theme/bootstrapbase/less/moodle/core.less
Expand Up @@ -871,56 +871,6 @@ tr.flagged-tag a {
.tag-management-table tr:hover td.tageditingon .tagnameedit img {
opacity: 0.2;
}
#relatedtags-autocomplete-container {
margin-left: auto;
margin-right: auto;
min-height: 4.6em;
width: 100%;
}
#relatedtags-autocomplete {
position: relative;
display: block;
width: 60%;
margin-left: auto;
margin-right: auto;
}
#relatedtags-autocomplete .yui-ac-content {
position: absolute;
width: 420px;
left: 20%;
border: 1px solid @dropdownBorder;
background: @dropdownBackground;
overflow: hidden;
z-index: 9050;
}
#relatedtags-autocomplete .ysearchquery {
position: absolute;
right: 10px;
color: #808080;
z-index: 10;
}
#relatedtags-autocomplete .yui-ac-shadow {
position: absolute;
margin: .3em;
width: 100%;
background: #a0a0a0;
z-index: 9049;
}
#relatedtags-autocomplete ul {
padding: 0;
width: 100%;
margin: 0;
list-style-type: none;
}
#relatedtags-autocomplete li {
padding: 0 5px;
cursor: default;
white-space: nowrap;
}
#relatedtags-autocomplete li.yui-ac-highlight{
background: @dropdownLinkBackgroundHover;
color: @dropdownLinkColorHover;
}
h2.tag-heading,
div#tag-description,
div#tag-blogs,
Expand Down
2 changes: 1 addition & 1 deletion theme/bootstrapbase/style/moodle.css

Large diffs are not rendered by default.

0 comments on commit a27c42e

Please sign in to comment.