diff options
author | Abyss777 <abyss@fox5.ru> | 2016-06-18 07:59:43 +0500 |
---|---|---|
committer | Abyss777 <abyss@fox5.ru> | 2016-06-18 07:59:43 +0500 |
commit | 4109447d0adc778b246543b77672c280d58da8bf (patch) | |
tree | 08ee98636cec128587bbf5f25654c5e3534dfcd9 /web/app/view | |
parent | b3b0cd9d6f2d26cef2e64ef38e23203f1f3fa51a (diff) | |
download | trackermap-server-4109447d0adc778b246543b77672c280d58da8bf.tar.gz trackermap-server-4109447d0adc778b246543b77672c280d58da8bf.tar.bz2 trackermap-server-4109447d0adc778b246543b77672c280d58da8bf.zip |
- Update Geofences API and Manager a bit
- Show geofence name in event toasts
- Link/Unlink geofences to users, devices and groups
Diffstat (limited to 'web/app/view')
-rw-r--r-- | web/app/view/DeviceGeofences.js | 43 | ||||
-rw-r--r-- | web/app/view/DeviceGeofencesController.js | 80 | ||||
-rw-r--r-- | web/app/view/Devices.js | 8 | ||||
-rw-r--r-- | web/app/view/DevicesController.js | 16 | ||||
-rw-r--r-- | web/app/view/GroupGeofences.js | 43 | ||||
-rw-r--r-- | web/app/view/GroupGeofencesController.js | 80 | ||||
-rw-r--r-- | web/app/view/Groups.js | 11 | ||||
-rw-r--r-- | web/app/view/GroupsController.js | 16 | ||||
-rw-r--r-- | web/app/view/UserGeofences.js | 44 | ||||
-rw-r--r-- | web/app/view/UserGeofencesController.js | 79 | ||||
-rw-r--r-- | web/app/view/Users.js | 5 | ||||
-rw-r--r-- | web/app/view/UsersController.js | 13 |
12 files changed, 436 insertions, 2 deletions
diff --git a/web/app/view/DeviceGeofences.js b/web/app/view/DeviceGeofences.js new file mode 100644 index 000000000..a309cc2ed --- /dev/null +++ b/web/app/view/DeviceGeofences.js @@ -0,0 +1,43 @@ +/* + * 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.DeviceGeofences', { + extend: 'Ext.grid.Panel', + xtype: 'deviceGeofencesView', + + requires: [ + 'Traccar.view.DeviceGeofencesController' + ], + + controller: 'deviceGeofences', + + selModel: { + selType: 'checkboxmodel', + checkOnly: true, + showHeaderCheckbox: false + }, + + listeners: { + beforedeselect: 'onBeforeDeselect', + beforeselect: 'onBeforeSelect' + }, + + columns: [{ + text: Strings.sharedName, + dataIndex: 'name', + flex: 1 + }] +}); diff --git a/web/app/view/DeviceGeofencesController.js b/web/app/view/DeviceGeofencesController.js new file mode 100644 index 000000000..c9d4b0aa9 --- /dev/null +++ b/web/app/view/DeviceGeofencesController.js @@ -0,0 +1,80 @@ +/* + * 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.DeviceGeofencesController', { + extend: 'Ext.app.ViewController', + alias: 'controller.deviceGeofences', + + init: function () { + var admin = Traccar.app.getUser().get('admin'); + this.deviceId = this.getView().device.getData().id; + this.getView().setStore(Ext.getStore((admin) ? 'AllGeofences' : 'Geofences')); + this.getView().getStore().load({ + scope: this, + callback: function (records, operation, success) { + var deviceStore = Ext.create((admin) ? 'Traccar.store.AllGeofences' : 'Traccar.store.Geofences'); + deviceStore.load({ + params: { + deviceId: this.deviceId + }, + scope: this, + callback: function (records, operation, success) { + var i, index; + if (success) { + for (i = 0; i < records.length; i++) { + index = this.getView().getStore().find('id', records[i].getData().id); + this.getView().getSelectionModel().select(index, true, true); + } + } + } + }); + } + }); + }, + + onBeforeSelect: function (object, record, index) { + Ext.Ajax.request({ + scope: this, + url: '/api/devices/geofences', + jsonData: { + deviceId: this.deviceId, + geofenceId: record.getData().id + }, + callback: function (options, success, response) { + if (!success) { + Traccar.app.showError(response); + } + } + }); + }, + + onBeforeDeselect: function (object, record, index) { + Ext.Ajax.request({ + scope: this, + method: 'DELETE', + url: '/api/devices/geofences', + jsonData: { + deviceId: this.deviceId, + geofenceId: record.getData().id + }, + callback: function (options, success, response) { + if (!success) { + Traccar.app.showError(response); + } + } + }); + } +}); diff --git a/web/app/view/Devices.js b/web/app/view/Devices.js index f06c2658b..1a70dfef8 100644 --- a/web/app/view/Devices.js +++ b/web/app/view/Devices.js @@ -41,6 +41,14 @@ Ext.define('Traccar.view.Devices', { tbar: { xtype: 'editToolbar', items: [{ + xtype: 'button', + disabled: true, + handler: 'onGeofencesClick', + reference: 'toolbarGeofencesButton', + glyph: 'xf21d@FontAwesome', + tooltip: Strings.sharedGeofences, + tooltipType: 'title' + }, { disabled: true, handler: 'onCommandClick', reference: 'deviceCommandButton', diff --git a/web/app/view/DevicesController.js b/web/app/view/DevicesController.js index 6b79a6804..d33368181 100644 --- a/web/app/view/DevicesController.js +++ b/web/app/view/DevicesController.js @@ -20,7 +20,8 @@ Ext.define('Traccar.view.DevicesController', { requires: [ 'Traccar.view.CommandDialog', - 'Traccar.view.DeviceDialog' + 'Traccar.view.DeviceDialog', + 'Traccar.view.DeviceGeofences' ], config: { @@ -84,6 +85,18 @@ Ext.define('Traccar.view.DevicesController', { }); }, + onGeofencesClick: function () { + device = this.getView().getSelectionModel().getSelection()[0]; + var admin = Traccar.app.getUser().get('admin'); + Ext.create('Traccar.view.BaseWindow', { + title: Strings.settingsGeofences, + items: { + xtype: 'deviceGeofencesView', + device: device + } + }).show(); + }, + onCommandClick: function () { var device, deviceId, command, dialog, comboStore; device = this.getView().getSelectionModel().getSelection()[0]; @@ -108,6 +121,7 @@ Ext.define('Traccar.view.DevicesController', { var empty = selected.getCount() === 0; this.lookupReference('toolbarEditButton').setDisabled(empty); this.lookupReference('toolbarRemoveButton').setDisabled(empty); + this.lookupReference('toolbarGeofencesButton').setDisabled(empty); this.lookupReference('deviceCommandButton').setDisabled(empty || (selected.getLastSelected().get('status') !== 'online')); if (!empty) { this.fireEvent('selectDevice', selected.getLastSelected(), true); diff --git a/web/app/view/GroupGeofences.js b/web/app/view/GroupGeofences.js new file mode 100644 index 000000000..9a46f3964 --- /dev/null +++ b/web/app/view/GroupGeofences.js @@ -0,0 +1,43 @@ +/* + * 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.GroupGeofences', { + extend: 'Ext.grid.Panel', + xtype: 'groupGeofencesView', + + requires: [ + 'Traccar.view.GroupGeofencesController' + ], + + controller: 'groupGeofences', + + selModel: { + selType: 'checkboxmodel', + checkOnly: true, + showHeaderCheckbox: false + }, + + listeners: { + beforedeselect: 'onBeforeDeselect', + beforeselect: 'onBeforeSelect' + }, + + columns: [{ + text: Strings.sharedName, + dataIndex: 'name', + flex: 1 + }] +}); diff --git a/web/app/view/GroupGeofencesController.js b/web/app/view/GroupGeofencesController.js new file mode 100644 index 000000000..e8b2a6f52 --- /dev/null +++ b/web/app/view/GroupGeofencesController.js @@ -0,0 +1,80 @@ +/* + * 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.GroupGeofencesController', { + extend: 'Ext.app.ViewController', + alias: 'controller.groupGeofences', + + init: function () { + var admin = Traccar.app.getUser().get('admin'); + this.groupId = this.getView().group.getData().id; + this.getView().setStore(Ext.getStore((admin) ? 'AllGeofences' : 'Geofences')); + this.getView().getStore().load({ + scope: this, + callback: function (records, operation, success) { + var groupStore = Ext.create((admin) ? 'Traccar.store.AllGeofences' : 'Traccar.store.Geofences'); + groupStore.load({ + params: { + groupId: this.groupId + }, + scope: this, + callback: function (records, operation, success) { + var i, index; + if (success) { + for (i = 0; i < records.length; i++) { + index = this.getView().getStore().find('id', records[i].getData().id); + this.getView().getSelectionModel().select(index, true, true); + } + } + } + }); + } + }); + }, + + onBeforeSelect: function (object, record, index) { + Ext.Ajax.request({ + scope: this, + url: '/api/groups/geofences', + jsonData: { + groupId: this.groupId, + geofenceId: record.getData().id + }, + callback: function (options, success, response) { + if (!success) { + Traccar.app.showError(response); + } + } + }); + }, + + onBeforeDeselect: function (object, record, index) { + Ext.Ajax.request({ + scope: this, + method: 'DELETE', + url: '/api/groups/geofences', + jsonData: { + groupId: this.groupId, + geofenceId: record.getData().id + }, + callback: function (options, success, response) { + if (!success) { + Traccar.app.showError(response); + } + } + }); + } +}); diff --git a/web/app/view/Groups.js b/web/app/view/Groups.js index 8404c59a9..59d20df31 100644 --- a/web/app/view/Groups.js +++ b/web/app/view/Groups.js @@ -29,7 +29,16 @@ Ext.define('Traccar.view.Groups', { selType: 'rowmodel', tbar: { - xtype: 'editToolbar' + xtype: 'editToolbar', + items: [{ + xtype: 'button', + disabled: true, + handler: 'onGeofencesClick', + reference: 'toolbarGeofencesButton', + glyph: 'xf21d@FontAwesome', + tooltip: Strings.sharedGeofences, + tooltipType: 'title' + }] }, listeners: { diff --git a/web/app/view/GroupsController.js b/web/app/view/GroupsController.js index 6cc568ea2..396a28e7e 100644 --- a/web/app/view/GroupsController.js +++ b/web/app/view/GroupsController.js @@ -18,6 +18,10 @@ Ext.define('Traccar.view.GroupsController', { extend: 'Ext.app.ViewController', alias: 'controller.groups', + requires: [ + 'Traccar.view.GroupGeofences' + ], + onAddClick: function () { var group, dialog; group = Ext.create('Traccar.model.Group'); @@ -55,9 +59,21 @@ Ext.define('Traccar.view.GroupsController', { }); }, + onGeofencesClick: function () { + group = this.getView().getSelectionModel().getSelection()[0]; + Ext.create('Traccar.view.BaseWindow', { + title: Strings.settingsGeofences, + items: { + xtype: 'groupGeofencesView', + group: group + } + }).show(); + }, + onSelectionChange: function (selected) { var disabled = selected.length > 0; this.lookupReference('toolbarEditButton').setDisabled(disabled); this.lookupReference('toolbarRemoveButton').setDisabled(disabled); + this.lookupReference('toolbarGeofencesButton').setDisabled(disabled); } }); diff --git a/web/app/view/UserGeofences.js b/web/app/view/UserGeofences.js new file mode 100644 index 000000000..83ded6665 --- /dev/null +++ b/web/app/view/UserGeofences.js @@ -0,0 +1,44 @@ +/* + * 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.UserGeofences', { + extend: 'Ext.grid.Panel', + xtype: 'userGeofencesView', + + requires: [ + 'Traccar.view.UserGeofencesController' + ], + + controller: 'userGeofences', + store: 'AllGeofences', + + selModel: { + selType: 'checkboxmodel', + checkOnly: true, + showHeaderCheckbox: false + }, + + listeners: { + beforedeselect: 'onBeforeDeselect', + beforeselect: 'onBeforeSelect' + }, + + columns: [{ + text: Strings.sharedName, + dataIndex: 'name', + flex: 1 + }] +}); diff --git a/web/app/view/UserGeofencesController.js b/web/app/view/UserGeofencesController.js new file mode 100644 index 000000000..5ce13b51e --- /dev/null +++ b/web/app/view/UserGeofencesController.js @@ -0,0 +1,79 @@ +/* + * 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.UserGeofencesController', { + extend: 'Ext.app.ViewController', + alias: 'controller.userGeofences', + + init: function () { + this.userId = this.getView().user.getData().id; + this.getView().getStore().load({ + scope: this, + callback: function (records, operation, success) { + var userStore = Ext.create('Traccar.store.Geofences'); + + userStore.load({ + params: { + userId: this.userId + }, + scope: this, + callback: function (records, operation, success) { + var i, index; + if (success) { + for (i = 0; i < records.length; i++) { + index = this.getView().getStore().find('id', records[i].getData().id); + this.getView().getSelectionModel().select(index, true, true); + } + } + } + }); + } + }); + }, + + onBeforeSelect: function (object, record, index) { + Ext.Ajax.request({ + scope: this, + url: '/api/permissions/geofences', + jsonData: { + userId: this.userId, + geofenceId: record.getData().id + }, + callback: function (options, success, response) { + if (!success) { + Traccar.app.showError(response); + } + } + }); + }, + + onBeforeDeselect: function (object, record, index) { + Ext.Ajax.request({ + scope: this, + method: 'DELETE', + url: '/api/permissions/geofences', + jsonData: { + userId: this.userId, + geofenceId: record.getData().id + }, + callback: function (options, success, response) { + if (!success) { + Traccar.app.showError(response); + } + } + }); + } +}); diff --git a/web/app/view/Users.js b/web/app/view/Users.js index 408a70885..4c5b2a05b 100644 --- a/web/app/view/Users.js +++ b/web/app/view/Users.js @@ -40,6 +40,11 @@ Ext.define('Traccar.view.Users', { disabled: true, handler: 'onGroupsClick', reference: 'userGroupsButton' + }, { + text: Strings.settingsGeofences, + disabled: true, + handler: 'onGeofencesClick', + reference: 'userGeofencesButton' }] }, diff --git a/web/app/view/UsersController.js b/web/app/view/UsersController.js index c48f57cf4..acf718c82 100644 --- a/web/app/view/UsersController.js +++ b/web/app/view/UsersController.js @@ -22,6 +22,7 @@ Ext.define('Traccar.view.UsersController', { 'Traccar.view.UserDialog', 'Traccar.view.UserDevices', 'Traccar.view.UserGroups', + 'Traccar.view.UserGeofences', 'Traccar.view.BaseWindow' ], @@ -87,11 +88,23 @@ Ext.define('Traccar.view.UsersController', { }).show(); }, + onGeofencesClick: function () { + var user = this.getView().getSelectionModel().getSelection()[0]; + Ext.create('Traccar.view.BaseWindow', { + title: Strings.settingsGeofences, + items: { + xtype: 'userGeofencesView', + user: user + } + }).show(); + }, + onSelectionChange: function (selected) { var disabled = selected.length > 0; this.lookupReference('toolbarEditButton').setDisabled(disabled); this.lookupReference('toolbarRemoveButton').setDisabled(disabled); this.lookupReference('userDevicesButton').setDisabled(disabled); this.lookupReference('userGroupsButton').setDisabled(disabled); + this.lookupReference('userGeofencesButton').setDisabled(disabled); } }); |