Merge pull request #2276 from FinnStutzenstein/Issue2259

Added a possibility to sort and renumber all motions in a category (closes #2259)
This commit is contained in:
Norman Jäckel 2016-08-18 16:59:12 +02:00 committed by GitHub
commit 21bbd4706c
5 changed files with 118 additions and 0 deletions

View File

@ -578,6 +578,14 @@ img {
margin-right: 5px;
}
.lead-div {
margin-bottom: 20px;
}
.lead-div .lead {
margin-bottom: 0;
}
.italic {
font-style: italic;
}

View File

@ -273,6 +273,21 @@ angular.module('OpenSlidesApp.motions', ['OpenSlidesApp.users'])
}
])
.factory('MotionList', [
function () {
return {
getList: function (items){
var list = [];
_.each(items, function (item) {
list.push({ id: item.id,
item: item });
});
return list;
}
};
}
])
.run([
'Motion',
'Category',

View File

@ -153,6 +153,19 @@ angular.module('OpenSlidesApp.motions.site', ['OpenSlidesApp.motions'])
views: {
'@motions.category': {}
}
})
.state('motions.category.sort', {
url: '/sort/{id}',
resolve: {
category: function(Category, $stateParams) {
return Category.find($stateParams.id);
},
motions: function(Motion) {
return Motion.findAll();
}
},
controller: 'CategorySortCtrl',
templateUrl: 'static/templates/motions/category-sort.html'
});
}
])
@ -1065,6 +1078,52 @@ angular.module('OpenSlidesApp.motions.site', ['OpenSlidesApp.motions'])
}
])
.controller('CategorySortCtrl', [
'$scope',
'$stateParams',
'$http',
'MotionList',
'Category',
'category',
'Motion',
'motions',
function($scope, $stateParams, $http, MotionList, Category, category, Motion, motions) {
Category.bindOne(category.id, $scope, 'category');
Motion.bindAll({}, $scope, 'motions');
$scope.filter = { category_id: category.id,
orderBy: 'identifier' };
$scope.$watch(
function () {
return Motion.lastModified();
},
function () {
$scope.items = MotionList.getTree(Motion.filter($scope.filter));
}
);
$scope.alert = {};
// Numbers all motions in this category by the given order in $scope.items
$scope.numbering = function () {
// Create a list of all motion ids in the current order.
var sorted_motions = [];
$scope.items.forEach(function (item) {
sorted_motions.push(item.item.id);
});
// renumber them
$http.post('/rest/motions/category/' + $scope.category.id + '/numbering/',
{'motions': sorted_motions} )
.success(function(data) {
$scope.alert = { type: 'success', msg: data.detail, show: true };
})
.error(function(data) {
$scope.alert = { type: 'danger', msg: data.detail, show: true };
});
};
}
])
//mark all motions config strings for translation in javascript
.config([
'gettext',

View File

@ -40,6 +40,8 @@
<td ng-mouseover="category.hover=true" ng-mouseleave="category.hover=false">
<strong>{{ category.name }}</strong>
<div class="hoverActions" ng-class="{'hiddenDiv': !category.hover}">
<!-- sort -->
<a ui-sref="motions.category.sort({ id: category.id })" translate>Sort</a> |
<!-- edit -->
<a ui-sref="motions.category.detail.update({id: category.id })" translate>Edit</a> |
<!-- delete -->

View File

@ -0,0 +1,34 @@
<div class="header">
<div class="title">
<div class="submenu">
<a ui-sref="motions.category.list" class="btn btn-sm btn-default">
<i class="fa fa-angle-double-left fa-lg"></i>
<translate>Back to categories</translate>
</a>
</div>
<h1><translate>Category</translate> {{ category.name }}</h1>
</div>
</div>
<div class="details">
<div class="lead-div">
<p class="lead" translate>
Drag and drop motions to reorder the category and when finished, renumber them.
</p>
<a os-perms="motions.can_manage" class="btn btn-primary btn-sm" ng-click="numbering()">
<i class="fa fa-sort-numeric-asc fa-lg"></i>
<translate>Numbering</translate>
</a>
</div>
<uib-alert ng-show="alert.show" type="{{ alert.type }}" ng-click="alert={}" close="alert={}">
{{ alert.msg }}
</uib-alert>
<div ui-tree="treeOptions" data-max-depth="1" data-empty-placeholder-enabled="false">
<ol ui-tree-nodes ng-model="items">
<li ui-tree-node ng-repeat="item in items">
<div ui-tree-handle bg-color="#FF0000">
{{ item.item.identifier }}: {{ item.item.getTitle() }}
</div>
</ol>
</div>
</div>