From eca93594d70b5cb12431a4597a3d92ba1d395c1f Mon Sep 17 00:00:00 2001 From: FinnStutzenstein Date: Mon, 5 Dec 2016 16:22:58 +0100 Subject: [PATCH] Moving csv exports in seperate files (closes #2728) --- openslides/agenda/static/js/agenda/csv.js | 31 ++++++++++++++++ openslides/agenda/static/js/agenda/site.js | 3 +- openslides/motions/static/js/motions/base.js | 1 - openslides/motions/static/js/motions/csv.js | 35 ++++++++++++++++++ openslides/motions/static/js/motions/docx.js | 2 +- openslides/motions/static/js/motions/site.js | 31 ++-------------- .../static/templates/motions/motion-list.html | 2 +- openslides/users/static/js/users/csv.js | 36 +++++++++++++++++++ openslides/users/static/js/users/site.js | 32 ++--------------- 9 files changed, 111 insertions(+), 62 deletions(-) create mode 100644 openslides/agenda/static/js/agenda/csv.js create mode 100644 openslides/motions/static/js/motions/csv.js create mode 100644 openslides/users/static/js/users/csv.js diff --git a/openslides/agenda/static/js/agenda/csv.js b/openslides/agenda/static/js/agenda/csv.js new file mode 100644 index 000000000..3af602796 --- /dev/null +++ b/openslides/agenda/static/js/agenda/csv.js @@ -0,0 +1,31 @@ +(function () { + +'use strict'; + +angular.module('OpenSlidesApp.agenda.csv', []) + +.factory('AgendaCsvExport', [ + function () { + return function (element, agenda) { + var csvRows = [ + ['title', 'text', 'duration', 'comment', 'is_hidden'], + ]; + _.forEach(agenda, function (item) { + var row = []; + row.push('"' + (item.title || '') + '"'); + row.push('"' + (item.text || '') + '"'); + row.push('"' + (item.duration || '') + '"'); + row.push('"' + (item.comment || '') + '"'); + row.push('"' + (item.is_hidden ? '1' : '') + '"'); + csvRows.push(row); + }); + + var csvString = csvRows.join("%0A"); + element.href = 'data:text/csv;charset=utf-8,' + csvString; + element.download = 'agenda-export.csv'; + element.target = '_blank'; + }; + } +]); + +}()); diff --git a/openslides/agenda/static/js/agenda/site.js b/openslides/agenda/static/js/agenda/site.js index 52b375a18..de8fd82f8 100644 --- a/openslides/agenda/static/js/agenda/site.js +++ b/openslides/agenda/static/js/agenda/site.js @@ -5,7 +5,8 @@ angular.module('OpenSlidesApp.agenda.site', [ 'OpenSlidesApp.agenda', 'OpenSlidesApp.core.pdf', - 'OpenSlidesApp.agenda.pdf' + 'OpenSlidesApp.agenda.pdf', + 'OpenSlidesApp.agenda.csv', ]) .config([ diff --git a/openslides/motions/static/js/motions/base.js b/openslides/motions/static/js/motions/base.js index 49d289db3..b50bd592e 100644 --- a/openslides/motions/static/js/motions/base.js +++ b/openslides/motions/static/js/motions/base.js @@ -6,7 +6,6 @@ angular.module('OpenSlidesApp.motions', [ 'OpenSlidesApp.motions.motionBlock', 'OpenSlidesApp.motions.lineNumbering', 'OpenSlidesApp.motions.diff', - 'OpenSlidesApp.motions.DOCX', 'OpenSlidesApp.poll.majority', 'OpenSlidesApp.users', ]) diff --git a/openslides/motions/static/js/motions/csv.js b/openslides/motions/static/js/motions/csv.js new file mode 100644 index 000000000..5e621f958 --- /dev/null +++ b/openslides/motions/static/js/motions/csv.js @@ -0,0 +1,35 @@ +(function () { + +'use strict'; + +angular.module('OpenSlidesApp.motions.csv', []) + +.factory('MotionCsvExport', [ + function () { + return function (element, motions) { + var csvRows = [ + ['identifier', 'title', 'text', 'reason', 'submitter', 'category', 'origin'], + ]; + _.forEach(motions, function (motion) { + var row = []; + row.push('"' + motion.identifier + '"'); + row.push('"' + motion.getTitle() + '"'); + row.push('"' + motion.getText() + '"'); + row.push('"' + motion.getReason() + '"'); + var submitter = motion.submitters[0] ? motion.submitters[0].get_full_name() : ''; + row.push('"' + submitter + '"'); + var category = motion.category ? motion.category.name : ''; + row.push('"' + category + '"'); + row.push('"' + motion.origin + '"'); + csvRows.push(row); + }); + + var csvString = csvRows.join("%0A"); + element.href = 'data:text/csv;charset=utf-8,' + csvString; + element.download = 'motions-export.csv'; + element.target = '_blank'; + }; + } +]); + +}()); diff --git a/openslides/motions/static/js/motions/docx.js b/openslides/motions/static/js/motions/docx.js index 6b3b7ef97..a02d5bb9d 100644 --- a/openslides/motions/static/js/motions/docx.js +++ b/openslides/motions/static/js/motions/docx.js @@ -2,7 +2,7 @@ 'use strict'; -angular.module('OpenSlidesApp.motions.DOCX', []) +angular.module('OpenSlidesApp.motions.docx', []) .factory('MotionDocxExport', [ '$http', diff --git a/openslides/motions/static/js/motions/site.js b/openslides/motions/static/js/motions/site.js index ec21c8152..ec0cd25e3 100644 --- a/openslides/motions/static/js/motions/site.js +++ b/openslides/motions/static/js/motions/site.js @@ -7,7 +7,9 @@ angular.module('OpenSlidesApp.motions.site', [ 'OpenSlidesApp.motions.motionservices', 'OpenSlidesApp.poll.majority', 'OpenSlidesApp.core.pdf', - 'OpenSlidesApp.motions.pdf' + 'OpenSlidesApp.motions.docx', + 'OpenSlidesApp.motions.pdf', + 'OpenSlidesApp.motions.csv', ]) .config([ @@ -716,33 +718,6 @@ angular.module('OpenSlidesApp.motions.site', [ } ]) -.factory('MotionCsvExport', [ - function () { - return function (element, motions) { - var csvRows = [ - ['identifier', 'title', 'text', 'reason', 'submitter', 'category', 'origin'], - ]; - _.forEach(motions, function (motion) { - var row = []; - row.push('"' + motion.identifier + '"'); - row.push('"' + motion.getTitle() + '"'); - row.push('"' + motion.getText() + '"'); - row.push('"' + motion.getReason() + '"'); - row.push('"' + motion.submitters[0].get_full_name() + '"'); - var category = motion.category ? motion.category.name : ''; - row.push('"' + category + '"'); - row.push('"' + motion.origin + '"'); - csvRows.push(row); - }); - - var csvString = csvRows.join("%0A"); - element.href = 'data:text/csv;charset=utf-8,' + csvString; - element.download = 'motions-export.csv'; - element.target = '_blank'; - }; - } -]) - // Cache for MotionPollDetailCtrl so that users choices are keeped during user actions (e. g. save poll form). .value('MotionPollDetailCtrlCache', {}) diff --git a/openslides/motions/static/templates/motions/motion-list.html b/openslides/motions/static/templates/motions/motion-list.html index c170f45b6..eb1090d77 100644 --- a/openslides/motions/static/templates/motions/motion-list.html +++ b/openslides/motions/static/templates/motions/motion-list.html @@ -369,7 +369,7 @@ -
+
by diff --git a/openslides/users/static/js/users/csv.js b/openslides/users/static/js/users/csv.js new file mode 100644 index 000000000..75ea503bf --- /dev/null +++ b/openslides/users/static/js/users/csv.js @@ -0,0 +1,36 @@ +(function () { + +'use strict'; + +angular.module('OpenSlidesApp.users.csv', []) + +.factory('UserCsvExport', [ + function () { + return function (element, users) { + var csvRows = [ + ['title', 'first_name', 'last_name', 'structure_level', 'number', 'groups', 'comment', 'is_active', 'is_present', 'is_committee'], + ]; + _.forEach(users, function (user) { + var row = []; + row.push('"' + user.title + '"'); + row.push('"' + user.first_name + '"'); + row.push('"' + user.last_name + '"'); + row.push('"' + user.structure_level + '"'); + row.push('"' + user.number + '"'); + row.push('"' + user.groups_id.join(',') + '"'); + row.push('"' + user.comment + '"'); + row.push(user.is_active ? '1' : '0'); + row.push(user.is_present ? '1' : '0'); + row.push(user.is_committee ? '1' : '0'); + csvRows.push(row); + }); + + var csvString = csvRows.join("%0A"); + element.href = 'data:text/csv;charset=utf-8,' + csvString; + element.download = 'users-export.csv'; + element.target = '_blank'; + }; + } +]); + +}()); diff --git a/openslides/users/static/js/users/site.js b/openslides/users/static/js/users/site.js index 1369ce08a..16634da5f 100644 --- a/openslides/users/static/js/users/site.js +++ b/openslides/users/static/js/users/site.js @@ -5,7 +5,8 @@ angular.module('OpenSlidesApp.users.site', [ 'OpenSlidesApp.users', 'OpenSlidesApp.core.pdf', - 'OpenSlidesApp.users.pdf' + 'OpenSlidesApp.users.pdf', + 'OpenSlidesApp.users.csv', ]) .config([ @@ -455,35 +456,6 @@ angular.module('OpenSlidesApp.users.site', [ } ]) -.factory('UserCsvExport', [ - function () { - return function (element, users) { - var csvRows = [ - ['title', 'first_name', 'last_name', 'structure_level', 'number', 'groups', 'comment', 'is_active', 'is_present', 'is_committee'], - ]; - _.forEach(users, function (user) { - var row = []; - row.push('"' + user.title + '"'); - row.push('"' + user.first_name + '"'); - row.push('"' + user.last_name + '"'); - row.push('"' + user.structure_level + '"'); - row.push('"' + user.number + '"'); - row.push('"' + user.groups_id.join(',') + '"'); - row.push('"' + user.comment + '"'); - row.push(user.is_active ? '1' : '0'); - row.push(user.is_present ? '1' : '0'); - row.push(user.is_committee ? '1' : '0'); - csvRows.push(row); - }); - - var csvString = csvRows.join("%0A"); - element.href = 'data:text/csv;charset=utf-8,' + csvString; - element.download = 'users-export.csv'; - element.target = '_blank'; - }; - } -]) - .controller('UserListCtrl', [ '$scope', '$state',