Skip to content

Commit

Permalink
Fix #25341 Template Builder error when loading a template (#25359)
Browse files Browse the repository at this point in the history
* fix form console error

* fix ngOnChanges error

* fix tests
  • Loading branch information
zJaaal committed Jun 27, 2023
1 parent fa3ab0c commit 84216b2
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 25 deletions.
Expand Up @@ -7,7 +7,7 @@
<dot-template-advanced
[didTemplateChanged]="didTemplateChanged"
[body]="item.body"
(updateTemplate)="updateTemplate.emit($event)"
(updateTemplate)="onTemplateItemChange($event)"
(save)="save.emit($event)"
(cancel)="cancel.emit()"
></dot-template-advanced>
Expand Down Expand Up @@ -37,7 +37,7 @@
[disablePublish]="item.live"
[layout]="item.layout"
(saveAndPublish)="saveAndPublish.emit($event)"
(updateTemplate)="updateTemplate.emit($event)"
(updateTemplate)="onTemplateItemChange($event)"
(save)="save.emit($event)"
></dot-edit-layout-designer>
</ng-template>
Expand Down
Expand Up @@ -178,6 +178,7 @@ describe('DotTemplateBuilderComponent', () => {
fixture = TestBed.createComponent(DotTemplateBuilderComponent);
de = fixture.debugElement;
component = fixture.componentInstance;

dotPropertiesService = TestBed.inject(DotPropertiesService);
spyOn(component.save, 'emit');
spyOn(component.updateTemplate, 'emit');
Expand Down Expand Up @@ -347,6 +348,9 @@ describe('DotTemplateBuilderComponent', () => {
theme: '123'
};
hostFixture.detectChanges();
const builder = hostFixture.debugElement.query(
By.css('dot-edit-layout-designer')
).componentInstance;
dotTestHostComponent.builder.historyIframe = {
iframeElement: {
nativeElement: {
Expand All @@ -362,6 +366,9 @@ describe('DotTemplateBuilderComponent', () => {
...EMPTY_TEMPLATE_DESIGN,
theme: 'dotcms-123'
};

builder.updateTemplate.emit(dotTestHostComponent.item);

hostFixture.detectChanges();
expect(
dotTestHostComponent.builder.historyIframe.iframeElement.nativeElement.contentWindow
Expand Down
@@ -1,12 +1,4 @@
import {
Component,
EventEmitter,
Input,
OnChanges,
OnInit,
Output,
ViewChild
} from '@angular/core';
import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core';

import { IframeComponent } from '@components/_common/iframe/iframe-component';
import { DotLayout, FeaturedFlags } from '@dotcms/dotcms-models';
Expand All @@ -18,7 +10,7 @@ import { DotTemplateItem } from '../store/dot-template.store';
templateUrl: './dot-template-builder.component.html',
styleUrls: ['./dot-template-builder.component.scss']
})
export class DotTemplateBuilderComponent implements OnInit, OnChanges {
export class DotTemplateBuilderComponent implements OnInit {
@Input() item: DotTemplateItem;
@Input() didTemplateChanged: boolean;
@Output() saveAndPublish = new EventEmitter<DotTemplateItem>();
Expand All @@ -36,12 +28,6 @@ export class DotTemplateBuilderComponent implements OnInit, OnChanges {
this.historyUrl = `/html/templates/push_history.jsp?templateId=${this.item.identifier}&popup=true`;
}

ngOnChanges(): void {
if (this.historyIframe) {
this.historyIframe.iframeElement.nativeElement.contentWindow.location.reload();
}
}

/**
* Update template and publish it
*
Expand All @@ -53,5 +39,22 @@ export class DotTemplateBuilderComponent implements OnInit, OnChanges {
...this.item,
layout
} as DotTemplateItem);

if (this.historyIframe) {
this.historyIframe.iframeElement.nativeElement.contentWindow.location.reload();
}
}

/**
* Update template and publish it
*
* @param {DotTemplateItem} item
* @memberof DotTemplateBuilderComponent
*/
onTemplateItemChange(item: DotTemplateItem) {
this.updateTemplate.emit(item);
if (this.historyIframe) {
this.historyIframe.iframeElement.nativeElement.contentWindow.location.reload();
}
}
}
Expand Up @@ -77,7 +77,9 @@ describe('TemplateBuilderComponent', () => {
location: 'left',
width: 'small',
containers: []
}
},
width: 'Mobile',
title: 'Test Title'
},
containerMap: CONTAINER_MAP_MOCK
}
Expand Down Expand Up @@ -208,11 +210,9 @@ describe('TemplateBuilderComponent', () => {
body: FULL_DATA_MOCK,
header: true,
footer: true,
sidebar: {
location: 'left',
width: 'small',
containers: []
}
sidebar: null,
width: 'Mobile',
title: 'Test Title'
});
done();
});
Expand Down
Expand Up @@ -126,7 +126,9 @@ export class TemplateBuilderComponent implements OnInit, AfterViewInit, OnDestro
sidebar: layoutProperties?.sidebar?.location?.length // Make it null if it's empty so it doesn't get saved
? layoutProperties.sidebar
: null,
body: items as DotLayoutBody
body: items as DotLayoutBody,
title: this.templateLayout?.title ?? '',
width: this.templateLayout?.width ?? ''
});
})
)
Expand Down

0 comments on commit 84216b2

Please sign in to comment.