|
|
|
@ -31,10 +31,8 @@ angular.module('openproject.workPackages.controllers') |
|
|
|
|
.controller('WorkPackagesListController', [ |
|
|
|
|
'$scope', |
|
|
|
|
'$rootScope', |
|
|
|
|
'$q', |
|
|
|
|
'$location', |
|
|
|
|
'$stateParams', |
|
|
|
|
'$state', |
|
|
|
|
'$location', |
|
|
|
|
'latestTab', |
|
|
|
|
'I18n', |
|
|
|
|
'WorkPackagesTableService', |
|
|
|
@ -43,14 +41,12 @@ angular.module('openproject.workPackages.controllers') |
|
|
|
|
'QueryService', |
|
|
|
|
'PaginationService', |
|
|
|
|
'AuthorisationService', |
|
|
|
|
'WorkPackageLoadingHelper', |
|
|
|
|
'HALAPIResource', |
|
|
|
|
'INITIALLY_SELECTED_COLUMNS', |
|
|
|
|
'UrlParamsHelper', |
|
|
|
|
'OPERATORS_AND_LABELS_BY_FILTER_TYPE', |
|
|
|
|
function($scope, $rootScope, $q, $location, $stateParams, $state, latestTab, |
|
|
|
|
function($scope, $rootScope, $state, $location, latestTab, |
|
|
|
|
I18n, WorkPackagesTableService, |
|
|
|
|
WorkPackageService, ProjectService, QueryService, PaginationService, |
|
|
|
|
AuthorisationService, WorkPackageLoadingHelper, HALAPIResource, INITIALLY_SELECTED_COLUMNS, |
|
|
|
|
AuthorisationService, UrlParamsHelper, |
|
|
|
|
OPERATORS_AND_LABELS_BY_FILTER_TYPE) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -59,12 +55,19 @@ angular.module('openproject.workPackages.controllers') |
|
|
|
|
$scope.operatorsAndLabelsByFilterType = OPERATORS_AND_LABELS_BY_FILTER_TYPE; |
|
|
|
|
$scope.disableFilters = false; |
|
|
|
|
$scope.disableNewWorkPackage = true; |
|
|
|
|
var queryParams = $location.search().query_props; |
|
|
|
|
|
|
|
|
|
var fetchWorkPackages; |
|
|
|
|
if($scope.query_id){ |
|
|
|
|
fetchWorkPackages = WorkPackageService.getWorkPackagesByQueryId($scope.projectIdentifier, $scope.query_id); |
|
|
|
|
if(queryParams) { |
|
|
|
|
// Attempt to build up query from URL params
|
|
|
|
|
fetchWorkPackages = fetchWorkPackagesFromUrlParams(queryParams); |
|
|
|
|
} else if($state.params.query_id) { |
|
|
|
|
// Load the query by id if present
|
|
|
|
|
fetchWorkPackages = WorkPackageService.getWorkPackagesByQueryId($scope.projectIdentifier, $state.params.query_id); |
|
|
|
|
} else { |
|
|
|
|
fetchWorkPackages = WorkPackageService.getWorkPackagesFromUrlQueryParams($scope.projectIdentifier, $location); |
|
|
|
|
// Clear the cached query and load the default
|
|
|
|
|
QueryService.clearQuery(); |
|
|
|
|
fetchWorkPackages = WorkPackageService.getWorkPackages($scope.projectIdentifier); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$scope.settingUpPage = fetchWorkPackages // put promise in scope for cg-busy
|
|
|
|
@ -76,6 +79,28 @@ angular.module('openproject.workPackages.controllers') |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function fetchWorkPackagesFromUrlParams(queryParams) { |
|
|
|
|
try { |
|
|
|
|
var queryData = UrlParamsHelper.decodeQueryFromJsonParams($state.params.query_id, queryParams); |
|
|
|
|
var queryFromParams = new Query(queryData, { rawFilters: true }); |
|
|
|
|
|
|
|
|
|
return WorkPackageService.getWorkPackages($scope.projectIdentifier, queryFromParams); |
|
|
|
|
} catch(e) { |
|
|
|
|
$scope.$emit('flashMessage', { |
|
|
|
|
isError: true, |
|
|
|
|
text: I18n.t('js.work_packages.query.errors.unretrievable_query') |
|
|
|
|
}); |
|
|
|
|
clearUrlQueryParams(); |
|
|
|
|
|
|
|
|
|
return WorkPackageService.getWorkPackages($scope.projectIdentifier); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function clearUrlQueryParams() { |
|
|
|
|
$location.search('query_props', null); |
|
|
|
|
$location.search('query_id', null); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function fetchProjectTypesAndQueries() { |
|
|
|
|
if ($scope.projectIdentifier) { |
|
|
|
|
ProjectService.getProject($scope.projectIdentifier) |
|
|
|
@ -98,21 +123,24 @@ angular.module('openproject.workPackages.controllers') |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function initQuery(metaData) { |
|
|
|
|
var storedQuery = QueryService.getQuery(); |
|
|
|
|
var queryData = metaData.query, |
|
|
|
|
columnData = metaData.columns; |
|
|
|
|
|
|
|
|
|
if (storedQuery && $stateParams.query_id !== null && storedQuery.id === $scope.query_id) { |
|
|
|
|
$scope.query = storedQuery; |
|
|
|
|
} else { |
|
|
|
|
var queryData = metaData.query, |
|
|
|
|
columnData = metaData.columns; |
|
|
|
|
var cachedQuery = QueryService.getQuery(); |
|
|
|
|
var urlQueryId = $state.params.query_id; |
|
|
|
|
|
|
|
|
|
$scope.query = QueryService.initQuery($scope.query_id, queryData, columnData, metaData.export_formats, afterQuerySetupCallback); |
|
|
|
|
if (cachedQuery && urlQueryId && cachedQuery.id == urlQueryId) { |
|
|
|
|
// Augment current unsaved query with url param data
|
|
|
|
|
var updateData = angular.extend(queryData, { columns: columnData }) |
|
|
|
|
$scope.query = QueryService.updateQuery(updateData, afterQuerySetupCallback); |
|
|
|
|
} else { |
|
|
|
|
// Set up fresh query from retrieved query meta data
|
|
|
|
|
$scope.query = QueryService.initQuery($state.params.query_id, queryData, columnData, metaData.export_formats, afterQuerySetupCallback); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function afterQuerySetupCallback(query) { |
|
|
|
|
$scope.showFiltersOptions = query.filters.length > 0; |
|
|
|
|
$scope.updateBackUrl(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function setupWorkPackagesTable(json) { |
|
|
|
@ -145,9 +173,6 @@ angular.module('openproject.workPackages.controllers') |
|
|
|
|
$scope.workPackageCountByGroup = meta.work_package_count_by_group; |
|
|
|
|
$scope.totalEntries = QueryService.getTotalEntries(); |
|
|
|
|
|
|
|
|
|
// back url
|
|
|
|
|
$scope.updateBackUrl(); |
|
|
|
|
|
|
|
|
|
// Authorisation
|
|
|
|
|
AuthorisationService.initModelAuth("work_package", meta._links); |
|
|
|
|
AuthorisationService.initModelAuth("query", meta.query._links); |
|
|
|
@ -162,21 +187,30 @@ angular.module('openproject.workPackages.controllers') |
|
|
|
|
|
|
|
|
|
// Updates
|
|
|
|
|
|
|
|
|
|
$scope.updateBackUrl = function(){ |
|
|
|
|
// Easier than trying to extract it from $location
|
|
|
|
|
$scope.maintainUrlQueryState = function(){ |
|
|
|
|
var relativeUrl = "/work_packages"; |
|
|
|
|
if ($scope.projectIdentifier){ |
|
|
|
|
relativeUrl = "/projects/" + $scope.projectIdentifier + relativeUrl; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if($scope.query){ |
|
|
|
|
relativeUrl = relativeUrl + "#?" + $scope.query.getQueryString(); |
|
|
|
|
if($scope.query) { |
|
|
|
|
var queryString = UrlParamsHelper.encodeQueryJsonParams($scope.query); |
|
|
|
|
$location.search('query_props', queryString); |
|
|
|
|
relativeUrl = relativeUrl + "?query_props=" + queryString; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$scope.backUrl = relativeUrl; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
$scope.updateResults = function() { |
|
|
|
|
$scope.loadQuery = function(queryId) { |
|
|
|
|
// Clear unsaved changes to current query
|
|
|
|
|
clearUrlQueryParams(); |
|
|
|
|
|
|
|
|
|
// Load new query
|
|
|
|
|
$state.go('work-packages.list', { query_id: queryId }); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
function updateResults() { |
|
|
|
|
$scope.$broadcast('openproject.workPackages.updateResults'); |
|
|
|
|
|
|
|
|
|
$scope.refreshWorkPackages = WorkPackageService.getWorkPackages($scope.projectIdentifier, $scope.query, PaginationService.getPaginationOptions()) |
|
|
|
@ -185,10 +219,6 @@ angular.module('openproject.workPackages.controllers') |
|
|
|
|
return $scope.refreshWorkPackages; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
$scope.setQueryState = function(query_id) { |
|
|
|
|
$state.go('work-packages.list', { query_id: query_id }); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// More
|
|
|
|
|
|
|
|
|
|
function serviceErrorHandler(data) { |
|
|
|
@ -208,6 +238,23 @@ angular.module('openproject.workPackages.controllers') |
|
|
|
|
$scope.selectedTitle = queryName || I18n.t('js.toolbar.unselected_title'); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
$rootScope.$on('queryStateChange', function(event, message) { |
|
|
|
|
$scope.maintainUrlQueryState(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
$rootScope.$on('workPackagesRefreshRequired', function(event, message) { |
|
|
|
|
updateResults(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
$rootScope.$on('queryClearRequired', function(event, message) { |
|
|
|
|
$location.search('query_props', null); |
|
|
|
|
if($location.search().query_id) { |
|
|
|
|
$location.search('query_id', null); |
|
|
|
|
} else { |
|
|
|
|
initialSetup(); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
$scope.openLatestTab = function() { |
|
|
|
|
$state.go(latestTab.getStateName(), { workPackageId: $scope.preselectedWorkPackageId }); |
|
|
|
|
}; |
|
|
|
|