-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEV: Migrate icons and links settings to new objects setting type (#36)
Since discourse/discourse@a440e15, we have started to support objects typed theme setting so we are switching this theme component to use it instead as it provides a much better UX for configuring the settings required for the theme component.
- Loading branch information
Showing
11 changed files
with
324 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
javascripts/discourse/components/brand-header-contents.gjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import Component from "@glimmer/component"; | ||
import { inject as service } from "@ember/service"; | ||
import dIcon from "discourse-common/helpers/d-icon"; | ||
|
||
export default class BrandHeaderContents extends Component { | ||
@service site; | ||
|
||
get shouldShow() { | ||
return !this.site.mobileView || settings.show_bar_on_mobile; | ||
} | ||
|
||
get brandLogo() { | ||
const mobileView = this.site.mobileView; | ||
const mobileLogoUrl = settings.mobile_logo_url || ""; | ||
const showMobileLogo = mobileView && mobileLogoUrl.length > 0; | ||
const logoUrl = settings.logo_url || ""; | ||
const title = settings.brand_name; | ||
|
||
return { | ||
url: showMobileLogo ? mobileLogoUrl : logoUrl, | ||
title, | ||
}; | ||
} | ||
|
||
get hasIcons() { | ||
return settings.icons.length > 0; | ||
} | ||
|
||
get hasLinks() { | ||
return settings.links.length > 0; | ||
} | ||
|
||
<template> | ||
<div class="title"> | ||
<a href={{settings.website_url}}> | ||
{{#if this.brandLogo.url}} | ||
<img | ||
id="brand-logo" | ||
class="logo-big" | ||
src={{this.brandLogo.url}} | ||
title={{this.brandLogo.title}} | ||
/> | ||
{{else}} | ||
<h2 id="#brand-text-logo" class="text-logo"> | ||
{{settings.brand_name}} | ||
</h2> | ||
{{/if}} | ||
</a> | ||
</div> | ||
|
||
{{#if this.hasLinks}} | ||
<nav class="links"> | ||
<ul class="nav {{if this.shouldShow 'nav-pills'}}"> | ||
{{#each settings.links as |tl|}} | ||
<li> | ||
<a href={{tl.url}} target={{tl.target}}> | ||
{{tl.text}} | ||
</a> | ||
</li> | ||
{{/each}} | ||
</ul> | ||
</nav> | ||
{{/if}} | ||
|
||
{{#if this.hasIcons}} | ||
<div class="panel"> | ||
<ul class="icons"> | ||
{{#each settings.icons as |il|}} | ||
<li> | ||
<a href={{il.url}} target={{il.target}}> | ||
{{dIcon il.icon_name}} | ||
</a> | ||
</li> | ||
{{/each}} | ||
</ul> | ||
</div> | ||
{{/if}} | ||
</template> | ||
} |
44 changes: 0 additions & 44 deletions
44
javascripts/discourse/components/brand-header-contents.hbs
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
en: | ||
theme_metadata: | ||
settings: | ||
links: | ||
description: Text links to be displayed in the header | ||
schema: | ||
properties: | ||
text: | ||
label: Text | ||
description: The text to display for the link | ||
url: | ||
label: URL | ||
description: The URL to link to | ||
target: | ||
label: Target | ||
description: The target attribute for the link | ||
icons: | ||
description: Icon links to be displayed in the header | ||
schema: | ||
properties: | ||
icon_name: | ||
label: Icon | ||
description: The name of the FontAwesome 5 icon to display for the link | ||
url: | ||
label: URL | ||
description: The URL to link to | ||
target: | ||
label: Target | ||
description: The target attribute for the link |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
export default function migrate(settings) { | ||
const oldSetting = settings.get("links"); | ||
|
||
if (oldSetting) { | ||
const newSetting = oldSetting.split("|").map((link) => { | ||
let [name, url, target] = link.split(",").map((s) => s.trim()); | ||
|
||
if (["_blank", "_self", "_parent", "_top"].indexOf(target) === -1) { | ||
target = "_blank"; | ||
} | ||
|
||
const newLink = { | ||
name, | ||
url, | ||
target | ||
} | ||
|
||
Object.keys(newLink).forEach((key) => { | ||
if (newLink[key] === undefined) { | ||
delete newLink[key]; | ||
} | ||
}); | ||
|
||
return newLink; | ||
}) | ||
|
||
settings.set("links", newSetting); | ||
} | ||
|
||
return settings; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
export default function migrate(settings) { | ||
const oldSetting = settings.get("icons"); | ||
|
||
if (oldSetting) { | ||
const newSetting = oldSetting.split("|").map((link) => { | ||
let [iconName, url, target] = link.split(",").map((s) => s.trim()); | ||
|
||
if (["_blank", "_self", "_parent", "_top"].indexOf(target) === -1) { | ||
target = "_blank"; | ||
} | ||
|
||
const newLink = { | ||
icon_name: iconName, | ||
url, | ||
target | ||
} | ||
|
||
Object.keys(newLink).forEach((key) => { | ||
if (newLink[key] === undefined) { | ||
delete newLink[key]; | ||
} | ||
}); | ||
|
||
return newLink; | ||
}) | ||
|
||
settings.set("icons", newSetting); | ||
} | ||
|
||
return settings; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.