-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(emeisOptions): passing options as a function
- this enable to pass options for meta-fields of type choice as static list or as a function
- Loading branch information
1 parent
cf6395b
commit f171980
Showing
15 changed files
with
357 additions
and
317 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{{#if this.visible}} | ||
<EditForm::Element @label={{optional-translate @field.label}}> | ||
{{#if (eq @field.type "choice")}} | ||
{{#if this.options.isRunning}} | ||
<UkSpinner @ratio="1" /> | ||
{{else}} | ||
<PowerSelect | ||
@disabled={{this.disabled}} | ||
@options={{this.options.value}} | ||
@selected={{find-by "value" (get @model.metainfo @field.slug) this.options.value}} | ||
@onChange={{fn this.updateMetaField @field @model}} | ||
@placeholder={{t @field.label}} | ||
@allowClear={{true}} | ||
@renderInPlace={{true}} | ||
as |option| | ||
> | ||
{{optional-translate option.label}} | ||
</PowerSelect> | ||
{{/if}} | ||
{{/if}} | ||
{{#if (eq @field.type "text")}} | ||
<input | ||
data-test-meta-field-text={{@field.slug}} | ||
class="uk-input" | ||
type="text" | ||
value={{get @model.metainfo @field.slug}} | ||
disabled={{this.disabled}} | ||
{{on "input" (fn this.updateMetaField @field @model)}} | ||
> | ||
{{/if}} | ||
</EditForm::Element> | ||
{{/if}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { assert } from "@ember/debug"; | ||
import { action } from "@ember/object"; | ||
import { inject as service } from "@ember/service"; | ||
import Component from "@glimmer/component"; | ||
import { task } from "ember-concurrency"; | ||
import { useTask } from "ember-resources"; | ||
|
||
export default class MetaFieldComponent extends Component { | ||
@service intl; | ||
|
||
constructor(...args) { | ||
super(...args); | ||
|
||
assert("Must pass a valid field argument", this.args.field); | ||
assert("Must pass a valid model argument", this.args.model); | ||
} | ||
|
||
evaluateProperty(expression) { | ||
if (typeof expression === "boolean") return expression; | ||
if (typeof expression === "function") return expression(this.args.model); | ||
if (typeof expression === "string") return expression === "true"; | ||
return false; | ||
} | ||
|
||
get visible() { | ||
return this.evaluateProperty(this.args.field.visible); | ||
} | ||
|
||
get disabled() { | ||
return this.evaluateProperty(this.args.field.readOnly); | ||
} | ||
|
||
options = useTask(this, this.fetchOptions, () => [this.args.field.options]); | ||
|
||
@task | ||
*fetchOptions(options) { | ||
// options may be a (asnyc) function or a complex property | ||
if (typeof options !== "function") { | ||
return options; | ||
} | ||
return yield options(); | ||
} | ||
|
||
@action | ||
updateMetaField(field, model, optionOrEvent) { | ||
const value = optionOrEvent?.target?.value ?? optionOrEvent?.value; | ||
model.metainfo = { ...model.metainfo, [field.slug]: value }; | ||
model.notifyPropertyChange("metainfo"); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "ember-emeis/components/meta-field"; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.