Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-22 17:30:29 +01:00
IMPR: added a state for insufficient characters
Dieser Commit ist enthalten in:
Ursprung
04b2b87ea2
Commit
c62f1ac96f
3 geänderte Dateien mit 24 neuen und 20 gelöschten Zeilen
|
@ -4,7 +4,7 @@ import { observes } from "discourse-common/utils/decorators";
|
||||||
import { cancel, later } from "@ember/runloop";
|
import { cancel, later } from "@ember/runloop";
|
||||||
import { A } from "@ember/array";
|
import { A } from "@ember/array";
|
||||||
import EmberObject, { computed } from "@ember/object";
|
import EmberObject, { computed } from "@ember/object";
|
||||||
import { notEmpty, and, equal, empty } from "@ember/object/computed";
|
import { notEmpty, and, equal, empty, alias } 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";
|
import { dasherize } from "@ember/string";
|
||||||
|
@ -12,7 +12,8 @@ import { dasherize } from "@ember/string";
|
||||||
export default WizardFieldValidator.extend({
|
export default WizardFieldValidator.extend({
|
||||||
classNames: ['similar-topics-validator'],
|
classNames: ['similar-topics-validator'],
|
||||||
similarTopics: null,
|
similarTopics: null,
|
||||||
hasInput: notEmpty('field.value'),
|
input: alias('field.value'),
|
||||||
|
hasInput: notEmpty('input'),
|
||||||
hasSimilarTopics: notEmpty('similarTopics'),
|
hasSimilarTopics: notEmpty('similarTopics'),
|
||||||
hasNotSearched: equal('similarTopics', null),
|
hasNotSearched: equal('similarTopics', null),
|
||||||
noSimilarTopics: computed('similarTopics', function() {
|
noSimilarTopics: computed('similarTopics', function() {
|
||||||
|
@ -21,6 +22,9 @@ export default WizardFieldValidator.extend({
|
||||||
showDefault: computed('hasNotSearched', 'hasInput', 'typing', function() {
|
showDefault: computed('hasNotSearched', 'hasInput', 'typing', function() {
|
||||||
return this.hasInput && (this.hasNotSearched || this.typing);
|
return this.hasInput && (this.hasNotSearched || this.typing);
|
||||||
}),
|
}),
|
||||||
|
insufficientCharacters: computed('typing', 'input', function() {
|
||||||
|
return this.hasInput && this.input.length < 5 && !this.typing;
|
||||||
|
}),
|
||||||
showSimilarTopics: computed('typing', 'hasSimilarTopics', function() {
|
showSimilarTopics: computed('typing', 'hasSimilarTopics', function() {
|
||||||
return this.hasSimilarTopics && !this.typing;
|
return this.hasSimilarTopics && !this.typing;
|
||||||
}),
|
}),
|
||||||
|
@ -28,7 +32,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'),
|
insufficientCharactersCategories: and('insufficientCharacters', 'hasValidationCategories'),
|
||||||
|
|
||||||
@discourseComputed('validation.categories')
|
@discourseComputed('validation.categories')
|
||||||
validationCategories(categoryIds) {
|
validationCategories(categoryIds) {
|
||||||
|
@ -46,15 +50,15 @@ export default WizardFieldValidator.extend({
|
||||||
'loading',
|
'loading',
|
||||||
'showSimilarTopics',
|
'showSimilarTopics',
|
||||||
'showNoSimilarTopics',
|
'showNoSimilarTopics',
|
||||||
'showValidationCategories',
|
'insufficientCharacters',
|
||||||
'showDefault'
|
'insufficientCharactersCategories'
|
||||||
)
|
)
|
||||||
currentState(
|
currentState(
|
||||||
loading,
|
loading,
|
||||||
showSimilarTopics,
|
showSimilarTopics,
|
||||||
showNoSimilarTopics,
|
showNoSimilarTopics,
|
||||||
showValidationCategories,
|
insufficientCharacters,
|
||||||
showDefault
|
insufficientCharactersCategories
|
||||||
) {
|
) {
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case loading:
|
case loading:
|
||||||
|
@ -63,10 +67,10 @@ export default WizardFieldValidator.extend({
|
||||||
return 'results';
|
return 'results';
|
||||||
case showNoSimilarTopics:
|
case showNoSimilarTopics:
|
||||||
return 'no_results';
|
return 'no_results';
|
||||||
case showValidationCategories:
|
case insufficientCharactersCategories:
|
||||||
return 'default_categories';
|
return 'insufficient_characters_categories';
|
||||||
case showDefault:
|
case insufficientCharacters:
|
||||||
return 'default';
|
return 'insufficient_characters';
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -97,11 +101,6 @@ export default WizardFieldValidator.extend({
|
||||||
|
|
||||||
this.set("typing", true);
|
this.set("typing", true);
|
||||||
|
|
||||||
if (value && value.length < 5) {
|
|
||||||
this.set('similarTopics', null);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const lastKeyUp = new Date();
|
const lastKeyUp = new Date();
|
||||||
this._lastKeyUp = lastKeyUp;
|
this._lastKeyUp = lastKeyUp;
|
||||||
|
|
||||||
|
@ -114,6 +113,11 @@ export default WizardFieldValidator.extend({
|
||||||
}
|
}
|
||||||
this.set("typing", false);
|
this.set("typing", false);
|
||||||
|
|
||||||
|
if (value && value.length < 5) {
|
||||||
|
this.set('similarTopics', null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.updateSimilarTopics();
|
this.updateSimilarTopics();
|
||||||
}, 1000);
|
}, 1000);
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<label class={{currentStateClass}}>
|
<label class={{currentStateClass}}>
|
||||||
{{#if currentState}}
|
{{#if currentState}}
|
||||||
{{#if showValidationCategories}}
|
{{#if insufficientCharactersCategories}}
|
||||||
{{html-safe (i18n currentStateKey catLinks=catLinks)}}
|
{{html-safe (i18n currentStateKey catLinks=catLinks)}}
|
||||||
{{else}}
|
{{else}}
|
||||||
{{i18n currentStateKey}}
|
{{i18n currentStateKey}}
|
||||||
|
|
|
@ -528,8 +528,8 @@ en:
|
||||||
|
|
||||||
realtime_validations:
|
realtime_validations:
|
||||||
similar_topics:
|
similar_topics:
|
||||||
default: "When you stop typing we'll look for similar topics."
|
insufficient_characters: "Type a minimum 5 characters to start looking for similar topics"
|
||||||
default_categories: "When you stop typing we'll look for similar topics in %{catLinks}"
|
insufficient_characters_categories: "Type a minimum 5 characters to start looking for similar topics in %{catLinks}"
|
||||||
results: "Your topic is similar to..."
|
results: "Your topic is similar to..."
|
||||||
no_results: "No similar topics."
|
no_results: "No similar topics."
|
||||||
loading: "Looking for similar topics..."
|
loading: "Looking for similar topics..."
|
||||||
|
|
Laden …
In neuem Issue referenzieren