-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
54 changed files
with
1,802 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
100
ember/app/cases/detail/work-items/edit/index/controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
Oops, something went wrong.