Skip to content

Commit

Permalink
fix(ember): improve code, apply review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Yelinz committed May 4, 2022
1 parent 49172be commit c2fa4da
Show file tree
Hide file tree
Showing 16 changed files with 38 additions and 110 deletions.
2 changes: 1 addition & 1 deletion ember/app/caluma-query/models/work-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class CustomWorkItemModel extends WorkItemModel {
}

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

static fragment = `{
Expand Down
12 changes: 0 additions & 12 deletions ember/app/cases/detail/work-items/edit/form/controller.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import Controller from "@ember/controller";
import { action } from "@ember/object";
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 { dropTask } from "ember-concurrency-decorators";

export default class CasesDetailWorkItemsEditFormController extends Controller {
@queryManager apollo;
Expand All @@ -15,16 +13,6 @@ export default class CasesDetailWorkItemsEditFormController extends Controller {
return this.model.value[0];
}

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

this.actionButtonOnSuccess();
}

@action
actionButtonOnSuccess() {
this.notification.success("workItem.finishSuccess");
Expand Down
1 change: 0 additions & 1 deletion ember/app/cases/detail/work-items/edit/form/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
{{else}}
<CfContent @documentId={{this.workItem.document.id}}
@context={{hash
completeCallback=(perform this.completeWorkItem)
actionButtonOnSuccess=this.actionButtonOnSuccess
}}
@disabled={{not this.workItem.isReady}}
Expand Down
29 changes: 3 additions & 26 deletions ember/app/cases/detail/work-items/edit/index/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ 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 { dropTask } from "ember-concurrency-decorators";
Expand All @@ -21,32 +20,10 @@ export default class CasesDetailWorkItemsEditController extends Controller {

@tracked description = this.workItem.description;

@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 },
});
finishWorkItem() {
this.notification.success(this.intl.t("workItems.finishSuccess"));

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

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

@dropTask
Expand Down
28 changes: 13 additions & 15 deletions ember/app/cases/detail/work-items/edit/index/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
{{this.workItem.task.name}}
</h2>

<div class="work-item-attributes">
<div>
{{#if this.workItem.isCompleted}}
<div class="work-item-attribute">
<span class="work-item-attribute__title">
<div>
<span>
{{t "workItems.closedBy"}}
</span>
{{this.workItem.closedByUser.fullName}}
</div>
<div class="work-item-attribute">
<span class="work-item-attribute__title">
<div>
<span>
{{t "workItems.closedAt"}}
</span>
{{
Expand Down Expand Up @@ -81,10 +81,7 @@

<div class="uk-margin">
<label class="uk-form-label" for="deadline">
{{t "workItems.deadline"}}
<span class="mandatory">
*
</span>
{{t "workItems.deadline"}}*
</label>
<div class="uk-form-controls">
<PikadayInput
Expand All @@ -110,12 +107,13 @@
@label={{t "global.save"}}
/>

<UkButton
@type="submit"
@color="primary"
@label={{t "workItems.actions.finish"}}
@onClick={{perform this.finishWorkItem}}
/>
<WorkItemButton
@mutation="complete"
@workItemId={{this.workItem.id}}
@onSuccess={{this.finishWorkItem}}
>
{{t "workItems.actions.finish"}}
</WorkItemButton>
</div>
</form>
{{/if}}
6 changes: 2 additions & 4 deletions ember/app/components/context-menu/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
<span hidden>{{t "global.openMenu"}}</span>
<UkIcon @icon="more-vertical" />
</UkButton>
<div uk-drop>
<div class="uk-card uk-card-body uk-card-small uk-card-default">
<ul class="uk-list">
<div uk-dropdown>
<ul class="uk-list uk-margin-remove">
{{#each @actions as |action|}}
<li>
<UkButton
Expand All @@ -21,5 +20,4 @@
</li>
{{/each}}
</ul>
</div>
</div>
2 changes: 1 addition & 1 deletion ember/app/components/filters/radio-buttons/template.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div>
<div class="uk-margin-right">
<label class="uk-display-block">{{@label}}</label>
<div class="uk-button-group">
{{#each @options as |option|}}
Expand Down
2 changes: 1 addition & 1 deletion ember/app/components/filters/template.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div class="filters" ...attributes>
<div class="uk-flex" ...attributes>
{{yield (hash RadioButtons=(component "filters/radio-buttons"))}}
</div>
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 @@ -8,7 +8,7 @@
</LinkTo>

<UkTab as |tab|>
<tab.item @href="/">{{t "nav.cases"}}</tab.item>
<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="/alexandria">{{t "nav.alexandria"}}</tab.item>
Expand Down
16 changes: 7 additions & 9 deletions ember/app/components/work-item-list/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
/>

<div class="uk-width-expand uk-flex uk-flex-middle uk-text-meta uk-margin">
<span>
{{
t
"global.paginationInfo"
count=@query.value.length
total=@query.totalCount
htmlSafe=true
}}
</span>
{{
t
"global.paginationInfo"
count=@query.value.length
total=@query.totalCount
htmlSafe=true
}}
</div>
1 change: 0 additions & 1 deletion ember/app/styles/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ $modal-z-index: 1;
@import "@projectcaluma/ember-form-builder";

@import "components/nav-bar";
@import "components/filters";

main {
display: flex;
Expand Down
24 changes: 0 additions & 24 deletions ember/app/styles/components/filters/_radio-buttons.scss

This file was deleted.

9 changes: 0 additions & 9 deletions ember/app/styles/components/filters/index.scss

This file was deleted.

5 changes: 2 additions & 3 deletions ember/app/work-items/controller.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import Controller from "@ember/controller";
import { action, set } from "@ember/object";
import { action } from "@ember/object";
import { tracked } from "@glimmer/tracking";
import { useCalumaQuery } from "@projectcaluma/ember-core/caluma-query";
import { allWorkItems } from "@projectcaluma/ember-core/caluma-query/queries";

export default class WorkItemsController extends Controller {
queryParams = ["order", "status"];

// Filters
@tracked order = "urgent";
@tracked status = "open";

Expand Down Expand Up @@ -73,6 +72,6 @@ export default class WorkItemsController extends Controller {

@action
updateFilter(type, value) {
set(this, type, value);
this[type] = value;
}
}
2 changes: 1 addition & 1 deletion ember/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@ember/optional-features": "2.0.0",
"@ember/render-modifiers": "2.0.4",
"@ember/test-helpers": "2.6.0",
"@faker-js/faker": "6.0.0",
"@faker-js/faker": "6.1.1",
"@glimmer/component": "1.0.4",
"@glimmer/tracking": "1.0.4",
"@projectcaluma/ember-core": "11.0.0-beta.5",
Expand Down
7 changes: 6 additions & 1 deletion ember/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1448,7 +1448,12 @@
minimatch "^3.0.4"
strip-json-comments "^3.1.1"

"@faker-js/[email protected]", "@faker-js/faker@^6.0.0":
"@faker-js/[email protected]":
version "6.1.1"
resolved "https://registry.yarnpkg.com/@faker-js/faker/-/faker-6.1.1.tgz#adf002d986e1751daadfcf65d1cc03944dab3ced"
integrity sha512-8yq1LJVGn4GY06riLddIU1LbJm15yjt46hjfkpWNpH/mqdciPOBVzicKOJxzQNrGgVHVBxcdm7sgwjI/Y19MYw==

"@faker-js/faker@^6.0.0":
version "6.0.0"
resolved "https://registry.yarnpkg.com/@faker-js/faker/-/faker-6.0.0.tgz#b613ebf5f5ebb2ab987afb567d8b7fe860199c13"
integrity sha512-10zLCKhp3YEmBuko71ivcMoIZcCLXgQVck6aNswX+AWwaek/L8S3yz9i8m3tHigRkcF6F2vI+qtdtyySHK+bGA==
Expand Down

0 comments on commit c2fa4da

Please sign in to comment.