|
|
@ -6,6 +6,7 @@ |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; |
|
|
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; |
|
|
|
|
|
import { FormGroup, FormBuilder, Validators } from '@angular/forms'; |
|
|
|
|
|
|
|
|
import { |
|
|
import { |
|
|
ApiUrlConfig, |
|
|
ApiUrlConfig, |
|
|
@ -18,8 +19,10 @@ import { |
|
|
AuthService, |
|
|
AuthService, |
|
|
DateTime, |
|
|
DateTime, |
|
|
fadeAnimation, |
|
|
fadeAnimation, |
|
|
|
|
|
ModalView, |
|
|
MathHelper, |
|
|
MathHelper, |
|
|
NotificationService, |
|
|
NotificationService, |
|
|
|
|
|
UpdateAssetDto, |
|
|
UsersProviderService, |
|
|
UsersProviderService, |
|
|
Version |
|
|
Version |
|
|
} from 'shared'; |
|
|
} from 'shared'; |
|
|
@ -33,10 +36,20 @@ import { |
|
|
] |
|
|
] |
|
|
}) |
|
|
}) |
|
|
export class AssetComponent extends AppComponentBase implements OnInit { |
|
|
export class AssetComponent extends AppComponentBase implements OnInit { |
|
|
private assetUrlVersion = MathHelper.guid(); |
|
|
private cacheBuster = MathHelper.guid(); |
|
|
private retries = 0; |
|
|
private previewRetries = 0; |
|
|
private version: Version; |
|
|
private version: Version; |
|
|
|
|
|
|
|
|
|
|
|
public renameDialog = new ModalView(); |
|
|
|
|
|
public renameFormSubmitted = false; |
|
|
|
|
|
public renameForm: FormGroup = |
|
|
|
|
|
this.formBuilder.group({ |
|
|
|
|
|
name: ['', |
|
|
|
|
|
[ |
|
|
|
|
|
Validators.required |
|
|
|
|
|
]] |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
@Input() |
|
|
@Input() |
|
|
public initFile: File; |
|
|
public initFile: File; |
|
|
|
|
|
|
|
|
@ -55,11 +68,11 @@ export class AssetComponent extends AppComponentBase implements OnInit { |
|
|
public progress = 0; |
|
|
public progress = 0; |
|
|
|
|
|
|
|
|
public get previewUrl(): string { |
|
|
public get previewUrl(): string { |
|
|
return this.apiUrl.buildUrl(`api/assets/${this.asset.id}/?width=230&height=155&mode=Crop&q=${this.assetUrlVersion}`); |
|
|
return this.apiUrl.buildUrl(`api/assets/${this.asset.id}/?width=230&height=155&mode=Crop&version=${this.version.value}&q=${this.cacheBuster}`); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public get downloadUrl(): string { |
|
|
public get downloadUrl(): string { |
|
|
return this.apiUrl.buildUrl(`api/assets/${this.asset.id}/?q=${this.assetUrlVersion}`); |
|
|
return this.apiUrl.buildUrl(`api/assets/${this.asset.id}/?q=${this.cacheBuster}`); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public get fileType(): string { |
|
|
public get fileType(): string { |
|
|
@ -89,6 +102,7 @@ export class AssetComponent extends AppComponentBase implements OnInit { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
constructor(apps: AppsStoreService, notifications: NotificationService, users: UsersProviderService, |
|
|
constructor(apps: AppsStoreService, notifications: NotificationService, users: UsersProviderService, |
|
|
|
|
|
private readonly formBuilder: FormBuilder, |
|
|
private readonly assetsService: AssetsService, |
|
|
private readonly assetsService: AssetsService, |
|
|
private readonly authService: AuthService, |
|
|
private readonly authService: AuthService, |
|
|
private readonly apiUrl: ApiUrlConfig |
|
|
private readonly apiUrl: ApiUrlConfig |
|
|
@ -104,7 +118,6 @@ export class AssetComponent extends AppComponentBase implements OnInit { |
|
|
.switchMap(app => this.assetsService.uploadFile(app, initFile)) |
|
|
.switchMap(app => this.assetsService.uploadFile(app, initFile)) |
|
|
.subscribe(result => { |
|
|
.subscribe(result => { |
|
|
if (result instanceof AssetCreatedDto) { |
|
|
if (result instanceof AssetCreatedDto) { |
|
|
setTimeout(() => { |
|
|
|
|
|
const me = `subject:${this.authService.user!.id}`; |
|
|
const me = `subject:${this.authService.user!.id}`; |
|
|
|
|
|
|
|
|
const asset = new AssetDto( |
|
|
const asset = new AssetDto( |
|
|
@ -114,19 +127,15 @@ export class AssetComponent extends AppComponentBase implements OnInit { |
|
|
DateTime.now(), |
|
|
DateTime.now(), |
|
|
result.fileName, |
|
|
result.fileName, |
|
|
result.fileSize, |
|
|
result.fileSize, |
|
|
|
|
|
result.fileVersion, |
|
|
result.mimeType, |
|
|
result.mimeType, |
|
|
result.isImage, |
|
|
result.isImage, |
|
|
result.pixelWidth, |
|
|
result.pixelWidth, |
|
|
result.pixelHeight, |
|
|
result.pixelHeight, |
|
|
result.version); |
|
|
result.version); |
|
|
|
|
|
this.updateAsset(asset); |
|
|
this.asset = asset; |
|
|
|
|
|
this.assetUrlVersion = MathHelper.guid(); |
|
|
|
|
|
this.version = result.version; |
|
|
|
|
|
this.progress = 0; |
|
|
|
|
|
|
|
|
|
|
|
this.loaded.emit(asset); |
|
|
this.loaded.emit(asset); |
|
|
}, 500); |
|
|
|
|
|
} else { |
|
|
} else { |
|
|
this.progress = result; |
|
|
this.progress = result; |
|
|
} |
|
|
} |
|
|
@ -136,7 +145,7 @@ export class AssetComponent extends AppComponentBase implements OnInit { |
|
|
this.notifyError(error); |
|
|
this.notifyError(error); |
|
|
}); |
|
|
}); |
|
|
} else { |
|
|
} else { |
|
|
this.version = this.asset.version; |
|
|
this.updateAsset(this.asset); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -146,7 +155,6 @@ export class AssetComponent extends AppComponentBase implements OnInit { |
|
|
.switchMap(app => this.assetsService.replaceFile(app, this.asset.id, files[0], this.version)) |
|
|
.switchMap(app => this.assetsService.replaceFile(app, this.asset.id, files[0], this.version)) |
|
|
.subscribe(result => { |
|
|
.subscribe(result => { |
|
|
if (result instanceof AssetReplacedDto) { |
|
|
if (result instanceof AssetReplacedDto) { |
|
|
setTimeout(() => { |
|
|
|
|
|
const me = `subject:${this.authService.user!.id}`; |
|
|
const me = `subject:${this.authService.user!.id}`; |
|
|
|
|
|
|
|
|
const asset = new AssetDto( |
|
|
const asset = new AssetDto( |
|
|
@ -155,17 +163,13 @@ export class AssetComponent extends AppComponentBase implements OnInit { |
|
|
this.asset.created, DateTime.now(), |
|
|
this.asset.created, DateTime.now(), |
|
|
this.asset.fileName, |
|
|
this.asset.fileName, |
|
|
result.fileSize, |
|
|
result.fileSize, |
|
|
|
|
|
result.fileVersion, |
|
|
result.mimeType, |
|
|
result.mimeType, |
|
|
result.isImage, |
|
|
result.isImage, |
|
|
result.pixelWidth, |
|
|
result.pixelWidth, |
|
|
result.pixelHeight, |
|
|
result.pixelHeight, |
|
|
result.version); |
|
|
result.version); |
|
|
|
|
|
this.updateAsset(asset); |
|
|
this.asset = asset; |
|
|
|
|
|
this.assetUrlVersion = MathHelper.guid(); |
|
|
|
|
|
this.progress = 0; |
|
|
|
|
|
this.retries = 0; |
|
|
|
|
|
}, 500); |
|
|
|
|
|
} else { |
|
|
} else { |
|
|
this.progress = result; |
|
|
this.progress = result; |
|
|
} |
|
|
} |
|
|
@ -177,13 +181,66 @@ export class AssetComponent extends AppComponentBase implements OnInit { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public renameAsset() { |
|
|
|
|
|
this.renameFormSubmitted = true; |
|
|
|
|
|
|
|
|
|
|
|
if (this.renameForm.valid) { |
|
|
|
|
|
this.renameForm.disable(); |
|
|
|
|
|
|
|
|
|
|
|
const dto = new UpdateAssetDto(this.renameForm.controls['name'].value); |
|
|
|
|
|
|
|
|
|
|
|
this.appName() |
|
|
|
|
|
.switchMap(app => this.assetsService.updateAsset(app, this.asset.id, dto, this.version)) |
|
|
|
|
|
.subscribe(_ => { |
|
|
|
|
|
const me = `subject:${this.authService.user!.id}`; |
|
|
|
|
|
|
|
|
|
|
|
const asset = new AssetDto( |
|
|
|
|
|
this.asset.id, |
|
|
|
|
|
this.asset.createdBy, me, |
|
|
|
|
|
this.asset.created, DateTime.now(), |
|
|
|
|
|
dto.fileName, |
|
|
|
|
|
this.asset.fileSize, |
|
|
|
|
|
this.asset.fileVersion, |
|
|
|
|
|
this.asset.mimeType, |
|
|
|
|
|
this.asset.isImage, |
|
|
|
|
|
this.asset.pixelWidth, |
|
|
|
|
|
this.asset.pixelHeight, |
|
|
|
|
|
this.asset.version); |
|
|
|
|
|
|
|
|
|
|
|
this.updateAsset(asset); |
|
|
|
|
|
this.resetRename(); |
|
|
|
|
|
}, error => { |
|
|
|
|
|
this.notifyError(error); |
|
|
|
|
|
this.resetRename(); |
|
|
|
|
|
}); |
|
|
|
|
|
this.resetRename(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private resetRename() { |
|
|
|
|
|
this.renameForm.enable(); |
|
|
|
|
|
this.renameForm.controls['name'].setValue(this.asset.fileName); |
|
|
|
|
|
this.renameFormSubmitted = false; |
|
|
|
|
|
this.renameDialog.hide(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private updateAsset(asset: AssetDto) { |
|
|
|
|
|
this.asset = asset; |
|
|
|
|
|
this.cacheBuster = MathHelper.guid(); |
|
|
|
|
|
this.progress = 0; |
|
|
|
|
|
this.previewRetries = 0; |
|
|
|
|
|
this.version = asset.version; |
|
|
|
|
|
|
|
|
|
|
|
this.resetRename(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public retryLoadingImage() { |
|
|
public retryLoadingImage() { |
|
|
this.retries++; |
|
|
this.previewRetries++; |
|
|
|
|
|
|
|
|
if (this.retries <= 10) { |
|
|
if (this.previewRetries <= 10) { |
|
|
setTimeout(() => { |
|
|
setTimeout(() => { |
|
|
this.assetUrlVersion = MathHelper.guid(); |
|
|
this.cacheBuster = MathHelper.guid(); |
|
|
}, this.retries * 1000); |
|
|
}, this.previewRetries * 1000); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|