Added two agenda import ways.

Note: CSV example file was updated because English csv header strings are
required now.
This commit is contained in:
Emanuel Schuetze 2015-05-13 23:44:45 +02:00
parent 51455e8563
commit b7abf770c7
7 changed files with 146 additions and 49 deletions

View File

@ -1,4 +1,4 @@
Titel,Text,Dauer title,text,duration
Begrüßung,Begrüßung durch den Vorstand,5 Begrüßung,Begrüßung durch den Vorstand,5
Regularia,,10 Regularia,,10
Grußworte,,15 Grußworte,,15

1 Titel title Text text Dauer duration
2 Begrüßung Begrüßung durch den Vorstand 5
3 Regularia 10
4 Grußworte 15

View File

@ -1,4 +1,4 @@
Title,Text,Duration title,text,duration
Welcome and Introductions,,10 Welcome and Introductions,,10
Reports,, Reports,,
Report of executive board,Mr. Smith,30 Report of executive board,Mr. Smith,30

1 Title title Text text Duration duration
2 Welcome and Introductions 10
3 Reports
4 Report of executive board Mr. Smith 30

View File

@ -62,9 +62,9 @@ angular.module('OpenSlidesApp.agenda', [])
url: '/sort', url: '/sort',
controller: 'AgendaSortCtrl', controller: 'AgendaSortCtrl',
}) })
.state('agenda.item.csv-import', { .state('agenda.item.import', {
url: '/csv-import', url: '/import',
controller: 'AgendaCSVImportCtrl', controller: 'AgendaImportCtrl',
}); });
}) })
@ -153,6 +153,54 @@ angular.module('OpenSlidesApp.agenda', [])
}; };
}) })
.controller('AgendaCSVImportCtrl', function($scope, Agenda) { .controller('AgendaImportCtrl', function($scope, $state, Agenda) {
// TODO // 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;
};
}); });

View File

@ -1,39 +0,0 @@
<h1 translate>Import agenda items</h1>
<div id="submenu">
<a ui-sref="agenda.item.list" class="btn btn-sm btn-default">
<i class="fa fa-angle-double-left fa-lg"></i>
<translate>Back to overview</translate>
</a>
</div>
<p translate>Select a CSV file to import agenda items!
<p translate>Please note:</p>
<ul><!--TODO: utf-8 encoding still required with agnular-csv? -->
<li><translate>Required comma separated values</translate>:<br>
<code translate>'title, text, duration'</code>
<li translate>Text and duration are optional and may be empty.
<li translate>The first line (header) is ignored.
<li translate>Required CSV file encoding is UTF-8.
<li><a href="https://github.com/OpenSlides/OpenSlides/wiki/CSV-Import" translate>
Use the CSV example file from OpenSlides Wiki.
</a>
</ul>
<!-- TODO: add post url to form-->
<form>
<div class="form-group">
<label for="InputFile" translate>CSV file:</label>
<input type="file" id="InputFile">
<p class="help-block" translate>The file has to be encoded in UTF-8.
</div>
<!--TODO-->
<button type="submit" ng-click="" class="btn btn-primary" translate>
Import
</button>
<button ui-sref="agenda.item.list" class="btn btn-default" translate>
Cancel
</button>
</form>

View File

