Builing up export options meta in wp controller.

pull/1466/head
Richard 11 years ago
parent 0b86c4e574
commit cfbc0ca963
  1. 2
      app/assets/javascripts/angular/controllers/dialogs/export.js
  2. 17
      app/assets/javascripts/angular/helpers/url-params-helper.js
  3. 12
      app/controllers/api/v3/work_packages_controller.rb
  4. 3
      public/templates/work_packages/modals/export.html

@ -42,5 +42,5 @@ angular.module('openproject.workPackages.controllers')
var query = QueryService.getQuery();
this.closeMe = exportModal.deactivate;
this.exportOptions = UrlParamsHelper.buildQueryExportUrl(query);
this.exportOptions = UrlParamsHelper.buildQueryExportOptions(query);
}]);

@ -51,21 +51,30 @@ angular.module('openproject.helpers')
return parts.join('&');
},
buildQueryExportUrl: function(query){
buildQueryExportOptions: function(query){
// Note: This is all rather hard-codey
// The alternative would be to pass back export URLs from the server with the meta data but given that columns
// can be added/removed without making a further work packages index call the meta data wouldn't be up to date.
// Therefor I think it makes sense to build up the URL from the javascript query object and let the server build
// up the exact query again.
// up the exact query from the params.
var relativeUrl = "/work_packages";
if (query.project_id){
relativeUrl = "/projects/" + query.project_id + relativeUrl;
}
return query.exportFormats.map(function(format){
var url = relativeUrl + "." + format.format + "?" + "set_filter=1&";
if(format.flags){
angular.forEach(format.flags, function(flag){
url = url + flag + "=" + "true";
});
}
url = url + query.getQueryString();
return {
label: format,
url: relativeUrl + "." + format + "?" + "set_filter=1&" + query.getQueryString()
label: format.label,
format: format.format,
url: url
}
})
}

@ -179,9 +179,6 @@ module Api
def set_work_packages_meta_data(query, results, work_packages)
@display_meta = true
export_formats = ["atom", "pdf", "csv"]
export_formats.push("xls") if Redmine::Plugin.all.sort.map{|f| f.id}.include?(:openproject_xls_export)
@work_packages_meta_data = {
query: query.as_json(except: :filters, include: :filters),
columns: get_columns_for_json(query.columns),
@ -197,6 +194,15 @@ module Api
}
end
def export_formats
export_formats = [{ format: "atom", label: "Atom" },
{ format: "pdf", label: "PDF"},
{ format: "pdf", label: "PDF with description", flags: ["show_descriptions"]},
{ format: "csv", label: "CSV"}]
export_formats.push({ format: "xls", label: "XLS"}) if Redmine::Plugin.all.sort.map{|f| f.id}.include?(:openproject_xls_export)
export_formats
end
# TODO RS: Taken from work_packages_controller, not dry - move to application controller.
def per_page_param
case params[:format]

@ -6,8 +6,9 @@
<ul class="export-options">
<li ng-repeat="option in modal.exportOptions">
<a ng-href="{{ option.url }}">
<i class="icon-page-{{ option.label }} icon-big"></i>
<i class="icon-page-{{ option.format }} icon-big"></i>
</a>
<span>{{ option.label }}</span>
</li>
</ul>
</div>

Loading…
Cancel
Save