summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Lamy <olamy@apache.org>2012-02-29 18:51:23 +0000
committerOlivier Lamy <olamy@apache.org>2012-02-29 18:51:23 +0000
commita15504344b6aeaf9e3415fd5821b455151f690ec (patch)
treedee45d1ccf1f0a824c3874661de2628cf3f7d316
parent4dcb5d3ebb72cc1ba96cc55723ac67d2632c8e60 (diff)
downloadarchiva-a15504344b6aeaf9e3415fd5821b455151f690ec.tar.gz
archiva-a15504344b6aeaf9e3415fd5821b455151f690ec.zip
add autocomplete to apply filtering on search results
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1295209 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/search.js49
-rw-r--r--archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/search.html7
-rw-r--r--archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/utils.js15
-rw-r--r--archiva-modules/archiva-web/pom.xml1
4 files changed, 66 insertions, 6 deletions
diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/search.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/search.js
index 51295b07e..a8de514c6 100644
--- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/search.js
+++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/search.js
@@ -703,6 +703,7 @@ $(function() {
var searchResultsGrid=mainContent.find("#search-results #search-results-grid" );
mainContent.find("#btn-basic-search" ).button("loading");
+ mainContent.find("#btn-advanced-search" ).button("loading");
$("#user-messages").html(mediumSpinnerImg());
@@ -733,8 +734,50 @@ $(function() {
"simpleGrid: gridViewModel,simpleGridTemplate:'search-results-view-grid-tmpl',pageLinksId:'search-results-view-grid-pagination'");
ko.applyBindings(self.resultViewModel,searchResultsGrid.get(0));
}
+ // FIXME something generic here !
+
+ $( "#main-content #search-filter-auto-groupId" ).autocomplete({
+ minLength: 1,
+ source: function(request, response){
+ var groupIds=[];
+ $(self.resultViewModel.artifacts()).each(function(idx,artifact){
+ if(artifact.groupId.startsWith(request.term)){
+ groupIds.push(artifact.groupId);
+ }
+ });
+ response(unifyArray(groupIds,true));
+ }
+ });
+
+ $( "#main-content #search-filter-auto-artifactId" ).autocomplete({
+ minLength: 1,
+ source: function(request, response){
+ var artifactIds=[];
+ $(self.resultViewModel.artifacts()).each(function(idx,artifact){
+ if(artifact.artifactId.startsWith(request.term)){
+ artifactIds.push(artifact.artifactId);
+ }
+ });
+ response(unifyArray(artifactIds,true));
+ }
+ });
+
+ $( "#main-content #search-filter-auto-version" ).autocomplete({
+ minLength: 1,
+ source: function(request, response){
+ var versions=[];
+ $(self.resultViewModel.artifacts()).each(function(idx,artifact){
+ if(artifact.version.startsWith(request.term)){
+ versions.push(artifact.version);
+ }
+ });
+ response(unifyArray(versions,true));
+ }
+ });
+
+
+
activateSearchResultsTab();
- mainContent.find("#btn-advanced-search-filter" ).show();
}
},
error: function(data) {
@@ -742,13 +785,15 @@ $(function() {
displayRestError(res);
},
complete:function() {
- $("#main-content #btn-basic-search" ).button("reset");
+ mainContent.find("##btn-basic-search" ).button("reset");
+ mainContent.find("#btn-advanced-search" ).button("reset");
removeMediumSpinnerImg("#user-messages");
}
}
);
}
+ // olamy not used as we cannot filter on className etc...
filterResults=function(){
var filtered=[];
for (var i=0;i<self.resultViewModel.artifacts().length;i++){
diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/search.html b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/search.html
index db333ab90..4c1b98637 100644
--- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/search.html
+++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/search.html
@@ -256,9 +256,6 @@
<button type="submit" id="btn-advanced-search" class="btn btn-primary"
data-bind="click: advancedSearch">${$.i18n.prop('search.artifact.search.form.btn.search')}</button>
- <button type="submit" id="btn-advanced-search-filter" class="btn btn-success hide"
- data-bind="click: filterResults">${$.i18n.prop('search.artifact.search.form.btn.search.filter')}</button>
-
</form>
</div>
<div class="pill-pane" id="search-osgi-form-pane">
@@ -290,7 +287,9 @@
</tr>
<tr>
{{each(i, columnDefinition) columns}}
- <th title="${ columnDefinition.title }" id="search-filter-auto-${ columnDefinition.id }"><input type="text" place-holder="filter"/></th>
+ <th title="${ columnDefinition.title }">
+ <input type="text" class="form-search" id="search-filter-auto-${ columnDefinition.id }" place-holder="filtering"/>
+ </th>
{{/each}}
</tr>
</thead>
diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/utils.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/utils.js
index c0ac9f7e3..6c31107c0 100644
--- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/utils.js
+++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/utils.js
@@ -329,6 +329,21 @@ mapStringList=function(data){
return [];
}
+/**
+ * return an array with removing duplicate strings
+ * @param strArray an array of string
+ * @param sorted to sort or not
+ */
+unifyArray=function(strArray,sorted){
+ var res = [];
+ $(strArray).each(function(idx,str){
+ if ( $.inArray(str,res)<0){
+ res.push(str);
+ }
+ });
+ return sorted?res.sort():res;
+}
+
// utils
String.prototype.endsWith = function(str) {
return (this.match(str+"$")==str)
diff --git a/archiva-modules/archiva-web/pom.xml b/archiva-modules/archiva-web/pom.xml
index 0dfdaa403..174ad6777 100644
--- a/archiva-modules/archiva-web/pom.xml
+++ b/archiva-modules/archiva-web/pom.xml
@@ -133,4 +133,5 @@
</modules>
</profile>
</profiles>
+
</project>