Skip to content

Commit

Permalink
For #327 - added possibility to preview reports without saving, added…
Browse files Browse the repository at this point in the history
… possibility to disable filtering of data on reports (probably helps for #329)
  • Loading branch information
vitalidze committed Nov 19, 2015
1 parent b6f70e2 commit 1af617d
Show file tree
Hide file tree
Showing 16 changed files with 74 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void onGenerate(Report report) {
private void generate(Report report) {
FormPanel form = new FormPanel("_blank");
form.setVisible(false);
form.setAction("traccar/report");
form.setAction("traccar/report" + (report.isPreview() ? "/" + report.getName() + ".html" : ""));
form.setMethod(FormPanel.METHOD_POST);
form.setEncoding(FormPanel.ENCODING_URLENCODED);
HorizontalPanel container = new HorizontalPanel();
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/traccar/web/client/i18n/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -482,4 +482,6 @@ String defaultNotificationTemplate(@Select DeviceEventType type,
String minIdleTime();

String wrapperLog();

String preview();
}
7 changes: 7 additions & 0 deletions src/main/java/org/traccar/web/client/view/ReportsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ public interface ReportHandler {
@UiField
CheckBox includeMap;

@UiField
CheckBox disableFilter;

@UiField
CheckBox preview;

@UiField(provided = true)
final ListStore<Device> deviceStore;

Expand Down Expand Up @@ -256,6 +262,7 @@ public void onGenerateClicked(SelectEvent event) {
private void reportTypeChanged(ReportType type) {
geoFencesList.setEnabled(type != null && type.supportsGeoFences());
includeMap.setEnabled(type != null && type.supportsMapDisplay());
disableFilter.setEnabled(type != null && type.supportsFiltering());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@
<container:child layoutData="{verticalLayoutData}">
<form:CheckBox ui:field="includeMap" boxLabel="{i18n.includeMap}" enabled="false" />
</container:child>
<container:child layoutData="{verticalLayoutData}">
<form:CheckBox ui:field="disableFilter" boxLabel="{i18n.disableFilter}" enabled="false" />
</container:child>
<container:child layoutData="{verticalLayoutData}">
<form:CheckBox ui:field="preview" boxLabel="{i18n.preview}" />
</container:child>
</container:VerticalLayoutContainer>
</gxt:ContentPanel>
</container:child>
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/org/traccar/web/server/model/DBMigrations.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public void migrate(EntityManager em) throws Exception {
new SetGlobalHashSalt(),
new SetDefaultUserSettings(),
new SetArchiveDefaultColumns(),
new SetGeoFenceAllDevicesFlag()
new SetGeoFenceAllDevicesFlag(),
new SetReportsFilterAndPreview()
}) {
em.getTransaction().begin();
try {
Expand Down Expand Up @@ -346,4 +347,16 @@ public void migrate(EntityManager em) throws Exception {
.executeUpdate();
}
}

static class SetReportsFilterAndPreview implements Migration {
@Override
public void migrate(EntityManager em) throws Exception {
em.createQuery("UPDATE " + Report.class.getSimpleName() + " R SET R.preview = :f WHERE R.preview IS NULL")
.setParameter("f", false)
.executeUpdate();
em.createQuery("UPDATE " + Report.class.getSimpleName() + " R SET R.disableFilter = :f WHERE R.disableFilter IS NULL")
.setParameter("f", false)
.executeUpdate();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected void configureServlets() {
serve("/traccar/rest/*").with(RESTApiServlet.class);
serve("/traccar/export/*").with(ExportServlet.class);
serve("/traccar/import/*").with(ImportServlet.class);
serve("/traccar/report").with(ReportServlet.class);
serve("/traccar/report*").with(ReportServlet.class);
serve("/traccar/s/login").with(LoginServlet.class);
serve("/" + Picture.URL_PREFIX + "*").with(PicturesServlet.class);

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/traccar/web/server/reports/ReportDS.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void generateImpl(Report report) throws IOException {
for (Device device : getDevices(report)) {
List<Position> positions;
try {
positions = dataService.getPositions(device, report.getFromDate(), report.getToDate(), true);
positions = dataService.getPositions(device, report.getFromDate(), report.getToDate(), !report.isDisableFilter());
} catch (AccessDeniedException ade) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void generateImpl(Report report) throws IOException {
List<GeoFence> geoFences = getGeoFences(report, device);
List<Position> positions;
try {
positions = dataService.getPositions(device, report.getFromDate(), report.getToDate(), true);
positions = dataService.getPositions(device, report.getFromDate(), report.getToDate(), !report.isDisableFilter());
} catch (AccessDeniedException ade) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/traccar/web/server/reports/ReportGI.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void generateImpl(Report report) throws IOException {
for (Device device : getDevices(report)) {
List<Position> positions;
try {
positions = dataService.getPositions(device, report.getFromDate(), report.getToDate(), true);
positions = dataService.getPositions(device, report.getFromDate(), report.getToDate(), !report.isDisableFilter());
} catch (AccessDeniedException ade) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/traccar/web/server/reports/ReportMD.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void generateImpl(Report report) throws IOException {
positions = Collections.emptyList();
} else {
try {
positions = dataService.getPositions(device, report.getFromDate(), report.getToDate(), true);
positions = dataService.getPositions(device, report.getFromDate(), report.getToDate(), !report.isDisableFilter());
} catch (AccessDeniedException ade) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/traccar/web/server/reports/ReportOS.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void generateImpl(Report report) throws IOException {
positions = Collections.emptyList();
} else {
try {
positions = dataService.getPositions(device, report.getFromDate(), report.getToDate(), true);
positions = dataService.getPositions(device, report.getFromDate(), report.getToDate(), !report.isDisableFilter());
} catch (AccessDeniedException ade) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public String getFilename(Report report) {

public void start(Report report) throws IOException {
response.setContentType("text/html;charset=UTF-8");
response.setHeader("Content-Disposition", "attachment; filename=" + getFilename(report));
if (!report.isPreview()) {
response.setHeader("Content-Disposition", "attachment; filename=" + getFilename(report));
}

line("<!DOCTYPE html>");
line("<html>");
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/org/traccar/web/shared/model/Report.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,28 @@ public void setIncludeMap(boolean displayMap) {
this.includeMap = displayMap;
}

@Column(nullable = true)
private boolean disableFilter;

public boolean isDisableFilter() {
return disableFilter;
}

public void setDisableFilter(boolean disableFilter) {
this.disableFilter = disableFilter;
}

@Column(nullable = true)
private boolean preview = true;

public boolean isPreview() {
return preview;
}

public void setPreview(boolean preview) {
this.preview = preview;
}

public Report copyFrom(Report report) {
this.id = report.id;
this.name = report.name;
Expand All @@ -159,6 +181,8 @@ public Report copyFrom(Report report) {
this.fromDate = report.fromDate;
this.toDate = report.toDate;
this.includeMap = report.includeMap;
this.disableFilter = report.disableFilter;
this.preview = report.preview;
return this;
}
}
9 changes: 9 additions & 0 deletions src/main/java/org/traccar/web/shared/model/ReportType.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public boolean supportsGeoFences() {
public boolean supportsGeoFences() {
return true;
}

@Override
public boolean supportsFiltering() {
return false;
}
};

public boolean supportsGeoFences() {
Expand All @@ -47,4 +52,8 @@ public boolean supportsGeoFences() {
public boolean supportsMapDisplay() {
return false;
}

public boolean supportsFiltering() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ reportType[GEO_FENCE_IN_OUT] = Geo-fence In/Out
reportType[EVENTS] = Events
reportType[MILEAGE_DETAIL] = Mileage detail
includeMap = Include map
preview = Preview
confirmReportRemoval = Are you sure you want remove report?
# Report 'General information'
routeStart = Route start
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ reportType[GEO_FENCE_IN_OUT] = Вход/выход в геозону
reportType[EVENTS] = События
reportType[MILEAGE_DETAIL] = Детализация пробега
includeMap = Включить карту
preview = Предварительный просмотр
confirmReportRemoval = Вы действительно хотите удалить отчет?
# Report 'General information'
routeStart = Начало пути
Expand Down

0 comments on commit 1af617d

Please sign in to comment.