From 41588ca7e9f31ef0f8e3df78532a7304775ab752 Mon Sep 17 00:00:00 2001 From: DrumsnChocolate Date: Sun, 3 Nov 2024 23:30:32 +0100 Subject: [PATCH 01/10] rewrite form-form in octane --- app/components/form/form-form.hbs | 12 +++--- app/components/form/form-form.js | 54 +++++++++++++------------- app/components/forms/activity-form.hbs | 2 +- 3 files changed, 34 insertions(+), 34 deletions(-) diff --git a/app/components/form/form-form.hbs b/app/components/form/form-form.hbs index e71284722..762b398a7 100644 --- a/app/components/form/form-form.hbs +++ b/app/components/form/form-form.hbs @@ -1,10 +1,10 @@ @@ -26,9 +26,9 @@
{{#if question.isOpenQuestion}} - + {{else}} - + {{/if}}
@@ -39,14 +39,14 @@ diff --git a/app/components/form/form-form.js b/app/components/form/form-form.js index 038070ff0..16789f49b 100644 --- a/app/components/form/form-form.js +++ b/app/components/form/form-form.js @@ -1,31 +1,31 @@ import { inject as service } from '@ember/service'; -import Component from '@ember/component'; +import Component from '@glimmer/component'; +import { action } from '@ember/object'; -export const FormFormComponent = Component.extend({ - model: null, - store: service(), - actions: { - createQuestion(modelClass, fieldType) { - const form = this.model; - const position = form.get('sortedQuestions.lastObject.position') + 1 || 0; - this.store.createRecord(modelClass, { - form, - fieldType, - position, - required: true, - }); - }, - addOpenQuestion() { - this.send('createQuestion', 'form/open-question', 'text'); - }, - addClosedQuestion() { - this.send('createQuestion', 'form/closed-question', 'radio'); - }, - }, -}); +export default class FormFormComponent extends Component { + @service store; + get model() { + return this.args.model; + } -FormFormComponent.reopenClass({ - positionalParams: ['model'], -}); + createQuestion(modelClass, fieldType) { + const form = this.model; + const position = form.get('sortedQuestions.lastObject.position') + 1 || 0; + this.store.createRecord(modelClass, { + form, + fieldType, + position, + required: true, + }); + } -export default FormFormComponent; + @action + addOpenQuestion() { + this.createQuestion('form/open-question', 'text'); + } + + @action + addClosedQuestion() { + this.createQuestion('form/closed-question', 'radio'); + } +} diff --git a/app/components/forms/activity-form.hbs b/app/components/forms/activity-form.hbs index 66b21e1a5..3cdfca295 100644 --- a/app/components/forms/activity-form.hbs +++ b/app/components/forms/activity-form.hbs @@ -171,7 +171,7 @@
Inschrijflijst
- {{form/form-form @model.form}} +
{{/if}} \ No newline at end of file From f65240d59ac46968ba0617d39ab1fdec007c674e Mon Sep 17 00:00:00 2001 From: DrumsnChocolate Date: Sun, 3 Nov 2024 23:38:30 +0100 Subject: [PATCH 02/10] rewrite responses-table-card in octane --- app/components/form/responses-table-card.hbs | 12 ++---- app/components/form/responses-table-card.js | 44 +++++++++----------- 2 files changed, 24 insertions(+), 32 deletions(-) diff --git a/app/components/form/responses-table-card.hbs b/app/components/form/responses-table-card.hbs index 065fc9b78..8e58b3c36 100644 --- a/app/components/form/responses-table-card.hbs +++ b/app/components/form/responses-table-card.hbs @@ -1,17 +1,17 @@ -{{#if form.amountOfResponses}} +{{#if @form.amountOfResponses}}
Inschrijvingen
-
- {{form/responses-table - form - form.responses - showAllergyInfo=showAllergyInfo - }} +
{{else}} diff --git a/app/components/form/responses-table-card.js b/app/components/form/responses-table-card.js index 2cf9777f4..bf7d2cb6f 100644 --- a/app/components/form/responses-table-card.js +++ b/app/components/form/responses-table-card.js @@ -1,26 +1,22 @@ -import Component from '@ember/component'; +import Component from '@glimmer/component'; import { inject as service } from '@ember/service'; +import { action } from '@ember/object'; +import { tracked } from '@glimmer/tracking'; -const FormResponsesTableCardComponent = Component.extend({ - session: service('session'), - actions: { - copyUsernames() { - let usernames = this.form - .get('responses') - .map((response) => response.get('user.username')); - if (!this.form.currentUserResponseCompleted) { - usernames = usernames.filter( - (name) => name !== this.session.currentUser.username - ); - } - usernames = usernames.join('\n'); - navigator.clipboard.writeText(usernames); - }, - }, -}); - -FormResponsesTableCardComponent.reopenClass({ - positionalParams: ['form'], -}); - -export default FormResponsesTableCardComponent; +export default class FormResponsesTableCardComponent extends Component { + @service session; + @tracked showAllergyInfo = false; + @action + copyUsernames() { + let usernames = this.form + .get('responses') + .map((response) => response.get('user.username')); + if (!this.form.currentUserResponseCompleted) { + usernames = usernames.filter( + (name) => name !== this.session.currentUser.username + ); + } + usernames = usernames.join('\n'); + navigator.clipboard.writeText(usernames); + } +} From 3b4e44b461e4f2a2b6db0cf8a794855f6b49d66a Mon Sep 17 00:00:00 2001 From: DrumsnChocolate Date: Sun, 3 Nov 2024 23:53:45 +0100 Subject: [PATCH 03/10] rewrite response-card in octane --- .../form/response/response-card.hbs | 46 ++++++------ app/components/form/response/response-card.js | 70 ++++++++----------- 2 files changed, 52 insertions(+), 64 deletions(-) diff --git a/app/components/form/response/response-card.hbs b/app/components/form/response/response-card.hbs index 84f053c9f..a39539d62 100644 --- a/app/components/form/response/response-card.hbs +++ b/app/components/form/response/response-card.hbs @@ -1,25 +1,27 @@ -
-
-
Inschrijven
- {{form-opened-label form}} +
+
+
+
Inschrijven
+ {{form-opened-label @form}} +
-
-
-
- {{form/response/response-form form response}} +
+ + - - {{#if form.questions}} - - Annuleren - - Vragen met een * zijn verplicht - {{/if}} - - + + {{#if @form.questions}} + + Annuleren + + Vragen met een * zijn verplicht + {{/if}} + + +
\ No newline at end of file diff --git a/app/components/form/response/response-card.js b/app/components/form/response/response-card.js index 0e184c17f..2fa6f365c 100644 --- a/app/components/form/response/response-card.js +++ b/app/components/form/response/response-card.js @@ -1,45 +1,31 @@ -import Component from '@ember/component'; +import Component from '@glimmer/component'; import { inject as service } from '@ember/service'; +import { action } from '@ember/object'; +import { tracked } from '@glimmer/tracking'; -const FormResponseCardComponent = Component.extend({ - flashNotice: service('flash-notice'), - classNames: ['card'], - form: null, - response: null, - errorMessage: null, - actions: { - submitResponse() { - this.response - .saveWithAnswers() - .then(() => { - // The response is the first thing that is saved (in order to save answers), so currently the response is - // always 'incomplete'. Furthermore, the form has a field 'amountOfResponses' which should be updated. - // We now reload the response and the corresponding form. - this.response.reload(); - this.form.reload(); - this.flashNotice.sendSuccess('Inschrijving opgeslagen'); - }) - .catch((error) => { - this.set('errorMessage', error.message); - if ( - error.payload?.errors && - error.payload.errors.isAny( - 'source.pointer', - '/data/attributes/user' - ) - ) { - this.set( - 'errorMessage', - 'Er is al een response gevonden, probeer eerst te refreshen, zie je dit formulier dan nog? Neem dan contact op met de ict-commissie.' - ); - } - }); - }, - }, -}); +export default class FormResponseCardComponent extends Component { + @service flashNotice; + @tracked errorMessage = null; -FormResponseCardComponent.reopenClass({ - positionalParams: ['form', 'response'], -}); - -export default FormResponseCardComponent; + @action + async submitResponse() { + try { + await this.args.response.saveWithAnswers(); + // The response is the first thing that is saved (in order to save answers), so currently the response is + // always 'incomplete'. Furthermore, the form has a field 'amountOfResponses' which should be updated. + // We now reload the response and the corresponding form. + this.args.response.reload(); + this.args.form.reload(); + this.flashNotice.sendSuccess('Inschrijving opgeslagen'); + } catch (error) { + this.errorMessage = error.message; + if ( + error.payload?.errors && + error.payload.errors.isAny('source.pointer', '/data/attributes/user') + ) { + this.errorMessage = + 'Er is al een response gevonden, probeer eerst te refreshen, zie je dit formulier dan nog? Neem dan contact op met de ict-commissie.'; + } + } + } +} From 4d29d7b76d7353ff7ceef338ccfff8db55468564 Mon Sep 17 00:00:00 2001 From: DrumsnChocolate Date: Tue, 5 Nov 2024 23:01:59 +0100 Subject: [PATCH 04/10] introduce prevent-default helper --- app/components/form/response/response-card.hbs | 2 +- app/helpers/prevent-default.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 app/helpers/prevent-default.js diff --git a/app/components/form/response/response-card.hbs b/app/components/form/response/response-card.hbs index a39539d62..5f35765b5 100644 --- a/app/components/form/response/response-card.hbs +++ b/app/components/form/response/response-card.hbs @@ -6,7 +6,7 @@
-
+ Date: Tue, 5 Nov 2024 23:07:10 +0100 Subject: [PATCH 05/10] apply prevent-default for more occurrences of {{on 'submit'}} --- app/controllers/login.js | 4 +--- app/templates/debit/collections/collection/edit.hbs | 2 +- app/templates/login.hbs | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/controllers/login.js b/app/controllers/login.js index 31558399e..fa28c31b2 100644 --- a/app/controllers/login.js +++ b/app/controllers/login.js @@ -14,9 +14,7 @@ export default class LoginController extends Controller { @tracked twoFactorRequired; @action - async authenticate(e) { - e.preventDefault(); - + async authenticate() { const headers = {}; if (this.twoFactorRequired) { headers['X-Amber-OTP'] = this.verificationCode; diff --git a/app/templates/debit/collections/collection/edit.hbs b/app/templates/debit/collections/collection/edit.hbs index 927b79b51..8d3315a46 100644 --- a/app/templates/debit/collections/collection/edit.hbs +++ b/app/templates/debit/collections/collection/edit.hbs @@ -3,7 +3,7 @@
{{if @model.isNew 'Incasso aanmaken' 'Incasso wijzigen'}}
- +
- +
{{#if errorMessage}}