implemented a relative time based filtering for similar topics
Dieser Commit ist enthalten in:
Ursprung
c01055bf04
Commit
c54273b94a
7 geänderte Dateien mit 53 neuen und 13 gelöschten Zeilen
|
@ -2,9 +2,25 @@ import Component from "@ember/component";
|
||||||
import EmberObject from "@ember/object";
|
import EmberObject from "@ember/object";
|
||||||
import { cloneJSON } from "discourse-common/lib/object";
|
import { cloneJSON } from "discourse-common/lib/object";
|
||||||
import Category from "discourse/models/category";
|
import Category from "discourse/models/category";
|
||||||
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
|
import I18n from "I18n";
|
||||||
|
|
||||||
export default Component.extend({
|
export default Component.extend({
|
||||||
classNames: ["realtime-validations"],
|
classNames: ["realtime-validations"],
|
||||||
|
@discourseComputed
|
||||||
|
timeUnits() {
|
||||||
|
return [
|
||||||
|
"days",
|
||||||
|
"weeks",
|
||||||
|
"months",
|
||||||
|
"years"
|
||||||
|
].map((unit) => {
|
||||||
|
return {
|
||||||
|
id: unit,
|
||||||
|
name: I18n.t(`admin.wizard.field.validations.time_units.${unit}`)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
this._super(...arguments);
|
this._super(...arguments);
|
||||||
|
|
|
@ -22,13 +22,15 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="validation-section">
|
<div class="validation-section">
|
||||||
<div class="setting-label">
|
<div class="setting-label">
|
||||||
<label>{{i18n 'admin.wizard.field.validations.date_after'}}</label>
|
<label>{{i18n 'admin.wizard.field.validations.time_after'}}</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="setting-value">
|
<div class="setting-value">
|
||||||
{{date-picker-past
|
{{input type="number" class="time-n-value" value=props.n_value}}
|
||||||
value=(readonly props.date_after)
|
{{combo-box
|
||||||
containerId="date-container"
|
value=(readonly props.time_unit)
|
||||||
onSelect=(action (mut props.date_after))}}
|
content=timeUnits
|
||||||
|
class="time-unit-selector"
|
||||||
|
onChange=(action (mut props.time_unit))}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="validation-section">
|
<div class="validation-section">
|
||||||
|
|
|
@ -124,7 +124,8 @@ export default WizardFieldValidator.extend({
|
||||||
this.backendValidate({
|
this.backendValidate({
|
||||||
title: this.get("field.value"),
|
title: this.get("field.value"),
|
||||||
categories: this.get("validation.categories"),
|
categories: this.get("validation.categories"),
|
||||||
date_after: this.get("validation.date_after"),
|
time_unit: this.get("validation.time_unit"),
|
||||||
|
n_value: this.get("validation.n_value")
|
||||||
}).then((result) => {
|
}).then((result) => {
|
||||||
const similarTopics = A(
|
const similarTopics = A(
|
||||||
deepMerge(result["topics"], result["similar_topics"])
|
deepMerge(result["topics"], result["similar_topics"])
|
||||||
|
|
|
@ -680,3 +680,13 @@
|
||||||
.wizard.category-selector {
|
.wizard.category-selector {
|
||||||
width: 200px !important;
|
width: 200px !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.time-n-value {
|
||||||
|
width: 70px;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
|
||||||
|
.select-kit.time-unit-selector {
|
||||||
|
width: 80px;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
|
|
@ -184,7 +184,12 @@ en:
|
||||||
above: "Above"
|
above: "Above"
|
||||||
below: "Below"
|
below: "Below"
|
||||||
categories: "Categories"
|
categories: "Categories"
|
||||||
date_after: "Date After"
|
time_after: "Time After"
|
||||||
|
time_units:
|
||||||
|
days: "Days"
|
||||||
|
weeks: "Weeks"
|
||||||
|
months: "Months"
|
||||||
|
years: "Years"
|
||||||
|
|
||||||
type:
|
type:
|
||||||
text: "Text"
|
text: "Text"
|
||||||
|
|
|
@ -21,8 +21,9 @@ class CustomWizard::RealtimeValidation::SimilarTopics
|
||||||
title = params[:title]
|
title = params[:title]
|
||||||
raw = params[:raw]
|
raw = params[:raw]
|
||||||
categories = params[:categories]
|
categories = params[:categories]
|
||||||
date_after = params[:date_after]
|
n_value = params[:n_value]
|
||||||
|
time_unit = params[:time_unit]
|
||||||
|
|
||||||
result = CustomWizard::RealtimeValidation::Result.new(:similar_topic)
|
result = CustomWizard::RealtimeValidation::Result.new(:similar_topic)
|
||||||
|
|
||||||
if title.length < SiteSetting.min_title_similar_length || !Topic.count_exceeds_minimum?
|
if title.length < SiteSetting.min_title_similar_length || !Topic.count_exceeds_minimum?
|
||||||
|
@ -31,7 +32,12 @@ class CustomWizard::RealtimeValidation::SimilarTopics
|
||||||
|
|
||||||
topics = Topic.similar_to(title, raw, user).to_a
|
topics = Topic.similar_to(title, raw, user).to_a
|
||||||
topics.select! { |t| categories.include?(t.category.id.to_s) } if categories.present?
|
topics.select! { |t| categories.include?(t.category.id.to_s) } if categories.present?
|
||||||
topics.select! { |t| t.created_at > DateTime.parse(date_after) } if date_after.present?
|
|
||||||
|
if n_value.present? and time_unit.present?
|
||||||
|
if n_value.to_i > 0
|
||||||
|
topics.select! { |t| t.created_at >= n_value.to_i.send(time_unit).ago }
|
||||||
|
end
|
||||||
|
end
|
||||||
topics.map! { |t| SimilarTopic.new(t) }
|
topics.map! { |t| SimilarTopic.new(t) }
|
||||||
|
|
||||||
result.items = topics
|
result.items = topics
|
||||||
|
|
|
@ -30,12 +30,12 @@ describe ::CustomWizard::RealtimeValidation::SimilarTopics do
|
||||||
expect(result.items.length).to eq(1)
|
expect(result.items.length).to eq(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "filters topics based on created date" do
|
it "filters topics based on Time After setting" do
|
||||||
topic.update!(created_at: 1.day.ago)
|
topic.update!(created_at: 23.hours.ago)
|
||||||
cat_topic.update!(created_at: 2.days.ago)
|
cat_topic.update!(created_at: 2.days.ago)
|
||||||
|
|
||||||
validation = ::CustomWizard::RealtimeValidation::SimilarTopics.new(user)
|
validation = ::CustomWizard::RealtimeValidation::SimilarTopics.new(user)
|
||||||
result = validation.perform({ title: "matching similar", date_after: 1.day.ago.to_date.to_s })
|
result = validation.perform({ title: "matching similar", n_value: 1, time_unit: "days" })
|
||||||
expect(result.items.length).to eq(1)
|
expect(result.items.length).to eq(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Laden …
In neuem Issue referenzieren