Browse Source

added websocket notifications; added delete button on edit page

tags/v0.1.0
Robin Thoni 7 years ago
parent
commit
c04c9df8a4

+ 72
- 24
app/app.js View File

12
     'pascalprecht.translate',
12
     'pascalprecht.translate',
13
     'angular-busy',
13
     'angular-busy',
14
     'luticate2Utils',
14
     'luticate2Utils',
15
+    'SignalR',
15
     // 'luticateAuth',
16
     // 'luticateAuth',
16
     'appSdk'
17
     'appSdk'
17
 ])
18
 ])
132
                 toolbarTitle: "pkguid.add.defaultToolbarTitle",
133
                 toolbarTitle: "pkguid.add.defaultToolbarTitle",
133
                 reloadOnSearch: false,
134
                 reloadOnSearch: false,
134
                 templateUrl:'views/pkguidedit.html',
135
                 templateUrl:'views/pkguidedit.html',
135
-                controller:'PkGuidEditController'
136
+                controller:'PkGuidEditController',
137
+                params: {
138
+                    pkguid: null
139
+                }
136
             });
140
             });
137
 
141
 
138
             $stateProvider.state('pkguid_edit', {
142
             $stateProvider.state('pkguid_edit', {
150
 
154
 
151
             $urlRouterProvider.otherwise('/');
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
             $mdDialog.show(
161
             $mdDialog.show(
160
                 $mdDialog.alert()
162
                 $mdDialog.alert()
161
                     .title(AppUtilsBusiness.tr('common.updateDetected.title'))
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
                     .ok(AppUtilsBusiness.tr('common.ok')));
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
         $translate('common.appName').then(function() {
236
         $translate('common.appName').then(function() {
189
             for (var i = 0; i < ssSideNav.sections.length; ++i) {
237
             for (var i = 0; i < ssSideNav.sections.length; ++i) {
190
                 var a = ssSideNav.sections[i];
238
                 var a = ssSideNav.sections[i];

+ 3
- 3
app/controllers/pkguid.controller.js View File

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

+ 14
- 0
app/controllers/pkguidedit.controller.js View File

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
             if ($state.params != null) {
53
             if ($state.params != null) {
40
                 if ($state.params.pkguid != null) {
54
                 if ($state.params.pkguid != null) {

+ 3
- 0
app/index.html View File

46
     <script src="../bower_components/messageformat/messageformat.js"></script>
46
     <script src="../bower_components/messageformat/messageformat.js"></script>
47
     <script src="../bower_components/angular-translate-interpolation-messageformat/angular-translate-interpolation-messageformat.min.js"></script>
47
     <script src="../bower_components/angular-translate-interpolation-messageformat/angular-translate-interpolation-messageformat.min.js"></script>
48
     <script src="../bower_components/angular-busy2/dist/angular-busy.js"></script>
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
     <!--<script src="../bower_components/luticate-auth/dist/luticate-auth.min.js"></script>-->
52
     <!--<script src="../bower_components/luticate-auth/dist/luticate-auth.min.js"></script>-->
50
     <!--<script src="../bower_components/angular-dialog-service/dist/dialogs.js"></script>-->
53
     <!--<script src="../bower_components/angular-dialog-service/dist/dialogs.js"></script>-->
51
     <!--<script src="../bower_components/angular-sanitize/angular-sanitize.js"></script>-->
54
     <!--<script src="../bower_components/angular-sanitize/angular-sanitize.js"></script>-->

+ 8
- 0
app/translations/en.json View File

14
     "menu": "Menu",
14
     "menu": "Menu",
15
     "cancel": "Cancel",
15
     "cancel": "Cancel",
16
     "ok": "OK",
16
     "ok": "OK",
17
+    "undo": "Undo",
18
+    "view": "View",
19
+    "save": "Save",
17
     "confirmDelete": "Confirm deletion",
20
     "confirmDelete": "Confirm deletion",
18
     "pagination": {
21
     "pagination": {
19
       "of": "of",
22
       "of": "of",
50
     "add": {
53
     "add": {
51
       "defaultTitle": "New PkGuid",
54
       "defaultTitle": "New PkGuid",
52
       "defaultToolbarTitle": "PkGuids ~ New"
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 View File

15
             <div flex>
15
             <div flex>
16
                 <md-progress-linear ng-disabled="!running" md-mode="indeterminate"></md-progress-linear>
16
                 <md-progress-linear ng-disabled="!running" md-mode="indeterminate"></md-progress-linear>
17
             </div>
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
             </div>
23
             </div>
21
             <div ng-repeat="error in busy.errors('pkguid.edit')" class="isa_error">
24
             <div ng-repeat="error in busy.errors('pkguid.edit')" class="isa_error">
22
                 <i class="fa fa-times-circle"></i>
25
                 <i class="fa fa-times-circle"></i>

+ 3
- 1
bower.json View File

20
     "angular-translate-loader-static-files": "^2.13.1",
20
     "angular-translate-loader-static-files": "^2.13.1",
21
     "angular-translate-interpolation-messageformat": "^2.13.1",
21
     "angular-translate-interpolation-messageformat": "^2.13.1",
22
     "angular-busy2": "^5.2.0",
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
   "resolutions": {
27
   "resolutions": {
26
     "angular": "1.6.x",
28
     "angular": "1.6.x",

+ 28
- 1
sdk/Business/apputils.business.js View File

6
     'use strict';
6
     'use strict';
7
 
7
 
8
     angular.module('appSdk')
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
             var AppUtilsBusiness = {};
12
             var AppUtilsBusiness = {};
12
 
13
 
54
                 return $translate.instant(id, data);
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
             return AppUtilsBusiness;
84
             return AppUtilsBusiness;
58
         }]);
85
         }]);
59
 })();
86
 })();

Loading…
Cancel
Save