Commit 1c49c3a5 authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review
Browse files

Merge "Bug 1777741 - Allow artefact chooser to also search by tag"

parents 262a8e97 92551f50
......@@ -138,7 +138,18 @@ function updateTextContent(a) {
jQuery('#instconf_licensorurl').prop('value', a.licensorurl);
jQuery('#instconf_textreadonly_display').html(a.safedescription);
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_tagsreadonly_display').html(a.safetags);
jQuery('#instconf_makecopy').prop('checked', false);
......
......@@ -3427,7 +3427,7 @@ class View {
else {
$sortorder .= ', ';
}
$fieldname = $field['fieldname'];
$fieldname = 'a.' . $field['fieldname'];
if (!empty($field['fieldvalue'])) {
$fieldname .= " = '" . $field['fieldvalue'] . "'";
}
......@@ -3459,10 +3459,10 @@ class View {
$extraselect .= ' AND ';
if (count($values) > 1) {
$extraselect .= $field['fieldname'] . ' IN (' . implode(', ', $values) . ')';
$extraselect .= 'a.' . $field['fieldname'] . ' IN (' . implode(', ', $values) . ')';
}
else {
$extraselect .= $field['fieldname'] . ' = ' . reset($values);
$extraselect .= 'a.' . $field['fieldname'] . ' = ' . reset($values);
}
}
}
......@@ -3471,6 +3471,15 @@ class View {
|| $data['blocktype'] == 'recentposts');
$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) {
// Get group-owned artefacts that the user has view
......@@ -3579,7 +3588,10 @@ class View {
if (!empty($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;
......@@ -3625,9 +3637,10 @@ class View {
}
$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 (!empty($data['artefacttypes'])) {
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