Commit 6b9acc52 by dileep bhimineni

changes for search results and paginations

parent 5b415fe0
...@@ -26,35 +26,57 @@ angular.module('dgc.search').controller('SearchController', ['$scope', '$locatio ...@@ -26,35 +26,57 @@ angular.module('dgc.search').controller('SearchController', ['$scope', '$locatio
$scope.resultCount=0; $scope.resultCount=0;
$scope.isCollapsed = true; $scope.isCollapsed = true;
$scope.currentPage = 1; $scope.currentPage = 1;
$scope.numPerPage = 10; $scope.itemsPerPage = 10
$scope.itemsPerPage = 2; $scope.totalItems = 40;
$scope.maxSize = 5; $scope.setPage = function (pageNo) {
$scope.$watch("currentPage + numPerPage", function() { $scope.currentPage = pageNo;
var begin = (($scope.currentPage - 1) * $scope.numPerPage); };
var end = begin + $scope.numPerPage;
$scope.filteredResults = $scope.results.slice(begin, end);
});
$scope.search = function(query) { $scope.search = function(query) {
$scope.results = []; $scope.results = [];
NotificationService.reset(); NotificationService.reset();
$scope.limit = 4; $scope.limit = 4;
SearchResource.search({query:query}, function searchSuccess(response) { SearchResource.search({query:query}, function searchSuccess(response) {
$scope.results = response.results;
$scope.resultCount=response.count; $scope.resultCount=response.count;
if ($scope.results.length < 1) { $scope.results = response.results;
NotificationService.error('No Result found', false); $scope.resultRows = $scope.results.rows;
} $scope.totalItems = $scope.resultCount;
$state.go('search.results', {query:query}, { $scope.$watch('currentPage + itemsPerPage', function() {
location: 'replace' var begin = (($scope.currentPage - 1) * $scope.itemsPerPage),
end = begin + $scope.itemsPerPage;
$scope.searchTypesAvailable = $scope.typeAvailable();
if ($scope.searchTypesAvailable) {
$scope.searchMessage = 'searching...';
$scope.filteredResults = $scope.resultRows.slice(begin, end);
$scope.pageCount = function () {
return Math.ceil($scope.resultCount / $scope.itemsPerPage);
};
if ($scope.results.rows)
$scope.searchMessage = $scope.results.rows.length +' results matching your search query '+ $scope.query +' were found';
else
$scope.searchMessage = '0 results matching your search query '+ $scope.query +' were found';
if ($scope.results.length < 1) {
NotificationService.error('No Result found', false);
}
} else {
$scope.searchMessage = '0 results matching your search query '+ $scope.query +' were found';
}
$state.go('search.results', {query:query}, {
location: 'replace'
});
}); });
}, function searchError(err) { }, function searchError(err) {
NotificationService.error('Error occurred during executing search query, error status code = ' + err.status + ', status text = ' + err.statusText, false); NotificationService.error('Error occurred during executing search query, error status code = ' + err.status + ', status text = ' + err.statusText, false);
}); });
}; };
$scope.typeAvailable = function() { $scope.typeAvailable = function() {
return $scope.types.indexOf(this.results.dataType.typeName && this.results.dataType.typeName.toLowerCase()) > -1; console.log($scope.results.dataType);
if($scope.results.dataType) {
return $scope.types.indexOf($scope.results.dataType.typeName && $scope.results.dataType.typeName.toLowerCase()) > -1;
}
}; };
$scope.doToggle = function($event,el) { $scope.doToggle = function($event,el) {
...@@ -62,14 +84,21 @@ angular.module('dgc.search').controller('SearchController', ['$scope', '$locatio ...@@ -62,14 +84,21 @@ angular.module('dgc.search').controller('SearchController', ['$scope', '$locatio
}; };
$scope.filterSearchResults = function(items) { $scope.filterSearchResults = function(items) {
var res = {}; var res = {};
var count = 0;
angular.forEach(items, function(value, key) { angular.forEach(items, function(value, key) {
if(typeof value !== 'object') if(typeof value !== 'object') {
res[key] = value; res[key] = value;
count++;
}
}); });
$scope.keyLength = count;
return res; return res;
}; };
$scope.query=$stateParams.query; $scope.searchQuery = $location.search();
$scope.query=($location.search()).query;
if ($scope.query) { if ($scope.query) {
$scope.searchMessage = 'searching...';
$scope.search($scope.query); $scope.search($scope.query);
} }
} }
......
...@@ -28,7 +28,7 @@ angular.module('dgc.search').config(['$stateProvider', ...@@ -28,7 +28,7 @@ angular.module('dgc.search').config(['$stateProvider',
templateUrl: '/modules/search/views/search.html', templateUrl: '/modules/search/views/search.html',
controller:'SearchController' controller:'SearchController'
}).state('search.results', { }).state('search.results', {
url: '/:query', url: '?query',
templateUrl: '/modules/search/views/searchResult.html', templateUrl: '/modules/search/views/searchResult.html',
controller:'SearchController' controller:'SearchController'
}); });
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
<div data-ng-include="'/modules/navigation/views/navigation.html'"></div> <div data-ng-include="'/modules/navigation/views/navigation.html'"></div>
<div class="col-lg-9" data-ui-view=""></div> <div class="col-lg-9" data-ui-view="" style="min-height: 1350px;"></div>
</div> </div>
</div> </div>
</div> </div>
...@@ -15,32 +15,34 @@ ...@@ -15,32 +15,34 @@
~ See the License for the specific language governing permissions and ~ See the License for the specific language governing permissions and
~ limitations under the License. ~ limitations under the License.
--> -->
<!--
<h4 ng-show='results.rows.length > 0'>{{results.rows.length}} results matching your search query "{{query}}" were found</h4>
<h4 ng-show='results.rows.length == "0"'>searching .....</h4>
<h4 ng-show='!(results.rows)'>0 results matching your search query "{{query}}" were found</h4>-->
<h4 ng-show='resultCount > 0'>{{resultCount}} results matching your search query "{{query}}" were found</h4> <h4 ng-show="searchMessage">{{searchMessage}}</h4>
<h4 ng-show='resultCount == "0"'>searching .....</h4>
<ul class="list-unstyled"> <ul class="list-unstyled">
<li ng-repeat="result in results.rows" class="searchresults"> <li ng-repeat="result in filteredResults" class="searchresults">
<div data-ng-if="typeAvailable()"> <h4><a data-ui-sref="details({id:result['$id$'].id})">{{result.name}}</a></h4>
<h4><a data-ui-sref="details({id:result['$id$'].id})">{{result.name}}</a></h4>
<p>{{result.description}}</p> <p>{{result.description}}</p>
<span ng-repeat="(key, value) in filterSearchResults(result)" > <span ng-repeat="(key, value) in filterSearchResults(result)" >
<span ng-show="$index < 4"><b>{{key}}: </b>{{value}}{{$index+1 === limit ? '' : ', '}}</span> <span ng-show="$index < 4"><b>{{key}}: </b>{{value}}{{$index+1 === limit ? '' : ', '}}</span>
</span> </span>
<div collapse="isCollapsed"> <div collapse="isCollapsed">
<span class="well well-lg"><span ng-repeat="(key, value) in filterSearchResults(result)" > <span ng-repeat="(key, value) in filterSearchResults(result)" >
<span ng-show="$index > 4"><b>{{key}}: </b>{{value}}{{$last ? '' : ', '}}</span> <span ng-show="$index > 4"><b>{{key}}: </b>{{value}}{{$last ? '' : ', '}}</span>
</span></span> </span>
</div> </div>
<a href="javascript: void(0);" ng-show="isCollapsed" ng-click="doToggle($event,isCollapsed)">..show more</a> <a href ng-show="isCollapsed && (keyLength > 4)" ng-click="doToggle($event,isCollapsed)">..show more</a>
<a href="javascript: void(0);" ng-show="!isCollapsed" ng-click="doToggle($event,isCollapsed)">..show less</a> <a href ng-show="!isCollapsed" ng-click="doToggle($event,isCollapsed)">..show less</a>
<h5>Tags : <a ng-repeat="(key, value) in result['$traits$']" data-ui-sref="search.results({query: key})">{{key}}</a> </h5> <h5>Tags : <a ng-repeat="(key, value) in result['$traits$']" data-ui-sref="search.results({query: key})">{{key}}</a> </h5>
</div> <div data-ng-if="!searchTypesAvailable" data-ng-include="'/modules/search/views/types/guid.html'"></div>
<div data-ng-if="!typeAvailable()" data-ng-include="'/modules/search/views/types/guid.html'"></div>
</li> </li>
</ul> </ul>
<div ng-show='resultCount > 0'><pagination total-items="totalItems" ng-model="currentPage" ng-change="pageChanged()"></pagination></div> <div ng-show='results.rows.length > 0'>
<pagination total-items="totalItems" items-per-page="itemsPerPage" ng-model="currentPage" ng-change="pageChanged()"></pagination>
<p>
</div>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment