2020-06-25 03:39:31 +02:00
|
|
|
/**
|
|
|
|
* Helps in uplaoding, by generating the rigth title, decription and by adding the tag to the changeset
|
|
|
|
*/
|
|
|
|
import {Changes} from "./Changes";
|
2020-07-30 00:59:08 +02:00
|
|
|
import {UIEventSource} from "../../UI/UIEventSource";
|
|
|
|
import {ImageUploadFlow} from "../../UI/ImageUploadFlow";
|
2020-06-25 03:39:31 +02:00
|
|
|
import {UserDetails} from "./OsmConnection";
|
2020-07-30 00:59:08 +02:00
|
|
|
import {SlideShow} from "../../UI/SlideShow";
|
2020-07-31 01:45:54 +02:00
|
|
|
import {State} from "../../State";
|
2020-06-25 03:39:31 +02:00
|
|
|
|
|
|
|
export class OsmImageUploadHandler {
|
|
|
|
private _tags: UIEventSource<any>;
|
2020-06-28 00:06:23 +02:00
|
|
|
private _slideShow: SlideShow;
|
2020-07-01 17:38:48 +02:00
|
|
|
private _preferedLicense: UIEventSource<string>;
|
2020-06-25 03:39:31 +02:00
|
|
|
|
|
|
|
constructor(tags: UIEventSource<any>,
|
2020-07-01 17:38:48 +02:00
|
|
|
preferedLicense: UIEventSource<string>,
|
2020-06-28 00:06:23 +02:00
|
|
|
slideShow : SlideShow
|
2020-06-25 03:39:31 +02:00
|
|
|
) {
|
2020-06-28 00:06:23 +02:00
|
|
|
this._slideShow = slideShow; // To move the slideshow (if any) to the last, just added element
|
2020-06-25 03:39:31 +02:00
|
|
|
this._tags = tags;
|
2020-07-01 17:38:48 +02:00
|
|
|
this._preferedLicense = preferedLicense;
|
2020-06-25 03:39:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private generateOptions(license: string) {
|
|
|
|
const tags = this._tags.data;
|
2020-06-28 00:06:23 +02:00
|
|
|
const self = this;
|
2020-06-25 03:39:31 +02:00
|
|
|
|
|
|
|
const title = tags.name ?? "Unknown area";
|
|
|
|
const description = [
|
2020-07-31 01:45:54 +02:00
|
|
|
"author:" + State.state.osmConnection.userDetails.data.name,
|
2020-06-25 03:39:31 +02:00
|
|
|
"license:" + license,
|
|
|
|
"wikidata:" + tags.wikidata,
|
|
|
|
"osmid:" + tags.id,
|
|
|
|
"name:" + tags.name
|
|
|
|
].join("\n");
|
|
|
|
|
2020-07-31 01:45:54 +02:00
|
|
|
const changes = State.state.changes;
|
2020-06-25 03:39:31 +02:00
|
|
|
return {
|
|
|
|
title: title,
|
|
|
|
description: description,
|
|
|
|
handleURL: function (url) {
|
2020-07-21 22:40:46 +02:00
|
|
|
|
|
|
|
let key = "image";
|
|
|
|
if (tags["image"] !== undefined) {
|
|
|
|
|
|
|
|
let freeIndex = 0;
|
|
|
|
while (tags["image:" + freeIndex] !== undefined) {
|
|
|
|
freeIndex++;
|
|
|
|
}
|
|
|
|
key = "image:" + freeIndex;
|
2020-06-25 03:39:31 +02:00
|
|
|
}
|
2020-07-21 22:40:46 +02:00
|
|
|
console.log("Adding image:" + key, url);
|
|
|
|
changes.addChange(tags.id, key, url);
|
2020-06-28 00:06:23 +02:00
|
|
|
self._slideShow.MoveTo(-1); // set the last (thus newly added) image) to view
|
2020-06-25 03:39:31 +02:00
|
|
|
},
|
|
|
|
allDone: function () {
|
|
|
|
changes.uploadAll(function () {
|
|
|
|
console.log("Writing changes...")
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getUI(): ImageUploadFlow {
|
|
|
|
const self = this;
|
2020-06-27 03:06:51 +02:00
|
|
|
return new ImageUploadFlow(
|
2020-07-01 17:38:48 +02:00
|
|
|
this._preferedLicense,
|
2020-06-27 03:06:51 +02:00
|
|
|
function (license) {
|
2020-06-25 03:39:31 +02:00
|
|
|
return self.generateOptions(license)
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|