From 8ae3e1d46884a6f923066fd62ad2ff3c5f3a660d Mon Sep 17 00:00:00 2001 From: Emanuel Schuetze Date: Tue, 2 Feb 2016 20:54:03 +0100 Subject: [PATCH] Add Pagination and improve import. - Use Pagination for users and item list and users import table. - Improve agenda import: Allow to define agenda item stuff like duration, comment, type. --- openslides/agenda/static/js/agenda/site.js | 79 +++++++++++++++---- .../static/templates/agenda/item-import.html | 18 +++-- .../static/templates/agenda/item-list.html | 4 +- openslides/core/static/css/app.css | 1 + openslides/users/static/js/users/site.js | 15 ++++ .../static/templates/users/user-import.html | 11 +-- .../static/templates/users/user-list.html | 3 +- 7 files changed, 103 insertions(+), 28 deletions(-) diff --git a/openslides/agenda/static/js/agenda/site.js b/openslides/agenda/static/js/agenda/site.js index e8d1b3f0c..67d2f5825 100644 --- a/openslides/agenda/static/js/agenda/site.js +++ b/openslides/agenda/static/js/agenda/site.js @@ -86,6 +86,14 @@ angular.module('OpenSlidesApp.agenda.site', ['OpenSlidesApp.agenda']) }); $scope.alert = {}; + // pagination + $scope.currentPage = 1; + $scope.itemsPerPage = 100; + $scope.limitBegin = 0; + $scope.pageChanged = function() { + $scope.limitBegin = ($scope.currentPage - 1) * $scope.itemsPerPage; + }; + // check open permission $scope.isAllowedToSeeOpenLink = function (item) { var collection = item.content_object.collection; @@ -356,17 +364,26 @@ angular.module('OpenSlidesApp.agenda.site', ['OpenSlidesApp.agenda']) function($scope, gettext, Agenda, Customslide) { // import from textarea $scope.importByLine = function () { - $scope.titleItems = $scope.itemlist[0].split("\n"); - $scope.importcounter = 0; - $scope.titleItems.forEach(function(title) { - var item = {title: title}; - // TODO: create all items in bulk mode - Customslide.create(item).then( - function(success) { - $scope.importcounter++; - } - ); - }); + if ($scope.itemlist) { + $scope.titleItems = $scope.itemlist[0].split("\n"); + $scope.importcounter = 0; + $scope.titleItems.forEach(function(title, index) { + var item = {title: title}; + // TODO: create all items in bulk mode + Customslide.create(item).then( + function(success) { + // find related agenda item + Agenda.find(success.agenda_item_id).then(function(item) { + // import all items as type AGENDA_ITEM = 1 + item.type = 1; + item.weight = 1000 + index; + Agenda.save(item); + }); + $scope.importcounter++; + } + ); + }); + } }; // *** CSV import *** @@ -397,7 +414,7 @@ angular.module('OpenSlidesApp.agenda.site', ['OpenSlidesApp.agenda']) $scope.$watch('csv.result', function () { $scope.items = []; var quotionRe = /^"(.*)"$/; - angular.forEach($scope.csv.result, function (item) { + angular.forEach($scope.csv.result, function (item, index) { // title if (item.title) { item.title = item.title.replace(quotionRe, '$1'); @@ -410,6 +427,29 @@ angular.module('OpenSlidesApp.agenda.site', ['OpenSlidesApp.agenda']) if (item.text) { item.text = item.text.replace(quotionRe, '$1'); } + // duration + if (item.duration) { + item.duration = item.duration.replace(quotionRe, '$1'); + } + // comment + if (item.comment) { + item.comment = item.comment.replace(quotionRe, '$1'); + } + // is_hidden + if (item.is_hidden) { + item.is_hidden = item.is_hidden.replace(quotionRe, '$1'); + if (item.is_hidden == '1') { + item.type = 2; + } else { + item.type = 1; + } + } else { + item.type = 1; + } + // set weight for right csv row order + // (Use 1000+ to protect existing items and prevent collision + // with new items which use weight 10000 as default.) + item.weight = 1000 + index; $scope.items.push(item); }); }); @@ -422,6 +462,14 @@ angular.module('OpenSlidesApp.agenda.site', ['OpenSlidesApp.agenda']) Customslide.create(item).then( function(success) { item.imported = true; + // find related agenda item + Agenda.find(success.agenda_item_id).then(function(agendaItem) { + agendaItem.duration = item.duration; + agendaItem.comment = item.comment; + agendaItem.type = item.type; + agendaItem.weight = item.weight; + Agenda.save(agendaItem); + }); } ); } @@ -436,10 +484,11 @@ angular.module('OpenSlidesApp.agenda.site', ['OpenSlidesApp.agenda']) var element = document.getElementById('downloadLink'); var csvRows = [ // column header line - ['title', 'text'], + ['title', 'text', 'duration', 'comment', 'is_hidden'], // example entries - ['Demo 1', 'Demo text 1'], - ['Demo 2', 'Demo text 2'] + ['Demo 1', 'Demo text 1', '1:00', 'test comment', ''], + ['Break', '', '0:10', '', '1'], + ['Demo 2', 'Demo text 2', '1:30', '', ''] ]; var csvString = csvRows.join("%0A"); diff --git a/openslides/agenda/static/templates/agenda/item-import.html b/openslides/agenda/static/templates/agenda/item-import.html index 91d12312a..a5d77795e 100644 --- a/openslides/agenda/static/templates/agenda/item-import.html +++ b/openslides/agenda/static/templates/agenda/item-import.html @@ -66,21 +66,24 @@ Keep each item in a single line.

