From b7abf770c78ffdb328bd29069a2bbe144634ecd0 Mon Sep 17 00:00:00 2001 From: Emanuel Schuetze Date: Wed, 13 May 2015 23:44:45 +0200 Subject: [PATCH] Added two agenda import ways. Note: CSV example file was updated because English csv header strings are required now. --- extras/csv-examples/agenda-demo_de.csv | 2 +- extras/csv-examples/agenda-demo_en.csv | 2 +- openslides/agenda/static/js/agenda/agenda.js | 58 ++++++++++-- .../templates/agenda/item-csv-import.html | 39 -------- .../static/templates/agenda/item-import.html | 88 +++++++++++++++++++ .../static/templates/agenda/item-list.html | 5 +- openslides/users/static/js/users/users.js | 1 - 7 files changed, 146 insertions(+), 49 deletions(-) delete mode 100644 openslides/agenda/static/templates/agenda/item-csv-import.html create mode 100644 openslides/agenda/static/templates/agenda/item-import.html 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 @@ -

Import agenda items

- - - -

Select a CSV file to import agenda items! - -

Please note:

- - - -
-
- - -

The file has to be encoded in UTF-8. -

- - - - -
diff --git a/openslides/agenda/static/templates/agenda/item-import.html b/openslides/agenda/static/templates/agenda/item-import.html new file mode 100644 index 000000000..c6e87ee2f --- /dev/null +++ b/openslides/agenda/static/templates/agenda/item-import.html @@ -0,0 +1,88 @@ +

Import agenda items

+ + + +

Import by copy/paste

+

Copy and paste your agenda item titles in this textbox. +Keep each item in a single line.

+ +
+
+ +
+
+ +
+ +
+ + {{ importcounter }} / {{ items.length }} {{ "imported" | translate }} + +
+
+ +
+ +

Import by CSV file

+

Select a CSV file to import agenda items! + +

Please note:

+ + + + +
+

Preview

+ + + + + +
# + Title + Text + Duration +
{{ $index+1 }} + {{ item.title }} + {{ item.text }} + {{ item.duration }} +
+ +
+ +
+ + {{ csvimportcounter }} / {{ csvlines }} {{ "imported" | translate }} + +
+ + + Back to agenda overview + +
+

+

+ +
+
diff --git a/openslides/agenda/static/templates/agenda/item-list.html b/openslides/agenda/static/templates/agenda/item-list.html index 2ea8db77b..75a2832e7 100644 --- a/openslides/agenda/static/templates/agenda/item-list.html +++ b/openslides/agenda/static/templates/agenda/item-list.html @@ -6,10 +6,10 @@ New - + Sort agenda - + Import @@ -32,6 +32,7 @@ +{{ items.length }} {{ "items" | translate }} diff --git a/openslides/users/static/js/users/users.js b/openslides/users/static/js/users/users.js index 7c0a64c0a..c9f536e6c 100644 --- a/openslides/users/static/js/users/users.js +++ b/openslides/users/static/js/users/users.js @@ -303,7 +303,6 @@ angular.module('OpenSlidesApp.users', []) }; $scope.import = function (result) { - console.log(result); var obj = JSON.parse(result); console.log(obj); var imported_users = 0;