Commit 8f64e6af by dileep bhimineni

changes for HDPDGI-41 and HDPDGI-40

parent fe28c005
......@@ -29,12 +29,6 @@ angular.module('dgc.search').controller('SearchController', ['$scope', '$locatio
$scope.itemsPerPage = 10;
$scope.filteredResults = [];
$scope.resultRows = [];
$scope.$on('$stateChangeStart', function(event, toState) {
if (toState.resolve) {
$scope.loading = true;
}
});
$scope.setPage = function(pageNo) {
$scope.currentPage = pageNo;
};
......@@ -48,43 +42,56 @@ angular.module('dgc.search').controller('SearchController', ['$scope', '$locatio
SearchResource.search({
query: query
}, function searchSuccess(response) {
$scope.querySuceess = true;
$scope.resultCount = response.count;
$scope.results = response.results;
$scope.resultRows = $scope.results.rows;
$scope.totalItems = $scope.resultCount;
$scope.$watch('currentPage + itemsPerPage', function() {
var begin = (($scope.currentPage - 1) * $scope.itemsPerPage),
end = begin + $scope.itemsPerPage;
$scope.searchTypesAvailable = $scope.typeAvailable();
if ($scope.searchTypesAvailable) {
$scope.searchMessage = 'loading results...';
$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);
$scope.transformedResults = {};
$scope.dataTransitioned = false ;
if(response.results.dataType.typeName.indexOf('__') === 0) {
$scope.dataTransitioned = true ;
var attrDef = response.results.dataType.attributeDefinitions;
angular.forEach(attrDef, function(value) {
if(value.dataTypeName === '__IdType') {
$scope.searchKey = value.name;
}
});
$scope.transformedResults = $scope.filterResults();
} else {
$scope.transformedResults = $scope.resultRows;
}
if ($scope.results.rows)
$scope.searchMessage = $scope.resultCount + ' results matching your search query ' + $scope.query + ' were found';
else
$scope.searchMessage = '0 results matching your search query ' + $scope.query + ' were found';
$scope.$watch('currentPage + itemsPerPage', function() {
var begin = (($scope.currentPage - 1) * $scope.itemsPerPage),
end = begin + $scope.itemsPerPage;
$scope.filteredResults = $scope.transformedResults.slice(begin, end);
$scope.pageCount = function() {
return Math.ceil($scope.resultCount / $scope.itemsPerPage);
};
if ($scope.results.length < 1) {
NotificationService.error('No Result found', false);
}
});
}, function searchError(err) {
NotificationService.error('Error occurred during executing search query, error status code = ' + err.status + ', status text = ' + err.statusText, false);
});
$state.go('search', {
query: query
}, {
location: 'replace'
});
};
$scope.typeAvailable = function() {
if ($scope.results.dataType) {
return $scope.types.indexOf($scope.results.dataType.typeName && $scope.results.dataType.typeName.toLowerCase()) > -1;
}
$scope.filterResults = function() {
var res = [];
angular.forEach($scope.resultRows, function(value,key) {
res.push( value[$scope.searchKey] );
});
return res;
};
$scope.doToggle = function($event, el) {
this.isCollapsed = !el;
......@@ -93,19 +100,19 @@ angular.module('dgc.search').controller('SearchController', ['$scope', '$locatio
var res = {};
var count = 0;
angular.forEach(items, function(value, key) {
if (typeof value !== 'object') {
if (typeof value !== 'object' && (key.indexOf('$$') < 0)) {
res[key] = value;
count++;
}
});
$scope.keyLength = count;
return res;
};
$scope.searchQuery = $location.search();
$scope.query = ($location.search()).query;
if ($scope.query) {
$scope.search($scope.query);
}
}
}
]);
......@@ -39,7 +39,7 @@
<div data-ng-include="'/modules/navigation/views/navigation.html'"></div>
<div class="col-lg-9" >
<div class="col-lg-9" ng-show='resultCount > 0' >
<h4 ng-show="searchMessage">{{searchMessage}}</h4>
<ul class="list-unstyled">
......@@ -47,7 +47,7 @@
<h4><a data-ui-sref="details({id:result['$id$'].id})">{{result.name}}</a></h4>
<p>{{result.description}}</p>
<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) || $last ) ? '' : ', '}}</span>
</span>
<div collapse="isCollapsed">
<span ng-repeat="(key, value) in filterSearchResults(result)" >
......@@ -57,11 +57,11 @@
<a href ng-show="isCollapsed && (keyLength > 4)" ng-click="doToggle($event,isCollapsed)">..show more</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>
<div data-ng-if="!searchTypesAvailable" data-ng-include="'/modules/search/views/types/guid.html'"></div>
<h5 ng-show="!dataTransitioned">Tags : <a ng-repeat="(key, value) in result['$traits$']" data-ui-sref="search({query: key})">{{key}}</a> </h5>
</li>
</ul>
<div class="resultsPagination" ng-show='filteredResults.length > 0'>
<div class="resultsPagination" ng-show='resultCount > 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