Skip to content

Commit

Permalink
Refactor: {{action}} helper usage (#635)
Browse files Browse the repository at this point in the history
* todos

* add checks for overrides of ModelSaveUtils, using the entity property of ModelSaveUtils

* got the activity destroy controller working properly, it seems :)

* 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.

* this is starting to look like something. not perfect, but it works for now

* this should comprise the last of controllers that extend DestroyController, and they are now all in octane style! :)

* debit collection show is currently broken, do not understand why. getting late, so I will continue this some other time.

* starting to get a grip on how ember works, I think

* more progress, now also added cancel action to editcontroller, and refactoring templates to use the new action

* refactoring all usages of "Annuleren" LinkTo elements into buttons that call the cancel action from one of the Created, Edit, Destroy Controllers

* jslint

* FINALLY figured out how to do a union of ObjectProxies

* moved thread save logic to model

* more stuff

* fix debit collection controllers

* going through the controllers alphabetically, decided to add some method to the madness lol

* idk, changes from last time I worked on this

* fix js lint

* fix template lint

* I found a way to keep the model just the model, while also querying posts in a paged fashion everytime the queryparams change

* more changes

* more changes

* typo

* better handling of transitions in destroycontrollers

* I think I have had all new edit and destroy controllers

* js lint fixes

* remove comment

* start of refactoring action helper usage

* remove preventdefaults

* rewrite board room presence in octane

* use @action syntax on newPresence, and move permission check to template

* use on, fn

* modal, sidebar

* rewrite privacy-modal to octane (afaik)

* remove unused import

* action helper in public-activity-card-small

* write open and closed question components in octane

* fix lint

* fix broken submit based on #896

* fix poll form
  • Loading branch information
