Skip to content

Commit

Permalink
Moved sorting of devices to the server side
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalidze committed May 5, 2016
1 parent d4fd997 commit 6223cb2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/main/java/org/traccar/web/client/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public Application() {
DeviceProperties deviceProperties = GWT.create(DeviceProperties.class);
final ListStore<Device> deviceStore = new ListStore<>(deviceProperties.id());
deviceStore.clearSortInfo();
deviceStore.addSortInfo(new Store.StoreSortInfo<>(deviceProperties.name(), SortDir.ASC));
final GroupStore groupStore = new GroupStore();

settingsController = new SettingsController(userSettingsHandler);
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/org/traccar/web/server/model/DataServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,17 @@ private List<Device> getDevices(boolean full) {
User user = getSessionUser();
List<Device> devices;
if (user.getAdmin()) {
devices = getSessionEntityManager().createQuery("SELECT x FROM Device x LEFT JOIN FETCH x.latestPosition", Device.class).getResultList();
devices = getSessionEntityManager().createQuery("SELECT x FROM Device x LEFT JOIN FETCH x.latestPosition ORDER BY x.name", Device.class).getResultList();
} else {
devices = new LinkedList<>(user.getAllAvailableDevices());
devices = new ArrayList<>(user.getAllAvailableDevices());
Collections.sort(devices, new Comparator<Device>() {
@Override
public int compare(Device o1, Device o2) {
String n1 = o1.getName() == null ? "" : o1.getName();
String n2 = o2.getName() == null ? "" : o2.getName();
return n1.compareTo(n2);
}
});
}
if (full && !devices.isEmpty()) {
List<Maintenance> maintenaces = getSessionEntityManager().createQuery("SELECT m FROM Maintenance m WHERE m.device IN :devices ORDER BY m.indexNo ASC", Maintenance.class)
Expand Down

0 comments on commit 6223cb2

Please sign in to comment.