Moving csv exports in seperate files (closes #2728)

This commit is contained in:
FinnStutzenstein 2016-12-05 16:22:58 +01:00
parent 787805efa6
commit eca93594d7
9 changed files with 111 additions and 62 deletions

View File

@ -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';
};
}
]);
}());

View File

@ -5,7 +5,8 @@
angular.module('OpenSlidesApp.agenda.site', [
'OpenSlidesApp.agenda',
'OpenSlidesApp.core.pdf',
'OpenSlidesApp.agenda.pdf'
'OpenSlidesApp.agenda.pdf',
'OpenSlidesApp.agenda.csv',
])
.config([

View File

@ -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',
])

View File

@ -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';
};
}
]);
}());

View File

@ -2,7 +2,7 @@
'use strict';
angular.module('OpenSlidesApp.motions.DOCX', [])
angular.module('OpenSlidesApp.motions.docx', [])
.factory('MotionDocxExport', [
'$http',

View File

@ -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', {})

View File

@ -369,7 +369,7 @@
</span>
</div>
<!-- Submitters -->
<div>
<div ng-if="motion.submitters.length">
<small>
<span class="optional" translate>by</span>
<span class="optional" ng-repeat="submitter in motion.submitters | limitTo:1">

View File

@ -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';
};
}
]);
}());

View File

@ -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',