Reorder projection of motions (fixes #2883)

This commit is contained in:
FinnStutzenstein 2017-01-16 15:15:29 +01:00
parent e9e0280a13
commit 2ac7df2ee6
2 changed files with 50 additions and 35 deletions

View File

@ -495,16 +495,25 @@ angular.module('OpenSlidesApp.motions', [
return false; return false;
} }
}, },
// Overrides from jsDataModel factory /* Overrides from jsDataModel factory.
* Also sets the projection mode if given; If not it projects in 'original' mode. */
project: function (projectorId, mode) { project: function (projectorId, mode) {
// if this object is already projected on projectorId, delete this element from this projector // if this object is already projected on projectorId, delete this element from this projector
var isProjectedIds = this.isProjected(mode); var isProjected = this.isProjectedWithMode();
_.forEach(isProjectedIds, function (id) { _.forEach(isProjected, function (mapping) {
$http.post('/rest/core/projector/' + id + '/clear_elements/'); $http.post('/rest/core/projector/' + mapping.projectorId + '/clear_elements/');
});
// Was there a projector with the same id and mode as the given id and mode?
// If not, project the motion.
var wasProjectedBefore = _.some(isProjected, function (mapping) {
var value = (mapping.projectorId === projectorId);
if (mode) {
value = value && (mapping.mode === mode);
}
return value;
}); });
mode = mode || 'original'; mode = mode || 'original';
// Show the element, if it was not projected before on the given projector if (!wasProjectedBefore) {
if (_.indexOf(isProjectedIds, projectorId) === -1) {
return $http.post( return $http.post(
'/rest/core/projector/' + projectorId + '/prune_elements/', '/rest/core/projector/' + projectorId + '/prune_elements/',
[{name: name, [{name: name,
@ -531,6 +540,23 @@ angular.module('OpenSlidesApp.motions', [
}); });
return projectorIds; return projectorIds;
}, },
/* returns a list of mappings between projector id and mode:
* [ {projectorId: 2, mode: 'original'}, ... ] */
isProjectedWithMode: function () {
var self = this;
var mapping = [];
_.forEach(Projector.getAll(), function (projector) {
_.forEach(projector.elements, function (element) {
if (element.name === name && element.id === self.id) {
mapping.push({
projectorId: projector.id,
mode: element.mode || 'original',
});
}
});
});
return mapping;
},
}, },
relations: { relations: {
belongsTo: { belongsTo: {

View File

@ -1075,7 +1075,6 @@ angular.module('OpenSlidesApp.motions.site', [
.controller('MotionDetailCtrl', [ .controller('MotionDetailCtrl', [
'$scope', '$scope',
'$http', '$http',
'$timeout',
'operator', 'operator',
'ngDialog', 'ngDialog',
'MotionForm', 'MotionForm',
@ -1096,7 +1095,7 @@ angular.module('OpenSlidesApp.motions.site', [
'MotionCommentsInlineEditing', 'MotionCommentsInlineEditing',
'Projector', 'Projector',
'ProjectionDefault', 'ProjectionDefault',
function($scope, $http, $timeout, operator, ngDialog, MotionForm, function($scope, $http, operator, ngDialog, MotionForm,
ChangeRecommmendationCreate, ChangeRecommmendationView, MotionChangeRecommendation, MotionPDFExport, ChangeRecommmendationCreate, ChangeRecommmendationView, MotionChangeRecommendation, MotionPDFExport,
Motion, MotionComment, Category, Mediafile, Tag, User, Workflow, Config, motion, MotionInlineEditing, Motion, MotionComment, Category, Mediafile, Tag, User, Workflow, Config, motion, MotionInlineEditing,
MotionCommentsInlineEditing, Projector, ProjectionDefault) { MotionCommentsInlineEditing, Projector, ProjectionDefault) {
@ -1138,35 +1137,25 @@ angular.module('OpenSlidesApp.motions.site', [
{mode: 'agreed', {mode: 'agreed',
label: 'Resolution'}, label: 'Resolution'},
]; ];
var getProjectionMode = function () { $scope.projectionMode = $scope.projectionModes[0];
var projectedIds = motion.isProjected(); if (motion.isProjected().length) {
if (projectedIds.length) { var modeMapping = motion.isProjectedWithMode();
var element = _.find(Projector.get(projectedIds[0]).elements, function (element) { _.forEach($scope.projectionModes, function (mode) {
return element.name === 'motions/motion' && element.id === motion.id; if (mode.mode === modeMapping[0].mode) {
}); $scope.projectionMode = mode;
var modeName = element.mode || 'original', mode; }
_.forEach($scope.projectionModes, function (_mode) { });
if (_mode.mode === modeName) { }
mode = _mode;
}
});
return mode || $scope.projectionModes[0];
} else {
return $scope.projectionModes[0];
}
};
$scope.projectionMode = getProjectionMode();
// TODO: Fix this timeout; check what mode is projected.
$scope.setProjectionMode = function (mode) { $scope.setProjectionMode = function (mode) {
$scope.projectionMode = mode; $scope.projectionMode = mode;
var isProjected = motion.isProjectedWithMode();
var projectedIds = motion.isProjected(); if (isProjected.length) {
_.forEach(projectedIds, function (id) { _.forEach(isProjected, function (mapping) {
motion.project(id, mode.mode); if (mapping.mode != mode.mode) { // change the mode if it is different
$timeout(function () { motion.project(mapping.projectorId, mode.mode);
motion.project(id, mode.mode); }
}, 100); });
}); }
}; };
$scope.commentsFields = Config.get('motions_comments').value; $scope.commentsFields = Config.get('motions_comments').value;
$scope.commentFieldForState = MotionComment.getFieldNameForFlag('forState'); $scope.commentFieldForState = MotionComment.getFieldNameForFlag('forState');