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

Content Edit: Allow Drag&Drop and select file #26077

Merged
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ab35d76
dev: add basic styles
rjvelazco Sep 12, 2023
0737583
dev: handle drop file errors
rjvelazco Sep 13, 2023
3147ad4
dev: create dot-drop-zone-message component
rjvelazco Sep 13, 2023
3c35e4a
dev: add internalization - i18n
rjvelazco Sep 13, 2023
f7ea9c2
dev: improve properties/methofs names
rjvelazco Sep 14, 2023
ea1705d
dev: improve interface names
rjvelazco Sep 14, 2023
b83c82b
dev: add dot binary field state
rjvelazco Sep 14, 2023
871bf1a
ev: add internalization - i18n v2
rjvelazco Sep 14, 2023
b3d20a6
Merge branch 'issue-26048-content-edit-refactor-allow-dragdrop-and-se…
rjvelazco Sep 14, 2023
eb55dd3
dev: clean up
rjvelazco Sep 14, 2023
31c14d2
test: fix broken tests
rjvelazco Sep 14, 2023
4ea5c5b
Merge branch 'master' into issue-26048-content-edit-refactor-allow-dr…
rjvelazco Sep 14, 2023
4631913
test: fix broken tests v2
rjvelazco Sep 14, 2023
4d17c22
dev: upload temp file
rjvelazco Sep 15, 2023
c3ee91a
dev: generate contenttype fields web component
rjvelazco Sep 15, 2023
9bbf067
dev: improve css classes
rjvelazco Sep 15, 2023
e4d6c7c
dev: choose file && improve styles
rjvelazco Sep 18, 2023
60997e9
dev: add remove file button
rjvelazco Sep 18, 2023
273f085
test: cover dot-ui-message component
rjvelazco Sep 18, 2023
bb5868a
test: cover binary field store
rjvelazco Sep 18, 2023
20b18ab
test: cover binary field component tests
rjvelazco Sep 19, 2023
b09a661
dev: implement binary field in .jsp
rjvelazco Sep 19, 2023
86c558d
dev: implement binary field in .jsp
rjvelazco Sep 19, 2023
77b5281
dev: clean up styles
rjvelazco Sep 19, 2023
ceae35f
feedback v1
rjvelazco Sep 20, 2023
8df269c
feedback v2
rjvelazco Sep 20, 2023
fc0935a
feedback v3
rjvelazco Sep 20, 2023
3dd4032
feedback v4
rjvelazco Sep 21, 2023
c664e2b
clean up
rjvelazco Sep 21, 2023
9753be4
feedback v5
rjvelazco Sep 21, 2023
9f56705
Merge branch 'master' into issue-26048-content-edit-refactor-allow-dr…
rjvelazco Sep 21, 2023
2969691
Merge branch 'master' into issue-26048-content-edit-refactor-allow-dr…
fmontes Sep 22, 2023
1ee6b6c
Merge branch 'master' into issue-26048-content-edit-refactor-allow-dr…
fmontes Sep 22, 2023
704c28b
Merge branch 'master' into issue-26048-content-edit-refactor-allow-dr…
fmontes Sep 22, 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
4 changes: 2 additions & 2 deletions core-web/apps/contenttype-fields-builder/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
},
{
"type": "anyComponentStyle",
"maximumWarning": "2kb",
"maximumError": "4kb"
"maximumWarning": "400kb",
"maximumError": "400kb"
}
],
"outputHashing": "all"
Expand Down
15 changes: 8 additions & 7 deletions core-web/apps/contenttype-fields-builder/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { HttpClientModule } from '@angular/common/http';
import { DoBootstrap, Injector, NgModule, Type } from '@angular/core';
import { createCustomElement } from '@angular/elements';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

import { ContenttypeFieldsModule } from '@dotcms/contenttype-fields';
import { DotMessageService } from '@dotcms/data-access';
import { DotBinaryFieldComponent } from '@dotcms/contenttype-fields';

import { AppComponent } from './app.component';

Expand All @@ -14,13 +12,16 @@ interface ContenttypeFieldElement {
component: Type<unknown>; // Expected to be a component
}

const CONTENTTYPE_FIELDS: ContenttypeFieldElement[] = [];
const CONTENTTYPE_FIELDS: ContenttypeFieldElement[] = [
{
tag: 'dotcms-binary-field',
component: DotBinaryFieldComponent
}
];

