WIP vaguely implement serialising query to url. lots of bugs.

pull/1765/head
Richard 10 years ago
parent 8476c5e64a
commit a4d4316788
  1. 25
      app/assets/javascripts/angular/helpers/url-params-helper.js
  2. 18
      app/assets/javascripts/angular/models/query.js
  3. 3
      app/assets/javascripts/angular/routing.js
  4. 8
      app/assets/javascripts/angular/work_packages/controllers/work-packages-list-controller.js
  5. 2
      app/assets/javascripts/angular/work_packages/directives/query-columns-directive.js
  6. 2
      app/assets/javascripts/angular/work_packages/directives/query-filter-directive.js
  7. 1
      app/assets/javascripts/angular/work_packages/directives/query-filters-directive.js
  8. 2
      app/assets/javascripts/angular/work_packages/directives/query-form-directive.js
  9. 2
      app/assets/javascripts/angular/work_packages/directives/work-package-group-sums-directive.js
  10. 2
      app/assets/javascripts/angular/work_packages/directives/work-package-total-sums-directive.js
  11. 2
      app/assets/javascripts/angular/work_packages/directives/work-packages-table-directive.js
  12. 2
      public/templates/work_packages.list.html

@ -66,21 +66,22 @@ angular.module('openproject.helpers')
}
if(query.filters && query.filters.length) {
paramsData.f = query.filters.map(function(filter) {
return {
var filterData = {
n: filter.name,
m: filter.modelName,
o: encodeURIComponent(filter.operator),
t: filter.type,
v: filter.values
t: filter.type
};
if(filter.values) {
angular.extend(filterData, { v: filter.values })
}
return filterData
});
}
// TODO: Pagination
return JSON.stringify(paramsData);
},
// Builds a Query object from the params so that we can use the existing query toParams method.
// Note: This is an almost pointless in-between stage only done so that we can have minimum length param names.
decodeQueryFromJsonParams: function(queryJson) {
var urlQuery = JSON.parse(queryJson);
// TODO: Catch parse error
@ -98,20 +99,24 @@ angular.module('openproject.helpers')
}
if(!!urlQuery.f) {
queryData.filters = urlQuery.f.map(function(urlFilter) {
return {
var filterData = {
name: urlFilter.n,
modelName: urlFilter.m,
operator: urlFilter.o,
type: urlFilter.t,
values: urlFilter.v
operator: decodeURIComponent(urlFilter.o),
type: urlFilter.t
};
if(urlFilter.v) {
var vs = Array.isArray(urlFilter.v) ? urlFilter.v : [urlFilter.v];
angular.extend(filterData, { values: vs });
}
return filterData;
});
}
if(!!urlQuery.t) {
queryData.sortCriteria = urlQuery.t;
}
return new Query(queryData);
return new Query(queryData, { rawFilters: true });
},
buildQueryExportOptions: function(query){

@ -39,7 +39,13 @@ angular.module('openproject.models')
this.filters = [];
this.groupBy = this.groupBy || '';
if(queryData.filters) this.setFilters(queryData.filters);
if(queryData.filters){
if(options.rawFilters) {
this.setRawFilters(queryData.filters);
} else {
this.setFilters(queryData.filters);
}
}
if(queryData.sortCriteria) this.setSortation(queryData.sortCriteria);
};
@ -165,6 +171,16 @@ angular.module('openproject.models')
}
},
setRawFilters: function(filters) {
if (filters){
var self = this;
this.filters = filters.map(function(filterData){
return new Filter(filterData);
});
}
},
/**
* @name isDefault
* @function

@ -57,7 +57,8 @@ angular.module('openproject')
.state('work-packages.list', {
url: "",
controller: 'WorkPackagesListController',
templateUrl: "/templates/work_packages.list.html"
templateUrl: "/templates/work_packages.list.html",
reloadOnSearch: false,
})
.state('work-packages.list.details', {
url: "/{workPackageId:[0-9]+}",

@ -117,7 +117,7 @@ angular.module('openproject.workPackages.controllers')
function afterQuerySetupCallback(query) {
$scope.showFiltersOptions = query.filters.length > 0;
$scope.updateBackUrl();
$scope.maintainUrlQueryState();
}
function setupWorkPackagesTable(json) {
@ -164,14 +164,16 @@ angular.module('openproject.workPackages.controllers')
// Updates
$scope.updateBackUrl = function(){
$scope.maintainUrlQueryState = function(){
var relativeUrl = "/work_packages";
if ($scope.projectIdentifier){
relativeUrl = "/projects/" + $scope.projectIdentifier + relativeUrl;
}
if($scope.query){
relativeUrl = relativeUrl + "?query=" + UrlParamsHelper.encodeQueryForJsonParams($scope.query);
var queryString = UrlParamsHelper.encodeQueryForJsonParams($scope.query);
$location.search('query', queryString);
relativeUrl = relativeUrl + "?query=" + queryString;
}
$scope.backUrl = relativeUrl;

@ -76,7 +76,7 @@ angular.module('openproject.workPackages.directives')
var newColumns = WorkPackagesTableHelper.selectColumnsByName(scope.columns, columnNames);
WorkPackageService.augmentWorkPackagesWithColumnsData(workPackages, newColumns, groupBy)
.then(scope.updateBackUrl);
.then(scope.maintainUrlQueryState);
}
}
};

@ -66,7 +66,7 @@ angular.module('openproject.workPackages.directives')
PaginationService.resetPage();
applyFilters();
scope.updateBackUrl();
scope.maintainUrlQueryState();
}
}
}, true);

@ -43,7 +43,6 @@ angular.module('openproject.workPackages.directives')
if (filterName) {
scope.query.addFilter(filterName);
scope.filterToBeAdded = undefined;
scope.updateBackUrl();
}
});

@ -73,7 +73,7 @@ angular.module('openproject.workPackages.directives')
if (!querySwitched(newProperties, oldProperties)) {
if (queryPropertiesChanged(newProperties, oldProperties)) {
scope.updateResults();
scope.updateBackUrl();
scope.maintainUrlQueryState();
}
}
}, true);

@ -48,7 +48,7 @@ angular.module('openproject.workPackages.directives')
scope.$watch('groupSums.length', function() {
// map columns to sums if the column data is a number
setSums();
scope.updateBackUrl();
scope.maintainUrlQueryState();
});
}

@ -64,7 +64,7 @@ angular.module('openproject.workPackages.directives')
scope.$watch(columnNames, function(columnNames, formerNames) {
if (!angular.equals(columnNames, formerNames) && !totalSumsFetched()) {
fetchTotalSums();
scope.updateBackUrl();
scope.maintainUrlQueryState();
}
}, true);
}

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

@ -122,7 +122,7 @@
total-sums="totalSums"
group-sums="groupSums"
update-results="updateResults()"
update-back-url="updateBackUrl">
maintain-url-query-state="maintainUrlQueryState">
</work-packages-table>
<table-pagination total-entries="totalEntries"

Loading…
Cancel
Save