Merge pull request #2899 from FinnStutzenstein/IssueCsvIE

Csv export for IE (closes #2898)
This commit is contained in:
Norman Jäckel 2017-01-23 16:59:07 +01:00 committed by GitHub
commit fb047fc5b9
7 changed files with 45 additions and 34 deletions

View File

@ -7,7 +7,8 @@ angular.module('OpenSlidesApp.agenda.csv', [])
.factory('AgendaCsvExport', [
'HumanTimeConverter',
'gettextCatalog',
function (HumanTimeConverter, gettextCatalog) {
'CsvDownload',
function (HumanTimeConverter, gettextCatalog, CsvDownload) {
var makeHeaderline = function () {
var headerline = ['Title', 'Text', 'Duration', 'Comment', 'Internal item'];
return _.map(headerline, function (entry) {
@ -31,11 +32,7 @@ angular.module('OpenSlidesApp.agenda.csv', [])
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';
CsvDownload(csvRows, element, 'agenda-export.csv');
},
};
}

View File

@ -145,7 +145,7 @@ img {
left: 0;
width: 100%;
height: 100%;
max-height: 356px;
max-height: 340px;
z-index: 1000;
}
#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', [
'OpenSlidesApp.core',
'OpenSlidesApp.core.start',
'OpenSlidesApp.core.csv',
'OpenSlidesApp.poll.majority',
'ui.router',
'colorpicker.module',

View File

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

View File

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

View File

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