mapcomplete/UI/Image/ImageCarousel.ts

85 lines
2.1 KiB
TypeScript
Raw Normal View History

2020-06-24 00:35:19 +02:00
import {UIElement} from "../UIElement";
import {ImageSearcher} from "../../Logic/ImageSearcher";
import {SlideShow} from "../SlideShow";
import {UIEventSource} from "../../Logic/UIEventSource";
import {
Dependencies,
TagDependantUIElement,
TagDependantUIElementConstructor
} from "../../Customizations/UIElementConstructor";
import Translation from "../i18n/Translation";
import Combine from "../Base/Combine";
import DeleteImage from "./DeleteImage";
export class ImageCarouselConstructor implements TagDependantUIElementConstructor {
IsKnown(properties: any): boolean {
return true;
}
IsQuestioning(properties: any): boolean {
return false;
}
Priority(): number {
return 0;
}
construct(dependencies: Dependencies): TagDependantUIElement {
return new ImageCarousel(dependencies.tags);
}
2020-07-20 17:30:02 +02:00
GetContent(tags: any): Translation {
return new Translation({"en":"Images without upload"});
2020-08-22 03:15:42 +02:00
}
}
export class ImageCarousel extends TagDependantUIElement {
2020-06-24 00:35:19 +02:00
public readonly slideshow: SlideShow;
2020-06-24 00:35:19 +02:00
2020-09-13 00:53:24 +02:00
constructor(tags: UIEventSource<any>) {
2020-06-24 00:35:19 +02:00
super(tags);
const searcher : UIEventSource<{url:string}[]> = new ImageSearcher(tags);
const uiElements = searcher.map((imageURLS: {key: string, url:string}[]) => {
2020-06-24 00:35:19 +02:00
const uiElements: UIElement[] = [];
for (const url of imageURLS) {
let image = ImageSearcher.CreateImageElement(url.url);
if(url.key !== undefined){
image = new Combine([
image,
new DeleteImage(url.key, tags)
]);
}
2020-07-07 15:08:52 +02:00
uiElements.push(image);
2020-06-24 00:35:19 +02:00
}
return uiElements;
});
2020-07-07 15:08:52 +02:00
2020-09-13 00:53:24 +02:00
this.slideshow = new SlideShow(uiElements).HideOnEmpty(true);
2020-06-24 00:35:19 +02:00
}
InnerRender(): string {
2020-09-13 00:53:24 +02:00
return this.slideshow.Render();
2020-07-07 15:08:52 +02:00
}
IsKnown(): boolean {
return true;
}
IsQuestioning(): boolean {
return false;
}
2020-07-25 01:07:02 +02:00
IsSkipped(): boolean {
return false;
}
Priority(): number {
return 0;
}
2020-06-24 00:35:19 +02:00
}