OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openproject/app/assets/javascripts/angular/models/query.js

79 lines
2.0 KiB

angular.module('openproject.models')
.factory('Query', ['Filter', function(Filter) {
Query = function (data) {
angular.extend(this, data);
if (this.filters === undefined) this.filters = [];
};
Query.prototype = {
toParams: function() {
return angular.extend.apply(this, [
{
'f[]': this.getFilterNames(this.getActiveConfiguredFilters()),
'c[]': this.selectedColumns.map(function(column) {
return column.name;
}),
'group_by': this.group_by
}].concat(this.getActiveConfiguredFilters().map(function(filter) {
return filter.toParams();
}))
);
},
getFilterNames: function(filters) {
return (filters || this.filters).map(function(filter){
return filter.name;
});
},
getFilterByName: function(filterName) {
return this.filters.filter(function(filter){
return filter.name === filterName;
}).first();
},
addFilter: function(filterName, options) {
var filter = this.getFilterByName(filterName);
if (filter) {
filter.deactivated = false;
} else {
this.filters.push(new Filter(angular.extend({name: filterName}, options)));
}
},
removeFilter: function(filterName) {
this.filters.splice(this.getFilterNames().indexOf(filterName), 1);
},
deactivateFilter: function(filter, loading) {
if (!loading) filter.deactivated = true;
},
getAvailableFilterValues: function(filterName) {
return this.available_work_package_filters[filterName].values;
},
getFilterType: function(filterName) {
return this.available_work_package_filters[filterName].type;
},
getActiveFilters: function() {
return this.filters.filter(function(filter){
return !filter.deactivated;
});
},
getActiveConfiguredFilters: function() {
return this.getActiveFilters().filter(function(filter){
return filter.isConfigured();
});
}
};
return Query;
}]);