Give motions by id in state and recommendation.

This commit is contained in:
FinnStutzenstein 2017-11-17 14:47:38 +01:00 committed by Emanuel Schütze
parent 7a3d3d99d6
commit 2bdaf85b67
5 changed files with 74 additions and 44 deletions

View File

@ -49,6 +49,7 @@ Motions:
- Improved the multiselect state filter [#3459].
- Added karma:watch command [#3466].
- Show the number of next speakers in motion list view [#3470].
- Reference to motions by id in state and recommendation special field [#3498].
Elections:
- Added pagination for list view [#3393].

View File

@ -189,10 +189,34 @@ angular.module('OpenSlidesApp.motions', [
}
])
.factory('MotionStateAndRecommendationParser', [
'DS',
'gettextCatalog',
function (DS, gettextCatalog) {
return {
formatMotion: function (motion) {
return '[motion:' + motion.id + ']';
},
parse: function (recommendation) {
return recommendation.replace(/\[motion:(\d+)\]/g, function (match, id) {
var motion = DS.get('motions/motion', id);
if (motion) {
return motion.identifier ? motion.identifier : motion.getTitle();
} else {
return gettextCatalog.getString("<unknown motion>");
}
});
},
};
}
])
.factory('Motion', [
'DS',
'$http',
'MotionPoll',
'MotionStateAndRecommendationParser',
'MotionChangeRecommendation',
'MotionComment',
'jsDataModel',
@ -204,7 +228,7 @@ angular.module('OpenSlidesApp.motions', [
'OpenSlidesSettings',
'Projector',
'operator',
function(DS, $http, MotionPoll, MotionChangeRecommendation, MotionComment, jsDataModel, gettext, gettextCatalog,
function(DS, $http, MotionPoll, MotionStateAndRecommendationParser, MotionChangeRecommendation, MotionComment, jsDataModel, gettext, gettextCatalog,
Config, lineNumberingService, diffService, OpenSlidesSettings, Projector, operator) {
var name = 'motions/motion';
return DS.defineResource({
@ -399,35 +423,33 @@ angular.module('OpenSlidesApp.motions', [
// depended by state and provided by a custom comment field
getStateName: function () {
var name = '';
var additionalName = '';
if (this.state) {
name = gettextCatalog.getString(this.state.name);
if (this.state.show_state_extension_field) {
// check motion comment fields for flag 'forState'
var commentFieldForStateId = MotionComment.getFieldIdForFlag('forState');
if (commentFieldForStateId > -1) {
additionalName = ' ' + this.comments[commentFieldForStateId];
name += ' ' + this.comments[commentFieldForStateId];
}
}
}
return name + additionalName;
return MotionStateAndRecommendationParser.parse(name);
},
// full recommendation string - optional with custom recommendationextension
// depended by state and provided by a custom comment field
getRecommendationName: function () {
var recommendation = '';
var additionalName = '';
if (Config.get('motions_recommendations_by').value !== '' && this.recommendation) {
recommendation = gettextCatalog.getString(this.recommendation.recommendation_label);
if (this.recommendation.show_recommendation_extension_field) {
// check motion comment fields for flag 'forRecommendation'
var commentFieldForRecommendationId = MotionComment.getFieldIdForFlag('forRecommendation');
if (commentFieldForRecommendationId > -1) {
additionalName = ' ' + this.comments[commentFieldForRecommendationId];
recommendation += ' ' + this.comments[commentFieldForRecommendationId];
}
}
}
return recommendation + additionalName;
return MotionStateAndRecommendationParser.parse(recommendation);
},
// link name which is shown in search result
getSearchResultName: function () {
@ -808,21 +830,6 @@ angular.module('OpenSlidesApp.motions', [
}
])
.factory('MotionList', [
function () {
return {
getList: function (items){
var list = [];
_.each(items, function (item) {
list.push({ id: item.id,
item: item });
});
return list;
}
};
}
])
.factory('MotionChangeRecommendation', [
'DS',
'Config',

View File

@ -185,7 +185,7 @@ angular.module('OpenSlidesApp.motions.motionservices', ['OpenSlidesApp.motions',
}
])
.factory('ChangeRecommmendationCreate', [
.factory('ChangeRecommendationCreate', [
'ngDialog',
'ChangeRecommendationForm',
function(ngDialog, ChangeRecommendationForm) {
@ -366,7 +366,7 @@ angular.module('OpenSlidesApp.motions.motionservices', ['OpenSlidesApp.motions',
}
])
.factory('ChangeRecommmendationView', [
.factory('ChangeRecommendationView', [
'Motion',
'MotionChangeRecommendation',
'Config',

View File

@ -1230,8 +1230,9 @@ angular.module('OpenSlidesApp.motions.site', [
'ngDialog',
'gettextCatalog',
'MotionForm',
'ChangeRecommmendationCreate',
'ChangeRecommmendationView',
'ChangeRecommendationCreate',
'ChangeRecommendationView',
'MotionStateAndRecommendationParser',
'MotionChangeRecommendation',
'Motion',
'MotionComment',
@ -1253,11 +1254,11 @@ angular.module('OpenSlidesApp.motions.site', [
'WebpageTitle',
'EditingWarning',
function($scope, $http, $timeout, $window, $filter, operator, ngDialog, gettextCatalog,
MotionForm, ChangeRecommmendationCreate, ChangeRecommmendationView,
MotionChangeRecommendation, Motion, MotionComment, Category, Mediafile, Tag, User,
Workflow, Config, motionId, MotionInlineEditing, MotionCommentsInlineEditing, Editor,
Projector, ProjectionDefault, MotionBlock, MotionPdfExport, PersonalNoteManager,
WebpageTitle, EditingWarning) {
MotionForm, ChangeRecommendationCreate, ChangeRecommendationView,
MotionStateAndRecommendationParser, MotionChangeRecommendation, Motion, MotionComment,
Category, Mediafile, Tag, User, Workflow, Config, motionId, MotionInlineEditing,
MotionCommentsInlineEditing, Editor, Projector, ProjectionDefault, MotionBlock,
MotionPdfExport, PersonalNoteManager, WebpageTitle, EditingWarning) {
var motion = Motion.get(motionId);
Category.bindAll({}, $scope, 'categories');
Mediafile.bindAll({}, $scope, 'mediafiles');
@ -1265,6 +1266,7 @@ angular.module('OpenSlidesApp.motions.site', [
User.bindAll({}, $scope, 'users');
Workflow.bindAll({}, $scope, 'workflows');
MotionBlock.bindAll({}, $scope, 'motionBlocks');
Motion.bindAll({}, $scope, 'motions');
$scope.$watch(function () {
return MotionChangeRecommendation.lastModified();
}, function () {
@ -1472,6 +1474,9 @@ angular.module('OpenSlidesApp.motions.site', [
motion['comment_' + $scope.commentFieldForRecommendationId] = recommendationExtension;
$scope.save(motion);
};
$scope.addMotionToRecommendationField = function (motion) {
$scope.recommendationExtension += MotionStateAndRecommendationParser.formatMotion(motion);
};
// update recommendation
$scope.updateRecommendation = function (recommendation_id) {
$http.put('/rest/motions/motion/' + motion.id + '/set_recommendation/', {'recommendation': recommendation_id});
@ -1645,11 +1650,11 @@ angular.module('OpenSlidesApp.motions.site', [
);
// Change recommendation creation functions
$scope.createChangeRecommendation = ChangeRecommmendationCreate;
$scope.createChangeRecommendation = ChangeRecommendationCreate;
$scope.createChangeRecommendation.init($scope, motion);
// Change recommendation viewing
$scope.viewChangeRecommendations = ChangeRecommmendationView;
$scope.viewChangeRecommendations = ChangeRecommendationView;
$scope.viewChangeRecommendations.init($scope, Config.get('motions_recommendation_text_mode').value);
// PDF creating functions
@ -2283,26 +2288,28 @@ angular.module('OpenSlidesApp.motions.site', [
'$scope',
'$stateParams',
'$http',
'MotionList',
'Category',
'categoryId',
'Motion',
'ErrorMessage',
function($scope, $stateParams, $http, MotionList, Category, categoryId, Motion, ErrorMessage) {
function($scope, $stateParams, $http, Category, categoryId, Motion, ErrorMessage) {
Category.bindOne(categoryId, $scope, 'category');
Motion.bindAll({}, $scope, 'motions');
$scope.filter = { category_id: categoryId,
parent_id: null,
orderBy: 'identifier' };
$scope.$watch(
function () {
return Motion.lastModified();
},
function () {
$scope.items = MotionList.getList(Motion.filter($scope.filter));
}
);
$scope.$watch(function () {
return Motion.lastModified();
}, function () {
var motions = Motion.filter($scope.filter);
$scope.items = _.map(motions, function (motion) {
return {
id: motion.id,
item: motion
};
});
});
$scope.alert = {};
// Numbers all motions in this category by the given order in $scope.items

View File

@ -224,7 +224,7 @@
<label class="sr-only" for="recommendationExtensionField">
{{ commentsFields[commentFieldForRecommendationId].name }}
</label>
<input type="text" ng-model="recommendationExtension"
<input type="text" ng-model="$parent.$parent.recommendationExtension"
id="recommendationExtensionField" class="form-control input-sm"
placeholder="{{ commentsFields[commentFieldForRecommendationId].name }}">
<span class="input-group-btn">
@ -232,6 +232,21 @@
<i class="fa fa-check"></i>
</button>
</span>
<span class="input-group-btn">
<span uib-dropdown>
<span id="motion-dropdown" class="drop-down-name btn btn-default btn-sm" uib-dropdown-toggle>
<i class="fa fa-plus"></i>
<translate>Motion</translate>
</span>
<ul uib-dropdown-menu class="dropdown-menu" aria-labelledby="motion-dropdown">
<li ng-repeat="m in motions">
<a href ng-click="addMotionToRecommendationField(m)">
{{ m.identifier ? m.identifier + ':' : '' }} {{ m.getTitle() }}
</a>
</li>
</ul>
</span>
</span>
</div>
<button
ng-if="motion.recommendation &&