2024-09-10 13:16:16 +08:00
|
|
|
import Component from "@glimmer/component";
|
2024-12-10 08:59:47 +08:00
|
|
|
import { tracked } from "@glimmer/tracking";
|
2024-08-20 07:59:43 +08:00
|
|
|
import { hash } from "@ember/helper";
|
2024-10-08 06:28:32 +08:00
|
|
|
import { service } from "@ember/service";
|
2024-08-20 07:59:43 +08:00
|
|
|
import { htmlSafe } from "@ember/template";
|
2024-10-08 06:28:32 +08:00
|
|
|
import { or } from "truth-helpers";
|
2024-08-20 07:59:43 +08:00
|
|
|
import DBreadcrumbsContainer from "discourse/components/d-breadcrumbs-container";
|
|
|
|
import DBreadcrumbsItem from "discourse/components/d-breadcrumbs-item";
|
2024-10-08 06:28:32 +08:00
|
|
|
import DropdownMenu from "discourse/components/dropdown-menu";
|
2024-08-20 07:59:43 +08:00
|
|
|
import HorizontalOverflowNav from "discourse/components/horizontal-overflow-nav";
|
2024-12-10 08:59:47 +08:00
|
|
|
import { bind } from "discourse-common/utils/decorators";
|
2024-11-20 04:45:18 +08:00
|
|
|
import { i18n } from "discourse-i18n";
|
2024-08-20 07:59:43 +08:00
|
|
|
import {
|
2024-10-08 06:28:32 +08:00
|
|
|
DangerActionListItem,
|
2024-08-20 07:59:43 +08:00
|
|
|
DangerButton,
|
2024-10-08 06:28:32 +08:00
|
|
|
DefaultActionListItem,
|
2024-08-20 07:59:43 +08:00
|
|
|
DefaultButton,
|
2024-10-08 06:28:32 +08:00
|
|
|
PrimaryActionListItem,
|
2024-08-20 07:59:43 +08:00
|
|
|
PrimaryButton,
|
2024-10-08 06:28:32 +08:00
|
|
|
WrappedActionListItem,
|
|
|
|
WrappedButton,
|
2024-08-20 07:59:43 +08:00
|
|
|
} from "admin/components/admin-page-action-button";
|
2024-10-08 06:28:32 +08:00
|
|
|
import DMenu from "float-kit/components/d-menu";
|
2024-08-20 07:59:43 +08:00
|
|
|
|
2024-12-10 08:59:47 +08:00
|
|
|
const HEADLESS_ACTIONS = ["new", "edit"];
|
|
|
|
|
2024-09-10 13:16:16 +08:00
|
|
|
export default class AdminPageHeader extends Component {
|
2024-10-08 06:28:32 +08:00
|
|
|
@service site;
|
2024-12-10 08:59:47 +08:00
|
|
|
@service router;
|
|
|
|
@tracked shouldDisplay = true;
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super(...arguments);
|
|
|
|
this.router.on("routeDidChange", this, this.#checkIfShouldDisplay);
|
|
|
|
this.#checkIfShouldDisplay();
|
|
|
|
}
|
|
|
|
|
|
|
|
willDestroy() {
|
|
|
|
super.willDestroy(...arguments);
|
|
|
|
this.router.off("routeDidChange", this, this.#checkIfShouldDisplay);
|
|
|
|
}
|
2024-10-08 06:28:32 +08:00
|
|
|
|
2024-09-10 13:16:16 +08:00
|
|
|
get title() {
|
|
|
|
if (this.args.titleLabelTranslated) {
|
|
|
|
return this.args.titleLabelTranslated;
|
|
|
|
} else if (this.args.titleLabel) {
|
|
|
|
return i18n(this.args.titleLabel);
|
|
|
|
}
|
|
|
|
}
|
2024-08-20 07:59:43 +08:00
|
|
|
|
2024-09-10 13:16:16 +08:00
|
|
|
get description() {
|
|
|
|
if (this.args.descriptionLabelTranslated) {
|
|
|
|
return this.args.descriptionLabelTranslated;
|
|
|
|
} else if (this.args.descriptionLabel) {
|
|
|
|
return i18n(this.args.descriptionLabel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-10 08:59:47 +08:00
|
|
|
@bind
|
|
|
|
#checkIfShouldDisplay() {
|
|
|
|
if (this.args.shouldDisplay !== undefined) {
|
|
|
|
return (this.shouldDisplay = this.args.shouldDisplay);
|
|
|
|
}
|
2024-08-20 07:59:43 +08:00
|
|
|
|
2024-12-10 08:59:47 +08:00
|
|
|
const currentPath = this.router._router.currentPath;
|
|
|
|
if (!currentPath) {
|
|
|
|
return (this.shouldDisplay = true);
|
|
|
|
}
|
2024-08-20 07:59:43 +08:00
|
|
|
|
2024-12-10 08:59:47 +08:00
|
|
|
const pathSegments = currentPath.split(".");
|
|
|
|
this.shouldDisplay =
|
|
|
|
!pathSegments.includes("admin") ||
|
|
|
|
!HEADLESS_ACTIONS.find((segment) => pathSegments.includes(segment));
|
|
|
|
}
|
|
|
|
|
|
|
|
<template>
|
|
|
|
{{#if this.shouldDisplay}}
|
|
|
|
<div class="admin-page-header">
|
|
|
|
<div class="admin-page-header__breadcrumbs">
|
|
|
|
<DBreadcrumbsContainer />
|
|
|
|
<DBreadcrumbsItem @path="/admin" @label={{i18n "admin_title"}} />
|
|
|
|
{{yield to="breadcrumbs"}}
|
|
|
|
</div>
|
2024-08-20 07:59:43 +08:00
|
|
|
|
2024-12-10 08:59:47 +08:00
|
|
|
<div class="admin-page-header__title-row">
|
|
|
|
{{#if this.title}}
|
|
|
|
<h1 class="admin-page-header__title">{{this.title}}</h1>
|
2024-09-10 13:16:16 +08:00
|
|
|
{{/if}}
|
|
|
|
|
2024-12-10 08:59:47 +08:00
|
|
|
{{#if (or (has-block "actions") @headerActionComponent)}}
|
|
|
|
<div class="admin-page-header__actions">
|
|
|
|
{{#if this.site.mobileView}}
|
|
|
|
<DMenu
|
|
|
|
@identifier="admin-page-header-mobile-actions"
|
|
|
|
@title={{i18n "more_options"}}
|
|
|
|
@icon="ellipsis-vertical"
|
|
|
|
class="btn-small"
|
|
|
|
>
|
|
|
|
<:content>
|
|
|
|
<DropdownMenu class="admin-page-header__mobile-actions">
|
|
|
|
{{#let
|
|
|
|
(hash
|
|
|
|
Primary=PrimaryActionListItem
|
|
|
|
Default=DefaultActionListItem
|
|
|
|
Danger=DangerActionListItem
|
|
|
|
Wrapped=WrappedActionListItem
|
|
|
|
)
|
|
|
|
as |actions|
|
|
|
|
}}
|
|
|
|
{{#if (has-block "actions")}}
|
|
|
|
{{yield actions to="actions"}}
|
|
|
|
{{else}}
|
|
|
|
<@headerActionComponent @actions={{actions}} />
|
|
|
|
{{/if}}
|
|
|
|
{{/let}}
|
|
|
|
</DropdownMenu>
|
|
|
|
</:content>
|
|
|
|
</DMenu>
|
|
|
|
{{else}}
|
|
|
|
{{#let
|
|
|
|
(hash
|
|
|
|
Primary=PrimaryButton
|
|
|
|
Default=DefaultButton
|
|
|
|
Danger=DangerButton
|
|
|
|
Wrapped=WrappedButton
|
|
|
|
)
|
|
|
|
as |actions|
|
|
|
|
}}
|
|
|
|
{{#if (has-block "actions")}}
|
|
|
|
{{yield actions to="actions"}}
|
|
|
|
{{else}}
|
|
|
|
<@headerActionComponent @actions={{actions}} />
|
|
|
|
{{/if}}
|
|
|
|
{{/let}}
|
|
|
|
{{/if}}
|
|
|
|
</div>
|
|
|
|
{{/if}}
|
2024-09-10 13:16:16 +08:00
|
|
|
</div>
|
2024-12-10 08:59:47 +08:00
|
|
|
|
|
|
|
{{#if this.description}}
|
|
|
|
<p class="admin-page-header__description">
|
|
|
|
{{htmlSafe this.description}}
|
|
|
|
{{#if @learnMoreUrl}}
|
|
|
|
<span class="admin-page-header__learn-more">{{htmlSafe
|
|
|
|
(i18n "learn_more_with_link" url=@learnMoreUrl)
|
|
|
|
}}</span>
|
|
|
|
{{/if}}
|
|
|
|
</p>
|
|
|
|
{{/if}}
|
|
|
|
|
|
|
|
{{#unless @hideTabs}}
|
|
|
|
<div class="admin-nav-submenu">
|
|
|
|
<HorizontalOverflowNav class="admin-nav-submenu__tabs">
|
|
|
|
{{yield to="tabs"}}
|
|
|
|
</HorizontalOverflowNav>
|
|
|
|
</div>
|
|
|
|
{{/unless}}
|
|
|
|
</div>
|
|
|
|
{{/if}}
|
2024-09-10 13:16:16 +08:00
|
|
|
</template>
|
|
|
|
}
|