0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00

Wired announcement api to admin ui (#16678)

refs TryGhost/Team#3052


<!-- Leave the line below if you'd like GitHub Copilot to generate a
summary from your commit -->
<!--
copilot:summary
-->
### <samp>🤖 Generated by Copilot at 7173288</samp>

This pull request adds new components and settings for the announcement
bar feature, which allows the user to customize the content, background,
and visibility of a banner that appears on the site.
This commit is contained in:
Elena Baidakova 2023-04-19 19:45:34 +04:00 committed by GitHub
parent 1c3523c2ad
commit ecb42a3680
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 116 additions and 14 deletions

View file

@ -0,0 +1,18 @@
<div class="gh-stack-item {{if (eq @index 0) "gh-setting-first" "gh-setting"}}">
<div class="flex-grow-1">
<label class="gh-setting-title gh-theme-setting-title" for="announcement-background">
Announcement background
</label>
<span class="gh-select">
<select class="ember-select" name="announcement-background" id="announcement-background" {{on "change" this.setBackground}}>
{{#each this.options as |settingOption|}}
<option value={{settingOption.value}} selected={{eq settingOption.value this.background}}>
{{settingOption.label}}
</option>
{{/each}}
</select>
{{svg-jar "arrow-down-small"}}
</span>
</div>
</div>

View file

@ -0,0 +1,26 @@
import Component from '@glimmer/component';
import {action} from '@ember/object';
import {inject as service} from '@ember/service';
export default class AnnouncementSettingsBackgroundComponent extends Component {
@service settings;
get background() {
return this.settings.announcementBackground;
}
get options() {
return [
{value: 'accent', label: 'Accent'},
{value: 'dark', label: 'Dark'},
{value: 'light', label: 'Light'}
];
}
@action
setBackground(event) {
this.settings.announcementBackground = event.target.value;
this.settings.save();
this.args.onChange?.();
}
}

View file

@ -6,8 +6,8 @@
<div class="gh-announcement-editor"> <div class="gh-announcement-editor">
<KoenigLexicalEditorInput <KoenigLexicalEditorInput
@placeholderText="Breaking news, a big story, a special offer, or any other message" @placeholderText="Breaking news, a big story, a special offer, or any other message"
@html={{'<p></p>'}} @html={{this.content}}
@onChangeHtml={{this.onChangeHtml}} @onChangeHtml={{this.setContent}}
/> />
</div> </div>
</div> </div>

View file

@ -0,0 +1,18 @@
import Component from '@glimmer/component';
import {action} from '@ember/object';
import {inject as service} from '@ember/service';
export default class AnnouncementSettingsContentComponent extends Component {
@service settings;
get content() {
return this.settings.announcementContent;
}
@action
setContent(html) {
this.settings.announcementContent = html;
this.settings.save();
this.args.onChange?.();
}
}

View file

@ -0,0 +1,18 @@
<div class="gh-stack-item {{if (eq @index 0) "gh-setting-first" "gh-setting"}}">
<div class="flex-grow-1">
<label class="gh-setting-title gh-theme-setting-title" for="announcement-visibility">
Announcement visibility
</label>
<span class="gh-select">
<select class="ember-select" name="announcement-visibility" id="announcement-visibility" {{on "change" this.setVisibility}}>
{{#each this.options as |settingOption|}}
<option value={{settingOption.value}} selected={{eq settingOption.value this.background}}>
{{settingOption.label}}
</option>
{{/each}}
</select>
{{svg-jar "arrow-down-small"}}
</span>
</div>
</div>

View file

@ -0,0 +1,27 @@
import Component from '@glimmer/component';
import {action} from '@ember/object';
import {inject as service} from '@ember/service';
export default class AnnouncementSettingsVisibilityComponent extends Component {
@service settings;
get visibility() {
return this.settings.announcementVisibility;
}
get options() {
return [
{value: 'public', label: 'Public'},
{value: 'visitors', label: 'Visitors'},
{value: 'members', label: 'Members'},
{value: 'paid', label: 'Paid'}
];
}
@action
setVisibility(event) {
this.settings.announcementVisibility = event.target.value;
this.settings.save();
this.args.onChange?.();
}
}

View file

@ -1,10 +0,0 @@
import Component from '@glimmer/component';
import {action} from '@ember/object';
export default class CustomThemeSettingsAnnouncementComponent extends Component {
@action
// eslint-disable-next-line no-unused-vars
onChangeHtml(html) {
this.args.onChange?.();
}
}

View file

@ -18,7 +18,9 @@
{{/if}} {{/if}}
{{/each}} {{/each}}
{{#if (feature 'announcementBar')}} {{#if (feature 'announcementBar')}}
<CustomThemeSettings::Announcement @onChange={{@updatePreview}} /> <AnnouncementSettings::Content @onChange={{@updatePreview}} />
<AnnouncementSettings::Background @onChange={{@updatePreview}} />
<AnnouncementSettings::Visibility @onChange={{@updatePreview}} />
{{/if}} {{/if}}
</form> </form>
</div> </div>

View file

@ -50,6 +50,9 @@ export default Model.extend(ValidationEngine, {
portalSignupTermsHtml: attr('string'), portalSignupTermsHtml: attr('string'),
portalSignupCheckboxRequired: attr('boolean'), portalSignupCheckboxRequired: attr('boolean'),
sharedViews: attr('string'), sharedViews: attr('string'),
announcementContent: attr('string'),
announcementBackground: attr('string'),
announcementVisibility: attr('string'),
/** /**
* Analytics settings * Analytics settings
*/ */

View file

@ -55,7 +55,7 @@ export default class SettingsService extends Service.extend(ValidationEngine) {
_loadSettings() { _loadSettings() {
if (!this._loadingPromise) { if (!this._loadingPromise) {
this._loadingPromise = this.store this._loadingPromise = this.store
.queryRecord('setting', {group: 'site,theme,private,members,portal,newsletter,email,amp,labs,slack,unsplash,views,firstpromoter,editor,comments,analytics'}) .queryRecord('setting', {group: 'site,theme,private,members,portal,newsletter,email,amp,labs,slack,unsplash,views,firstpromoter,editor,comments,analytics,announcement'})
.then((settings) => { .then((settings) => {
this._loadingPromise = null; this._loadingPromise = null;
return settings; return settings;