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 { notEmpty, and, equal, empty } from "@ember/object/computed";
|
||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
import { categoryBadgeHTML } from "discourse/helpers/category-link";
|
import { categoryBadgeHTML } from "discourse/helpers/category-link";
|
||||||
|
import { dasherize } from "@ember/string";
|
||||||
|
|
||||||
export default WizardFieldValidator.extend({
|
export default WizardFieldValidator.extend({
|
||||||
classNames: ['similar-topics-validator'],
|
classNames: ['similar-topics-validator'],
|
||||||
|
@ -27,6 +28,7 @@ export default WizardFieldValidator.extend({
|
||||||
return this.noSimilarTopics && !this.typing;
|
return this.noSimilarTopics && !this.typing;
|
||||||
}),
|
}),
|
||||||
hasValidationCategories: notEmpty('validationCategories'),
|
hasValidationCategories: notEmpty('validationCategories'),
|
||||||
|
showValidationCategories: and('showDefault', 'hasValidationCategories'),
|
||||||
|
|
||||||
@discourseComputed('validation.categories')
|
@discourseComputed('validation.categories')
|
||||||
validationCategories(categoryIds) {
|
validationCategories(categoryIds) {
|
||||||
|
@ -39,7 +41,51 @@ export default WizardFieldValidator.extend({
|
||||||
catLinks(categories) {
|
catLinks(categories) {
|
||||||
return categories.map(category => categoryBadgeHTML(category)).join("");
|
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() {},
|
validate() {},
|
||||||
|
|
||||||
@observes("field.value")
|
@observes("field.value")
|
||||||
|
|
|
@ -1,16 +1,13 @@
|
||||||
{{#if loading}}
|
<label class={{currentStateClass}}>
|
||||||
<label>{{i18n 'realtime_validations.similar_topics.loading'}}</label>
|
{{#if currentState}}
|
||||||
{{else if showSimilarTopics}}
|
{{#if showValidationCategories}}
|
||||||
<label>{{i18n 'realtime_validations.similar_topics.results'}}</label>
|
{{html-safe (i18n currentStateKey catLinks=catLinks)}}
|
||||||
{{wizard-similar-topics topics=similarTopics}}
|
{{else}}
|
||||||
{{else if showNoSimilarTopics}}
|
{{i18n currentStateKey}}
|
||||||
<label>{{i18n 'realtime_validations.similar_topics.no_results'}}</label>
|
{{/if}}
|
||||||
{{else if showDefault}}
|
|
||||||
{{#if hasValidationCategories}}
|
|
||||||
<label>{{{i18n 'realtime_validations.similar_topics.default_categories' catLinks=catLinks}}}</label>
|
|
||||||
{{else}}
|
|
||||||
<label>{{i18n 'realtime_validations.similar_topics.default'}}</label>
|
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{else}}
|
</label>
|
||||||
<label></label>
|
|
||||||
{{/if}}
|
{{#if showSimilarTopics}}
|
||||||
|
{{wizard-similar-topics topics=similarTopics}}
|
||||||
|
{{/if}}
|
||||||
|
|
Laden …
In neuem Issue referenzieren