Skip to content

Commit

Permalink
DEV: Add preview
Browse files Browse the repository at this point in the history
  • Loading branch information
janzenisaac committed Apr 9, 2024
1 parent c8d7716 commit 1429cae
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 0 deletions.
18 changes: 18 additions & 0 deletions admin/assets/javascripts/discourse/components/modal/preview.gjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { htmlSafe } from "@ember/template";
import DModal from "discourse/components/d-modal";
import i18n from "discourse-common/helpers/i18n";

const Preview = <template>
<DModal
@closeModal={{@closeModal}}
@title={{i18n "admin.adplugin.house_ads.preview"}}
>
<:body>
<div class="house-ad-preview">
{{htmlSafe @model.html}}
</div>
</:body>
</DModal>
</template>;

export default Preview;
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
import Category from "discourse/models/category";
import I18n from "I18n";
import Preview from "../components/modal/preview";

export default class adminPluginsHouseAdsShow extends Controller {
@service router;
@service modal;

@controller("adminPlugins.houseAds") houseAdsController;

Expand Down Expand Up @@ -133,6 +135,15 @@ export default class adminPluginsHouseAdsShow extends Controller {
}
}

@action
openPreview() {
this.modal.show(Preview, {
model: {
html: this.buffered.html,
},
});
}

setCategoriesForBuffered() {
// we need to fetch the categories because the serializer is not being used
// to attach the category object to the house ads
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
{{/unless}}
{{/if}}

<DButton
@action={{this.openPreview}}
@label="admin.adplugin.house_ads.preview"
/>

<DButton
@action={{this.destroy}}
@label="admin.adplugin.house_ads.delete"
Expand Down
4 changes: 4 additions & 0 deletions assets/stylesheets/adplugin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,7 @@
}
}
}

.house-ad-preview {
width: 100%;
}
1 change: 1 addition & 0 deletions config/locales/client.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ en:
show_to_logged_in_users: "Show to logged in users"
category_chooser_description: "Choose the categories where this ad should be displayed or leave empty to show the ad everywhere. The `no_ads_for_categories` site setting has priority over this setting."
group_chooser_description: "Choose the groups that can view this ad or leave empty to show the ad to all signed in users."
preview: "Preview"

topic_list_top:
title: "Topic list top ads"
Expand Down

0 comments on commit 1429cae

Please sign in to comment.