mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 12:53:42 +08:00
FIX: Fix subcategory, tag drops and none values (#11934)
* FIX: Generate correct URLs for category and tag drops * DEV: Remove unused properties * FIX: No subcategory and tag filter did not work
This commit is contained in:
parent
fad1fac196
commit
d89c5aedbe
|
@ -494,4 +494,23 @@ export function prefixProtocol(url) {
|
||||||
: url;
|
: url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getCategoryAndTagUrl(category, subcategories, tag) {
|
||||||
|
let url;
|
||||||
|
|
||||||
|
if (category) {
|
||||||
|
url = category.url;
|
||||||
|
if (!subcategories) {
|
||||||
|
url += "/none";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag) {
|
||||||
|
url = url
|
||||||
|
? "/tags" + url + "/" + tag.toLowerCase()
|
||||||
|
: "/tag/" + tag.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
return url || "/";
|
||||||
|
}
|
||||||
|
|
||||||
export default _urlInstance;
|
export default _urlInstance;
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
{{#unless additionalTags}}
|
{{#unless additionalTags}}
|
||||||
{{!-- the tag filter doesn't work with tag intersections, so hide it --}}
|
{{!-- the tag filter doesn't work with tag intersections, so hide it --}}
|
||||||
{{#if siteSettings.show_filter_by_tag}}
|
{{#if siteSettings.show_filter_by_tag}}
|
||||||
{{tag-drop firstCategory=category tagId=tag.id}}
|
{{tag-drop currentCategory=category noSubcategories=noSubcategories tagId=tag.id}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{/unless}}
|
{{/unless}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
import Category from "discourse/models/category";
|
import Category from "discourse/models/category";
|
||||||
import ComboBoxComponent from "select-kit/components/combo-box";
|
import ComboBoxComponent from "select-kit/components/combo-box";
|
||||||
import DiscourseURL from "discourse/lib/url";
|
import DiscourseURL, { getCategoryAndTagUrl } from "discourse/lib/url";
|
||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
import { categoryBadgeHTML } from "discourse/helpers/category-link";
|
import { categoryBadgeHTML } from "discourse/helpers/category-link";
|
||||||
import { computed } from "@ember/object";
|
import { computed } from "@ember/object";
|
||||||
import getURL from "discourse-common/lib/get-url";
|
|
||||||
import { readOnly } from "@ember/object/computed";
|
import { readOnly } from "@ember/object/computed";
|
||||||
|
|
||||||
export const NO_CATEGORIES_ID = "no-categories";
|
export const NO_CATEGORIES_ID = "no-categories";
|
||||||
|
@ -107,8 +106,6 @@ export default ComboBoxComponent.extend({
|
||||||
|
|
||||||
parentCategoryName: readOnly("selectKit.options.parentCategory.name"),
|
parentCategoryName: readOnly("selectKit.options.parentCategory.name"),
|
||||||
|
|
||||||
parentCategoryUrl: readOnly("selectKit.options.parentCategory.url"),
|
|
||||||
|
|
||||||
allCategoriesLabel: computed(
|
allCategoriesLabel: computed(
|
||||||
"parentCategoryName",
|
"parentCategoryName",
|
||||||
"selectKit.options.subCategory",
|
"selectKit.options.subCategory",
|
||||||
|
@ -123,22 +120,6 @@ export default ComboBoxComponent.extend({
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
|
|
||||||
allCategoriesUrl: computed(
|
|
||||||
"parentCategoryUrl",
|
|
||||||
"selectKit.options.subCategory",
|
|
||||||
function () {
|
|
||||||
return getURL(
|
|
||||||
this.selectKit.options.subCategory
|
|
||||||
? `${this.parentCategoryUrl}/all` || "/"
|
|
||||||
: "/"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
),
|
|
||||||
|
|
||||||
noCategoriesUrl: computed("parentCategoryUrl", function () {
|
|
||||||
return getURL(`${this.parentCategoryUrl}/none`);
|
|
||||||
}),
|
|
||||||
|
|
||||||
search(filter) {
|
search(filter) {
|
||||||
if (filter) {
|
if (filter) {
|
||||||
let results = Category.search(filter);
|
let results = Category.search(filter);
|
||||||
|
@ -159,27 +140,18 @@ export default ComboBoxComponent.extend({
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
onChange(categoryId) {
|
onChange(categoryId) {
|
||||||
let categoryURL;
|
const category =
|
||||||
|
categoryId === ALL_CATEGORIES_ID || categoryId === NO_CATEGORIES_ID
|
||||||
|
? this.selectKit.options.parentCategory
|
||||||
|
: Category.findById(parseInt(categoryId, 10));
|
||||||
|
|
||||||
if (this.tagId && !this.category) {
|
DiscourseURL.routeToUrl(
|
||||||
const category = Category.findById(parseInt(categoryId, 10));
|
getCategoryAndTagUrl(
|
||||||
categoryURL = getURL(
|
category,
|
||||||
`/tags/c/${Category.slugFor(category)}/${
|
categoryId !== NO_CATEGORIES_ID,
|
||||||
category.id
|
this.tagId
|
||||||
}/${this.tagId.toLowerCase()}`
|
)
|
||||||
);
|
);
|
||||||
} else if (categoryId === ALL_CATEGORIES_ID) {
|
|
||||||
categoryURL = this.allCategoriesUrl;
|
|
||||||
} else if (categoryId === NO_CATEGORIES_ID) {
|
|
||||||
categoryURL = this.noCategoriesUrl;
|
|
||||||
} else {
|
|
||||||
const category = Category.findById(parseInt(categoryId, 10));
|
|
||||||
categoryURL = category.url;
|
|
||||||
}
|
|
||||||
|
|
||||||
DiscourseURL.routeToUrl(categoryURL);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
import { equal, gte, or, readOnly } from "@ember/object/computed";
|
import { equal, gte, readOnly } from "@ember/object/computed";
|
||||||
import { i18n, setting } from "discourse/lib/computed";
|
import { i18n, setting } from "discourse/lib/computed";
|
||||||
import Category from "discourse/models/category";
|
|
||||||
import ComboBoxComponent from "select-kit/components/combo-box";
|
import ComboBoxComponent from "select-kit/components/combo-box";
|
||||||
import DiscourseURL from "discourse/lib/url";
|
import DiscourseURL, { getCategoryAndTagUrl } from "discourse/lib/url";
|
||||||
import TagsMixin from "select-kit/mixins/tags";
|
import TagsMixin from "select-kit/mixins/tags";
|
||||||
import { computed } from "@ember/object";
|
import { computed } from "@ember/object";
|
||||||
import getURL from "discourse-common/lib/get-url";
|
|
||||||
import { isEmpty } from "@ember/utils";
|
import { isEmpty } from "@ember/utils";
|
||||||
import { makeArray } from "discourse-common/lib/helpers";
|
import { makeArray } from "discourse-common/lib/helpers";
|
||||||
|
|
||||||
|
@ -19,7 +17,6 @@ export default ComboBoxComponent.extend(TagsMixin, {
|
||||||
classNames: ["tag-drop"],
|
classNames: ["tag-drop"],
|
||||||
value: readOnly("tagId"),
|
value: readOnly("tagId"),
|
||||||
tagName: "li",
|
tagName: "li",
|
||||||
currentCategory: or("secondCategory", "firstCategory"),
|
|
||||||
showFilterByTag: setting("show_filter_by_tag"),
|
showFilterByTag: setting("show_filter_by_tag"),
|
||||||
categoryStyle: setting("category_style"),
|
categoryStyle: setting("category_style"),
|
||||||
maxTagSearchResults: setting("max_tag_search_results"),
|
maxTagSearchResults: setting("max_tag_search_results"),
|
||||||
|
@ -70,28 +67,6 @@ export default ComboBoxComponent.extend(TagsMixin, {
|
||||||
return this.tagId ? `tag-${this.tagId}` : "tag_all";
|
return this.tagId ? `tag-${this.tagId}` : "tag_all";
|
||||||
}),
|
}),
|
||||||
|
|
||||||
currentCategoryUrl: readOnly("currentCategory.url"),
|
|
||||||
|
|
||||||
allTagsUrl: computed("firstCategory", "secondCategory", function () {
|
|
||||||
if (this.currentCategory) {
|
|
||||||
return getURL(`${this.currentCategoryUrl}?allTags=1`);
|
|
||||||
} else {
|
|
||||||
return getURL("/");
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
|
|
||||||
noTagsUrl: computed("firstCategory", "secondCategory", function () {
|
|
||||||
let url;
|
|
||||||
if (this.currentCategory) {
|
|
||||||
url = `/tags/c/${Category.slugFor(this.currentCategory)}/${
|
|
||||||
this.currentCategory.id
|
|
||||||
}`;
|
|
||||||
} else {
|
|
||||||
url = "/tag";
|
|
||||||
}
|
|
||||||
return getURL(`${url}/${NONE_TAG_ID}`);
|
|
||||||
}),
|
|
||||||
|
|
||||||
allTagsLabel: i18n("tagging.selector_all_tags"),
|
allTagsLabel: i18n("tagging.selector_all_tags"),
|
||||||
|
|
||||||
noTagsLabel: i18n("tagging.selector_no_tags"),
|
noTagsLabel: i18n("tagging.selector_no_tags"),
|
||||||
|
@ -171,32 +146,17 @@ export default ComboBoxComponent.extend(TagsMixin, {
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
onChange(tagId, tag) {
|
onChange(tagId, tag) {
|
||||||
let url;
|
if (tagId === NO_TAG_ID) {
|
||||||
|
tagId = NONE_TAG_ID;
|
||||||
switch (tagId) {
|
} else if (tagId === ALL_TAGS_ID) {
|
||||||
case ALL_TAGS_ID:
|
tagId = null;
|
||||||
url = this.allTagsUrl;
|
} else if (tag && tag.targetTagId) {
|
||||||
break;
|
tagId = tag.targetTagId;
|
||||||
case NO_TAG_ID:
|
|
||||||
url = this.noTagsUrl;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (this.currentCategory) {
|
|
||||||
url = `/tags/c/${Category.slugFor(this.currentCategory)}/${
|
|
||||||
this.currentCategory.id
|
|
||||||
}`;
|
|
||||||
} else {
|
|
||||||
url = "/tag";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tag && tag.targetTagId) {
|
|
||||||
url += `/${tag.targetTagId.toLowerCase()}`;
|
|
||||||
} else {
|
|
||||||
url += `/${tagId.toLowerCase()}`;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DiscourseURL.routeTo(getURL(url));
|
DiscourseURL.routeToUrl(
|
||||||
|
getCategoryAndTagUrl(this.currentCategory, !this.noSubcategories, tagId)
|
||||||
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -452,7 +452,7 @@ class TagsController < ::ApplicationController
|
||||||
search: params[:search],
|
search: params[:search],
|
||||||
q: params[:q]
|
q: params[:q]
|
||||||
)
|
)
|
||||||
options[:no_subcategories] = true if params[:no_subcategories] == 'true'
|
options[:no_subcategories] = true if params[:no_subcategories] == true || params[:no_subcategories] == 'true'
|
||||||
options[:per_page] = params[:per_page].to_i.clamp(1, 30) if params[:per_page].present?
|
options[:per_page] = params[:per_page].to_i.clamp(1, 30) if params[:per_page].present?
|
||||||
|
|
||||||
if params[:tag_id] == 'none'
|
if params[:tag_id] == 'none'
|
||||||
|
|
Loading…
Reference in New Issue
Block a user