Skip to content

Commit

Permalink
dev: filew preview v1
Browse files Browse the repository at this point in the history
  • Loading branch information
rjvelazco committed Oct 19, 2023
1 parent 14ef42b commit 42b1e69
Show file tree
Hide file tree
Showing 15 changed files with 510 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,13 @@
*ngIf="vm.status === BINARY_FIELD_STATUS.UPLOADING"
data-testId="loading"></dot-spinner>

<!-- This component is another ticket -->
<div *ngIf="vm.status === BINARY_FIELD_STATUS.PREVIEW" data-testId="preview">
<span>
{{ vm.tempFile.fileName }}
</span>
<br />
<p-button
class="p-button-outlined"
[label]="'dot.binary.field.action.remove' | dm"
(click)="removeFile()"
data-testId="action-remove-btn"
icon="pi pi-trash"></p-button>
</div>
<dot-binary-field-preview
*ngIf="vm.status === BINARY_FIELD_STATUS.PREVIEW"
[previewData]="vm.previewFile"
(click)="removeFile()"
data-testId="preview">
</dot-binary-field-preview>

<p-dialog
[(visible)]="dialogOpen"
[modal]="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
border: $field-border-size solid $color-palette-gray-300;
padding: $spacing-1;
margin-bottom: $spacing-1;
height: 10rem;
height: 12.5rem;
max-width: 36rem;
}

