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

Commit

Permalink
fix(activities): small improvements
Browse files Browse the repository at this point in the history
* Break activitySum loop when in testing, otherwise it never settles
* Use 'transition.send' for save event triggering in protected route
* Assume 'this.user' is resolved later and could possibly be null
  • Loading branch information
derrabauke committed Dec 16, 2022
1 parent d77f2c2 commit a888a95
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
28 changes: 14 additions & 14 deletions app/index/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,25 @@ export default class IndexController extends Controller {
AbsenceValidations = AbsenceValidations;
MultipleAbsenceValidations = MultipleAbsenceValidations;

constructor(...args) {
super(...args);
// this kicks off the activity sum loop
scheduleOnce("afterRender", this, this._activitySumTask.perform);
}

get _allActivities() {
return this.store.peekAll("activity");
}

get _activities() {
const activitiesThen = this._allActivities.filter((a) => {
return this._allActivities.filter((a) => {
return (
a.get("date") &&
a.get("date").isSame(this.date, "day") &&
a.get("user.id") === this.user.id &&
a.get("user.id") === this.user?.id &&
!a.get("isDeleted")
);
});

if (activitiesThen.get("length")) {
scheduleOnce("afterRender", this, this._activitySumTask.perform);
}

return activitiesThen;
}

get activitySum() {
Expand Down Expand Up @@ -100,7 +100,7 @@ export default class IndexController extends Controller {
* @private
*/
_activitySum() {
// Do not trigger updates whne there is no active activity, but let it run once to
// Do not trigger updates when there is no active activity, but let it run once to
// null the duration.
if (
!this.tracking.hasActiveActivity &&
Expand Down Expand Up @@ -139,7 +139,7 @@ export default class IndexController extends Controller {
this._activitySum();

if (macroCondition(isTesting())) {
return;
break;
}

yield timeout(1000);
Expand Down Expand Up @@ -167,7 +167,7 @@ export default class IndexController extends Controller {
return (
attendance.get("date") &&
attendance.get("date").isSame(this.date, "day") &&
attendance.get("user.id") === this.user.id &&
attendance.get("user.id") === this.user?.id &&
!attendance.get("isDeleted")
);
});
Expand Down Expand Up @@ -215,7 +215,7 @@ export default class IndexController extends Controller {
return this._allReports.filter((report) => {
return (
report.date.isSame(this.date, "day") &&
report.get("user.id") === this.user.id &&
report.get("user.id") === this.user?.id &&
!report.isNew &&
!report.isDeleted
);
Expand All @@ -232,7 +232,7 @@ export default class IndexController extends Controller {
return this._allAbsences.filter((absence) => {
return (
absence.date.isSame(this.date, "day") &&
absence.get("user.id") === this.user.id &&
absence.get("user.id") === this.user?.id &&
!absence.isNew &&
!absence.isDeleted
);
Expand Down Expand Up @@ -438,7 +438,7 @@ export default class IndexController extends Controller {
const params = {
from_date: from.format("YYYY-MM-DD"),
to_date: to.format("YYYY-MM-DD"),
user: this.user.id,
user: this.user?.id,
};

const absences = yield this.store.query("absence", params);
Expand Down
2 changes: 1 addition & 1 deletion app/index/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default class IndexRoute extends Route.extend(RouteAutostartTourMixin) {
* @public
*/
model({ day }) {
return moment(day, DATE_FORMAT);
return day ? moment(day, DATE_FORMAT) : moment(DATE_FORMAT);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/protected/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export default class ProtectedRoute extends Route {

if (transition) {
transition.promise.finally(function () {
controller.send("finished");
transition.send("finished");
});
}
}
Expand Down

0 comments on commit a888a95

Please sign in to comment.