Skip to content

Commit

Permalink
refactor: remove usage of useCaluma in route
Browse files Browse the repository at this point in the history
  • Loading branch information
Yelinz committed May 4, 2022
1 parent c2fa4da commit 42abd4d
Show file tree
Hide file tree
Showing 24 changed files with 202 additions and 166 deletions.
17 changes: 15 additions & 2 deletions ember/app/cases/detail/controller.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import Controller from "@ember/controller";
import getCaseQuery from "caluma-portal-demo/gql/queries/get-case";
import { queryManager } from "ember-apollo-client";
import { dropTask, lastValue } from "ember-concurrency";

export default class CasesDetailController extends Controller {
get case() {
return this.model.value[0];
@queryManager apollo;

@lastValue("getCase") case;
@dropTask
*getCase() {
return (yield this.apollo.query(
{
query: getCaseQuery,
variables: { filter: [{ id: this.model }] },
},
"allCases.edges"
)).map(({ node }) => node)[0];
}
}
6 changes: 2 additions & 4 deletions ember/app/cases/detail/edit/controller.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import Controller from "@ember/controller";
import Controller, { inject as controller } from "@ember/controller";

export default class CasesDetailEditController extends Controller {
get case() {
return this.model.value[0];
}
@controller("cases.detail") parent;
}
6 changes: 1 addition & 5 deletions ember/app/cases/detail/edit/route.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import CasesDetailRoute from "caluma-portal-demo/cases/detail/index/route";

export default class CasesDetailEditRoute extends CasesDetailRoute {
model() {
return this.modelFor("cases.detail");
}
}
export default class CasesDetailEditRoute extends CasesDetailRoute {}
4 changes: 2 additions & 2 deletions ember/app/cases/detail/edit/template.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{{#if @model}}
<CfContent @documentId={{this.case.document.id}} />
{{#if this.parent.case}}
<CfContent @documentId={{this.parent.case.document.id}} />
{{/if}}
9 changes: 3 additions & 6 deletions ember/app/cases/detail/index/controller.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Controller from "@ember/controller";
import Controller, { inject as controller } from "@ember/controller";
import { inject as service } from "@ember/service";
import cancelCaseMutation from "caluma-portal-demo/gql/mutations/cancel-case";
import { queryManager } from "ember-apollo-client";
Expand All @@ -7,16 +7,13 @@ import { dropTask } from "ember-concurrency";
export default class CasesDetailIndexController extends Controller {
@service router;
@queryManager apollo;

get case() {
return this.model.value[0];
}
@controller("cases.detail") parent;

@dropTask
*closeCase() {
yield this.apollo.mutate({
mutation: cancelCaseMutation,
variables: { case: this.case.id },
variables: { case: this.parent.case.id },
});
this.router.transitionTo("cases.index");
}
Expand Down
6 changes: 1 addition & 5 deletions ember/app/cases/detail/index/route.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import Route from "@ember/routing/route";

export default class CasesDetailRoute extends Route {
model() {
return this.modelFor("cases.detail");
}
}
export default class CasesDetailRoute extends Route {}
14 changes: 7 additions & 7 deletions ember/app/cases/detail/index/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
{{t "cases.status"}}
</th>
<td class="uk-width-1-3">
<CaseStateLabel @state={{this.case.raw.status}} @iconPosition="right" />
<CaseStateLabel @state={{this.parent.case.status}} @iconPosition="right" />
</td>
<th class="uk-text-bold uk-width-1-6">
{{t "cases.description"}}
</th>
<td class="uk-width-1-3">
{{or this.case.form.description "-"}}
{{or this.parent.case.form.description "-"}}
</td>
</tr>
<tr>
Expand All @@ -28,8 +28,8 @@
<td class="uk-width-1-3">
{{
if
this.case.createdAt
(moment-format this.case.createdAt "DD.MM.YYYY")
this.parent.case.createdAt
(moment-format this.parent.case.createdAt "DD.MM.YYYY")
"-"
}}
</td>
Expand All @@ -39,8 +39,8 @@
<td class="uk-width-1-3">
{{
if
this.case.modifiedAt
(moment-format this.case.modifiedAt "DD.MM.YYYY")
this.parent.case.modifiedAt
(moment-format this.parent.case.modifiedAt "DD.MM.YYYY")
"-"
}}
</td>
Expand Down Expand Up @@ -76,7 +76,7 @@
{{t "cases.deleteText"}}
</p>
<UkButton
@onClick={{perform this.closeCase this.case}}
@onClick={{perform this.closeCase}}
@disabled={{this.closeCase.isRunning}}
@loading={{this.closeCase.isRunning}}
>
Expand Down
13 changes: 6 additions & 7 deletions ember/app/cases/detail/route.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import Route from "@ember/routing/route";
import { useCalumaQuery } from "@projectcaluma/ember-core/caluma-query";
import { allCases } from "@projectcaluma/ember-core/caluma-query/queries";

export default class CasesDetailRoute extends Route {
model({ case_id }) {
const caseQuery = useCalumaQuery(this, allCases, () => ({
options: { pageSize: 1 },
filter: [{ id: case_id }],
}));
return case_id;
}

return caseQuery;
setupController(controller, post) {
super.setupController(controller, post);
controller.getCase.perform();
}
}
2 changes: 1 addition & 1 deletion ember/app/cases/detail/template.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{#if @model.isLoading}}
{{#if this.getCase.isRunning}}
<div class="uk-text-center uk-padding">
<UkSpinner @ratio={{2}} />
</div>
Expand Down
20 changes: 20 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,20 @@
import Controller from "@ember/controller";
import getWorkItemQuery from "caluma-portal-demo/gql/queries/get-work-item";
import { queryManager } from "ember-apollo-client";
import { dropTask, lastValue } from "ember-concurrency";

export default class CasesDetailWorkItemsEditController extends Controller {
@queryManager apollo;

@lastValue("getWorkItem") workItem;
@dropTask
*getWorkItem() {
return (yield this.apollo.query(
{
query: getWorkItemQuery,
variables: { filter: [{ id: this.model }] },
},
"allWorkItems.edges"
)).map(({ node }) => node)[0];
}
}
9 changes: 2 additions & 7 deletions ember/app/cases/detail/work-items/edit/form/controller.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import Controller from "@ember/controller";
import Controller, { inject as controller } from "@ember/controller";
import { action } from "@ember/object";
import { inject as service } from "@ember/service";
import { queryManager } from "ember-apollo-client";

export default class CasesDetailWorkItemsEditFormController extends Controller {
@queryManager apollo;

@service notification;
@service router;

get workItem() {
return this.model.value[0];
}
@controller("cases.detail.work-items.edit") parent;

@action
actionButtonOnSuccess() {
Expand Down
6 changes: 1 addition & 5 deletions ember/app/cases/detail/work-items/edit/form/route.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import Route from "@ember/routing/route";

export default class CasesDetailWorkItemsEditFormRoute extends Route {
model() {
return this.modelFor("cases.detail.work-items.edit");
}
}
export default class CasesDetailWorkItemsEditFormRoute extends Route {}
8 changes: 4 additions & 4 deletions ember/app/cases/detail/work-items/edit/form/template.hbs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<h3>{{this.workItem.name}}</h3>
<h3>{{this.parent.workItem.name}}</h3>

{{#if @model.isLoading}}
{{#if this.parent.getWorkItem.isRunning}}
<div class="uk-text-center uk-padding">
<UkSpinner @ratio={{2}} />
</div>
{{else}}
<CfContent @documentId={{this.workItem.document.id}}
<CfContent @documentId={{this.parent.workItem.document.id}}
@context={{hash
actionButtonOnSuccess=this.actionButtonOnSuccess
}}
@disabled={{not this.workItem.isReady}}
@disabled={{not (eq this.parent.workItem.status "READY")}}
/>
{{/if}}
17 changes: 8 additions & 9 deletions ember/app/cases/detail/work-items/edit/index/controller.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Controller from "@ember/controller";
import Controller, { inject as controller } from "@ember/controller";
import { action } from "@ember/object";
import { inject as service } from "@ember/service";
import { tracked } from "@glimmer/tracking";
Expand All @@ -14,12 +14,11 @@ export default class CasesDetailWorkItemsEditController extends Controller {
@service intl;
@service router;

get workItem() {
return this.model.value[0];
}
@controller("cases.detail.work-items.edit") parent;

@tracked description = this.workItem.description;
@tracked description = this.parent.workItem?.description;

@action
finishWorkItem() {
this.notification.success(this.intl.t("workItems.finishSuccess"));

Expand All @@ -34,9 +33,9 @@ export default class CasesDetailWorkItemsEditController extends Controller {
mutation: saveWorkItem,
variables: {
input: {
workItem: this.workItem.id,
description: this.workItem.description,
deadline: this.workItem.deadline,
workItem: this.parent.workItem.id,
description: this.parent.workItem.description,
deadline: this.parent.workItem.deadline,
},
},
});
Expand All @@ -50,7 +49,7 @@ export default class CasesDetailWorkItemsEditController extends Controller {

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

@action
Expand Down
6 changes: 1 addition & 5 deletions ember/app/cases/detail/work-items/edit/index/route.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import Route from "@ember/routing/route";

export default class CasesDetailWorkItemsEditRoute extends Route {
model() {
return this.modelFor("cases.detail.work-items.edit");
}
}
export default class CasesDetailWorkItemsEditRoute extends Route {}
20 changes: 7 additions & 13 deletions ember/app/cases/detail/work-items/edit/index/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,24 @@
</h1>

<hr>
{{#if @model.isLoading}}
{{#if this.parent.getWorkItem.isRunning}}
<div class="uk-text-center uk-padding">
<UkSpinner @ratio={{2}} />
</div>
{{else}}
<h2>
{{this.workItem.task.name}}
{{this.parent.workItem.task.name}}
</h2>

<div>
{{#if this.workItem.isCompleted}}
<div>
<span>
{{t "workItems.closedBy"}}
</span>
{{this.workItem.closedByUser.fullName}}
</div>
{{#if this.parent.workItem.isCompleted}}
<div>
<span>
{{t "workItems.closedAt"}}
</span>
{{
format-date
this.workItem.closedAt
this.parent.workItem.closedAt
day="2-digit"
month="2-digit"
year="numeric"
Expand All @@ -53,7 +47,7 @@
type="text"
value={{
format-date
this.workItem.raw.createdAt
this.parent.workItem.createdAt
day="2-digit"
month="2-digit"
year="numeric"
Expand Down Expand Up @@ -87,7 +81,7 @@
<PikadayInput
id="deadline"
class="uk-input"
@value={{this.workItem.raw.deadline}}
@value={{this.parent.workItem.deadline}}
@useUTC={{true}}
@onSelection={{this.setDeadline}}
/>
Expand All @@ -109,7 +103,7 @@

<WorkItemButton
@mutation="complete"
@workItemId={{this.workItem.id}}
@workItemId={{this.parent.workItem.id}}
@onSuccess={{this.finishWorkItem}}
>
{{t "workItems.actions.finish"}}
Expand Down
12 changes: 5 additions & 7 deletions ember/app/cases/detail/work-items/edit/route.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import Route from "@ember/routing/route";
import { useCalumaQuery } from "@projectcaluma/ember-core/caluma-query";
import { allWorkItems } from "@projectcaluma/ember-core/caluma-query/queries";

export default class CasesDetailWorkItemsEditRoute extends Route {
model({ work_item_id }) {
const workItemsQuery = useCalumaQuery(this, allWorkItems, () => ({
options: { pageSize: 1 },
filter: [{ id: work_item_id }],
}));
return work_item_id;
}

return workItemsQuery;
setupController(controller, post) {
super.setupController(controller, post);
controller.getWorkItem.perform();
}
}
2 changes: 1 addition & 1 deletion ember/app/cases/detail/work-items/index/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default class CasesDetailWorkItemsController extends Controller {
}

queryFilter(status) {
return [{ case: this.model.value[0].id }, { status }];
return [{ case: this.model }, { status }];
}

get readyOrder() {
Expand Down
2 changes: 1 addition & 1 deletion ember/app/components/nav-bar/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<UkTab as |tab|>
<tab.item @href="/" @linkToIndex={{true}}>{{t "nav.cases"}}</tab.item>
<tab.item @href="/work-items">{{t "nav.workItems"}}</tab.item>
<tab.item @href="/form-builder">{{t "nav.form-builder"}}</tab.item>
<tab.item @href="/form-builder">{{t "nav.formBuilder"}}</tab.item>
<tab.item @href="/alexandria">{{t "nav.alexandria"}}</tab.item>
<tab.item @href="/emeis">{{t "nav.emeis"}}</tab.item>
</UkTab>
Expand Down
19 changes: 19 additions & 0 deletions ember/app/gql/queries/get-case.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
query getCaseQuery($filter: [CaseFilterSetType]) {
allCases(filter: $filter) {
edges {
node {
id
status
createdAt
modifiedAt
document {
id
form {
name
description
}
}
}
}
}
}
Loading

0 comments on commit 42abd4d

Please sign in to comment.