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

Commit

Permalink
Merge pull request #777 from derrabauke/feat-reject-report
Browse files Browse the repository at this point in the history
feat: reject report
  • Loading branch information
derrabauke authored Jan 25, 2023
2 parents 89c5b29 + 7e9df37 commit a236e0d
Show file tree
Hide file tree
Showing 13 changed files with 205 additions and 56 deletions.
20 changes: 20 additions & 0 deletions app/analysis/edit/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,26 @@
</SyCheckbox>
</f.input>

<f.input @name="rejected" as |fi|>
<SyCheckbox
data-test-rejected
@checked={{fi.value}}
@onChange={{fi.update}}
@disabled={{or
(not this.canVerify)
this.hasSelectedOwnReports
}}
>
Reject report
{{#if (eq model.rejected null)}}
<NotIdenticalWarning />
{{/if}}
{{#if (not (eq f.model.rejected model.rejected))}}
<ChangedWarning />
{{/if}}
</SyCheckbox>
</f.input>

<f.input @name="billed" as |fi|>
<SyCheckbox
data-test-billed
Expand Down
5 changes: 5 additions & 0 deletions app/analysis/index/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ export const AnalysisQueryParams = new QueryParams({
replace: true,
refresh: true,
},
rejected: {
defaultValue: undefined,
replace: true,
refresh: true,
},
notBillable: {
defaultValue: undefined,
replace: true,
Expand Down
31 changes: 24 additions & 7 deletions app/analysis/index/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,23 @@
/>
</fs.group>
<fs.group @label="State">
<fs.label>
Rejected
<fs.filter
data-test-filter-rejected
@type="button"
@selected={{this.rejected}}
@valuePath="value"
@labelPath="label"
@options={{array
(hash label="All" value="")
(hash label="Rejected" value="1")
(hash label="Not rejected" value="0")
}}
@onChange={{fn (mut this.rejected)}}
/>
</fs.label>

<fs.label>
Review
<fs.filter
Expand Down Expand Up @@ -260,6 +277,9 @@
<col />
<col />
<col />
<col />
<col />
<col />
</colgroup>
<thead>
<tr>
Expand Down Expand Up @@ -303,6 +323,7 @@
@current={{this.ordering}}
@by="verified_by__username"
>Verified by</SortHeader>
<th>Rejected</th>
<th>Review</th>
<th>Not billable</th>
<th>Billed</th>
Expand All @@ -323,6 +344,8 @@
<col />
<col />
<col />
<col />
<col />
</colgroup>
<tbody>
{{#each reports as |report|}}
Expand Down Expand Up @@ -351,6 +374,7 @@
report.verifiedBy
report.verifiedBy.username
}}</td>
<td><SyCheckmark @checked={{report.rejected}} /></td>
<td><SyCheckmark @checked={{report.review}} /></td>
<td><SyCheckmark @checked={{report.notBillable}} /></td>
<td><SyCheckmark @checked={{report.billed}} /></td>
Expand Down Expand Up @@ -381,13 +405,6 @@
<col />
<col />
<col />
<col />
<col />
<col />
<col />
<col />
<col />
<col />
</colgroup>
<tfoot>
<tr>
Expand Down
7 changes: 3 additions & 4 deletions app/components/report-review-warning/component.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { tagName } from "@ember-decorators/component";
import Component from "@ember/component";
import { inject as service } from "@ember/service";
import classic from "ember-classic-decorator";

@classic
@tagName("")
export default class ReportReviewWarning extends Component {
@service
session;

@service
unverifiedReports;

@service
rejectedReports;
}
78 changes: 53 additions & 25 deletions app/components/report-review-warning/template.hbs
Original file line number Diff line number Diff line change
@@ -1,25 +1,53 @@
{{#if this.unverifiedReports.hasReports}}
<li class="nav-top-list-item" title="You have reports to verify">
<LinkTo
@route="analysis.index"
@query={{hash
fromDate=null
toDate=this.unverifiedReports.reportsToDate
reviewer=this.session.data.user.id
editable=1
verified=0
customer=null
project=null
task=null
user=null
billingType=null
costCenter=null
review=""
notBillable=""
}}
>
<FaIcon @icon="exclamation-triangle" @prefix="fas" />
{{this.unverifiedReports.amountReports}}
</LinkTo>
</li>
{{/if}}
<div class="flex">
{{#if this.unverifiedReports.hasReports}}
<li class="nav-top-list-item" title="You have reports to verify">
<LinkTo
@route="analysis.index"
@query={{hash
fromDate=null
toDate=this.unverifiedReports.reportsToDate
reviewer=this.session.data.user.id
editable=1
verified=0
customer=null
project=null
task=null
user=null
billingType=null
costCenter=null
review=""
notBillable=""
}}
>
<FaIcon @icon="exclamation-triangle" @prefix="fas" />
{{this.unverifiedReports.amountReports}}
</LinkTo>
</li>
{{/if}}
{{#if this.rejectedReports.hasReports}}
<li class="nav-top-list-item" title="You have rejected reports">
<LinkTo
@route="analysis.index"
@query={{hash
fromDate=null
toDate=this.unverifiedReports.reportsToDate
reviewer=this.session.data.user.id
editable=1
rejected=1
verified=0
customer=null
project=null
task=null
user=null
billingType=null
costCenter=null
review=""
notBillable=""
}}
>
<FaIcon @icon="times-circle" />
{{this.rejectedReports.amountReports}}
</LinkTo>
</li>
{{/if}}
</div>
13 changes: 1 addition & 12 deletions app/components/user-selection/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,7 @@ export default class UserSelection extends Component {

constructor(...args) {
super(...args);
this.fetchUsers();
}

async fetchUsers() {
try {
await this.tracking.users.perform();
} catch (e) {
if (e.taskInstance && e.taskInstance.isCanceling) {
return;
}
throw e;
}
this.tracking.users.perform();
}

@restartableTask
Expand Down
1 change: 1 addition & 0 deletions app/models/report-intersection.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Model, { attr, belongsTo } from "@ember-data/model";
export default Model.extend({
comment: attr("string"),
notBillable: attr("boolean", { allowNull: true, defaultValue: null }),
rejected: attr("boolean", { allowNull: true, defaultValue: null }),
review: attr("boolean", { allowNull: true, defaultValue: null }),
billed: attr("boolean", { allowNull: true, defaultValue: null }),
verified: attr("boolean", { allowNull: true, defaultValue: null }),
Expand Down
8 changes: 8 additions & 0 deletions app/models/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ export default class Report extends Model {
*/
@attr("boolean", { defaultValue: false }) review;

/**
* Whether the report got rejected by the reviewer
*
* @property {Boolean} reject
* @public
*/
@attr("boolean", { defaultValue: false }) rejected;

/**
* Whether the report is not billable
*
Expand Down
64 changes: 64 additions & 0 deletions app/services/rejected-reports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import Service, { inject as service } from "@ember/service";
import { macroCondition, isTesting } from "@embroider/macros";
import { tracked } from "@glimmer/tracking";
import moment from "moment";

const INTERVAL_DELAY = 10 * 60000; // 10 Minutes

export default class RejectedReportsService extends Service {
@service
store;

@service
session;

@service
notify;

@tracked amountReports = 0;
@tracked intervalId;

get hasReports() {
return this.amountReports > 0;
}

get reportsToDate() {
return moment().subtract(1, "month").endOf("month");
}

constructor(...args) {
super(...args);

this.pollReports();

/* instanbul ignore next */
if (macroCondition(isTesting())) {
this.intervalId = null;
} else {
this.intervalId = setInterval(
this.pollReports.bind(this),
INTERVAL_DELAY
);
}
}

async pollReports() {
try {
const reports = await this.store.query("report", {
to_date: this.reportsToDate.format("YYYY-MM-DD"),
reviewer: this.session.data.user.id,
editable: 1,
rejected: 1,
page: { number: 1, size: 1 },
});

this.amountReports = reports.meta.pagination.count;
} catch (e) {
this.notify.error("Error while polling reports");
}
}

willDestroy() {
clearInterval(this.intervalId);
}
}
6 changes: 3 additions & 3 deletions app/services/tracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export default class TrackingService extends Service {
* @property {EmberConcurrency.Task} users
* @public
*/
@task
@dropTask
*users() {
return yield this.store.query("user", {});
}
Expand Down Expand Up @@ -288,7 +288,7 @@ export default class TrackingService extends Service {
* @param {Number} customer The customer id to filter by
* @public
*/
@task
@dropTask
*projects(customer) {
if (!customer) {
// We can't test this because the UI prevents it
Expand All @@ -305,7 +305,7 @@ export default class TrackingService extends Service {
* @param {Number} project The project id to filter by
* @public
*/
@task
@dropTask
*tasks(project) {
if (!project) {
// We can't test this because the UI prevents it
Expand Down
11 changes: 6 additions & 5 deletions app/styles/analysis.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
&:nth-child(4),
&:nth-child(5),
&:nth-child(6) {
width: 11%;
width: 10%;
}

&:nth-child(8) {
Expand All @@ -34,12 +34,13 @@

&:nth-child(9),
&:nth-child(10),
&:nth-child(11){
width: 6%;
&:nth-child(11),
&:nth-child(12) {
width: 5%;
}

&:nth-child(7) {
width: 20%;
width: 21%;
}
}

Expand All @@ -50,7 +51,7 @@

.analysis-scrollable-container::after,
.analysis-scrollable-container::before {
content: '';
content: "";
position: absolute;
z-index: 1;
left: 0;
Expand Down
5 changes: 5 additions & 0 deletions app/styles/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ strong {
font-weight: bold;
}

.flex {
display: flex;
}

.pointer {
cursor: pointer;
}
Expand Down Expand Up @@ -322,6 +326,7 @@ strong {
color: darken($color-border, 25%);
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
Expand Down
Loading

0 comments on commit a236e0d

Please sign in to comment.