Преглед изворни кода

added websocket notifications; added delete button on edit page

tags/v0.1.0
Robin Thoni пре 7 година
родитељ
комит
c04c9df8a4

+ 72
- 24
app/app.js Прегледај датотеку

@@ -12,6 +12,7 @@ angular.module('app', [
12 12
     'pascalprecht.translate',
13 13
     'angular-busy',
14 14
     'luticate2Utils',
15
+    'SignalR',
15 16
     // 'luticateAuth',
16 17
     'appSdk'
17 18
 ])
@@ -132,7 +133,10 @@ angular.module('app', [
132 133
                 toolbarTitle: "pkguid.add.defaultToolbarTitle",
133 134
                 reloadOnSearch: false,
134 135
                 templateUrl:'views/pkguidedit.html',
135
-                controller:'PkGuidEditController'
136
+                controller:'PkGuidEditController',
137
+                params: {
138
+                    pkguid: null
139
+                }
136 140
             });
137 141
 
138 142
             $stateProvider.state('pkguid_edit', {
@@ -150,41 +154,85 @@ angular.module('app', [
150 154
 
151 155
             $urlRouterProvider.otherwise('/');
152 156
     }])
153
-    .run(['$rootScope', '$transitions', 'AppUtilsBusiness', 'ssSideNav', '$translate', 'luRequest', '$mdDialog',
154
-        function ($rootScope, $transitions, AppUtilsBusiness, ssSideNav, $translate, luRequest, $mdDialog) {
155
-
156
-        var apiVersion = null;
157
+    .run(['$rootScope', '$transitions', 'AppUtilsBusiness', 'ssSideNav', '$translate', 'luRequest', '$mdDialog', 'luNotificationsBusiness', '$mdToast', '$state',
158
+        function ($rootScope, $transitions, AppUtilsBusiness, ssSideNav, $translate, luRequest, $mdDialog, luNotificationsBusiness, $mdToast, $state) {
157 159
 
158
-        function apiVersionChanged(oldVersion, newVersion) {
160
+        AppUtilsBusiness.addApiVersionChangedCallback(function(oldVersion, newVersion) {
159 161
             $mdDialog.show(
160 162
                 $mdDialog.alert()
161 163
                     .title(AppUtilsBusiness.tr('common.updateDetected.title'))
162
-                    .textContent(AppUtilsBusiness.tr('common.updateDetected.text', {oldVersion: oldVersion, newVersion: newVersion}))
164
+                    .textContent(AppUtilsBusiness.tr('common.updateDetected.text',
165
+                        {oldVersion: oldVersion, newVersion: newVersion}))
163 166
                     .ok(AppUtilsBusiness.tr('common.ok')));
164
-        }
165
-
166
-        luRequest.addHook('resolve', function(url, method, dataGet, dataPost, luBusyGroups, data)
167
-        {
168
-            if (apiVersion == null) {
169
-                apiVersion = data.version;
170
-            }
171
-            else if (data.version != null && data.version != apiVersion) {
172
-                apiVersionChanged(apiVersion, data.version);
173
-                apiVersion = data.version;
174
-            }
175 167
         });
176 168
 
177
-        luRequest.addHook('reject', function(url, method, dataGet, dataPost, luBusyGroups, error)
169
+        luNotificationsBusiness.init();
170
+
171
+        luNotificationsBusiness.addEventCrudCallback('pkguid', function(eventName, entityType, oldEntity, newEntity)
178 172
         {
179
-            if (apiVersion == null) {
180
-                apiVersion = error.data.version;
173
+            var text = null;
174
+            if (eventName == luNotificationsBusiness.EVENT_CREATE) {
175
+                text = AppUtilsBusiness.tr('pkguid.notifications.create', {text: newEntity.someText});
176
+            }
177
+            else if (eventName == luNotificationsBusiness.EVENT_UPDATE) {
178
+                text = AppUtilsBusiness.tr('pkguid.notifications.update', {text: newEntity.someText});
181 179
             }
182
-            else if (error.data.version != null && error.data.version != apiVersion) {
183
-                apiVersionChanged(apiVersion, error.data.version);
184
-                apiVersion = error.data.version;
180
+            else if (eventName == luNotificationsBusiness.EVENT_DELETE) {
181
+                text = AppUtilsBusiness.tr('pkguid.notifications.delete', {text: oldEntity.someText});
185 182
             }
183
+            var toast = $mdToast.simple()
184
+                .textContent(text)
185
+                .action(eventName == luNotificationsBusiness.EVENT_DELETE ? AppUtilsBusiness.tr('common.undo') : AppUtilsBusiness.tr('common.view'))
186
+                .highlightAction(true)
187
+                .highlightClass('md-accent')
188
+                .position('bottom right');
189
+
190
+            $mdToast.show(toast).then(function(response) {
191
+                if (response == 'ok') {
192
+                    if (eventName == luNotificationsBusiness.EVENT_DELETE) {
193
+                        oldEntity.id = null;
194
+                        $state.go('pkguid_add', {pkguid: oldEntity});
195
+                    }
196
+                    else {
197
+                        $state.go('pkguid_edit', {id: newEntity.id, pkguid: newEntity});
198
+                    }
199
+                }
200
+            });
186 201
         });
187 202
 
203
+        // luNotificationsBusiness.addEventDeleteCallback('pkguid', function(eventName, entityType, oldEntity)
204
+        // {
205
+        //     var toast = $mdToast.simple()
206
+        //         .textContent("PkGuid \'" + oldEntity.someText + "\' was deleted")
207
+        //         .action("Undo")
208
+        //         .highlightAction(true)
209
+        //         .highlightClass('md-accent')
210
+        //         .position('bottom right');
211
+        //
212
+        //     $mdToast.show(toast).then(function(response) {
213
+        //         if (response == 'ok') {
214
+        //             oldEntity.id = null;
215
+        //             $state.go('pkguid_add', {pkguid: oldEntity});
216
+        //         }
217
+        //     });
218
+        // });
219
+        //
220
+        // luNotificationsBusiness.addEventCreateCallback('pkguid', function(eventName, entityType, oldEntity, newEntity)
221
+        // {
222
+        //     var toast = $mdToast.simple()
223
+        //         .textContent("PkGuid \'" + newEntity.someText + "\' was added")
224
+        //         .action("View")
225
+        //         .highlightAction(true)
226
+        //         .highlightClass('md-accent')
227
+        //         .position('bottom right');
228
+        //
229
+        //     $mdToast.show(toast).then(function(response) {
230
+        //         if (response == 'ok') {
231
+        //             $state.go('pkguid_edit', {id: newEntity.id, pkguid: newEntity});
232
+        //         }
233
+        //     });
234
+        // });
235
+
188 236
         $translate('common.appName').then(function() {
189 237
             for (var i = 0; i < ssSideNav.sections.length; ++i) {
190 238
                 var a = ssSideNav.sections[i];

+ 3
- 3
app/controllers/pkguid.controller.js Прегледај датотеку

@@ -37,9 +37,7 @@ angular.module('app')
37 37
                     pkGuidBusiness.deleteDbo(pkguid.id, 'pkguid.table').then(function(data)
38 38
                     {
39 39
                         $scope.getPkGuids();
40
-                    }, function(error)
41
-                    {
42
-                    });
40
+                    }, function(error) {});
43 41
                 }, function () {});
44 42
             };
45 43
 
@@ -82,5 +80,7 @@ angular.module('app')
82 80
                 });
83 81
             };
84 82
 
83
+
84
+
85 85
             $scope.getPkGuids();
86 86
     }]);

+ 14
- 0
app/controllers/pkguidedit.controller.js Прегледај датотеку

@@ -35,6 +35,20 @@ angular.module('app')
35 35
                 }
36 36
             };
37 37
 
38
+            $scope.askRemoveOne = function (pkguid) {
39
+                var confirm = $mdDialog.confirm()
40
+                    .title(AppUtilsBusiness.tr('common.confirmDelete'))
41
+                    .textContent(AppUtilsBusiness.tr('pkguid.deleteOne', {text: pkguid.someText}))
42
+                    .ok(AppUtilsBusiness.tr('common.delete'))
43
+                    .cancel(AppUtilsBusiness.tr('common.cancel'));
44
+                $mdDialog.show(confirm).then(function() {
45
+                    pkGuidBusiness.deleteDbo(pkguid.id, 'pkguid.edit').then(function(data)
46
+                    {
47
+                        $state.go('pkguid');
48
+                    }, function(error) {});
49
+                }, function () {});
50
+            };
51
+
38 52
 
39 53
             if ($state.params != null) {
40 54
                 if ($state.params.pkguid != null) {

+ 3
- 0
app/index.html Прегледај датотеку

@@ -46,6 +46,9 @@
46 46
     <script src="../bower_components/messageformat/messageformat.js"></script>
47 47
     <script src="../bower_components/angular-translate-interpolation-messageformat/angular-translate-interpolation-messageformat.min.js"></script>
48 48
     <script src="../bower_components/angular-busy2/dist/angular-busy.js"></script>
49
+    <script src="../bower_components/signalr/jquery.signalR.min.js"></script>
50
+    <script src="/signalr/hubs"></script>
51
+    <script src="../bower_components/angular-signalr-hub/signalr-hub.min.js"></script>
49 52
     <!--<script src="../bower_components/luticate-auth/dist/luticate-auth.min.js"></script>-->
50 53
     <!--<script src="../bower_components/angular-dialog-service/dist/dialogs.js"></script>-->
51 54
     <!--<script src="../bower_components/angular-sanitize/angular-sanitize.js"></script>-->

+ 8
- 0
app/translations/en.json Прегледај датотеку

@@ -14,6 +14,9 @@
14 14
     "menu": "Menu",
15 15
     "cancel": "Cancel",
16 16
     "ok": "OK",
17
+    "undo": "Undo",
18
+    "view": "View",
19
+    "save": "Save",
17 20
     "confirmDelete": "Confirm deletion",
18 21
     "pagination": {
19 22
       "of": "of",
@@ -50,6 +53,11 @@
50 53
     "add": {
51 54
       "defaultTitle": "New PkGuid",
52 55
       "defaultToolbarTitle": "PkGuids ~ New"
56
+    },
57
+    "notifications": {
58
+      "create": "PkGuid '{text}' was added",
59
+      "update": "PkGuid '{text}' was updated",
60
+      "delete": "PkGuid '{text}' was deleted"
53 61
     }
54 62
   }
55 63
 }

+ 5
- 2
app/views/pkguidedit.html Прегледај датотеку

@@ -15,8 +15,11 @@
15 15
             <div flex>
16 16
                 <md-progress-linear ng-disabled="!running" md-mode="indeterminate"></md-progress-linear>
17 17
             </div>
18
-            <div>
19
-                <md-button type="submit" ng-click="!editForm.$invalid && submit()">{{ 'common.submit' | translate }}</md-button>
18
+            <div layout="row" layout-align="space-between center">
19
+                <md-button class="md-raised md-primary" type="submit" ng-click="!editForm.$invalid && submit()">{{ 'common.save' | translate }}</md-button>
20
+                <md-button class="md-warn md-icon-button" ng-show="pkguid.id != null" ng-click="askRemoveOne(pkguid)" title="{{ 'common.delete' | translate }}">
21
+                    <md-icon class="material-icons">delete</md-icon>
22
+                </md-button>
20 23
             </div>
21 24
             <div ng-repeat="error in busy.errors('pkguid.edit')" class="isa_error">
22 25
                 <i class="fa fa-times-circle"></i>

+ 3
- 1
bower.json Прегледај датотеку

@@ -20,7 +20,9 @@
20 20
     "angular-translate-loader-static-files": "^2.13.1",
21 21
     "angular-translate-interpolation-messageformat": "^2.13.1",
22 22
     "angular-busy2": "^5.2.0",
23
-    "luticate2-utils": "https://git.rthoni.com/luticate2/front-utils.git#develop"
23
+    "luticate2-utils": "https://git.rthoni.com/luticate2/front-utils.git#develop",
24
+    "angular-signalr-hub": "^1.6.2",
25
+    "signalr": "^2.2.1"
24 26
   },
25 27
   "resolutions": {
26 28
     "angular": "1.6.x",

+ 28
- 1
sdk/Business/apputils.business.js Прегледај датотеку

@@ -6,7 +6,8 @@
6 6
     'use strict';
7 7
 
8 8
     angular.module('appSdk')
9
-        .factory('AppUtilsBusiness', ['$rootScope', '$translate', 'luBusyBusiness', function($rootScope, $translate, luBusyBusiness) {
9
+        .factory('AppUtilsBusiness', ['$rootScope', '$translate', 'luBusyBusiness', 'luRequest',
10
+            function($rootScope, $translate, luBusyBusiness, luRequest) {
10 11
 
11 12
             var AppUtilsBusiness = {};
12 13
 
@@ -54,6 +55,32 @@
54 55
                 return $translate.instant(id, data);
55 56
             };
56 57
 
58
+            AppUtilsBusiness.addApiVersionChangedCallback = function(callback)
59
+            {
60
+                var apiVersion = null;
61
+                luRequest.addHook('resolve', function(url, method, dataGet, dataPost, luBusyGroups, data)
62
+                {
63
+                    if (apiVersion == null) {
64
+                        apiVersion = data.version;
65
+                    }
66
+                    else if (data.version != null && data.version != apiVersion) {
67
+                        callback(apiVersion, data.version);
68
+                        apiVersion = data.version;
69
+                    }
70
+                });
71
+
72
+                luRequest.addHook('reject', function(url, method, dataGet, dataPost, luBusyGroups, error)
73
+                {
74
+                    if (apiVersion == null) {
75
+                        apiVersion = error.data.version;
76
+                    }
77
+                    else if (error.data.version != null && error.data.version != apiVersion) {
78
+                        callback(apiVersion, error.data.version);
79
+                        apiVersion = error.data.version;
80
+                    }
81
+                });
82
+            };
83
+
57 84
             return AppUtilsBusiness;
58 85
         }]);
59 86
 })();

Loading…
Откажи
Сачувај