From 33f80a575f7743080d5d6fe51aba7161b6899a32 Mon Sep 17 00:00:00 2001 From: gustavo Date: Fri, 29 Apr 2016 02:23:15 +0200 Subject: [PATCH] STOMP client, text area improvements --- angularjs/stomp/src/stomp/app/app.module.js | 1 + .../src/stomp/app/example/example.controller.js | 39 +++++++++++++------- angularjs/stomp/src/stomp/app/example/example.html | 19 +++++++--- .../src/stomp/app/widgets/auto-height.directive.js | 41 ++++++++++++++++++++++ .../stomp/src/stomp/app/widgets/widgets.module.js | 18 ++++++++++ angularjs/stomp/src/stomp/index.html | 2 ++ 6 files changed, 103 insertions(+), 17 deletions(-) create mode 100644 angularjs/stomp/src/stomp/app/widgets/auto-height.directive.js create mode 100644 angularjs/stomp/src/stomp/app/widgets/widgets.module.js diff --git a/angularjs/stomp/src/stomp/app/app.module.js b/angularjs/stomp/src/stomp/app/app.module.js index d89cc71..7059d83 100644 --- a/angularjs/stomp/src/stomp/app/app.module.js +++ b/angularjs/stomp/src/stomp/app/app.module.js @@ -18,6 +18,7 @@ angular.module('app', [ /* Shared modules */ 'app.core', + 'app.widgets', /* Feature areas */ 'app.example' diff --git a/angularjs/stomp/src/stomp/app/example/example.controller.js b/angularjs/stomp/src/stomp/app/example/example.controller.js index 4f7cb99..9d3fc0e 100644 --- a/angularjs/stomp/src/stomp/app/example/example.controller.js +++ b/angularjs/stomp/src/stomp/app/example/example.controller.js @@ -9,28 +9,41 @@ * @ngdoc controller * @name app.example.controller:ExampleController * - * @requires $rootScope - * @requires $scope + * @requires $location * *

*
- * {@link https://docs.angularjs.org/api/ng/service/$rootScope $rootScope} - * {@link https://docs.angularjs.org/api/ng/type/$rootScope.Scope $scope} + * {@link https://docs.angularjs.org/api/ng/service/$location $location} *

* * @description * ExampleController controller. */ /* @ngInject */ - function ExampleController() { + function ExampleController($location) { var vm = this; - var client; var subscription; - // vm.serverDestination = {}; - // vm.payload = {}; - // vm.headers = {}; + vm.url = $location.protocol() + '://' + $location.host() + '/spring-stomp-server/portfolio'; + vm.clientDestination = '/topic/greeting'; + vm.serverDestination = '/app/greeting'; + vm.connectHeaders = JSON.stringify({ + login: 'mylogin', + passcode: 'mypasscode', + // User defined headers + 'client-id': 'gumartin-id' + }, null, 4); + // User defined headers + vm.sendHeaders = JSON.stringify({ + priority: 9 + }, null, 4); + // User defined headers + vm.subscribeHeaders = JSON.stringify({ + id: 123456 + }, null, 4); + + vm.connect = function () { // use SockJS implementation instead of the browser's native implementation @@ -46,11 +59,11 @@ client = Stomp.over(ws); client.heartbeat.outgoing = 20000; // client will send heartbeats every 20000ms client.heartbeat.incoming = 0; // client does not want to receive heartbeats from the server - client.connect(vm.connectHeaders, connectCallback, errorCallback); + client.connect(JSON.parse(vm.connectHeaders), connectCallback, errorCallback); }; vm.subscribe = function () { - subscription = client.subscribe(vm.clientDestination, subscribeCallback); + subscription = client.subscribe(vm.clientDestination, subscribeCallback, JSON.parse(vm.subscribeHeaders)); }; vm.unsubscribe = function () { @@ -58,7 +71,7 @@ }; vm.send = function () { - client.send(vm.serverDestination, vm.headers, vm.payload); + client.send(vm.serverDestination, JSON.parse(vm.sendHeaders), vm.payload); }; vm.disconnect = function() { @@ -78,7 +91,7 @@ function subscribeCallback(message) { // called when the client receives a STOMP message from the server if (message.body) { - alert('got message with body ' + message.body) + alert('got message with body ' + message.body); } else { alert('got empty message'); } diff --git a/angularjs/stomp/src/stomp/app/example/example.html b/angularjs/stomp/src/stomp/app/example/example.html index 752c43e..283e7db 100644 --- a/angularjs/stomp/src/stomp/app/example/example.html +++ b/angularjs/stomp/src/stomp/app/example/example.html @@ -12,7 +12,8 @@
@@ -35,7 +36,15 @@
+ +
+
@@ -59,14 +68,16 @@

diff --git a/angularjs/stomp/src/stomp/app/widgets/auto-height.directive.js b/angularjs/stomp/src/stomp/app/widgets/auto-height.directive.js new file mode 100644 index 0000000..89bf98d --- /dev/null +++ b/angularjs/stomp/src/stomp/app/widgets/auto-height.directive.js @@ -0,0 +1,41 @@ +(function () { + 'use strict'; + + angular + .module('app.widgets') + .directive('autoHeight', autoHeight); + + /** + * @ngdoc directive + * @name app.widgets.directive:autoHeight + * @restrict EA + * + * + * @description + * Controller child directive example. + * + * @element auto-height-directive + * + * @example + + + + + + */ + function autoHeight() { + return { + restrict: 'EA', + link: linkFunc, + scope: {} + }; + + function linkFunc(scope, el, attr, ctrl) { + var height = (el[0].scrollHeight < 30) ? 80 : el[0].scrollHeight; + + height = height + 80; + el[0].style.height = height + 'px'; + } + } + +})(); diff --git a/angularjs/stomp/src/stomp/app/widgets/widgets.module.js b/angularjs/stomp/src/stomp/app/widgets/widgets.module.js new file mode 100644 index 0000000..de39fec --- /dev/null +++ b/angularjs/stomp/src/stomp/app/widgets/widgets.module.js @@ -0,0 +1,18 @@ +(function() { + 'use strict'; + + /** + * @ngdoc overview + * @name app.widgets + * + * @description + * # app.widgets + * + * ## Module widgets. + * Module for implementing widget directives. + */ + angular.module('app.widgets', [ + 'app.core' + ]); + +})(); diff --git a/angularjs/stomp/src/stomp/index.html b/angularjs/stomp/src/stomp/index.html index 20c4fff..3b89ad8 100644 --- a/angularjs/stomp/src/stomp/index.html +++ b/angularjs/stomp/src/stomp/index.html @@ -55,6 +55,8 @@ + + -- 2.1.4