Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ebmber): add links from interest to identity #992

Merged
merged 4 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ember/app/models/interest-category.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { localizedAttr, LocalizedModel } from "ember-localized-model";
export default class InterestCategoryModel extends LocalizedModel {
@localizedAttr title;
@attr description;
@hasMany interests;
@attr archived;
@attr public;

@hasMany("interest", { inverse: "category", async: true }) interests;
}
4 changes: 3 additions & 1 deletion ember/app/models/interest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { localizedAttr, LocalizedModel } from "ember-localized-model";
export default class InterestModel extends LocalizedModel {
@localizedAttr title;
@attr description;
@belongsTo("interest-category") category;
@attr archived;

@belongsTo("interest-category", { inverse: "interests", async: true })
category;
}
2 changes: 1 addition & 1 deletion ember/app/ui/application/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class ApplicationRoute extends Route {

await this.session.setup();

const locale = localStorage.getItem("locale") ?? "en";
const locale = localStorage.getItem("locale") ?? "de";
this.intl.setLocale([locale]);

this.calumaOptions.registerComponentOverride({
Expand Down
23 changes: 18 additions & 5 deletions ember/app/ui/components/identity-interests/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,16 @@
<ul class="uk-padding-remove uk-list">
{{#each category.interests as |interest|}}
<li class="uk-flex uk-flex-between uk-flex-middle">
<div>{{interest.title}}</div>
{{#if (can "list interest")}}
<LinkTo
@route="identities"
@query={{hash searchTerm=(concat '"' interest.title '"')}}
>
{{interest.title}}
</LinkTo>
{{else}}
{{interest.title}}
{{/if}}

{{#if (can "remove interest from identity" @identity)}}
<div>
Expand Down Expand Up @@ -54,12 +63,18 @@
{{/if}}

{{#if this.changeset}}
<hr>
<hr />

<h3 class="uk-margin-remove-top">
{{t "components.identity-interests.form.title.add"}}
</h3>

{{#if @profileView}}
<p>
{{t "components.identity-interests.disclaimer" htmlSafe=true}}
</p>
{{/if}}

<ValidatedForm
@model={{this.changeset}}
@on-submit={{perform this.submit}}
Expand Down Expand Up @@ -96,9 +111,7 @@
{{t "global.cancel"}}
</button>

<Form.submit
@label={{t "global.save"}}
/>
<Form.submit @label={{t "global.save"}} />
</p>
</ValidatedForm>
{{/if}}
Expand Down
5 changes: 5 additions & 0 deletions ember/app/ui/components/interest-category-form/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<Form.input
@label={{t "components.interest-category-form.label.title" lang="DE"}}
@name="_title.de"
data-test-input-title
/>

<Form.input
Expand All @@ -30,13 +31,15 @@
@label={{t "components.interest-category-form.label.description"}}
@name="description"
@required={{false}}
data-test-input-description
/>

<Form.input
@label={{t "components.interest-category-form.label.public"}}
@name="public"
@type="checkbox"
@required={{false}}
data-test-input-public
/>

<div class="uk-text-right">
Expand All @@ -50,13 +53,15 @@
<Form.submit
@label={{t "global.save"}}
@disabled={{cannot "edit interest-category" this.changeset.data}}
data-test-save
/>
<UkButton
@type="submit"
@color="primary"
@onClick={{this.setBackToInterests}}
@label={{t "global.saveAndBack"}}
@disabled={{cannot "edit interest-category" this.changeset.data}}
data-test-save-back
/>
</div>
</ValidatedForm>
Expand Down
3 changes: 2 additions & 1 deletion ember/app/ui/identities/index/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ export default class IdentitiesIndexController extends Controller {
@service intl;
@service fetch;

queryParams = ["pageSize", "pageNumber"];
queryParams = ["pageSize", "pageNumber", "searchTerm"];
@tracked pageSize = 25;
@tracked pageNumber = 1;
@tracked totalPages;
@tracked totalCount = 0;
@tracked searchTerm = "";

get pages() {
if (!this.totalPages) {
Expand Down
5 changes: 4 additions & 1 deletion ember/app/ui/interests/add/controller.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import Controller from "@ember/controller";
import { action } from "@ember/object";
import { inject as service } from "@ember/service";

export default class InterestsAddController extends Controller {
@service router;

@action onSave(interest) {
this.transitionToRoute("interests.edit", interest.id);
this.router.transitionTo("interests.edit", interest.id);
}
}
3 changes: 3 additions & 0 deletions ember/app/ui/interests/edit/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
<Form.input
@label={{t "interests.edit.form.label.title" lang="DE"}}
@name="_title.de"
data-test-new-interest-title
/>

<Form.input
Expand All @@ -104,6 +105,7 @@
@label={{t "interests.edit.form.label.description"}}
@name="description"
@required={{false}}
data-test-new-interest-description
/>

<p class="uk-text-right">
Expand All @@ -117,6 +119,7 @@

<Form.submit
@label={{t "global.save"}}
data-test-new-interest-save
/>
</p>
</ValidatedForm>
Expand Down
49 changes: 33 additions & 16 deletions ember/app/ui/interests/index/template.hbs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
<div
{{did-insert this.onUpdate}}
{{did-update this.onUpdate}}
>
<div {{did-insert this.onUpdate}} {{did-update this.onUpdate}}>
<div class="uk-flex uk-flex-between uk-flex-middle uk-margin-bottom">
<h1 class="uk-margin-remove">{{t "interests.index.title"}}</h1>

{{#if (can "add interest-category")}}
<LinkTo
@route="interests.add"
class="uk-button uk-button-default uk-flex-none"
data-test-category-add
>
{{t "interests.index.add"}}
</LinkTo>
Expand All @@ -19,21 +17,27 @@
<LoadingSpinner />
{{else if this.categories.length}}
<div
class="
uk-child-width-1-2@s
uk-child-width-1-3@m
uk-child-width-1-4@l
"
class="uk-child-width-1-2@s uk-child-width-1-3@m uk-child-width-1-4@l"
uk-grid="masonry: true"
>
{{#each this.categories as |category|}}
<div>
<div data-test-category={{category.title}}>
<div class="uk-card uk-card-default uk-card-body uk-card-small">
<div class="uk-flex uk-flex-between uk-flex-middle">
<div>
<strong>{{category.title}}</strong>{{#if category.public}} - <i>{{t "interests.index.list.public"}}</i>{{/if}}
<strong data-test-category-title>{{category.title}}</strong>
{{#if category.public}}
-
<i data-test-category-public>
{{t "interests.index.list.public"}}
</i>
{{/if}}
{{#if category.description}}
<div>{{category.description}}</div>
<div
data-test-category-description
>
{{category.description}}
</div>
{{/if}}
</div>

Expand Down Expand Up @@ -70,9 +74,22 @@
<ul class="uk-list uk-list-divider">
{{#each category.interests as |interest|}}
{{#unless interest.isNew}}
<li>
{{interest.title}}
<div class="uk-text-meta">{{interest.description}}</div>
<li data-test-interest>
<LinkTo
@route="identities"
@query={{hash
searchTerm=(concat '"' interest.title '"')
}}
data-test-interest-title
>
{{interest.title}}
</LinkTo>
<div
class="uk-text-meta"
data-test-interest-description
>
{{interest.description}}
</div>
</li>
{{/unless}}
{{/each}}
Expand All @@ -85,4 +102,4 @@
{{else}}
<p>{{t "interests.index.list.empty"}}</p>
{{/if}}
</div>
</div>
3 changes: 2 additions & 1 deletion ember/app/ui/interests/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { inject as service } from "@ember/service";

export default class InterestsRoute extends Route {
@service can;
@service router;

beforeModel() {
if (this.can.cannot("list interest")) {
return this.transitionTo("notfound");
return this.router.transitionTo("notfound");
}
}
}
3 changes: 1 addition & 2 deletions ember/mirage/factories/interest-category.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export default Factory.extend({
archived: () => faker.datatype.boolean(),

afterCreate(category, server) {
const children = Math.floor(Math.random() * 5 + 0.5);
server.createList("interest", children, { category });
server.createList("interest", 3, { category });
},
});
2 changes: 1 addition & 1 deletion ember/tests/acceptance/identities-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module("Acceptance | identities", function (hooks) {

await click(".uk-button-danger");

assert.dom(".uk-modal-body").includesText("applications");
assert.dom(".uk-modal-body").includesText("0 Gesuche");

await click(".uk-modal-footer .uk-button-primary");

Expand Down
90 changes: 90 additions & 0 deletions ember/tests/acceptance/interest-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { visit, fillIn, click, waitFor, currentURL } from "@ember/test-helpers";
import { setupMirage } from "ember-cli-mirage/test-support";
import { setupIntl } from "ember-intl/test-support";
import { setupApplicationTest } from "ember-qunit";
import { authenticateSession } from "ember-simple-auth/test-support";
import { module, test } from "qunit";

module("Acceptance | interest", function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
setupIntl(hooks);

hooks.beforeEach(async function () {
this.category = this.server.create("interest-category");

await authenticateSession({
access_token: "123qweasdyxc",
userinfo: { mysagw_groups: ["sagw"] },
});

await visit("/interests");
});

test("can list", async function (assert) {
assert.dom("[data-test-category]").exists({ count: 1 });
assert.dom("[data-test-interest]").exists({ count: 3 });
});

test("can add new category", async function (assert) {
await click("[data-test-category-add]");

assert.strictEqual(currentURL(), "/interests/add");

// create new category
await fillIn("[data-test-input-title]", "Apple");
await fillIn("[data-test-input-description]", "Pear");
await click("[data-test-input-public]");

await click("[data-test-save]");

assert.ok(currentURL().includes("/edit/"));

await click("[data-test-interest-add]");

// create new interest
await fillIn("[data-test-new-interest-title]", "Melon");
await fillIn("[data-test-new-interest-description]", "Pumpkin");
await click("[data-test-new-interest-save]");

await click("[data-test-save-back]");

assert.dom("[data-test-category]").exists({ count: 2 });

assert
.dom('[data-test-category="Apple"] [data-test-category-title]')
.hasText("Apple");
assert
.dom('[data-test-category="Apple"] [data-test-category-description]')
.hasText("Pear");
assert
.dom('[data-test-category="Apple"] [data-test-category-public]')
.exists({ count: 1 });

assert
.dom('[data-test-category="Apple"] [data-test-interest]')
.exists({ count: 1 });
assert
.dom('[data-test-category="Apple"] [data-test-interest-title]')
.hasText("Melon");
assert
.dom('[data-test-category="Apple"] [data-test-interest-description]')
.hasText("Pumpkin");
});

test("can delete category", async function (assert) {
await click("[data-test-category-delete]");

await waitFor(".uk-modal.uk-open");

await click(".uk-modal button.uk-button-primary");

assert.dom("[data-test-category]").doesNotExist();
});

test("interest is linked", async function (assert) {
await click(`[data-test-interest]:first-child [data-test-interest-title]`);

assert.ok(currentURL().includes("/identities?searchTerm=%22"));
});
});
1 change: 1 addition & 0 deletions ember/translations/components/identity-interests/de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ components:
identity-interests:
title: "Interessen"
add: "Interesse hinzufügen"
disclaimer: "Mit dem Speichern erkläre ich mich einverstanden, von der SAGW Informationen oder Publikationen zu den von mir angegebenen Interessen zu erhalten und bestätige, dass ich die <a href=''https://www.sagw.ch/sagw/zur-sagw/impressum'' target=''_blank''>Hinweise zum Datenschutz</a> gelesen habe und sie akzeptiere."

list:
delete: "Interesse löschen"
Expand Down
1 change: 1 addition & 0 deletions ember/translations/components/identity-interests/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ components:
identity-interests:
title: "Interests"
add: "Add interest"
disclaimer: "By saving, I agree to receive information or publications from the SAHS on the interests I have indicated and confirm that I have read and accept the <a href=''https://www.sagw.ch/sagw/zur-sagw/impressum'' target=''_blank''>information on data protection</a>."

list:
delete: "Delete interest"
Expand Down
Loading