aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2016-06-18 07:59:43 +0500
committerAbyss777 <abyss@fox5.ru>2016-06-18 07:59:43 +0500
commit4109447d0adc778b246543b77672c280d58da8bf (patch)
tree08ee98636cec128587bbf5f25654c5e3534dfcd9
parentb3b0cd9d6f2d26cef2e64ef38e23203f1f3fa51a (diff)
downloadtrackermap-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
-rw-r--r--src/org/traccar/api/resource/GeofenceResource.java25
-rw-r--r--src/org/traccar/database/GeofenceManager.java25
-rw-r--r--web/app/Application.js7
-rw-r--r--web/app/controller/Root.js7
-rw-r--r--web/app/model/Device.js2
-rw-r--r--web/app/model/Event.js3
-rw-r--r--web/app/model/Geofence.js36
-rw-r--r--web/app/store/AllGeofences.js28
-rw-r--r--web/app/store/Geofences.js28
-rw-r--r--web/app/view/DeviceGeofences.js43
-rw-r--r--web/app/view/DeviceGeofencesController.js80
-rw-r--r--web/app/view/Devices.js8
-rw-r--r--web/app/view/DevicesController.js16
-rw-r--r--web/app/view/GroupGeofences.js43
-rw-r--r--web/app/view/GroupGeofencesController.js80
-rw-r--r--web/app/view/Groups.js11
-rw-r--r--web/app/view/GroupsController.js16
-rw-r--r--web/app/view/UserGeofences.js44
-rw-r--r--web/app/view/UserGeofencesController.js79
-rw-r--r--web/app/view/Users.js5
-rw-r--r--web/app/view/UsersController.js13
-rw-r--r--web/l10n/en.json2
22 files changed, 590 insertions, 11 deletions
diff --git a/src/org/traccar/api/resource/GeofenceResource.java b/src/org/traccar/api/resource/GeofenceResource.java
index 9c80e61a1..e94e3fedb 100644
--- a/src/org/traccar/api/resource/GeofenceResource.java
+++ b/src/org/traccar/api/resource/GeofenceResource.java
@@ -17,6 +17,7 @@ package org.traccar.api.resource;
import org.traccar.Context;
import org.traccar.api.BaseResource;
+import org.traccar.database.GeofenceManager;
import org.traccar.model.Geofence;
import javax.ws.rs.Consumes;
@@ -33,6 +34,8 @@ import javax.ws.rs.core.Response;
import java.sql.SQLException;
import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
@Path("geofences")
@Produces(MediaType.APPLICATION_JSON)
@@ -41,17 +44,33 @@ public class GeofenceResource extends BaseResource {
@GET
public Collection<Geofence> get(
- @QueryParam("all") boolean all, @QueryParam("userId") long userId) throws SQLException {
+ @QueryParam("all") boolean all, @QueryParam("userId") long userId, @QueryParam("groupId") long groupId,
+ @QueryParam("deviceId") long deviceId) throws SQLException {
+
+ GeofenceManager geofenceManager = Context.getGeofenceManager();
+ Set<Long> result;
if (all) {
Context.getPermissionsManager().checkAdmin(getUserId());
- return Context.getGeofenceManager().getAllGeofences();
+ result = new HashSet<>(geofenceManager.getAllGeofencesIds());
} else {
if (userId == 0) {
userId = getUserId();
}
Context.getPermissionsManager().checkUser(getUserId(), userId);
- return Context.getGeofenceManager().getUserGeofences(userId);
+ result = new HashSet<Long>(geofenceManager.getUserGeofencesIds(userId));
+ }
+
+ if (groupId != 0) {
+ Context.getPermissionsManager().checkGroup(getUserId(), groupId);
+ result.retainAll(geofenceManager.getGroupGeofencesIds(groupId));
}
+
+ if (deviceId != 0) {
+ Context.getPermissionsManager().checkDevice(getUserId(), deviceId);
+ result.retainAll(geofenceManager.getDeviceGeofencesIds(deviceId));
+ }
+ return Context.getGeofenceManager().getGeofences(result);
+
}
@POST
diff --git a/src/org/traccar/database/GeofenceManager.java b/src/org/traccar/database/GeofenceManager.java
index 0a07e2cf3..3f4d4c5ce 100644
--- a/src/org/traccar/database/GeofenceManager.java
+++ b/src/org/traccar/database/GeofenceManager.java
@@ -70,6 +70,15 @@ public class GeofenceManager {
return groupGeofences.get(groupId);
}
+ public Set<Long> getGroupGeofencesIds(long groupId) {
+ groupGeofencesLock.readLock().lock();
+ try {
+ return getGroupGeofences(groupId);
+ } finally {
+ groupGeofencesLock.readLock().unlock();
+ }
+ }
+
public Set<Long> getAllDeviceGeofences(long deviceId) {
deviceGeofencesLock.readLock().lock();
try {
@@ -77,10 +86,9 @@ public class GeofenceManager {
} finally {
deviceGeofencesLock.readLock().unlock();
}
-
}
- public Set<Long> getDeviceGeofences(long deviceId) {
+ public Set<Long> getDeviceGeofencesIds(long deviceId) {
deviceGeofencesLock.readLock().lock();
try {
return getDeviceGeofences(deviceGeofences, deviceId);
@@ -174,11 +182,20 @@ public class GeofenceManager {
}
}
- public final Collection<Geofence> getUserGeofences(long userId) {
+ public final Set<Long> getAllGeofencesIds() {
+ geofencesLock.readLock().lock();
+ try {
+ return geofences.keySet();
+ } finally {
+ geofencesLock.readLock().unlock();
+ }
+ }
+
+ public final Collection<Geofence> getGeofences(Set<Long> geofencesIds) {
geofencesLock.readLock().lock();
try {
Collection<Geofence> result = new LinkedList<>();
- for (Long geofenceId : getUserGeofencesIds(userId)) {
+ for (Long geofenceId : geofencesIds) {
result.add(getGeofence(geofenceId));
}
return result;
diff --git a/web/app/Application.js b/web/app/Application.js
index e798a73e2..dbbc7a594 100644
--- a/web/app/Application.js
+++ b/web/app/Application.js
@@ -31,7 +31,8 @@ Ext.define('Traccar.Application', {
'Position',
'Attribute',
'Command',
- 'Event'
+ 'Event',
+ 'Geofence'
],
stores: [
@@ -49,7 +50,9 @@ Ext.define('Traccar.Application', {
'CommandTypes',
'TimeUnits',
'Languages',
- 'Events'
+ 'Events',
+ 'Geofences',
+ 'AllGeofences'
],
controllers: [
diff --git a/web/app/controller/Root.js b/web/app/controller/Root.js
index 991a2572c..bbbe616a0 100644
--- a/web/app/controller/Root.js
+++ b/web/app/controller/Root.js
@@ -75,6 +75,7 @@ Ext.define('Traccar.controller.Root', {
loadApp: function () {
Ext.getStore('Groups').load();
Ext.getStore('Devices').load();
+ Ext.getStore('Geofences').load();
Ext.get('attribution').remove();
if (this.isPhone) {
Ext.create('widget.mainMobile');
@@ -147,6 +148,12 @@ Ext.define('Traccar.controller.Root', {
text = typeKey;
}
}
+ if (array[i].geofenceId !== 0) {
+ geofence = Ext.getStore('Geofences').getById(array[i].geofenceId);
+ if (typeof geofence != "undefined") {
+ text += ' \"' + geofence.getData().name + '"';
+ }
+ }
device = Ext.getStore('Devices').getById(array[i].deviceId);
if (typeof device != "undefined") {
Ext.toast(text, device.getData().name);
diff --git a/web/app/model/Device.js b/web/app/model/Device.js
index 588d53c1f..c0a6739f5 100644
--- a/web/app/model/Device.js
+++ b/web/app/model/Device.js
@@ -37,5 +37,7 @@ Ext.define('Traccar.model.Device', {
}, {
name: 'groupId',
type: 'int'
+ }, {
+ name: 'geofenceIds',
}]
});
diff --git a/web/app/model/Event.js b/web/app/model/Event.js
index 4dd3ea7ff..698ebb535 100644
--- a/web/app/model/Event.js
+++ b/web/app/model/Event.js
@@ -35,6 +35,9 @@ Ext.define('Traccar.model.Event', {
name: 'positionId',
type: 'int'
}, {
+ name: 'geofenceId',
+ type: 'int'
+ }, {
name: 'attributes'
}]
});
diff --git a/web/app/model/Geofence.js b/web/app/model/Geofence.js
new file mode 100644
index 000000000..a832455ac
--- /dev/null
+++ b/web/app/model/Geofence.js
@@ -0,0 +1,36 @@
+/*
+ * 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.Geofence', {
+ extend: 'Ext.data.Model',
+ identifier: 'negative',
+
+ fields: [{
+ name: 'id',
+ type: 'int'
+ }, {
+ name: 'name',
+ type: 'string'
+ }, {
+ name: 'description',
+ type: 'string'
+ }, {
+ name: 'area',
+ type: 'string'
+ }, {
+ name: 'attributes'
+ }]
+});
diff --git a/web/app/store/AllGeofences.js b/web/app/store/AllGeofences.js
new file mode 100644
index 000000000..aa6f9abfc
--- /dev/null
+++ b/web/app/store/AllGeofences.js
@@ -0,0 +1,28 @@
+/*
+ * 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.store.AllGeofences', {
+ extend: 'Ext.data.Store',
+ model: 'Traccar.model.Geofence',
+
+ proxy: {
+ type: 'rest',
+ url: '/api/geofences',
+ extraParams: {
+ all: true
+ }
+ }
+});
diff --git a/web/app/store/Geofences.js b/web/app/store/Geofences.js
new file mode 100644
index 000000000..8c5c0b3cf
--- /dev/null
+++ b/web/app/store/Geofences.js
@@ -0,0 +1,28 @@
+/*
+ * 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.store.Geofences', {
+ extend: 'Ext.data.Store',
+ model: 'Traccar.model.Geofence',
+
+ proxy: {
+ type: 'rest',
+ url: '/api/geofences',
+ writer: {
+ writeAllFields: true
+ }
+ }
+});
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);
}
});
diff --git a/web/l10n/en.json b/web/l10n/en.json
index 48dc6533c..4455071d2 100644
--- a/web/l10n/en.json
+++ b/web/l10n/en.json
@@ -16,6 +16,7 @@
"sharedSecond": "Second",
"sharedName": "Name",
"sharedSearch": "Search",
+ "sharedGeofences": "Geofences",
"errorTitle": "Error",
"errorUnknown": "Unknown error",
"errorConnection": "Connection error",
@@ -47,6 +48,7 @@
"settingsDistanceUnit": "Distance",
"settingsSpeedUnit": "Speed",
"settingsTwelveHourFormat": "12-hour Format",
+ "settingsGeofences": "Geofences",
"reportTitle": "Reports",
"reportDevice": "Device",
"reportFrom": "From",