Browse Source

added websocket notifications

tags/v0.1.1
Robin Thoni 7 years ago
parent
commit
e658e653af

+ 1
- 1
dist/luticate-utils.min.js
File diff suppressed because it is too large
View File


+ 47
- 0
src/Business/lu-notifications-business.js View File

@@ -0,0 +1,47 @@
1
+/**
2
+ * Created by robin on 12/11/16.
3
+ */
4
+
5
+(function () {
6
+    'use strict';
7
+    angular.module('luticate2Utils')
8
+        .factory('luNotificationsBusiness', ['luNotificationsDataAccess', function(luNotificationsDataAccess) {
9
+
10
+            var luNotificationsBusiness = {};
11
+
12
+            luNotificationsBusiness.EVENT_CREATE = 'EVENT_CREATE';
13
+
14
+            luNotificationsBusiness.EVENT_UPDATE = 'EVENT_UPDATE';
15
+
16
+            luNotificationsBusiness.EVENT_DELETE = 'EVENT_DELETE';
17
+
18
+
19
+            luNotificationsBusiness.init = function () {
20
+                luNotificationsDataAccess.init();
21
+            };
22
+
23
+            luNotificationsBusiness.addEventCreateCallback = function (entityType, callback) {
24
+                luNotificationsDataAccess.addCallback(luNotificationsBusiness.EVENT_CREATE, entityType, callback);
25
+            };
26
+
27
+            luNotificationsBusiness.addEventUpdateCallback = function (entityType, callback) {
28
+                luNotificationsDataAccess.addCallback(luNotificationsBusiness.EVENT_UPDATE, entityType, callback);
29
+            };
30
+
31
+            luNotificationsBusiness.addEventDeleteCallback = function (entityType, callback) {
32
+                luNotificationsDataAccess.addCallback(luNotificationsBusiness.EVENT_DELETE, entityType, callback);
33
+            };
34
+
35
+            luNotificationsBusiness.addEventCrudCallback = function (entityType, callback) {
36
+                luNotificationsBusiness.addEventCreateCallback(entityType, callback);
37
+                luNotificationsBusiness.addEventUpdateCallback(entityType, callback);
38
+                luNotificationsBusiness.addEventDeleteCallback(entityType, callback);
39
+            };
40
+
41
+
42
+
43
+
44
+            return luNotificationsBusiness;
45
+
46
+        }]);
47
+})();

+ 84
- 0
src/DataAccess/lu-notifications-dataaccess.js View File

@@ -0,0 +1,84 @@
1
+/**
2
+ * Created by robin on 12/11/16.
3
+ */
4
+
5
+(function () {
6
+    'use strict';
7
+    angular.module('luticate2Utils')
8
+        .factory('luNotificationsDataAccess', ['Hub', function(Hub) {
9
+
10
+            var luNotificationsDataAccess = {};
11
+
12
+            luNotificationsDataAccess.hub = null;
13
+
14
+            luNotificationsDataAccess.callbacks = {};
15
+
16
+            luNotificationsDataAccess.addCallback = function (eventName, entityType, callback) {
17
+                if (luNotificationsDataAccess.callbacks[eventName] == null) {
18
+                    luNotificationsDataAccess.callbacks[eventName] = {};
19
+                }
20
+                var event = luNotificationsDataAccess.callbacks[eventName];
21
+                if (event[entityType] == null) {
22
+                    event[entityType] = [];
23
+                }
24
+                event[entityType].push(callback);
25
+            };
26
+
27
+            luNotificationsDataAccess.init = function () {
28
+                luNotificationsDataAccess.hub = new Hub('luNotificationsHub', {
29
+
30
+                    //client side methods
31
+                    listeners:{
32
+                        'notify': function (eventName, entityType, oldEntity, newEntity) {
33
+                            var event = luNotificationsDataAccess.callbacks[eventName];
34
+                            if (event != null) {
35
+                                var type = event[entityType];
36
+                                if (type != null) {
37
+                                    for (var i = 0; i < type.length; ++i) {
38
+                                        type[i](eventName, entityType, oldEntity, newEntity);
39
+                                    }
40
+                                }
41
+                            }
42
+                        }
43
+                    },
44
+
45
+                    //server side methods
46
+                    methods: [],
47
+
48
+                    //query params sent on initial connection
49
+                    queryParams:{
50
+                    },
51
+
52
+                    //handle connection error
53
+                    errorHandler: function(error){
54
+                        console.error(error);
55
+                    },
56
+
57
+                    //specify a non default root
58
+                    // rootPath: 'http://127.0.0.1:8080/signalr/',
59
+
60
+                    stateChanged: function(state){
61
+                        switch (state.newState) {
62
+                            case $.signalR.connectionState.connecting:
63
+                                //your code here
64
+                                break;
65
+                            case $.signalR.connectionState.connected:
66
+                                //your code here
67
+                                break;
68
+                            case $.signalR.connectionState.reconnecting:
69
+                                //your code here
70
+                                break;
71
+                            case $.signalR.connectionState.disconnected:
72
+                                //your code here
73
+                                break;
74
+                        }
75
+                    }
76
+                });
77
+            };
78
+
79
+
80
+
81
+            return luNotificationsDataAccess;
82
+
83
+        }]);
84
+})();

Loading…
Cancel
Save