@ -0,0 +1,88 @@
<h1 translate>Import agenda items</h1>
<div id="submenu">
<a ui-sref="agenda.item.list" class="btn btn-sm btn-default">
<i class="fa fa-angle-double-left fa-lg"></i>
<translate>Back to overview</translate>
</a>
</div>
<h2 translate>Import by copy/paste</h2>
<p translate>Copy and paste your agenda item titles in this textbox.
Keep each item in a single line.</p>
<div class="row">
<div class="form-group col-sm-6">
<textarea ng-model="itemlist" rows="5" class="form-control" ng-list="/\n/"></textarea>
</div>
</div>
<div class="clearfix">
<button ng-click="importByLine()" class="btn btn-primary pull-left" translate>Import</button>
<div class="col-xs-5" ng-if="items">
<progressbar animate="false" type="success" max="items.length" value="importcounter">
<i>{{ importcounter }} / {{ items.length }} {{ "imported" | translate }}</i>
</progressbar>
</div>
</div>
<hr>
<h2 translate>Import by CSV file</h2>
<p translate>Select a CSV file to import agenda items!
<p translate>Please note:</p>
<ul><!--TODO: utf-8 encoding still required with angular-csv? -->
<li><translate>Required comma separated values</translate>:<br>
<code translate>'title, text, duration'</code>
<li translate>Text and duration are optional and may be empty.
<li translate>The first line (header) is ignored.
<li translate>Required CSV file encoding is UTF-8.
<li><a href="https://github.com/OpenSlides/OpenSlides/wiki/CSV-Import" translate>
Use the CSV example file from OpenSlides Wiki.
</a>
</ul>
<ng-csv-import
content="csv.content"
class="import"
header="csv.header"
separator="csv.separator"
result="csv.result"></ng-csv-import>
<div ng-if="csv.result" class="col-sm-6 well">
<h3 translate>Preview</h3>
<table class="table table-striped table-bordered table-condensed">
<thead>
<tr>
<th>#
<th translate>Title
<th translate>Text
<th translate>Duration
<tbody ng-repeat="item in csv.result">
<tr>
<td>{{ $index+1 }}
<td>{{ item.title }}
<td>{{ item.text }}
<td>{{ item.duration }}
</table>
<div class="clearfix">
<button ng-if="!csvimporting" ng-click="importByCSV(csv.result)" class="btn btn-primary pull-left" translate>Import</button>
<div ng-if="csvimporting">
<progressbar animate="false" type="success" max="csvlines" value="csvimportcounter">
<i>{{ csvimportcounter }} / {{ csvlines }} {{ "imported" | translate }}</i>
</progressbar>
</div>
<a ng-if="csvimported" ui-sref="agenda.item.list" class="btn btn-sm btn-default">
<i class="fa fa-angle-double-left fa-lg"></i>
<translate>Back to agenda overview</translate>
</a>
</div>
<p>
<div class="form-group">
<button ng-if="!csvimporting" ng-click="clear()" class="btn btn-default" translate>
Clear
</button>
</div>
</div>

View File

@ -6,10 +6,10 @@
<translate>New</translate> <translate>New</translate>
</a> </a>
<a ui-sref="agenda.item.sort" os-perms="agenda.can_manage" class="btn btn-default btn-sm"> <a ui-sref="agenda.item.sort" os-perms="agenda.can_manage" class="btn btn-default btn-sm">
<i class="fa fa-download fa-lg"></i> <i class="fa fa-sitemap fa-lg"></i>
<translate>Sort agenda</translate> <translate>Sort agenda</translate>
</a> </a>
<a ui-sref="agenda.item.csv-import" os-perms="agenda.can_manage" class="btn btn-default btn-sm"> <a ui-sref="agenda.item.import" os-perms="agenda.can_manage" class="btn btn-default btn-sm">
<i class="fa fa-download fa-lg"></i> <i class="fa fa-download fa-lg"></i>
<translate>Import</translate> <translate>Import</translate>
</a> </a>
@ -32,6 +32,7 @@
</div> </div>
</div> </div>
<i>{{ items.length }} {{ "items" | translate }}</i>
<table class="table table-striped table-bordered table-hover"> <table class="table table-striped table-bordered table-hover">
<thead> <thead>
<tr> <tr>

View File

@ -303,7 +303,6 @@ angular.module('OpenSlidesApp.users', [])
}; };
$scope.import = function (result) { $scope.import = function (result) {
console.log(result);
var obj = JSON.parse(result); var obj = JSON.parse(result);
console.log(obj); console.log(obj);
var imported_users = 0; var imported_users = 0;