Remove query params from ui-router and manually reload work packages.

pull/1765/head
Richard 10 years ago
parent 4c7e926530
commit 5374ae4b01
  1. 5
      app/assets/javascripts/angular/directives/components/table-pagination-directive.js
  2. 79
      app/assets/javascripts/angular/helpers/url-params-helper.js
  3. 2
      app/assets/javascripts/angular/routing.js
  4. 49
      app/assets/javascripts/angular/work_packages/controllers/work-packages-list-controller.js
  5. 1
      app/assets/javascripts/angular/work_packages/directives/query-filter-directive.js
  6. 27
      app/assets/javascripts/angular/work_packages/directives/query-form-directive.js
  7. 1
      app/assets/javascripts/angular/work_packages/directives/work-package-group-sums-directive.js
  8. 3
      app/assets/javascripts/angular/work_packages/directives/work-packages-table-directive.js
  9. 6
      public/templates/work_packages.list.html
  10. 15
      public/templates/work_packages/query_filters.html
  11. 3
      public/templates/work_packages/work_packages_table.html

@ -33,8 +33,7 @@ angular.module('openproject.uiComponents')
restrict: 'EA', restrict: 'EA',
templateUrl: '/templates/components/table_pagination.html', templateUrl: '/templates/components/table_pagination.html',
scope: { scope: {
totalEntries: '=', totalEntries: '='
updateResults: '&'
}, },
link: function(scope, element, attributes) { link: function(scope, element, attributes) {
scope.I18n = I18n; scope.I18n = I18n;
@ -53,7 +52,7 @@ angular.module('openproject.uiComponents')
updateCurrentRangeLabel(); updateCurrentRangeLabel();
updatePageNumbers(); updatePageNumbers();
scope.updateResults(); // update table scope.$emit('workPackagesRefreshRequired');
}; };
/** /**

@ -51,6 +51,7 @@ angular.module('openproject.helpers')
return parts.join('&'); return parts.join('&');
}, },
// TODO: Remove
encodeQueryForJsonParams: function(query) { encodeQueryForJsonParams: function(query) {
var paramsData = {}; var paramsData = {};
@ -84,6 +85,7 @@ angular.module('openproject.helpers')
return JSON.stringify(paramsData); return JSON.stringify(paramsData);
}, },
// TODO: Remove
encodeQueryForNonUpdateJsonParams: function(query) { encodeQueryForNonUpdateJsonParams: function(query) {
var paramsData = { var paramsData = {
c: query.columns.map(function(column) { return column.name; }) c: query.columns.map(function(column) { return column.name; })
@ -95,23 +97,67 @@ angular.module('openproject.helpers')
return JSON.stringify(paramsData); return JSON.stringify(paramsData);
}, },
decodeQueryFromJsonParams: function(queryId, requiringUpdateJson, nonRequiringUpdateJson) { encodeQueryAllJsonParams: function(query) {
var paramsData = {
c: query.columns.map(function(column) { return column.name; })
};
if(!!query.displaySums) {
paramsData.s = query.displaySums;
}
if(!!query.projectId) {
paramsData.p = query.projectId;
}
if(!!query.groupBy) {
paramsData.g = query.groupBy;
}
if(!!query.getSortation()) {
paramsData.t = query.getSortation().encode()
}
if(query.filters && query.filters.length) {
paramsData.f = query.filters.filter(function(filter) {
return !filter.deactivated;
})
.map(function(filter) {
var filterData = {
n: filter.name,
m: filter.modelName,
o: encodeURIComponent(filter.operator),
t: filter.type
};
if(filter.values) {
angular.extend(filterData, { v: filter.values })
}
return filterData
});
}
return JSON.stringify(paramsData);
},
decodeQueryFromJsonParams: function(queryId, updateJson) {
var queryData = {}; var queryData = {};
if(queryId) { if(queryId) {
queryData.id = queryId; queryData.id = queryId;
} }
if(requiringUpdateJson) { if(updateJson) {
var updateRequiringProperties = JSON.parse(requiringUpdateJson); var properties = JSON.parse(updateJson);
if(!!updateRequiringProperties.p) { if(!!properties.c) {
queryData.projectId = updateRequiringProperties.p; queryData.columns = properties.c.map(function(column) { return { name: column }; });
}
if(!!properties.s) {
queryData.displaySums = properties.s;
}
if(!!properties.p) {
queryData.projectId = properties.p;
} }
if(!!updateRequiringProperties.g) { if(!!properties.g) {
queryData.groupBy = updateRequiringProperties.g; queryData.groupBy = properties.g;
} }
if(!!updateRequiringProperties.f) { if(!!properties.f) {
queryData.filters = updateRequiringProperties.f.map(function(urlFilter) { queryData.filters = properties.f.map(function(urlFilter) {
var filterData = { var filterData = {
name: urlFilter.n, name: urlFilter.n,
modelName: urlFilter.m, modelName: urlFilter.m,
@ -125,19 +171,8 @@ angular.module('openproject.helpers')
return filterData; return filterData;
}); });
} }
if(!!updateRequiringProperties.t) { if(!!properties.t) {
queryData.sortCriteria = updateRequiringProperties.t; queryData.sortCriteria = properties.t;
}
}
if(nonRequiringUpdateJson) {
var nonUpdateRequiringProperties = JSON.parse(nonRequiringUpdateJson);
if(!!nonUpdateRequiringProperties.c) {
queryData.columns = nonUpdateRequiringProperties.c.map(function(column) { return { name: column }; });
}
if(!!nonUpdateRequiringProperties.s) {
queryData.displaySums = nonUpdateRequiringProperties.s;
} }
} }

@ -35,7 +35,7 @@ angular.module('openproject')
$stateProvider $stateProvider
.state('work-packages', { .state('work-packages', {
url: '{projectPath:.*}/work_packages?query_id&live_query', url: '{projectPath:.*}/work_packages?query_id',
abstract: true, abstract: true,
templateUrl: "/templates/work_packages.html", templateUrl: "/templates/work_packages.html",
controller: 'WorkPackagesController', controller: 'WorkPackagesController',

@ -55,13 +55,12 @@ angular.module('openproject.workPackages.controllers')
$scope.operatorsAndLabelsByFilterType = OPERATORS_AND_LABELS_BY_FILTER_TYPE; $scope.operatorsAndLabelsByFilterType = OPERATORS_AND_LABELS_BY_FILTER_TYPE;
$scope.disableFilters = false; $scope.disableFilters = false;
$scope.disableNewWorkPackage = true; $scope.disableNewWorkPackage = true;
var updateCausingParams = $state.params.live_query; var queryParams = $location.search().query_props;
var nonUpdeCausingParams = $location.search().passive_query;
var fetchWorkPackages; var fetchWorkPackages;
if(updateCausingParams || nonUpdeCausingParams) { if(queryParams) {
// Attempt to build up query from URL params // Attempt to build up query from URL params
fetchWorkPackages = fetchWorkPackagesFromUrlParams(updateCausingParams, nonUpdeCausingParams); fetchWorkPackages = fetchWorkPackagesFromUrlParams(queryParams);
} else if($state.params.query_id) { } else if($state.params.query_id) {
// Load the query by id if present // Load the query by id if present
fetchWorkPackages = WorkPackageService.getWorkPackagesByQueryId($scope.projectIdentifier, $state.params.query_id); fetchWorkPackages = WorkPackageService.getWorkPackagesByQueryId($scope.projectIdentifier, $state.params.query_id);
@ -80,9 +79,9 @@ angular.module('openproject.workPackages.controllers')
}); });
} }
function fetchWorkPackagesFromUrlParams(updateCausingParams, nonUpdeCausingParams) { function fetchWorkPackagesFromUrlParams(queryParams) {
try { try {
var queryData = UrlParamsHelper.decodeQueryFromJsonParams($state.params.query_id, updateCausingParams, nonUpdeCausingParams); var queryData = UrlParamsHelper.decodeQueryFromJsonParams($state.params.query_id, queryParams);
var queryFromParams = new Query(queryData, { rawFilters: true }); var queryFromParams = new Query(queryData, { rawFilters: true });
return WorkPackageService.getWorkPackages($scope.projectIdentifier, queryFromParams); return WorkPackageService.getWorkPackages($scope.projectIdentifier, queryFromParams);
@ -196,27 +195,22 @@ angular.module('openproject.workPackages.controllers')
} }
if($scope.query) { if($scope.query) {
var queryString = UrlParamsHelper.encodeQueryForNonUpdateJsonParams($scope.query); var queryString = UrlParamsHelper.encodeQueryAllJsonParams($scope.query);
$location.search('passive_query', queryString); $location.search('query_props', queryString);
relativeUrl = relativeUrl + "?passive_query=" + queryString; relativeUrl = relativeUrl + "?query_props=" + queryString;
var queryString = UrlParamsHelper.encodeQueryForJsonParams($scope.query); // var queryString = UrlParamsHelper.encodeQueryForNonUpdateJsonParams($scope.query);
$location.search('live_query', queryString); // $location.search('passive_query', queryString);
relativeUrl = relativeUrl + "?live_query=" + queryString; // relativeUrl = relativeUrl + "?passive_query=" + queryString;
// var queryString = UrlParamsHelper.encodeQueryForJsonParams($scope.query);
// $location.search('live_query', queryString);
// relativeUrl = relativeUrl + "?live_query=" + queryString;
} }
$scope.backUrl = relativeUrl; $scope.backUrl = relativeUrl;
}; };
$scope.updateResults = function() {
$scope.$broadcast('openproject.workPackages.updateResults');
$scope.refreshWorkPackages = WorkPackageService.getWorkPackages($scope.projectIdentifier, $scope.query, PaginationService.getPaginationOptions())
.then(setupWorkPackagesTable);
return $scope.refreshWorkPackages;
};
$scope.loadQuery = function(queryId) { $scope.loadQuery = function(queryId) {
// Clear unsaved changes to current query // Clear unsaved changes to current query
clearUrlQueryParams(); clearUrlQueryParams();
@ -225,6 +219,15 @@ angular.module('openproject.workPackages.controllers')
$state.go('work-packages.list', { query_id: queryId }); $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())
.then(setupWorkPackagesTable);
return $scope.refreshWorkPackages;
};
// More // More
function serviceErrorHandler(data) { function serviceErrorHandler(data) {
@ -246,6 +249,10 @@ angular.module('openproject.workPackages.controllers')
$rootScope.$on('queryStateChange', function(event, message) { $rootScope.$on('queryStateChange', function(event, message) {
$scope.maintainUrlQueryState(); $scope.maintainUrlQueryState();
});
$rootScope.$on('workPackagesRefreshRequired', function(event, message) {
updateResults();
}) })
$scope.openLatestTab = function() { $scope.openLatestTab = function() {

@ -65,6 +65,7 @@ angular.module('openproject.workPackages.directives')
if (filter.isConfigured() && (filterChanged(filter, oldFilter) || valueReset(filter, oldFilter))) { if (filter.isConfigured() && (filterChanged(filter, oldFilter) || valueReset(filter, oldFilter))) {
PaginationService.resetPage(); PaginationService.resetPage();
scope.$emit('queryStateChange'); scope.$emit('queryStateChange');
scope.$emit('workPackagesRefreshRequired');
} }
} }
}, true); }, true);

@ -51,10 +51,17 @@ angular.module('openproject.workPackages.directives')
var groupByChanged = currentProperties.groupBy !== formerProperties.groupBy; var groupByChanged = currentProperties.groupBy !== formerProperties.groupBy;
var sortElementsChanged = JSON.stringify(currentProperties.sortElements) !== JSON.stringify(formerProperties.sortElements); var sortElementsChanged = JSON.stringify(currentProperties.sortElements) !== JSON.stringify(formerProperties.sortElements);
return groupByChanged || sortElementsChanged;
}
function passiveQueryPropertiesChanged(currentProperties, formerProperties) {
if (formerProperties === undefined) return false;
var columnsChanged = JSON.stringify(currentProperties.columns) !== JSON.stringify(formerProperties.columns); var columnsChanged = JSON.stringify(currentProperties.columns) !== JSON.stringify(formerProperties.columns);
var displaySumsChanged = currentProperties.displaySums !== formerProperties.displaySums; var displaySumsChanged = currentProperties.displaySums !== formerProperties.displaySums;
return groupByChanged || sortElementsChanged || columnsChanged || displaySumsChanged; return columnsChanged || displaySumsChanged;
} }
function observedQueryProperties() { function observedQueryProperties() {
@ -66,7 +73,16 @@ angular.module('openproject.workPackages.directives')
return { return {
id: query.id, id: query.id,
groupBy: query.groupBy, groupBy: query.groupBy,
sortElements: query.sortation.sortElements, sortElements: query.sortation.sortElements
};
}
}
function passiveQueryProperties() {
var query = scope.query;
if (query !== undefined) {
return {
columns: query.columns, columns: query.columns,
displaySums: query.displaySums displaySums: query.displaySums
}; };
@ -77,9 +93,16 @@ angular.module('openproject.workPackages.directives')
if (!querySwitched(newProperties, oldProperties)) { if (!querySwitched(newProperties, oldProperties)) {
if (queryPropertiesChanged(newProperties, oldProperties)) { if (queryPropertiesChanged(newProperties, oldProperties)) {
scope.$emit('queryStateChange'); scope.$emit('queryStateChange');
scope.$emit('workPackagesRefreshRequired');
} }
} }
}, true); }, true);
scope.$watch(passiveQueryProperties, function(newProperties, oldProperties) {
if (passiveQueryPropertiesChanged(newProperties, oldProperties)) {
scope.$emit('queryStateChange');
}
}, true);
} }
}; };
} }

@ -49,6 +49,7 @@ angular.module('openproject.workPackages.directives')
// map columns to sums if the column data is a number // map columns to sums if the column data is a number
setSums(); setSums();
scope.$emit('queryStateChange'); scope.$emit('queryStateChange');
scope.$emit('workPackagesRefreshRequired');
}); });
} }

@ -50,8 +50,7 @@ angular.module('openproject.workPackages.directives')
groupByColumn: '=', groupByColumn: '=',
displaySums: '=', displaySums: '=',
totalSums: '=', totalSums: '=',
groupSums: '=', groupSums: '='
updateResults: '&'
}, },
link: function(scope, element, attributes) { link: function(scope, element, attributes) {
var activeSelectionBorderIndex; var activeSelectionBorderIndex;

@ -120,12 +120,10 @@
count-by-group="workPackageCountByGroup" count-by-group="workPackageCountByGroup"
display-sums="query.displaySums" display-sums="query.displaySums"
total-sums="totalSums" total-sums="totalSums"
group-sums="groupSums" group-sums="groupSums">
update-results="updateResults()">
</work-packages-table> </work-packages-table>
<table-pagination total-entries="totalEntries" <table-pagination total-entries="totalEntries">
update-results="updateResults()">
</table-pagination> </table-pagination>
</div> </div>
<modal-loading> <modal-loading>

@ -58,8 +58,7 @@
size="30" size="30"
type="text" type="text"
value="" value=""
ng-disabled="isLoading" ng-disabled="isLoading"/>
execute-on-enter="updateResults()"/>
<label ng-switch-when="string" <label ng-switch-when="string"
for="values_{{name}}" for="values_{{name}}"
class="hidden-for-sighted"> class="hidden-for-sighted">
@ -76,8 +75,7 @@
size="30" size="30"
type="text" type="text"
value="" value=""
ng-disabled="isLoading" ng-disabled="isLoading"/>
execute-on-enter="updateResults()"/>
<label ng-switch-when="'text'"for="values_{{name}}" class="hidden-for-sighted"> <label ng-switch-when="'text'"for="values_{{name}}" class="hidden-for-sighted">
{{ I18n.t('js.work_packages.description_enter_text') }} {{ I18n.t('js.work_packages.description_enter_text') }}
</label> </label>
@ -91,8 +89,7 @@
min="0" min="0"
type="number" type="number"
value="" value=""
ng-disabled="isLoading" ng-disabled="isLoading"/>
execute-on-enter="updateResults()"/>
<label ng-switch-when="'integer'" for="values_{{name}}" class="hidden-for-sighted"> <label ng-switch-when="'integer'" for="values_{{name}}" class="hidden-for-sighted">
{{ I18n.t('js.work_packages.description_enter_text') }} {{ I18n.t('js.work_packages.description_enter_text') }}
</label> </label>
@ -105,8 +102,7 @@
name="v[{{filter.name}}]" name="v[{{filter.name}}]"
size="3" size="3"
type="text" type="text"
ng-disabled="isLoading" ng-disabled="isLoading"/>
execute-on-enter="updateResults()"/>
<label ng-switch-when="date" for="values_{{name}}" class="hidden-for-sighted"> <label ng-switch-when="date" for="values_{{name}}" class="hidden-for-sighted">
{{ I18n.t('js.work_packages.time_relative.days') }} {{ I18n.t('js.work_packages.time_relative.days') }}
</label> </label>
@ -120,8 +116,7 @@
name="v[{{filter.name}}]" name="v[{{filter.name}}]"
size="3" size="3"
type="text" type="text"
ng-disabled="isLoading" ng-disabled="isLoading"/>
execute-on-enter="updateResults()"/>
<label ng-switch-when="date_past" for="values_{{name}}" class="hidden-for-sighted"> <label ng-switch-when="date_past" for="values_{{name}}" class="hidden-for-sighted">
{{ I18n.t('js.work_packages.time_relative.days') }} {{ I18n.t('js.work_packages.time_relative.days') }}
</label> </label>

@ -24,8 +24,7 @@
target="ColumnContextMenu" target="ColumnContextMenu"
locals="columns, column" locals="columns, column"
sortable="true" sortable="true"
query="query" query="query"/>
update-results="updateResults()"/>
<th sort-header ng-repeat="column in columns" <th sort-header ng-repeat="column in columns"
has-dropdown-menu has-dropdown-menu

Loading…
Cancel
Save