start displaying search results in a grid

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1294406 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2012-02-28 00:03:47 +00:00
parent 7c71fde835
commit c6946043df
4 changed files with 67 additions and 21 deletions

View File

@ -217,3 +217,7 @@ search.artifact.search.form.advanced=Advanced Parameters
search.artifact.search.form.query.artifactId=Artifact ID
search.artifact.search.form.repositories.all=All
search.artifact.search.form.terms.empty=You must enter some search terms.
search.artifact.noresults=No results found.
search.artifact.results.groupId=Group ID
search.artifact.results.artifactId=Artifact ID
search.artifact.results.version=Version

View File

@ -639,15 +639,38 @@ $(function() {
}
ResultViewModel=function(artifacts){
this.artifacts=artifacts;
var self=this;
this.artifacts=ko.observableArray(artifacts);
this.gridViewModel = new ko.simpleGrid.viewModel({
data: self.artifacts,
columns: [
{
headerText: $.i18n.prop('search.artifact.results.groupId'),
rowText: "groupId"
},
{
headerText: $.i18n.prop('search.artifact.results.artifactId'),
rowText: "artifactId"
},
{
headerText: $.i18n.prop('search.artifact.results.version'),
rowText: "version"
}
],
pageSize: 10,
gridUpdateCallBack: function(){
}
});
}
SearchViewModel=function(){
var self=this;
this.searchRequest=ko.observable(new SearchRequest());
this.observableRepoIds=ko.observableArray([]);
this.selectedRepoIds=[];
this.resultViewModel=new ResultViewModel([]);
basicSearch=function(){
//$.log("query:"+this.searchParameters().basicQueryString());
//$.log("repoIds:"+this.selectedRepoIds);
@ -664,8 +687,8 @@ $(function() {
// cleanup previours error message
customShowError("#main-content #search-basic-form", null, null, []);
}
var searchResults=$("#main-content #search-results" );
searchResults.html(mediumSpinnerImg());
var searchResultsGrid=$("#main-content #search-results #search-results-grid" );
$("#main-content #user-messages").html(mediumSpinnerImg());
this.searchRequest().repositories=this.selectedRepoIds;
$.ajax("restServices/archivaServices/searchService/quickSearchWithRepositories",
{
@ -674,10 +697,20 @@ $(function() {
contentType: 'application/json',
dataType: 'json',
success: function(data) {
var resultViewModel=new ResultViewModel(mapArtifacts(data));
searchResults.attr("data-bind","template:{name:'search-results-view-tmpl'}");
ko.applyBindings(resultViewModel,searchResults.get(0));
activateSearchResultsTab();
clearUserMessages();
var artifacts=mapArtifacts(data);
if (artifacts.length<1){
displayWarningMessage( $.i18n.prop("search.artifact.noresults"));
return;
} else {
self.resultViewModel.artifacts(artifacts);
if (!searchResultsGrid.attr("data-bind")){
searchResultsGrid.attr("data-bind",
"simpleGrid: gridViewModel,simpleGridTemplate:'search-results-view-grid-tmpl',pageLinksId:'search-results-view-grid-pagination'");
ko.applyBindings(self.resultViewModel,searchResultsGrid.get(0));
}
activateSearchResultsTab();
}
},
error: function(data) {
var res = $.parseJSON(data.responseText);

View File

@ -255,7 +255,9 @@
<div id="search-results" class="tab-pane">
No Results yet. Try a search !
<table class="table table-striped table-bordered" id="search-results-grid">
</table>
<div id="search-results-view-grid-pagination"></div>
</div>
</div>
@ -264,10 +266,21 @@
</script>
<script id="search-results-view-tmpl" type="text/html">
{{if artifacts.length==0}}
no results
{{else}}
results
{{/if}}
<script id="search-results-view-grid-tmpl" type="text/html">
<thead>
<tr>
{{each(i, columnDefinition) columns}}
<th title="${ columnDefinition.title }">${ columnDefinition.headerText }</th>
{{/each}}
</tr>
</thead>
<tbody>
{{each(i, row) itemsOnCurrentPage()}}
<tr>
{{each(j, columnDefinition) columns}}
<td>${ typeof columnDefinition.rowText == 'function' ? columnDefinition.rowText(row) : row[columnDefinition.rowText] }</td>
{{/each}}
</tr>
{{/each}}
</tbody>
</script>

View File

@ -64,12 +64,8 @@
// Render the page links
var pageLinksContainer = $("#"+allBindings.pageLinksId).get(0);
if (viewModel.pageLinksUpdateCallBack){
ko.renderTemplate(pageLinksTemplateName, viewModel, { templateEngine: templateEngine }, pageLinksContainer, "replaceNode")
.subscribe(viewModel.pageLinksUpdateCallBack);
} else {
ko.renderTemplate(pageLinksTemplateName, viewModel, { templateEngine: templateEngine }, pageLinksContainer, "replaceNode");
}
ko.renderTemplate(pageLinksTemplateName, viewModel, { templateEngine: templateEngine }, pageLinksContainer, "replaceNode")
.subscribe(viewModel.pageLinksUpdateCallBack?viewModel.pageLinksUpdateCallBack:function(){});
if (viewModel.pageLinksUpdateCallBack) viewModel.pageLinksUpdateCallBack();
}
};