Please note:

Preview

- +
+
# Title - TextText + Duration + Comment + Is hidden
- {{ $index + 1 }} + {{ $index + 1 }} - {{ item.getTitle() }} + {{ item.title }} {{ item.text | limitTo:80 }}{{ item.text.length > 80 ? '...' : '' }} + {{ item.duration }} + {{ item.comment }} + {{ item.is_hidden }}
diff --git a/openslides/agenda/static/templates/agenda/item-list.html b/openslides/agenda/static/templates/agenda/item-list.html index 056d65e77..5509c6bde 100644 --- a/openslides/agenda/static/templates/agenda/item-list.html +++ b/openslides/agenda/static/templates/agenda/item-list.html @@ -117,7 +117,8 @@ Done @@ -206,4 +207,5 @@
+
diff --git a/openslides/core/static/css/app.css b/openslides/core/static/css/app.css index a51974ff6..752293fdf 100644 --- a/openslides/core/static/css/app.css +++ b/openslides/core/static/css/app.css @@ -91,6 +91,7 @@ img { border: 1px solid red; position: fixed; width: 100%; + z-index: 1000; } #header a.headerlink { text-decoration: none; diff --git a/openslides/users/static/js/users/site.js b/openslides/users/static/js/users/site.js index f64bd3209..722dbf6d1 100644 --- a/openslides/users/static/js/users/site.js +++ b/openslides/users/static/js/users/site.js @@ -390,6 +390,14 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users']) $scope.sortColumn = column; }; + // pagination + $scope.currentPage = 1; + $scope.itemsPerPage = 100; + $scope.limitBegin = 0; + $scope.pageChanged = function() { + $scope.limitBegin = ($scope.currentPage - 1) * $scope.itemsPerPage; + }; + // open new/edit dialog $scope.openDialog = function (user) { ngDialog.open(UserForm.getDialog(user)); @@ -643,6 +651,13 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users']) $scope.setSeparator = function () { $scope.csv.separator = $scope.separator; }; + // pagination + $scope.currentPage = 1; + $scope.itemsPerPage = 100; + $scope.limitBegin = 0; + $scope.pageChanged = function() { + $scope.limitBegin = ($scope.currentPage - 1) * $scope.itemsPerPage; + }; // detect if csv file is loaded $scope.$watch('csv.result', function () { $scope.users = []; diff --git a/openslides/users/static/templates/users/user-import.html b/openslides/users/static/templates/users/user-import.html index 39ebc3509..a45964636 100644 --- a/openslides/users/static/templates/users/user-import.html +++ b/openslides/users/static/templates/users/user-import.html @@ -77,9 +77,9 @@
  • Download CSV example file -
    +

    Preview

    - +
    - - + +
    @@ -91,8 +91,8 @@ Groups Comment Is active
    @@ -129,6 +129,7 @@
    +
    @@ -151,7 +152,7 @@
    -