source: main/trunk/model-interfaces-dev/heritage-nz/iframe/heritage-nz-dl_files/searchService.js@ 32796

Last change on this file since 32796 was 32796, checked in by davidb, 5 years ago

Initial set of files to provide look and feel of Heritage NZ site, plus SVN clickable map in an iframe

  • Property svn:executable set to *
File size: 2.6 KB
Line 
1(function (ng) {
2 angular.module('search')
3 .factory('SearchService', ['$http', function ($http) {
4 var Search = function (searchObject) {
5 this.search = searchObject.search;
6 this.pageSize = searchObject.pageSize;
7 this.siteSections = searchObject.siteSections;
8 this.includeDocuments = searchObject.includeDocuments;
9 this.dateFrom = searchObject.dateFrom;
10 this.dateTo = searchObject.dateTo;
11 this.pageNumber = 1;
12 this.resultsCount = 0;
13 this.pagedResultsCount = 0;
14 this.results = [];
15 this.busy = false;
16 this.isSearchExhausted = function () {
17 return (this.pagedResultsCount == this.resultsCount) && this.resultsCount > 0;
18 };
19 };
20
21 Search.prototype.nextPage = function () {
22 if (this.busy || this.isSearchExhausted()) {
23 return;
24 }
25
26 this.busy = true;
27
28 // Maps to our Web API search dto
29 var searchDto = angular.toJson({
30 Search: this.search,
31 SectionIds: this.siteSections != null ? this.siteSections : [],
32 PageNumber: this.pageNumber,
33 PageSize: this.pageSize,
34 DateFrom: getDate(this.dateFrom),
35 DateTo: getDate(this.dateTo),
36 IncludeDocuments: this.includeDocuments,
37 });
38
39 $http({ cache: false, dataType: 'json', url: "/api/cms/PostSearchQuery", method: 'POST', data: searchDto })
40 .success(function (data) {
41 this.resultsCount = data.Count;
42 var items = data.Results;
43 for (var i = 0; i < items.length; i++) {
44 this.results.push(items[i]);
45 }
46 this.pagedResultsCount = this.pagedResultsCount + items.length;
47 this.pageNumber = this.pageNumber + 1;
48 this.busy = false;
49 }.bind(this));
50
51 };
52
53 return {
54 GetInstance: function (searchData) {
55 return new Search(searchData);
56 }
57 };
58
59 function getDate(date) {
60 if (date instanceof Date) {
61 return date.toDateString();
62 }
63
64 return "";
65 }
66
67 }]);
68})(angular);
Note: See TracBrowser for help on using the repository browser.