2020-06-24 00:35:19 +02:00
|
|
|
import {UIElement} from "../UIElement";
|
|
|
|
import {ImageSearcher} from "../../Logic/ImageSearcher";
|
|
|
|
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 {VariableUiElement} from "../Base/VariableUIElement";
|
2020-07-08 11:23:36 +02:00
|
|
|
import {ConfirmDialog} from "../ConfirmDialog";
|
2020-08-17 17:23:15 +02:00
|
|
|
import {UIEventSource} from "../../Logic/UIEventSource";
|
2020-07-31 01:45:54 +02:00
|
|
|
import {
|
|
|
|
Dependencies,
|
|
|
|
TagDependantUIElement,
|
|
|
|
TagDependantUIElementConstructor
|
|
|
|
} from "../../Customizations/UIElementConstructor";
|
|
|
|
import {State} from "../../State";
|
2020-08-30 01:13:18 +02:00
|
|
|
import Translation from "../i18n/Translation";
|
2020-07-14 20:18:44 +02:00
|
|
|
|
|
|
|
export class ImageCarouselConstructor implements TagDependantUIElementConstructor{
|
|
|
|
IsKnown(properties: any): boolean {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
IsQuestioning(properties: any): boolean {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Priority(): number {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-31 01:45:54 +02:00
|
|
|
construct(dependencies: Dependencies): TagDependantUIElement {
|
|
|
|
return new ImageCarousel(dependencies.tags);
|
2020-07-14 20:18:44 +02:00
|
|
|
}
|
2020-07-20 17:30:02 +02:00
|
|
|
|
2020-08-30 01:13:18 +02:00
|
|
|
GetContent(tags: any): Translation {
|
|
|
|
return new Translation({"en":"Images without upload"});
|
2020-08-22 03:15:42 +02:00
|
|
|
}
|
|
|
|
|
2020-07-14 20:18:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export class ImageCarousel extends TagDependantUIElement {
|
2020-06-24 00:35:19 +02:00
|
|
|
|
2020-07-08 13:12:23 +02:00
|
|
|
|
2020-06-24 00:35:19 +02:00
|
|
|
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 _deleteButton: UIElement;
|
2020-07-08 13:12:23 +02:00
|
|
|
private readonly _isDeleted: UIElement;
|
2020-07-13 16:18:04 +02:00
|
|
|
|
2020-07-31 01:45:54 +02:00
|
|
|
constructor(tags: UIEventSource<any>) {
|
2020-06-24 00:35:19 +02:00
|
|
|
super(tags);
|
2020-07-13 16:18:04 +02:00
|
|
|
|
2020-07-07 15:08:52 +02:00
|
|
|
const self = this;
|
2020-07-31 01:45:54 +02:00
|
|
|
this.searcher = new ImageSearcher(tags);
|
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
|
|
|
|
|
|
|
|
2020-07-08 11:23:36 +02:00
|
|
|
const showDeleteButton = this.slideshow._currentSlide.map((i) => {
|
2020-07-31 01:45:54 +02:00
|
|
|
if(!State.state.osmConnection.userDetails.data.loggedIn){
|
2020-07-13 16:18:04 +02:00
|
|
|
return false;
|
|
|
|
}
|
2020-07-08 11:23:36 +02:00
|
|
|
return self.searcher.IsDeletable(self.searcher.data[i]);
|
2020-07-31 01:45:54 +02:00
|
|
|
}, [this.searcher, State.state.osmConnection.userDetails]);
|
2020-07-08 11:23:36 +02:00
|
|
|
this.slideshow._currentSlide.addCallback(() => {
|
|
|
|
showDeleteButton.ping(); // This pings the showDeleteButton, which indicates that it has to hide it's subbuttons
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2020-07-08 13:12:23 +02:00
|
|
|
const deleteCurrent = () => {
|
|
|
|
self.searcher.Delete(self.searcher.data[self.slideshow._currentSlide.data]);
|
|
|
|
}
|
|
|
|
|
2020-07-07 15:08:52 +02:00
|
|
|
|
2020-07-08 11:23:36 +02:00
|
|
|
this._deleteButton = new ConfirmDialog(showDeleteButton,
|
2020-09-03 19:05:18 +02:00
|
|
|
"<img src='./assets/delete.svg' alt='Afbeelding verwijderen' class='delete-image'>",
|
2020-07-08 11:23:36 +02:00
|
|
|
"<span>Afbeelding verwijderen</span>",
|
|
|
|
"<span>Terug</span>",
|
|
|
|
deleteCurrent,
|
2020-07-13 16:18:04 +02:00
|
|
|
() => { },
|
2020-07-08 11:23:36 +02:00
|
|
|
'delete-image-confirm',
|
|
|
|
'delete-image-cancel');
|
2020-07-08 13:12:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
const mapping = this.slideshow._currentSlide.map((i) => {
|
|
|
|
if (this.searcher._deletedImages.data.indexOf(
|
|
|
|
this.searcher.data[i]
|
|
|
|
) >= 0) {
|
|
|
|
return "<div class='image-is-removed'>Deze afbeelding is verwijderd</div>"
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
});
|
|
|
|
this._isDeleted = new VariableUiElement(
|
|
|
|
mapping
|
|
|
|
)
|
|
|
|
|
|
|
|
this.searcher._deletedImages.addCallback(() => {
|
|
|
|
this.slideshow._currentSlide.ping();
|
|
|
|
})
|
|
|
|
|
2020-06-24 00:35:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
InnerRender(): string {
|
2020-07-08 11:23:36 +02:00
|
|
|
return "<span class='image-carousel-container'>" +
|
|
|
|
"<div class='image-delete-container'>" +
|
|
|
|
this._deleteButton.Render() +
|
2020-07-08 13:12:23 +02:00
|
|
|
this._isDeleted.Render() +
|
2020-07-08 11:23:36 +02:00
|
|
|
"</div>" +
|
|
|
|
this.slideshow.Render() +
|
|
|
|
"</span>";
|
2020-07-07 15:08:52 +02:00
|
|
|
}
|
|
|
|
|
2020-07-14 20:18:44 +02:00
|
|
|
IsKnown(): boolean {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
IsQuestioning(): boolean {
|
|
|
|
return false;
|
|
|
|
}
|
2020-07-25 01:07:02 +02:00
|
|
|
|
|
|
|
IsSkipped(): boolean {
|
|
|
|
return false;
|
|
|
|
}
|
2020-07-14 20:18:44 +02:00
|
|
|
|
|
|
|
Priority(): number {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-07 15:08:52 +02:00
|
|
|
InnerUpdate(htmlElement: HTMLElement) {
|
|
|
|
super.InnerUpdate(htmlElement);
|
|
|
|
this._deleteButton.Update();
|
2020-07-08 13:12:23 +02:00
|
|
|
this._isDeleted.Update();
|
2020-06-24 00:35:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Activate() {
|
|
|
|
super.Activate();
|
|
|
|
this.searcher.Activate();
|
2020-09-03 19:05:18 +02:00
|
|
|
return this;
|
2020-06-24 00:35:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|