mirror of
https://github.com/discourse/discourse.git
synced 2025-04-30 03:14:35 +08:00
DEV: Update tag-show route to native class syntax (#23701)
This commit is contained in:
parent
9136109ca0
commit
0ec3cc4eb2
@ -1,6 +1,6 @@
|
|||||||
import DiscoverySortableController from "discourse/controllers/discovery-sortable";
|
import DiscoverySortableController from "discourse/controllers/discovery-sortable";
|
||||||
import Site from "discourse/models/site";
|
import Site from "discourse/models/site";
|
||||||
import TagShowRoute from "discourse/routes/tag-show";
|
import { buildTagRoute } from "discourse/routes/tag-show";
|
||||||
import buildCategoryRoute from "discourse/routes/build-category-route";
|
import buildCategoryRoute from "discourse/routes/build-category-route";
|
||||||
import buildTopicRoute from "discourse/routes/build-topic-route";
|
import buildTopicRoute from "discourse/routes/build-topic-route";
|
||||||
import { dasherize } from "@ember/string";
|
import { dasherize } from "@ember/string";
|
||||||
@ -66,16 +66,16 @@ export default {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.register("route:tags.show-category", TagShowRoute.extend());
|
app.register("route:tags.show-category", buildTagRoute());
|
||||||
app.register(
|
app.register(
|
||||||
"route:tags.show-category-none",
|
"route:tags.show-category-none",
|
||||||
TagShowRoute.extend({
|
buildTagRoute({
|
||||||
noSubcategories: true,
|
noSubcategories: true,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
app.register(
|
app.register(
|
||||||
"route:tags.show-category-all",
|
"route:tags.show-category-all",
|
||||||
TagShowRoute.extend({
|
buildTagRoute({
|
||||||
noSubcategories: false,
|
noSubcategories: false,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@ -85,21 +85,21 @@ export default {
|
|||||||
|
|
||||||
app.register(
|
app.register(
|
||||||
`route:tag.show-${filterDasherized}`,
|
`route:tag.show-${filterDasherized}`,
|
||||||
TagShowRoute.extend({
|
buildTagRoute({
|
||||||
navMode: filter,
|
navMode: filter,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
app.register(
|
app.register(
|
||||||
`route:tags.show-category-${filterDasherized}`,
|
`route:tags.show-category-${filterDasherized}`,
|
||||||
TagShowRoute.extend({ navMode: filter })
|
buildTagRoute({ navMode: filter })
|
||||||
);
|
);
|
||||||
app.register(
|
app.register(
|
||||||
`route:tags.show-category-none-${filterDasherized}`,
|
`route:tags.show-category-none-${filterDasherized}`,
|
||||||
TagShowRoute.extend({ navMode: filter, noSubcategories: true })
|
buildTagRoute({ navMode: filter, noSubcategories: true })
|
||||||
);
|
);
|
||||||
app.register(
|
app.register(
|
||||||
`route:tags.show-category-all-${filterDasherized}`,
|
`route:tags.show-category-all-${filterDasherized}`,
|
||||||
TagShowRoute.extend({ navMode: filter, noSubcategories: false })
|
buildTagRoute({ navMode: filter, noSubcategories: false })
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { inject as service } from "@ember/service";
|
||||||
import {
|
import {
|
||||||
filterQueryParams,
|
filterQueryParams,
|
||||||
findTopicList,
|
findTopicList,
|
||||||
@ -17,21 +18,27 @@ import { setTopicList } from "discourse/lib/topic-list-tracker";
|
|||||||
import showModal from "discourse/lib/show-modal";
|
import showModal from "discourse/lib/show-modal";
|
||||||
import { action } from "@ember/object";
|
import { action } from "@ember/object";
|
||||||
import PreloadStore from "discourse/lib/preload-store";
|
import PreloadStore from "discourse/lib/preload-store";
|
||||||
import { inject as service } from "@ember/service";
|
|
||||||
|
|
||||||
const NONE = "none";
|
const NONE = "none";
|
||||||
const ALL = "all";
|
const ALL = "all";
|
||||||
|
|
||||||
export default DiscourseRoute.extend({
|
export default class TagShowRoute extends DiscourseRoute {
|
||||||
composer: service(),
|
@service composer;
|
||||||
router: service(),
|
@service router;
|
||||||
currentUser: service(),
|
@service currentUser;
|
||||||
navMode: "latest",
|
|
||||||
|
|
||||||
queryParams,
|
queryParams = queryParams;
|
||||||
|
controllerName = "tag.show";
|
||||||
|
templateName = "tag.show";
|
||||||
|
routeConfig = {};
|
||||||
|
|
||||||
controllerName: "tag.show",
|
get navMode() {
|
||||||
templateName: "tag.show",
|
return this.routeConfig.navMode || "latest";
|
||||||
|
}
|
||||||
|
|
||||||
|
get noSubcategories() {
|
||||||
|
return this.routeConfig.noSubcategories;
|
||||||
|
}
|
||||||
|
|
||||||
beforeModel() {
|
beforeModel() {
|
||||||
const controller = this.controllerFor("tag.show");
|
const controller = this.controllerFor("tag.show");
|
||||||
@ -39,7 +46,7 @@ export default DiscourseRoute.extend({
|
|||||||
loading: true,
|
loading: true,
|
||||||
showInfo: false,
|
showInfo: false,
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
|
|
||||||
async model(params, transition) {
|
async model(params, transition) {
|
||||||
const tag = this.store.createRecord("tag", {
|
const tag = this.store.createRecord("tag", {
|
||||||
@ -138,7 +145,7 @@ export default DiscourseRoute.extend({
|
|||||||
canCreateTopicOnCategory: category?.permission === PermissionType.FULL,
|
canCreateTopicOnCategory: category?.permission === PermissionType.FULL,
|
||||||
canCreateTopicOnTag: !tag.staff || this.currentUser?.staff,
|
canCreateTopicOnTag: !tag.staff || this.currentUser?.staff,
|
||||||
};
|
};
|
||||||
},
|
}
|
||||||
|
|
||||||
setupController(controller, model) {
|
setupController(controller, model) {
|
||||||
const noSubcategories = this.noSubcategories;
|
const noSubcategories = this.noSubcategories;
|
||||||
@ -166,7 +173,7 @@ export default DiscourseRoute.extend({
|
|||||||
} else {
|
} else {
|
||||||
this.searchService.searchContext = model.tag.searchContext;
|
this.searchService.searchContext = model.tag.searchContext;
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
titleToken() {
|
titleToken() {
|
||||||
const filterText = I18n.t(
|
const filterText = I18n.t(
|
||||||
@ -199,17 +206,17 @@ export default DiscourseRoute.extend({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
deactivate() {
|
deactivate() {
|
||||||
this._super(...arguments);
|
super.deactivate(...arguments);
|
||||||
this.searchService.searchContext = null;
|
this.searchService.searchContext = null;
|
||||||
},
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
renameTag(tag) {
|
renameTag(tag) {
|
||||||
showModal("rename-tag", { model: tag });
|
showModal("rename-tag", { model: tag });
|
||||||
},
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
createTopic() {
|
createTopic() {
|
||||||
@ -231,13 +238,13 @@ export default DiscourseRoute.extend({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
dismissReadTopics(dismissTopics) {
|
dismissReadTopics(dismissTopics) {
|
||||||
const operationType = dismissTopics ? "topics" : "posts";
|
const operationType = dismissTopics ? "topics" : "posts";
|
||||||
this.send("dismissRead", operationType);
|
this.send("dismissRead", operationType);
|
||||||
},
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
dismissRead(operationType) {
|
dismissRead(operationType) {
|
||||||
@ -256,16 +263,22 @@ export default DiscourseRoute.extend({
|
|||||||
}
|
}
|
||||||
|
|
||||||
controller.send("dismissRead", operationType, options);
|
controller.send("dismissRead", operationType, options);
|
||||||
},
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
resetParams(skipParams = []) {
|
resetParams(skipParams = []) {
|
||||||
resetParams.call(this, skipParams);
|
resetParams.call(this, skipParams);
|
||||||
},
|
}
|
||||||
|
|
||||||
_controllerTags(controller) {
|
_controllerTags(controller) {
|
||||||
return [controller.get("model.id"), ...makeArray(controller.additionalTags)]
|
return [controller.get("model.id"), ...makeArray(controller.additionalTags)]
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.filter((tag) => ![NONE, ALL].includes(tag));
|
.filter((tag) => ![NONE, ALL].includes(tag));
|
||||||
},
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
|
export function buildTagRoute(routeConfig = {}) {
|
||||||
|
return class extends TagShowRoute {
|
||||||
|
routeConfig = routeConfig;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import TagShowRoute from "discourse/routes/tag-show";
|
import { buildTagRoute } from "discourse/routes/tag-show";
|
||||||
|
|
||||||
export default TagShowRoute.extend({});
|
export default buildTagRoute();
|
||||||
|
|
||||||
// The tags-intersection route is exactly the same as the tags-show route, but the wildcard at the
|
// The tags-intersection route is exactly the same as the tags-show route, but the wildcard at the
|
||||||
// end of the route (*additional_tags) will cause a match when query parameters are present,
|
// end of the route (*additional_tags) will cause a match when query parameters are present,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user