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