Commit 2d643dec 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

behatnotneeded

Change-Id: I9c514f98998b0a97326a8ba7c1de4566453a38aa
Signed-off-by: default avatarRobert Lyon <robertl@catalyst.net.nz>
parent 5fe0a979
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -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);
+12 −6
Original line number Diff line number Diff line
@@ -3388,7 +3388,7 @@ class View {
                else {
                    $sortorder .= ', ';
                }
                $fieldname = $field['fieldname'];
                $fieldname = 'a.' . $field['fieldname'];
                if (!empty($field['fieldvalue'])) {
                    $fieldname .= " = '" . $field['fieldvalue'] . "'";
                }
@@ -3420,10 +3420,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);
                }
            }
        }
@@ -3432,6 +3432,8 @@ class View {
             || $data['blocktype'] == 'recentposts');

        $from = ' FROM {artefact} a ';
        // To also check tags
        $from .= " LEFT JOIN {artefact_tag} t ON t.artefact = a.id ";

        if ($group) {
            // Get group-owned artefacts that the user has view
@@ -3540,7 +3542,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;
@@ -3586,9 +3591,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');