Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(edit-content): Use DotContentletThumbnail Component in Binary File #27321

Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,789 changes: 1,418 additions & 1,371 deletions core-web/libs/dotcms-webcomponents/src/components.d.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export class DotContentletThumbnail {
@Prop()
showVideoThumbnail = true;

@Prop()
playableVideo = false;

@Prop()
contentlet: DotContentletItem;

Expand All @@ -49,7 +52,11 @@ export class DotContentletThumbnail {
return (
<Host>
{this.shouldShowVideoThumbnail() ? (
<dot-video-thumbnail contentlet={this.contentlet} cover={this.cover} />
<dot-video-thumbnail
contentlet={this.contentlet}
cover={this.cover}
playable={this.playableVideo}
/>
) : this.renderImage ? (
<div class={`thumbnail ${imgClass}`} style={{ 'background-image': image }}>
<img
Expand All @@ -73,7 +80,9 @@ export class DotContentletThumbnail {
private getImageURL(): string {
return this.contentlet.mimeType === 'application/pdf'
? `/contentAsset/image/${this.contentlet.inode}/${this.contentlet.titleImage}/pdf_page/1/resize_w/250/quality_q/45`
: `/dA/${this.contentlet.inode}/500w/50q?r=${this.contentlet.modDateMilis}`;
: `/dA/${this.contentlet.inode}/500w/50q?r=${
this.contentlet.modDateMilis || this.contentlet.modDate
}`;
}

private switchToIcon(): any {
Expand All @@ -87,6 +96,7 @@ export class DotContentletThumbnail {
}

private shouldShowVideoThumbnail() {
console.log(this.contentlet);
rjvelazco marked this conversation as resolved.
Show resolved Hide resolved
return this.contentlet?.mimeType?.includes('video') && this.showVideoThumbnail;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

<!-- Auto Generated Below -->


## Properties

| Property | Attribute | Description | Type | Default |
Expand All @@ -12,22 +11,23 @@
| `cover` | `cover` | | `boolean` | `true` |
| `height` | `height` | | `string` | `''` |
| `iconSize` | `icon-size` | | `string` | `''` |
| `playableVideo` | `playable-video` | | `boolean` | `false` |
| `showVideoThumbnail` | `show-video-thumbnail` | | `boolean` | `true` |
| `width` | `width` | | `string` | `''` |


## Dependencies

### Used by

- [dot-card-contentlet](../../components/dot-card-contentlet)
- [dot-card-contentlet](../../components/dot-card-contentlet)

### Depends on

- [dot-video-thumbnail](../dot-video-thumbnail)
- [dot-contentlet-icon](../dot-contentlet-icon)
- [dot-video-thumbnail](../dot-video-thumbnail)
- [dot-contentlet-icon](../dot-contentlet-icon)

### Graph

```mermaid
graph TD;
dot-contentlet-thumbnail --> dot-video-thumbnail
Expand All @@ -36,6 +36,6 @@ graph TD;
style dot-contentlet-thumbnail fill:#f9f,stroke:#333,stroke-width:4px
```

----------------------------------------------
---

*Built with [StencilJS](https://stenciljs.com/)*
_Built with [StencilJS](https://stenciljs.com/)_
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ dot-video-thumbnail {
height: 100%;

.thumbnail,
img {
img,
video {
width: 100%;
height: 100%;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ export class DotVideoThumbnail {
*/
@Prop() contentlet: DotContentletItem;

/**
* If the video is playable or not.
*
* @type {boolean}
* @memberof DotVideoThumbnail
*/
@Prop() playable: boolean = false;

/**
*
*
Expand All @@ -31,10 +39,14 @@ export class DotVideoThumbnail {

return (
<Host>
{this.src && (
<div class={`thumbnail ${cssClass}`} style={bgImage}>
<img src={this.src} alt={title} />
</div>
{this.playable ? (
<video src={`/dA/${this.contentlet.inode}`} controls></video>
) : (
this.src && (
<div class={`thumbnail ${cssClass}`} style={bgImage}>
<img src={this.src} alt={title} />
</div>
)
fmontes marked this conversation as resolved.
Show resolved Hide resolved
)}
</Host>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@

<!-- Auto Generated Below -->


## Properties

| Property | Attribute | Description | Type | Default |
| ------------ | --------- | ----------- | ------------------- | ----------- |
| `contentlet` | -- | | `DotContentletItem` | `undefined` |
| `cover` | `cover` | | `boolean` | `true` |

| Property | Attribute | Description | Type | Default |
| ------------ | ---------- | -------------------------------- | ------------------- | ----------- |
| `contentlet` | -- | | `DotContentletItem` | `undefined` |
| `cover` | `cover` | | `boolean` | `true` |
| `playable` | `playable` | If the video is playable or not. | `boolean` | `false` |

## Dependencies

### Used by

- [dot-contentlet-thumbnail](../dot-contentlet-thumbnail)
- [dot-contentlet-thumbnail](../dot-contentlet-thumbnail)

### Graph

```mermaid
graph TD;
dot-contentlet-thumbnail --> dot-video-thumbnail
style dot-video-thumbnail fill:#f9f,stroke:#333,stroke-width:4px
```

----------------------------------------------
---

*Built with [StencilJS](https://stenciljs.com/)*
_Built with [StencilJS](https://stenciljs.com/)_
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,20 @@ describe('DotBinaryFieldEditorComponent', () => {
spectator.detectChanges();
});

it('should emit cancel event on escape keydown', () => {
const event = new KeyboardEvent('keydown', { key: 'Escape' });

const cancelSpy = jest.spyOn(spectator.component.cancel, 'emit');
const preventDefaultSpy = jest.spyOn(event, 'preventDefault');
const stopPropagationSpy = jest.spyOn(event, 'stopPropagation');

document.dispatchEvent(event);

expect(cancelSpy).toHaveBeenCalled();
expect(preventDefaultSpy).toHaveBeenCalled();
expect(stopPropagationSpy).toHaveBeenCalled();
});

describe('label', () => {
it('should set label and have css class required', () => {
const label = spectator.query(byTestId('editor-label'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
ChangeDetectorRef,
Component,
EventEmitter,
HostListener,
Input,
OnInit,
Output,
Expand Down Expand Up @@ -103,6 +104,19 @@ export class DotBinaryFieldEditorComponent implements OnInit {
return this.form.get('content') as FormControl;
}

/**
* Close the editor when the user press ESC
* And prevent the default behavior of the edit conten iframe
*
* @param {*} event
* @memberof DotBinaryFieldEditorComponent
*/
@HostListener('document:keydown.escape', ['$event']) onEscape(event) {
this.cancel.emit();
event.preventDefault();
event.stopPropagation();
}

ngOnInit(): void {
this.setFormValues();
this.name.valueChanges
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,41 @@
<div class="preview-container" [ngClass]="{ 'preview-container--fade': file.content }">
<div class="preview-code_container" *ngIf="file.content; else contentThumnail">
<code>{{ file.content }}</code>
<div class="preview-container" [ngClass]="{ 'preview-container--fade': content }">
<div
class="preview-code_container"
*ngIf="content; else contentThumnail"
(click)="this.editFile.emit()"
data-testId="code-preview">
<code>{{ content }}</code>
</div>

<ng-template #contentThumnail>
<div class="preview-image__container">
<dot-content-thumbnail
[url]="file.url"
[inode]="file.inode"
[name]="file.name"
[contentType]="file.contentType"
[titleImage]="file.titleImage"
[objectFit]="objectFit"
[iconSize]="'48px'"></dot-content-thumbnail>
<ng-container *ngIf="tempFile; else contentletThumbnail">
<dot-temp-file-thumbnail
rjvelazco marked this conversation as resolved.
Show resolved Hide resolved
[tempFile]="tempFile"
[iconSize]="'48px'"
data-testId="temp-file-thumbnail"></dot-temp-file-thumbnail>
</ng-container>

<ng-template #contentletThumbnail>
<dot-contentlet-thumbnail
[iconSize]="'48px'"
[cover]="false"
[contentlet]="contentlet"
[playableVideo]="true"
data-testId="contentlet-thumbnail">
</dot-contentlet-thumbnail>
</ng-template>
</div>

<div class="preview-metadata__container">
<span class="preview-metadata_header">{{ file.name }}</span>
<div class="preview-metadata" *ngIf="file.width && file.height">
<span class="preview-metadata_header">{{ metadata.name }}</span>
<div class="preview-metadata" *ngIf="metadata.width && metadata.height">
<i class="pi pi-arrows-alt"></i>
<span>{{ file.width }} x {{ file.height }}</span>
<span>{{ metadata.width }} x {{ metadata.height }}</span>
</div>
<div class="preview-metadata" *ngIf="file.fileSize">
<div class="preview-metadata" *ngIf="metadata.fileSize">
<i class="pi pi-file"></i>
<span>{{ file.fileSize | dotFileSizeFormat }}</span>
<span>{{ metadata.fileSize | dotFileSizeFormat }}</span>
</div>
</div>
</ng-template>
Expand Down Expand Up @@ -67,14 +79,14 @@

<p-overlayPanel #op>
<div class="preview-metadata__responsive">
<span class="preview-metadata_header">{{ file.name }}</span>
<div *ngIf="file.width && file.height">
<span class="preview-metadata_header">{{ metadata.name }}</span>
<div *ngIf="metadata.width && metadata.height">
{{ 'dot.binary.field.file.dimension' | dm }}:
<span>{{ file.width }}px, {{ file.height }}px</span>
<span>{{ metadata.width }}px, {{ metadata.height }}px</span>
</div>
<div *ngIf="file.fileSize">
<div *ngIf="metadata.fileSize">
{{ 'dot.binary.field.file.size' | dm }}:
<span>{{ file.fileSize }} Bytes</span>
<span>{{ metadata.fileSize }} Bytes</span>
</div>
</div>
</p-overlayPanel>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
height: 100%;
}

dot-contentlet-thumbnail::ng-deep {
img {
object-fit: cover;
}
}

.preview-container {
display: flex;
gap: $spacing-1;
Expand All @@ -29,9 +35,11 @@
height: 100%;
width: 100%;
user-select: none;
cursor: pointer;
}

.preview-image__container {
.preview-image__container,
dot-contentlet-thumbnail {
height: 100%;
width: 100%;
display: flex;
Expand All @@ -49,6 +57,7 @@
bottom: 0;
left: 0;
border-radius: $border-radius-md;
pointer-events: none;
}

.preview-metadata__container,
Expand Down Expand Up @@ -98,7 +107,6 @@
justify-content: flex-end;
align-items: center;
gap: $spacing-1;
width: 100%;
z-index: 100;
}

Expand All @@ -118,6 +126,7 @@ code {
width: 100%;
white-space: pre-wrap;
overflow: hidden;
line-height: normal;
}

@container preview (min-width: 376px) {
Expand Down
Loading
Loading