Csv export for IE (closes #2898)

This commit is contained in:
FinnStutzenstein 2017-01-20 15:03:45 +01:00
parent 29907c83b7
commit 9247009f1c
7 changed files with 45 additions and 34 deletions

View File

@ -7,7 +7,8 @@ angular.module('OpenSlidesApp.agenda.csv', [])
.factory('AgendaCsvExport', [ .factory('AgendaCsvExport', [
'HumanTimeConverter', 'HumanTimeConverter',
'gettextCatalog', 'gettextCatalog',
function (HumanTimeConverter, gettextCatalog) { 'CsvDownload',
function (HumanTimeConverter, gettextCatalog, CsvDownload) {
var makeHeaderline = function () { var makeHeaderline = function () {
var headerline = ['Title', 'Text', 'Duration', 'Comment', 'Internal item']; var headerline = ['Title', 'Text', 'Duration', 'Comment', 'Internal item'];
return _.map(headerline, function (entry) { return _.map(headerline, function (entry) {
@ -31,11 +32,7 @@ angular.module('OpenSlidesApp.agenda.csv', [])
row.push('"' + (item.is_hidden ? '1' : '') + '"'); row.push('"' + (item.is_hidden ? '1' : '') + '"');
csvRows.push(row); csvRows.push(row);
}); });
CsvDownload(csvRows, element, 'agenda-export.csv');
var csvString = csvRows.join("%0A");
element.href = 'data:text/csv;charset=utf-8,' + csvString;
element.download = 'agenda-export.csv';
element.target = '_blank';
}, },
}; };
} }

View File

@ -145,7 +145,7 @@ img {
left: 0; left: 0;
width: 100%; width: 100%;
height: 100%; height: 100%;
max-height: 356px; max-height: 340px;
z-index: 1000; z-index: 1000;
} }
#spinner-container div { #spinner-container div {

View File

@ -0,0 +1,25 @@
(function () {
'use strict';
angular.module('OpenSlidesApp.core.csv', [])
.factory('CsvDownload', [
function () {
return function (contentRows, element, fileName) {
if (navigator.msSaveBlob && typeof navigator.msSaveBlob === 'function') {
// Bad browsers
var blob = new Blob([contentRows.join('\r\n')]);
navigator.msSaveBlob(blob, fileName);
} else { // Good browsers
// %0A is the url encoded linefeed character. Needed to be
// percentage encoded for the data url.
element.href = 'data:text/csv;charset=utf-8,' + contentRows.join('%0A');
element.download = fileName;
element.target = '_blank';
}
};
}
]);
}());

View File

@ -6,6 +6,7 @@
angular.module('OpenSlidesApp.core.site', [ angular.module('OpenSlidesApp.core.site', [
'OpenSlidesApp.core', 'OpenSlidesApp.core',
'OpenSlidesApp.core.start', 'OpenSlidesApp.core.start',
'OpenSlidesApp.core.csv',
'OpenSlidesApp.poll.majority', 'OpenSlidesApp.poll.majority',
'ui.router', 'ui.router',
'colorpicker.module', 'colorpicker.module',

View File

@ -6,7 +6,8 @@ angular.module('OpenSlidesApp.motions.csv', [])
.factory('MotionCsvExport', [ .factory('MotionCsvExport', [
'gettextCatalog', 'gettextCatalog',
function (gettextCatalog) { 'CsvDownload',
function (gettextCatalog, CsvDownload) {
var makeHeaderline = function () { var makeHeaderline = function () {
var headerline = ['Identifier', 'Title', 'Text', 'Reason', 'Submitter', 'Category', 'Origin']; var headerline = ['Identifier', 'Title', 'Text', 'Reason', 'Submitter', 'Category', 'Origin'];
return _.map(headerline, function (entry) { return _.map(headerline, function (entry) {
@ -31,11 +32,7 @@ angular.module('OpenSlidesApp.motions.csv', [])
row.push('"' + motion.origin + '"'); row.push('"' + motion.origin + '"');
csvRows.push(row); csvRows.push(row);
}); });
CsvDownload(csvRows, element, 'motions-export.csv');
var csvString = csvRows.join("%0A");
element.href = 'data:text/csv;charset=utf-8,' + csvString;
element.download = 'motions-export.csv';
element.target = '_blank';
}, },
downloadExample: function (element) { downloadExample: function (element) {
var csvRows = [makeHeaderline(), var csvRows = [makeHeaderline(),
@ -44,10 +41,7 @@ angular.module('OpenSlidesApp.motions.csv', [])
['B1', 'Title 2', 'Text 2', 'Reason 2', 'Submitter B', 'Category B', '' ], ['B1', 'Title 2', 'Text 2', 'Reason 2', 'Submitter B', 'Category B', '' ],
['' , 'Title 3', 'Text 3', '' , '' , '' , '' ], ['' , 'Title 3', 'Text 3', '' , '' , '' , '' ],
]; ];
var csvString = csvRows.join("%0A"); CsvDownload(csvRows, element, 'motions-example.csv');
element.href = 'data:text/csv;charset=utf-8,' + csvString;
element.download = 'motions-example.csv';
element.target = '_blank';
}, },
}; };
} }

View File

@ -6,7 +6,8 @@ angular.module('OpenSlidesApp.topics.csv', [])
.factory('TopicsCsvExample', [ .factory('TopicsCsvExample', [
'gettextCatalog', 'gettextCatalog',
function (gettextCatalog) { 'CsvDownload',
function (gettextCatalog, CsvDownload) {
var makeHeaderline = function () { var makeHeaderline = function () {
var headerline = ['Title', 'Text', 'Duration', 'Comment', 'Internal item']; var headerline = ['Title', 'Text', 'Duration', 'Comment', 'Internal item'];
return _.map(headerline, function (entry) { return _.map(headerline, function (entry) {
@ -22,11 +23,7 @@ angular.module('OpenSlidesApp.topics.csv', [])
['Demo 2', 'Demo text 2', '1:30', '', ''] ['Demo 2', 'Demo text 2', '1:30', '', '']
]; ];
var csvString = csvRows.join("%0A"); CsvDownload(csvRows, element, 'agenda-example.csv');
element.href = 'data:text/csv;charset=utf-8,' + csvString;
element.download = 'agenda-example.csv';
element.target = '_blank';
}, },
}; };
} }

View File

@ -7,7 +7,8 @@ angular.module('OpenSlidesApp.users.csv', [])
.factory('UserCsvExport', [ .factory('UserCsvExport', [
'Group', 'Group',
'gettextCatalog', 'gettextCatalog',
function (Group, gettextCatalog) { 'CsvDownload',
function (Group, gettextCatalog, CsvDownload) {
var makeHeaderline = function () { var makeHeaderline = function () {
var headerline = ['Title', 'Given name', 'Surname', 'Structure level', 'Participant number', 'Groups', var headerline = ['Title', 'Given name', 'Surname', 'Structure level', 'Participant number', 'Groups',
'Comment', 'Is active', 'Is present', 'Is a committee']; 'Comment', 'Is active', 'Is present', 'Is a committee'];
@ -21,24 +22,23 @@ angular.module('OpenSlidesApp.users.csv', [])
makeHeaderline() makeHeaderline()
]; ];
_.forEach(users, function (user) { _.forEach(users, function (user) {
var groups = _.map(user.groups_id, function (id) {
return gettextCatalog.getString(Group.get(id).name);
}).join(',');
var row = []; var row = [];
row.push('"' + user.title + '"'); row.push('"' + user.title + '"');
row.push('"' + user.first_name + '"'); row.push('"' + user.first_name + '"');
row.push('"' + user.last_name + '"'); row.push('"' + user.last_name + '"');
row.push('"' + user.structure_level + '"'); row.push('"' + user.structure_level + '"');
row.push('"' + user.number + '"'); row.push('"' + user.number + '"');
row.push('"' + user.groups_id.join(',') + '"'); row.push('"' + groups + '"');
row.push('"' + user.comment + '"'); row.push('"' + user.comment + '"');
row.push(user.is_active ? '1' : '0'); row.push(user.is_active ? '1' : '0');
row.push(user.is_present ? '1' : '0'); row.push(user.is_present ? '1' : '0');
row.push(user.is_committee ? '1' : '0'); row.push(user.is_committee ? '1' : '0');
csvRows.push(row); csvRows.push(row);
}); });
CsvDownload(csvRows, element, 'users-export.csv');
var csvString = csvRows.join("%0A");
element.href = 'data:text/csv;charset=utf-8,' + csvString;
element.download = 'users-export.csv';
element.target = '_blank';
}, },
downloadExample: function (element) { downloadExample: function (element) {
@ -62,10 +62,7 @@ angular.module('OpenSlidesApp.users.csv', [])
['', '', 'Executive Board', '', '', '', '', '', '', '1'], ['', '', 'Executive Board', '', '', '', '', '', '', '1'],
]; ];
var csvString = csvRows.join("%0A"); CsvDownload(csvRows, element, 'users-example.csv');
element.href = 'data:text/csv;charset=utf-8,' + csvString;
element.download = 'users-example.csv';
element.target = '_blank';
} }
}; };
} }