@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, BrowserAnimationsModule, HttpClientModule, ContenttypeFieldsModule],
providers: [DotMessageService],
bootstrap: [AppComponent]
imports: [BrowserModule, BrowserAnimationsModule, DotBinaryFieldComponent]
})
export class AppModule implements DoBootstrap {
constructor(private readonly injector: Injector) {}
Expand Down
19 changes: 3 additions & 16 deletions core-web/apps/contenttype-fields-builder/tsconfig.json
rjvelazco marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
{
"compilerOptions": {
"target": "es2022",
"useDefineForClassFields": false,
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"extends": "../../tsconfig.base.json",
"files": [],
"include": [],
"references": [
Expand All @@ -22,11 +13,7 @@
"path": "./tsconfig.editor.json"
}
],
"extends": "../../tsconfig.base.json",
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true
"compilerOptions": {
"target": "es2020"
}
}
4 changes: 2 additions & 2 deletions core-web/libs/contenttype-fields/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
"error",
{
"type": "attribute",
"prefix": "dotcms",
"prefix": "dot",
"style": "camelCase"
}
],
"@angular-eslint/component-selector": [
"error",
{
"type": "element",
"prefix": "dotcms",
"prefix": "dot",
"style": "kebab-case"
}
]
Expand Down
2 changes: 1 addition & 1 deletion core-web/libs/contenttype-fields/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"$schema": "../node_modules/nx/schemas/project-schema.json",
"projectType": "library",
"sourceRoot": "libs/contenttype-fields/src",
"prefix": "dotcms",
"prefix": "dot",
"targets": {
"test": {
"executor": "@nrwl/jest:jest",
Expand Down
1 change: 1 addition & 0 deletions core-web/libs/contenttype-fields/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './lib/contenttype-fields.module';
export * from './lib/fields/binary-field/binary-field.component';
Original file line number Diff line number Diff line change
@@ -1,7 +1,98 @@
<p-button (click)="showCodeEditor()" data-testId="code-button">{{ labelCode }}</p-button>
<div
class="binary-field__container"
*ngIf="vm$ | async as vm"
[ngClass]="{
'binary-field__container--uploading': vm.status === BINARY_FIELD_STATUS.UPLOADING
}">
<div
class="binary-field__drop-zone-container"
*ngIf="vm.status === BINARY_FIELD_STATUS.INIT || vm.status === BINARY_FIELD_STATUS.ERROR"
data-testId="binary-field__drop-zone-container">
<div
class="binary-field__drop-zone"
[ngClass]="{ 'binary-field__drop-zone--active': vm.dropZoneActive }">
<dot-drop-zone
[accept]="vm.rules.accept"
[maxFileSize]="vm.rules.maxFileSize"
(fileDragOver)="setDropZoneActiveState(true)"
(fileDragLeave)="setDropZoneActiveState(false)"
(fileDropped)="handleFileDrop($event)"
data-testId="dropzone">
<dot-ui-message
[message]="vm.UiMessage.message | dm : vm.UiMessage.args"
[icon]="vm.UiMessage.icon"
[severity]="vm.UiMessage.severity">
<button
class="binary-field__drop-zone-btn"
(click)="openFilePicker()"
data-testId="choose-file-btn">
{{ 'dot.binary.field.action.choose.file' | dm }}
</button>
</dot-ui-message>
</dot-drop-zone>
<input
class="binary-field__input"
#inputFile
[accept]="vm.rules.accept.join(',')"
(change)="handleFileSelection($event)"
data-testId="binary-field__file-input"
type="file" />
</div>

<p-dialog [(visible)]="visible" [style]="{ width: '80rem' }" [header]="labelCode">
<ngx-monaco-editor
class="binary-field__code-editor"
data-testId="code-editor"></ngx-monaco-editor>
</p-dialog>
<div class="binary-field__actions">
<p-button
[label]="'dot.binary.field.action.import.from.url' | dm"
(click)="openDialog(BINARY_FIELD_MODE.URL)"
data-testId="action-url-btn"
styleClass="p-button-link"
icon="pi pi-link"></p-button>
<p-button
[label]="'dot.binary.field.action.create.new.file' | dm"
(click)="openDialog(BINARY_FIELD_MODE.EDITOR)"
data-testId="action-editor-btn"
styleClass="p-button-link"
icon="pi pi-code">
</p-button>
</div>
</div>

<dot-spinner
*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>

<p-dialog
[visible]="vm.dialogOpen"
[modal]="true"
[header]="dialogHeaderMap[vm.mode] | dm"
[draggable]="false"
[resizable]="false"
(visibleChange)="visibleChange($event)">
<div [ngSwitch]="vm.mode">
<div *ngSwitchCase="BINARY_FIELD_MODE.URL" data-testId="url">
TODO: Implement Import from URL
</div>
<div *ngSwitchCase="BINARY_FIELD_MODE.EDITOR" data-testId="editor">
TODO: Implement Write Code
</div>
</div>
</p-dialog>
</div>

<div class="binary-field__helper" *ngIf="helperText">
<i class="pi pi-info-circle binary-field__helper-icon"></i>
<span data-testId="helper-text">{{ helperText }}</span>
</div>
Original file line number Diff line number Diff line change
@@ -1,5 +1,109 @@
@use "variables" as *;

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

:host ::ng-deep {
@import "libs/dotcms-scss/angular/styles";
@import "node_modules/primeng/resources/primeng.min";
@import "node_modules/primeicons/primeicons";
}

.binary-field__container {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
gap: $spacing-3;
border-radius: $border-radius-md;
border: $boder-width-md solid $color-palette-gray-300;
padding: $spacing-1;
margin-bottom: $spacing-1;
height: 10rem;
}

.binary-field__container--uploading {
border: $boder-width-lg dashed $color-palette-gray-300;
}

.binary-field__helper-icon {
color: $color-palette-gray-600;
}

.binary-field__helper {
display: flex;
justify-content: flex-start;
align-items: center;
gap: $spacing-1;
color: $color-palette-gray-700;
font-weight: $font-size-sm;
}

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

.binary-field__actions ::ng-deep {
.p-button-link {
.p-button-label {
color: $black;
}

.p-button-icon {
color: $color-palette-secondary-500;
}
}
}

.binary-field__drop-zone-container {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
width: 100%;
}

.binary-field__drop-zone {
border: $boder-width-lg dashed $input-border-color;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
border-radius: $border-radius-md;
user-select: none;
cursor: default;
flex-grow: 1;
height: 100%;

.binary-field__drop-zone-btn {
border: none;
background: none;
color: $color-palette-primary-500;
text-decoration: underline;
font-size: $font-size-md;
font-family: $font-default;
}
}

.binary-field__drop-zone--active {
border-radius: $border-radius-md;
border-color: $color-palette-secondary-500;
background: $white;
box-shadow: $md-shadow-6;
}

.binary-field__drop-zone dot-drop-zone {
height: 100%;
width: 100%;
}

.binary-field__input {
display: none;
}

.binary-field__code-editor {
border: 1px solid $input-border-color;
display: block;
Expand Down
Loading