mirror of
https://github.com/discourse/discourse.git
synced 2024-12-01 17:23:44 +08:00
782f43cc55
Previously if a specific plugin route was not available (e.g. there was an error loading the plugin's JS due to an ad blocker), the entire page would fail to load. This commit updates the behavior to catch this kind of issue and display a user-friendly message at the top of the screen.
44 lines
953 B
JavaScript
44 lines
953 B
JavaScript
import { action } from "@ember/object";
|
|
import Controller from "@ember/controller";
|
|
import { inject as service } from "@ember/service";
|
|
|
|
export default Controller.extend({
|
|
router: service(),
|
|
|
|
get adminRoutes() {
|
|
return this.allAdminRoutes.filter((r) => this.routeExists(r.full_location));
|
|
},
|
|
|
|
get brokenAdminRoutes() {
|
|
return this.allAdminRoutes.filter(
|
|
(r) => !this.routeExists(r.full_location)
|
|
);
|
|
},
|
|
|
|
get allAdminRoutes() {
|
|
return this.model
|
|
.filter((p) => p?.enabled)
|
|
.map((p) => {
|
|
return p.admin_route;
|
|
})
|
|
.filter(Boolean);
|
|
},
|
|
|
|
@action
|
|
toggleMenu() {
|
|
const adminDetail = document.querySelector(".admin-detail");
|
|
["mobile-closed", "mobile-open"].forEach((state) => {
|
|
adminDetail.classList.toggle(state);
|
|
});
|
|
},
|
|
|
|
routeExists(routeName) {
|
|
try {
|
|
this.router.urlFor(routeName);
|
|
return true;
|
|
} catch (e) {
|
|
return false;
|
|
}
|
|
},
|
|
});
|