OpenSlides/openslides/agenda/static/js/agenda/csv.js

42 lines
1.4 KiB
JavaScript
Raw Normal View History

(function () {
'use strict';
angular.module('OpenSlidesApp.agenda.csv', [])
.factory('AgendaCsvExport', [
'HumanTimeConverter',
2017-01-06 12:21:37 +01:00
'gettextCatalog',
2017-01-20 15:03:45 +01:00
'CsvDownload',
function (HumanTimeConverter, gettextCatalog, CsvDownload) {
2017-01-06 12:21:37 +01:00
var makeHeaderline = function () {
var headerline = ['Title', 'Text', 'Duration', 'Comment', 'Internal item'];
return _.map(headerline, function (entry) {
return gettextCatalog.getString(entry);
});
2017-01-06 12:21:37 +01:00
};
return {
export: function (agenda) {
2017-01-06 12:21:37 +01:00
var csvRows = [
makeHeaderline()
];
_.forEach(agenda, function (item) {
var row = [];
var duration = item.duration ? HumanTimeConverter.secondsToHumanTime(item.duration*60,
{ seconds: 'disabled',
hours: 'enabled' }) : '';
row.push('"' + (item.title || '') + '"');
row.push('"' + (item.getCSVExportText() || '') + '"');
2017-01-06 12:21:37 +01:00
row.push('"' + duration + '"');
row.push('"' + (item.comment || '') + '"');
row.push('"' + (item.is_hidden ? '1' : '') + '"');
csvRows.push(row);
});
CsvDownload(csvRows, gettextCatalog.getString('Agenda') + '.csv');
2017-01-06 12:21:37 +01:00
},
};
}
]);
}());