Commit 92551f50 authored by Robert Lyon's avatar Robert Lyon
Browse files

Bug 1777741 - Allow artefact chooser to also search by tag



So that we now can search by title/description/tag for valid artefacts

Note: For 18.10 system of tags

behatnotneeded

Change-Id: I9c514f98998b0a97326a8ba7c1de4566453a38aa
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 2cfa4ac5
...@@ -138,7 +138,18 @@ function updateTextContent(a) { ...@@ -138,7 +138,18 @@ function updateTextContent(a) {
jQuery('#instconf_licensorurl').prop('value', a.licensorurl); jQuery('#instconf_licensorurl').prop('value', a.licensorurl);
jQuery('#instconf_textreadonly_display').html(a.safedescription); jQuery('#instconf_textreadonly_display').html(a.safedescription);
jQuery('#instconf_licensereadonly_display').html(a.safelicense); jQuery('#instconf_licensereadonly_display').html(a.safelicense);
jQuery('#instconf_tags').prop('value', a.tags); if (a.tags && a.tags.length > 0) {
for (var i = 0; i < a.tags.length; i++) {
// Set the value, creating a new option if necessary
if (!$('#instconf_tags').find("option[value='" + a.tags[i] + "']").length) {
// Create a DOM Option and pre-select by default
var newOption = new Option(a.tags[i], a.tags[i], true, true);
// Append it to the select
$('#instconf_tags').append(newOption);
}
}
$('#instconf_tags').val(a.tags).trigger('change');
}
jQuery('#instconf_textreadonly_display').html(a.safedescription); jQuery('#instconf_textreadonly_display').html(a.safedescription);
jQuery('#instconf_tagsreadonly_display').html(a.safetags); jQuery('#instconf_tagsreadonly_display').html(a.safetags);
jQuery('#instconf_makecopy').prop('checked', false); jQuery('#instconf_makecopy').prop('checked', false);
......
...@@ -3427,7 +3427,7 @@ class View { ...@@ -3427,7 +3427,7 @@ class View {
else { else {
$sortorder .= ', '; $sortorder .= ', ';
} }
$fieldname = $field['fieldname']; $fieldname = 'a.' . $field['fieldname'];
if (!empty($field['fieldvalue'])) { if (!empty($field['fieldvalue'])) {
$fieldname .= " = '" . $field['fieldvalue'] . "'"; $fieldname .= " = '" . $field['fieldvalue'] . "'";
} }
...@@ -3459,10 +3459,10 @@ class View { ...@@ -3459,10 +3459,10 @@ class View {
$extraselect .= ' AND '; $extraselect .= ' AND ';
if (count($values) > 1) { if (count($values) > 1) {
$extraselect .= $field['fieldname'] . ' IN (' . implode(', ', $values) . ')'; $extraselect .= 'a.' . $field['fieldname'] . ' IN (' . implode(', ', $values) . ')';
} }
else { else {
$extraselect .= $field['fieldname'] . ' = ' . reset($values); $extraselect .= 'a.' . $field['fieldname'] . ' = ' . reset($values);
} }
} }
} }
...@@ -3471,6 +3471,15 @@ class View { ...@@ -3471,6 +3471,15 @@ class View {
|| $data['blocktype'] == 'recentposts'); || $data['blocktype'] == 'recentposts');
$from = ' FROM {artefact} a '; $from = ' FROM {artefact} a ';
// To also check tags
require_once('ddl.php');
if (!table_exists(new XMLDBTable("tag"))) {
$from .= " LEFT JOIN {artefact_tag} t ON t.artefact = a.id ";
}
else {
$typecast = is_postgres() ? '::varchar' : '';
$from .= " LEFT JOIN {tag} t ON t.resourcetype = 'artefact' AND a.id" . $typecast . " = t.resourceid ";
}
if ($group) { if ($group) {
// Get group-owned artefacts that the user has view // Get group-owned artefacts that the user has view
...@@ -3579,7 +3588,10 @@ class View { ...@@ -3579,7 +3588,10 @@ class View {
if (!empty($data['search'])) { if (!empty($data['search'])) {
$search = db_quote('%' . str_replace('%', '%%', $data['search']) . '%'); $search = db_quote('%' . str_replace('%', '%%', $data['search']) . '%');
$select .= 'AND (title ' . db_ilike() . '(' . $search . ') OR description ' . db_ilike() . '(' . $search . ') )'; $select .= 'AND (title ' . db_ilike() . '(' . $search . ')
OR description ' . db_ilike() . '(' . $search . ')
OR t.tag ' . db_ilike() . '(' . $search . ')
)';
} }
$select .= $extraselect; $select .= $extraselect;
...@@ -3625,9 +3637,10 @@ class View { ...@@ -3625,9 +3637,10 @@ class View {
} }
$artefacts = get_records_sql_assoc( $artefacts = get_records_sql_assoc(
'SELECT ' . $cols . $from . ' WHERE ' . $select . $sortorder, $selectph, $offset, $limit 'SELECT DISTINCT agg.* FROM (SELECT ' . $cols . $from . ' WHERE ' . $select . $sortorder . ') AS agg', $selectph, $offset, $limit
); );
$totalartefacts = count_records_sql('SELECT COUNT(*) ' . $from . ' WHERE ' . $select, $countph); $totalartefacts = count_records_sql('SELECT COUNT(DISTINCT agg.id) FROM (SELECT a.* ' . $from . ' WHERE ' . $select . ') AS agg', $countph);
// If our profile artefact is saving it's data to a special place // If our profile artefact is saving it's data to a special place
if (!empty($data['artefacttypes'])) { if (!empty($data['artefacttypes'])) {
safe_require('artefact', 'internal'); safe_require('artefact', 'internal');
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment