2020-06-24 00:35:19 +02:00
|
|
|
import {UIElement} from "./UIElement";
|
|
|
|
import {UserDetails} from "../Logic/OsmConnection";
|
|
|
|
import {UIEventSource} from "./UIEventSource";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles and updates the user badge
|
|
|
|
*/
|
|
|
|
export class UserBadge extends UIElement {
|
|
|
|
private _userDetails: UIEventSource<UserDetails>;
|
2020-06-27 03:06:51 +02:00
|
|
|
private _pendingChanges: UIElement;
|
2020-06-24 00:35:19 +02:00
|
|
|
|
|
|
|
|
2020-06-27 03:06:51 +02:00
|
|
|
constructor(userDetails: UIEventSource<UserDetails>,
|
|
|
|
pendingChanges : UIElement) {
|
2020-06-24 00:35:19 +02:00
|
|
|
super(userDetails);
|
|
|
|
this._userDetails = userDetails;
|
2020-06-27 03:06:51 +02:00
|
|
|
this._pendingChanges = pendingChanges;
|
2020-06-24 00:35:19 +02:00
|
|
|
|
|
|
|
userDetails.addCallback(function () {
|
|
|
|
const profilePic = document.getElementById("profile-pic");
|
|
|
|
profilePic.onload = function () {
|
|
|
|
profilePic.style.opacity = "1"
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected InnerRender(): string {
|
|
|
|
const user = this._userDetails.data;
|
|
|
|
if (!user.loggedIn) {
|
|
|
|
return "<div class='activate-osm-authentication'>Klik hier om aan te melden bij OSM</div>";
|
|
|
|
}
|
2020-06-27 03:06:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
let messageSpan = "<span id='messages'>" +
|
|
|
|
" <a href='https://www.openstreetmap.org/messages/inbox' target='_blank'><img class='envelope' src='./assets/envelope.svg'/>" +
|
|
|
|
user.totalMessages +
|
|
|
|
"</a></span>";
|
|
|
|
|
|
|
|
if (user.unreadMessages > 0) {
|
|
|
|
messageSpan = "<span id='messages' class='alert'>" +
|
|
|
|
" <a href='https://www.openstreetmap.org/messages/inbox' target='_blank'><img class='envelope' src='./assets/envelope.svg'/>" +
|
|
|
|
" " +
|
|
|
|
"" +
|
|
|
|
user.unreadMessages.toString() +
|
|
|
|
"</a></span>";
|
|
|
|
}
|
|
|
|
|
|
|
|
let dryrun = "";
|
|
|
|
if (user.dryRun) {
|
|
|
|
dryrun = " <span class='alert'>TESTING</span>";
|
|
|
|
}
|
2020-06-24 00:35:19 +02:00
|
|
|
|
|
|
|
return "<img id='profile-pic' src='" + user.img + "'/> " +
|
2020-06-27 03:06:51 +02:00
|
|
|
"<div id='usertext'>" +
|
|
|
|
"<p id='username'>" +
|
|
|
|
"<a href='https://www.openstreetmap.org/user/" + user.name + "' target='_blank'>" + user.name + "</a>" +
|
|
|
|
dryrun +
|
|
|
|
"</p> " +
|
|
|
|
"<p id='userstats'>" +
|
|
|
|
messageSpan +
|
|
|
|
"<span id='csCount'> " +
|
|
|
|
" <a href='https://www.openstreetmap.org/user/" + user.name + "/history' target='_blank'><img class='star' src='./assets/star.svg'/> " + user.csCount +
|
|
|
|
"</a></span> " +
|
|
|
|
this._pendingChanges.Render() +
|
|
|
|
"</p>" +
|
|
|
|
|
2020-06-24 00:35:19 +02:00
|
|
|
"</div>";
|
|
|
|
}
|
|
|
|
|
|
|
|
InnerUpdate(htmlElement: HTMLElement) {
|
2020-06-27 03:06:51 +02:00
|
|
|
this._pendingChanges.Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
Activate() {
|
|
|
|
this._pendingChanges.Activate();
|
2020-06-24 00:35:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|