Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Commit

Permalink
fix(analysis): show sensible messages
Browse files Browse the repository at this point in the history
Distinguish between "No filters applied" and "No results found"
  • Loading branch information
Akanksh Saxena committed Oct 6, 2021
1 parent 3a153c1 commit 7a548eb
Show file tree
Hide file tree
Showing 2 changed files with 186 additions and 178 deletions.
104 changes: 51 additions & 53 deletions app/analysis/index/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,63 +278,61 @@ const AnalysisController = Controller.extend(AnalysisQueryParams.Mixin, {
}),

data: task(function*() {
if (this.appliedFilters.length) {
const params = underscoreQueryParams(
serializeParachuteQueryParams(
this.get("allQueryParams"),
AnalysisQueryParams
)
);

const data = yield this.store.query("report", {
page: {
number: this.get("_lastPage") + 1,
size: 20
},
...params,
include: "task,task.project,task.project.customer,user"
});
const params = underscoreQueryParams(
serializeParachuteQueryParams(
this.get("allQueryParams"),
AnalysisQueryParams
)
);

const data = yield this.store.query("report", {
page: {
number: this.get("_lastPage") + 1,
size: 20
},
...params,
include: "task,task.project,task.project.customer,user"
});

const assignees = yield this.fetchAssignees.perform(data);
const assignees = yield this.fetchAssignees.perform(data);

const mappedReports = data.map(report => {
report.set(
"taskAssignees",
assignees.taskAssignees.filter(
taskAssignee =>
report.get("task.id") === taskAssignee.get("task.id")
)
);
report.set(
"projectAssignees",
assignees.projectAssignees.filter(
projectAssignee =>
report.get("task.project.id") ===
projectAssignee.get("project.id")
)
);
report.set(
"customerAssignees",
assignees.customerAssignees.filter(
customerAssignee =>
report.get("task.project.customer.id") ===
customerAssignee.get("customer.id")
)
);
return report;
});
const mappedReports = data.map(report => {
report.set(
"taskAssignees",
assignees.taskAssignees.filter(
taskAssignee =>
report.get("task.id") === taskAssignee.get("task.id")
)
);
report.set(
"projectAssignees",
assignees.projectAssignees.filter(
projectAssignee =>
report.get("task.project.id") ===
projectAssignee.get("project.id")
)
);
report.set(
"customerAssignees",
assignees.customerAssignees.filter(
customerAssignee =>
report.get("task.project.customer.id") ===
customerAssignee.get("customer.id")
)
);
return report;
});

this.setProperties({
totalTime: parseDjangoDuration(data.get("meta.total-time")),
totalItems: parseInt(data.get("meta.pagination.count")),
_canLoadMore:
data.get("meta.pagination.pages") !==
data.get("meta.pagination.page"),
_lastPage: data.get("meta.pagination.page")
});
this.setProperties({
totalTime: parseDjangoDuration(data.get("meta.total-time")),
totalItems: parseInt(data.get("meta.pagination.count")),
_canLoadMore:
data.get("meta.pagination.pages") !==
data.get("meta.pagination.page"),
_lastPage: data.get("meta.pagination.page")
});

this.get("_dataCache").pushObjects(mappedReports.toArray());
}
this.get("_dataCache").pushObjects(mappedReports.toArray());

return this.get("_dataCache");
}).enqueue(),
Expand Down
260 changes: 135 additions & 125 deletions app/analysis/index/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -192,65 +192,36 @@
{{/filter-sidebar}}
{{/task-selection}}

