Skip to content

Commit

Permalink
feat(ember): add work item list
Browse files Browse the repository at this point in the history
  • Loading branch information
Yelinz committed May 27, 2021
1 parent 0a200fa commit 7696fc6
Show file tree
Hide file tree
Showing 54 changed files with 1,802 additions and 3 deletions.
162 changes: 162 additions & 0 deletions ember/app/caluma-query/models/work-item.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
import { inject as service } from "@ember/service";
import { tracked } from "@glimmer/tracking";
import saveWorkItemMutation from "caluma-portal-demo/gql/mutations/save-work-item";
import { queryManager } from "ember-apollo-client";
import WorkItemModel from "ember-caluma/caluma-query/models/work-item";

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";
}

get isCompleted() {
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
createdByGroup
closedAt
closedByUser
closedByGroup
status
meta
addressedGroups
controllingGroups
assignedUsers
name
deadline
description
document {
id
form {
slug
}
}
case {
id
meta
document {
id
form {
slug
name
}
}
}
task {
slug
name
description
meta
__typename
}
}`;
}
3 changes: 3 additions & 0 deletions ember/app/cases/detail/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
<tab.link-item @route="cases.detail.index" @model={{this.caseNode}}>
{{t "documents.subnav.overview"}}
</tab.link-item>
<tab.link-item @route="cases.detail.work-items" @model={{this.caseNode}}>
{{t "documents.subnav.workItems"}}
</tab.link-item>
<tab.link-item @route="cases.detail.edit" @model={{this.caseNode}}>
{{t "documents.subnav.document"}}
</tab.link-item>
Expand Down
3 changes: 3 additions & 0 deletions ember/app/cases/detail/work-items/edit/controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Controller from "@ember/controller";

export default class CasesDetailWorkItemsEditController extends Controller {}
49 changes: 49 additions & 0 deletions ember/app/cases/detail/work-items/edit/form/controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import Controller from "@ember/controller";
import { inject as service } from "@ember/service";
import completeWorkItem from "caluma-portal-demo/gql/mutations/complete-work-item";
import { queryManager } from "ember-apollo-client";
import calumaQuery from "ember-caluma/caluma-query";
import { allWorkItems } from "ember-caluma/caluma-query/queries";
import {
dropTask,
restartableTask,
lastValue,
} from "ember-concurrency-decorators";

export default class CasesDetailWorkItemsEditFormController extends Controller {
@queryManager apollo;

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

@lastValue("fetchWorkItems") workItem;

@calumaQuery({ query: allWorkItems })
workItemsQuery;

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

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

@dropTask()
*completeWorkItem() {
yield this.apollo.mutate({
mutation: completeWorkItem,
variables: { id: this.workItem.id },
});
this.transitionToRoute("cases.detail.work-items");
}
}
12 changes: 12 additions & 0 deletions ember/app/cases/detail/work-items/edit/form/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Route from "@ember/routing/route";

export default class CasesDetailWorkItemsEditFormRoute extends Route {
model() {
return this.modelFor("cases.detail.work-items.edit");
}

setupController(controller, model) {
super.setupController(controller, model);
controller.fetchWorkItems.perform(model);
}
}
12 changes: 12 additions & 0 deletions ember/app/cases/detail/work-items/edit/form/template.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<h3>{{this.workItem.name}}</h3>

{{#if this.fetchWorkItems.isRunning}}
<div class="uk-text-center uk-padding">
<UkSpinner @ratio={{2}} />
</div>
{{else}}
<CfContent @documentId={{this.workItem.document.id}}
@context={{hash completeCallback=(perform this.completeWorkItem)}}
@disabled={{not this.workItem.isReady}}
/>
{{/if}}
100 changes: 100 additions & 0 deletions ember/app/cases/detail/work-items/edit/index/controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import Controller from "@ember/controller";
import { action } from "@ember/object";
import { inject as service } from "@ember/service";
import { tracked } from "@glimmer/tracking";
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 calumaQuery from "ember-caluma/caluma-query";
import { allWorkItems } from "ember-caluma/caluma-query/queries";
import { dropTask } from "ember-concurrency-decorators";
import moment from "moment";

export default class CasesDetailWorkItemsEditController extends Controller {
@queryManager apollo;

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

@tracked workItem;

@calumaQuery({ query: allWorkItems, options: "options" })
workItemsQuery;

get options() {
return {
pageSize: 1,
};
}

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

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

@dropTask
*finishWorkItem(event) {
event.preventDefault();

try {
yield this.apollo.mutate({
mutation: saveWorkItem,
variables: {
input: {
workItem: this.workItem.id,
meta: JSON.stringify(this.workItem.meta),
},
},
});

yield this.apollo.mutate({
mutation: completeWorkItem,
variables: { id: this.workItem.id },
});

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

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

@dropTask
*saveManualWorkItem(event) {
event.preventDefault();

try {
yield this.apollo.mutate({
mutation: saveWorkItem,
variables: {
input: {
workItem: this.workItem.id,
description: this.workItem.description,
deadline: this.workItem.deadline,
meta: JSON.stringify(this.workItem?.meta),
},
},
});

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

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

@action
setDeadline(value) {
this.workItem.deadline = moment(value);
}
}
7 changes: 7 additions & 0 deletions ember/app/cases/detail/work-items/edit/index/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Route from "@ember/routing/route";

export default class CasesDetailWorkItemsEditRoute extends Route {
model() {
return this.modelFor("cases.detail.work-items.edit");
}
}
Loading

0 comments on commit 7696fc6

Please sign in to comment.