DrumsnChocolate authored Feb 5, 2025
1 parent 865ba61 commit fa25ea1
Show file tree
Hide file tree
Showing 56 changed files with 526 additions and 465 deletions.
6 changes: 3 additions & 3 deletions app/components/basic-modal.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class='btn-close'
data-bs-dismiss='modal'
aria-label='Close'
{{action @closeModal}}
{{on 'click' @closeModal}}
type='button'
></button>
{{/if}}
Expand All @@ -24,14 +24,14 @@
<button
type='button'
class='btn btn-secondary {{if @submitDisabled "disabled"}}'
{{action @onSubmit}}
{{on 'click' @onSubmit}}
disabled={{@submitDisabled}}
>
{{@submitText}}
</button>
{{/if}}
{{#if @closeModal}}
<button type='button' class='btn btn-default' {{action @closeModal}}>
<button type='button' class='btn btn-default' {{on 'click' @closeModal}}>
Annuleren
</button>
{{/if}}
Expand Down
2 changes: 1 addition & 1 deletion app/components/cards/public-activity-card-small.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
itemscope
itemtype='https://schema.org/Event'
class='card-body p-0'
{{action action}}
{{on 'click' @action}}
>
<div class='d-flex' data-test-public-activity-card>
<div
Expand Down
51 changes: 25 additions & 26 deletions app/components/form/closed-question.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{{#unless question.form.hasResponses}}
<div class='float-md-end mb-3'>
<FaIcon @icon='xmark' {{on 'click' (action 'deleteQuestion')}} />
<FaIcon @icon='xmark' {{on 'click' this.deleteQuestion}} />
</div>
{{/unless}}

Expand All @@ -13,8 +13,8 @@
aria-label='Vraag'
name='question'
placeholder='Vraag'
@value={{question.question}}
disabled={{question.form.hasResponses}}
@value={{@question.question}}
disabled={{@question.form.hasResponses}}
/>
</div>

Expand All @@ -25,11 +25,10 @@
<label class='visually-hidden form-label'>Vraagtype</label>
<Input::SelectInput
@class='form-select w-auto'
@required={{required}}
@options={{questionTypeOptions}}
@placeholder={{Vraagtype}}
@value={{question.fieldType}}
@disabled={{question.form.hasResponses}}
@options={{this.questionTypeOptions}}
@placeholder="vraagtype"
@value={{@question.fieldType}}
@disabled={{@question.form.hasResponses}}
/>
</div>

Expand All @@ -38,22 +37,22 @@
class='form-check-input'
@type='checkbox'
name='required'
@checked={{question.required}}
disabled={{question.form.hasResponses}}
id="question-{{question.position}}-required-check"
@checked={{@question.required}}
disabled={{@question.form.hasResponses}}
id="question-{{@question.position}}-required-check"
/>
<label class='form-check-label' for="question-{{question.position}}-required-check">Verplicht</label>
<label class='form-check-label' for="question-{{@question.position}}-required-check">Verplicht</label>
</div>
</div>
</div>

{{#unless question.form.hasResponses}}
{{#unless @question.form.hasResponses}}
<div class='col-md-7 col-sm-12'>
<div class='float-md-end'>
<button
type='button'
class='btn btn-default'
{{action 'moveQuestionUp'}}
{{on 'click' this.moveQuestionUp}}
>
<FaIcon @icon='arrow-up' />
Omhoog
Expand All @@ -62,7 +61,7 @@
<button
type='button'
class='btn btn-default'
{{action 'moveQuestionDown'}}
{{on 'click' this.moveQuestionDown}}
>
<FaIcon @icon='arrow-down' />
Omlaag
Expand All @@ -72,14 +71,14 @@
{{/unless}}
</div>

{{#each question.sortedOptions as |opt|}}
{{#each @question.sortedOptions as |opt|}}
{{#unless opt.isDeleted}}
<div class='d-flex mb-3'>
<span class='input-group-addon d-flex justify-content-center align-items-center me-3'>
<input id="question-{{question.position}}-option-{{opt.position}}-check" class="form-check-input" type={{question.fieldType}} disabled={{true}} />
<label for="question-{{question.position}}-option-{{opt.position}}-required-check"/>
<input id="question-{{@question.position}}-option-{{opt.position}}-check" class="form-check-input" type={{@question.fieldType}} disabled={{true}} />
<label for="question-{{@question.position}}-option-{{opt.position}}-required-check"/>
</span>

<div class='input-group'>
<Input
@type='text'
Expand All @@ -88,28 +87,28 @@
name='option'
placeholder='Optie'
@value={{opt.option}}
disabled={{question.form.hasResponses}}
disabled={{@question.form.hasResponses}}
/>

{{#unless question.form.hasResponses}}
{{#unless @question.form.hasResponses}}
<button
type='button'
class='btn btn-default'
{{action 'moveOptionUp' opt}}
{{on 'click' (fn this.moveOptionUp opt)}}
>
<FaIcon @icon='arrow-up' />
</button>
<button
type='button'
class='btn btn-default'
{{action 'moveOptionDown' opt}}
{{on 'click' (fn this.moveOptionDown opt)}}
>
<FaIcon @icon='arrow-down' />
</button>
<button
type='button'
class='btn btn-default'
{{action 'deleteOption' opt}}
{{on 'click' (fn this.deleteOption opt)}}
>
<FaIcon @icon='trash' />
</button>
Expand All @@ -119,8 +118,8 @@
{{/unless}}
{{/each}}

{{#unless question.form.hasResponses}}
<button type='button' class='btn btn-default mb-3' {{action 'addOption'}}>
{{#unless @question.form.hasResponses}}
<button type='button' class='btn btn-default mb-3' {{on 'click' this.addOption}}>
Optie toevoegen
</button>
{{/unless}}
77 changes: 39 additions & 38 deletions app/components/form/closed-question.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
import { ClosedQuestionTypes } from 'amber-ui/constants';
import { inject as service } from '@ember/service';
import OpenQuestionComponent from './open-question';
import { action } from '@ember/object';

export default OpenQuestionComponent.extend({
store: service(),
questionTypes: ClosedQuestionTypes,
init() {
this._super();
},
actions: {
addOption() {
const position =
this.question.get('sortedOptions.lastObject.position') + 1 || 0;
this.store.createRecord('form/closed-question-option', {
question: this.question,
position,
});
},
deleteOption(option) {
option.deleteRecord();
},
moveOptionUp(option) {
const index = this.question.get('sortedOptions').indexOf(option);
if (index > 0) {
const previousOption = this.question
.get('sortedOptions')
.objectAt(index - 1);
this.send('switchPositions', option, previousOption);
}
},
moveOptionDown(option) {
const index = this.question.get('sortedOptions').indexOf(option);
if (index < this.question.get('sortedOptions.length') - 1) {
const nextOption = this.question
.get('sortedOptions')
.objectAt(index + 1);
this.send('switchPositions', option, nextOption);
}
},
},
});
export default class ClosedQuestionComponent extends OpenQuestionComponent {
@service store;
questionTypes = ClosedQuestionTypes;
@action
addOption() {
const position =
this.question.get('sortedOptions.lastObject.position') + 1 || 0;
this.store.createRecord('form/closed-question-option', {
question: this.question,
position,
});
}

@action
deleteOption(option) {
option.deleteRecord();
}

@action
moveOptionUp(option) {
const index = this.question.get('sortedOptions').indexOf(option);
if (index > 0) {
const previousOption = this.question
.get('sortedOptions')
.objectAt(index - 1);
this.switchPositions(option, previousOption);
}
}

@action
moveOptionDown(option) {
const index = this.question.get('sortedOptions').indexOf(option);
if (index < this.question.get('sortedOptions.length') - 1) {
const nextOption = this.question.get('sortedOptions').objectAt(index + 1);
this.switchPositions(option, nextOption);
}
}
}
4 changes: 2 additions & 2 deletions app/components/form/form-form.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
<div class='card'>
<div class='card-body create-new-question'>
{{#if question.isOpenQuestion}}
{{form/open-question question form=model}}
<Form::OpenQuestion @question={{question}} @form={{model}}/>
{{else}}
{{form/closed-question question form=model}}
<Form::ClosedQuestion @question={{question}} @form={{model}}/>
{{/if}}
</div>
</div>
Expand Down
31 changes: 15 additions & 16 deletions app/components/form/open-question.hbs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<span class='fw-bold mb-3'>Open vraag</span>

{{#unless question.form.hasResponses}}
{{#unless @question.form.hasResponses}}
<div class='float-md-end mb-3'>
<FaIcon @icon='xmark' {{on 'click' (action 'deleteQuestion')}} />
<FaIcon @icon='xmark' {{on 'click' this.deleteQuestion}} />
</div>
{{/unless}}

Expand All @@ -13,8 +13,8 @@
aria-label='Vraag'
name='question'
placeholder='Vraag'
@value={{question.question}}
disabled={{question.form.hasResponses}}
@value={{@question.question}}
disabled={{@question.form.hasResponses}}
/>
</div>

Expand All @@ -25,11 +25,10 @@
<label class='visually-hidden form-label'>Vraagtype</label>
<Input::SelectInput
@class='form-select'
@required={{required}}
@options={{questionTypeOptions}}
@placeholder={{Vraagtype}}
@value={{question.fieldType}}
@disabled={{question.form.hasResponses}}
@options={{this.questionTypeOptions}}
@placeholder="vraagtype"
@value={{@question.fieldType}}
@disabled={{@question.form.hasResponses}}
/>
</div>

Expand All @@ -38,22 +37,22 @@
class='form-check-input'
@type='checkbox'
name='required'
@checked={{question.required}}
disabled={{question.form.hasResponses}}
id="question-{{question.position}}-required-check"
@checked={{@question.required}}
disabled={{@question.form.hasResponses}}
id="question-{{@question.position}}-required-check"
/>
<label class='form-check-label' for="question-{{question.position}}-required-check">Verplicht</label>
<label class='form-check-label' for="question-{{@question.position}}-required-check">Verplicht</label>
</div>
</div>
</div>

{{#unless question.form.hasResponses}}
{{#unless @question.form.hasResponses}}
<div class='col-md-7 col-sm-12'>
<div class='float-md-end'>
<button
type='button'
class='btn btn-default'
{{action 'moveQuestionUp'}}
{{on 'click' this.moveQuestionUp}}
>
<FaIcon @icon='arrow-up' />
Omhoog
Expand All @@ -62,7 +61,7 @@
<button
type='button'
class='btn btn-default'
{{action 'moveQuestionDown'}}
{{on 'click' this.moveQuestionDown}}
>
<FaIcon @icon='arrow-down' />
Omlaag
Expand Down
Loading

0 comments on commit fa25ea1

Please sign in to comment.