2020-04-02 11:35:33 -07:00
|
|
|
define(["events", "globalize", "dom", "date-fns", "dfnshelper", "userSettings", "serverNotifications", "connectionManager", "emby-button", "listViewStyle"], function (events, globalize, dom, datefns, dfnshelper, userSettings, serverNotifications, connectionManager) {
|
2018-10-22 15:05:09 -07:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
function getEntryHtml(entry, apiClient) {
|
|
|
|
var html = "";
|
|
|
|
html += '<div class="listItem listItem-border">';
|
2019-05-22 01:52:48 -07:00
|
|
|
var color = "#00a4dc";
|
2019-10-09 09:19:20 -07:00
|
|
|
var icon = "notifications";
|
|
|
|
|
2019-05-19 06:53:26 -07:00
|
|
|
if ("Error" == entry.Severity || "Fatal" == entry.Severity || "Warn" == entry.Severity) {
|
2019-05-22 01:52:48 -07:00
|
|
|
color = "#cc0000";
|
|
|
|
icon = "notification_important";
|
2019-05-19 06:53:26 -07:00
|
|
|
}
|
2019-10-09 09:19:20 -07:00
|
|
|
|
2018-10-22 15:05:09 -07:00
|
|
|
if (entry.UserId && entry.UserPrimaryImageTag) {
|
2020-04-25 16:37:28 -07:00
|
|
|
html += '<span class="listItemIcon material-icons dvr" style="width:2em!important;height:2em!important;padding:0;color:transparent;background-color:' + color + ";background-image:url('" + apiClient.getUserImageUrl(entry.UserId, {
|
2018-10-22 15:05:09 -07:00
|
|
|
type: "Primary",
|
2019-10-13 12:46:22 -07:00
|
|
|
tag: entry.UserPrimaryImageTag
|
2020-04-25 16:37:28 -07:00
|
|
|
}) + "');background-repeat:no-repeat;background-position:center center;background-size: cover;\"></span>";
|
2019-05-22 01:52:48 -07:00
|
|
|
} else {
|
2020-04-25 16:37:28 -07:00
|
|
|
html += '<span class="listItemIcon material-icons ' + icon + '" style="background-color:' + color + '"></span>';
|
2019-05-22 01:52:48 -07:00
|
|
|
}
|
2019-10-09 09:19:20 -07:00
|
|
|
|
|
|
|
html += '<div class="listItemBody three-line">';
|
|
|
|
html += '<div class="listItemBodyText">';
|
|
|
|
html += entry.Name;
|
|
|
|
html += "</div>";
|
|
|
|
html += '<div class="listItemBodyText secondary">';
|
2020-04-02 11:35:33 -07:00
|
|
|
html += datefns.formatRelative(Date.parse(entry.Date), Date.parse(new Date()), { locale: dfnshelper.getLocale() });
|
2019-10-09 09:19:20 -07:00
|
|
|
html += "</div>";
|
|
|
|
html += '<div class="listItemBodyText secondary listItemBodyText-nowrap">';
|
|
|
|
html += entry.ShortOverview || "";
|
|
|
|
html += "</div>";
|
|
|
|
html += "</div>";
|
|
|
|
|
|
|
|
if (entry.Overview) {
|
2020-04-25 16:37:28 -07:00
|
|
|
html += '<button type="button" is="paper-icon-button-light" class="btnEntryInfo" data-id="' + entry.Id + '" title="' + globalize.translate("Info") + '"><span class="material-icons info"></span></button>';
|
2019-10-09 09:19:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return html += "</div>";
|
2018-10-22 15:05:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function renderList(elem, apiClient, result, startIndex, limit) {
|
2019-10-09 09:19:20 -07:00
|
|
|
elem.innerHTML = result.Items.map(function (i) {
|
|
|
|
return getEntryHtml(i, apiClient);
|
|
|
|
}).join("");
|
2018-10-22 15:05:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function reloadData(instance, elem, apiClient, startIndex, limit) {
|
2019-10-09 09:19:20 -07:00
|
|
|
if (null == startIndex) {
|
|
|
|
startIndex = parseInt(elem.getAttribute("data-activitystartindex") || "0");
|
|
|
|
}
|
|
|
|
|
|
|
|
limit = limit || parseInt(elem.getAttribute("data-activitylimit") || "7");
|
|
|
|
var minDate = new Date();
|
|
|
|
var hasUserId = "false" !== elem.getAttribute("data-useractivity");
|
|
|
|
|
|
|
|
if (hasUserId) {
|
2019-10-15 10:15:58 -07:00
|
|
|
minDate.setTime(minDate.getTime() - 24 * 60 * 60 * 1000); // one day back
|
2019-10-09 09:19:20 -07:00
|
|
|
} else {
|
2019-10-15 10:15:58 -07:00
|
|
|
minDate.setTime(minDate.getTime() - 7 * 24 * 60 * 60 * 1000); // one week back
|
2019-10-09 09:19:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
ApiClient.getJSON(ApiClient.getUrl("System/ActivityLog/Entries", {
|
2018-10-22 15:05:09 -07:00
|
|
|
startIndex: startIndex,
|
|
|
|
limit: limit,
|
|
|
|
minDate: minDate.toISOString(),
|
|
|
|
hasUserId: hasUserId
|
2019-10-09 09:19:20 -07:00
|
|
|
})).then(function (result) {
|
2019-10-15 10:15:58 -07:00
|
|
|
elem.setAttribute("data-activitystartindex", startIndex);
|
|
|
|
elem.setAttribute("data-activitylimit", limit);
|
|
|
|
if (!startIndex) {
|
2018-10-22 15:05:09 -07:00
|
|
|
var activityContainer = dom.parentWithClass(elem, "activityContainer");
|
2019-10-09 09:19:20 -07:00
|
|
|
|
|
|
|
if (activityContainer) {
|
|
|
|
if (result.Items.length) {
|
|
|
|
activityContainer.classList.remove("hide");
|
|
|
|
} else {
|
|
|
|
activityContainer.classList.add("hide");
|
|
|
|
}
|
|
|
|
}
|
2018-10-22 15:05:09 -07:00
|
|
|
}
|
2019-10-09 09:19:20 -07:00
|
|
|
|
|
|
|
instance.items = result.Items;
|
|
|
|
renderList(elem, apiClient, result, startIndex, limit);
|
|
|
|
});
|
2018-10-22 15:05:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function onActivityLogUpdate(e, apiClient, data) {
|
|
|
|
var options = this.options;
|
2019-10-09 09:19:20 -07:00
|
|
|
|
|
|
|
if (options && options.serverId === apiClient.serverId()) {
|
|
|
|
reloadData(this, options.element, apiClient);
|
|
|
|
}
|
2018-10-22 15:05:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function onListClick(e) {
|
|
|
|
var btnEntryInfo = dom.parentWithClass(e.target, "btnEntryInfo");
|
2019-10-09 09:19:20 -07:00
|
|
|
|
2018-10-22 15:05:09 -07:00
|
|
|
if (btnEntryInfo) {
|
2019-10-09 09:19:20 -07:00
|
|
|
var id = btnEntryInfo.getAttribute("data-id");
|
|
|
|
var items = this.items;
|
|
|
|
|
2018-10-22 15:05:09 -07:00
|
|
|
if (items) {
|
2019-10-09 09:19:20 -07:00
|
|
|
var item = items.filter(function (i) {
|
|
|
|
return i.Id.toString() === id;
|
2018-10-22 15:05:09 -07:00
|
|
|
})[0];
|
2019-10-09 09:19:20 -07:00
|
|
|
|
|
|
|
if (item) {
|
|
|
|
showItemOverview(item);
|
|
|
|
}
|
2018-10-22 15:05:09 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function showItemOverview(item) {
|
2019-10-09 09:19:20 -07:00
|
|
|
require(["alert"], function (alert) {
|
2018-10-22 15:05:09 -07:00
|
|
|
alert({
|
|
|
|
text: item.Overview
|
2019-10-09 09:19:20 -07:00
|
|
|
});
|
|
|
|
});
|
2018-10-22 15:05:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function ActivityLog(options) {
|
|
|
|
this.options = options;
|
|
|
|
var element = options.element;
|
2019-10-09 09:19:20 -07:00
|
|
|
element.classList.add("activityLogListWidget");
|
|
|
|
element.addEventListener("click", onListClick.bind(this));
|
2018-10-22 15:05:09 -07:00
|
|
|
var apiClient = connectionManager.getApiClient(options.serverId);
|
|
|
|
reloadData(this, element, apiClient);
|
|
|
|
var onUpdate = onActivityLogUpdate.bind(this);
|
2019-10-09 09:19:20 -07:00
|
|
|
this.updateFn = onUpdate;
|
|
|
|
events.on(serverNotifications, "ActivityLogEntry", onUpdate);
|
|
|
|
apiClient.sendMessage("ActivityLogEntryStart", "0,1500");
|
2018-10-22 15:05:09 -07:00
|
|
|
}
|
2019-10-09 09:19:20 -07:00
|
|
|
|
|
|
|
ActivityLog.prototype.destroy = function () {
|
2018-10-22 15:05:09 -07:00
|
|
|
var options = this.options;
|
2019-10-09 09:19:20 -07:00
|
|
|
|
2018-10-22 15:05:09 -07:00
|
|
|
if (options) {
|
|
|
|
options.element.classList.remove("activityLogListWidget");
|
2019-10-09 09:19:20 -07:00
|
|
|
connectionManager.getApiClient(options.serverId).sendMessage("ActivityLogEntryStop", "0,1500");
|
2018-10-22 15:05:09 -07:00
|
|
|
}
|
2019-10-09 09:19:20 -07:00
|
|
|
|
2018-10-22 15:05:09 -07:00
|
|
|
var onUpdate = this.updateFn;
|
2019-10-09 09:19:20 -07:00
|
|
|
|
|
|
|
if (onUpdate) {
|
|
|
|
events.off(serverNotifications, "ActivityLogEntry", onUpdate);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.items = null;
|
|
|
|
this.options = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
return ActivityLog;
|
2019-05-16 04:42:48 -07:00
|
|
|
});
|