From 23139785a193684389a9e2f283908ccb4e06bf9e Mon Sep 17 00:00:00 2001 From: matteo Date: Wed, 18 May 2022 17:01:43 +0200 Subject: [PATCH 01/40] todos --- app/controllers/application/destroy.js | 1 + app/controllers/application/edit.js | 1 + 2 files changed, 2 insertions(+) diff --git a/app/controllers/application/destroy.js b/app/controllers/application/destroy.js index 9d80f445c..a144fc336 100644 --- a/app/controllers/application/destroy.js +++ b/app/controllers/application/destroy.js @@ -3,6 +3,7 @@ import EditController from 'amber-ui/controllers/application/edit'; import ModelSaveUtil from 'amber-ui/utils/model-save'; export default EditController.extend({ + //todo: refactor to octane style successMessage: 'Verwijderen gelukt!', actions: { destroy() { diff --git a/app/controllers/application/edit.js b/app/controllers/application/edit.js index 13ccbe436..26096589c 100644 --- a/app/controllers/application/edit.js +++ b/app/controllers/application/edit.js @@ -5,6 +5,7 @@ import { inject as service } from '@ember/service'; import { tracked } from '@glimmer/tracking'; export default class EditController extends Controller { + //todo: refactor to octane style @service('flash-notice') flashNotice; @tracked errorMessage = null; From 77c57cf4c9218fbc69cf5b0b19f42e869424d6a8 Mon Sep 17 00:00:00 2001 From: matteo Date: Wed, 18 May 2022 17:29:39 +0200 Subject: [PATCH 02/40] add checks for overrides of ModelSaveUtils, using the entity property of ModelSaveUtils --- app/controllers/application/edit.js | 1 - app/utils/model-save.js | 45 ++++++++++++++++++----------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/app/controllers/application/edit.js b/app/controllers/application/edit.js index 26096589c..13ccbe436 100644 --- a/app/controllers/application/edit.js +++ b/app/controllers/application/edit.js @@ -5,7 +5,6 @@ import { inject as service } from '@ember/service'; import { tracked } from '@glimmer/tracking'; export default class EditController extends Controller { - //todo: refactor to octane style @service('flash-notice') flashNotice; @tracked errorMessage = null; diff --git a/app/utils/model-save.js b/app/utils/model-save.js index dec6bbc46..1ae3c33ff 100644 --- a/app/utils/model-save.js +++ b/app/utils/model-save.js @@ -1,33 +1,44 @@ import { isNone } from '@ember/utils'; - export default class ModelSaveUtil { constructor(entity) { this.entity = entity; } - onSuccess(model) { - // Show notice - if (!isNone(this.entity.successMessage)) { - this.entity.flashNotice.sendSuccess(this.entity.successMessage); + sendSuccess() { + if (!isNone(this.entity?.successMessage)) { + this.entity?.flashNotice?.sendSuccess(this.entity.successMessage); } + } - // Redirect - if (!isNone(this.entity.successTransitionTarget)) { - if (isNone(model)) { - // In destroy routes, model is undefined - this.entity.transitionToRoute(this.entity.successTransitionTarget); - } else { - const targetModel = this.entity.successTransitionModel || model; - this.entity.transitionToRoute( - this.entity.successTransitionTarget, - targetModel - ); + onSuccess(model) { + // Show notice + this.sendSuccess(); + // todo: make sure that all subclasses of the edit controller correctly implement onsuccess, and don't call sendsuccess unnecessarily + if (this.entity?.onSuccess) { + this.entity.onSuccess(); + } else { + // Redirect + const targetModel = this.entity?.successTransitionModel ?? model; + if (!isNone(this.entity?.successTransitionTarget)) { + if (isNone(targetModel)) { + // In destroy routes, targetModel is undefined + this.entity.transitionToRoute(this.entity.successTransitionTarget); + } else { + this.entity.transitionToRoute( + this.entity.successTransitionTarget, + targetModel, + ); + } } } } onError(error) { - this.entity.errorMessage = error.errors.map((err) => err.detail).join(', '); + if (this.entity?.onError) { + this.entity.onError(error); + } else { + this.entity.errorMessage = error.errors.map((err) => err.detail).join(', '); + } } saveModel(model) { From bc89493b88fff4add9228c7d38760024a10d5ecc Mon Sep 17 00:00:00 2001 From: matteo Date: Tue, 30 Aug 2022 19:49:38 +0200 Subject: [PATCH 03/40] got the activity destroy controller working properly, it seems :) --- app/controllers/activities/destroy.js | 8 ++++--- app/controllers/activities/edit.js | 1 + app/controllers/application/destroy.js | 32 ++++++++++---------------- app/templates/activities/destroy.hbs | 2 +- app/utils/model-save.js | 13 +++++++++++ 5 files changed, 32 insertions(+), 24 deletions(-) diff --git a/app/controllers/activities/destroy.js b/app/controllers/activities/destroy.js index 46c76cdd1..68bb83c43 100644 --- a/app/controllers/activities/destroy.js +++ b/app/controllers/activities/destroy.js @@ -1,5 +1,7 @@ import DestroyController from 'amber-ui/controllers/application/destroy'; -export default DestroyController.extend({ - successTransitionTarget: 'activities.index', -}); +export default class DestroyActivityController extends DestroyController { + successTransitionTarget = 'activities.index'; +} + + diff --git a/app/controllers/activities/edit.js b/app/controllers/activities/edit.js index fc8130635..efd192032 100644 --- a/app/controllers/activities/edit.js +++ b/app/controllers/activities/edit.js @@ -7,6 +7,7 @@ import { inject as service } from '@ember/service'; // eslint-disable-next-line ember/no-computed-properties-in-native-classes import { union } from '@ember/object/computed'; +//todo: refactor below class to extend EditController export default class EditActivityController extends Controller { @service session; @service store; diff --git a/app/controllers/application/destroy.js b/app/controllers/application/destroy.js index a144fc336..c812a0a5a 100644 --- a/app/controllers/application/destroy.js +++ b/app/controllers/application/destroy.js @@ -1,23 +1,15 @@ -import { isNone } from '@ember/utils'; import EditController from 'amber-ui/controllers/application/edit'; -import ModelSaveUtil from 'amber-ui/utils/model-save'; +import { action } from '@ember/object'; -export default EditController.extend({ - //todo: refactor to octane style - successMessage: 'Verwijderen gelukt!', - actions: { - destroy() { - const modelSaveUtil = new ModelSaveUtil(this); - this.set('errorMessage', null); - if (!isNone(this.model)) { - this.model - .destroyRecord() - .then(modelSaveUtil.onSuccess.bind(modelSaveUtil)) - .catch(modelSaveUtil.onError.bind(modelSaveUtil)); - } - }, - saveModel: undefined, - submit: undefined, - }, -}); +export default class DestroyController extends EditController { + successMessage = 'Verwijderen gelukt!'; + + @action + destroyModel() { + this.modelSaveUtil.destroyModel(this.model) + } + + submit = undefined + +} diff --git a/app/templates/activities/destroy.hbs b/app/templates/activities/destroy.hbs index 295ac26b4..09efe85ad 100644 --- a/app/templates/activities/destroy.hbs +++ b/app/templates/activities/destroy.hbs @@ -20,7 +20,7 @@ verwijderen?

- { + this.onSuccess(null); + }) + .catch((error) => { + this.onError(error); + }); + } + } } From 50bfe4f819a537b8bb4e9123a10725095324c1ec Mon Sep 17 00:00:00 2001 From: matteo Date: Tue, 30 Aug 2022 20:52:55 +0200 Subject: [PATCH 04/40] article comments now properly redirect. Took me a while to figure out how to do this, and it should not have taken this long lol. --- app/controllers/application/destroy.js | 5 ++-- app/controllers/application/edit.js | 2 +- app/controllers/article-comments/destroy.js | 24 +++++++++---------- .../category/threads/thread/posts/destroy.js | 8 +++---- app/controllers/polls/destroy.js | 7 +++--- app/templates/article-comments/destroy.hbs | 2 +- app/templates/articles/destroy.hbs | 2 +- app/templates/books/destroy.hbs | 2 +- app/templates/debit/collections/destroy.hbs | 2 +- app/templates/debit/transactions/destroy.hbs | 2 +- app/templates/form/responses/destroy.hbs | 2 +- .../forum/categories/category/destroy.hbs | 2 +- .../category/threads/thread/destroy.hbs | 2 +- .../category/threads/thread/posts/destroy.hbs | 2 +- app/templates/mail-aliases/destroy.hbs | 2 +- app/templates/mail-moderations/destroy.hbs | 2 +- .../photo-albums/photo-album/destroy.hbs | 2 +- .../photo-album/photos/destroy.hbs | 2 +- app/templates/photo-comments/destroy.hbs | 2 +- app/templates/polls/destroy.hbs | 2 +- app/templates/static-pages/destroy.hbs | 2 +- app/templates/users/destroy.hbs | 2 +- app/utils/model-save.js | 1 + 23 files changed, 41 insertions(+), 40 deletions(-) diff --git a/app/controllers/application/destroy.js b/app/controllers/application/destroy.js index c812a0a5a..d542d4eda 100644 --- a/app/controllers/application/destroy.js +++ b/app/controllers/application/destroy.js @@ -7,9 +7,10 @@ export default class DestroyController extends EditController { @action destroyModel() { - this.modelSaveUtil.destroyModel(this.model) + console.log('destroying shit') + this.modelSaveUtil.destroyModel(this.model); } - submit = undefined + submit = undefined; } diff --git a/app/controllers/application/edit.js b/app/controllers/application/edit.js index 13ccbe436..6b8f99057 100644 --- a/app/controllers/application/edit.js +++ b/app/controllers/application/edit.js @@ -11,7 +11,7 @@ export default class EditController extends Controller { successMessage = 'Wijzigen gelukt!'; successTransitionTarget = null; - successTransitionModel = null; + @tracked successTransitionModel = null; constructor() { super(...arguments); diff --git a/app/controllers/article-comments/destroy.js b/app/controllers/article-comments/destroy.js index 2f9404321..49c835b95 100644 --- a/app/controllers/article-comments/destroy.js +++ b/app/controllers/article-comments/destroy.js @@ -1,15 +1,13 @@ import DestroyController from 'amber-ui/controllers/application/destroy'; +import { action } from '@ember/object'; -export default DestroyController.extend({ - successMessage: 'Artikelreactie verwijderd!', - actions: { - destroy() { - this.set('article', this.model.article); - this._super(...arguments); - }, - onSuccess() { - this._super(...arguments); - this.transitionToRoute('articles.show', this.article); - }, - }, -}); +export default class DestroyArticleCommentController extends DestroyController { + successMessage = 'Artikelreactie verwijderd!'; + successTransitionTarget = 'articles.show'; + @action + async destroyModel() { + this.successTransitionModel = await this.model.article; + super.destroyModel(); + } + +} diff --git a/app/controllers/forum/categories/category/threads/thread/posts/destroy.js b/app/controllers/forum/categories/category/threads/thread/posts/destroy.js index 8429d5ac3..64b6047ed 100644 --- a/app/controllers/forum/categories/category/threads/thread/posts/destroy.js +++ b/app/controllers/forum/categories/category/threads/thread/posts/destroy.js @@ -1,6 +1,6 @@ import DestroyController from 'amber-ui/controllers/application/destroy'; -export default DestroyController.extend({ - successMessage: 'Forumbericht verwijderd!', - successTransitionTarget: 'forum.categories.category.threads.thread', -}); +export default class DestroyPostController extends DestroyController { + successMessage = 'Forumbericht verwijderd!'; + successTransitionTarget = 'forum.categories.category.threads.thread'; +} diff --git a/app/controllers/polls/destroy.js b/app/controllers/polls/destroy.js index b08af4956..b4d62c248 100644 --- a/app/controllers/polls/destroy.js +++ b/app/controllers/polls/destroy.js @@ -1,5 +1,6 @@ import DestroyController from 'amber-ui/controllers/application/destroy'; -export default DestroyController.extend({ - successTransitionTarget: 'polls.index', -}); +export default class DestroyPollController extends DestroyController { + successMessage = 'Poll verwijderd!'; + successTransitionTarget = 'polls.index'; +} diff --git a/app/templates/article-comments/destroy.hbs b/app/templates/article-comments/destroy.hbs index e42bb39a0..e0b2851d9 100644 --- a/app/templates/article-comments/destroy.hbs +++ b/app/templates/article-comments/destroy.hbs @@ -11,7 +11,7 @@ {{/if}} diff --git a/app/components/forms/mail-alias-form.hbs b/app/components/forms/mail-alias-form.hbs index da9766427..48c77351c 100644 --- a/app/components/forms/mail-alias-form.hbs +++ b/app/components/forms/mail-alias-form.hbs @@ -101,9 +101,9 @@ @errors={{@model.errors}} @errorMessage={{@errorMessage}} > - + diff --git a/app/components/forms/mandate-form.hbs b/app/components/forms/mandate-form.hbs index f210ee574..e43b0f43b 100644 --- a/app/components/forms/mandate-form.hbs +++ b/app/components/forms/mandate-form.hbs @@ -41,9 +41,9 @@ - + diff --git a/app/components/forms/photo-album-form.hbs b/app/components/forms/photo-album-form.hbs index 0d7b0a797..e16c2e753 100644 --- a/app/components/forms/photo-album-form.hbs +++ b/app/components/forms/photo-album-form.hbs @@ -73,9 +73,9 @@ @errors={{@model.errors}} @errorMessage={{@errorMessage}} > - + diff --git a/app/components/forms/post-form.hbs b/app/components/forms/post-form.hbs index a57309289..1b53df8f3 100644 --- a/app/components/forms/post-form.hbs +++ b/app/components/forms/post-form.hbs @@ -21,13 +21,13 @@ @errors={{@model.errors}} @errorMessage={{@errorMessage}} > - Annuleren - + diff --git a/app/components/forms/static-page-form.hbs b/app/components/forms/static-page-form.hbs index f58bacdca..49c0287bc 100644 --- a/app/components/forms/static-page-form.hbs +++ b/app/components/forms/static-page-form.hbs @@ -42,9 +42,9 @@ - + diff --git a/app/components/forms/thread-form.hbs b/app/components/forms/thread-form.hbs index 33b9b52f4..bf93da928 100644 --- a/app/components/forms/thread-form.hbs +++ b/app/components/forms/thread-form.hbs @@ -1,26 +1,26 @@
-
{{if @model.thread.isNew 'Topic aanmaken' 'Topic wijzigen'}}
+
{{if @model.isNew 'Topic aanmaken' 'Topic wijzigen'}}
- {{#if @model.post}} + {{#if @model.firstPost }} {{else}} {{#if (can 'edit forum/threads')}} @@ -31,7 +31,7 @@ @errors={{@model.errors}} @errorMessage={{@errorMessage}} > - {{#if @model.thread.isNew}} + {{#if @model.isNew}} Annuleren diff --git a/app/controllers/application/destroy.js b/app/controllers/application/destroy.js index 5ad2a3298..1d58b4f09 100644 --- a/app/controllers/application/destroy.js +++ b/app/controllers/application/destroy.js @@ -1,9 +1,14 @@ import EditController from 'amber-ui/controllers/application/edit'; import { action } from '@ember/object'; +import {tracked} from '@glimmer/tracking'; export default class DestroyController extends EditController { successMessage = 'Verwijderen gelukt!'; + cancelMessage = 'Verwijderen geannuleerd.'; + @tracked successTransitionModel = null; + @tracked cancelTransitionTarget = null; + @tracked cancelTransitionModel = this.model; @action destroyModel() { diff --git a/app/controllers/application/edit.js b/app/controllers/application/edit.js index 75c24750a..e522d7142 100644 --- a/app/controllers/application/edit.js +++ b/app/controllers/application/edit.js @@ -9,6 +9,7 @@ export default class EditController extends Controller { @tracked errorMessage = null; successMessage = 'Wijzigen gelukt!'; + cancelMessage = 'Wijzigen geannuleerd.'; @tracked successTransitionTarget = null; @tracked successTransitionModel = this.model; @tracked cancelTransitionTarget = this.successTransitionTarget; // sensible default diff --git a/app/controllers/application/new.js b/app/controllers/application/new.js index ef4e1784d..a3fcd19f9 100644 --- a/app/controllers/application/new.js +++ b/app/controllers/application/new.js @@ -2,6 +2,7 @@ import EditController from 'amber-ui/controllers/application/edit'; export default class NewController extends EditController { successMessage = 'Aanmaken gelukt!'; + cancelMessage = 'Aanmaken geannuleerd.'; cancelTransitionTarget = null; // default should not be successTransitionTarget, in contrast to the edit controller cancelTransitionModel = null; } diff --git a/app/controllers/books/destroy.js b/app/controllers/books/destroy.js index cbbfc510e..36256fc49 100644 --- a/app/controllers/books/destroy.js +++ b/app/controllers/books/destroy.js @@ -2,4 +2,5 @@ import DestroyController from 'amber-ui/controllers/application/destroy'; export default class BookDestroyController extends DestroyController { successTransitionTarget = 'books.index'; + cancelTransitionTarget = 'books.show'; } diff --git a/app/controllers/debit/collections/destroy.js b/app/controllers/debit/collections/destroy.js index 790315c84..68a5d67a2 100644 --- a/app/controllers/debit/collections/destroy.js +++ b/app/controllers/debit/collections/destroy.js @@ -2,4 +2,5 @@ import DestroyController from 'amber-ui/controllers/application/destroy'; export default class DebitCollectionDestroyController extends DestroyController { successTransitionTarget = 'debit.collections.index'; + cancelTransitionTarget = 'debit.collections.show'; } diff --git a/app/controllers/debit/mandates/edit.js b/app/controllers/debit/mandates/edit.js index e6978d04d..7779047ff 100644 --- a/app/controllers/debit/mandates/edit.js +++ b/app/controllers/debit/mandates/edit.js @@ -1,12 +1,13 @@ import EditController from 'amber-ui/controllers/application/edit'; // eslint-disable-next-line ember/no-computed-properties-in-native-classes -import { computed } from '@ember/object'; +import { inject as service } from '@ember/service'; export default class EditMandateController extends EditController { successTransitionTarget = 'debit.mandates.show'; - @computed('store', function () { + @service store; + + get users() { return this.store.findAll('user'); - }) - users; + } } diff --git a/app/controllers/debit/mandates/new.js b/app/controllers/debit/mandates/new.js index 673f6942e..0bb54d52f 100644 --- a/app/controllers/debit/mandates/new.js +++ b/app/controllers/debit/mandates/new.js @@ -1,3 +1,8 @@ import EditMandateController from './edit'; -export default class NewMandateController extends EditMandateController {} +export default class NewMandateController extends EditMandateController { + successMessage = 'Aanmaken gelukt!'; + cancelMessage = 'Aanmaken geannuleerd.'; + cancelTransitionTarget = 'debit.mandates.index'; + cancelTransitionModel = null; +} diff --git a/app/controllers/forum/categories/category/threads/new.js b/app/controllers/forum/categories/category/threads/new.js index 7adcd3427..852887e34 100644 --- a/app/controllers/forum/categories/category/threads/new.js +++ b/app/controllers/forum/categories/category/threads/new.js @@ -6,46 +6,42 @@ import { inject as service } from '@ember/service'; export default class NewThreadController extends NewController { @service('flash-notice') flashNotice; - successTransitionTarget = 'forum.categories.category.threads.thread'; + successTransitionTarget = 'forum.categories.category.threads.thread.show'; + cancelTransitionTarget = 'forum.categories.category.show'; + cancelTransitionModel = this.model?.thread?.category; + - routeIsNew = true; content = ''; @action - onSuccess() { + onSuccess(savedModel) { // Reload thread to update thread.amountOfPosts - this.model.thread.reload(); + savedModel.reload(); // Reload category to update category.amountOfThreads - this.model.category.reload(); + savedModel.category.reload(); + // redirect + this.modelSaveUtil.redirectSuccess(savedModel); } @action - submit() { - this.set('errorMessage', null); - const { thread } = this.model; - const { post } = this.model; + async submit() { + this.errorMessage = null; + const thread = await this.model; + const post = thread.firstPost; - if (isNone(post.get('message'))) { + if (isNone(post.message)) { this.set('errorMessage', 'Je moet eerst een bericht aanmaken'); return; } if (!isNone(thread)) { - thread - .save() - .then((savedModel) => { - post - .save() - .then(() => { - this.send('onSuccess', savedModel); - }) - .catch((error) => { - this.send('onError', error); - }); - }) - .catch((error) => { - this.send('onError', error); - }); + try { + const savedModel = await thread.save(); + await post.save(); + this.onSuccess(savedModel); + } catch (error) { + this.modelSaveUtil.onError(error); + } } } } diff --git a/app/controllers/forum/categories/category/threads/thread/edit.js b/app/controllers/forum/categories/category/threads/thread/edit.js index ad6dbf743..d8e8b4d21 100644 --- a/app/controllers/forum/categories/category/threads/thread/edit.js +++ b/app/controllers/forum/categories/category/threads/thread/edit.js @@ -3,10 +3,6 @@ import { action } from '@ember/object'; export default class EditThreadController extends EditController { successMessage = 'Topic aangepast!'; - successTransitionTarget = 'forum.categories.category.threads.thread'; + successTransitionTarget = 'forum.categories.category.threads.thread.show'; - @action - submit() { - this.modelSaveUtil.saveModel(this.model.thread); - } } diff --git a/app/controllers/forum/categories/new.js b/app/controllers/forum/categories/new.js index f082a5dee..429e0cd72 100644 --- a/app/controllers/forum/categories/new.js +++ b/app/controllers/forum/categories/new.js @@ -4,4 +4,5 @@ export default class NewCategoryController extends NewController { successMessage = 'Categorie toegevoegd!'; successTransitionTarget = 'forum.categories'; successTransitionTarget = null; + cancelTransitionTarget = 'forum.categories'; } diff --git a/app/controllers/groups/edit.js b/app/controllers/groups/edit.js index 32ec82c15..eb4deb426 100644 --- a/app/controllers/groups/edit.js +++ b/app/controllers/groups/edit.js @@ -1,15 +1,17 @@ // eslint-disable-next-line ember/no-computed-properties-in-native-classes -import { action, computed } from '@ember/object'; -import { A } from '@ember/array'; +import {action, computed} from '@ember/object'; +import {A} from '@ember/array'; import Controller from '@ember/controller'; -import { GroupKinds } from 'amber-ui/constants'; -import { all } from 'rsvp'; -import { capitalize } from '@ember/string'; -import { inject as service } from '@ember/service'; +import {GroupKinds} from 'amber-ui/constants'; +import {all} from 'rsvp'; +import {capitalize} from '@ember/string'; +import {inject as service} from '@ember/service'; +import EditController from "../application/edit"; -export default class EditGroupController extends Controller { - @service('flash-notice') flashNotice; +export default class EditGroupController extends EditController { @service session; + successMessage = 'Groep aangepast!'; + successTransitionTarget = 'groups.show'; _groupKindToOption(groupKind) { return { @@ -18,15 +20,13 @@ export default class EditGroupController extends Controller { }; } - @computed('_groupKindToOption', function () { + get groupKindOptions() { return GroupKinds.map(this._groupKindToOption); - }) - groupKindOptions; + } - @computed('store', function () { + get users() { return this.store.findAll('user'); - }) - users; + } @action addUser(user) { @@ -44,52 +44,47 @@ export default class EditGroupController extends Controller { } @action - submit() { + async submit() { + // todo: take a good look at this method, and see if its can be simplified to conform more to the + // EditController + model-save-utils pattern const membershipErrors = A(); if (this.model !== undefined) { let failedMembershipSavings = 0; - this.model - .save() - .then(() => { - return all( - this.model.get('memberships').map((membership) => { - if (membership.get('hasDirtyAttributes')) { - return membership.save().catch((error) => { - membershipErrors.push({ membership, error }); - failedMembershipSavings++; - }); - } - }) + try { + const savedModel = await this.model.save(); + await all( + this.model.get('memberships').map((membership) => { + if (membership.get('hasDirtyAttributes')) { + return membership.save().catch((error) => { + membershipErrors.push({membership, error}); + failedMembershipSavings++; + }); + } + }) + ); + if (failedMembershipSavings) { + const prefix = failedMembershipSavings > 1 ? 'zijn' : 'is'; + const suffix = + failedMembershipSavings > 1 ? 'lidmaatschappen' : 'lidmaatschap'; + + const membershipErrorText = membershipErrors.reduce( + (errorMessage, membershipError) => { + const singleError = `\t ${membershipError.membership.get( + 'user.fullName' + )} (${membershipError.error.errors[0].source.pointer}) \n`; + return errorMessage + singleError; + }, + '' ); - }) - .then(() => { - if (failedMembershipSavings) { - const prefix = failedMembershipSavings > 1 ? 'zijn' : 'is'; - const suffix = - failedMembershipSavings > 1 ? 'lidmaatschappen' : 'lidmaatschap'; + this.errorMessage = `Er ${prefix} ${failedMembershipSavings} ${suffix} niet juist opgeslagen: \n ${membershipErrorText}`; + } else { + this.modelSaveUtil.onSuccess(savedModel); + } - const membershipErrorText = membershipErrors.reduce( - (errorMessage, membershipError) => { - const singleError = `\t ${membershipError.membership.get( - 'user.fullName' - )} (${membershipError.error.errors[0].source.pointer}) \n`; - return errorMessage + singleError; - }, - '' - ); - this.set( - 'errorMessage', - `Er ${prefix} ${failedMembershipSavings} ${suffix} niet juist opgeslagen: \n ${membershipErrorText}` - ); - } else { - this.flashNotice.sendSuccess('Groep aangepast!'); - this.transitionToRoute('groups.show', this.model.id); - } - }) - .catch((error) => { - this.set('errorMessage', error.message); - }); + } catch (error) { + this.errorMessage = error.message; + } } } diff --git a/app/controllers/groups/new.js b/app/controllers/groups/new.js index 08ab6442f..94d0c8aa7 100644 --- a/app/controllers/groups/new.js +++ b/app/controllers/groups/new.js @@ -1,3 +1,8 @@ import EditController from './edit'; -export default class NewGroupController extends EditController {} +export default class NewGroupController extends EditController { + successMessage = 'Groep aangemaakt!'; + cancelMessage = 'Groep aanmaken geannuleerd.'; + cancelTransitionTarget = 'groups.index'; + cancelTransitionModel = null; +} diff --git a/app/controllers/mail-aliases/new.js b/app/controllers/mail-aliases/new.js index b8d1ae8b3..79dd988eb 100644 --- a/app/controllers/mail-aliases/new.js +++ b/app/controllers/mail-aliases/new.js @@ -1,3 +1,8 @@ import EditMailAliasController from './edit'; -export default class NewMailAliasController extends EditMailAliasController {} +export default class NewMailAliasController extends EditMailAliasController { + successMessage = 'Mail-alias aangemaakt!'; + cancelMessage = 'Mail-alias aanmaken geannuleerd.'; + cancelTransitionTarget = 'mail-aliases.index'; + cancelTransitionModel = null; +} diff --git a/app/controllers/photo-albums/new.js b/app/controllers/photo-albums/new.js index 12db4fa2e..589d5e5b7 100644 --- a/app/controllers/photo-albums/new.js +++ b/app/controllers/photo-albums/new.js @@ -9,31 +9,14 @@ export default class NewPhotoAlbumController extends NewController { @service abilities; successTransitionTarget = 'photo-albums.photo-album.edit'; + cancelTransitionTarget = 'photo-albums.index'; - @computed('session.currentUser.{group,groups}', function () { - const optionArray = [ - { - label: '', - value: null, - }, - ]; - const groups = this.session.currentUser.group; - groups.forEach((group) => { - optionArray.push({ - label: group, - value: group, - }); - }); - return optionArray; - }) - groupOptions; - @computed('session.currentUser', 'store', function () { + get groups() { if (this.abilities.can('select all groups for photo-albums')) { return this.store.findAll('group'); } return this.session.currentUser.get('groups'); - }) - groups; + } } diff --git a/app/controllers/photo-albums/photo-album/edit.js b/app/controllers/photo-albums/photo-album/edit.js index aab37d424..b6f19559e 100644 --- a/app/controllers/photo-albums/photo-album/edit.js +++ b/app/controllers/photo-albums/photo-album/edit.js @@ -1,26 +1,17 @@ // eslint-disable-next-line ember/no-computed-properties-in-native-classes import { action, computed } from '@ember/object'; -import NewPhotoAlbumController from 'amber-ui/controllers/photo-albums/new'; import { inject as service } from '@ember/service'; +import EditController from "../../application/edit"; +import NewPhotoAlbumController from "../new"; export default class EditPhotoAlbumController extends NewPhotoAlbumController { + successMessage = "Wijzigen en/of foto's toevoegen gelukt!"; + cancelMessage = "Wijzigen en/of foto's toevoegen geannuleerd."; + successTransitionTarget = 'photo-albums.photo-album.show'; + cancelTransitionTarget = this.successTransitionTarget; + cancelTransitionModel = this.model; @service fetch; - @action - submit() { - const photoAlbum = this.model; - photoAlbum - .save() - .then(() => { - photoAlbum.photos.reload(); - // Only pass id when force reload is required, see http://emberigniter.com/force-store-reload-data-api-backend/ - this.transitionToRoute('photo-albums.photo-album', photoAlbum.id); - }) - .catch((error) => { - this.set('errorMessage', error.message); - }); - } - @computed(function () { return { Authorization: this.fetch.authorizationHeader() }; }) diff --git a/app/controllers/polls/edit.js b/app/controllers/polls/edit.js index 3b74db161..0becbbc18 100644 --- a/app/controllers/polls/edit.js +++ b/app/controllers/polls/edit.js @@ -9,8 +9,8 @@ export default class EditPollController extends EditController { successTransitionTarget = 'polls.show'; @action - submit() { - this.modelSaveUtil.saveModelWithForm(this.model); + async submit() { + await this.modelSaveUtil.saveModelWithForm(this.model); } @union('model.errors', 'model.form.errors') combinedErrors; diff --git a/app/controllers/polls/new.js b/app/controllers/polls/new.js index c2e26e468..79da18209 100644 --- a/app/controllers/polls/new.js +++ b/app/controllers/polls/new.js @@ -1,6 +1,8 @@ import EditPollController from './edit'; export default class NewPollController extends EditPollController { + successMessage = 'Aanmaken gelukt!'; + cancelMessage = 'Aanmaken geannuleerd.'; cancelTransitionTarget = 'polls.index'; cancelTransitionModel = null; } diff --git a/app/controllers/static-pages/edit.js b/app/controllers/static-pages/edit.js index 1bb6847e4..00a99da0d 100644 --- a/app/controllers/static-pages/edit.js +++ b/app/controllers/static-pages/edit.js @@ -8,13 +8,12 @@ export default class EditStaticPageController extends EditController { successMessage = 'Infopagina aangepast!'; successTransitionTarget = 'static-pages.show'; - @computed(function () { + get staticPageCategoryOptions() { return StaticPageCategories.map((pageCategory) => { return { value: pageCategory, label: capitalize(pageCategory), }; }); - }) - staticPageCategoryOptions; + } } diff --git a/app/controllers/static-pages/new.js b/app/controllers/static-pages/new.js index 06e677354..0df2af3d1 100644 --- a/app/controllers/static-pages/new.js +++ b/app/controllers/static-pages/new.js @@ -1,3 +1,8 @@ import EditStaticPageController from './edit'; -export default class NewStaticPageController extends EditStaticPageController {} +export default class NewStaticPageController extends EditStaticPageController { + successMessage = 'Infopagina aangemaakt!'; + cancelMessage = 'Aanmaken geannuleerd.'; + cancelTransitionTarget = 'static-pages.index'; + cancelTransitionModel = null; +} diff --git a/app/models/forum/thread.js b/app/models/forum/thread.js index 512e20eeb..6cee9028d 100644 --- a/app/models/forum/thread.js +++ b/app/models/forum/thread.js @@ -14,6 +14,10 @@ export default class Thread extends Model { @belongsTo('forum/category') category; @hasMany('forum/post') posts; + get firstPost() { + return this.posts.length > 0 ? this.posts[0] : null; + } + get isOpen() { return this.closedAt === null; } @@ -25,4 +29,11 @@ export default class Thread extends Model { this.set('closedAt', new Date()); } } + + rollbackAttributesAndPosts() { + this.rollbackAttributes(); + this.posts.forEach((post) => { + post.rollbackAttributes(); + }) + } } diff --git a/app/routes/forum/categories/category/threads/new.js b/app/routes/forum/categories/category/threads/new.js index 3eb40e284..a989cdcd1 100644 --- a/app/routes/forum/categories/category/threads/new.js +++ b/app/routes/forum/categories/category/threads/new.js @@ -7,17 +7,16 @@ export default class NewTopicRoute extends AuthenticatedRoute { return this.abilities.can('create forum/thread'); } - model() { + async model() { const category = this.modelFor('forum.categories.category'); - const thread = this.store.createRecord('forum/thread', { category }); - const post = this.store.createRecord('forum/post', { thread }); - - return { category, thread, post }; + const thread = await this.store.createRecord('forum/thread', { category }); + const post = await this.store.createRecord('forum/post', { thread }); + post.reload(); // hoping this updates thread.posts? + return thread; } deactivate() { super.deactivate(); - this.controller.model.thread?.rollbackAttributes(); - this.controller.model.post?.rollbackAttributes(); + this.controller.model.rollbackAttributesAndPosts(); } } diff --git a/app/routes/forum/categories/category/threads/thread/edit.js b/app/routes/forum/categories/category/threads/thread/edit.js index eba09fc0f..0e69256c3 100644 --- a/app/routes/forum/categories/category/threads/thread/edit.js +++ b/app/routes/forum/categories/category/threads/thread/edit.js @@ -7,13 +7,13 @@ export default class EditTopicRoute extends AuthenticatedRoute { return this.abilities.can('edit forum/threads'); } - model() { - const thread = this.modelFor('forum.categories.category.threads.thread'); - return { thread }; + async model() { + const thread = await this.modelFor('forum.categories.category.threads.thread'); + return thread; } deactivate() { super.deactivate(); - this.controller.model.thread?.rollbackAttributes(); + this.controller.model.rollbackAttributesAndPosts(); } } diff --git a/app/routes/forum/categories/category/threads/thread/posts/edit.js b/app/routes/forum/categories/category/threads/thread/posts/edit.js index 798da50f4..ca1b86c2d 100644 --- a/app/routes/forum/categories/category/threads/thread/posts/edit.js +++ b/app/routes/forum/categories/category/threads/thread/posts/edit.js @@ -13,6 +13,6 @@ export default class EditPostRoute extends AuthenticatedRoute { deactivate() { super.deactivate(); - this.controller.model.thread?.rollbackAttributes(); + this.controller.model.rollbackAttributes(); } } diff --git a/app/templates/articles/edit.hbs b/app/templates/articles/edit.hbs index f01658f23..f4cf3818c 100644 --- a/app/templates/articles/edit.hbs +++ b/app/templates/articles/edit.hbs @@ -5,6 +5,7 @@
\ No newline at end of file diff --git a/app/templates/books/edit.hbs b/app/templates/books/edit.hbs index 378cf0a66..08ad373fe 100644 --- a/app/templates/books/edit.hbs +++ b/app/templates/books/edit.hbs @@ -11,6 +11,7 @@ @lookupIsbnError={{this.lookupIsbnError}} @errorMessage={{this.errorMessage}} @onSubmit={{action 'submit'}} + @onCancel={{action 'cancel'}} @onToggleScanner={{action 'toggleScanner'}} @onDevicesFound={{action 'onDevicesFound'}} @onScanSuccess={{action 'onScanSuccess'}} diff --git a/app/templates/debit/mandates/edit.hbs b/app/templates/debit/mandates/edit.hbs index 198b5cba0..a3a15eb5b 100644 --- a/app/templates/debit/mandates/edit.hbs +++ b/app/templates/debit/mandates/edit.hbs @@ -3,6 +3,7 @@ \ No newline at end of file diff --git a/app/templates/debit/mandates/new.hbs b/app/templates/debit/mandates/new.hbs index 2e243460c..715f527e8 100644 --- a/app/templates/debit/mandates/new.hbs +++ b/app/templates/debit/mandates/new.hbs @@ -3,6 +3,7 @@ \ No newline at end of file diff --git a/app/templates/forum/categories/category/edit.hbs b/app/templates/forum/categories/category/edit.hbs index b79838a2e..0005c2a9f 100644 --- a/app/templates/forum/categories/category/edit.hbs +++ b/app/templates/forum/categories/category/edit.hbs @@ -1,5 +1,6 @@ \ No newline at end of file diff --git a/app/templates/forum/categories/category/threads/thread/posts/edit.hbs b/app/templates/forum/categories/category/threads/thread/posts/edit.hbs index 4a5a07983..07604a864 100644 --- a/app/templates/forum/categories/category/threads/thread/posts/edit.hbs +++ b/app/templates/forum/categories/category/threads/thread/posts/edit.hbs @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/app/templates/forum/categories/new.hbs b/app/templates/forum/categories/new.hbs index b79838a2e..0005c2a9f 100644 --- a/app/templates/forum/categories/new.hbs +++ b/app/templates/forum/categories/new.hbs @@ -1,5 +1,6 @@ \ No newline at end of file diff --git a/app/templates/groups/edit.hbs b/app/templates/groups/edit.hbs index 9644b420b..c624513ab 100644 --- a/app/templates/groups/edit.hbs +++ b/app/templates/groups/edit.hbs @@ -1,6 +1,7 @@ \ No newline at end of file diff --git a/app/templates/photo-albums/photo-album/edit.hbs b/app/templates/photo-albums/photo-album/edit.hbs index 830ac401d..e5fe92e0b 100644 --- a/app/templates/photo-albums/photo-album/edit.hbs +++ b/app/templates/photo-albums/photo-album/edit.hbs @@ -1,6 +1,7 @@ \ No newline at end of file diff --git a/app/templates/static-pages/edit.hbs b/app/templates/static-pages/edit.hbs index 00b21a964..24b20a3f1 100644 --- a/app/templates/static-pages/edit.hbs +++ b/app/templates/static-pages/edit.hbs @@ -1,6 +1,7 @@ \ No newline at end of file diff --git a/app/templates/static-pages/new.hbs b/app/templates/static-pages/new.hbs index 00b21a964..24b20a3f1 100644 --- a/app/templates/static-pages/new.hbs +++ b/app/templates/static-pages/new.hbs @@ -1,6 +1,7 @@ \ No newline at end of file diff --git a/app/utils/model-save.js b/app/utils/model-save.js index a8fd72b60..5fdbf6d98 100644 --- a/app/utils/model-save.js +++ b/app/utils/model-save.js @@ -10,8 +10,15 @@ export default class ModelSaveUtil { } } + sendCancel() { + if (!isNone(this.entity?.cancelMessage)) { + this.entity?.flashNotice?.sendInfo(this.entity.cancelMessage); + } + } + transition(target, model) { - const transition_args = model ? [target, model] : [target] + target = target ?? 'index'; + const transition_args = model ? [target, model] : [target]; if (this.entity.transition) { this.entity.transition(...transition_args); } else { @@ -46,7 +53,16 @@ export default class ModelSaveUtil { this.entity.onSuccess(model); } else { // Redirect - this.redirectSuccess(model) + this.redirectSuccess(model); + } + } + + onCancel() { + this.sendCancel(); + if (this.entity?.onCancel) { + this.entity.onCancel(); + } else { + this.redirectCancel(); } } @@ -58,30 +74,27 @@ export default class ModelSaveUtil { } } - saveModel(model) { + async saveModel(model) { this.entity.errorMessage = null; if (!isNone(model)) { - model - .save() - .then((savedModel) => { - this.onSuccess(savedModel); - }) - .catch((error) => { - this.onError(error); - }); + try { + const savedModel = await model.save() + this.onSuccess(savedModel); + } catch (error) { + this.onError(error); + } } } - saveModelWithForm(model) { + async saveModelWithForm(model) { this.entity.errorMessage = null; if (!isNone(model)) { - model.saveWithForm() - .then((savedModel) => { - this.onSuccess(savedModel); - }) - .catch((error) => { - this.onError(error); - }); + try { + const savedModel = await model.saveWithForm(); + this.onSuccess(savedModel); + } catch (error) { + this.onError(error); + } } } @@ -100,6 +113,6 @@ export default class ModelSaveUtil { cancelEdit() { this.entity.errorMessage = null; - this.redirectCancel(); + this.onCancel(); } } From 5393cfa01260320b41107cf408db77e5abd02820 Mon Sep 17 00:00:00 2001 From: matteo Date: Sat, 3 Sep 2022 18:35:06 +0200 Subject: [PATCH 11/40] jslint --- app/controllers/activities/destroy.js | 2 -- app/controllers/activities/edit.js | 3 +-- app/controllers/application/destroy.js | 10 +++----- app/controllers/application/edit.js | 5 ++-- app/controllers/application/new.js | 2 +- app/controllers/article-comments/destroy.js | 1 - app/controllers/debit/collections/new.js | 1 - app/controllers/form/responses/destroy.js | 1 + .../forum/categories/category/destroy.js | 2 +- .../forum/categories/category/threads/new.js | 1 - .../category/threads/thread/edit.js | 2 -- app/controllers/groups/edit.js | 18 ++++++------- app/controllers/photo-albums/new.js | 2 -- .../photo-albums/photo-album/edit.js | 10 +++----- app/controllers/photo-comments/destroy.js | 1 - app/controllers/polls/edit.js | 2 +- app/controllers/static-pages/edit.js | 2 -- app/models/forum/thread.js | 2 +- app/routes/debit/collections/show.js | 4 +-- .../category/threads/thread/edit.js | 4 ++- app/utils/model-save.js | 25 ++++++++----------- 21 files changed, 39 insertions(+), 61 deletions(-) diff --git a/app/controllers/activities/destroy.js b/app/controllers/activities/destroy.js index 7ccd36287..563f7d948 100644 --- a/app/controllers/activities/destroy.js +++ b/app/controllers/activities/destroy.js @@ -3,5 +3,3 @@ import DestroyController from 'amber-ui/controllers/application/destroy'; export default class ActivityDestroyController extends DestroyController { successTransitionTarget = 'activities.index'; } - - diff --git a/app/controllers/activities/edit.js b/app/controllers/activities/edit.js index f1d5bfe30..2c617a93a 100644 --- a/app/controllers/activities/edit.js +++ b/app/controllers/activities/edit.js @@ -1,12 +1,11 @@ // eslint-disable-next-line ember/no-computed-properties-in-native-classes import { action, computed } from '@ember/object'; import { ActivityCategories } from 'amber-ui/constants'; -import Controller from '@ember/controller'; import { isNone } from '@ember/utils'; import { inject as service } from '@ember/service'; // eslint-disable-next-line ember/no-computed-properties-in-native-classes import { union } from '@ember/object/computed'; -import EditController from "../application/edit"; +import EditController from '../application/edit'; //todo: refactor below class to extend EditController export default class EditActivityController extends EditController { diff --git a/app/controllers/application/destroy.js b/app/controllers/application/destroy.js index 1d58b4f09..f0ff994a6 100644 --- a/app/controllers/application/destroy.js +++ b/app/controllers/application/destroy.js @@ -1,7 +1,6 @@ import EditController from 'amber-ui/controllers/application/edit'; import { action } from '@ember/object'; -import {tracked} from '@glimmer/tracking'; - +import { tracked } from '@glimmer/tracking'; export default class DestroyController extends EditController { successMessage = 'Verwijderen gelukt!'; @@ -17,14 +16,13 @@ export default class DestroyController extends EditController { onError(error) { // todo: somehow incorporate the error into the message maybe? could be useful if users can show us the error message - this.errorMessage = 'Er ging iets fout bij het verwijderen.' - this.errorMessage += error + this.errorMessage = 'Er ging iets fout bij het verwijderen.'; + this.errorMessage += error; } transition() { - this.replaceRoute(...arguments) + this.replaceRoute(...arguments); } submit = undefined; - } diff --git a/app/controllers/application/edit.js b/app/controllers/application/edit.js index e522d7142..67ec3aa50 100644 --- a/app/controllers/application/edit.js +++ b/app/controllers/application/edit.js @@ -12,7 +12,7 @@ export default class EditController extends Controller { cancelMessage = 'Wijzigen geannuleerd.'; @tracked successTransitionTarget = null; @tracked successTransitionModel = this.model; - @tracked cancelTransitionTarget = this.successTransitionTarget; // sensible default + @tracked cancelTransitionTarget = this.successTransitionTarget; // sensible default @tracked cancelTransitionModel = this.model; constructor() { @@ -27,7 +27,8 @@ export default class EditController extends Controller { onError(error) { // todo: somehow incorporate the error into the message maybe? could be useful if users can show us the error message - this.errorMessage = 'Er ging iets fout bij het opslaan van je wijzigingen. ' + error + this.errorMessage = + 'Er ging iets fout bij het opslaan van je wijzigingen. ' + error; } @action diff --git a/app/controllers/application/new.js b/app/controllers/application/new.js index a3fcd19f9..02cd746c0 100644 --- a/app/controllers/application/new.js +++ b/app/controllers/application/new.js @@ -3,6 +3,6 @@ import EditController from 'amber-ui/controllers/application/edit'; export default class NewController extends EditController { successMessage = 'Aanmaken gelukt!'; cancelMessage = 'Aanmaken geannuleerd.'; - cancelTransitionTarget = null; // default should not be successTransitionTarget, in contrast to the edit controller + cancelTransitionTarget = null; // default should not be successTransitionTarget, in contrast to the edit controller cancelTransitionModel = null; } diff --git a/app/controllers/article-comments/destroy.js b/app/controllers/article-comments/destroy.js index 9bae88114..fa8f8bffb 100644 --- a/app/controllers/article-comments/destroy.js +++ b/app/controllers/article-comments/destroy.js @@ -9,5 +9,4 @@ export default class ArticleCommentDestroyController extends DestroyController { this.successTransitionModel = await this.model.article; super.destroyModel(); } - } diff --git a/app/controllers/debit/collections/new.js b/app/controllers/debit/collections/new.js index 4ff448270..d344361db 100644 --- a/app/controllers/debit/collections/new.js +++ b/app/controllers/debit/collections/new.js @@ -1,4 +1,3 @@ -import { alias } from '@ember/object/computed'; import EmberArray from '@ember/array'; import { action } from '@ember/object'; import EditController from 'amber-ui/controllers/application/edit'; diff --git a/app/controllers/form/responses/destroy.js b/app/controllers/form/responses/destroy.js index 556521289..620bd7675 100644 --- a/app/controllers/form/responses/destroy.js +++ b/app/controllers/form/responses/destroy.js @@ -12,6 +12,7 @@ export default class FormResponseDestroyController extends DestroyController { this.form = await this.model.form; super.destroyModel(); } + onSuccess(model) { this.form.reload(); this.modelSaveUtil.redirectSuccess(model); diff --git a/app/controllers/forum/categories/category/destroy.js b/app/controllers/forum/categories/category/destroy.js index da50af3c3..eef0eed16 100644 --- a/app/controllers/forum/categories/category/destroy.js +++ b/app/controllers/forum/categories/category/destroy.js @@ -2,5 +2,5 @@ import DestroyController from 'amber-ui/controllers/application/destroy'; export default class ForumCategoryDestroyController extends DestroyController { successMessage = 'Categorie verwijderd!'; - successTransitionTarget ='forum.index'; + successTransitionTarget = 'forum.index'; } diff --git a/app/controllers/forum/categories/category/threads/new.js b/app/controllers/forum/categories/category/threads/new.js index 852887e34..0ea06caa9 100644 --- a/app/controllers/forum/categories/category/threads/new.js +++ b/app/controllers/forum/categories/category/threads/new.js @@ -10,7 +10,6 @@ export default class NewThreadController extends NewController { cancelTransitionTarget = 'forum.categories.category.show'; cancelTransitionModel = this.model?.thread?.category; - content = ''; @action diff --git a/app/controllers/forum/categories/category/threads/thread/edit.js b/app/controllers/forum/categories/category/threads/thread/edit.js index d8e8b4d21..97704fe21 100644 --- a/app/controllers/forum/categories/category/threads/thread/edit.js +++ b/app/controllers/forum/categories/category/threads/thread/edit.js @@ -1,8 +1,6 @@ import EditController from 'amber-ui/controllers/application/edit'; -import { action } from '@ember/object'; export default class EditThreadController extends EditController { successMessage = 'Topic aangepast!'; successTransitionTarget = 'forum.categories.category.threads.thread.show'; - } diff --git a/app/controllers/groups/edit.js b/app/controllers/groups/edit.js index eb4deb426..8ad68651a 100644 --- a/app/controllers/groups/edit.js +++ b/app/controllers/groups/edit.js @@ -1,12 +1,11 @@ // eslint-disable-next-line ember/no-computed-properties-in-native-classes -import {action, computed} from '@ember/object'; -import {A} from '@ember/array'; -import Controller from '@ember/controller'; -import {GroupKinds} from 'amber-ui/constants'; -import {all} from 'rsvp'; -import {capitalize} from '@ember/string'; -import {inject as service} from '@ember/service'; -import EditController from "../application/edit"; +import { action } from '@ember/object'; +import { A } from '@ember/array'; +import { GroupKinds } from 'amber-ui/constants'; +import { all } from 'rsvp'; +import { capitalize } from '@ember/string'; +import { inject as service } from '@ember/service'; +import EditController from '../application/edit'; export default class EditGroupController extends EditController { @service session; @@ -57,7 +56,7 @@ export default class EditGroupController extends EditController { this.model.get('memberships').map((membership) => { if (membership.get('hasDirtyAttributes')) { return membership.save().catch((error) => { - membershipErrors.push({membership, error}); + membershipErrors.push({ membership, error }); failedMembershipSavings++; }); } @@ -81,7 +80,6 @@ export default class EditGroupController extends EditController { } else { this.modelSaveUtil.onSuccess(savedModel); } - } catch (error) { this.errorMessage = error.message; } diff --git a/app/controllers/photo-albums/new.js b/app/controllers/photo-albums/new.js index 589d5e5b7..c16c1994e 100644 --- a/app/controllers/photo-albums/new.js +++ b/app/controllers/photo-albums/new.js @@ -1,6 +1,5 @@ import NewController from 'amber-ui/controllers/application/new'; // eslint-disable-next-line ember/no-computed-properties-in-native-classes -import { computed } from '@ember/object'; import { inject as service } from '@ember/service'; export default class NewPhotoAlbumController extends NewController { @@ -11,7 +10,6 @@ export default class NewPhotoAlbumController extends NewController { successTransitionTarget = 'photo-albums.photo-album.edit'; cancelTransitionTarget = 'photo-albums.index'; - get groups() { if (this.abilities.can('select all groups for photo-albums')) { return this.store.findAll('group'); diff --git a/app/controllers/photo-albums/photo-album/edit.js b/app/controllers/photo-albums/photo-album/edit.js index b6f19559e..8170fd416 100644 --- a/app/controllers/photo-albums/photo-album/edit.js +++ b/app/controllers/photo-albums/photo-album/edit.js @@ -1,8 +1,5 @@ -// eslint-disable-next-line ember/no-computed-properties-in-native-classes -import { action, computed } from '@ember/object'; import { inject as service } from '@ember/service'; -import EditController from "../../application/edit"; -import NewPhotoAlbumController from "../new"; +import NewPhotoAlbumController from '../new'; export default class EditPhotoAlbumController extends NewPhotoAlbumController { successMessage = "Wijzigen en/of foto's toevoegen gelukt!"; @@ -12,8 +9,7 @@ export default class EditPhotoAlbumController extends NewPhotoAlbumController { cancelTransitionModel = this.model; @service fetch; - @computed(function () { + get dropzoneHeaders() { return { Authorization: this.fetch.authorizationHeader() }; - }) - dropzoneHeaders; + } } diff --git a/app/controllers/photo-comments/destroy.js b/app/controllers/photo-comments/destroy.js index 325275038..dfbcf3338 100644 --- a/app/controllers/photo-comments/destroy.js +++ b/app/controllers/photo-comments/destroy.js @@ -9,5 +9,4 @@ export default class PhotoCommentDestroyController extends DestroyController { this.successTransitionModel = await this.model.photo.get('photoAlbum'); super.destroyModel(); } - } diff --git a/app/controllers/polls/edit.js b/app/controllers/polls/edit.js index 0becbbc18..a117a8dd7 100644 --- a/app/controllers/polls/edit.js +++ b/app/controllers/polls/edit.js @@ -1,6 +1,5 @@ import EditController from '../application/edit'; import { action } from '@ember/object'; -import { inject as service } from '@ember/service'; // eslint-disable-next-line ember/no-computed-properties-in-native-classes import { union } from '@ember/object/computed'; @@ -12,6 +11,7 @@ export default class EditPollController extends EditController { async submit() { await this.modelSaveUtil.saveModelWithForm(this.model); } + @union('model.errors', 'model.form.errors') combinedErrors; } diff --git a/app/controllers/static-pages/edit.js b/app/controllers/static-pages/edit.js index 00a99da0d..7d5633991 100644 --- a/app/controllers/static-pages/edit.js +++ b/app/controllers/static-pages/edit.js @@ -1,8 +1,6 @@ import EditController from 'amber-ui/controllers/application/edit'; import { StaticPageCategories } from 'amber-ui/constants'; import { capitalize } from '@ember/string'; -// eslint-disable-next-line ember/no-computed-properties-in-native-classes -import { computed } from '@ember/object'; export default class EditStaticPageController extends EditController { successMessage = 'Infopagina aangepast!'; diff --git a/app/models/forum/thread.js b/app/models/forum/thread.js index 6cee9028d..8e62b7cf0 100644 --- a/app/models/forum/thread.js +++ b/app/models/forum/thread.js @@ -34,6 +34,6 @@ export default class Thread extends Model { this.rollbackAttributes(); this.posts.forEach((post) => { post.rollbackAttributes(); - }) + }); } } diff --git a/app/routes/debit/collections/show.js b/app/routes/debit/collections/show.js index 605048041..c56f004e1 100644 --- a/app/routes/debit/collections/show.js +++ b/app/routes/debit/collections/show.js @@ -1,6 +1,4 @@ import { AuthenticatedRoute } from 'amber-ui/routes/application/application'; -import { assign } from '@ember/polyfills'; -import { hash } from 'rsvp'; export default class CollectionsIndexRoute extends AuthenticatedRoute { get breadCrumb() { @@ -41,7 +39,7 @@ export default class CollectionsIndexRoute extends AuthenticatedRoute { async model(params) { const collection = await this.store.findRecord( 'debit/collection', - params.id, + params.id ); const transactions = collection.transactions; // todo: simplify this to just returning collection, because transactions can be gotten from the collection, right? diff --git a/app/routes/forum/categories/category/threads/thread/edit.js b/app/routes/forum/categories/category/threads/thread/edit.js index 0e69256c3..2662be6f3 100644 --- a/app/routes/forum/categories/category/threads/thread/edit.js +++ b/app/routes/forum/categories/category/threads/thread/edit.js @@ -8,7 +8,9 @@ export default class EditTopicRoute extends AuthenticatedRoute { } async model() { - const thread = await this.modelFor('forum.categories.category.threads.thread'); + const thread = await this.modelFor( + 'forum.categories.category.threads.thread' + ); return thread; } diff --git a/app/utils/model-save.js b/app/utils/model-save.js index 5fdbf6d98..1330c1b14 100644 --- a/app/utils/model-save.js +++ b/app/utils/model-save.js @@ -18,31 +18,25 @@ export default class ModelSaveUtil { transition(target, model) { target = target ?? 'index'; - const transition_args = model ? [target, model] : [target]; + const transitionArgs = model ? [target, model] : [target]; if (this.entity.transition) { - this.entity.transition(...transition_args); + this.entity.transition(...transitionArgs); } else { - this.entity.transitionToRoute(...transition_args); + this.entity.transitionToRoute(...transitionArgs); } } redirectSuccess(model) { const targetModel = this.entity?.successTransitionModel ?? model; if (!isNone(this.entity?.successTransitionTarget)) { - this.transition( - this.entity.successTransitionTarget, - targetModel?.id, - ); + this.transition(this.entity.successTransitionTarget, targetModel?.id); } } redirectCancel() { const targetModel = this.entity?.cancelTransitionModel; if (!isNone(this.entity?.cancelTransitionTarget)) { - this.transition( - this.entity.cancelTransitionTarget, - targetModel?.id, - ) + this.transition(this.entity.cancelTransitionTarget, targetModel?.id); } } @@ -70,7 +64,9 @@ export default class ModelSaveUtil { if (this.entity?.onError) { this.entity.onError(error); } else { - this.entity.errorMessage = error.errors.map((err) => err.detail).join(', '); + this.entity.errorMessage = error.errors + .map((err) => err.detail) + .join(', '); } } @@ -78,7 +74,7 @@ export default class ModelSaveUtil { this.entity.errorMessage = null; if (!isNone(model)) { try { - const savedModel = await model.save() + const savedModel = await model.save(); this.onSuccess(savedModel); } catch (error) { this.onError(error); @@ -101,7 +97,8 @@ export default class ModelSaveUtil { destroyModel(model) { this.entity.errorMessage = null; if (!isNone(model)) { - model.destroyRecord() + model + .destroyRecord() .then(() => { this.onSuccess(null); }) From 2dd9e231014f4924464af1585338dba7cbc12d76 Mon Sep 17 00:00:00 2001 From: matteo Date: Sat, 3 Sep 2022 22:03:43 +0200 Subject: [PATCH 12/40] FINALLY figured out how to do a union of ObjectProxies --- app/controllers/activities/edit.js | 10 +++++----- app/controllers/polls/edit.js | 9 +++++---- app/utils/array-operations.js | 4 ++++ 3 files changed, 14 insertions(+), 9 deletions(-) create mode 100644 app/utils/array-operations.js diff --git a/app/controllers/activities/edit.js b/app/controllers/activities/edit.js index 2c617a93a..484f952ee 100644 --- a/app/controllers/activities/edit.js +++ b/app/controllers/activities/edit.js @@ -4,8 +4,8 @@ import { ActivityCategories } from 'amber-ui/constants'; import { isNone } from '@ember/utils'; import { inject as service } from '@ember/service'; // eslint-disable-next-line ember/no-computed-properties-in-native-classes -import { union } from '@ember/object/computed'; import EditController from '../application/edit'; +import { union } from '../../utils/array-operations'; //todo: refactor below class to extend EditController export default class EditActivityController extends EditController { @@ -21,10 +21,10 @@ export default class EditActivityController extends EditController { label: activityCategory, }; } - - // todo: do we want to get rid of @union ? idk how to octane this - @union('model.errors', 'model.form.errors') - combinedErrors; + get combinedErrors() { + const combined = union(this.model.errors.content, this.model.form?.get('errors')?.content); + return combined.length > 0 ? combined : null; + } // todo: refactor computed @computed('model.form.content', { diff --git a/app/controllers/polls/edit.js b/app/controllers/polls/edit.js index a117a8dd7..a8ffab65b 100644 --- a/app/controllers/polls/edit.js +++ b/app/controllers/polls/edit.js @@ -1,7 +1,6 @@ import EditController from '../application/edit'; import { action } from '@ember/object'; -// eslint-disable-next-line ember/no-computed-properties-in-native-classes -import { union } from '@ember/object/computed'; +import { union } from '../../utils/array-operations'; export default class EditPollController extends EditController { successMessage = 'Poll opgeslagen!'; @@ -12,6 +11,8 @@ export default class EditPollController extends EditController { await this.modelSaveUtil.saveModelWithForm(this.model); } - @union('model.errors', 'model.form.errors') - combinedErrors; + get combinedErrors() { + const combined = union(this.model.errors.content, this.model.form?.get('errors')?.content); + return combined.length > 0 ? combined : null; + } } diff --git a/app/utils/array-operations.js b/app/utils/array-operations.js new file mode 100644 index 000000000..4acc76259 --- /dev/null +++ b/app/utils/array-operations.js @@ -0,0 +1,4 @@ +export function union() { + const uniques = new Set([...arguments].reduce((a,b) => [...a, ...(b ?? [])], [])); + return [...uniques]; +} From 8c407d53671dc87eb43ae7d70040e8f561388fe5 Mon Sep 17 00:00:00 2001 From: matteo Date: Sat, 3 Sep 2022 23:04:19 +0200 Subject: [PATCH 13/40] moved thread save logic to model --- app/components/forms/thread-form.hbs | 19 +++------- .../forum/categories/category/threads/new.js | 36 ++++--------------- app/models/forum/thread.js | 15 +++++++- .../forum/categories/category/threads/new.js | 4 +-- .../forum/categories/category/threads/new.hbs | 1 + .../category/threads/thread/edit.hbs | 1 + 6 files changed, 29 insertions(+), 47 deletions(-) diff --git a/app/components/forms/thread-form.hbs b/app/components/forms/thread-form.hbs index bf93da928..5dd2ff5ad 100644 --- a/app/components/forms/thread-form.hbs +++ b/app/components/forms/thread-form.hbs @@ -11,7 +11,7 @@ @required={{true}} /> - {{#if @model.firstPost }} + {{#if @model.isNew }} - {{#if @model.isNew}} - Annuleren - - {{else}} - - Annuleren - - {{/if}} +
diff --git a/app/controllers/forum/categories/category/threads/new.js b/app/controllers/forum/categories/category/threads/new.js index 0ea06caa9..498f6cdf6 100644 --- a/app/controllers/forum/categories/category/threads/new.js +++ b/app/controllers/forum/categories/category/threads/new.js @@ -4,43 +4,19 @@ import { isNone } from '@ember/utils'; import { inject as service } from '@ember/service'; export default class NewThreadController extends NewController { - @service('flash-notice') flashNotice; successTransitionTarget = 'forum.categories.category.threads.thread.show'; cancelTransitionTarget = 'forum.categories.category.show'; - cancelTransitionModel = this.model?.thread?.category; - - content = ''; - - @action - onSuccess(savedModel) { - // Reload thread to update thread.amountOfPosts - savedModel.reload(); - // Reload category to update category.amountOfThreads - savedModel.category.reload(); - // redirect - this.modelSaveUtil.redirectSuccess(savedModel); - } + cancelTransitionModel = this.model?.category; @action async submit() { this.errorMessage = null; - const thread = await this.model; - const post = thread.firstPost; - - if (isNone(post.message)) { - this.set('errorMessage', 'Je moet eerst een bericht aanmaken'); - return; - } - - if (!isNone(thread)) { - try { - const savedModel = await thread.save(); - await post.save(); - this.onSuccess(savedModel); - } catch (error) { - this.modelSaveUtil.onError(error); - } + try { + const savedModel = await this.model.saveWithFirstPost(); + this.modelSaveUtil.onSuccess(savedModel); + } catch (error) { + this.modelSaveUtil.onError(error); } } } diff --git a/app/models/forum/thread.js b/app/models/forum/thread.js index 8e62b7cf0..c636f8ee7 100644 --- a/app/models/forum/thread.js +++ b/app/models/forum/thread.js @@ -1,4 +1,5 @@ import Model, { belongsTo, hasMany, attr } from '@ember-data/model'; +import { isNone } from '@ember/utils'; export default class Thread extends Model { // Properties @@ -15,7 +16,7 @@ export default class Thread extends Model { @hasMany('forum/post') posts; get firstPost() { - return this.posts.length > 0 ? this.posts[0] : null; + return this.posts.get('firstObject'); } get isOpen() { @@ -30,6 +31,18 @@ export default class Thread extends Model { } } + async saveWithFirstPost() { + const post = await this.firstPost; + if (isNone(post.message)) { + throw new Error('Je moet eerst een bericht invullen.'); + } else { + const response = await this.save(); + const firstPost = await response.firstPost; + await firstPost.save(); + return response; + } + } + rollbackAttributesAndPosts() { this.rollbackAttributes(); this.posts.forEach((post) => { diff --git a/app/routes/forum/categories/category/threads/new.js b/app/routes/forum/categories/category/threads/new.js index a989cdcd1..4ddd41ac6 100644 --- a/app/routes/forum/categories/category/threads/new.js +++ b/app/routes/forum/categories/category/threads/new.js @@ -10,8 +10,8 @@ export default class NewTopicRoute extends AuthenticatedRoute { async model() { const category = this.modelFor('forum.categories.category'); const thread = await this.store.createRecord('forum/thread', { category }); - const post = await this.store.createRecord('forum/post', { thread }); - post.reload(); // hoping this updates thread.posts? + await this.store.createRecord('forum/post', { thread }); + // the post created above can magically be accessed via the thread model return thread; } diff --git a/app/templates/forum/categories/category/threads/new.hbs b/app/templates/forum/categories/category/threads/new.hbs index 94fa22309..5a888472b 100644 --- a/app/templates/forum/categories/category/threads/new.hbs +++ b/app/templates/forum/categories/category/threads/new.hbs @@ -1,5 +1,6 @@ \ No newline at end of file diff --git a/app/templates/forum/categories/category/threads/thread/edit.hbs b/app/templates/forum/categories/category/threads/thread/edit.hbs index 94fa22309..5a888472b 100644 --- a/app/templates/forum/categories/category/threads/thread/edit.hbs +++ b/app/templates/forum/categories/category/threads/thread/edit.hbs @@ -1,5 +1,6 @@ \ No newline at end of file From 29e8f507c4c814af1574801cc40d920644ff026b Mon Sep 17 00:00:00 2001 From: matteo Date: Sun, 4 Sep 2022 01:33:13 +0200 Subject: [PATCH 14/40] more stuff --- app/components/forms/transaction-form.hbs | 4 +- app/components/forms/user-form.hbs | 4 +- app/components/forum/forum-post-new.js | 3 +- app/components/users/privacy-settings.hbs | 6 +- app/components/users/privacy-settings.js | 5 - app/controllers/activities/destroy.js | 1 + app/controllers/application/edit.js | 2 +- app/controllers/debit/transactions/edit.js | 20 +-- app/controllers/users/batch/new.js | 145 +++++++++++---------- app/controllers/users/edit-permissions.js | 8 +- app/controllers/users/edit-privacy.js | 4 + app/controllers/users/edit.js | 21 ++- app/controllers/users/new.js | 3 + app/routes/users/edit.js | 4 +- app/templates/activities/destroy.hbs | 8 +- app/templates/article-comments/destroy.hbs | 8 +- app/templates/debit/transactions/edit.hbs | 1 + app/templates/users/edit-permissions.hbs | 8 +- app/templates/users/edit-privacy.hbs | 2 +- app/templates/users/edit.hbs | 1 + app/templates/users/new.hbs | 1 + 21 files changed, 137 insertions(+), 122 deletions(-) create mode 100644 app/controllers/users/edit-privacy.js diff --git a/app/components/forms/transaction-form.hbs b/app/components/forms/transaction-form.hbs index 64956be86..d25208572 100644 --- a/app/components/forms/transaction-form.hbs +++ b/app/components/forms/transaction-form.hbs @@ -36,9 +36,9 @@ - + diff --git a/app/components/forms/user-form.hbs b/app/components/forms/user-form.hbs index 62ba5a11d..a1dd04a49 100644 --- a/app/components/forms/user-form.hbs +++ b/app/components/forms/user-form.hbs @@ -170,8 +170,8 @@ @errorMessage={{@errorMessage}} @inputLayout='vertical' > - + \ No newline at end of file diff --git a/app/components/forum/forum-post-new.js b/app/components/forum/forum-post-new.js index 6cd0f08c9..1a305eb86 100644 --- a/app/components/forum/forum-post-new.js +++ b/app/components/forum/forum-post-new.js @@ -2,9 +2,10 @@ import { inject as service } from '@ember/service'; import Component from '@ember/component'; import { action } from '@ember/object'; +// todo: incorporate the model-save-util into components? export default class ForumPostNewComponent extends Component { @service store; - @service('flash-notice') flashNotice; + @service flashNotice; @action save() { diff --git a/app/components/users/privacy-settings.hbs b/app/components/users/privacy-settings.hbs index 819c308ba..3da63404b 100644 --- a/app/components/users/privacy-settings.hbs +++ b/app/components/users/privacy-settings.hbs @@ -1,5 +1,5 @@
Privacyinstellingen
-
+ {{#if isOwnUser}}
\ No newline at end of file diff --git a/app/templates/debit/transactions/edit.hbs b/app/templates/debit/transactions/edit.hbs index 94b9d9b54..35bf3c01d 100644 --- a/app/templates/debit/transactions/edit.hbs +++ b/app/templates/debit/transactions/edit.hbs @@ -3,6 +3,7 @@ - Annuleren - + \ No newline at end of file diff --git a/app/templates/users/edit-privacy.hbs b/app/templates/users/edit-privacy.hbs index 1acccc0da..686ec8c39 100644 --- a/app/templates/users/edit-privacy.hbs +++ b/app/templates/users/edit-privacy.hbs @@ -1,3 +1,3 @@ - + \ No newline at end of file diff --git a/app/templates/users/edit.hbs b/app/templates/users/edit.hbs index 00a613e70..70c5cd7c5 100644 --- a/app/templates/users/edit.hbs +++ b/app/templates/users/edit.hbs @@ -2,6 +2,7 @@ Date: Tue, 6 Sep 2022 17:52:30 +0200 Subject: [PATCH 15/40] fix debit collection controllers --- app/controllers/article-comments/destroy.js | 7 ++ app/controllers/articles/destroy.js | 1 + app/controllers/debit/collections/edit.js | 83 +++++++------------ app/controllers/debit/transactions/destroy.js | 11 ++- app/models/debit/collection.js | 22 ++++- app/routes/debit/collections/show.js | 11 +-- app/templates/articles/destroy.hbs | 4 +- app/templates/debit/collections/edit.hbs | 4 +- app/templates/debit/collections/show.hbs | 6 +- 9 files changed, 80 insertions(+), 69 deletions(-) diff --git a/app/controllers/article-comments/destroy.js b/app/controllers/article-comments/destroy.js index fa8f8bffb..377af6f76 100644 --- a/app/controllers/article-comments/destroy.js +++ b/app/controllers/article-comments/destroy.js @@ -4,9 +4,16 @@ import { action } from '@ember/object'; export default class ArticleCommentDestroyController extends DestroyController { successMessage = 'Artikelreactie verwijderd!'; successTransitionTarget = 'articles.show'; + cancelTransitionTarget = 'articles.show'; @action async destroyModel() { this.successTransitionModel = await this.model.article; super.destroyModel(); } + + @action + async cancel() { + this.cancelTransitionModel = await this.model.article; + super.cancel(); + } } diff --git a/app/controllers/articles/destroy.js b/app/controllers/articles/destroy.js index eb2dfde5b..8180029e9 100644 --- a/app/controllers/articles/destroy.js +++ b/app/controllers/articles/destroy.js @@ -2,4 +2,5 @@ import DestroyController from 'amber-ui/controllers/application/destroy'; export default class ArticleDestroyController extends DestroyController { successTransitionTarget = 'articles.index'; + cancelTransitionTarget = 'articles.show'; } diff --git a/app/controllers/debit/collections/edit.js b/app/controllers/debit/collections/edit.js index 41621d0c5..2a46a8000 100644 --- a/app/controllers/debit/collections/edit.js +++ b/app/controllers/debit/collections/edit.js @@ -1,57 +1,34 @@ -import { computed } from '@ember/object'; -import { all } from 'rsvp'; -import { isNone } from '@ember/utils'; +import { action } from '@ember/object'; import EditController from 'amber-ui/controllers/application/edit'; -export default EditController.extend({ - successMessage: 'Incasso aangepast!', - users: computed('store', function () { +export default class DebitCollectionEditController extends EditController { + successMessage = 'Incasso aangepast!'; + cancelMessage = 'Incasso aanpassen geannuleerd.'; + successTransitionTarget = 'debit.collections.show'; + + get users() { return this.store.findAll('user'); - }), - actions: { - addUser(user) { - this.model - .get('transactions') - .pushObject(this.store.createRecord('debit/transaction', { user })); - }, - removeTransaction(transaction) { - transaction.deleteRecord(); - }, - submit() { - const collection = this.model; - this.set('errorMessage', null); + } - if (!isNone(collection)) { - let failedTransactions = 0; - collection - .save() - .then(() => { - return all( - collection.get('transactions').map((transaction) => { - if (transaction.get('hasDirtyAttributes')) { - return transaction.save().catch(() => { - failedTransactions++; - }); - } - }) - ); - }) - .then(() => { - if (failedTransactions) { - const prefix = failedTransactions > 1 ? 'zijn' : 'is'; - this.set( - 'errorMessage', - `Er ${prefix} ${failedTransactions} transacties niet juist opgeslagen` - ); - } else { - this.flashNotice.sendSuccess('Incasso aangepast!'); - this.transitionToRoute('debit.collections.show', collection.id); - } - }) - .catch((error) => { - this.set('errorMessage', error.message); - }); - } - }, - }, -}); + @action + addUser(user) { + this.model + .get('transactions') + .pushObject(this.store.createRecord('debit/transaction', { user })); + } + @action + removeTransaction(transaction) { + // todo: refactor this to be more in accordance with how we do deletions (such as showing feedback with the flash notice) + transaction.deleteRecord(); + } + @action + async submit() { + this.errorMessage = null; + try { + const savedModel = await this.model.saveWithTransactions(); + this.modelSaveUtil.onSuccess(savedModel); + } catch (error) { + this.modelSaveUtil.onError(error); + } + } +} diff --git a/app/controllers/debit/transactions/destroy.js b/app/controllers/debit/transactions/destroy.js index 905e8ebd7..a367c535f 100644 --- a/app/controllers/debit/transactions/destroy.js +++ b/app/controllers/debit/transactions/destroy.js @@ -1,5 +1,14 @@ import DestroyController from 'amber-ui/controllers/application/destroy'; +import { action } from '@ember/object'; export default class DebitTransactionDestroyController extends DestroyController { - successTransitionTarget = 'debit.collections'; + successTransitionTarget = 'debit.collections.index'; + cancelTransitionTarget = 'debit.collections.show'; + + @action + async cancel() { + this.cancelTransitionModel = await this.model.collection; + console.log(this.cancelTransitionModel); + super.cancel(); + } } diff --git a/app/models/debit/collection.js b/app/models/debit/collection.js index d979dd7ee..3b859b134 100644 --- a/app/models/debit/collection.js +++ b/app/models/debit/collection.js @@ -1,4 +1,4 @@ -import Model, { belongsTo, hasMany, attr } from '@ember-data/model'; +import Model, {attr, belongsTo, hasMany} from '@ember-data/model'; export default class Collection extends Model { @attr name; @@ -10,4 +10,24 @@ export default class Collection extends Model { // Relationships @hasMany('debit/transaction') transactions; @belongsTo('user') author; + + + async saveWithTransactions() { + const response = await this.save(); + const transactions = await response.transactions; + let failedTransactions = 0; + transactions.forEach((transaction) => { + if (transaction.hasDirtyAttributes) { + try { + transaction.save(); + } catch { + failedTransactions++; + } + } + }); + if (failedTransactions) { + const prefix = failedTransactions > 1 ? 'zijn' : 'is'; + throw `Er ${prefix} ${failedTransactions} transacties niet juist opgeslagen`; + } + } } diff --git a/app/routes/debit/collections/show.js b/app/routes/debit/collections/show.js index c56f004e1..246f9aaba 100644 --- a/app/routes/debit/collections/show.js +++ b/app/routes/debit/collections/show.js @@ -2,11 +2,11 @@ import { AuthenticatedRoute } from 'amber-ui/routes/application/application'; export default class CollectionsIndexRoute extends AuthenticatedRoute { get breadCrumb() { - return { title: this.controller.model.collection.name }; + return { title: this.controller.model.name }; } get pageActions() { - const { collection } = this.controller.model; + const collection = this.controller.model return [ { link: 'debit.collections.edit', @@ -41,11 +41,8 @@ export default class CollectionsIndexRoute extends AuthenticatedRoute { 'debit/collection', params.id ); - const transactions = collection.transactions; + await collection.transactions; // todo: simplify this to just returning collection, because transactions can be gotten from the collection, right? - return { - collection: collection, - transactions: transactions, - }; + return collection; } } diff --git a/app/templates/articles/destroy.hbs b/app/templates/articles/destroy.hbs index 69afb60dc..c0c45121a 100644 --- a/app/templates/articles/destroy.hbs +++ b/app/templates/articles/destroy.hbs @@ -14,8 +14,8 @@ - + \ No newline at end of file diff --git a/app/templates/debit/collections/edit.hbs b/app/templates/debit/collections/edit.hbs index a7a7ee553..f754c1e2b 100644 --- a/app/templates/debit/collections/edit.hbs +++ b/app/templates/debit/collections/edit.hbs @@ -21,9 +21,9 @@ @model={{model}} @errorMessage={{this.errorMessage}} > - + diff --git a/app/templates/debit/collections/show.hbs b/app/templates/debit/collections/show.hbs index 3f14b8635..fc0e54e58 100644 --- a/app/templates/debit/collections/show.hbs +++ b/app/templates/debit/collections/show.hbs @@ -5,13 +5,13 @@
- {{@model.collection.name}} + {{@model.name}} - - {{moment-format @model.collection.date 'DD-MM-YYYY'}} + {{moment-format @model.date 'DD-MM-YYYY'}}
Gemaakt door - {{@model.collection.author.fullName}} + {{@model.author.fullName}}
From 581e29d02e3afb926b2f3b2059ad2bde8f6e86eb Mon Sep 17 00:00:00 2001 From: matteo Date: Tue, 6 Sep 2022 18:12:43 +0200 Subject: [PATCH 16/40] going through the controllers alphabetically, decided to add some method to the madness lol --- app/controllers/activities/edit.js | 47 +++++++++------------ app/controllers/activities/new.js | 7 ++- app/controllers/article-comments/destroy.js | 1 + app/controllers/articles/edit.js | 6 +-- app/routes/activities/edit.js | 2 +- app/routes/article-comments/destroy.js | 6 ++- 6 files changed, 36 insertions(+), 33 deletions(-) diff --git a/app/controllers/activities/edit.js b/app/controllers/activities/edit.js index 484f952ee..ff1aa1324 100644 --- a/app/controllers/activities/edit.js +++ b/app/controllers/activities/edit.js @@ -9,10 +9,10 @@ import { union } from '../../utils/array-operations'; //todo: refactor below class to extend EditController export default class EditActivityController extends EditController { - @service session; - successTransitionTarget = 'activities.show'; - successTransitionModel = this.model; successMessage = 'Activiteit opgeslagen!'; + successTransitionTarget = 'activities.show'; + + @service session; @service abilities; _activityCategoryToOption(activityCategory) { @@ -26,29 +26,24 @@ export default class EditActivityController extends EditController { return combined.length > 0 ? combined : null; } - // todo: refactor computed - @computed('model.form.content', { - get() { - return !isNone(this.model.form.content); - }, - set(_, value) { - if (value) { - const form = this.store.createRecord('form/form'); - this.store.createRecord('form/open-question', { - form, - question: 'Opmerkingen', - fieldType: 'text', - position: 0, - }); - this.set('model.form', form); - } else { - this.set('model.form', null); - } - - return value; - }, - }) - activityHasForm; + get activityHasForm() { + return !isNone(this.model.form.content); + } + set activityHasForm(value) { + if (value) { + const form = this.store.createRecord('form/form'); + this.store.createRecord('form/open-question', { + form, + question: 'Opmerkingen', + fieldType: 'text', + position: 0, + }); + this.model.form = form; + } else { + this.model.form = null; + } + return value; + } get groups() { if (this.abilities.can('select all groups for activities')) { diff --git a/app/controllers/activities/new.js b/app/controllers/activities/new.js index cfaad13b1..47cc539af 100644 --- a/app/controllers/activities/new.js +++ b/app/controllers/activities/new.js @@ -1,3 +1,8 @@ import EditActivityController from './edit'; -export default class NewActivityController extends EditActivityController {} +export default class NewActivityController extends EditActivityController { + successMessage = 'Aanmaken gelukt!'; + cancelMessage = 'Aanmaken geannuleerd.'; + cancelTransitionTarget = 'activities.index'; + cancelTransitionModel = null; +} diff --git a/app/controllers/article-comments/destroy.js b/app/controllers/article-comments/destroy.js index 377af6f76..2080f38e5 100644 --- a/app/controllers/article-comments/destroy.js +++ b/app/controllers/article-comments/destroy.js @@ -5,6 +5,7 @@ export default class ArticleCommentDestroyController extends DestroyController { successMessage = 'Artikelreactie verwijderd!'; successTransitionTarget = 'articles.show'; cancelTransitionTarget = 'articles.show'; + @action async destroyModel() { this.successTransitionModel = await this.model.article; diff --git a/app/controllers/articles/edit.js b/app/controllers/articles/edit.js index 514f49d72..f667f4b9f 100644 --- a/app/controllers/articles/edit.js +++ b/app/controllers/articles/edit.js @@ -4,11 +4,11 @@ import { action, computed } from '@ember/object'; import { inject as service } from '@ember/service'; export default class EditArticleController extends EditController { - @service session; - @service abilities; - successTransitionTarget = 'articles.show'; + @service session; + @service abilities; + @computed('session.currentUser', function () { return this.session.hasPermission('article.update'); }) diff --git a/app/routes/activities/edit.js b/app/routes/activities/edit.js index b956ec694..1a8845f1e 100644 --- a/app/routes/activities/edit.js +++ b/app/routes/activities/edit.js @@ -9,7 +9,7 @@ export default class EdityActivityRoute extends AuthenticatedRoute { async model(params) { const activity = await this.store.findRecord('activity', params.id, params); - await activity.get('form'); + await activity.form; return activity; } diff --git a/app/routes/article-comments/destroy.js b/app/routes/article-comments/destroy.js index bfa7c4167..de01b0f8f 100644 --- a/app/routes/article-comments/destroy.js +++ b/app/routes/article-comments/destroy.js @@ -7,7 +7,9 @@ export default class DestroyArticleCommentRoute extends AuthenticatedRoute { return this.abilities.can('destroy article-comments'); } - model(params) { - return this.store.findRecord('article-comment', params.id, params); + async model(params) { + const articleComment = this.store.findRecord('article-comment', params.id, params); + await articleComment.get('article'); + return articleComment; } } From 9e8dd3a465c7e372b896d3aa9194ac2b3a8fe964 Mon Sep 17 00:00:00 2001 From: matteo Date: Mon, 19 Sep 2022 22:05:24 +0200 Subject: [PATCH 17/40] idk, changes from last time I worked on this --- app/controllers/articles/edit.js | 2 +- app/controllers/articles/new.js | 7 ++++++- app/controllers/books/new.js | 7 ++++++- app/controllers/debit/collections/new.js | 6 +++++- app/controllers/debit/transactions/destroy.js | 1 - app/controllers/debit/transactions/edit.js | 4 ++-- .../category/threads/thread/posts/destroy.js | 16 +++++++++++++++- .../category/threads/thread/posts/destroy.hbs | 7 +++---- 8 files changed, 38 insertions(+), 12 deletions(-) diff --git a/app/controllers/articles/edit.js b/app/controllers/articles/edit.js index f667f4b9f..faec4d690 100644 --- a/app/controllers/articles/edit.js +++ b/app/controllers/articles/edit.js @@ -8,7 +8,7 @@ export default class EditArticleController extends EditController { @service session; @service abilities; - + @computed('session.currentUser', function () { return this.session.hasPermission('article.update'); }) diff --git a/app/controllers/articles/new.js b/app/controllers/articles/new.js index b090aaaf0..90222f32f 100644 --- a/app/controllers/articles/new.js +++ b/app/controllers/articles/new.js @@ -1,3 +1,8 @@ import EditArticleController from './edit'; -export default class NewArticleController extends EditArticleController {} +export default class NewArticleController extends EditArticleController { + cancelTransitionTarget = 'articles.index'; + cancelTransitionModel = null; + successMessage = 'Artikel aangemaakt!'; + cancelMessage = 'Artikel aanmaken geannuleerd.'; +} diff --git a/app/controllers/books/new.js b/app/controllers/books/new.js index b834f9f06..b71305870 100644 --- a/app/controllers/books/new.js +++ b/app/controllers/books/new.js @@ -1,3 +1,8 @@ import EditController from './edit'; -export default class NewBookController extends EditController {} +export default class NewBookController extends EditController { + successMessage = 'Aanmaken gelukt!'; + cancelMessage = 'Aanmaken geannuleerd.'; + cancelTransitionTarget = 'books.index'; + cancelTransitionModel = null; +} diff --git a/app/controllers/debit/collections/new.js b/app/controllers/debit/collections/new.js index d344361db..2a77a47f2 100644 --- a/app/controllers/debit/collections/new.js +++ b/app/controllers/debit/collections/new.js @@ -3,8 +3,12 @@ import { action } from '@ember/object'; import EditController from 'amber-ui/controllers/application/edit'; export default class DebitCollectionNewController extends EditController { - successMessage = 'Incasso opgeslagen!'; + successMessage = 'Incasso aangemaakt!'; + cancelMessage = 'Incasso aanmaken geannuleerd.'; successTransitionTarget = 'debit.collections.show'; + cancelTransitionTarget = 'debit.collections.index'; + cancelTransitionModel = null; + validMimetypes = 'text/csv'; validExtensions = EmberArray.apply(['csv']); @action diff --git a/app/controllers/debit/transactions/destroy.js b/app/controllers/debit/transactions/destroy.js index a367c535f..e27f0ae88 100644 --- a/app/controllers/debit/transactions/destroy.js +++ b/app/controllers/debit/transactions/destroy.js @@ -8,7 +8,6 @@ export default class DebitTransactionDestroyController extends DestroyController @action async cancel() { this.cancelTransitionModel = await this.model.collection; - console.log(this.cancelTransitionModel); super.cancel(); } } diff --git a/app/controllers/debit/transactions/edit.js b/app/controllers/debit/transactions/edit.js index 87aa243a9..7be6f018e 100644 --- a/app/controllers/debit/transactions/edit.js +++ b/app/controllers/debit/transactions/edit.js @@ -6,12 +6,12 @@ import { inject as service } from '@ember/service'; export default class EditTransactionController extends EditController { successMessage = 'Transactie aangepast!'; + cancelMessage = 'Transactie wijzigen geannuleerd.'; successTransitionTarget = 'debit.collections.show'; @service store; @action async submit() { - // couldn't figure out how to do set the successTransitionModel reactively, so we fetch it manually here this.successTransitionModel = await this.model.collection; super.submit(); } @@ -22,6 +22,6 @@ export default class EditTransactionController extends EditController { @action setUser(user) { - this.model.set('user', user); + this.model.user = user; } } diff --git a/app/controllers/forum/categories/category/threads/thread/posts/destroy.js b/app/controllers/forum/categories/category/threads/thread/posts/destroy.js index 90328f2e9..5c5822dcd 100644 --- a/app/controllers/forum/categories/category/threads/thread/posts/destroy.js +++ b/app/controllers/forum/categories/category/threads/thread/posts/destroy.js @@ -1,6 +1,20 @@ import DestroyController from 'amber-ui/controllers/application/destroy'; +imprt {action } from '@ember/objects'; export default class ForumPostDestroyController extends DestroyController { successMessage = 'Forumbericht verwijderd!'; - successTransitionTarget = 'forum.categories.category.threads.thread'; + successTransitionTarget = 'forum.categories.category.threads.thread.show'; + cancelTransitionTarget = 'forum.categories.category.threads.thread.show'; + + @action + async cancel() { + this.cancelTransitionModel = await this.model.thread; + super.cancel(); + } + + @action + async destroyModel() { + this.successTransitionModel = await this.model.thread; + super.destroyModel(); + } } diff --git a/app/templates/forum/categories/category/threads/thread/posts/destroy.hbs b/app/templates/forum/categories/category/threads/thread/posts/destroy.hbs index b0892fa66..727285f7d 100644 --- a/app/templates/forum/categories/category/threads/thread/posts/destroy.hbs +++ b/app/templates/forum/categories/category/threads/thread/posts/destroy.hbs @@ -21,12 +21,11 @@ - Annuleren - +
\ No newline at end of file From b8253726fa706e4db246d97c327ab24b37bbc193 Mon Sep 17 00:00:00 2001 From: matteo Date: Mon, 19 Sep 2022 22:16:20 +0200 Subject: [PATCH 18/40] fix js lint --- app/components/users/privacy-settings.js | 1 - app/controllers/activities/edit.js | 10 +++++++--- app/controllers/debit/collections/edit.js | 2 ++ app/controllers/debit/transactions/edit.js | 1 - .../forum/categories/category/threads/new.js | 3 --- .../category/threads/thread/posts/destroy.js | 2 +- app/controllers/polls/edit.js | 5 ++++- app/controllers/users/batch/new.js | 5 ++--- app/controllers/users/edit-privacy.js | 5 ++--- app/controllers/users/edit.js | 2 +- app/models/debit/collection.js | 3 +-- app/routes/article-comments/destroy.js | 6 +++++- app/routes/debit/collections/show.js | 2 +- app/utils/array-operations.js | 4 +++- 14 files changed, 29 insertions(+), 22 deletions(-) diff --git a/app/components/users/privacy-settings.js b/app/components/users/privacy-settings.js index 65dab1b90..ce4a40b3f 100644 --- a/app/components/users/privacy-settings.js +++ b/app/components/users/privacy-settings.js @@ -4,7 +4,6 @@ import { } from 'amber-ui/constants'; import Component from '@glimmer/component'; import ModelSaveUtil from 'amber-ui/utils/model-save'; -import { action } from '@ember/object'; import { inject as service } from '@ember/service'; import { isPresent } from '@ember/utils'; import { tracked } from '@glimmer/tracking'; diff --git a/app/controllers/activities/edit.js b/app/controllers/activities/edit.js index ff1aa1324..499214f05 100644 --- a/app/controllers/activities/edit.js +++ b/app/controllers/activities/edit.js @@ -1,5 +1,5 @@ // eslint-disable-next-line ember/no-computed-properties-in-native-classes -import { action, computed } from '@ember/object'; +import { action } from '@ember/object'; import { ActivityCategories } from 'amber-ui/constants'; import { isNone } from '@ember/utils'; import { inject as service } from '@ember/service'; @@ -21,14 +21,19 @@ export default class EditActivityController extends EditController { label: activityCategory, }; } + get combinedErrors() { - const combined = union(this.model.errors.content, this.model.form?.get('errors')?.content); + const combined = union( + this.model.errors.content, + this.model.form?.get('errors')?.content + ); return combined.length > 0 ? combined : null; } get activityHasForm() { return !isNone(this.model.form.content); } + set activityHasForm(value) { if (value) { const form = this.store.createRecord('form/form'); @@ -42,7 +47,6 @@ export default class EditActivityController extends EditController { } else { this.model.form = null; } - return value; } get groups() { diff --git a/app/controllers/debit/collections/edit.js b/app/controllers/debit/collections/edit.js index 2a46a8000..6bb8b5d86 100644 --- a/app/controllers/debit/collections/edit.js +++ b/app/controllers/debit/collections/edit.js @@ -16,11 +16,13 @@ export default class DebitCollectionEditController extends EditController { .get('transactions') .pushObject(this.store.createRecord('debit/transaction', { user })); } + @action removeTransaction(transaction) { // todo: refactor this to be more in accordance with how we do deletions (such as showing feedback with the flash notice) transaction.deleteRecord(); } + @action async submit() { this.errorMessage = null; diff --git a/app/controllers/debit/transactions/edit.js b/app/controllers/debit/transactions/edit.js index 7be6f018e..1e1ae9015 100644 --- a/app/controllers/debit/transactions/edit.js +++ b/app/controllers/debit/transactions/edit.js @@ -3,7 +3,6 @@ import { action } from '@ember/object'; import EditController from 'amber-ui/controllers/application/edit'; import { inject as service } from '@ember/service'; - export default class EditTransactionController extends EditController { successMessage = 'Transactie aangepast!'; cancelMessage = 'Transactie wijzigen geannuleerd.'; diff --git a/app/controllers/forum/categories/category/threads/new.js b/app/controllers/forum/categories/category/threads/new.js index 498f6cdf6..f17bd7dd3 100644 --- a/app/controllers/forum/categories/category/threads/new.js +++ b/app/controllers/forum/categories/category/threads/new.js @@ -1,10 +1,7 @@ import NewController from 'amber-ui/controllers/application/new'; import { action } from '@ember/object'; -import { isNone } from '@ember/utils'; -import { inject as service } from '@ember/service'; export default class NewThreadController extends NewController { - successTransitionTarget = 'forum.categories.category.threads.thread.show'; cancelTransitionTarget = 'forum.categories.category.show'; cancelTransitionModel = this.model?.category; diff --git a/app/controllers/forum/categories/category/threads/thread/posts/destroy.js b/app/controllers/forum/categories/category/threads/thread/posts/destroy.js index 5c5822dcd..9c74eeecf 100644 --- a/app/controllers/forum/categories/category/threads/thread/posts/destroy.js +++ b/app/controllers/forum/categories/category/threads/thread/posts/destroy.js @@ -1,5 +1,5 @@ import DestroyController from 'amber-ui/controllers/application/destroy'; -imprt {action } from '@ember/objects'; +import { action } from '@ember/objects'; export default class ForumPostDestroyController extends DestroyController { successMessage = 'Forumbericht verwijderd!'; diff --git a/app/controllers/polls/edit.js b/app/controllers/polls/edit.js index a8ffab65b..e3e8baf58 100644 --- a/app/controllers/polls/edit.js +++ b/app/controllers/polls/edit.js @@ -12,7 +12,10 @@ export default class EditPollController extends EditController { } get combinedErrors() { - const combined = union(this.model.errors.content, this.model.form?.get('errors')?.content); + const combined = union( + this.model.errors.content, + this.model.form?.get('errors')?.content + ); return combined.length > 0 ? combined : null; } } diff --git a/app/controllers/users/batch/new.js b/app/controllers/users/batch/new.js index 7c8edc631..7497cdc73 100644 --- a/app/controllers/users/batch/new.js +++ b/app/controllers/users/batch/new.js @@ -3,7 +3,7 @@ import EmberArray, { A } from '@ember/array'; import { action } from '@ember/object'; import { tracked } from '@glimmer/tracking'; import { isInvalidResponse } from 'ember-fetch/errors'; -import NewController from "../../application/new"; +import NewController from '../../application/new'; export default class NewUserBatchController extends NewController { successMessage = 'Gebruikers aanmaken gelukt!'; @@ -11,7 +11,7 @@ export default class NewUserBatchController extends NewController { cancelTransitionTarget = 'users.index'; successTransitionTarget = 'users.index'; successTransitionModel = null; - + @service fetch; @tracked importFile = null; @tracked addToGroup = null; @@ -36,7 +36,6 @@ export default class NewUserBatchController extends NewController { @action async uploadFile() { - const groupId = this.addToGroup ? this.addToGroup.id : null; let response = await this.fetch.post('/users/batch_import', { body: { file: this.importFile, group: groupId }, diff --git a/app/controllers/users/edit-privacy.js b/app/controllers/users/edit-privacy.js index 0dc496072..abc416fbb 100644 --- a/app/controllers/users/edit-privacy.js +++ b/app/controllers/users/edit-privacy.js @@ -1,4 +1,3 @@ -import EditUserController from "./edit"; +import EditUserController from './edit'; -export default class EditUserPrivacyController extends EditUserController { -} +export default class EditUserPrivacyController extends EditUserController {} diff --git a/app/controllers/users/edit.js b/app/controllers/users/edit.js index 80be00cba..37dfa3e1e 100644 --- a/app/controllers/users/edit.js +++ b/app/controllers/users/edit.js @@ -1,5 +1,5 @@ // eslint-disable-next-line ember/no-computed-properties-in-native-classes -import { action, computed } from '@ember/object'; +import { action } from '@ember/object'; import { DigtusSubscriptionPreferenceTypes, AlmanakSubscriptionPreferenceTypes, diff --git a/app/models/debit/collection.js b/app/models/debit/collection.js index 3b859b134..463eac4ed 100644 --- a/app/models/debit/collection.js +++ b/app/models/debit/collection.js @@ -1,4 +1,4 @@ -import Model, {attr, belongsTo, hasMany} from '@ember-data/model'; +import Model, { attr, belongsTo, hasMany } from '@ember-data/model'; export default class Collection extends Model { @attr name; @@ -11,7 +11,6 @@ export default class Collection extends Model { @hasMany('debit/transaction') transactions; @belongsTo('user') author; - async saveWithTransactions() { const response = await this.save(); const transactions = await response.transactions; diff --git a/app/routes/article-comments/destroy.js b/app/routes/article-comments/destroy.js index de01b0f8f..751ba55db 100644 --- a/app/routes/article-comments/destroy.js +++ b/app/routes/article-comments/destroy.js @@ -8,7 +8,11 @@ export default class DestroyArticleCommentRoute extends AuthenticatedRoute { } async model(params) { - const articleComment = this.store.findRecord('article-comment', params.id, params); + const articleComment = this.store.findRecord( + 'article-comment', + params.id, + params + ); await articleComment.get('article'); return articleComment; } diff --git a/app/routes/debit/collections/show.js b/app/routes/debit/collections/show.js index 246f9aaba..806efce3b 100644 --- a/app/routes/debit/collections/show.js +++ b/app/routes/debit/collections/show.js @@ -6,7 +6,7 @@ export default class CollectionsIndexRoute extends AuthenticatedRoute { } get pageActions() { - const collection = this.controller.model + const collection = this.controller.model; return [ { link: 'debit.collections.edit', diff --git a/app/utils/array-operations.js b/app/utils/array-operations.js index 4acc76259..8b5245037 100644 --- a/app/utils/array-operations.js +++ b/app/utils/array-operations.js @@ -1,4 +1,6 @@ export function union() { - const uniques = new Set([...arguments].reduce((a,b) => [...a, ...(b ?? [])], [])); + const uniques = new Set( + [...arguments].reduce((a, b) => [...a, ...(b ?? [])], []) + ); return [...uniques]; } From 7aa8b6da23d43b3c81b95ca4df982feb2d3f0104 Mon Sep 17 00:00:00 2001 From: matteo Date: Mon, 19 Sep 2022 22:20:15 +0200 Subject: [PATCH 19/40] fix template lint --- app/components/forms/thread-form.hbs | 14 +++++++------- app/controllers/users/edit.js | 1 - .../category/threads/thread/posts/destroy.hbs | 1 + 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/components/forms/thread-form.hbs b/app/components/forms/thread-form.hbs index 5dd2ff5ad..f4389ad3c 100644 --- a/app/components/forms/thread-form.hbs +++ b/app/components/forms/thread-form.hbs @@ -31,13 +31,13 @@ @errors={{@model.errors}} @errorMessage={{@errorMessage}} > - + diff --git a/app/controllers/users/edit.js b/app/controllers/users/edit.js index 37dfa3e1e..110c0f0e3 100644 --- a/app/controllers/users/edit.js +++ b/app/controllers/users/edit.js @@ -1,4 +1,3 @@ -// eslint-disable-next-line ember/no-computed-properties-in-native-classes import { action } from '@ember/object'; import { DigtusSubscriptionPreferenceTypes, diff --git a/app/templates/forum/categories/category/threads/thread/posts/destroy.hbs b/app/templates/forum/categories/category/threads/thread/posts/destroy.hbs index 727285f7d..92e43171d 100644 --- a/app/templates/forum/categories/category/threads/thread/posts/destroy.hbs +++ b/app/templates/forum/categories/category/threads/thread/posts/destroy.hbs @@ -24,6 +24,7 @@ From 3d7a48edbc6a63710e2a8bdd20f45689ac41d381 Mon Sep 17 00:00:00 2001 From: matteo Date: Thu, 29 Sep 2022 18:11:40 +0200 Subject: [PATCH 20/40] I found a way to keep the model just the model, while also querying posts in a paged fashion everytime the queryparams change --- app/components/forum/forum-post-new.js | 14 +- app/controllers/articles/edit.js | 18 +-- app/controllers/debit/collections/edit.js | 8 +- app/controllers/debit/transactions/edit.js | 1 - app/controllers/form/responses/destroy.js | 9 +- .../forum/categories/category/threads/new.js | 4 +- .../category/threads/thread/posts/destroy.js | 2 +- .../category/threads/thread/posts/edit.js | 12 +- .../category/threads/thread/posts/index.js | 125 ++++++++++-------- app/controllers/groups/edit.js | 4 +- app/models/forum/thread.js | 16 ++- .../category/threads/thread/posts/index.js | 34 ++--- app/templates/form/responses/destroy.hbs | 4 +- .../category/threads/thread/posts/index.hbs | 14 +- app/utils/model-save.js | 12 +- 15 files changed, 145 insertions(+), 132 deletions(-) diff --git a/app/components/forum/forum-post-new.js b/app/components/forum/forum-post-new.js index 1a305eb86..ee1ef85a9 100644 --- a/app/components/forum/forum-post-new.js +++ b/app/components/forum/forum-post-new.js @@ -8,20 +8,18 @@ export default class ForumPostNewComponent extends Component { @service flashNotice; @action - save() { + async save() { let { content, thread } = this; - - this.store + await this.store .createRecord('forum/post', { message: content, thread, }) .save() - .then(() => { - this.flashNotice.sendSuccess('Forumbericht toegevoegd!'); - this.set('content', ''); - this.onSubmit(); - }); + this.flashNotice.sendSuccess('Forumbericht toegevoegd!'); + this.set('content', ''); + this.onSubmit(); + } @action diff --git a/app/controllers/articles/edit.js b/app/controllers/articles/edit.js index faec4d690..5ec66fec5 100644 --- a/app/controllers/articles/edit.js +++ b/app/controllers/articles/edit.js @@ -1,6 +1,5 @@ import EditController from 'amber-ui/controllers/application/edit'; -// eslint-disable-next-line ember/no-computed-properties-in-native-classes -import { action, computed } from '@ember/object'; +import { action } from '@ember/object'; import { inject as service } from '@ember/service'; export default class EditArticleController extends EditController { @@ -9,12 +8,11 @@ export default class EditArticleController extends EditController { @service session; @service abilities; - @computed('session.currentUser', function () { + get canPin() { return this.session.hasPermission('article.update'); - }) - canPin; + } - @computed('session.currentUser.{group,groups}', function () { + get groupOptions() { const optionArray = [ { label: '', @@ -29,17 +27,15 @@ export default class EditArticleController extends EditController { }); }); return optionArray; - }) - groupOptions; + } - @computed('session.currentUser', 'store', function () { + get groups() { if (this.abilities.can('select all groups for articles')) { return this.store.findAll('group'); } return this.session.currentUser.get('groups'); - }) - groups; + } @action coverPhotoLoaded(file) { diff --git a/app/controllers/debit/collections/edit.js b/app/controllers/debit/collections/edit.js index 6bb8b5d86..c244cb389 100644 --- a/app/controllers/debit/collections/edit.js +++ b/app/controllers/debit/collections/edit.js @@ -19,7 +19,9 @@ export default class DebitCollectionEditController extends EditController { @action removeTransaction(transaction) { - // todo: refactor this to be more in accordance with how we do deletions (such as showing feedback with the flash notice) + // note: this deletion only persists when calling .save() on the transaction, + // or by calling something like saveWithTransactions() on the collection. + // TLDR: deleteRecord is not the same as destroyRecord transaction.deleteRecord(); } @@ -27,8 +29,8 @@ export default class DebitCollectionEditController extends EditController { async submit() { this.errorMessage = null; try { - const savedModel = await this.model.saveWithTransactions(); - this.modelSaveUtil.onSuccess(savedModel); + await this.model.saveWithTransactions(); + this.modelSaveUtil.onSuccess(); } catch (error) { this.modelSaveUtil.onError(error); } diff --git a/app/controllers/debit/transactions/edit.js b/app/controllers/debit/transactions/edit.js index 1e1ae9015..e63bfb927 100644 --- a/app/controllers/debit/transactions/edit.js +++ b/app/controllers/debit/transactions/edit.js @@ -1,4 +1,3 @@ -// eslint-disable-next-line ember/no-computed-properties-in-native-classes import { action } from '@ember/object'; import EditController from 'amber-ui/controllers/application/edit'; import { inject as service } from '@ember/service'; diff --git a/app/controllers/form/responses/destroy.js b/app/controllers/form/responses/destroy.js index 620bd7675..ebccb8012 100644 --- a/app/controllers/form/responses/destroy.js +++ b/app/controllers/form/responses/destroy.js @@ -6,6 +6,11 @@ export default class FormResponseDestroyController extends DestroyController { @service store; successMessage = 'Je inschrijving is verwijderd.'; successTransitionTarget = 'activities.index'; + cancelTransitionTarget = 'activities.index'; + // important note: there is no way (currently) to redirect from a form response to the activity, since the models + // are not designed with this in mind. + // I would not mind this being enabled by a slight redesign in the future, though. + cancelTransitionModel = null; @action async destroyModel() { @@ -13,8 +18,8 @@ export default class FormResponseDestroyController extends DestroyController { super.destroyModel(); } - onSuccess(model) { + onSuccess() { this.form.reload(); - this.modelSaveUtil.redirectSuccess(model); + this.modelSaveUtil.redirectSuccess(); } } diff --git a/app/controllers/forum/categories/category/threads/new.js b/app/controllers/forum/categories/category/threads/new.js index f17bd7dd3..f3741f789 100644 --- a/app/controllers/forum/categories/category/threads/new.js +++ b/app/controllers/forum/categories/category/threads/new.js @@ -10,8 +10,8 @@ export default class NewThreadController extends NewController { async submit() { this.errorMessage = null; try { - const savedModel = await this.model.saveWithFirstPost(); - this.modelSaveUtil.onSuccess(savedModel); + await this.model.saveWithFirstPost(); + this.modelSaveUtil.onSuccess(); } catch (error) { this.modelSaveUtil.onError(error); } diff --git a/app/controllers/forum/categories/category/threads/thread/posts/destroy.js b/app/controllers/forum/categories/category/threads/thread/posts/destroy.js index 9c74eeecf..515a566ae 100644 --- a/app/controllers/forum/categories/category/threads/thread/posts/destroy.js +++ b/app/controllers/forum/categories/category/threads/thread/posts/destroy.js @@ -1,5 +1,5 @@ import DestroyController from 'amber-ui/controllers/application/destroy'; -import { action } from '@ember/objects'; +import { action } from '@ember/object'; export default class ForumPostDestroyController extends DestroyController { successMessage = 'Forumbericht verwijderd!'; diff --git a/app/controllers/forum/categories/category/threads/thread/posts/edit.js b/app/controllers/forum/categories/category/threads/thread/posts/edit.js index 380683c74..7fe03cfbc 100644 --- a/app/controllers/forum/categories/category/threads/thread/posts/edit.js +++ b/app/controllers/forum/categories/category/threads/thread/posts/edit.js @@ -1,15 +1,9 @@ import EditController from 'amber-ui/controllers/application/edit'; -import { action } from '@ember/object'; export default class EditPostController extends EditController { successMessage = 'Forumbericht aangepast!'; - successTransitionTarget = null; // Custom transition is used in onSuccess. + successTransitionTarget = 'forum.categories.category.threads.thread'; + + successTransitionModel = null; - @action - onSuccess(model) { - this.transitionToRoute( - 'forum.categories.category.threads.thread', - model.get('thread') - ); - } } diff --git a/app/controllers/forum/categories/category/threads/thread/posts/index.js b/app/controllers/forum/categories/category/threads/thread/posts/index.js index 9eeb6abb6..30fd8416f 100644 --- a/app/controllers/forum/categories/category/threads/thread/posts/index.js +++ b/app/controllers/forum/categories/category/threads/thread/posts/index.js @@ -1,63 +1,82 @@ -import { inject as service } from '@ember/service'; +import {inject as service} from '@ember/service'; import Controller from '@ember/controller'; -import { computed } from '@ember/object'; -import { next } from '@ember/runloop'; +import {action} from '@ember/object'; +import {next} from '@ember/runloop'; +import { tracked } from '@glimmer/tracking'; -export default Controller.extend({ - session: service(), - newContent: '', - queryParams: ['page'], +export default class PostsIndexController extends Controller { + @service session; + @service store; + @tracked + newContent = ''; + queryParams = ['page']; - count: computed.reads('model.posts.length'), + @tracked + postsPaged; - currentPageIsLastPage: computed( - 'model.posts.meta.{page,totalPages}', - function () { - const page = parseInt(this.model.posts.meta.page, 10); - const totalPages = parseInt(this.model.posts.meta.totalPages, 10); + get count() { + return this.model.postsPaged.length; + } - return totalPages === 0 || page === totalPages; - } - ), + get currentPageIsLastPage() { + const page = parseInt(this.model.postsPaged.meta.page, 10); + const totalPages = parseInt(this.model.postsPaged.meta.totalPages, 10); + + return totalPages === 0 || page === totalPages; + } advanceToPage(delta) { - const page = this.model.posts.meta.page; - const pages = this.model.posts.meta.totalPages; + const page = this.model.postsPaged.meta.page; + const pages = this.model.postsPaged.meta.totalPages; this.replaceRoute({ - queryParams: { page: ((page - 1 + delta + pages) % pages) + 1 }, + queryParams: {page: ((page - 1 + delta + pages) % pages) + 1}, }); - }, - actions: { - async newPostCreated() { - await this.model.posts.reload(); - }, - addQuote(q) { - this.set('newContent', `${this.newContent}${q} \n\n`); - function scrollToNewForumPost() { - document - .getElementById('newForumPostCard') - .scrollIntoView({ behavior: 'smooth', block: 'center' }); - } - if (!this.currentPageIsLastPage) { - this.transitionToRoute({ - queryParams: { page: this.model.posts.meta.totalPages }, - }).then(() => { - next(() => { - scrollToNewForumPost(); - }); + } + + async queryPostsPaged(params) { + this.postsPaged = await this.store.queryPaged('forum/post', params); + } + + @action + async newPostCreated() { + await this.model.posts.reload(); + } + + @action + addQuote(q) { + this.set('newContent', `${this.newContent}${q} \n\n`); + + function scrollToNewForumPost() { + document + .getElementById('newForumPostCard') + .scrollIntoView({behavior: 'smooth', block: 'center'}); + } + + if (!this.currentPageIsLastPage) { + this.transitionToRoute({ + queryParams: {page: this.postsPaged.meta.totalPages}, + }).then(() => { + next(() => { + scrollToNewForumPost(); }); - } else { - scrollToNewForumPost(); - } - }, - goToPreviousPage() { - return this.advanceToPage(-1); - }, - goToNextPage() { - return this.advanceToPage(1); - }, - onSwipe(direction) { - return this.advanceToPage(-direction); - }, - }, -}); + }); + } else { + scrollToNewForumPost(); + } + } + + @action + goToPreviousPage() { + return this.advanceToPage(-1); + } + + @action + goToNextPage() { + return this.advanceToPage(1); + } + + @action + onSwipe(direction) { + return this.advanceToPage(-direction); + } +} diff --git a/app/controllers/groups/edit.js b/app/controllers/groups/edit.js index 8ad68651a..c4dfff166 100644 --- a/app/controllers/groups/edit.js +++ b/app/controllers/groups/edit.js @@ -51,7 +51,7 @@ export default class EditGroupController extends EditController { if (this.model !== undefined) { let failedMembershipSavings = 0; try { - const savedModel = await this.model.save(); + await this.model.save(); await all( this.model.get('memberships').map((membership) => { if (membership.get('hasDirtyAttributes')) { @@ -78,7 +78,7 @@ export default class EditGroupController extends EditController { ); this.errorMessage = `Er ${prefix} ${failedMembershipSavings} ${suffix} niet juist opgeslagen: \n ${membershipErrorText}`; } else { - this.modelSaveUtil.onSuccess(savedModel); + this.modelSaveUtil.onSuccess(); } } catch (error) { this.errorMessage = error.message; diff --git a/app/models/forum/thread.js b/app/models/forum/thread.js index c636f8ee7..38db95dd1 100644 --- a/app/models/forum/thread.js +++ b/app/models/forum/thread.js @@ -1,7 +1,12 @@ import Model, { belongsTo, hasMany, attr } from '@ember-data/model'; +import {inject as service} from '@ember/service'; import { isNone } from '@ember/utils'; +import { tracked } from '@glimmer/tracking'; +import { assign } from '@ember/polyfills'; + export default class Thread extends Model { + @service store; // Properties @attr title; @attr read; @@ -13,12 +18,21 @@ export default class Thread extends Model { // Relations @belongsTo('user') author; @belongsTo('forum/category') category; - @hasMany('forum/post') posts; + @hasMany('forum/post', {sort: 'created_at'}) posts; + + @tracked + postsPaged; + get firstPost() { return this.posts.get('firstObject'); } + async queryPostsPaged(params) { + assign(params,{filter: {thread: this.id}, sort: 'created_at'}) + this.postsPaged = await this.store.queryPaged('forum/post', params); + } + get isOpen() { return this.closedAt === null; } diff --git a/app/routes/forum/categories/category/threads/thread/posts/index.js b/app/routes/forum/categories/category/threads/thread/posts/index.js index a0769cd1c..f37d309e8 100644 --- a/app/routes/forum/categories/category/threads/thread/posts/index.js +++ b/app/routes/forum/categories/category/threads/thread/posts/index.js @@ -1,18 +1,14 @@ -import { AuthenticatedRoute } from 'amber-ui/routes/application/application'; -import { inject as service } from '@ember/service'; -import { assign } from '@ember/polyfills'; -import { action } from '@ember/object'; -import { - bindKeyboardShortcuts, - unbindKeyboardShortcuts, -} from 'ember-keyboard-shortcuts'; +import {AuthenticatedRoute} from 'amber-ui/routes/application/application'; +import {inject as service} from '@ember/service'; +import {action} from '@ember/object'; +import {bindKeyboardShortcuts, unbindKeyboardShortcuts,} from 'ember-keyboard-shortcuts'; export default class PostIndexRoute extends AuthenticatedRoute { @service router; @service fetch; get breadCrumb() { - return { title: this.controller.model.thread.title }; + return { title: this.controller.model.title }; } get pageActions() { @@ -21,14 +17,14 @@ export default class PostIndexRoute extends AuthenticatedRoute { link: 'forum.categories.category.threads.thread.edit', title: 'Wijzigen', icon: 'pencil', - linkArgument: this.controller.model.thread, + linkArgument: this.controller.model, canAccess: this.abilities.can('edit forum/threads'), }, { link: 'forum.categories.category.threads.thread.destroy', title: 'Verwijderen', icon: 'trash', - linkArgument: this.controller.model.thread, + linkArgument: this.controller.model, canAccess: this.abilities.can('destroy forum/threads'), }, ]; @@ -39,19 +35,9 @@ export default class PostIndexRoute extends AuthenticatedRoute { } async model(params) { - const category = this.modelFor('forum.categories.category'); - const thread = this.modelFor('forum.categories.category.threads.thread'); - assign(params, { - filter: { thread: thread.id }, - sort: 'created_at', - }); - const postsPromise = await this.store.queryPaged('forum/post', params); - - return { - category, - thread, - posts: postsPromise, - }; + const model = this.modelFor('forum.categories.category.threads.thread') + await model.queryPostsPaged(params); + return model } activate() { diff --git a/app/templates/form/responses/destroy.hbs b/app/templates/form/responses/destroy.hbs index dc486c5e0..bcf4c25ff 100644 --- a/app/templates/form/responses/destroy.hbs +++ b/app/templates/form/responses/destroy.hbs @@ -16,9 +16,7 @@ - - Nee - + {{#if errorMessage}}
{{this.errorMessage}}
diff --git a/app/templates/forum/categories/category/threads/thread/posts/index.hbs b/app/templates/forum/categories/category/threads/thread/posts/index.hbs index 52d9e7338..b9cb9eb5f 100644 --- a/app/templates/forum/categories/category/threads/thread/posts/index.hbs +++ b/app/templates/forum/categories/category/threads/thread/posts/index.hbs @@ -3,11 +3,11 @@
- +
- {{#each @model.posts as |post|}} + {{#each @model.postsPaged as |post|}} {{#unless post.isDeleted}} {{forum/forum-post post @@ -19,10 +19,10 @@ {{#if currentPageIsLastPage}} - {{#unless @model.thread.isOpen}} + {{#unless @model.isOpen}} {{/unless}} - {{#if (can 'create post for forum/thread' @model.thread)}} + {{#if (can 'create post for forum/thread' @model)}}
Reageren
@@ -47,5 +47,5 @@ {{/if}}
- +
\ No newline at end of file diff --git a/app/utils/model-save.js b/app/utils/model-save.js index 1330c1b14..96ba2590a 100644 --- a/app/utils/model-save.js +++ b/app/utils/model-save.js @@ -26,8 +26,9 @@ export default class ModelSaveUtil { } } - redirectSuccess(model) { - const targetModel = this.entity?.successTransitionModel ?? model; + redirectSuccess() { + const targetModel = this.entity?.successTransitionModel; + console.log(targetModel) if (!isNone(this.entity?.successTransitionTarget)) { this.transition(this.entity.successTransitionTarget, targetModel?.id); } @@ -35,19 +36,20 @@ export default class ModelSaveUtil { redirectCancel() { const targetModel = this.entity?.cancelTransitionModel; + console.log(targetModel) if (!isNone(this.entity?.cancelTransitionTarget)) { this.transition(this.entity.cancelTransitionTarget, targetModel?.id); } } - onSuccess(model) { + onSuccess() { // Show notice this.sendSuccess(); if (this.entity?.onSuccess) { - this.entity.onSuccess(model); + this.entity.onSuccess(); } else { // Redirect - this.redirectSuccess(model); + this.redirectSuccess(); } } From ab44d8040821cd2172420f89c09fa47235225388 Mon Sep 17 00:00:00 2001 From: matteo Date: Fri, 30 Sep 2022 15:47:00 +0200 Subject: [PATCH 21/40] more changes --- app/controllers/application/destroy.js | 5 ++- .../category/threads/thread/posts/edit.js | 3 +- .../category/threads/thread/posts/index.js | 25 +++++++------- app/controllers/forum/categories/new.js | 2 +- app/controllers/groups/edit.js | 5 +-- app/controllers/mail-aliases/destroy.js | 1 + app/controllers/mail-aliases/edit.js | 34 ++++++++----------- app/utils/model-save.js | 12 ++++--- 8 files changed, 42 insertions(+), 45 deletions(-) diff --git a/app/controllers/application/destroy.js b/app/controllers/application/destroy.js index f0ff994a6..85d6d543b 100644 --- a/app/controllers/application/destroy.js +++ b/app/controllers/application/destroy.js @@ -15,9 +15,8 @@ export default class DestroyController extends EditController { } onError(error) { - // todo: somehow incorporate the error into the message maybe? could be useful if users can show us the error message - this.errorMessage = 'Er ging iets fout bij het verwijderen.'; - this.errorMessage += error; + // todo: somehow incorporate the error into the message in a more robust manner? + this.errorMessage = `Er ging iets fout bij het verwijderen: ${error}`; } transition() { diff --git a/app/controllers/forum/categories/category/threads/thread/posts/edit.js b/app/controllers/forum/categories/category/threads/thread/posts/edit.js index 7fe03cfbc..ff97f6fe8 100644 --- a/app/controllers/forum/categories/category/threads/thread/posts/edit.js +++ b/app/controllers/forum/categories/category/threads/thread/posts/edit.js @@ -3,7 +3,6 @@ import EditController from 'amber-ui/controllers/application/edit'; export default class EditPostController extends EditController { successMessage = 'Forumbericht aangepast!'; successTransitionTarget = 'forum.categories.category.threads.thread'; - - successTransitionModel = null; + successTransitionModel = this.model?.thread; } diff --git a/app/controllers/forum/categories/category/threads/thread/posts/index.js b/app/controllers/forum/categories/category/threads/thread/posts/index.js index 30fd8416f..94b96c444 100644 --- a/app/controllers/forum/categories/category/threads/thread/posts/index.js +++ b/app/controllers/forum/categories/category/threads/thread/posts/index.js @@ -37,31 +37,30 @@ export default class PostsIndexController extends Controller { this.postsPaged = await this.store.queryPaged('forum/post', params); } + scrollToNewForumPost() { + document + .getElementById('newForumPostCard') + .scrollIntoView({behavior: 'smooth', block: 'center'}); + } + @action async newPostCreated() { await this.model.posts.reload(); } @action - addQuote(q) { + async addQuote(q) { this.set('newContent', `${this.newContent}${q} \n\n`); - function scrollToNewForumPost() { - document - .getElementById('newForumPostCard') - .scrollIntoView({behavior: 'smooth', block: 'center'}); - } - if (!this.currentPageIsLastPage) { - this.transitionToRoute({ + await this.transitionToRoute({ queryParams: {page: this.postsPaged.meta.totalPages}, - }).then(() => { - next(() => { - scrollToNewForumPost(); - }); + }) + next(() => { + this.scrollToNewForumPost(); }); } else { - scrollToNewForumPost(); + this.scrollToNewForumPost(); } } diff --git a/app/controllers/forum/categories/new.js b/app/controllers/forum/categories/new.js index 429e0cd72..5c4601343 100644 --- a/app/controllers/forum/categories/new.js +++ b/app/controllers/forum/categories/new.js @@ -3,6 +3,6 @@ import NewController from 'amber-ui/controllers/application/new'; export default class NewCategoryController extends NewController { successMessage = 'Categorie toegevoegd!'; successTransitionTarget = 'forum.categories'; - successTransitionTarget = null; + successTransitionModel = null; cancelTransitionTarget = 'forum.categories'; } diff --git a/app/controllers/groups/edit.js b/app/controllers/groups/edit.js index c4dfff166..ab2967341 100644 --- a/app/controllers/groups/edit.js +++ b/app/controllers/groups/edit.js @@ -1,4 +1,3 @@ -// eslint-disable-next-line ember/no-computed-properties-in-native-classes import { action } from '@ember/object'; import { A } from '@ember/array'; import { GroupKinds } from 'amber-ui/constants'; @@ -46,6 +45,7 @@ export default class EditGroupController extends EditController { async submit() { // todo: take a good look at this method, and see if its can be simplified to conform more to the // EditController + model-save-utils pattern + // Especially the error handling has to be cleaned up heavily. It's hard to read and understand what's going on const membershipErrors = A(); if (this.model !== undefined) { @@ -76,12 +76,13 @@ export default class EditGroupController extends EditController { }, '' ); + this.errorMessage = `Er ${prefix} ${failedMembershipSavings} ${suffix} niet juist opgeslagen: \n ${membershipErrorText}`; } else { this.modelSaveUtil.onSuccess(); } } catch (error) { - this.errorMessage = error.message; + this.modelSaveUtil.onError(error); } } } diff --git a/app/controllers/mail-aliases/destroy.js b/app/controllers/mail-aliases/destroy.js index bb9c7c3f7..496180efc 100644 --- a/app/controllers/mail-aliases/destroy.js +++ b/app/controllers/mail-aliases/destroy.js @@ -2,4 +2,5 @@ import DestroyController from 'amber-ui/controllers/application/destroy'; export default class MailAliasDestroyController extends DestroyController { successTransitionTarget = 'mail-aliases.index'; + // cancelTransitionTarget = 'mail-aliases.index'; } diff --git a/app/controllers/mail-aliases/edit.js b/app/controllers/mail-aliases/edit.js index 4671084a9..2ba315499 100644 --- a/app/controllers/mail-aliases/edit.js +++ b/app/controllers/mail-aliases/edit.js @@ -1,9 +1,5 @@ -// eslint-disable-next-line ember/no-computed-properties-in-native-classes -import { equal, reads } from '@ember/object/computed'; import EditController from 'amber-ui/controllers/application/edit'; import { MailAliasModerationTypes } from 'amber-ui/constants'; -// eslint-disable-next-line ember/no-computed-properties-in-native-classes -import { computed } from '@ember/object'; export default class EditMailAliasController extends EditController { successTransitionTarget = 'mail-aliases.show'; @@ -15,27 +11,27 @@ export default class EditMailAliasController extends EditController { }; } - @equal('model.moderationType', 'open') - moderationTypeOpen; + get moderationTypeOpen() { + return this.model.moderationsType === 'open'; + } - @computed('store', function () { + get groups() { return this.store.findAll('group'); - }) - groups; + } - @computed('store', function () { + get users() { return this.store.findAll('user'); - }) - users; + } - @reads('model.user.id') - anyUser; + get anyUser() { + return this.model.user.id; + } - @reads('model.group.id') - anyGroup; + get anyGroup() { + return this.model.group.id; + } - @computed('_mailAliasModerationTypes', function () { + get mailAliasModerationTypes() { return MailAliasModerationTypes.map(this._mailAliasModerationTypes); - }) - mailAliasModerationTypes; + } } diff --git a/app/utils/model-save.js b/app/utils/model-save.js index 96ba2590a..483c59750 100644 --- a/app/utils/model-save.js +++ b/app/utils/model-save.js @@ -28,7 +28,6 @@ export default class ModelSaveUtil { redirectSuccess() { const targetModel = this.entity?.successTransitionModel; - console.log(targetModel) if (!isNone(this.entity?.successTransitionTarget)) { this.transition(this.entity.successTransitionTarget, targetModel?.id); } @@ -36,7 +35,6 @@ export default class ModelSaveUtil { redirectCancel() { const targetModel = this.entity?.cancelTransitionModel; - console.log(targetModel) if (!isNone(this.entity?.cancelTransitionTarget)) { this.transition(this.entity.cancelTransitionTarget, targetModel?.id); } @@ -66,9 +64,13 @@ export default class ModelSaveUtil { if (this.entity?.onError) { this.entity.onError(error); } else { - this.entity.errorMessage = error.errors - .map((err) => err.detail) - .join(', '); + if (error.errors) { + this.entity.errorMessage = error.errors + .map((err) => err.detail) + .join(', '); + } else { + this.entity.errorMessage = String(error) + } } } From fa693ba5d3f6bbfa6240bcc4b96333180a3e0fca Mon Sep 17 00:00:00 2001 From: matteo Date: Fri, 30 Sep 2022 15:47:15 +0200 Subject: [PATCH 22/40] more changes --- app/controllers/mail-aliases/destroy.js | 2 +- app/templates/mail-aliases/destroy.hbs | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/controllers/mail-aliases/destroy.js b/app/controllers/mail-aliases/destroy.js index 496180efc..38369008b 100644 --- a/app/controllers/mail-aliases/destroy.js +++ b/app/controllers/mail-aliases/destroy.js @@ -2,5 +2,5 @@ import DestroyController from 'amber-ui/controllers/application/destroy'; export default class MailAliasDestroyController extends DestroyController { successTransitionTarget = 'mail-aliases.index'; - // cancelTransitionTarget = 'mail-aliases.index'; + cancelTransitionTarget = 'mail-aliases.show'; } diff --git a/app/templates/mail-aliases/destroy.hbs b/app/templates/mail-aliases/destroy.hbs index f2dcb507d..4dee4946c 100644 --- a/app/templates/mail-aliases/destroy.hbs +++ b/app/templates/mail-aliases/destroy.hbs @@ -1,9 +1,7 @@

Weet je zeker dat je dit mail-alias ({{@model.email}}) wil verwijderen?

- - Nee - + {{#if errorMessage}}
{{this.errorMessage}}
From 54813ae0d970f6e22172358dccf178fa944fa0d6 Mon Sep 17 00:00:00 2001 From: matteo Date: Fri, 30 Sep 2022 15:50:39 +0200 Subject: [PATCH 23/40] typo --- app/controllers/mail-aliases/edit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/mail-aliases/edit.js b/app/controllers/mail-aliases/edit.js index 2ba315499..78e580040 100644 --- a/app/controllers/mail-aliases/edit.js +++ b/app/controllers/mail-aliases/edit.js @@ -12,7 +12,7 @@ export default class EditMailAliasController extends EditController { } get moderationTypeOpen() { - return this.model.moderationsType === 'open'; + return this.model.moderationType === 'open'; } get groups() { From f1c07274189fb8a6117344c40e0a3420430f9907 Mon Sep 17 00:00:00 2001 From: matteo Date: Fri, 30 Sep 2022 16:16:00 +0200 Subject: [PATCH 24/40] better handling of transitions in destroycontrollers --- app/controllers/application/destroy.js | 8 +++++++- app/controllers/mail-moderations/accept.js | 2 +- app/controllers/mail-moderations/destroy.js | 4 +++- app/controllers/mail-moderations/reject.js | 2 +- app/controllers/oauth/authorize.js | 2 +- app/controllers/photo-albums/new.js | 1 - app/controllers/photo-albums/photo-album/destroy.js | 1 + app/controllers/photo-albums/photo-album/edit.js | 2 ++ .../photo-albums/photo-album/photos/destroy.js | 1 + app/templates/photo-albums/photo-album/destroy.hbs | 8 +------- app/utils/model-save.js | 3 ++- 11 files changed, 20 insertions(+), 14 deletions(-) diff --git a/app/controllers/application/destroy.js b/app/controllers/application/destroy.js index 85d6d543b..0633171b9 100644 --- a/app/controllers/application/destroy.js +++ b/app/controllers/application/destroy.js @@ -8,6 +8,7 @@ export default class DestroyController extends EditController { @tracked successTransitionModel = null; @tracked cancelTransitionTarget = null; @tracked cancelTransitionModel = this.model; + @tracked destroyed = false; @action destroyModel() { @@ -20,7 +21,12 @@ export default class DestroyController extends EditController { } transition() { - this.replaceRoute(...arguments); + // todo: this does not quite work everywhere, because navigating back after the transition + if (this.destroyed) { + this.replaceRoute(...arguments); + } else { + this.transitionToRoute(...arguments); + } } submit = undefined; diff --git a/app/controllers/mail-moderations/accept.js b/app/controllers/mail-moderations/accept.js index 630aba196..fdb64e93b 100644 --- a/app/controllers/mail-moderations/accept.js +++ b/app/controllers/mail-moderations/accept.js @@ -1,7 +1,7 @@ import { inject as service } from '@ember/service'; import Controller from '@ember/controller'; import { isInvalidResponse } from 'ember-fetch/errors'; - +// todo: octane export default Controller.extend({ fetch: service(), errorMessage: null, diff --git a/app/controllers/mail-moderations/destroy.js b/app/controllers/mail-moderations/destroy.js index f3086446d..158f24fd3 100644 --- a/app/controllers/mail-moderations/destroy.js +++ b/app/controllers/mail-moderations/destroy.js @@ -1,6 +1,8 @@ import DestroyController from 'amber-ui/controllers/application/destroy'; export default class MailModerationDestroyController extends DestroyController { + successMessage = 'Mail is genegeerd.'; + cancelMessage = 'Wijzigingen geannuleerd.' successTransitionTarget = 'mail-moderations.index'; - successMessage = 'Mail is genegeerd'; + cancelTransitionTarget = 'mail-moderations.show'; } diff --git a/app/controllers/mail-moderations/reject.js b/app/controllers/mail-moderations/reject.js index 4156d0c5c..db1c47ca7 100644 --- a/app/controllers/mail-moderations/reject.js +++ b/app/controllers/mail-moderations/reject.js @@ -1,7 +1,7 @@ import { inject as service } from '@ember/service'; import Controller from '@ember/controller'; import { isInvalidResponse } from 'ember-fetch/errors'; - +// todo: octane export default Controller.extend({ fetch: service(), errorMessage: null, diff --git a/app/controllers/oauth/authorize.js b/app/controllers/oauth/authorize.js index 27973b007..5213a5496 100644 --- a/app/controllers/oauth/authorize.js +++ b/app/controllers/oauth/authorize.js @@ -1,6 +1,6 @@ import Controller from '@ember/controller'; import { inject as service } from '@ember/service'; - +// todo: octane export default Controller.extend({ fetch: service(), clientName: null, diff --git a/app/controllers/photo-albums/new.js b/app/controllers/photo-albums/new.js index c16c1994e..83e86b7c3 100644 --- a/app/controllers/photo-albums/new.js +++ b/app/controllers/photo-albums/new.js @@ -1,5 +1,4 @@ import NewController from 'amber-ui/controllers/application/new'; -// eslint-disable-next-line ember/no-computed-properties-in-native-classes import { inject as service } from '@ember/service'; export default class NewPhotoAlbumController extends NewController { diff --git a/app/controllers/photo-albums/photo-album/destroy.js b/app/controllers/photo-albums/photo-album/destroy.js index bc230e475..859f22900 100644 --- a/app/controllers/photo-albums/photo-album/destroy.js +++ b/app/controllers/photo-albums/photo-album/destroy.js @@ -2,4 +2,5 @@ import DestroyController from 'amber-ui/controllers/application/destroy'; export default class PhotoAlbumDestroyController extends DestroyController { successTransitionTarget = 'photo-albums.index'; + cancelTransitionTarget = 'photo-albums.photo-album.show'; } diff --git a/app/controllers/photo-albums/photo-album/edit.js b/app/controllers/photo-albums/photo-album/edit.js index 8170fd416..d5ca94c15 100644 --- a/app/controllers/photo-albums/photo-album/edit.js +++ b/app/controllers/photo-albums/photo-album/edit.js @@ -1,6 +1,8 @@ import { inject as service } from '@ember/service'; import NewPhotoAlbumController from '../new'; +// todo: it would follow the pattern more if we let the NewPhotoAlbumController extend the EditPhotoAlbumController, +// instead of vice versa export default class EditPhotoAlbumController extends NewPhotoAlbumController { successMessage = "Wijzigen en/of foto's toevoegen gelukt!"; cancelMessage = "Wijzigen en/of foto's toevoegen geannuleerd."; diff --git a/app/controllers/photo-albums/photo-album/photos/destroy.js b/app/controllers/photo-albums/photo-album/photos/destroy.js index 62e1828bc..855425c3e 100644 --- a/app/controllers/photo-albums/photo-album/photos/destroy.js +++ b/app/controllers/photo-albums/photo-album/photos/destroy.js @@ -2,4 +2,5 @@ import DestroyController from 'amber-ui/controllers/application/destroy'; export default class PhotoAlbumPhotoDestroyController extends DestroyController { successTransitionTarget = 'photo-albums.photo-album.photos.index'; + cancelTransitionTarget = 'photo-albums.photo-album.photos.show'; } diff --git a/app/templates/photo-albums/photo-album/destroy.hbs b/app/templates/photo-albums/photo-album/destroy.hbs index bb11a0c13..72e87470d 100644 --- a/app/templates/photo-albums/photo-album/destroy.hbs +++ b/app/templates/photo-albums/photo-album/destroy.hbs @@ -14,12 +14,6 @@ - - Annuleren - +
\ No newline at end of file diff --git a/app/utils/model-save.js b/app/utils/model-save.js index 483c59750..205bbf91e 100644 --- a/app/utils/model-save.js +++ b/app/utils/model-save.js @@ -104,7 +104,8 @@ export default class ModelSaveUtil { model .destroyRecord() .then(() => { - this.onSuccess(null); + this.entity.destroyed = true; + this.onSuccess(); }) .catch((error) => { this.onError(error); From 3a164840a037ec24f675f274a9f54ce72b2725d5 Mon Sep 17 00:00:00 2001 From: matteo Date: Fri, 30 Sep 2022 16:59:22 +0200 Subject: [PATCH 25/40] I think I have had all new edit and destroy controllers --- app/controllers/polls/destroy.js | 2 ++ app/controllers/sog/name-trainer.js | 2 +- app/controllers/static-pages/destroy.js | 1 + app/controllers/users/activate-account.js | 2 +- app/controllers/users/destroy.js | 1 + app/controllers/users/resend-activation.js | 2 +- app/templates/static-pages/destroy.hbs | 4 +--- app/templates/users/destroy.hbs | 4 +--- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/controllers/polls/destroy.js b/app/controllers/polls/destroy.js index ed496383a..185fc2534 100644 --- a/app/controllers/polls/destroy.js +++ b/app/controllers/polls/destroy.js @@ -2,5 +2,7 @@ import DestroyController from 'amber-ui/controllers/application/destroy'; export default class PollDestroyController extends DestroyController { successMessage = 'Poll verwijderd!'; + cancelMessage = 'Poll verwijderen geannuleerd.'; successTransitionTarget = 'polls.index'; + cancelTransitionTarget = 'polls.show'; } diff --git a/app/controllers/sog/name-trainer.js b/app/controllers/sog/name-trainer.js index 11ffc4b62..5aa4f5955 100644 --- a/app/controllers/sog/name-trainer.js +++ b/app/controllers/sog/name-trainer.js @@ -1,7 +1,7 @@ import Controller from '@ember/controller'; import { computed } from '@ember/object'; import { run } from '@ember/runloop'; - +// todo: octane export default Controller.extend({ queryParams: ['groupId', 'difficulty'], groupId: null, diff --git a/app/controllers/static-pages/destroy.js b/app/controllers/static-pages/destroy.js index 0ee21c8a6..00adb245e 100644 --- a/app/controllers/static-pages/destroy.js +++ b/app/controllers/static-pages/destroy.js @@ -2,4 +2,5 @@ import DestroyController from 'amber-ui/controllers/application/destroy'; export default class StaticPageDestroyController extends DestroyController { successTransitionTarget = 'static-pages.index'; + cancelTransitionTarget = 'static-pages.show'; } diff --git a/app/controllers/users/activate-account.js b/app/controllers/users/activate-account.js index 9d7ade848..544eb83da 100644 --- a/app/controllers/users/activate-account.js +++ b/app/controllers/users/activate-account.js @@ -4,7 +4,7 @@ import { computed } from '@ember/object'; import { run } from '@ember/runloop'; import { isNone } from '@ember/utils'; import { isNotFoundResponse } from 'ember-fetch/errors'; - +// todo: octane export default Controller.extend({ fetch: service(), diff --git a/app/controllers/users/destroy.js b/app/controllers/users/destroy.js index c99f535c9..90f64de3d 100644 --- a/app/controllers/users/destroy.js +++ b/app/controllers/users/destroy.js @@ -2,4 +2,5 @@ import DestroyController from 'amber-ui/controllers/application/destroy'; export default class UserDestroyController extends DestroyController { successTransitionTarget = 'users.index'; + cancelTransitionTarget = 'users.show'; } diff --git a/app/controllers/users/resend-activation.js b/app/controllers/users/resend-activation.js index 2a81598e6..f04410a54 100644 --- a/app/controllers/users/resend-activation.js +++ b/app/controllers/users/resend-activation.js @@ -1,7 +1,7 @@ import { inject as service } from '@ember/service'; import Controller from '@ember/controller'; import { isNotFoundResponse } from 'ember-fetch/errors'; - +// todo: octane export default Controller.extend({ fetch: service(), actions: { diff --git a/app/templates/static-pages/destroy.hbs b/app/templates/static-pages/destroy.hbs index e12d17057..6120d52b0 100644 --- a/app/templates/static-pages/destroy.hbs +++ b/app/templates/static-pages/destroy.hbs @@ -1,9 +1,7 @@

Weet je zeker dat je deze informatie pagina wilt verwijderen?

- - Nee - + {{#if errorMessage}}
{{this.errorMessage}}
diff --git a/app/templates/users/destroy.hbs b/app/templates/users/destroy.hbs index 975efa12e..b19d510b8 100644 --- a/app/templates/users/destroy.hbs +++ b/app/templates/users/destroy.hbs @@ -15,9 +15,7 @@ - - Annuleren - + From e9d58e2e53d577a4f51129d8c1f0dc5f6c32e9a6 Mon Sep 17 00:00:00 2001 From: matteo Date: Fri, 30 Sep 2022 17:01:27 +0200 Subject: [PATCH 26/40] js lint fixes --- app/components/forum/forum-post-new.js | 3 +-- .../category/threads/thread/posts/edit.js | 1 - .../category/threads/thread/posts/index.js | 15 ++++++++------- app/controllers/mail-moderations/destroy.js | 2 +- app/models/forum/thread.js | 8 +++----- .../category/threads/thread/posts/index.js | 15 +++++++++------ app/utils/model-save.js | 2 +- 7 files changed, 23 insertions(+), 23 deletions(-) diff --git a/app/components/forum/forum-post-new.js b/app/components/forum/forum-post-new.js index ee1ef85a9..037605e85 100644 --- a/app/components/forum/forum-post-new.js +++ b/app/components/forum/forum-post-new.js @@ -15,11 +15,10 @@ export default class ForumPostNewComponent extends Component { message: content, thread, }) - .save() + .save(); this.flashNotice.sendSuccess('Forumbericht toegevoegd!'); this.set('content', ''); this.onSubmit(); - } @action diff --git a/app/controllers/forum/categories/category/threads/thread/posts/edit.js b/app/controllers/forum/categories/category/threads/thread/posts/edit.js index ff97f6fe8..acba8ca67 100644 --- a/app/controllers/forum/categories/category/threads/thread/posts/edit.js +++ b/app/controllers/forum/categories/category/threads/thread/posts/edit.js @@ -4,5 +4,4 @@ export default class EditPostController extends EditController { successMessage = 'Forumbericht aangepast!'; successTransitionTarget = 'forum.categories.category.threads.thread'; successTransitionModel = this.model?.thread; - } diff --git a/app/controllers/forum/categories/category/threads/thread/posts/index.js b/app/controllers/forum/categories/category/threads/thread/posts/index.js index 94b96c444..c04dc0cd7 100644 --- a/app/controllers/forum/categories/category/threads/thread/posts/index.js +++ b/app/controllers/forum/categories/category/threads/thread/posts/index.js @@ -1,7 +1,7 @@ -import {inject as service} from '@ember/service'; +import { inject as service } from '@ember/service'; import Controller from '@ember/controller'; -import {action} from '@ember/object'; -import {next} from '@ember/runloop'; +import { action } from '@ember/object'; +import { next } from '@ember/runloop'; import { tracked } from '@glimmer/tracking'; export default class PostsIndexController extends Controller { @@ -9,6 +9,7 @@ export default class PostsIndexController extends Controller { @service store; @tracked newContent = ''; + queryParams = ['page']; @tracked @@ -29,7 +30,7 @@ export default class PostsIndexController extends Controller { const page = this.model.postsPaged.meta.page; const pages = this.model.postsPaged.meta.totalPages; this.replaceRoute({ - queryParams: {page: ((page - 1 + delta + pages) % pages) + 1}, + queryParams: { page: ((page - 1 + delta + pages) % pages) + 1 }, }); } @@ -40,7 +41,7 @@ export default class PostsIndexController extends Controller { scrollToNewForumPost() { document .getElementById('newForumPostCard') - .scrollIntoView({behavior: 'smooth', block: 'center'}); + .scrollIntoView({ behavior: 'smooth', block: 'center' }); } @action @@ -54,8 +55,8 @@ export default class PostsIndexController extends Controller { if (!this.currentPageIsLastPage) { await this.transitionToRoute({ - queryParams: {page: this.postsPaged.meta.totalPages}, - }) + queryParams: { page: this.postsPaged.meta.totalPages }, + }); next(() => { this.scrollToNewForumPost(); }); diff --git a/app/controllers/mail-moderations/destroy.js b/app/controllers/mail-moderations/destroy.js index 158f24fd3..1260169c8 100644 --- a/app/controllers/mail-moderations/destroy.js +++ b/app/controllers/mail-moderations/destroy.js @@ -2,7 +2,7 @@ import DestroyController from 'amber-ui/controllers/application/destroy'; export default class MailModerationDestroyController extends DestroyController { successMessage = 'Mail is genegeerd.'; - cancelMessage = 'Wijzigingen geannuleerd.' + cancelMessage = 'Wijzigingen geannuleerd.'; successTransitionTarget = 'mail-moderations.index'; cancelTransitionTarget = 'mail-moderations.show'; } diff --git a/app/models/forum/thread.js b/app/models/forum/thread.js index 38db95dd1..99bac7f54 100644 --- a/app/models/forum/thread.js +++ b/app/models/forum/thread.js @@ -1,10 +1,9 @@ import Model, { belongsTo, hasMany, attr } from '@ember-data/model'; -import {inject as service} from '@ember/service'; +import { inject as service } from '@ember/service'; import { isNone } from '@ember/utils'; import { tracked } from '@glimmer/tracking'; import { assign } from '@ember/polyfills'; - export default class Thread extends Model { @service store; // Properties @@ -18,18 +17,17 @@ export default class Thread extends Model { // Relations @belongsTo('user') author; @belongsTo('forum/category') category; - @hasMany('forum/post', {sort: 'created_at'}) posts; + @hasMany('forum/post', { sort: 'created_at' }) posts; @tracked postsPaged; - get firstPost() { return this.posts.get('firstObject'); } async queryPostsPaged(params) { - assign(params,{filter: {thread: this.id}, sort: 'created_at'}) + assign(params, { filter: { thread: this.id }, sort: 'created_at' }); this.postsPaged = await this.store.queryPaged('forum/post', params); } diff --git a/app/routes/forum/categories/category/threads/thread/posts/index.js b/app/routes/forum/categories/category/threads/thread/posts/index.js index f37d309e8..dc8ca0346 100644 --- a/app/routes/forum/categories/category/threads/thread/posts/index.js +++ b/app/routes/forum/categories/category/threads/thread/posts/index.js @@ -1,7 +1,10 @@ -import {AuthenticatedRoute} from 'amber-ui/routes/application/application'; -import {inject as service} from '@ember/service'; -import {action} from '@ember/object'; -import {bindKeyboardShortcuts, unbindKeyboardShortcuts,} from 'ember-keyboard-shortcuts'; +import { AuthenticatedRoute } from 'amber-ui/routes/application/application'; +import { inject as service } from '@ember/service'; +import { action } from '@ember/object'; +import { + bindKeyboardShortcuts, + unbindKeyboardShortcuts, +} from 'ember-keyboard-shortcuts'; export default class PostIndexRoute extends AuthenticatedRoute { @service router; @@ -35,9 +38,9 @@ export default class PostIndexRoute extends AuthenticatedRoute { } async model(params) { - const model = this.modelFor('forum.categories.category.threads.thread') + const model = this.modelFor('forum.categories.category.threads.thread'); await model.queryPostsPaged(params); - return model + return model; } activate() { diff --git a/app/utils/model-save.js b/app/utils/model-save.js index 205bbf91e..8cd150872 100644 --- a/app/utils/model-save.js +++ b/app/utils/model-save.js @@ -69,7 +69,7 @@ export default class ModelSaveUtil { .map((err) => err.detail) .join(', '); } else { - this.entity.errorMessage = String(error) + this.entity.errorMessage = String(error); } } } From f00b5d0140c3d351c8330dbdc17e4a9fd4d3d777 Mon Sep 17 00:00:00 2001 From: matteo Date: Sun, 23 Oct 2022 20:59:15 +0200 Subject: [PATCH 27/40] remove comment --- app/controllers/activities/edit.js | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/activities/edit.js b/app/controllers/activities/edit.js index 499214f05..7a938961a 100644 --- a/app/controllers/activities/edit.js +++ b/app/controllers/activities/edit.js @@ -7,7 +7,6 @@ import { inject as service } from '@ember/service'; import EditController from '../application/edit'; import { union } from '../../utils/array-operations'; -//todo: refactor below class to extend EditController export default class EditActivityController extends EditController { successMessage = 'Activiteit opgeslagen!'; successTransitionTarget = 'activities.show'; From 3ebeb38e0161e6291b4467113a85097332da642e Mon Sep 17 00:00:00 2001 From: matteo Date: Sun, 23 Oct 2022 20:59:58 +0200 Subject: [PATCH 28/40] start of refactoring action helper usage --- app/components/md-editor.hbs | 2 +- app/components/photo-comments/comments.hbs | 2 +- app/components/tools/board-room-presence.hbs | 4 ++-- app/controllers/application/edit.js | 5 ++++- app/controllers/debit/collections/edit.js | 5 ++++- app/templates/activities/destroy.hbs | 4 ++-- app/templates/activities/edit.hbs | 6 +++--- app/templates/activities/index.hbs | 2 +- app/templates/activities/new.hbs | 6 +++--- app/templates/activities/print-enrolled.hbs | 10 +++++----- app/templates/article-comments/destroy.hbs | 4 ++-- app/templates/articles/destroy.hbs | 4 ++-- app/templates/articles/edit.hbs | 6 +++--- app/templates/articles/index.hbs | 2 +- app/templates/articles/new.hbs | 6 +++--- app/templates/articles/show.hbs | 2 +- app/templates/books/edit.hbs | 14 +++++++------- app/templates/books/index.hbs | 2 +- app/templates/books/new.hbs | 12 ++++++------ app/templates/debit/collections/destroy.hbs | 2 +- app/templates/debit/collections/edit.hbs | 6 +++--- app/templates/debit/collections/index.hbs | 2 +- app/templates/debit/collections/new.hbs | 2 +- app/templates/debit/mandates/edit.hbs | 4 ++-- app/templates/debit/mandates/index.hbs | 2 +- app/templates/debit/mandates/new.hbs | 4 ++-- app/templates/debit/transactions/edit.hbs | 6 +++--- app/templates/forum/categories/category/edit.hbs | 4 ++-- .../forum/categories/category/threads/index.hbs | 2 +- .../forum/categories/category/threads/new.hbs | 4 ++-- .../categories/category/threads/thread/edit.hbs | 4 ++-- .../category/threads/thread/posts/destroy.hbs | 4 ++-- .../category/threads/thread/posts/edit.hbs | 2 +- .../category/threads/thread/posts/index.hbs | 4 ++-- app/templates/forum/categories/new.hbs | 4 ++-- app/templates/groups/edit.hbs | 10 +++++----- app/templates/groups/index.hbs | 2 +- app/templates/groups/new.hbs | 10 +++++----- app/templates/groups/show.hbs | 2 +- app/templates/mail-aliases/edit.hbs | 4 ++-- app/templates/mail-aliases/index.hbs | 2 +- app/templates/mail-aliases/new.hbs | 4 ++-- app/templates/photo-albums/new.hbs | 4 ++-- app/templates/photo-albums/photo-album/edit.hbs | 4 ++-- .../photo-albums/photo-album/photos/show.hbs | 2 +- app/templates/photo-comments/index.hbs | 2 +- app/templates/polls/edit.hbs | 4 ++-- app/templates/polls/index.hbs | 2 +- app/templates/polls/new.hbs | 4 ++-- app/templates/sog/name-trainer.hbs | 4 ++-- app/templates/static-pages/edit.hbs | 4 ++-- app/templates/static-pages/index.hbs | 2 +- app/templates/static-pages/new.hbs | 4 ++-- app/templates/users/batch/new.hbs | 2 +- app/templates/users/edit.hbs | 6 +++--- app/templates/users/index.hbs | 2 +- app/templates/users/members.hbs | 2 +- app/templates/users/new.hbs | 6 +++--- app/templates/users/show-groups.hbs | 2 +- 59 files changed, 125 insertions(+), 119 deletions(-) diff --git a/app/components/md-editor.hbs b/app/components/md-editor.hbs index 9ff912b43..963938d5a 100644 --- a/app/components/md-editor.hbs +++ b/app/components/md-editor.hbs @@ -1,6 +1,6 @@ {{#if editMode}} diff --git a/app/components/photo-comments/comments.hbs b/app/components/photo-comments/comments.hbs index 5ade64ab0..9c54065ae 100644 --- a/app/components/photo-comments/comments.hbs +++ b/app/components/photo-comments/comments.hbs @@ -36,7 +36,7 @@ aria-label='Reactie' minlength='1' maxlength='500' - @enter={{action 'submitPhotoComment'}} + @enter={{this.submitPhotoComment}} /> @@ -128,7 +128,7 @@ - diff --git a/app/templates/articles/edit.hbs b/app/templates/articles/edit.hbs index f4cf3818c..c77fc4249 100644 --- a/app/templates/articles/edit.hbs +++ b/app/templates/articles/edit.hbs @@ -4,9 +4,9 @@ diff --git a/app/templates/articles/new.hbs b/app/templates/articles/new.hbs index f4cf3818c..c77fc4249 100644 --- a/app/templates/articles/new.hbs +++ b/app/templates/articles/new.hbs @@ -4,9 +4,9 @@ Incasso bewerken
-
+ - @@ -35,7 +35,7 @@
diff --git a/app/templates/debit/collections/new.hbs b/app/templates/debit/collections/new.hbs index 6c0e2746e..34dde0493 100644 --- a/app/templates/debit/collections/new.hbs +++ b/app/templates/debit/collections/new.hbs @@ -35,7 +35,7 @@ @model={{model}} @property='importFile' @label='Import file' - @loadedCallback={{action 'fileLoaded'}} + @loadedCallback={{this.fileLoaded}} @validExtensions={{this.validExtensions}} @validMimetypes={{this.validMimetypes}} /> diff --git a/app/templates/debit/mandates/edit.hbs b/app/templates/debit/mandates/edit.hbs index a3a15eb5b..631c890b9 100644 --- a/app/templates/debit/mandates/edit.hbs +++ b/app/templates/debit/mandates/edit.hbs @@ -2,8 +2,8 @@ \ No newline at end of file diff --git a/app/templates/debit/mandates/index.hbs b/app/templates/debit/mandates/index.hbs index 2892a4ab1..454ff8f1b 100644 --- a/app/templates/debit/mandates/index.hbs +++ b/app/templates/debit/mandates/index.hbs @@ -6,7 +6,7 @@ @sortedAttribute={{sortedAttribute}} @sortableAttributes={{sortableAttributes}} @sortedAscending={{sortedAscending}} - @enter={{action 'selectFirstItem'}} + @enter={{this.selectFirstItem}} /> diff --git a/app/templates/debit/mandates/new.hbs b/app/templates/debit/mandates/new.hbs index 715f527e8..e833299de 100644 --- a/app/templates/debit/mandates/new.hbs +++ b/app/templates/debit/mandates/new.hbs @@ -2,8 +2,8 @@ \ No newline at end of file diff --git a/app/templates/debit/transactions/edit.hbs b/app/templates/debit/transactions/edit.hbs index 35bf3c01d..ff7db3692 100644 --- a/app/templates/debit/transactions/edit.hbs +++ b/app/templates/debit/transactions/edit.hbs @@ -2,9 +2,9 @@ \ No newline at end of file diff --git a/app/templates/forum/categories/category/edit.hbs b/app/templates/forum/categories/category/edit.hbs index 0005c2a9f..39d76b01e 100644 --- a/app/templates/forum/categories/category/edit.hbs +++ b/app/templates/forum/categories/category/edit.hbs @@ -1,6 +1,6 @@ \ No newline at end of file diff --git a/app/templates/forum/categories/category/threads/index.hbs b/app/templates/forum/categories/category/threads/index.hbs index 0f34119b7..dedad8258 100644 --- a/app/templates/forum/categories/category/threads/index.hbs +++ b/app/templates/forum/categories/category/threads/index.hbs @@ -6,7 +6,7 @@ @sortedAttribute={{sortedAttribute}} @sortableAttributes={{sortableAttributes}} @sortedAscending={{sortedAscending}} - @enter={{action 'selectFirstItem'}} + @enter={{this.selectFirstItem}} /> diff --git a/app/templates/forum/categories/category/threads/new.hbs b/app/templates/forum/categories/category/threads/new.hbs index 5a888472b..0fb63d923 100644 --- a/app/templates/forum/categories/category/threads/new.hbs +++ b/app/templates/forum/categories/category/threads/new.hbs @@ -1,6 +1,6 @@ \ No newline at end of file diff --git a/app/templates/forum/categories/category/threads/thread/edit.hbs b/app/templates/forum/categories/category/threads/thread/edit.hbs index 5a888472b..0fb63d923 100644 --- a/app/templates/forum/categories/category/threads/thread/edit.hbs +++ b/app/templates/forum/categories/category/threads/thread/edit.hbs @@ -1,6 +1,6 @@ \ No newline at end of file diff --git a/app/templates/forum/categories/category/threads/thread/posts/destroy.hbs b/app/templates/forum/categories/category/threads/thread/posts/destroy.hbs index 92e43171d..5dc7215e9 100644 --- a/app/templates/forum/categories/category/threads/thread/posts/destroy.hbs +++ b/app/templates/forum/categories/category/threads/thread/posts/destroy.hbs @@ -18,11 +18,11 @@ {{/if}}
- + {{#each @model.postsPaged as |post|}} {{#unless post.isDeleted}} {{forum/forum-post @@ -39,7 +39,7 @@
diff --git a/app/templates/forum/categories/new.hbs b/app/templates/forum/categories/new.hbs index 0005c2a9f..39d76b01e 100644 --- a/app/templates/forum/categories/new.hbs +++ b/app/templates/forum/categories/new.hbs @@ -1,6 +1,6 @@ \ No newline at end of file diff --git a/app/templates/groups/edit.hbs b/app/templates/groups/edit.hbs index c624513ab..a6c1f2103 100644 --- a/app/templates/groups/edit.hbs +++ b/app/templates/groups/edit.hbs @@ -1,11 +1,11 @@ \ No newline at end of file diff --git a/app/templates/groups/index.hbs b/app/templates/groups/index.hbs index 1008df75f..4eb239a8d 100644 --- a/app/templates/groups/index.hbs +++ b/app/templates/groups/index.hbs @@ -6,7 +6,7 @@ @sortedAttribute={{sortedAttribute}} @sortableAttributes={{sortableAttributes}} @sortedAscending={{sortedAscending}} - @enter={{action 'selectFirstItem'}} + @enter={{this.selectFirstItem}} >
diff --git a/app/templates/mail-aliases/edit.hbs b/app/templates/mail-aliases/edit.hbs index a711abc7b..aedd99f1b 100644 --- a/app/templates/mail-aliases/edit.hbs +++ b/app/templates/mail-aliases/edit.hbs @@ -1,7 +1,7 @@ diff --git a/app/templates/mail-aliases/new.hbs b/app/templates/mail-aliases/new.hbs index a711abc7b..aedd99f1b 100644 --- a/app/templates/mail-aliases/new.hbs +++ b/app/templates/mail-aliases/new.hbs @@ -1,7 +1,7 @@ \ No newline at end of file diff --git a/app/templates/photo-albums/photo-album/edit.hbs b/app/templates/photo-albums/photo-album/edit.hbs index e5fe92e0b..971bc85b3 100644 --- a/app/templates/photo-albums/photo-album/edit.hbs +++ b/app/templates/photo-albums/photo-album/edit.hbs @@ -1,7 +1,7 @@ - +
diff --git a/app/templates/photo-comments/index.hbs b/app/templates/photo-comments/index.hbs index 088501fab..57645f322 100644 --- a/app/templates/photo-comments/index.hbs +++ b/app/templates/photo-comments/index.hbs @@ -6,7 +6,7 @@ @sortedAttribute={{sortedAttribute}} @sortableAttributes={{sortableAttributes}} @sortedAscending={{sortedAscending}} - @enter={{action 'selectFirstItem'}} + @enter={{this.selectFirstItem}} /> diff --git a/app/templates/polls/edit.hbs b/app/templates/polls/edit.hbs index acf44337f..bbab1df0f 100644 --- a/app/templates/polls/edit.hbs +++ b/app/templates/polls/edit.hbs @@ -1,7 +1,7 @@ \ No newline at end of file diff --git a/app/templates/polls/index.hbs b/app/templates/polls/index.hbs index 28871a824..dce3037d8 100644 --- a/app/templates/polls/index.hbs +++ b/app/templates/polls/index.hbs @@ -6,7 +6,7 @@ @sortedAttribute={{sortedAttribute}} @sortableAttributes={{sortableAttributes}} @sortedAscending={{sortedAscending}} - @enter={{action 'selectFirstItem'}} + @enter={{this.selectFirstItem}} /> diff --git a/app/templates/polls/new.hbs b/app/templates/polls/new.hbs index acf44337f..bbab1df0f 100644 --- a/app/templates/polls/new.hbs +++ b/app/templates/polls/new.hbs @@ -1,7 +1,7 @@ \ No newline at end of file diff --git a/app/templates/sog/name-trainer.hbs b/app/templates/sog/name-trainer.hbs index a8c75d9cb..b5b058c1e 100644 --- a/app/templates/sog/name-trainer.hbs +++ b/app/templates/sog/name-trainer.hbs @@ -96,7 +96,7 @@ id='answer' class={{inputClass}} placeholder='Type hier de volledige naam' - @enter={{action 'checkAnswer'}} + @enter={{this.checkAnswer}} />