diff --git a/extras/csv-examples/agenda-demo_de.csv b/extras/csv-examples/agenda-demo_de.csv index d15029dee..c2adbbf35 100644 --- a/extras/csv-examples/agenda-demo_de.csv +++ b/extras/csv-examples/agenda-demo_de.csv @@ -1,4 +1,4 @@ -Titel,Text,Dauer +title,text,duration Begrüßung,Begrüßung durch den Vorstand,5 Regularia,,10 Grußworte,,15 diff --git a/extras/csv-examples/agenda-demo_en.csv b/extras/csv-examples/agenda-demo_en.csv index b1cabbdbf..a63a42b90 100644 --- a/extras/csv-examples/agenda-demo_en.csv +++ b/extras/csv-examples/agenda-demo_en.csv @@ -1,4 +1,4 @@ -Title,Text,Duration +title,text,duration Welcome and Introductions,,10 Reports,, Report of executive board,Mr. Smith,30 diff --git a/openslides/agenda/static/js/agenda/agenda.js b/openslides/agenda/static/js/agenda/agenda.js index 763adcdce..8037d3676 100644 --- a/openslides/agenda/static/js/agenda/agenda.js +++ b/openslides/agenda/static/js/agenda/agenda.js @@ -62,9 +62,9 @@ angular.module('OpenSlidesApp.agenda', []) url: '/sort', controller: 'AgendaSortCtrl', }) - .state('agenda.item.csv-import', { - url: '/csv-import', - controller: 'AgendaCSVImportCtrl', + .state('agenda.item.import', { + url: '/import', + controller: 'AgendaImportCtrl', }); }) @@ -153,6 +153,54 @@ angular.module('OpenSlidesApp.agenda', []) }; }) -.controller('AgendaCSVImportCtrl', function($scope, Agenda) { - // TODO +.controller('AgendaImportCtrl', function($scope, $state, Agenda) { + // import from textarea + $scope.importByLine = function () { + $scope.items = $scope.itemlist[0].split("\n"); + $scope.importcounter = 0; + $scope.items.forEach(function(title) { + var item = {title: title}; + item.weight = 0; // TODO: the rest_api should do this + item.tags = []; // TODO: the rest_api should do this + // TODO: create all items in bulk mode + Agenda.create(item).then( + function(success) { + $scope.importcounter++; + } + ); + }); + } + + // import from csv file + $scope.csv = { + content: null, + header: true, + separator: ',', + result: null + }; + $scope.importByCSV = function (result) { + var obj = JSON.parse(JSON.stringify(result)); + $scope.csvimporting = true; + $scope.csvlines = Object.keys(obj).length; + $scope.csvimportcounter = 0; + for (var i = 0; i < obj.length; i++) { + var item = {}; + item.title = obj[i].titel; + item.text = obj[i].text; + item.duration = obj[i].duration; + item.weight = 0; // TODO: the rest_api should do this + item.tags = []; // TODO: the rest_api should do this + Agenda.create(item).then( + function(success) { + $scope.csvimportcounter++; + } + ); + } + $scope.csvimported = true; + } + + $scope.clear = function () { + $scope.csv.result = null; + }; + }); diff --git a/openslides/agenda/static/templates/agenda/item-csv-import.html b/openslides/agenda/static/templates/agenda/item-csv-import.html deleted file mode 100644 index 18b95ea27..000000000 --- a/openslides/agenda/static/templates/agenda/item-csv-import.html +++ /dev/null @@ -1,39 +0,0 @@ -
Select a CSV file to import agenda items! - -
Please note:
-'title, text, duration'
- Copy and paste your agenda item titles in this textbox. +Keep each item in a single line.
+ +Select a CSV file to import agenda items! + +
Please note:
+'title, text, duration'
+ # + | Title + | Text + | Duration + |
---|---|---|---|
{{ $index+1 }} + | {{ item.title }} + | {{ item.text }} + | {{ item.duration }} + |
+