From a25e7bd56c128fb2a1c673abf735b3e64706f9a8 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Sun, 26 Jun 2016 00:51:33 +0500 Subject: Added notifications via email Added notifications settings --- web/app/Application.js | 7 ++- web/app/controller/Root.js | 2 +- web/app/model/Notification.js | 33 +++++++++++++ web/app/model/User.js | 2 + web/app/store/AllNotifications.js | 30 ++++++++++++ web/app/store/Notifications.js | 25 ++++++++++ web/app/view/Notifications.js | 58 +++++++++++++++++++++++ web/app/view/NotificationsController.js | 83 +++++++++++++++++++++++++++++++++ web/app/view/SettingsMenu.js | 3 ++ web/app/view/SettingsMenuController.js | 13 ++++++ web/app/view/Users.js | 5 ++ web/app/view/UsersController.js | 14 ++++++ web/l10n/en.json | 8 +++- 13 files changed, 278 insertions(+), 5 deletions(-) create mode 100644 web/app/model/Notification.js create mode 100644 web/app/store/AllNotifications.js create mode 100644 web/app/store/Notifications.js create mode 100644 web/app/view/Notifications.js create mode 100644 web/app/view/NotificationsController.js (limited to 'web') diff --git a/web/app/Application.js b/web/app/Application.js index dbbc7a594..5911579b8 100644 --- a/web/app/Application.js +++ b/web/app/Application.js @@ -32,7 +32,8 @@ Ext.define('Traccar.Application', { 'Attribute', 'Command', 'Event', - 'Geofence' + 'Geofence', + 'Notification' ], stores: [ @@ -52,7 +53,9 @@ Ext.define('Traccar.Application', { 'Languages', 'Events', 'Geofences', - 'AllGeofences' + 'AllGeofences', + 'Notifications', + 'AllNotifications' ], controllers: [ diff --git a/web/app/controller/Root.js b/web/app/controller/Root.js index da3e3a2a9..ba23b90bf 100644 --- a/web/app/controller/Root.js +++ b/web/app/controller/Root.js @@ -144,7 +144,7 @@ Ext.define('Traccar.controller.Root', { break; } } - text = Strings.eventCommandResult + text; + text = Strings.eventCommandResult + ": " + text; } else { typeKey = 'event' + array[i].type.charAt(0).toUpperCase() + array[i].type.slice(1); text = Strings[typeKey]; diff --git a/web/app/model/Notification.js b/web/app/model/Notification.js new file mode 100644 index 000000000..9b4d61eb4 --- /dev/null +++ b/web/app/model/Notification.js @@ -0,0 +1,33 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +Ext.define('Traccar.model.Notification', { + extend: 'Ext.data.Model', + identifier: 'negative', + + fields: [{ + name: 'id', + type: 'int' + }, { + name: 'type', + type: 'string' + }, { + name: 'userId', + type: 'int' + }, { + name: 'attributes' + }] +}); diff --git a/web/app/model/User.js b/web/app/model/User.js index 35b849187..352acc651 100644 --- a/web/app/model/User.js +++ b/web/app/model/User.js @@ -54,6 +54,8 @@ Ext.define('Traccar.model.User', { }, { name: 'twelveHourFormat', type: 'boolean' + }, { + name: 'attributes' }], proxy: { diff --git a/web/app/store/AllNotifications.js b/web/app/store/AllNotifications.js new file mode 100644 index 000000000..fed02b260 --- /dev/null +++ b/web/app/store/AllNotifications.js @@ -0,0 +1,30 @@ +/* + * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +Ext.define('Traccar.store.AllNotifications', { + extend: 'Ext.data.Store', + model: 'Traccar.model.Notification', + + proxy: { + type: 'rest', + url: '/api/users/notifications', + extraParams: { + all: true + } + }, + sortOnLoad: true, + sorters: { property: 'type', direction : 'ASC' } +}); diff --git a/web/app/store/Notifications.js b/web/app/store/Notifications.js new file mode 100644 index 000000000..5dc8cb614 --- /dev/null +++ b/web/app/store/Notifications.js @@ -0,0 +1,25 @@ +/* + * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +Ext.define('Traccar.store.Notifications', { + extend: 'Ext.data.Store', + model: 'Traccar.model.Notification', + + proxy: { + type: 'rest', + url: '/api/users/notifications' + } +}); diff --git a/web/app/view/Notifications.js b/web/app/view/Notifications.js new file mode 100644 index 000000000..8efebd038 --- /dev/null +++ b/web/app/view/Notifications.js @@ -0,0 +1,58 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +Ext.define('Traccar.view.Notifications', { + extend: 'Ext.grid.Panel', + xtype: 'notificationsView', + + requires: [ + 'Traccar.view.NotificationsController' + ], + + controller: 'notificationsController', + store: 'AllNotifications', + + selModel: { + selType: 'cellmodel', + }, + + columns: [{ + text: Strings.notificationType, + dataIndex: 'type', + flex: 1, + renderer: function (value) { + var typeKey = 'event' + value.charAt(0).toUpperCase() + value.slice(1); + return Strings[typeKey]; + } + }, { + text: Strings.notificationWeb, + dataIndex: 'web', + xtype: 'checkcolumn', + flex: 1, + listeners: { + checkChange: 'onCheckChange' + } + }, { + text: Strings.notificationMail, + dataIndex: 'mail', + xtype: 'checkcolumn', + flex: 1, + listeners: { + checkChange: 'onCheckChange' + } + }], + +}); diff --git a/web/app/view/NotificationsController.js b/web/app/view/NotificationsController.js new file mode 100644 index 000000000..7a609ef19 --- /dev/null +++ b/web/app/view/NotificationsController.js @@ -0,0 +1,83 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +Ext.define('Traccar.view.NotificationsController', { + extend: 'Ext.app.ViewController', + alias: 'controller.notificationsController', + + init: function () { + this.userId = this.getView().user.getData().id; + this.getView().getStore().load({ + scope: this, + callback: function (records, operation, success) { + var notificationsStore = Ext.create('Traccar.store.Notifications'); + notificationsStore.load({ + params: { + userId: this.userId + }, + scope: this, + callback: function (records, operation, success) { + var i, index, attributes, storeRecord; + if (success) { + for (i = 0; i < records.length; i++) { + index = this.getView().getStore().find('type', records[i].getData().type); + attributes = records[i].getData().attributes; + storeRecord = this.getView().getStore().getAt(index); + if (typeof attributes.web != 'undefined') { + storeRecord.set('web', attributes.web); + } + if (typeof attributes.mail != 'undefined') { + storeRecord.set('mail', attributes.mail); + } + + storeRecord.commit(); + } + } + } + }); + } + }); + }, + + onCheckChange: function (column, rowIndex, checked, eOpts) { + var record = this.getView().getStore().getAt(rowIndex); + var web, mail; + var data = { + userId: this.userId, + type: record.getData().type, + attributes: {} + }; + web = record.getData().web; + if (typeof web != 'undefined' && web) { + data.attributes.web = "true"; + } + mail = record.getData().mail; + if (typeof mail != 'undefined' && mail) { + data.attributes.mail = "true"; + } + Ext.Ajax.request({ + scope: this, + url: '/api/users/notifications', + jsonData: data, + callback: function (options, success, response) { + if (!success) { + Traccar.app.showError(response); + } + } + }); + + } +}); diff --git a/web/app/view/SettingsMenu.js b/web/app/view/SettingsMenu.js index 704884928..70041bd63 100644 --- a/web/app/view/SettingsMenu.js +++ b/web/app/view/SettingsMenu.js @@ -47,6 +47,9 @@ Ext.define('Traccar.view.SettingsMenu', { hidden: true, handler: 'onUsersClick', reference: 'settingsUsersButton' + }, { + text: Strings.sharedNotifications, + handler: 'onNotificationsClick', }, { text: Strings.loginLogout, handler: 'onLogoutClick' diff --git a/web/app/view/SettingsMenuController.js b/web/app/view/SettingsMenuController.js index 48ae60aa5..45b159ccb 100644 --- a/web/app/view/SettingsMenuController.js +++ b/web/app/view/SettingsMenuController.js @@ -25,6 +25,7 @@ Ext.define('Traccar.view.SettingsMenuController', { 'Traccar.view.Users', 'Traccar.view.Groups', 'Traccar.view.Geofences', + 'Traccar.view.Notifications', 'Traccar.view.BaseWindow' ], @@ -77,6 +78,18 @@ Ext.define('Traccar.view.SettingsMenuController', { }).show(); }, + onNotificationsClick: function () { + var user = Traccar.app.getUser(); + Ext.create('Traccar.view.BaseWindow', { + title: Strings.sharedNotifications, + modal: false, + items: { + xtype: 'notificationsView', + user: user + } + }).show(); + }, + onLogoutClick: function () { Ext.create('Traccar.view.LoginController').logout(); } diff --git a/web/app/view/Users.js b/web/app/view/Users.js index b6301b38b..4abfff1ef 100644 --- a/web/app/view/Users.js +++ b/web/app/view/Users.js @@ -45,6 +45,11 @@ Ext.define('Traccar.view.Users', { disabled: true, handler: 'onGeofencesClick', reference: 'userGeofencesButton' + }, { + text: Strings.sharedNotifications, + disabled: true, + handler: 'onNotificationsClick', + reference: 'userNotificationsButton' }] }, diff --git a/web/app/view/UsersController.js b/web/app/view/UsersController.js index acba66b4d..e745ee04c 100644 --- a/web/app/view/UsersController.js +++ b/web/app/view/UsersController.js @@ -23,6 +23,7 @@ Ext.define('Traccar.view.UsersController', { 'Traccar.view.UserDevices', 'Traccar.view.UserGroups', 'Traccar.view.UserGeofences', + 'Traccar.view.Notifications', 'Traccar.view.BaseWindow' ], @@ -114,6 +115,18 @@ Ext.define('Traccar.view.UsersController', { }).show(); }, + onNotificationsClick: function () { + var user = this.getView().getSelectionModel().getSelection()[0]; + Ext.create('Traccar.view.BaseWindow', { + title: Strings.sharedNotifications, + modal: false, + items: { + xtype: 'notificationsView', + user: user + } + }).show(); + }, + onSelectionChange: function (selected) { var disabled = selected.length > 0; this.lookupReference('toolbarEditButton').setDisabled(disabled); @@ -121,5 +134,6 @@ Ext.define('Traccar.view.UsersController', { this.lookupReference('userDevicesButton').setDisabled(disabled); this.lookupReference('userGroupsButton').setDisabled(disabled); this.lookupReference('userGeofencesButton').setDisabled(disabled); + this.lookupReference('userNotificationsButton').setDisabled(disabled); } }); diff --git a/web/l10n/en.json b/web/l10n/en.json index 8ac09caf2..351ad462d 100644 --- a/web/l10n/en.json +++ b/web/l10n/en.json @@ -19,6 +19,7 @@ "sharedSearch": "Search", "sharedGeofence": "Geofence", "sharedGeofences": "Geofences", + "sharedNotifications": "Notifications", "errorTitle": "Error", "errorUnknown": "Unknown error", "errorConnection": "Connection error", @@ -106,7 +107,10 @@ "eventDeviceMoving": "Device is moving", "eventDeviceStopped": "Device is stopped", "eventDeviceOverspeed": "Device exceeds the speed", - "eventCommandResult": "Command result: ", + "eventCommandResult": "Command result", "eventGeofenceEnter": "Device has entered geofence", - "eventGeofenceExit": "Device has exited geofence" + "eventGeofenceExit": "Device has exited geofence", + "notificationType": "Type of Notification", + "notificationWeb": "Send via Web", + "notificationMail": "Send via Mail" } \ No newline at end of file -- cgit v1.2.3 From 1972191b8802f3f9295cb151202c50d115a87f0e Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Mon, 27 Jun 2016 14:34:37 +0500 Subject: Do not use plane record fields to handle attributes nested fields --- web/app/view/Notifications.js | 8 +++++++ web/app/view/NotificationsController.js | 41 +++++++++++++++------------------ 2 files changed, 26 insertions(+), 23 deletions(-) (limited to 'web') diff --git a/web/app/view/Notifications.js b/web/app/view/Notifications.js index 8efebd038..2ae980afe 100644 --- a/web/app/view/Notifications.js +++ b/web/app/view/Notifications.js @@ -43,7 +43,11 @@ Ext.define('Traccar.view.Notifications', { xtype: 'checkcolumn', flex: 1, listeners: { + beforeCheckChange: 'onBeforeCheckChange', checkChange: 'onCheckChange' + }, + renderer: function (value, metaData, record) { + return (new Ext.ux.CheckColumn()).renderer(record.getData().attributes.web, metaData); } }, { text: Strings.notificationMail, @@ -51,7 +55,11 @@ Ext.define('Traccar.view.Notifications', { xtype: 'checkcolumn', flex: 1, listeners: { + beforeCheckChange: 'onBeforeCheckChange', checkChange: 'onCheckChange' + }, + renderer: function (value, metaData, record) { + return (new Ext.ux.CheckColumn()).renderer(record.getData().attributes.mail, metaData); } }], diff --git a/web/app/view/NotificationsController.js b/web/app/view/NotificationsController.js index 7a609ef19..1638e4520 100644 --- a/web/app/view/NotificationsController.js +++ b/web/app/view/NotificationsController.js @@ -36,13 +36,7 @@ Ext.define('Traccar.view.NotificationsController', { index = this.getView().getStore().find('type', records[i].getData().type); attributes = records[i].getData().attributes; storeRecord = this.getView().getStore().getAt(index); - if (typeof attributes.web != 'undefined') { - storeRecord.set('web', attributes.web); - } - if (typeof attributes.mail != 'undefined') { - storeRecord.set('mail', attributes.mail); - } - + storeRecord.set('attributes', attributes); storeRecord.commit(); } } @@ -52,32 +46,33 @@ Ext.define('Traccar.view.NotificationsController', { }); }, - onCheckChange: function (column, rowIndex, checked, eOpts) { + onBeforeCheckChange: function (column, rowIndex, checked, eOpts) { var record = this.getView().getStore().getAt(rowIndex); - var web, mail; - var data = { - userId: this.userId, - type: record.getData().type, - attributes: {} - }; - web = record.getData().web; - if (typeof web != 'undefined' && web) { - data.attributes.web = "true"; - } - mail = record.getData().mail; - if (typeof mail != 'undefined' && mail) { - data.attributes.mail = "true"; + var attributes = record.getData().attributes; + if (!attributes[column.dataIndex]) { + attributes[column.dataIndex] = "true"; + } else { + delete attributes[column.dataIndex]; } + record.set('attributes', attributes); + record.commit(); + }, + + onCheckChange: function (column, rowIndex, checked, eOpts) { + var record = this.getView().getStore().getAt(rowIndex); Ext.Ajax.request({ scope: this, url: '/api/users/notifications', - jsonData: data, + jsonData: { + userId: this.userId, + type: record.getData().type, + attributes: record.getData().attributes + }, callback: function (options, success, response) { if (!success) { Traccar.app.showError(response); } } }); - } }); -- cgit v1.2.3 From 2716bcccafb3ec2f19858a5e5fea262af2a8cb30 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Mon, 27 Jun 2016 17:41:39 +0500 Subject: Made code more universal --- web/app/view/Notifications.js | 10 ++++++---- web/app/view/NotificationsController.js | 13 +++++++------ 2 files changed, 13 insertions(+), 10 deletions(-) (limited to 'web') diff --git a/web/app/view/Notifications.js b/web/app/view/Notifications.js index 2ae980afe..211e5cd15 100644 --- a/web/app/view/Notifications.js +++ b/web/app/view/Notifications.js @@ -39,7 +39,7 @@ Ext.define('Traccar.view.Notifications', { } }, { text: Strings.notificationWeb, - dataIndex: 'web', + dataIndex: 'attributes.web', xtype: 'checkcolumn', flex: 1, listeners: { @@ -47,11 +47,12 @@ Ext.define('Traccar.view.Notifications', { checkChange: 'onCheckChange' }, renderer: function (value, metaData, record) { - return (new Ext.ux.CheckColumn()).renderer(record.getData().attributes.web, metaData); + var fields = this.dataIndex.split('\.',2); + return (new Ext.ux.CheckColumn()).renderer(record.get(fields[0])[fields[1]], metaData); } }, { text: Strings.notificationMail, - dataIndex: 'mail', + dataIndex: 'attributes.mail', xtype: 'checkcolumn', flex: 1, listeners: { @@ -59,7 +60,8 @@ Ext.define('Traccar.view.Notifications', { checkChange: 'onCheckChange' }, renderer: function (value, metaData, record) { - return (new Ext.ux.CheckColumn()).renderer(record.getData().attributes.mail, metaData); + var fields = this.dataIndex.split('\.',2); + return (new Ext.ux.CheckColumn()).renderer(record.get(fields[0])[fields[1]], metaData); } }], diff --git a/web/app/view/NotificationsController.js b/web/app/view/NotificationsController.js index 1638e4520..a7c4290ca 100644 --- a/web/app/view/NotificationsController.js +++ b/web/app/view/NotificationsController.js @@ -45,16 +45,17 @@ Ext.define('Traccar.view.NotificationsController', { } }); }, - + onBeforeCheckChange: function (column, rowIndex, checked, eOpts) { + var fields = column.dataIndex.split('\.',2); var record = this.getView().getStore().getAt(rowIndex); - var attributes = record.getData().attributes; - if (!attributes[column.dataIndex]) { - attributes[column.dataIndex] = "true"; + var data = record.get(fields[0]); + if (!data[fields[1]]) { + data[fields[1]] = "true"; } else { - delete attributes[column.dataIndex]; + delete data[fields[1]]; } - record.set('attributes', attributes); + record.set(fields[0], data); record.commit(); }, -- cgit v1.2.3