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

Edit Contentlet: Allow user to upload files from external sources #26313

Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
abe7ab8
dev: add url mode
rjvelazco Sep 27, 2023
a8e1ae4
dev: create DotBinaryFieldUrlMode component
rjvelazco Sep 27, 2023
12faf12
test: cover dotBinaryFieldUrlMode Component tests
rjvelazco Sep 28, 2023
07ebeba
dev: add i18n - internalization
rjvelazco Sep 28, 2023
effa9e0
Merge branch 'master' into issue-26047-edit-contentlet-allow-user-to-…
rjvelazco Sep 28, 2023
ce802ab
dev: improve style & build binary field
rjvelazco Sep 28, 2023
34b6fc2
dev: avoid closing the dialog while uploading
rjvelazco Sep 29, 2023
df24057
dev: add store for URL Mode
rjvelazco Oct 2, 2023
341d1d9
test: DotBinaryFieldUrlMode Component
rjvelazco Oct 2, 2023
d4fadb1
Merge branch 'master' into issue-26047-edit-contentlet-allow-user-to-…
rjvelazco Oct 2, 2023
4720997
dev: generate contenttype-fields-styles.css file
rjvelazco Oct 3, 2023
3d2aaf4
clean up
rjvelazco Oct 3, 2023
0508569
Merge branch 'master' into issue-26047-edit-contentlet-allow-user-to-…
rjvelazco Oct 3, 2023
a95011f
Merge branch 'master' into issue-26047-edit-contentlet-allow-user-to-…
rjvelazco Oct 3, 2023
7b2fcd5
clean up v2
rjvelazco Oct 3, 2023
f6cac1a
Merge branch 'master' into issue-26047-edit-contentlet-allow-user-to-…
zJaaal Oct 3, 2023
66a5986
feedback
rjvelazco Oct 3, 2023
f0af00f
Merge branch 'issue-26047-edit-contentlet-allow-user-to-upload-files-…
rjvelazco Oct 3, 2023
c9b81ff
clean up
rjvelazco Oct 3, 2023
0d89925
feedback v1
rjvelazco Oct 4, 2023
2f50886
move fonts.scss to dotcms-scss/angular
rjvelazco Oct 4, 2023
cfb5e3b
feedback v3
rjvelazco Oct 4, 2023
7aa6731
clean up
rjvelazco Oct 4, 2023
4f22c6d
feeback: input & button styles
rjvelazco Oct 5, 2023
d9062ee
feeback: binart fiel css file
rjvelazco Oct 5, 2023
3cdd3ce
styles: fix error message height
rjvelazco Oct 5, 2023
e5b396f
Merge branch 'master' into issue-26047-edit-contentlet-allow-user-to-…
rjvelazco Oct 6, 2023
76890a5
clean up
rjvelazco Oct 6, 2023
ff72d17
feedback: button styles
rjvelazco Oct 6, 2023
332852f
dev: build binary field web-component
rjvelazco Oct 6, 2023
b3cb1c7
clean up
rjvelazco Oct 6, 2023
5585633
Merge branch 'master' into issue-26047-edit-contentlet-allow-user-to-…
rjvelazco Oct 6, 2023
757a308
fix: frontend tests
rjvelazco Oct 6, 2023
2353aa3
clean up v2
rjvelazco Oct 6, 2023
19500d3
build web component
rjvelazco Oct 6, 2023
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
12 changes: 11 additions & 1 deletion core-web/apps/contenttype-fields-builder/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,17 @@
"apps/contenttype-fields-builder/src/favicon.ico",
"apps/contenttype-fields-builder/src/assets"
],
"styles": ["apps/contenttype-fields-builder/src/styles.scss"],
"styles": [
"node_modules/primeicons/primeicons.css",
"node_modules/primeng/resources/primeng.min.css",
"libs/dotcms-scss/angular/dotcms-theme/_misc.scss",
"libs/dotcms-scss/angular/dotcms-theme/components/buttons/common.scss",
"libs/dotcms-scss/angular/dotcms-theme/components/buttons/_button.scss",
"libs/dotcms-scss/angular/dotcms-theme/components/_dialog.scss",
"libs/dotcms-scss/angular/dotcms-theme/components/form/_inputtext.scss",
"libs/dotcms-scss/angular/dotcms-theme/utils/_validation.scss",
"libs/block-editor/src/fonts.scss"
rjvelazco marked this conversation as resolved.
Show resolved Hide resolved
],
"stylePreprocessorOptions": {
"includePaths": ["libs/dotcms-scss/angular"]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class="binary-field__drop-zone"
[ngClass]="{ 'binary-field__drop-zone--active': vm.dropZoneActive }">
<dot-drop-zone
[accept]="acceptedTypes"
[accept]="accept"
[maxFileSize]="maxFileSize"
(fileDragOver)="setDropZoneActiveState(true)"
(fileDragLeave)="setDropZoneActiveState(false)"
Expand All @@ -33,7 +33,7 @@
<input
class="binary-field__input"
#inputFile
[accept]="acceptedTypes.join(',')"
[accept]="accept.join(',')"
(change)="handleFileSelection($event)"
data-testId="binary-field__file-input"
type="file" />
Expand Down Expand Up @@ -73,17 +73,21 @@
data-testId="action-remove-btn"
icon="pi pi-trash"></p-button>
</div>

<p-dialog
[visible]="vm.dialogOpen"
[modal]="true"
[header]="dialogHeaderMap[vm.mode] | dm"
[draggable]="false"
[resizable]="false"
(onHide)="dialogClosed()"
(visibleChange)="visibleChange($event)">
<div [ngSwitch]="vm.mode">
<div *ngSwitchCase="BINARY_FIELD_MODE.URL" data-testId="url">
TODO: Implement Import from URL
<dot-dot-binary-field-url-mode
[accept]="accept"
[maxFileSize]="maxFileSize"
(tempFile)="setTempFile($event)"
(cancel)="visibleChange(false)"></dot-dot-binary-field-url-mode>
rjvelazco marked this conversation as resolved.
Show resolved Hide resolved
</div>
<div *ngSwitchCase="BINARY_FIELD_MODE.EDITOR" data-testId="editor">
TODO: Implement Write Code
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
@use "variables" as *;
rjvelazco marked this conversation as resolved.
Show resolved Hide resolved

@import "libs/block-editor/src/fonts"; // Import PrimeNG Icon

:host ::ng-deep {
@import "libs/dotcms-scss/angular/dotcms-theme/components/buttons/button";
@import "libs/dotcms-scss/angular/dotcms-theme/components/dialog";
@import "node_modules/primeicons/primeicons";
@import "libs/dotcms-scss/angular/dotcms-theme/_misc.scss";
}

.binary-field__container {
display: flex;
justify-content: center;
Expand Down Expand Up @@ -119,3 +110,11 @@
display: block;
height: 25rem;
}

p-dialog ::ng-deep {
.p-dialog-mask.p-component-overlay {
background-color: transparent;
-webkit-backdrop-filter: blur($blur-md);
backdrop-filter: blur($blur-md);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('DotBinaryFieldComponent', () => {
spectator = createComponent({
detectChanges: false,
props: {
accept: 'image/*',
accept: ['image/*'],
maxFileSize: 1000,
helperText: 'helper text'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

import { ButtonModule } from 'primeng/button';
import { DialogModule } from 'primeng/dialog';
import { InputTextModule } from 'primeng/inputtext';

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

import { DotBinaryFieldComponent } from './binary-field.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';

import { CONTENTTYPE_FIELDS_MESSAGE_MOCK } from '../../utils/mock';
Expand All @@ -32,7 +34,9 @@ export default {
DotDropZoneComponent,
DotBinaryFieldUiMessageComponent,
DotMessagePipe,
DotSpinnerModule
DotSpinnerModule,
InputTextModule,
DotBinaryFieldUrlModeComponent
],
providers: [
DotBinaryFieldStore,
Expand Down Expand Up @@ -65,14 +69,14 @@ export default {
})
],
args: {
accept: 'image/*',
accept: ['image/*'],
maxFileSize: 1000000,
helperText: 'This field accepts only images with a maximum size of 1MB.'
},
argTypes: {
accept: {
defaultValue: 'image/*',
control: 'string',
defaultValue: ['image/*'],
control: 'object',
description: 'Accepted file types'
},
maxFileSize: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {

import { ButtonModule } from 'primeng/button';
import { DialogModule } from 'primeng/dialog';
import { InputTextModule } from 'primeng/inputtext';

import { skip } from 'rxjs/operators';

Expand All @@ -29,6 +30,7 @@ import {
} from '@dotcms/ui';

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 {
BINARY_FIELD_MODE,
BINARY_FIELD_STATUS,
Expand Down Expand Up @@ -60,7 +62,9 @@ const initialState: BinaryFieldState = {
DotMessagePipe,
DotBinaryFieldUiMessageComponent,
DotSpinnerModule,
HttpClientModule
HttpClientModule,
InputTextModule,
DotBinaryFieldUrlModeComponent
],
providers: [DotBinaryFieldStore],
templateUrl: './binary-field.component.html',
Expand All @@ -69,11 +73,7 @@ const initialState: BinaryFieldState = {
})
export class DotBinaryFieldComponent implements OnInit {
//Inputs
acceptedTypes: string[] = [];
@Input() set accept(accept: string) {
this.acceptedTypes = accept.split(',').map((type) => type.trim());
}

@Input() accept: string[] = [];
@Input() maxFileSize: number;
@Input() helperText: string;

Expand Down Expand Up @@ -161,6 +161,15 @@ export class DotBinaryFieldComponent implements OnInit {
}
}

/**
* Listen to dialog close event
*
* @memberof DotBinaryFieldComponent
*/
dialogClosed() {
this.dotBinaryFieldStore.setMode(BINARY_FIELD_MODE.DROPZONE);
}

/**
* Open file picker dialog
*
Expand Down Expand Up @@ -195,8 +204,8 @@ export class DotBinaryFieldComponent implements OnInit {
// TODO: Implement - Write Code
}

handleExternalSourceFile(_event) {
// TODO: Implement - FROM URL
setTempFile(tempFile: DotCMSTempFile) {
this.dotBinaryFieldStore.setTempFile(tempFile);
}

/**
Expand All @@ -210,7 +219,7 @@ export class DotBinaryFieldComponent implements OnInit {
fileTypeMismatch,
maxFileSizeExceeded
}: DropZoneFileValidity): UiMessageI {
const acceptedTypes = this.acceptedTypes.join(', ');
const acceptedTypes = this.accept.join(', ');
const maxSize = `${this.maxFileSize} bytes`;
let uiMessage: UiMessageI;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<form
class="url-mode__form"
*ngIf="vm$ | async as vm"
[formGroup]="form"
(ngSubmit)="onSubmit()"
data-testId="form">
<div class="url-mode__input-container">
rjvelazco marked this conversation as resolved.
Show resolved Hide resolved
<span>{{ 'dot.binary.field.action.import.from.url' | dm }}</span>
<input
type="text"
formControlName="url"
pInputText
placeholder="https://www.google.com/"
rjvelazco marked this conversation as resolved.
Show resolved Hide resolved
data-testId="url-input" />
<div class="error-message p-invalid" data-testId="error-message">
<span *ngIf="vm.error">{{ vm.error | dm }}</span>
</div>
</div>
<div class="url-mode__actions">
<p-button
[label]="'dot.common.cancel' | dm"
(click)="cancelUpload()"
styleClass="p-button-outlined"
data-testId="cancel-button"></p-button>

<div class="url-mode__actions--main">
<p-button
rjvelazco marked this conversation as resolved.
Show resolved Hide resolved
*ngIf="!vm.isLoading; else loadingButton"
[label]="'dot.common.import' | dm"
[icon]="'pi pi-download'"
type="submit"
data-testId="import-button"></p-button>

<ng-template #loadingButton>
<p-button [icon]="'pi pi-spin pi-spinner'" data-testId="loading-button"> </p-button>
</ng-template>
</div>
</div>
</form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
@use "variables" as *;

.url-mode__form {
display: flex;
flex-direction: column;
gap: $spacing-3;
justify-content: center;
align-items: flex-start;
}

.url-mode__input-container {
width: 100%;
display: flex;
gap: $spacing-1;
flex-direction: column;

input {
width: 100%;
rjvelazco marked this conversation as resolved.
Show resolved Hide resolved
min-width: 32rem;
}
}

.url-mode__actions {
width: 100%;
display: flex;
gap: $spacing-1;
align-items: center;
justify-content: flex-end;
}

.error-message {
justify-content: flex-start;
align-items: flex-start;
display: flex;
font-size: $font-size-sm;
color: $color-alert-red;
height: $spacing-3;
}
rjvelazco marked this conversation as resolved.
Show resolved Hide resolved

.url-mode__actions--main {
width: 6.85rem;

&::ng-deep {
p-button .p-button {
width: 100%;
}

.p-button-icon-only {
border-radius: $border-radius-md;
}
rjvelazco marked this conversation as resolved.
Show resolved Hide resolved
}
}
Loading
Loading