-
Notifications
You must be signed in to change notification settings - Fork 0
/
reportsFilter.patch
377 lines (370 loc) · 17.7 KB
/
reportsFilter.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
From 10c1114ed31e4c45df3547603a792e1f77ace1d7 Mon Sep 17 00:00:00 2001
From: Abhishek <[email protected]>
Date: Wed, 10 Apr 2013 23:26:22 +0530
Subject: [PATCH] Abhi #0 Refactored PatientReportsFilter and Writing
filterUpdated handler for ContainerTrackingReport.
---
.../webservice/controller/HomeController.java | 14 ++-
.../src/main/webapp/WEB-INF/views/layout/menu.ftl | 4 +-
.../WEB-INF/views/reports/patientReportsFilter.ftl | 118 +++++++++++++++++++
.../webapp/WEB-INF/views/reports/reportsFilter.ftl | 122 --------------------
.../main/webapp/js/modules/containerTracking.js | 5 +
.../webservice/controller/HomeControllerTest.java | 20 +++-
6 files changed, 150 insertions(+), 133 deletions(-)
create mode 100644 whp-reports-web/src/main/webapp/WEB-INF/views/reports/patientReportsFilter.ftl
delete mode 100644 whp-reports-web/src/main/webapp/WEB-INF/views/reports/reportsFilter.ftl
create mode 100644 whp-reports-web/src/main/webapp/js/modules/containerTracking.js
diff --git a/whp-reports-web/src/main/java/org/motechproject/whp/reports/webservice/controller/HomeController.java b/whp-reports-web/src/main/java/org/motechproject/whp/reports/webservice/controller/HomeController.java
index 14a2f28..e626254 100644
--- a/whp-reports-web/src/main/java/org/motechproject/whp/reports/webservice/controller/HomeController.java
+++ b/whp-reports-web/src/main/java/org/motechproject/whp/reports/webservice/controller/HomeController.java
@@ -6,7 +6,6 @@ import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -30,11 +29,16 @@ public class HomeController extends BaseController {
response.sendRedirect(request.getContextPath() + response.encodeURL(homePage));
}
- @RequestMapping(value="/reportsFilter", method = RequestMethod.GET)
- public String patientReportsPage(Model uiModel, @RequestParam(value = "reportType") String reportType) throws IOException {
+ @RequestMapping(value="/patientReportsFilter", method = RequestMethod.GET)
+ public String patientReportsPage(Model uiModel) throws IOException {
uiModel.addAttribute("districts", districtService.getAllDistricts());
- uiModel.addAttribute("reportType", reportType);
- return "reports/reportsFilter";
+ return "reports/patientReportsFilter";
+ }
+
+ @RequestMapping(value="/containerReports", method = RequestMethod.GET)
+ public String containerReportsPage(Model uiModel) throws IOException {
+ uiModel.addAttribute("districts", districtService.getAllDistricts());
+ return "dashboard/dashboardFilter";
}
@RequestMapping(value="/dashboard/tbRegistration", method = RequestMethod.GET)
diff --git a/whp-reports-web/src/main/webapp/WEB-INF/views/layout/menu.ftl b/whp-reports-web/src/main/webapp/WEB-INF/views/layout/menu.ftl
index a7f3529..5b8073b 100644
--- a/whp-reports-web/src/main/webapp/WEB-INF/views/layout/menu.ftl
+++ b/whp-reports-web/src/main/webapp/WEB-INF/views/layout/menu.ftl
@@ -12,7 +12,7 @@
<a href="<@spring.message 'whp.reports.adherence.audit.report'/>">All adherence audit data</a>
</li>
<li>
- <a href="/whp-reports/reportsFilter?reportType=<@spring.message 'whp.reports.type.container'/>">Container tracking data</a>
+ <a href="/whp-reports/containerReports">Container tracking data</a>
</li>
<li>
<a href="<@spring.message 'whp.reports.provider.reminder.call.report'/>">Provider reminder call logs</a>
@@ -21,7 +21,7 @@
<a href="<@spring.message 'whp.reports.patient.alert.call.log.report'/>">Patient alert call logs</a>
</li>
<li>
- <a href="/whp-reports/reportsFilter?reportType=<@spring.message 'whp.reports.type.patient'/>">Patient Reports</a>
+ <a href="/whp-reports/patientReportsFilter">Patient Reports</a>
</li>
</ul>
</li>
diff --git a/whp-reports-web/src/main/webapp/WEB-INF/views/reports/patientReportsFilter.ftl b/whp-reports-web/src/main/webapp/WEB-INF/views/reports/patientReportsFilter.ftl
new file mode 100644
index 0000000..83ff895
--- /dev/null
+++ b/whp-reports-web/src/main/webapp/WEB-INF/views/reports/patientReportsFilter.ftl
@@ -0,0 +1,118 @@
+<#import "/spring.ftl" as spring />
+<#import "../layout/default-with-menu.ftl" as layout>
+<@layout.defaultLayout title="Reports Filter">
+
+<h1>Patient Reports</h1>
+<form name="patientReportsFilter">
+
+ <div class="row-fluid">
+ <div class="well">
+ <fieldset class="filters">
+ <div class="control-group span2">
+ <label class="control-label">Select Report</label>
+
+ <div class="controls">
+ <select id="report" name="report">
+ <option value="patientreports/patientSummary.xls">Patient Summary Report</option>
+ <option value="patientreports/patientRegistrations.xls">Patient Registrations Report</option>
+ <option value="patientreports/patientClosedTreatments.xls">Patient Closed Treatments Report</option>
+ </select>
+ </div>
+
+ <label class="control-label">District</label>
+
+ <div class="controls">
+ <select id="district" name="district">
+ <option value="">All</option>
+ <#list districts as district>
+ <option value="${district.name}">${district.name}</option>
+ </#list>
+ </select>
+ </div>
+
+ <div class="controls">
+ <label class="control-label date-field">Date From</label>
+
+ <div class="input-append input-prepend">
+ <span class="add-on show-date-button"><i class="icon-calendar"></i></span>
+ <input class="dates" type="text" placeholder="From: dd/mm/yyyy"
+ data-date-format="dd/mm/yyyy" id="from" name="from" data-date-range="to">
+ <span class="add-on clear-date-button"><i class="icon-remove-sign"></i></span>
+ </div>
+ </div>
+ <label class="control-label date-field">Date To</label>
+
+ <div class="controls">
+ <div class="input-append input-prepend">
+ <span class="add-on show-date-button"><i class="icon-calendar"></i></span>
+ <input class="dates" type="text" placeholder="To: dd/mm/yyyy" data-date-format="dd/mm/yyyy"
+ id="to" name="to" data-date-range="from">
+ <span class="add-on clear-date-button"><i class="icon-remove-sign"></i></span>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ <div class="control-group buttons-group row-fluid">
+ <div class="controls pull-left">
+ <button id="clearFilter" type="reset" class="btn">Clear All</button>
+ <button type="button" id="download" class="btn btn-primary">Download <i
+ class="icon-download icon-white"></i></button>
+ </div>
+ </div>
+</form>
+
+
+<script type="text/javascript">
+ $(function () {
+
+ $("#from").datepicker({
+ dateFormat:'dd/mm/yy',
+ onClose:function (selectedDate) {
+ $("#to").datepicker("option", "minDate", selectedDate);
+ $("#to").datepicker("option", "maxDate", getDate(selectedDate, 180));
+ }
+ });
+ $("#to").datepicker({
+ dateFormat:'dd/mm/yy',
+ onClose:function (selectedDate) {
+ $("#from").datepicker("option", "minDate", getDate(selectedDate, -180));
+ $("#from").datepicker("option", "maxDate", selectedDate);
+ }
+ });
+
+ getDate = function(dtString, deltaDays){
+ var dateParts = dtString.split("/");
+ var newDate = new Date(dateParts[2], dateParts[1] - 1, dateParts[0]);
+ newDate.setDate(parseInt(dateParts[0]) + deltaDays)
+
+ return newDate;
+ }
+
+ // $("#district").combobox();
+
+ $("#district").bind("autocomplete-selected", function (event, ui) {
+ $("#district").val($(this).val());
+ });
+
+ $(".show-date-button").click(function () {
+ $(this).parent().find(".dates").focus();
+ });
+
+ $(".clear-date-button").click(function () {
+ var dateElement = $(this).parent().find(".dates");
+ dateElement.val("");
+
+ var relatedDateField = $("#" + dateElement.data("date-range"));
+ relatedDateField.datepicker("option", "minDate", "");
+ relatedDateField.datepicker("option", "maxDate", "");
+ });
+
+ $('#download').bind('click', function (event) {
+ $("#district").val($("#district-autocomplete").val());
+ window.open($("#report").val() + "?" + $("#district, #from, #to").serialize());
+ return false;
+ });
+ });
+</script>
+</@layout.defaultLayout>
\ No newline at end of file
diff --git a/whp-reports-web/src/main/webapp/WEB-INF/views/reports/reportsFilter.ftl b/whp-reports-web/src/main/webapp/WEB-INF/views/reports/reportsFilter.ftl
deleted file mode 100644
index 5cd373d..0000000
--- a/whp-reports-web/src/main/webapp/WEB-INF/views/reports/reportsFilter.ftl
+++ /dev/null
@@ -1,122 +0,0 @@
-<#import "/spring.ftl" as spring />
-<#import "../layout/default-with-menu.ftl" as layout>
-<@layout.defaultLayout title="Reports Filter">
-
-<h1>Reports Filter</h1>
-<form name="reportsFilter">
-
- <div class="row-fluid">
- <div class="well">
- <fieldset class="filters">
- <div class="control-group span2">
- <label class="control-label">Select Report</label>
-
- <div class="controls">
- <select id="report" name="report">
- <#if reportType == "patientReports">
- <option value="patientreports/patientSummary.xls">Patient Summary Report</option>
- <option value="patientreports/patientRegistrations.xls">Patient Registrations Report</option>
- <option value="patientreports/patientClosedTreatments.xls">Patient Closed Treatments Report</option>
- <#elseif reportType == "containerReport">
- <option value="<@spring.message 'whp.reports.container.tracking.report'/>">Container Tracking Report</option>
- </#if>
- </select>
- </div>
-
- <label class="control-label">District</label>
-
- <div class="controls">
- <select id="district" name="district">
- <option value="">All</option>
- <#list districts as district>
- <option value="${district.name}">${district.name}</option>
- </#list>
- </select>
- </div>
-
- <div class="controls">
- <label class="control-label date-field">Date From</label>
-
- <div class="input-append input-prepend">
- <span class="add-on show-date-button"><i class="icon-calendar"></i></span>
- <input class="dates" type="text" placeholder="From: dd/mm/yyyy"
- data-date-format="dd/mm/yyyy" id="from" name="from" data-date-range="to">
- <span class="add-on clear-date-button"><i class="icon-remove-sign"></i></span>
- </div>
- </div>
- <label class="control-label date-field">Date To</label>
-
- <div class="controls">
- <div class="input-append input-prepend">
- <span class="add-on show-date-button"><i class="icon-calendar"></i></span>
- <input class="dates" type="text" placeholder="To: dd/mm/yyyy" data-date-format="dd/mm/yyyy"
- id="to" name="to" data-date-range="from">
- <span class="add-on clear-date-button"><i class="icon-remove-sign"></i></span>
- </div>
- </div>
- </div>
- </div>
- </div>
- <div class="control-group buttons-group row-fluid">
- <div class="controls pull-left">
- <button id="clearFilter" type="reset" class="btn">Clear All</button>
- <button type="button" id="download" class="btn btn-primary">Download <i
- class="icon-download icon-white"></i></button>
- </div>
- </div>
-</form>
-
-
-<script type="text/javascript">
- $(function () {
-
- $("#from").datepicker({
- dateFormat:'dd/mm/yy',
- onClose:function (selectedDate) {
- $("#to").datepicker("option", "minDate", selectedDate);
- $("#to").datepicker("option", "maxDate", getDate(selectedDate, 180));
- }
- });
- $("#to").datepicker({
- dateFormat:'dd/mm/yy',
- onClose:function (selectedDate) {
- $("#from").datepicker("option", "minDate", getDate(selectedDate, -180));
- $("#from").datepicker("option", "maxDate", selectedDate);
- }
- });
-
- getDate = function(dtString, deltaDays){
- var dateParts = dtString.split("/");
- var newDate = new Date(dateParts[2], dateParts[1] - 1, dateParts[0]);
- newDate.setDate(parseInt(dateParts[0]) + deltaDays)
-
- return newDate;
- }
-
- // $("#district").combobox();
-
- $("#district").bind("autocomplete-selected", function (event, ui) {
- $("#district").val($(this).val());
- });
-
- $(".show-date-button").click(function () {
- $(this).parent().find(".dates").focus();
- });
-
- $(".clear-date-button").click(function () {
- var dateElement = $(this).parent().find(".dates");
- dateElement.val("");
-
- var relatedDateField = $("#" + dateElement.data("date-range"));
- relatedDateField.datepicker("option", "minDate", "");
- relatedDateField.datepicker("option", "maxDate", "");
- });
-
- $('#download').bind('click', function (event) {
- $("#district").val($("#district-autocomplete").val());
- window.open($("#report").val() + "?" + $("#district, #from, #to").serialize());
- return false;
- });
- });
-</script>
-</@layout.defaultLayout>
\ No newline at end of file
diff --git a/whp-reports-web/src/main/webapp/js/modules/containerTracking.js b/whp-reports-web/src/main/webapp/js/modules/containerTracking.js
new file mode 100644
index 0000000..697041c
--- /dev/null
+++ b/whp-reports-web/src/main/webapp/js/modules/containerTracking.js
@@ -0,0 +1,5 @@
+$(function () {
+ $(document).on("filterUpdated", function(event){
+ window.open($('#filter').data('url') + "&filterParams=" + event.message).serialize();
+ });
+})
diff --git a/whp-reports-web/src/test/java/org/motechproject/whp/reports/webservice/controller/HomeControllerTest.java b/whp-reports-web/src/test/java/org/motechproject/whp/reports/webservice/controller/HomeControllerTest.java
index 88947a4..adfe846 100644
--- a/whp-reports-web/src/test/java/org/motechproject/whp/reports/webservice/controller/HomeControllerTest.java
+++ b/whp-reports-web/src/test/java/org/motechproject/whp/reports/webservice/controller/HomeControllerTest.java
@@ -29,15 +29,27 @@ public class HomeControllerTest {
@Test
public void shouldReturnAllDistrictsOnReportsPageLoad() throws Exception {
List districts = mock(List.class);
- String reportType = "patientReports";
when(districtService.getAllDistricts()).thenReturn(districts);
standaloneSetup(homeController)
.build()
- .perform(get("/reportsFilter").param("reportType", reportType))
+ .perform(get("/patientReportsFilter"))
.andExpect(status().isOk())
.andExpect(model().attribute("districts", districts))
- .andExpect(model().attribute("reportType", reportType))
- .andExpect(forwardedUrl("reports/reportsFilter"));
+ .andExpect(forwardedUrl("reports/patientReportsFilter"));
+
+ verify(districtService).getAllDistricts();
+ }
+
+ @Test
+ public void shouldProvideDistrictsToContainerReportsPageLoad() throws Exception {
+ List districts = mock(List.class);
+ when(districtService.getAllDistricts()).thenReturn(districts);
+ standaloneSetup(homeController)
+ .build()
+ .perform(get("/containerReports"))
+ .andExpect(status().isOk())
+ .andExpect(model().attribute("districts", districts))
+ .andExpect(forwardedUrl("dashboard/dashboardFilter"));
verify(districtService).getAllDistricts();
}
--
1.7.7.5 (Apple Git-26)