}
SearchRequest=function(){
+
+ this.queryTerms=ko.observable();
+
//private String groupId;
this.groupId=ko.observable();
this.className=ko.observable();
//private List<String> repositories = new ArrayList<String>();
- this.repositories=ko.observableArray();
+ this.repositories=ko.observableArray([]);
//private String bundleVersion;
this.bundleVersion=ko.observable();
this.includePomArtifacts=ko.observable(false);
}
-
- SearchParameters=function(){
- this.basicQueryString=ko.observable();
- this.searchRequest=ko.observable(new SearchRequest());
+ ResultViewModel=function(artifacts){
+ this.artifacts=artifacts;
}
+
SearchViewModel=function(){
- this.searchParameters=ko.observable(new SearchParameters());
+ this.searchRequest=ko.observable(new SearchRequest());
this.observableRepoIds=ko.observableArray([]);
this.selectedRepoIds=[];
basicSearch=function(){
//$.log("query:"+this.searchParameters().basicQueryString());
//$.log("repoIds:"+this.selectedRepoIds);
- var queryTerm=this.searchParameters().basicQueryString();
+ var queryTerm=this.searchRequest().queryTerms();
if (!queryTerm || $.trim(queryTerm).length<1){
$.log("empty");
var errorList=[{
// cleanup previours error message
customShowError("#main-content #search-basic-form", null, null, []);
}
- $("#main-content #search-results" ).html(mediumSpinnerImg());
- activateSearchResultsTab();
+ var searchResults=$("#main-content #search-results" );
+ searchResults.html(mediumSpinnerImg());
+ this.searchRequest().repositories=this.selectedRepoIds;
+ $.ajax("restServices/archivaServices/searchService/quickSearchWithRepositories",
+ {
+ type: "POST",
+ data: "{\"searchRequest\": " + ko.toJSON(this.searchRequest)+"}",
+ 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();
+ },
+ error: function(data) {
+ var res = $.parseJSON(data.responseText);
+ displayRestError(res);
+ }
+ }
+ );
+
}
<label class="control-label" for="search-terms"></label>
<div class="controls">
<input type="text" class="input-medium search-query" id="search-terms" name="search-terms" size="50"
- data-bind="value: searchParameters().basicQueryString" placeholder="${$.i18n.prop('search.artifact.search.form.query.terms')}"/>
+ data-bind="value: searchRequest().queryTerms" placeholder="${$.i18n.prop('search.artifact.search.form.query.terms')}"/>
</div>
</div>
<button type="submit" class="btn" data-bind="click: basicSearch">Search</button>
<label class="control-label" for="groupId">${$.i18n.prop('search.artifact.search.form.query.groupId')}</label>
<div class="controls">
<input type="text" class="input-medium search-query" id="groupId" name="groupId" size="50"
- data-bind="value: searchParameters().searchRequest().groupId"/>
+ data-bind="value: searchRequest().groupId"/>
</div>
</div>
<div class="control-group">
<label class="control-label" for="artifactId">${$.i18n.prop('search.artifact.search.form.query.artifactId')}</label>
<div class="controls">
<input type="text" class="input-medium search-query" id="artifactId" name="artifactId" size="50"
- data-bind="value: searchParameters().searchRequest().artifactId"/>
+ data-bind="value: searchRequest().artifactId"/>
</div>
</div>
<div class="control-group">
<label class="control-label" for="artifactId">${$.i18n.prop('search.artifact.search.form.query.version')}</label>
<div class="controls">
<input type="text" class="input-medium search-query" id="version" name="version" size="50"
- data-bind="value: searchParameters().searchRequest().version"/>
+ data-bind="value: searchRequest().version"/>
</div>
</div>
<div class="control-group">
<label class="control-label" for="artifactId">${$.i18n.prop('search.artifact.search.form.query.packaging')}</label>
<div class="controls">
<input type="text" class="input-medium search-query" id="packaging" name="packaging" size="50"
- data-bind="value: searchParameters().searchRequest().packaging"/>
+ data-bind="value: searchRequest().packaging"/>
</div>
</div>
<div class="control-group">
<label class="control-label" for="artifactId">${$.i18n.prop('search.artifact.search.form.query.className')}</label>
<div class="controls">
<input type="text" class="input-medium search-query" id="className" name="className" size="50"
- data-bind="value: searchParameters().searchRequest().className"/>
+ data-bind="value: searchRequest().className"/>
</div>
</div>
</fieldset>
</div>
</div>
-</script>
\ No newline at end of file
+</script>
+
+<script id="search-results-view-tmpl" type="text/html">
+ {{if artifacts.length==0}}
+ no results
+ {{else}}
+ results
+ {{/if}}
+</script>