Merge pull request #1522 from emanuelschuetze/agenda-import
Added two agenda import ways.
This commit is contained in:
commit
b703655153
@ -1,4 +1,4 @@
|
||||
Titel,Text,Dauer
|
||||
title,text,duration
|
||||
Begrüßung,Begrüßung durch den Vorstand,5
|
||||
Regularia,,10
|
||||
Grußworte,,15
|
||||
|
|
@ -1,4 +1,4 @@
|
||||
Title,Text,Duration
|
||||
title,text,duration
|
||||
Welcome and Introductions,,10
|
||||
Reports,,
|
||||
Report of executive board,Mr. Smith,30
|
||||
|
|
@ -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;
|
||||
};
|
||||
|
||||
});
|
||||
|
@ -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>
|
88
openslides/agenda/static/templates/agenda/item-import.html
Normal file
88
openslides/agenda/static/templates/agenda/item-import.html
Normal 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>
|
@ -6,10 +6,10 @@
|
||||
<translate>New</translate>
|
||||
</a>
|
||||
<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>
|
||||
</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>
|
||||
<translate>Import</translate>
|
||||
</a>
|
||||
@ -32,6 +32,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<i>{{ items.length }} {{ "items" | translate }}</i>
|
||||
<table class="table table-striped table-bordered table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user