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', [ .factory('loadGlobalData', [
'$rootScope', '$rootScope',
'$http', '$http',
'ChatMessage',
'Config', 'Config',
'Projector', 'Projector',
function ($rootScope, $http, Config, Projector) { function ($rootScope, $http, ChatMessage, Config, Projector) {
return function () { return function () {
// Puts the config object into each scope. // Puts the config object into each scope.
Config.findAll().then(function() { Config.findAll().then(function() {
@ -100,6 +101,9 @@ angular.module('OpenSlidesApp.core', [
// Loads all projector data // Loads all projector data
Projector.findAll(); Projector.findAll();
// Loads all chat messages data
ChatMessage.findAll();
// Loads server time and calculates server offset // Loads server time and calculates server offset
$http.get('/core/servertime/').then(function(data) { $http.get('/core/servertime/').then(function(data) {
$rootScope.serverOffset = Math.floor( Date.now() / 1000 - data.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. /* Model for a projector.
* *
* At the moment we use only one projector, so there will be only one object * 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 // 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) { .directive('osFocusMe', function ($timeout) {
return { return {
link: function (scope, element, attrs, model) { link: function (scope, element, attrs, model) {

View File

@ -127,9 +127,10 @@
</nav> </nav>
<!-- Container --> <!-- Container -->
<div class="container-fluid" id="container"> <div id="container" class="container-fluid">
<div class="row"> <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"> <ul ng-controller="MainMenuCtrl">
<li ng-repeat="element in elements"> <li ng-repeat="element in elements">
<a ui-sref="{{ element.ui_sref }}"> <a ui-sref="{{ element.ui_sref }}">
@ -137,8 +138,7 @@
<span class="text" translate>{{ element.title }}</span> <span class="text" translate>{{ element.title }}</span>
</a> </a>
</ul> </ul>
</div> </div><!--/#main-menu-->
<!-- Content --> <!-- Content -->
<div id="content" class="col-md-10"> <div id="content" class="col-md-10">
<div class="row"> <div class="row">
@ -146,7 +146,21 @@
<div ui-view></div> <div ui-view></div>
</div> </div>
</div> </div>
<hr /> </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> <footer>
<small> <small>
&copy; Copyright 2011-2015 | &copy; Copyright 2011-2015 |
@ -154,8 +168,6 @@
<a ui-sref="version">Version</a> <a ui-sref="version">Version</a>
</small> </small>
</footer> </footer>
</div><!--/#content-->
</div><!--/.row-->
</div><!--/#container--> </div><!--/#container-->
<script src="/angular_js/site/"></script> <script src="/angular_js/site/"></script>