Skip to content

Commit 95e09f0

Browse files
Merge pull request #65 from amrarick26/dev
Hook for page editor saveChanges method
2 parents 3ed5d1f + 50721ef commit 95e09f0

6 files changed

Lines changed: 45 additions & 18 deletions

File tree

projects/lib/src/admin/components/page-editor/page-editor.component.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export class PageEditorComponent implements OnInit, OnChanges {
6262
@Input() additionalAssetFilters?: TemplateRef<any>;
6363
@Input() defaultListOptions?: ListArgs<Asset> = { filters: { Active: true } };
6464
@Input() beforeAssetUpload?: (asset: AssetUpload) => Promise<AssetUpload>;
65+
@Input() beforeDocumentSave?: (page: Partial<PageContentDoc>) => Promise<Partial<PageContentDoc>>;
6566
@Output() selectedAssetChange = new EventEmitter<Asset | Asset[]>();
6667
@Output() backClicked = new EventEmitter<MouseEvent>();
6768
@Output() pageSaved = new EventEmitter<JDocument>();
@@ -196,17 +197,27 @@ export class PageEditorComponent implements OnInit, OnChanges {
196197
}
197198

198199
async saveChanges(): Promise<RequiredDeep<JDocument>> {
200+
if (this.beforeDocumentSave) {
201+
return this.beforeDocumentSave(this.page).then(async (page) => {
202+
this.document.Doc = page;
203+
return await this.saveDocument(this.document);
204+
});
205+
} else {
206+
return await this.saveDocument(this.document);
207+
}
208+
}
209+
210+
async saveDocument(document): Promise<RequiredDeep<JDocument>> {
199211
const me = await OrderCloudSDK.Me.Get();
200212
const nowDate = new Date().toISOString();
201213
const fullName = `${me.FirstName} ${me.LastName}`;
202214
let updated: RequiredDeep<JDocument>;
203-
204-
if (this.document && this.document.ID) {
215+
if (document && document.ID) {
205216
updated = await HeadStartSDK.Documents.Save(
206217
this.pageSchemaID,
207-
this.document.ID,
218+
document.ID,
208219
{
209-
ID: this.document.ID,
220+
ID: document.ID,
210221
Doc: {
211222
...this.page,
212223
DateLastUpdated: nowDate,

projects/lib/src/admin/components/page-list/page-list.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@
150150
[additionalAssetFilters]="additionalAssetFilters"
151151
[defaultListOptions]="defaultListOptions"
152152
[beforeAssetUpload]="beforeAssetUpload"
153+
[beforeDocumentSave]="beforeDocumentSave"
153154
(selectedAssetChange)="selectedAssetChange.emit($event)"
154155
>
155156
</cms-page-editor>

projects/lib/src/admin/components/page-list/page-list.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { PAGE_SCHEMA } from '../../constants/page-schema.constants';
2323
import DEFAULT_ASSET_TYPES, {
2424
ASSET_TYPES,
2525
} from '../../constants/asset-types.constants';
26+
import { PageContentDoc } from '../../models/page-content-doc.interface';
2627

2728
@Component({
2829
selector: 'cms-page-list',
@@ -43,6 +44,7 @@ export class PageListComponent implements OnInit, OnChanges {
4344
@Input() additionalAssetFilters?: TemplateRef<any>;
4445
@Input() defaultListOptions?: ListArgs<Asset> = { filters: { Active: true } };
4546
@Input() beforeAssetUpload?: (asset: AssetUpload) => Promise<AssetUpload>;
47+
@Input() beforeDocumentSave?: (page: Partial<PageContentDoc>) => Promise<Partial<PageContentDoc>>;
4648
@Output() selectedAssetChange = new EventEmitter<Asset | Asset[]>();
4749
@Output() backClicked = new EventEmitter<MouseEvent>();
4850
@Output() pageSaved = new EventEmitter<JDocument>();

projects/lib/src/stories/mock/se-section-templates.constants.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -222,17 +222,7 @@ export default [
222222
</div>`,
223223

224224
`<div class="card__translucent p-5 m-3 m-sm-0">
225-
<!-- Inline SVG: START -->
226-
<svg xmlns="http://www.w3.org/2000/svg"
227-
aria-hidden="true"
228-
viewBox="0 0 401 79"
229-
width="100px">
230-
<text class="sr-only">Fivestars Rewards Logo</text>
231-
<defs />
232-
<path fill="#6b20ce"
233-
d="M75 24.7H55.4c-.9 0-1.7-.6-2-1.4l-6-18.6C46.5 1.8 44 0 40.9 0c-3 0-5.6 1.8-6.5 4.7l-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.4-4.6 3.2L293.3 59c-.1.3-.2.7-.2 1.1 0 1.6 1.3 2.9 2.9 2.9 1.2 0 2.3-.8 2.7-1.8l2.4-6.4zm57.5-18.1c0 3.6-3.3 6.5-7.3 6.5h-9.6v-13h9.6c4.1 0 7.3 2.9 7.3 6.5M339 63c1.5 0 2.8-1.3 2.8-2.9V48.7h8.1l7.6 12.9c.5.8 1.3 1.3 2.3 1.4 1.6.1 2.8-1.2 2.9-2.4.1-.9-.1-1.4-.4-1.8L355.7 48c4.9-1.7 8.5-6.1 8.5-11.3 0-6.6-5.7-12-12.8-12h-12.2c-2 0-3.1 1.1-3.1 3v32.5c0 1.5 1.3 2.8 2.9 2.8" />
234-
</svg>
235-
<!-- Inline SVG: END -->
225+
<img src="https://marktplacetest.blob.core.windows.net/assets-6c4f4c59-0581-4c23-a0df-5905acf5869a/eca21e9e-452f-4fe1-987f-7e778ebe2f42" alt="fivestars.png" width="100" height="20" />
236226
<h2 class="text-uppercase short-underline short-underline--double">Get
237227
Rewarded </h2>
238228
<p> We all love points. Get rewarded every time you shop for or sell,

projects/lib/src/stories/page-list.stories.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,18 +149,26 @@ export const WithBeforeAssetUpload = () => ({
149149
[resourceID]="resourceID"
150150
[editorOptions]="editorOptions"
151151
[beforeAssetUpload]="beforeAssetUpload"
152+
[beforeDocumentSave]="beforeDocumentSave"
152153
>
153154
</cms-page-list>
154155
</div>`,
155156
props: {
156157
renderSiteUrl: 'https://www.my-awesome-website.com',
157-
resourceType: 'Suppliers',
158-
resourceID: '41106',
158+
resourceType: 'Buyers',
159+
resourceID: 'sedev',
159160
lockedSlugs: ['', 'about-us'],
160161
editorOptions: {},
161162
beforeAssetUpload: (asset) => {
162163
console.log('before asset upload was hit');
163164
return Promise.resolve(asset);
164165
},
166+
beforeDocumentSave: (page) => {
167+
const span = document.createElement('span');
168+
span.innerHTML = page.Content;
169+
const images = span.getElementsByTagName('img');
170+
page.HeroImage = images.length ? images[0].currentSrc : null;
171+
return Promise.resolve(page);
172+
}
165173
},
166174
});

projects/lib/src/stories/page-renderer.stories.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,22 @@ export const FullExample = () => ({
2929
Url: 'test-page1',
3030
Description: '',
3131
HeaderEmbeds: '',
32-
Content: '<div data-oc-widget="oc-section">\n<div class="card__translucent p-5 m-3 m-sm-0"><!-- Inline SVG: START --> Fivestars Rewards Logo <!-- Inline SVG: END -->\n<h2 class="text-uppercase short-underline short-underline--double">Get Rewarded</h2>\n<p>We all love points. Get rewarded every time you shop for or sell, classic and trendy, secondhand styles by signing up for our rewards program, where you&rsquo;ll get access to exclusive discounts, special promotions, store events, and more. <br />Never miss a beat!</p>\n<div class="mt-2"><a class="btn btn-sm btn-outline-primary mb-2" href="[[REWARDS_URL]]"> Sign up online </a></div>\n [[DUMMY_TEXT]] [[REWARDS_URL]]</div>\n</div>',
32+
Content: `<div class="card__translucent p-5 m-3 m-sm-0">
33+
<img src="https://marktplacetest.blob.core.windows.net/assets-6c4f4c59-0581-4c23-a0df-5905acf5869a/eca21e9e-452f-4fe1-987f-7e778ebe2f42" alt="fivestars.png" width="100" height="20" />
34+
<h2 class="text-uppercase short-underline short-underline--double">Get
35+
Rewarded </h2>
36+
<p> We all love points. Get rewarded every time you shop for or sell,
37+
classic and trendy, secondhand styles by signing up for our rewards
38+
program, where you’ll get access to exclusive discounts, special
39+
promotions, store events, and more. <br />Never miss a beat! </p>
40+
<div class="mt-2">
41+
<a class="btn btn-sm btn-outline-primary mb-2"
42+
href="[[REWARDS_URL]]">
43+
Sign up online
44+
</a>
45+
</div>
46+
[[DUMMY_TEXT]]
47+
</div>`,
3348
FooterEmbeds: '',
3449
Active: false,
3550
NavigationTitle: 'test page1',

0 commit comments

Comments
 (0)