From 556b29952c8013e5c8f5683b3d4f3b7c772c9e29 Mon Sep 17 00:00:00 2001 From: Daniel Waterworth Date: Thu, 21 Nov 2019 10:52:50 +0000 Subject: [PATCH] FIX: followup to a8d58c3b It helps to include the files you intend to add --- .../discourse/mixins/filter-mode.js.es6 | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 app/assets/javascripts/discourse/mixins/filter-mode.js.es6 diff --git a/app/assets/javascripts/discourse/mixins/filter-mode.js.es6 b/app/assets/javascripts/discourse/mixins/filter-mode.js.es6 new file mode 100644 index 00000000000..1e16f075ee6 --- /dev/null +++ b/app/assets/javascripts/discourse/mixins/filter-mode.js.es6 @@ -0,0 +1,50 @@ +import Mixin from "@ember/object/mixin"; +import { computed } from "@ember/object"; +import Category from "discourse/models/category"; + +export default Mixin.create({ + filterModeInternal: computed( + "rawFilterMode", + "filterType", + "category", + "noSubcategories", + function() { + const rawFilterMode = this.get("rawFilterMode"); + if (rawFilterMode) { + return rawFilterMode; + } else { + const category = this.get("category"); + const filterType = this.get("filterType"); + + if (category) { + const noSubcategories = this.get("noSubcategories"); + + return `c/${Category.slugFor(category)}${ + noSubcategories ? "/none" : "" + }/l/${filterType}`; + } else { + return filterType; + } + } + } + ), + + filterMode: computed("filterModeInternal", { + get() { + return this.get("filterModeInternal"); + }, + + set(key, value) { + this.set("rawFilterMode", value); + const parts = value.split("/"); + + if (parts.length >= 2 && parts[parts.length - 2] === "top") { + this.set("filterType", "top"); + } else { + this.set("filterType", parts.pop()); + } + + return value; + } + }) +});