Add url params helper (WIP)

TODO test it
pull/1263/head
Till Breuer 11 years ago
parent 39b38e439b
commit 15f1d45544
  1. 70
      app/assets/javascripts/angular/helpers/url-params-helper.js
  2. 1
      karma.conf.js

@ -0,0 +1,70 @@
//-- copyright
// OpenProject is a project management system.
// Copyright (C) 2012-2014 the OpenProject Foundation (OPF)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License version 3.
//
// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
// Copyright (C) 2006-2013 Jean-Philippe Lang
// Copyright (C) 2010-2013 the ChiliProject Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// See doc/COPYRIGHT.rdoc for more details.
//++
angular.module('openproject.helpers')
.service('UrlParamsHelper', [function() {
var UrlParamsHelper = {
getConvertedParams: function(object) {
var params = {};
angular.forEach(object, function(value, key) {
if (Array.isArray(value)) {
params[key + '[]'] = value;
} else {
params[key] = value;
}
});
return params;
},
// copied from angular buildUrl
getRailsCompliantQueryString: function(params) {
if (!params) return;
var parts = [];
angular.forEach(UrlParamsHelper.getConvertedParams(params), function(value, key) {
if (!value) return;
if (!Array.isArray(value)) value = [value];
angular.forEach(value, function(v) {
if (v !== null && typeof v === 'object') {
v = toJson(v);
}
parts.push(encodeURIComponent(key) + '=' +
encodeURIComponent(v));
});
});
return parts.join('&');
}
};
return UrlParamsHelper;
}]);

@ -40,6 +40,7 @@ module.exports = function(config) {
'app/assets/javascripts/angular/helpers/work-package-context-menu-helper.js', 'app/assets/javascripts/angular/helpers/work-package-context-menu-helper.js',
'app/assets/javascripts/angular/helpers/timeline-table-helper.js', 'app/assets/javascripts/angular/helpers/timeline-table-helper.js',
'app/assets/javascripts/angular/helpers/function-decorators.js', 'app/assets/javascripts/angular/helpers/function-decorators.js',
'app/assets/javascripts/angular/helpers/url-params-helper.js',
'app/assets/javascripts/angular/filters/work-packages-filters.js', 'app/assets/javascripts/angular/filters/work-packages-filters.js',

Loading…
Cancel
Save