Merge pull request #1566 from ostcar/projector_activation

Added projector methods to user model
This commit is contained in:
Norman Jäckel 2015-06-24 13:52:39 +02:00
commit 6187ec450d
3 changed files with 45 additions and 25 deletions

View File

@ -35,7 +35,7 @@ angular.module('OpenSlidesApp.core', [])
}); });
}) })
.run(function($rootScope, Config) { .run(function($rootScope, Config, Projector) {
// Puts the config object into each scope. // Puts the config object into each scope.
// TODO: maybe rootscope.config has to set before findAll() is finished // TODO: maybe rootscope.config has to set before findAll() is finished
Config.findAll().then(function() { Config.findAll().then(function() {
@ -49,6 +49,9 @@ angular.module('OpenSlidesApp.core', [])
} }
} }
}); });
// Loads all projector data
Projector.findAll();
}) })
.factory('autoupdate', function() { .factory('autoupdate', function() {
@ -79,10 +82,38 @@ angular.module('OpenSlidesApp.core', [])
return Autoupdate; return Autoupdate;
}) })
.factory('Customslide', function(DS) { .factory('jsDataModel', function($http, Projector) {
var BaseModel = function() {};
BaseModel.prototype.project = function() {
return $http.post(
'/rest/core/projector/1/prune_elements/',
[{name: this.getResourceName(), id: this.id}]
);
}
BaseModel.prototype.isProjected = function() {
// Returns true if there is a projector element with the same
// name and the same id.
var projector = Projector.get(id=1);
var self = this;
return _.findIndex(projector.elements, function(element) {
return element.name == self.getResourceName() &&
typeof(element.context.id) !== 'undefined' &&
element.context.id == self.id;
}) > -1;
}
return BaseModel;
})
.factory('Customslide', function(DS, jsDataModel) {
var name = 'core/customslide'
return DS.defineResource({ return DS.defineResource({
name: 'core/customslide', name: name,
endpoint: '/rest/core/customslide/' endpoint: '/rest/core/customslide/',
methods: {
getResourceName: function () {
return name;
},
},
}); });
}) })
@ -294,17 +325,6 @@ angular.module('OpenSlidesApp.core.site', ['OpenSlidesApp.core'])
editableOptions.theme = 'bs3'; editableOptions.theme = 'bs3';
}) })
// Activate an Element from the Rest-API on the projector
// At the moment it only activates item on projector 1
.factory('projectorActivate', function($http) {
return function(model, id) {
return $http.post(
'/rest/core/projector/1/prune_elements/',
[{name: model.name, id: id}]
);
};
})
.controller("LanguageCtrl", function ($scope, gettextCatalog) { .controller("LanguageCtrl", function ($scope, gettextCatalog) {
// controller to switch app language // controller to switch app language
// TODO: detect browser language for default language // TODO: detect browser language for default language

View File

@ -1,10 +1,15 @@
angular.module('OpenSlidesApp.users', []) angular.module('OpenSlidesApp.users', [])
.factory('User', function(DS, Group) { .factory('User', function(DS, Group, jsDataModel) {
var name = 'users/user'
return DS.defineResource({ return DS.defineResource({
name: 'users/user', name: name,
endpoint: '/rest/users/user/', endpoint: '/rest/users/user/',
useClass: jsDataModel,
methods: { methods: {
getResourceName: function () {
return name;
},
get_short_name: function() { get_short_name: function() {
// should be the same as in the python user model. // should be the same as in the python user model.
var firstName = _.trim(this.first_name), var firstName = _.trim(this.first_name),
@ -280,7 +285,7 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
}; };
}]) }])
.controller('UserListCtrl', function($scope, User, projectorActivate) { .controller('UserListCtrl', function($scope, User) {
User.bindAll({}, $scope, 'users'); User.bindAll({}, $scope, 'users');
// setup table sorting // setup table sorting
@ -305,10 +310,6 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
$scope.delete = function (user) { $scope.delete = function (user) {
User.destroy(user.id); User.destroy(user.id);
}; };
$scope.project = function(user) {
projectorActivate(User, user.id).error(function() {console.log('success')});
};
}) })
.controller('UserDetailCtrl', function($scope, User, user) { .controller('UserDetailCtrl', function($scope, User, user) {

View File

@ -105,11 +105,10 @@
<td class="optional">{{ user.groups }} <td class="optional">{{ user.groups }}
<td os-perms="users.can_manage" class="optional">{{ user.last_login | date:'yyyy-MM-dd HH:mm:ss'}} <td os-perms="users.can_manage" class="optional">{{ user.last_login | date:'yyyy-MM-dd HH:mm:ss'}}
<td os-perms="users.can_manage core.can_manage_projector" class="nobr"> <td os-perms="users.can_manage core.can_manage_projector" class="nobr">
<!-- projector, TODO: add link to activate slidea-->
<a os-perms="core.can_manage_projector" class="btn btn-default btn-sm" <a os-perms="core.can_manage_projector" class="btn btn-default btn-sm"
ng-click="project(user)" ng-click="user.project()"
title="{{ 'Show' | translate }}"> title="{{ 'Show' | translate }}">
<i class="fa fa-video-camera"></i> <i class="fa fa-video-camera"><span ng-if="user.isProjected()">projected</span></i>
</a> </a>
<!-- edit --> <!-- edit -->
<a ui-sref="users.user.detail.update({id: user.id})" os-perms="users.can_manage" <a ui-sref="users.user.detail.update({id: user.id})" os-perms="users.can_manage"