{{#if (and (not _dataCache.length) data.isRunning)}}
<div class="empty">
{{loading-icon}}
</div>
{{else}}
{{#with data.lastSuccessful.value as |reports|}}
<div class="btn-toolbar btn-toolbar--right form-group">
{{#if selectedReportIds.length}}
{{#if appliedFilters.length}}
{{#if (and (not _dataCache.length) data.isRunning)}}
<div class="empty">
{{loading-icon}}
</div>
{{else}}
{{#with data.lastSuccessful.value as |reports|}}
<div class="btn-toolbar btn-toolbar--right form-group">
{{#if selectedReportIds.length}}
<button
data-test-edit-selected
type="button"
class="btn btn-success"
{{action 'edit' selectedReportIds}}
>
Edit {{selectedReportIds.length}} selected report{{unless (eq selectedReportIds.length 1) 's'}}
</button>
{{/if}}
<button
data-test-edit-selected
data-test-edit-all
type="button"
class="btn btn-success"
{{action 'edit' selectedReportIds}}
class="btn"
title={{unless editable 'Please enable the "editable" filter to modify all entries at once.'}}
disabled={{unless editable 'true'}}
{{action 'edit'}}
>
Edit {{selectedReportIds.length}} selected report{{unless (eq selectedReportIds.length 1) 's'}}
Edit all
</button>
{{/if}}
<button
data-test-edit-all
type="button"
class="btn"
title={{unless editable 'Please enable the "editable" filter to modify all entries at once.'}}
disabled={{unless editable 'true'}}
{{action 'edit'}}
>
Edit all
</button>
</div>
</div>

<table class="table table--striped table--analysis">
<colgroup>
<col>
<col>
<col>
<col>
<col>
<col>
<col>
<col>
<col>
<col>
</colgroup>
<thead>
<tr>
{{#sort-header update=(action (mut ordering)) current=ordering by='user__username'}}User{{/sort-header}}
{{#sort-header update=(action (mut ordering)) current=ordering by='date'}}Date{{/sort-header}}
{{#sort-header update=(action (mut ordering)) current=ordering by='duration'}}Duration{{/sort-header}}
{{#sort-header update=(action (mut ordering)) current=ordering by='task__project__customer__name'}}Customer{{/sort-header}}
{{#sort-header update=(action (mut ordering)) current=ordering by='task__project__name'}}Project{{/sort-header}}
{{#sort-header update=(action (mut ordering)) current=ordering by='task__name'}}Task{{/sort-header}}
{{#sort-header update=(action (mut ordering)) current=ordering by='comment'}}Comment{{/sort-header}}
{{#sort-header update=(action (mut ordering)) current=ordering by='verified_by__username'}}Verified by{{/sort-header}}
<th>Review</th>
<th>Not billable</th>
<th>Billed</th>
</tr>
</thead>
</table>
{{#ember-scrollable class='analysis-scrollable-container'}}
<table class="table table--striped table--analysis">
<colgroup>
<col>
Expand All @@ -263,82 +234,121 @@
<col>
<col>
<col>
</colgroup>
<thead>
<tr>
{{#sort-header update=(action (mut ordering)) current=ordering by='user__username'}}User{{/sort-header}}
{{#sort-header update=(action (mut ordering)) current=ordering by='date'}}Date{{/sort-header}}
{{#sort-header update=(action (mut ordering)) current=ordering by='duration'}}Duration{{/sort-header}}
{{#sort-header update=(action (mut ordering)) current=ordering by='task__project__customer__name'}}Customer{{/sort-header}}
{{#sort-header update=(action (mut ordering)) current=ordering by='task__project__name'}}Project{{/sort-header}}
{{#sort-header update=(action (mut ordering)) current=ordering by='task__name'}}Task{{/sort-header}}
{{#sort-header update=(action (mut ordering)) current=ordering by='comment'}}Comment{{/sort-header}}
{{#sort-header update=(action (mut ordering)) current=ordering by='verified_by__username'}}Verified by{{/sort-header}}
<th>Review</th>
<th>Not billable</th>
<th>Billed</th>
</tr>
</thead>
</table>
{{#ember-scrollable class='analysis-scrollable-container'}}
<table class="table table--striped table--analysis">
<colgroup>
<col>
<col>
<col>
<col>
<col>
<col>
<col>
<col>
<col>
<col>
<col>
</colgroup>
<tbody>
{{#each reports as |report|}}
<tr class="{{if (contains report.id selectedReportIds) 'selected'}} {{if (can 'edit report' report) 'pointer'}}" {{action 'selectRow' report}}>
<td>{{report.user.username}}</td>
<td>{{moment-format report.date 'DD.MM.YYYY'}}</td>
<td>{{format-duration report.duration false}}</td>
<td>{{report.task.project.customer.name}}</td>
<td>{{report.task.project.name}}</td>
<td>{{report.task.name}}</td>
<td><span title="{{report.comment}}">{{report.comment}}</span></td>
<td>{{if report.verifiedBy report.verifiedBy.username}}</td>
<td>{{sy-checkmark checked=report.review}}</td>
<td>{{sy-checkmark checked=report.notBillable}}</td>
<td>{{sy-checkmark checked=report.billed}}</td>
</tr>
{{/each}}
{{#if _canLoadMore}}
<tr>
<td colspan="10" class="text-center">
{{#in-viewport
rootSelector='analysis-scrollable-container'
on-enter-viewport=(perform loadNext)
on-exit-viewport=(action (mut _shouldLoadMore) false)
}}
Loading<span class="loading-dots"><i>.</i><i>.</i><i>.</i></span>
{{/in-viewport}}
</td>
</tr>
{{/if}}
</tbody>
</table>
{{/ember-scrollable}}
<table class="table table--striped table--analysis">
<colgroup>
<col>
<col>
<col>
<col>
<col>
<col>
<col>
<col>
<col>
<col>
</colgroup>
<tbody>
{{#each reports as |report|}}
<tr class="{{if (contains report.id selectedReportIds) 'selected'}} {{if (can 'edit report' report) 'pointer'}}" {{action 'selectRow' report}}>
<td>{{report.user.username}}</td>
<td>{{moment-format report.date 'DD.MM.YYYY'}}</td>
<td>{{format-duration report.duration false}}</td>
<td>{{report.task.project.customer.name}}</td>
<td>{{report.task.project.name}}</td>
<td>{{report.task.name}}</td>
<td><span title="{{report.comment}}">{{report.comment}}</span></td>
<td>{{if report.verifiedBy report.verifiedBy.username}}</td>
<td>{{sy-checkmark checked=report.review}}</td>
<td>{{sy-checkmark checked=report.notBillable}}</td>
<td>{{sy-checkmark checked=report.billed}}</td>
</tr>
{{/each}}
{{#if _canLoadMore}}
<tr>
<td colspan="10" class="text-center">
{{#in-viewport
rootSelector='analysis-scrollable-container'
on-enter-viewport=(perform loadNext)
on-exit-viewport=(action (mut _shouldLoadMore) false)
}}
Loading<span class="loading-dots"><i>.</i><i>.</i><i>.</i></span>
{{/in-viewport}}
</td>
</tr>
{{/if}}
</tbody>
<tfoot>
<tr>
<td colspan="2"><strong>Total:</strong></td>
<td colspan="2"><strong class="total">{{format-duration totalTime false}}</strong></td>
<td colspan="6" class="text-right"><em>Displaying {{reports.length}} of {{totalItems}} reports</em></td>
</tr>
</tfoot>
</table>
{{/ember-scrollable}}
<table class="table table--striped table--analysis">
<colgroup>
<col>
<col>
<col>
<col>
<col>
<col>
<col>
<col>
<col>
<col>
</colgroup>
<tfoot>
<tr>
<td colspan="2"><strong>Total:</strong></td>
<td colspan="2"><strong class="total">{{format-duration totalTime false}}</strong></td>
<td colspan="6" class="text-right"><em>Displaying {{reports.length}} of {{totalItems}} reports</em></td>
</tr>
</tfoot>
</table>
<div class="export-buttons">
{{#each exportLinks as |link|}}
<button {{action (perform download) notify allQueryParams jwt link}}
type="button"
data-download-count="{{download.performCount}}"
class="btn btn-primary {{if (and (eq download.last.url link.url) (eq download.last.params link.params) download.isRunning) 'loading'}}"
disabled={{exportLimitExceeded}}
title={{if exportLimitExceeded exportLimitMessage}}
>
{{fa-icon 'download'}}&nbsp;{{link.label}}
</button>
{{/each}}
</div>
{{^}}
<div class="empty">
<div>
{{fa-icon 'search'}}
<h3>Apply filters to display reports</h3>
<div class="export-buttons">
{{#each exportLinks as |link|}}
<button {{action (perform download) notify allQueryParams jwt link}}
type="button"
data-download-count="{{download.performCount}}"
class="btn btn-primary {{if (and (eq download.last.url link.url) (eq download.last.params link.params) download.isRunning) 'loading'}}"
disabled={{exportLimitExceeded}}
title={{if exportLimitExceeded exportLimitMessage}}
>
{{fa-icon 'download'}}&nbsp;{{link.label}}
</button>
{{/each}}
</div>
{{^}}
<div class="empty">
<div>
{{fa-icon 'search'}}
<h3>0 Results</h3>
<p>Maybe widen your filters</p>
</div>
</div>
{{/with}}
{{/if}}
{{else}}
<div class="empty">
<div>
{{fa-icon 'search'}}
<h3>Apply filters to display reports</h3>
</div>
{{/with}}
</div>
{{/if}}
</PagePermission>
{{/if}}

0 comments on commit 7a548eb

Please sign in to comment.