.binary-field__container--uploading {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import { InputTextModule } from 'primeng/inputtext';

import { DotMessageService, DotUploadService } from '@dotcms/data-access';
import {
DotContentThumbnailComponent,
DotDropZoneComponent,
DotFieldValidationMessageComponent,
DotMessagePipe,
DotSpinnerModule
} from '@dotcms/ui';

import { DotBinaryFieldComponent } from './binary-field.component';
import { DotBinaryFieldPreviewComponent } from './components/dot-binary-field-preview/dot-binary-field-preview.component';
import { DotBinaryFieldUiMessageComponent } from './components/dot-binary-field-ui-message/dot-binary-field-ui-message.component';
import { DotBinaryFieldUrlModeComponent } from './components/dot-binary-field-url-mode/dot-binary-field-url-mode.component';
import { DotBinaryFieldStore } from './store/binary-field.store';
Expand All @@ -42,29 +44,28 @@ export default {
DotSpinnerModule,
InputTextModule,
DotBinaryFieldUrlModeComponent,
DotFieldValidationMessageComponent
DotBinaryFieldPreviewComponent,
DotFieldValidationMessageComponent,
DotContentThumbnailComponent
],
providers: [
DotBinaryFieldStore,
{
provide: DotUploadService,
useValue: {
uploadFile: () => {
return new Promise((resolve, reject) => {
return new Promise((resolve, _reject) => {
setTimeout(() => {
reject({
message: 'error URL'
resolve({
fileName: 'Image.jpg',
folder: 'folder',
id: 'tempFileId',
image: true,
length: 10000,
mimeType: 'mimeType',
referenceUrl: 'referenceUrl',
thumbnailUrl: 'thumbnailUrl'
});
// resolve({
// fileName: 'Image.jpg',
// folder: 'folder',
// id: 'tempFileId',
// image: true,
// length: 10000,
// mimeType: 'mimeType',
// referenceUrl: 'referenceUrl',
// thumbnailUrl: 'thumbnailUrl'
// });
}, 4000);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
DropZoneFileValidity
} from '@dotcms/ui';

import { DotBinaryFieldPreviewComponent } from './components/dot-binary-field-preview/dot-binary-field-preview.component';
import { DotBinaryFieldUiMessageComponent } from './components/dot-binary-field-ui-message/dot-binary-field-ui-message.component';
import { DotBinaryFieldUrlModeComponent } from './components/dot-binary-field-url-mode/dot-binary-field-url-mode.component';
import {
Expand All @@ -41,6 +42,24 @@ import {
import { UI_MESSAGE_KEYS, UiMessageI, getUiMessage } from '../../utils/binary-field-utils';

const initialState: BinaryFieldState = {
previewFile: {
type: 'image',
resolution: {
width: '400',
height: '400'
},
fileSize: 8000,
content: '',
mimeType: 'image/png',
inode: '123456789',
titleImage: 'true',
name: 'image.jpg',
title: 'image.jpg',
hasTitleImage: 'true',
contentType: 'image/png',
__icon__: 'contentIcon',
contentTypeIcon: 'image'
},
file: null,
tempFile: null,
mode: BINARY_FIELD_MODE.DROPZONE,
Expand All @@ -63,7 +82,8 @@ const initialState: BinaryFieldState = {
DotSpinnerModule,
HttpClientModule,
InputTextModule,
DotBinaryFieldUrlModeComponent
DotBinaryFieldUrlModeComponent,
DotBinaryFieldPreviewComponent
],
providers: [DotBinaryFieldStore],
templateUrl: './binary-field.component.html',
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,47 @@
<p>dot-binary-field-preview works!</p>
<div
class="preview_container"
[ngClass]="{ 'preview_container--fade': previewData?.type === 'file' }">
<ng-container *ngIf="previewData.type !== 'file'; else filePreview">
<div class="preview-image_container">
<dot-content-thumbnail
[contentType]="previewData.contentType"
[inode]="previewData.inode"
[name]="previewData.name"
[iconSize]="'48px'"></dot-content-thumbnail>
</div>

<div class="preview-metadata_container">
<div class="preview-metadata_info">
<h4>{{ previewData.name }}</h4>
<div class="preview-metadata" *ngIf="resolution">
<i class="pi pi-arrows-alt" style="font-size: 1rem"></i>
<span>{{ resolution.width }}px, {{ resolution.height }}px</span>
</div>
<div class="preview-metadata">
<i class="pi pi-file" style="font-size: 1rem"></i>
<span>{{ previewData.fileSize | number : '1.0-2' }} Bytes</span>
</div>
</div>
</div>
</ng-container>

<ng-template #filePreview>
<code>{{ previewData.content }}</code>
</ng-template>

<div></div>

<div class="preview-metadata_actions">
<p-button
[label]="'Remove'"
(click)="removeFile.emit()"
styleClass="p-button-link p-button-sm p-button-secondary"
icon="pi pi-trash"></p-button>
<p-button
[label]="'Edit'"
(click)="editFile.emit(contentType)"
severity="secondary"
styleClass="p-button-outlined p-button-sm p-button-secondary"
icon="pi pi-pencil"></p-button>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
@use "variables" as *;

:host {
display: block;
width: 100%;
height: 100%;
}

.preview_container {
display: flex;
gap: $spacing-1;
align-items: flex-start;
height: 100%;
max-width: 36rem;
width: 100%;
position: relative;
}

.preview-image_container ::ng-deep {
height: 100%;
width: 280px;
display: flex;
justify-content: center;
align-items: center;
background: $color-palette-gray-200;

.thumbnail {
img,
video {
object-fit: contain;
}
}
}

.preview_container--fade::after {
content: "";
background: linear-gradient(0deg, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0) 100%);
position: absolute;
width: 100%;
height: 50%;
bottom: 0;
left: 0;
border-radius: $border-radius-md;
}

.preview-metadata_container {
flex-grow: 1;
padding: $spacing-1;
display: flex;
justify-content: center;
flex-direction: column;
height: 100%;
}

.preview-metadata_info {
flex-grow: 1;
display: flex;
gap: $spacing-1;
flex-direction: column;

h4 {
font-size: $font-size-md;
font-weight: $font-weight-bold;
margin: 0;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
}

.preview-metadata {
display: flex;
justify-content: flex-start;
align-items: center;
gap: $spacing-1;

span {
color: $color-palette-gray-700;
}
}

.preview-metadata_actions {
position: absolute;
bottom: $spacing-1;
right: $spacing-1;
display: flex;
justify-content: flex-end;
align-items: center;
gap: $spacing-1;
width: 100%;
z-index: 100;
}

code {
background: $white;
color: $color-palette-primary-500;
height: 100%;
width: 100%;
white-space: pre-wrap;
overflow: hidden;
}
Loading

0 comments on commit 42b1e69

Please sign in to comment.