mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ci:force] auto update node version when media management actions are triggered (#6992)
This commit is contained in:
@@ -89,7 +89,6 @@ export class ImgViewerComponent implements AfterViewInit, OnChanges {
|
||||
dragMode: 'move',
|
||||
background: false,
|
||||
scalable: true,
|
||||
modal: false,
|
||||
zoomOnWheel: false,
|
||||
toggleDragModeOnDblclick: false,
|
||||
viewMode: 1,
|
||||
@@ -185,8 +184,10 @@ export class ImgViewerComponent implements AfterViewInit, OnChanges {
|
||||
save() {
|
||||
this.isEditing = false;
|
||||
this.cropper.setDragMode('move');
|
||||
|
||||
this.cropper.getCroppedCanvas().toBlob((blob) => {
|
||||
this.submit.emit(blob);
|
||||
this.cropper.replace(this.cropper.getCroppedCanvas().toDataURL());
|
||||
this.cropper.clear();
|
||||
});
|
||||
}
|
||||
|
@@ -222,7 +222,6 @@
|
||||
[blobFile]="blobFile"
|
||||
[readOnly]="readOnly"
|
||||
(error)="onUnsupportedFile()"
|
||||
(submit)="onSubmitFile($event)"
|
||||
></adf-img-viewer>
|
||||
</ng-container>
|
||||
|
||||
|
@@ -961,13 +961,26 @@ describe('ViewerComponent', () => {
|
||||
component.ngOnChanges();
|
||||
});
|
||||
|
||||
it('should emit new blob when emitted by image-viewer ', () => {
|
||||
spyOn(component.fileSubmit, 'emit');
|
||||
it('should update version when emitted by image-viewer and user has update permissions', () => {
|
||||
component.readOnly = false;
|
||||
component.nodeEntry = new NodeEntry({ entry: { name: 'fakeImage.png', id: '12', content: { mimeType: 'txt' } } });
|
||||
const data = atob('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==');
|
||||
const fakeBlob = new Blob([data], { type: 'image/png' });
|
||||
component.onSubmitFile(fakeBlob);
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.fileSubmit.emit).toHaveBeenCalledWith(fakeBlob);
|
||||
expect(component.blobFile).toEqual(fakeBlob);
|
||||
});
|
||||
|
||||
it('should not update version when emitted by image-viewer and user doesn`t have update permissions', () => {
|
||||
component.readOnly = true;
|
||||
component.nodeEntry = new NodeEntry({ entry: { name: 'fakeImage.png', id: '12', content: { mimeType: 'txt' } } });
|
||||
const data = atob('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==');
|
||||
const fakeBlob = new Blob([data], { type: 'image/png' });
|
||||
component.onSubmitFile(fakeBlob);
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.blobFile).toEqual(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
|
@@ -33,6 +33,9 @@ import { ViewUtilService } from '../services/view-util.service';
|
||||
import { AppExtensionService, ViewerExtensionRef } from '@alfresco/adf-extensions';
|
||||
import { filter, skipWhile, takeUntil } from 'rxjs/operators';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { ContentService } from '../../services/content.service';
|
||||
import { UploadService } from '../../services/upload.service';
|
||||
import { FileModel } from '../../models';
|
||||
|
||||
@Component({
|
||||
selector: 'adf-viewer',
|
||||
@@ -97,10 +100,6 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
|
||||
@Input()
|
||||
showToolbar = true;
|
||||
|
||||
/** Hide or show media management actions for image-viewer component */
|
||||
@Input()
|
||||
readOnly = true;
|
||||
|
||||
/** Specifies the name of the file when it is not available from the URL. */
|
||||
@Input()
|
||||
displayName: string;
|
||||
@@ -210,10 +209,6 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
|
||||
@Output()
|
||||
invalidSharedLink = new EventEmitter();
|
||||
|
||||
/** Emitted when user updates a node via rotate, crop, etc. */
|
||||
@Output()
|
||||
fileSubmit = new EventEmitter<Blob>();
|
||||
|
||||
TRY_TIMEOUT: number = 10000;
|
||||
|
||||
viewerType = 'unknown';
|
||||
@@ -230,6 +225,7 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
|
||||
sidebarLeftTemplateContext: { node: Node } = { node: null };
|
||||
fileTitle: string;
|
||||
viewerExtensions: Array<ViewerExtensionRef> = [];
|
||||
readOnly = true;
|
||||
|
||||
private cacheBusterNumber;
|
||||
cacheTypeForContent = '';
|
||||
@@ -258,6 +254,8 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
|
||||
private viewUtilService: ViewUtilService,
|
||||
private logService: LogService,
|
||||
private extensionService: AppExtensionService,
|
||||
private contentService: ContentService,
|
||||
private uploadService: UploadService,
|
||||
private el: ElementRef,
|
||||
public dialog: MatDialog) {
|
||||
viewUtilService.maxRetries = this.maxRetries;
|
||||
@@ -402,6 +400,8 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
private async setUpNodeFile(nodeData: Node, versionData?: Version) {
|
||||
this.readOnly = !this.contentService.hasAllowableOperations(nodeData, 'update');
|
||||
|
||||
let setupNode;
|
||||
|
||||
if (versionData && versionData.content) {
|
||||
@@ -694,7 +694,22 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
onSubmitFile(newImageBlob: Blob) {
|
||||
this.fileSubmit.emit(newImageBlob);
|
||||
const newImageFile: File = new File([newImageBlob], this?.nodeEntry?.entry?.name, { type: this?.nodeEntry?.entry?.content?.mimeType });
|
||||
if (this?.nodeEntry?.entry?.id && !this.readOnly) {
|
||||
const newFile = new FileModel(
|
||||
newImageFile,
|
||||
{
|
||||
majorVersion: false,
|
||||
newVersion: true,
|
||||
parentId: this?.nodeEntry?.entry?.parentId,
|
||||
nodeType: this?.nodeEntry?.entry?.content?.mimeType
|
||||
},
|
||||
this?.nodeEntry?.entry?.id
|
||||
);
|
||||
this.blobFile = newImageBlob;
|
||||
this.uploadService.addToQueue(...[newFile]);
|
||||
this.uploadService.uploadFilesInTheQueue();
|
||||
}
|
||||
}
|
||||
|
||||
onUnsupportedFile() {
|
||||
|
Reference in New Issue
Block a user