Added first chatbox draft on client side.

This commit is contained in:
Norman Jäckel 2015-09-21 22:02:23 +02:00 committed by Emanuel Schuetze
parent c6d9701369
commit b1dfd2a4e9
3 changed files with 70 additions and 14 deletions

View File

@ -80,9 +80,10 @@ angular.module('OpenSlidesApp.core', [
.factory('loadGlobalData', [
'$rootScope',
'$http',
'ChatMessage',
'Config',
'Projector',
function ($rootScope, $http, Config, Projector) {
function ($rootScope, $http, ChatMessage, Config, Projector) {
return function () {
// Puts the config object into each scope.
Config.findAll().then(function() {
@ -100,6 +101,9 @@ angular.module('OpenSlidesApp.core', [
// Loads all projector data
Projector.findAll();
// Loads all chat messages data
ChatMessage.findAll();
// Loads server time and calculates server offset
$http.get('/core/servertime/').then(function(data) {
$rootScope.serverOffset = Math.floor( Date.now() / 1000 - data.data );
@ -181,6 +185,20 @@ angular.module('OpenSlidesApp.core', [
});
}])
.factory('ChatMessage', ['DS', function(DS) {
return DS.defineResource({
name: 'core/chatmessage',
relations: {
belongsTo: {
'users/user': {
localField: 'user',
localKey: 'user_id',
}
}
}
});
}])
/* Model for a projector.
*
* At the moment we use only one projector, so there will be only one object
@ -258,6 +276,13 @@ angular.module('OpenSlidesApp.core', [
})
// Make sure that the DS factories are loaded by making them a dependency
.run(['Projector', 'Config', 'Tag', 'Customslide', function(Projector, Config, Tag, Customslide){}]);
.run([
'ChatMessage',
'Config',
'Customslide',
'Projector',
'Tag',
function (ChatMessage, Config, Customslide, Projector, Tag) {}
]);
}());

View File

@ -752,6 +752,25 @@ angular.module('OpenSlidesApp.core.site', [
};
})
// ChatMessage Controller
.controller('ChatMessageCtrl', [
'$scope',
'$http',
'ChatMessage',
function ($scope, $http, ChatMessage) {
ChatMessage.bindAll({}, $scope, 'chatmessages');
$scope.sendMessage = function () {
$http.post(
'/rest/core/chatmessage/',
{message: $scope.newMessage}
)
.success(function () {
$scope.newMessage = '';
});
};
}
])
.directive('osFocusMe', function ($timeout) {
return {
link: function (scope, element, attrs, model) {

View File

@ -127,9 +127,10 @@
</nav>
<!-- Container -->
<div class="container-fluid" id="container">
<div id="container" class="container-fluid">
<div class="row">
<div class="col-md-2 leftmenu lefticon">
<!-- Main menu -->
<div id="main-menu" class="col-md-2 leftmenu lefticon">
<ul ng-controller="MainMenuCtrl">
<li ng-repeat="element in elements">
<a ui-sref="{{ element.ui_sref }}">
@ -137,8 +138,7 @@
<span class="text" translate>{{ element.title }}</span>
</a>
</ul>
</div>
</div><!--/#main-menu-->
<!-- Content -->
<div id="content" class="col-md-10">
<div class="row">
@ -146,16 +146,28 @@
<div ui-view></div>
</div>
</div>
<hr />
<footer>
<small>
&copy; Copyright 2011-2015 |
Powered by <a href="http://openslides.org" target="_blank">OpenSlides</a> |
<a ui-sref="version">Version</a>
</small>
</footer>
</div><!--/#content-->
</div><!--/.row-->
<div ng-controller="ChatMessageCtrl">
<ul>
<li ng-repeat="chatmessage in chatmessages">
{{ chatmessage.user.get_full_name() }} says {{ chatmessage.message }} on {{ chatmessage.timestamp }}
</ul>
<input ng-model="newMessage">
<button ng-click="sendMessage()" class="btn btn-primary" translate>
Chat
</button>
</div>
<hr>
<footer>
<small>
&copy; Copyright 2011-2015 |
Powered by <a href="http://openslides.org" target="_blank">OpenSlides</a> |
<a ui-sref="version">Version</a>
</small>
</footer>
</div><!--/#container-->
<script src="/angular_js/site/"></script>