Skip to content

Commit

Permalink
Fixed bug on publish file contentlet (#27411)
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinDavilaDotCMS authored Jan 23, 2024
1 parent e5b18c7 commit 213cd0e
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</div>

<div class="preview-metadata__container">
<span class="preview-metadata_header">{{ metadata.name }}</span>
<span class="preview-metadata_header">{{ title }}</span>
<div class="preview-metadata" *ngIf="metadata.width && metadata.height">
<i class="pi pi-arrows-alt"></i>
<span>{{ metadata.width }} x {{ metadata.height }}</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ export class DotBinaryFieldPreviewComponent implements OnChanges {
return this.tempFile?.metadata || this.contentletMetadata;
}

get title(): string {
return this.contentlet?.fileName || this.metadata.name;
}

get contentletMetadata(): DotFileMetadata {
const { metaData = '', fieldVariable = '' } = this.contentlet;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ import { InputTextModule } from 'primeng/inputtext';
import { delay, filter, skip, tap } from 'rxjs/operators';

import { DotLicenseService, DotMessageService } from '@dotcms/data-access';
import {
DotCMSBaseTypesContentTypes,
DotCMSContentTypeField,
DotCMSContentlet,
DotCMSTempFile
} from '@dotcms/dotcms-models';
import { DotCMSContentTypeField, DotCMSContentlet, DotCMSTempFile } from '@dotcms/dotcms-models';
import {
DotDropZoneComponent,
DotMessagePipe,
Expand Down Expand Up @@ -111,13 +106,6 @@ export class DotEditContentBinaryFieldComponent
return this.field.variable;
}

private get metaDataKey(): string {
const { baseType } = this.contentlet;
const isFileAsset = baseType === DotCMSBaseTypesContentTypes.FILEASSET;

return isFileAsset ? 'metaData' : this.variable + 'MetaData';
}

get value(): string {
return this.contentlet?.[this.variable] ?? this.field.defaultValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ describe('DotBinaryFieldStore', () => {

const NEW_BINARY_FIELD_CONTENTLET = {
...BINARY_FIELD_CONTENTLET,
fileAsset: '12345',
fileAssetVersion: '12345',
metaData
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { from, Observable, of } from 'rxjs';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';

import { switchMap, tap, map, catchError } from 'rxjs/operators';
import { switchMap, tap, map, catchError, distinctUntilChanged } from 'rxjs/operators';

import { DotLicenseService, DotUploadService } from '@dotcms/data-access';
import { DotCMSContentlet, DotCMSTempFile } from '@dotcms/dotcms-models';
Expand Down Expand Up @@ -53,10 +53,10 @@ export class DotBinaryFieldStore extends ComponentStore<BinaryFieldState> {
isLoading: state.status === BinaryFieldStatus.UPLOADING
}));

readonly value$ = this.select((state) => ({
value: state.value,
fileName: state.tempFile?.fileName
}));
readonly value$ = this.select(({ value, tempFile }) => ({
value,
fileName: tempFile?.fileName
})).pipe(distinctUntilChanged((previous, current) => previous.value === current.value));

constructor(
private readonly dotUploadService: DotUploadService,
Expand Down Expand Up @@ -180,10 +180,10 @@ export class DotBinaryFieldStore extends ComponentStore<BinaryFieldState> {
return contentlet$.pipe(
tap(() => this.setUploading()),
switchMap((contentlet) => {
const { fileAsset, metaData, fieldVariable } = contentlet;
const { fileAssetVersion, metaData, fieldVariable } = contentlet;
const metadata = metaData || contentlet[`${fieldVariable}MetaData`];
const { contentType: mimeType, editableAsText, name } = metadata || {};
const contentURL = fileAsset || contentlet[fieldVariable];
const contentURL = fileAssetVersion || contentlet[`${fieldVariable}Version`];
const obs$ = editableAsText ? this.getFileContent(contentURL) : of('');

return obs$.pipe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@
* This is a workaround to get the contentlet from the API
* because there is no way to get the same contentlet the AP retreive from the dwr call.
*/
fetch('/api/v1/content/<%=contentlet.getInode()%>', {
fetch('/api/v1/content/<%=inode%>', {
method: 'GET',
headers: {
'Content-Type': 'application/json'
Expand Down Expand Up @@ -783,13 +783,18 @@
const contentBaseType = <%= contentlet.getContentType().baseType().getType() %>;
binaryField.addEventListener('valueUpdated', ({ detail }) => {
const { id, fileName } = detail;
field.value = id;
const { value, fileName } = detail;
field.value = value;
if(contentBaseType === 4){ // FileAsset
let titleField = dijit.byId("title");
let fileNameField = dijit.byId("fileName");
titleField?.setValue(fileName);
fileNameField?.setValue(fileName);
if(!titleField.value ){
titleField?.setValue(fileName);
}
if(!fileNameField.value){
fileNameField?.setValue(fileName);
}
}
});
Expand Down

0 comments on commit 213cd0e

Please sign in to comment.