2020-06-24 00:35:19 +02:00
|
|
|
import {UIElement} from "../UIElement";
|
|
|
|
import {ImageSearcher} from "../../Logic/ImageSearcher";
|
|
|
|
import {UIEventSource} from "../UIEventSource";
|
|
|
|
import {SlideShow} from "../SlideShow";
|
2020-06-29 03:16:34 +02:00
|
|
|
import {FixedUiElement} from "../Base/FixedUiElement";
|
2020-07-07 15:08:52 +02:00
|
|
|
import {VerticalCombine} from "../Base/VerticalCombine";
|
|
|
|
import {Changes} from "../../Logic/Changes";
|
|
|
|
import {VariableUiElement} from "../Base/VariableUIElement";
|
2020-06-24 00:35:19 +02:00
|
|
|
|
|
|
|
export class ImageCarousel extends UIElement {
|
|
|
|
/**
|
|
|
|
* There are multiple way to fetch images for an object
|
|
|
|
* 1) There is an image tag
|
|
|
|
* 2) There is an image tag, the image tag contains multiple ';'-seperated URLS
|
|
|
|
* 3) there are multiple image tags, e.g. 'image', 'image:0', 'image:1', and 'image_0', 'image_1' - however, these are pretty rare so we are gonna ignore them
|
|
|
|
* 4) There is a wikimedia_commons-tag, which either has a 'File': or a 'category:' containing images
|
|
|
|
* 5) There is a wikidata-tag, and the wikidata item either has an 'image' attribute or has 'a link to a wikimedia commons category'
|
|
|
|
* 6) There is a wikipedia article, from which we can deduct the wikidata item
|
|
|
|
*
|
|
|
|
* For some images, author and license should be shown
|
|
|
|
*/
|
|
|
|
private readonly searcher: ImageSearcher;
|
|
|
|
|
2020-06-28 00:06:23 +02:00
|
|
|
public readonly slideshow: SlideShow;
|
2020-06-24 00:35:19 +02:00
|
|
|
|
2020-07-07 15:08:52 +02:00
|
|
|
private readonly _uiElements: UIEventSource<UIElement[]>;
|
|
|
|
|
|
|
|
private readonly _deleteButtonText = new UIEventSource<string>("");
|
|
|
|
private readonly _deleteButton: UIElement;
|
|
|
|
|
|
|
|
constructor(tags: UIEventSource<any>, changes: Changes) {
|
2020-06-24 00:35:19 +02:00
|
|
|
super(tags);
|
|
|
|
|
2020-07-07 15:08:52 +02:00
|
|
|
const self = this;
|
|
|
|
this.searcher = new ImageSearcher(tags, changes);
|
2020-06-24 00:35:19 +02:00
|
|
|
|
2020-07-07 15:08:52 +02:00
|
|
|
this._uiElements = this.searcher.map((imageURLS: string[]) => {
|
2020-06-24 00:35:19 +02:00
|
|
|
const uiElements: UIElement[] = [];
|
|
|
|
for (const url of imageURLS) {
|
2020-07-07 15:08:52 +02:00
|
|
|
const image = ImageSearcher.CreateImageElement(url);
|
|
|
|
uiElements.push(image);
|
2020-06-24 00:35:19 +02:00
|
|
|
}
|
|
|
|
return uiElements;
|
|
|
|
});
|
2020-07-07 15:08:52 +02:00
|
|
|
|
2020-06-24 00:35:19 +02:00
|
|
|
this.slideshow = new SlideShow(
|
2020-07-07 15:08:52 +02:00
|
|
|
this._uiElements,
|
2020-06-27 03:06:51 +02:00
|
|
|
new FixedUiElement("")).HideOnEmpty(true);
|
2020-07-07 15:08:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
this._deleteButtonText = this.slideshow._currentSlide.map((i) => {
|
|
|
|
if(self.searcher.IsDeletable(self.searcher.data[i])){
|
|
|
|
return "DELETE";
|
|
|
|
}else{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this._deleteButton = new VariableUiElement(this._deleteButtonText)
|
|
|
|
.HideOnEmpty(true)
|
|
|
|
.onClick(() => {
|
|
|
|
self.searcher.Delete(self.searcher.data[self.slideshow._currentSlide.data]);
|
|
|
|
});
|
2020-06-24 00:35:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
InnerRender(): string {
|
2020-07-07 15:08:52 +02:00
|
|
|
return this.slideshow.Render() ;
|
|
|
|
// + this._deleteButton.Render();
|
|
|
|
}
|
|
|
|
|
|
|
|
InnerUpdate(htmlElement: HTMLElement) {
|
|
|
|
super.InnerUpdate(htmlElement);
|
|
|
|
this._deleteButton.Update();
|
2020-06-24 00:35:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Activate() {
|
|
|
|
super.Activate();
|
|
|
|
this.searcher.Activate();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|