From 0fdb3641600dea4a7b7676ba53bc7f5285b9fa6f Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Fri, 1 Aug 2014 15:00:20 +0400 Subject: [PATCH] Fix keyword webservice, take all keyword list from field_metadata --- Bugzilla/Keyword.pm | 5 ++-- Bugzilla/WebService/Keyword.pm | 29 ++++++++++--------- enter_bug.cgi | 6 ---- js/bug-visibility.js | 9 ++++-- js/field.js | 13 +++++++++ js/global.js | 10 ++----- js/query-form.js | 7 ++--- query.cgi | 7 ----- show_bug.cgi | 3 -- .../en/default/bug/create/create.html.tmpl | 8 +---- template/en/default/bug/edit.html.tmpl | 15 +++------- template/en/default/search/form.html.tmpl | 1 - 12 files changed, 47 insertions(+), 66 deletions(-) diff --git a/Bugzilla/Keyword.pm b/Bugzilla/Keyword.pm index 42aa26200..d2bce9938 100644 --- a/Bugzilla/Keyword.pm +++ b/Bugzilla/Keyword.pm @@ -60,10 +60,9 @@ sub get_by_match } if (@match_items) { - my $joined = join(' OR ', @match_items); - $keywords = $dbh->selectall_arrayref("SELECT * FROM keywords WHERE ".$joined, {Slice => {}}); - return [] unless $keywords; + return $self->_do_list_select(join(' OR ', @match_items)); } + return []; } 1; diff --git a/Bugzilla/WebService/Keyword.pm b/Bugzilla/WebService/Keyword.pm index d76257f03..4f4d44b64 100644 --- a/Bugzilla/WebService/Keyword.pm +++ b/Bugzilla/WebService/Keyword.pm @@ -1,5 +1,3 @@ -# -*- Mode: perl; indent-tabs-mode: nil -*- -# # The contents of this file are subject to the Mozilla Public # License Version 1.1 (the "License"); you may not use this file # except in compliance with the License. You may obtain a copy of @@ -25,7 +23,7 @@ use base qw(Bugzilla::WebService); use Bugzilla; use Bugzilla::Constants; use Bugzilla::Error; -use Bugzilla::Util qw(trim); +use Bugzilla::Util; use Bugzilla::WebService::Util qw(filter validate); # Function to return keywords by passing either keyword ids or @@ -36,37 +34,42 @@ use Bugzilla::WebService::Util qw(filter validate); # Can be also used to match keywords based on their name: # $call = $rpc->call( 'Keyword.get', { match => [ 'testkeyworda', 'testkeywordb' ]}); # -sub get { +sub get +{ my ($self, $params) = validate(@_, 'names', 'ids'); # Make them arrays if they aren't - if ($params->{names} && !ref $params->{names}) { + if ($params->{names} && !ref $params->{names}) + { $params->{names} = [ $params->{names} ]; } - if ($params->{ids} && !ref $params->{ids}) { + if ($params->{ids} && !ref $params->{ids}) + { $params->{ids} = [ $params->{ids} ]; } - if ($params->{match} && !ref $params->{match}) { + if ($params->{match} && !ref $params->{match}) + { $params->{match} = [ $params->{match} ]; } + warn Dumper $params; my @keyword_list; if ($params->{names}) { - my $keyword_objects = Bugzilla::Keyword->match( { name => @{$params->{names}} } ); - @keyword_list = map { { name => $_->{name} } } @$keyword_objects; + my $keyword_objects = Bugzilla::Keyword->match({ value => @{$params->{names}} }); + @keyword_list = map { { name => $_->name } } @$keyword_objects; } if ($params->{ids}) { - my $keyword_objects = Bugzilla::Keyword->match( { id => @{$params->{ids}} } ); - @keyword_list = map { { name => $_->{name} } } @$keyword_objects; + my $keyword_objects = Bugzilla::Keyword->match({ id => @{$params->{ids}} }); + @keyword_list = map { { name => $_->name } } @$keyword_objects; } if ($params->{match}) { - my $keyword_objects = Bugzilla::Keyword->get_by_match( @{$params->{match}} ); - @keyword_list = map { { name => $_->{name} } } @$keyword_objects; + my $keyword_objects = Bugzilla::Keyword->get_by_match(@{$params->{match}}); + @keyword_list = map { { name => $_->name } } @$keyword_objects; } return { keywords => \@keyword_list }; diff --git a/enter_bug.cgi b/enter_bug.cgi index 334496d53..171ebf1c5 100755 --- a/enter_bug.cgi +++ b/enter_bug.cgi @@ -559,12 +559,6 @@ foreach my $row (@$grouplist) $vars->{group} = \@groups; -# Custis Bug 66910 -my @keyword_list = Bugzilla::Keyword->get_all(); -my @keyword_list_out = map { { name => $_->{name} } } @keyword_list; -$vars->{keyword_list} = \@keyword_list_out; -# END Custis Bug 66910 - Bugzilla::Hook::process('enter_bug_entrydefaultvars', { vars => $vars }); $vars->{default} = \%default; diff --git a/js/bug-visibility.js b/js/bug-visibility.js index bf2201881..7632d1af8 100644 --- a/js/bug-visibility.js +++ b/js/bug-visibility.js @@ -46,10 +46,13 @@ function getSelectedIds(sel) { var opt = {}; var lm = sel.id.length+2; - if (sel.type == 'hidden' && sel.name == 'product') + if (sel.nodeName != 'SELECT') { - // product is a special case - it is preselected as hidden field on bug creation form - opt[product_id] = true; + if (sel.name == 'product') + { + // product is a special case - it is preselected as hidden field on bug creation form + opt[product_id] = true; + } return opt; } for (var i = 0; i < sel.options.length; i++) diff --git a/js/field.js b/js/field.js index cb18ba699..ca2343633 100644 --- a/js/field.js +++ b/js/field.js @@ -277,6 +277,19 @@ function _value_id(field_name, id) return 'v' + id + '_' + field_name; } +function addKeywordsAutocomplete() +{ + var emptyKeywordsOptions = []; + for (var i = 0; i < field_metadata.keywords.legal.length; i++) + { + emptyKeywordsOptions.push({ name: field_metadata.keywords.legal[i][1] }); + } + new SimpleAutocomplete("keywords", + function(h) { keywordAutocomplete(h, emptyKeywordsOptions); }, + { emptyText: 'No keywords found', multipleDelimiter: "," } + ); +} + // CustIS bug 66910 - check new keywords and requery description for its function check_new_keywords(form) { diff --git a/js/global.js b/js/global.js index 9f289f673..c5d6922a2 100644 --- a/js/global.js +++ b/js/global.js @@ -180,13 +180,9 @@ function convertSimpleList(k) { var data = []; for (var i = 0; i < k.length; i++) - data.push([ - '' + k[i].name + - '', - k[i].name - ]); + data.push([ '' + k[i].name + '', k[i].name ]); return data; -} +} // Data loader for keyword autocomplete function keywordAutocomplete(hint, emptyOptions) @@ -221,7 +217,7 @@ function keywordAutocomplete(hint, emptyOptions) hint.replaceItems(data); } }); -} +} // Data loader for field in buglist autocomplete function fieldBuglistAutocomplete(hint, field, emptyOptions) diff --git a/js/query-form.js b/js/query-form.js index 840918343..2a3661801 100644 --- a/js/query-form.js +++ b/js/query-form.js @@ -2,14 +2,10 @@ // License: Dual-license GPL 3.0+ or MPL 1.1+ // Author(s): Vitaliy Filippov -// Requires global vars: queryform, allKeywords, checkwidths, userAutocomplete +// Requires global vars: queryform, checkwidths, userAutocomplete addListener(window, 'load', function() { document.forms[queryform].content.focus(); - new SimpleAutocomplete("keywords", - function(h) { keywordAutocomplete(h, allKeywords); }, - { emptyText: 'No keywords found', multipleDelimiter: "," } - ); if (document.getElementById('deadlinefrom')) { Calendar.set('deadlinefrom'); @@ -20,6 +16,7 @@ addListener(window, 'load', function() Calendar.set('chfieldfrom'); Calendar.set('chfieldto'); new SimpleAutocomplete("chfieldwho", userAutocomplete, { emptyText: 'No users found' }); + addKeywordsAutocomplete(); var lim = 250; function checkw(e) diff --git a/query.cgi b/query.cgi index f5fee737c..1caedd478 100755 --- a/query.cgi +++ b/query.cgi @@ -304,13 +304,6 @@ if ($vars->{query_format} eq "create-series") $vars->{category} = Bugzilla::Chart::getVisibleSeries(); } -# Custis Bug 66910 -my @keyword_list = Bugzilla::Keyword->get_all(); -my @keyword_list_out = map { { name => $_->{name} } } @keyword_list; -$vars->{keyword_list} = \@keyword_list_out; -# END Custis Bug 66910 - - # Set cookie to current format as default, but only if the format # one that we should remember. if (defined $vars->{format} && IsValidQueryType($vars->{format})) diff --git a/show_bug.cgi b/show_bug.cgi index 710b9cbc7..0f0a6f9bf 100755 --- a/show_bug.cgi +++ b/show_bug.cgi @@ -149,9 +149,6 @@ if ($ARGS->{includefield} || $ARGS->{field}) $vars->{displayfields} = \%displayfields; -# CustIS Bug 66910 - Autocomplete for keywords -$vars->{keyword_list} = [ map { { name => $_->name } } Bugzilla::Keyword->get_all() ]; - Bugzilla->cgi->send_header($format->{ctype}); $template->process($format->{template}, $vars) || ThrowTemplateError($template->error()); diff --git a/template/en/default/bug/create/create.html.tmpl b/template/en/default/bug/create/create.html.tmpl index c0c89161b..8c2fa8a3c 100644 --- a/template/en/default/bug/create/create.html.tmpl +++ b/template/en/default/bug/create/create.html.tmpl @@ -446,13 +446,7 @@ var close_status_array = [ [% END %]
diff --git a/template/en/default/bug/edit.html.tmpl b/template/en/default/bug/edit.html.tmpl index 8dbe45cde..3a11e57d7 100644 --- a/template/en/default/bug/edit.html.tmpl +++ b/template/en/default/bug/edit.html.tmpl @@ -534,19 +534,12 @@ document.changeform = document.[% cfname %]; [% IF use_keywords %] - - : + : [% PROCESS input inputname => "keywords" size => 40 colspan => 2 %] + [% END %] [% END %] diff --git a/template/en/default/search/form.html.tmpl b/template/en/default/search/form.html.tmpl index 65a242ff3..f890759e1 100644 --- a/template/en/default/search/form.html.tmpl +++ b/template/en/default/search/form.html.tmpl @@ -422,5 +422,4 @@