mapcomplete/UI/Image/ImageCarousel.ts

38 lines
1.3 KiB
TypeScript
Raw Normal View History

2020-06-23 22:35:19 +00:00
import {UIElement} from "../UIElement";
import {ImageSearcher} from "../../Logic/ImageSearcher";
2020-10-14 10:15:09 +00:00
import {SlideShow} from "./SlideShow";
import {UIEventSource} from "../../Logic/UIEventSource";
import Combine from "../Base/Combine";
import DeleteImage from "./DeleteImage";
2020-10-27 00:01:34 +00:00
export class ImageCarousel extends UIElement{
2020-06-23 22:35:19 +00:00
2020-11-02 17:59:21 +00:00
public readonly slideshow: UIElement;
2020-06-23 22:35:19 +00:00
constructor(tags: UIEventSource<any>, imagePrefix: string = "image", loadSpecial: boolean =true) {
2020-06-23 22:35:19 +00:00
super(tags);
const searcher : UIEventSource<{url:string}[]> = new ImageSearcher(tags, imagePrefix, loadSpecial);
const uiElements = searcher.map((imageURLS: {key: string, url:string}[]) => {
2020-06-23 22:35:19 +00: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 13:08:52 +00:00
uiElements.push(image);
2020-06-23 22:35:19 +00:00
}
return uiElements;
});
2020-07-07 13:08:52 +00:00
2020-09-12 22:53:24 +00:00
this.slideshow = new SlideShow(uiElements).HideOnEmpty(true);
2020-11-02 17:59:21 +00:00
2020-06-23 22:35:19 +00:00
}
2020-11-02 11:38:04 +00:00
2020-06-23 22:35:19 +00:00
InnerRender(): string {
2020-09-12 22:53:24 +00:00
return this.slideshow.Render();
2020-07-07 13:08:52 +00:00
}
2020-06-23 22:35:19 +00:00
}