Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from fkm/feature/custom-widgets
Custom widgets for single and multiple choice questions
- Loading branch information
Showing
19 changed files
with
381 additions
and
13 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
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,81 @@ | ||
import Component from "@ember/component"; | ||
import { computed } from "@ember/object"; | ||
import { inject as service } from "@ember/service"; | ||
import layout from "../../../templates/components/cf-field/input/powerselect"; | ||
|
||
/** | ||
* Dropdown component for the single and multiple choice question type | ||
* | ||
* @class CfFieldInputPowerSelectComponent | ||
* @argument {Field} field The field for this input type | ||
*/ | ||
export default Component.extend({ | ||
layout, | ||
tagName: "", | ||
intl: service(), | ||
|
||
multiple: computed("field.question.__typename", function() { | ||
return this.get("field.question.__typename").startsWith("Multiple"); | ||
}), | ||
|
||
choices: computed( | ||
"multiple", | ||
"field.question.{choiceOptions,multipleChoiceOptions}.edges", | ||
function() { | ||
const options = this.get("multiple") | ||
? this.get("field.question.multipleChoiceOptions") | ||
: this.get("field.question.choiceOptions"); | ||
|
||
return options.edges.map(edge => edge.node); | ||
} | ||
), | ||
|
||
selected: computed( | ||
"field.answer.{_valueKey,listValue,stringValue}", | ||
function() { | ||
const key = this.get("field.answer._valueKey"); | ||
const answers = this.get(`field.answer.${key}`); | ||
|
||
if (!answers) { | ||
return null; | ||
} | ||
|
||
const selection = this.get("choices").filter(choice => { | ||
return answers.includes(choice.slug); | ||
}); | ||
|
||
return key === "stringValue" ? selection[0] : selection; | ||
} | ||
), | ||
|
||
componentName: computed("multiple", function() { | ||
return this.get("multiple") ? "power-select-multiple" : "power-select"; | ||
}), | ||
|
||
searchEnabled: computed("choices", function() { | ||
return this.get("choices").length > 10; | ||
}), | ||
|
||
placeholder: computed("multiple", function() { | ||
const suffix = this.get("multiple") ? "multiple" : "single"; | ||
const path = `caluma.form.power-select.placeholder-${suffix}`; | ||
return this.get("intl").t(path); | ||
}), | ||
|
||
actions: { | ||
change: function(choices) { | ||
let value = null; | ||
|
||
if (Array.isArray(choices)) { | ||
value = choices.map(choice => choice.slug); | ||
} else if (choices !== null) { | ||
value = choices.slug; | ||
} | ||
// ELSE will never be taken as long as we don't allow for empty | ||
// selections in single choice fields. Empty selections must first be | ||
// implemented/allowed by the backend. | ||
|
||
this.onSave(value); | ||
} | ||
} | ||
}); |
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 |
---|---|---|
|
@@ -3,5 +3,6 @@ fragment QuestionInfo on Question { | |
label | ||
isRequired | ||
isHidden | ||
meta | ||
isArchived | ||
} |
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,20 @@ | ||
{{#component componentName | ||
options=choices | ||
selected=selected | ||
disabled=disabled | ||
allowClear=false | ||
preventScroll=true | ||
searchEnabled=searchEnabled | ||
searchField="label" | ||
|
||
placeholder=placeholder | ||
loadingMessage=(t "caluma.form.power-select.options-loading") | ||
searchMessage=(t "caluma.form.power-select.options-empty") | ||
searchPlaceholder=(t "caluma.form.power-select.search-placeholder") | ||
noMatchesMessage=(t "caluma.form.power-select.search-empty") | ||
|
||
onchange=(action "change") | ||
as |choice| | ||
}} | ||
{{choice.label}} | ||
{{/component}} |
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-caluma/components/cf-field/input/powerselect"; |
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,17 @@ | ||
$ember-power-select-focus-outline: 0; | ||
$ember-power-select-border-color: #e5e5e5; | ||
$ember-power-select-default-border-radius: 0; | ||
$ember-power-select-line-height: 38px; | ||
|
||
$ember-power-select-selected-background: #3799ad; | ||
$ember-power-select-multiple-selection-color: #ffffff; | ||
$ember-power-select-multiple-selection-background-color: $ember-power-select-selected-background; | ||
|
||
$ember-power-select-multiple-option-padding: 0 8px; | ||
$ember-power-select-multiple-option-line-height: 32px; | ||
$ember-power-select-multiple-option-border-color: $ember-power-select-border-color; | ||
|
||
$ember-power-select-highlighted-color: #ffffff; | ||
$ember-power-select-highlighted-background: lighten($ember-power-select-selected-background, 10%); | ||
|
||
@import "ember-power-select"; |
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
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
Oops, something went wrong.