Merge pull request #2620 from FinnStutzenstein/Issue2590

Highlighting motions for multiprojector and move httpProvider (fixes …
This commit is contained in:
Emanuel Schütze 2016-11-15 20:21:19 +01:00 committed by GitHub
commit b9a325ba5d
4 changed files with 26 additions and 54 deletions

View File

@ -15,6 +15,15 @@ angular.module('OpenSlidesApp.core', [
'OpenSlidesApp-templates', 'OpenSlidesApp-templates',
]) ])
.config([
'$httpProvider',
function($httpProvider) {
// Combine the django csrf system with the angular csrf system
$httpProvider.defaults.xsrfCookieName = 'csrftoken';
$httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken';
}
])
.config([ .config([
'DSProvider', 'DSProvider',
'DSHttpAdapterProvider', 'DSHttpAdapterProvider',

View File

@ -139,15 +139,6 @@ angular.module('OpenSlidesApp.core.site', [
} }
]) ])
.config([
'$httpProvider',
function($httpProvider) {
// Combine the django csrf system with the angular csrf system
$httpProvider.defaults.xsrfCookieName = 'csrftoken';
$httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken';
}
])
.config([ .config([
'$stateProvider', '$stateProvider',
'$urlMatcherFactoryProvider', '$urlMatcherFactoryProvider',

View File

@ -25,45 +25,15 @@ angular.module('OpenSlidesApp.motions.projector', [
'Config', 'Config',
'Projector', 'Projector',
'$timeout', '$timeout',
function($scope, $rootScope, $http, Motion, User, Config, Projector, $timeout) { 'ProjectorID',
function($scope, $rootScope, $http, Motion, User, Config, Projector, $timeout, ProjectorID) {
// Attention! Each object that is used here has to be dealt on server side. // Attention! Each object that is used here has to be dealt on server side.
// Add it to the coresponding get_requirements method of the ProjectorElement // Add it to the coresponding get_requirements method of the ProjectorElement
// class. // class.
var id = $scope.element.id; var id = $scope.element.id;
var thisProjector = Projector.get(ProjectorID());
$scope.line = $scope.element.highlightAndScroll; $scope.line = $scope.element.highlightAndScroll;
// get cookie using jQuery
var getCookie = function (name) {
var cookieValue = null;
if (document.cookie && document.cookie !== '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
};
var scrollRequest = function (position) {
// request with csrf token
// TODO: Why is the X-CSRFToken not included in the header by default?
var csrfToken = getCookie('csrftoken');
var request = {
method: 'POST',
url: '/rest/core/projector/1/set_scroll/',
data: position,
headers: {
'X-CSRFToken': csrfToken
}
};
$http(request);
};
$scope.scroll = function () { $scope.scroll = function () {
// Prevent getting in an infinite loop by updating only if the value has changed. // Prevent getting in an infinite loop by updating only if the value has changed.
// (if this check is removed this happends: controller loads --> call of $scope.scroll // (if this check is removed this happends: controller loads --> call of $scope.scroll
@ -73,11 +43,11 @@ angular.module('OpenSlidesApp.motions.projector', [
var lineElement = document.getElementsByName('L' + $scope.line); var lineElement = document.getElementsByName('L' + $scope.line);
if (lineElement[0]) { if (lineElement[0]) {
$rootScope.motion_projector_line = $scope.line; $rootScope.motion_projector_line = $scope.line;
var pos = lineElement[0].getBoundingClientRect().top + Projector.get(1).scroll*80; var pos = lineElement[0].getBoundingClientRect().top + thisProjector.scroll*80;
scrollRequest(Math.floor(pos/80.0) - 1); $http.post('/rest/core/projector/' + thisProjector.id + '/set_scroll/', Math.floor(pos/80.0) - 1);
} else if ($scope.line === 0) { } else if ($scope.line === 0) {
$rootScope.motion_projector_line = $scope.line; $rootScope.motion_projector_line = $scope.line;
scrollRequest(0); $http.post('/rest/core/projector/' + thisProjector.id + '/set_scroll/', 0);
} }
} }
}; };

View File

@ -1066,16 +1066,18 @@ angular.module('OpenSlidesApp.motions.site', [
$scope.linesForProjector = false; $scope.linesForProjector = false;
// Set 0 for disable highlighting on projector // Set 0 for disable highlighting on projector
var setHighlightOnProjector = function (line) { var setHighlightOnProjector = function (line) {
var elements = _.map(Projector.get(1).elements, function(element) { return element; }); _.forEach(Projector.getAll(), function (projector) {
var elements = _.map(projector.elements, function(element) { return element; });
elements.forEach(function (element) { elements.forEach(function (element) {
if (element.name == 'motions/motion') { if (element.name == 'motions/motion' && element.id == motion.id) {
var data = {}; var data = {};
data[element.uuid] = { data[element.uuid] = {
highlightAndScroll: line, highlightAndScroll: line,
}; };
$http.post('/rest/core/projector/1/update_elements/', data); $http.post('/rest/core/projector/' + projector.id + '/update_elements/', data);
} }
}); });
});
}; };
$scope.scrollToAndHighlight = function (line) { $scope.scrollToAndHighlight = function (line) {
$scope.highlight = line; $scope.highlight = line;