IMPR: simplified similar topics template (#73)
* IMPR: simplified similar topics template * renamed label to key * minor formatting * added dasherize logic for classnames
Dieser Commit ist enthalten in:
Ursprung
19cc7a7365
Commit
3d9a564d63
2 geänderte Dateien mit 59 neuen und 16 gelöschten Zeilen
|
@ -7,6 +7,7 @@ import EmberObject, { computed } from "@ember/object";
|
|||
import { notEmpty, and, equal, empty } from "@ember/object/computed";
|
||||
import discourseComputed from "discourse-common/utils/decorators";
|
||||
import { categoryBadgeHTML } from "discourse/helpers/category-link";
|
||||
import { dasherize } from "@ember/string";
|
||||
|
||||
export default WizardFieldValidator.extend({
|
||||
classNames: ['similar-topics-validator'],
|
||||
|
@ -27,6 +28,7 @@ export default WizardFieldValidator.extend({
|
|||
return this.noSimilarTopics && !this.typing;
|
||||
}),
|
||||
hasValidationCategories: notEmpty('validationCategories'),
|
||||
showValidationCategories: and('showDefault', 'hasValidationCategories'),
|
||||
|
||||
@discourseComputed('validation.categories')
|
||||
validationCategories(categoryIds) {
|
||||
|
@ -40,6 +42,50 @@ export default WizardFieldValidator.extend({
|
|||
return categories.map(category => categoryBadgeHTML(category)).join("");
|
||||
},
|
||||
|
||||
@discourseComputed(
|
||||
'loading',
|
||||
'showSimilarTopics',
|
||||
'showNoSimilarTopics',
|
||||
'showValidationCategories',
|
||||
'showDefault'
|
||||
)
|
||||
currentState(
|
||||
loading,
|
||||
showSimilarTopics,
|
||||
showNoSimilarTopics,
|
||||
showValidationCategories,
|
||||
showDefault
|
||||
) {
|
||||
switch (true) {
|
||||
case loading:
|
||||
return 'loading';
|
||||
case showSimilarTopics:
|
||||
return 'results';
|
||||
case showNoSimilarTopics:
|
||||
return 'no_results';
|
||||
case showValidationCategories:
|
||||
return 'default_categories';
|
||||
case showDefault:
|
||||
return 'default';
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
@discourseComputed('currentState')
|
||||
currentStateClass (currentState) {
|
||||
if (currentState) return `similar-topics-${dasherize(currentState)}`;
|
||||
|
||||
return "similar-topics";
|
||||
},
|
||||
|
||||
@discourseComputed('currentState')
|
||||
currentStateKey (currentState) {
|
||||
if (currentState) return `realtime_validations.similar_topics.${currentState}`;
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
validate() {},
|
||||
|
||||
@observes("field.value")
|
||||
|
|
|
@ -1,16 +1,13 @@
|
|||
{{#if loading}}
|
||||
<label>{{i18n 'realtime_validations.similar_topics.loading'}}</label>
|
||||
{{else if showSimilarTopics}}
|
||||
<label>{{i18n 'realtime_validations.similar_topics.results'}}</label>
|
||||
{{wizard-similar-topics topics=similarTopics}}
|
||||
{{else if showNoSimilarTopics}}
|
||||
<label>{{i18n 'realtime_validations.similar_topics.no_results'}}</label>
|
||||
{{else if showDefault}}
|
||||
{{#if hasValidationCategories}}
|
||||
<label>{{{i18n 'realtime_validations.similar_topics.default_categories' catLinks=catLinks}}}</label>
|
||||
<label class={{currentStateClass}}>
|
||||
{{#if currentState}}
|
||||
{{#if showValidationCategories}}
|
||||
{{html-safe (i18n currentStateKey catLinks=catLinks)}}
|
||||
{{else}}
|
||||
<label>{{i18n 'realtime_validations.similar_topics.default'}}</label>
|
||||
{{i18n currentStateKey}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
<label></label>
|
||||
{{/if}}
|
||||
</label>
|
||||
|
||||
{{#if showSimilarTopics}}
|
||||
{{wizard-similar-topics topics=similarTopics}}
|
||||
{{/if}}
|
Laden …
In neuem Issue referenzieren