UI: Apply special prefix to gallery image inputs.
This commit is contained in:
parent
344a7afb47
commit
5f98e654cd
@ -25,7 +25,7 @@ import {
|
|||||||
ImageResourceInfo,
|
ImageResourceInfo,
|
||||||
imageResourceType,
|
imageResourceType,
|
||||||
ImageResourceType,
|
ImageResourceType,
|
||||||
IMAGES_URL_PREFIX, isImageResourceUrl, ImageExportData
|
IMAGES_URL_PREFIX, isImageResourceUrl, ImageExportData, removeTbImagePrefix
|
||||||
} from '@shared/models/resource.models';
|
} from '@shared/models/resource.models';
|
||||||
import { catchError, map, switchMap } from 'rxjs/operators';
|
import { catchError, map, switchMap } from 'rxjs/operators';
|
||||||
import { DomSanitizer, SafeUrl } from '@angular/platform-browser';
|
import { DomSanitizer, SafeUrl } from '@angular/platform-browser';
|
||||||
@ -97,6 +97,7 @@ export class ImageService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public resolveImageUrl(imageUrl: string, preview = false, asString = false, emptyUrl = NO_IMAGE_DATA_URI): Observable<SafeUrl | string> {
|
public resolveImageUrl(imageUrl: string, preview = false, asString = false, emptyUrl = NO_IMAGE_DATA_URI): Observable<SafeUrl | string> {
|
||||||
|
imageUrl = removeTbImagePrefix(imageUrl);
|
||||||
if (isImageResourceUrl(imageUrl)) {
|
if (isImageResourceUrl(imageUrl)) {
|
||||||
return this.getImageDataUrl(imageUrl, preview, asString, emptyUrl);
|
return this.getImageDataUrl(imageUrl, preview, asString, emptyUrl);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -33,7 +33,7 @@ import {
|
|||||||
extractParamsFromImageResourceUrl,
|
extractParamsFromImageResourceUrl,
|
||||||
ImageResourceInfo,
|
ImageResourceInfo,
|
||||||
isBase64DataImageUrl,
|
isBase64DataImageUrl,
|
||||||
isImageResourceUrl
|
isImageResourceUrl, prependTbImagePrefix, removeTbImagePrefix
|
||||||
} from '@shared/models/resource.models';
|
} from '@shared/models/resource.models';
|
||||||
import { ImageService } from '@core/http/image.service';
|
import { ImageService } from '@core/http/image.service';
|
||||||
import { MatButton } from '@angular/material/button';
|
import { MatButton } from '@angular/material/button';
|
||||||
@ -123,12 +123,13 @@ export class GalleryImageInputComponent extends PageComponent implements OnInit,
|
|||||||
}
|
}
|
||||||
|
|
||||||
writeValue(value: string): void {
|
writeValue(value: string): void {
|
||||||
|
value = removeTbImagePrefix(value);
|
||||||
if (this.imageUrl !== value) {
|
if (this.imageUrl !== value) {
|
||||||
this.reset();
|
this.reset();
|
||||||
this.imageUrl = value;
|
this.imageUrl = value;
|
||||||
this.detectLinkType();
|
this.detectLinkType();
|
||||||
if (this.linkType === ImageLinkType.resource) {
|
if (this.linkType === ImageLinkType.resource) {
|
||||||
const params = extractParamsFromImageResourceUrl(value);
|
const params = extractParamsFromImageResourceUrl(this.imageUrl);
|
||||||
this.loadingImageResource = true;
|
this.loadingImageResource = true;
|
||||||
this.imageService.getImageInfo(params.type, params.key, {ignoreLoading: true, ignoreErrors: true}).subscribe(
|
this.imageService.getImageInfo(params.type, params.key, {ignoreLoading: true, ignoreErrors: true}).subscribe(
|
||||||
{
|
{
|
||||||
@ -171,7 +172,7 @@ export class GalleryImageInputComponent extends PageComponent implements OnInit,
|
|||||||
this.cd.markForCheck();
|
this.cd.markForCheck();
|
||||||
if (this.imageUrl !== value) {
|
if (this.imageUrl !== value) {
|
||||||
this.imageUrl = value;
|
this.imageUrl = value;
|
||||||
this.propagateChange(this.imageUrl);
|
this.propagateChange(prependTbImagePrefix(this.imageUrl));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -27,6 +27,7 @@ import { ImageLinkType } from '@shared/components/image/gallery-image-input.comp
|
|||||||
import { TbPopoverService } from '@shared/components/popover.service';
|
import { TbPopoverService } from '@shared/components/popover.service';
|
||||||
import { MatButton } from '@angular/material/button';
|
import { MatButton } from '@angular/material/button';
|
||||||
import { ImageGalleryComponent } from '@shared/components/image/image-gallery.component';
|
import { ImageGalleryComponent } from '@shared/components/image/image-gallery.component';
|
||||||
|
import { prependTbImagePrefixToUrls, removeTbImagePrefixFromUrls } from '@shared/models/resource.models';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'tb-multiple-gallery-image-input',
|
selector: 'tb-multiple-gallery-image-input',
|
||||||
@ -88,12 +89,12 @@ export class MultipleGalleryImageInputComponent extends PageComponent implements
|
|||||||
|
|
||||||
writeValue(value: string[]): void {
|
writeValue(value: string[]): void {
|
||||||
this.reset();
|
this.reset();
|
||||||
this.imageUrls = value || [];
|
this.imageUrls = removeTbImagePrefixFromUrls(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateModel() {
|
private updateModel() {
|
||||||
this.cd.markForCheck();
|
this.cd.markForCheck();
|
||||||
this.propagateChange(this.imageUrls);
|
this.propagateChange(prependTbImagePrefixToUrls(this.imageUrls));
|
||||||
}
|
}
|
||||||
|
|
||||||
private reset() {
|
private reset() {
|
||||||
|
|||||||
@ -127,11 +127,27 @@ export const toImageDeleteResult = (image: ImageResourceInfo, e?: any): ImageDel
|
|||||||
export const imageResourceType = (imageInfo: ImageResourceInfo): ImageResourceType =>
|
export const imageResourceType = (imageInfo: ImageResourceInfo): ImageResourceType =>
|
||||||
(!imageInfo.tenantId || imageInfo.tenantId?.id === NULL_UUID) ? 'system' : 'tenant';
|
(!imageInfo.tenantId || imageInfo.tenantId?.id === NULL_UUID) ? 'system' : 'tenant';
|
||||||
|
|
||||||
|
export const TB_IMAGE_PREFIX = 'tb-image;';
|
||||||
|
|
||||||
export const IMAGES_URL_REGEXP = /\/api\/images\/(tenant|system)\/(.*)/;
|
export const IMAGES_URL_REGEXP = /\/api\/images\/(tenant|system)\/(.*)/;
|
||||||
export const IMAGES_URL_PREFIX = '/api/images';
|
export const IMAGES_URL_PREFIX = '/api/images';
|
||||||
|
|
||||||
export const IMAGE_BASE64_URL_PREFIX = 'data:image/';
|
export const IMAGE_BASE64_URL_PREFIX = 'data:image/';
|
||||||
|
|
||||||
|
export const removeTbImagePrefix = (url: string): string => url ? url.replace(TB_IMAGE_PREFIX, '') : url;
|
||||||
|
|
||||||
|
export const removeTbImagePrefixFromUrls = (urls: string[]): string[] => urls ? urls.map(url => removeTbImagePrefix(url)) : [];
|
||||||
|
|
||||||
|
export const prependTbImagePrefix = (url: string): string => {
|
||||||
|
if (url && !url.startsWith(TB_IMAGE_PREFIX)) {
|
||||||
|
url = TB_IMAGE_PREFIX + url;
|
||||||
|
}
|
||||||
|
return url;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const prependTbImagePrefixToUrls = (urls: string[]): string[] => urls ? urls.map(url => prependTbImagePrefix(url)) : [];
|
||||||
|
|
||||||
|
|
||||||
export const isImageResourceUrl = (url: string): boolean => url && IMAGES_URL_REGEXP.test(url);
|
export const isImageResourceUrl = (url: string): boolean => url && IMAGES_URL_REGEXP.test(url);
|
||||||
|
|
||||||
export const extractParamsFromImageResourceUrl = (url: string): {type: ImageResourceType; key: string} => {
|
export const extractParamsFromImageResourceUrl = (url: string): {type: ImageResourceType; key: string} => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user