diff --git a/CHANGELOG b/CHANGELOG index 2b454cd1a..cfb194778 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -30,7 +30,9 @@ Motions: - Reworked DOCX export parser and added comments to DOCX [#3258]. - New PDF export for personal note and comments [#3239]. - Bugfix: Creating colliding change recommendation is now prevented - on server side [#3304] + on server side [#3304]. +- Added config value for customize sorting of category list in + pdf/docx export [#3329]. Users: - User without permission to see users can now see agenda item speakers, diff --git a/openslides/motions/config_variables.py b/openslides/motions/config_variables.py index 3f79d243b..333d49567 100644 --- a/openslides/motions/config_variables.py +++ b/openslides/motions/config_variables.py @@ -253,3 +253,15 @@ def get_config_variables(): weight=375, group='Motions', subgroup='Export') + + yield ConfigVariable( + name='motions_export_category_sorting', + default_value='prefix', + input_type='choice', + label='Sort categories by', + choices=( + {'value': 'prefix', 'display_name': 'Prefix'}, + {'value': 'name', 'display_name': 'Name'}), + weight=385, + group='Motions', + subgroup='Export') diff --git a/openslides/motions/static/js/motions/docx.js b/openslides/motions/static/js/motions/docx.js index ea76be16d..ede74639f 100644 --- a/openslides/motions/static/js/motions/docx.js +++ b/openslides/motions/static/js/motions/docx.js @@ -22,7 +22,6 @@ angular.module('OpenSlidesApp.motions.docx', ['OpenSlidesApp.core.docx']) var getData = function (motions, params) { var data = {}; - var categories = Category.getAll(); // header var headerline1 = [ Config.translate(Config.get('general_event_name').value), @@ -39,9 +38,10 @@ angular.module('OpenSlidesApp.motions.docx', ['OpenSlidesApp.core.docx']) data.preamble = Config.get('motions_export_preamble').value; // categories + var categories = getCategoriesData(motions); data.has_categories = categories.length === 0 ? false : true; data.categories_translation = gettextCatalog.getString('Categories'); - data.categories = getCategoriesData(categories); + data.categories = categories; data.no_categories = gettextCatalog.getString('No categories available.'); data.pagebreak_main = categories.length === 0 ? '' : PAGEBREAK; @@ -58,13 +58,21 @@ angular.module('OpenSlidesApp.motions.docx', ['OpenSlidesApp.core.docx']) }); }; - var getCategoriesData = function (categories) { - return _.map(categories, function (category) { - return { - prefix: category.prefix, - name: category.name, - }; + var getCategoriesData = function (motions) { + var categories = _.map(motions, function (motion) { + if (motion.category) { + return { + prefix: motion.category.prefix, + name: motion.category.name, + }; + } }); + // clear out 'undefined' and make the categories unique. + categories = _.uniqBy(_.filter(categories, function(category) { + return category; + }), 'prefix'); + var sortKey = Config.get('motions_export_category_sorting').value; + return _.orderBy(categories, [sortKey]); }; var getMotionShortData = function (motions) { diff --git a/openslides/motions/static/js/motions/pdf.js b/openslides/motions/static/js/motions/pdf.js index 6ed1eb98d..205bcbca9 100644 --- a/openslides/motions/static/js/motions/pdf.js +++ b/openslides/motions/static/js/motions/pdf.js @@ -712,21 +712,22 @@ angular.module('OpenSlidesApp.motions.pdf', ['OpenSlidesApp.core.pdf']) // function to create the table of catergories (if any) var createTOCategories = function() { var categories = []; - _.forEach(allMotions, function(motion) { + _.forEach(allMotions, function (motion) { var category = motion.getCategory(); if (category) { categories.push(category); } }); - categories = _.uniqBy(categories, 'id'); + var sortKey = Config.get('motions_export_category_sorting').value; + categories = _.orderBy(_.uniqBy(categories, 'id'), [sortKey]); if (categories.length > 1) { var heading = { - text: gettextCatalog.getString("Categories"), - style: "heading2" + text: gettextCatalog.getString('Categories'), + style: 'heading2', }; var toc = []; - angular.forEach(_.orderBy(categories, ['prefix']), function(cat) { + angular.forEach(categories, function(cat) { toc.push( { columns: [ diff --git a/openslides/motions/static/js/motions/site.js b/openslides/motions/static/js/motions/site.js index 3ee240607..f20837f2d 100644 --- a/openslides/motions/static/js/motions/site.js +++ b/openslides/motions/static/js/motions/site.js @@ -2260,6 +2260,7 @@ angular.module('OpenSlidesApp.motions.site', [ // subgroup PDF gettext('Title for PDF and DOCX documents (all motions)'); gettext('Preamble text for PDF and DOCX documents (all motions)'); + gettext('Sort categories by'); // misc strings (used dynamically in templates by translate filter) gettext('needed');