Skip to content

Commit

Permalink
feat: rework work item list
Browse files Browse the repository at this point in the history
  • Loading branch information
Yelinz committed Mar 25, 2022
1 parent face3a4 commit 3577e08
Show file tree
Hide file tree
Showing 42 changed files with 256 additions and 979 deletions.
106 changes: 0 additions & 106 deletions ember/app/caluma-query/models/work-item.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,6 @@
import { inject as service } from "@ember/service";
import { tracked } from "@glimmer/tracking";
import WorkItemModel from "@projectcaluma/ember-core/caluma-query/models/work-item";
import saveWorkItemMutation from "caluma-portal-demo/gql/mutations/save-work-item";
import { queryManager } from "ember-apollo-client";

export default class CustomWorkItemModel extends WorkItemModel {
@queryManager apollo;

@service store;
@service router;
@service intl;
@service notifications;

@tracked meta = this.raw.meta;
@tracked notViewed = this.raw.meta["not-viewed"];
@tracked assignedUsers = this.raw.assignedUsers;
@tracked addressedGroups = this.raw.addressedGroups;

get assignedUser() {
return this.assignedUsers;
}
set assignedUser(user) {
this.assignedUsers = [user];
}

get addressedGroup() {
return this.addressedGroups;
}

get closedByUser() {
return this.raw.closedByUser;
}

get createdByUser() {
return this.raw.createdByUser;
}

get createdByGroup() {
return this.raw.createdByGroup;
}

get isReady() {
return this.raw.status === "READY";
}
Expand All @@ -48,77 +9,10 @@ export default class CustomWorkItemModel extends WorkItemModel {
return this.raw.status === "COMPLETED";
}

get canEdit() {
return this.isReady;
}

get canEditAsCreator() {
return this.isReady;
}

get canComplete() {
return this.isReady;
}

get responsible() {
return this.assignedUser;
}

get case() {
return this.raw.case.parentWorkItem?.case || this.raw.case;
}

get calumaForm() {
return null;
}

async toggleRead() {
try {
this.notViewed = !this.notViewed;

await this.apollo.mutate({
mutation: saveWorkItemMutation,
variables: {
input: {
workItem: this.id,
meta: JSON.stringify({
...this.raw.meta,
"not-viewed": this.notViewed,
}),
},
},
});

return true;
} catch (error) {
this.notifications.error(this.intl.t("workItems.saveError"));
}
}

async assignToMe() {
return await this.assignToUser(/* TODO current user*/);
}

async assignToUser(user) {
try {
this.assignedUser = user;

await this.apollo.mutate({
mutation: saveWorkItemMutation,
variables: {
input: {
workItem: this.id,
assignedUsers: this.assignedUsers,
},
},
});

return true;
} catch (error) {
this.notifications.error(this.intl.t("workItems.saveError"));
}
}

static fragment = `{
createdAt
createdByUser
Expand Down
5 changes: 3 additions & 2 deletions ember/app/cases/detail/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ export default class CasesDetailController extends Controller.extend(
this.fetchCase.cancelAll();
}

@lastValue("fetchCase") caseNode;
@task *fetchCase() {
@lastValue("fetchCase") case;
@task
*fetchCase() {
if (typeof this.model === "object" && this.model) {
return this.model;
}
Expand Down
14 changes: 7 additions & 7 deletions ember/app/cases/detail/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
class="uk-icon-button uk-margin-right"
uk-icon="icon: arrow-left; ratio: 2"
/>
{{this.caseNode.document.form.name}}
{{this.case.document.form.name}}
</h2>

<UkTab as |tab|>
<tab.link-item @route="cases.detail.index" @model={{this.caseNode}}>
<tab.item @href="/{{this.case.id}}" @linkToIndex={{true}}>
{{t "documents.subnav.overview"}}
</tab.link-item>
<tab.link-item @route="cases.detail.work-items" @model={{this.caseNode}}>
</tab.item>
<tab.item @href="/{{this.case.id}}/work-items">
{{t "documents.subnav.workItems"}}
</tab.link-item>
<tab.link-item @route="cases.detail.edit" @model={{this.caseNode}}>
</tab.item>
<tab.item @href="/{{this.case.id}}/edit">
{{t "documents.subnav.document"}}
</tab.link-item>
</tab.item>
</UkTab>

{{outlet}}
Expand Down
3 changes: 0 additions & 3 deletions ember/app/cases/detail/work-items/edit/controller.js

This file was deleted.

19 changes: 9 additions & 10 deletions ember/app/cases/detail/work-items/edit/form/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,26 @@ export default class CasesDetailWorkItemsEditFormController extends Controller {
@queryManager apollo;

@service store;
@service notifications;
@service notification;
@service intl;
@service moment;

@lastValue("fetchWorkItems") workItem;
@service router;

@calumaQuery({ query: allWorkItems })
workItemsQuery;

@lastValue("fetchWorkItems") workItem;
@restartableTask()
*fetchWorkItems(model) {
if (typeof model === "object") {
return model;
*fetchWorkItems(id) {
if (typeof id === "object") {
return id;
}
try {
yield this.workItemsQuery.fetch({ filter: [{ id: model }] });
yield this.workItemsQuery.fetch({ filter: [{ id }] });

return this.workItemsQuery.value[0];
} catch (error) {
console.error(error);
this.notifications.error(this.intl.t("workItems.fetchError"));
this.notification.danger(this.intl.t("workItems.fetchError"));
}
}

Expand All @@ -44,6 +43,6 @@ export default class CasesDetailWorkItemsEditFormController extends Controller {
mutation: completeWorkItem,
variables: { id: this.workItem.id },
});
this.transitionToRoute("cases.detail.work-items");
this.router.transitionTo("cases.detail.work-items");
}
}
34 changes: 19 additions & 15 deletions ember/app/cases/detail/work-items/edit/index/controller.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
import Controller from "@ember/controller";
import { action } from "@ember/object";
import { inject as service } from "@ember/service";
import { tracked } from "@glimmer/tracking";
import calumaQuery from "@projectcaluma/ember-core/caluma-query";
import { allWorkItems } from "@projectcaluma/ember-core/caluma-query/queries";
import completeWorkItem from "caluma-portal-demo/gql/mutations/complete-work-item";
import saveWorkItem from "caluma-portal-demo/gql/mutations/save-work-item";
import { queryManager } from "ember-apollo-client";
import { lastValue } from "ember-concurrency";
import { dropTask } from "ember-concurrency-decorators";
import moment from "moment";

export default class CasesDetailWorkItemsEditController extends Controller {
@queryManager apollo;

@service store;
@service notifications;
@service notification;
@service intl;
@service moment;

@tracked workItem;
@service router;

@calumaQuery({ query: allWorkItems, options: "options" })
workItemsQuery;
Expand All @@ -29,14 +27,15 @@ export default class CasesDetailWorkItemsEditController extends Controller {
};
}

@lastValue("fetchWorkItem") workItem;
@dropTask()
*fetchWorkItems() {
*fetchWorkItem(id) {
try {
yield this.workItemsQuery.fetch({ filter: [{ id: this.model }] });
yield this.workItemsQuery.fetch({ filter: [{ id }] });

this.workItem = this.workItemsQuery.value[0];
return this.workItemsQuery.value[0];
} catch (error) {
this.notifications.error(this.intl.t("workItems.fetchError"));
this.notification.danger(this.intl.t("workItems.fetchError"));
}
}

Expand All @@ -60,11 +59,11 @@ export default class CasesDetailWorkItemsEditController extends Controller {
variables: { id: this.workItem.id },
});

this.notifications.success(this.intl.t("workItems.finishSuccess"));
this.notification.success(this.intl.t("workItems.finishSuccess"));

this.transitionToRoute("cases.detail.work-items.index");
this.router.transitionTo("cases.detail.work-items.index");
} catch (error) {
this.notifications.error(this.intl.t("workItems.saveError"));
this.notification.danger(this.intl.t("workItems.saveError"));
}
}

Expand All @@ -85,16 +84,21 @@ export default class CasesDetailWorkItemsEditController extends Controller {
},
});

this.notifications.success(this.intl.t("workItems.saveSuccess"));
this.notification.success(this.intl.t("workItems.saveSuccess"));

this.transitionToRoute("cases.detail.work-items.index");
this.router.transitionTo("cases.detail.work-items.index");
} catch (error) {
this.notifications.error(this.intl.t("workItems.saveError"));
this.notification.danger(this.intl.t("workItems.saveError"));
}
}

@action
setDeadline(value) {
this.workItem.deadline = moment(value);
}

@action
cancel() {
this.router.transitionTo("cases.detail.work-items.index");
}
}
5 changes: 5 additions & 0 deletions ember/app/cases/detail/work-items/edit/index/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ export default class CasesDetailWorkItemsEditRoute extends Route {
model() {
return this.modelFor("cases.detail.work-items.edit");
}

setupController(controller, model) {
super.setupController(controller, model);
controller.fetchWorkItem.perform(model);
}
}
Loading

0 comments on commit 3577e08

Please sign in to comment.