implements OnInit {
+ @Input()
+ public isCompact = false;
+
+ public valueControl = new FormControl('');
+
+ public valueThumb =
+ this.valueControl.valueChanges.pipe(
+ startWith(this.valueControl.value),
+ shareReplay(1),
+ map(value => thumbnail(value, 400) || value));
+
+ public stockPhotoSearch = new FormControl('');
+
+ public stockPhotos =
+ this.stockPhotoSearch.valueChanges.pipe(
+ startWith(this.stockPhotoSearch.value),
+ distinctUntilChanged(),
+ debounceTime(500),
+ tap(query => {
+ if (query && query.length > 0) {
+ this.next({ isLoading: true });
+ }
+ }),
+ switchMap(query => {
+ if (query && query.length > 0) {
+ return this.stockPhotoService.getImages(query);
+ } else {
+ return of([]);
+ }
+ }),
+ tap(() => {
+ this.next({ isLoading: false });
+ }));
+
+ constructor(changeDetector: ChangeDetectorRef,
+ private readonly stockPhotoService: StockPhotoService
+ ) {
+ super(changeDetector, {});
+ }
+
+ public ngOnInit() {
+ this.own(this.valueThumb);
+
+ this.own(
+ this.valueControl.valueChanges
+ .subscribe(value => {
+ this.callChange(value);
+ }));
+ }
+
+ public writeValue(obj: string) {
+ if (Types.isString(obj)) {
+ this.valueControl.setValue(obj, { emitEvent: true });
+ } else {
+ this.valueControl.setValue('', { emitEvent: true });
+ }
+ }
+
+ public selectPhoto(photo: StockPhotoDto) {
+ if (!this.snapshot.isDisabled) {
+ this.valueControl.setValue(photo.url);
+ }
+ }
+
+ public reset() {
+ if (!this.snapshot.isDisabled) {
+ this.valueControl.setValue('');
+ }
+ }
+
+ public isSelected(photo: StockPhotoDto) {
+ return photo.url === this.valueControl.value;
+ }
+
+ public trackByPhoto(index: number, photo: StockPhotoDto) {
+ return photo.thumbUrl;
+ }
+}
\ No newline at end of file
diff --git a/frontend/app/features/schemas/pages/schema/types/string-ui.component.html b/frontend/app/features/schemas/pages/schema/types/string-ui.component.html
index 3cd8cb71e..3b1ad566a 100644
--- a/frontend/app/features/schemas/pages/schema/types/string-ui.component.html
+++ b/frontend/app/features/schemas/pages/schema/types/string-ui.component.html
@@ -88,6 +88,13 @@
HTML
+