1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

activitylog

This commit is contained in:
grafixeyehero 2019-10-09 19:19:20 +03:00
parent f86d2d47ac
commit cae2898da2

View file

@ -1,96 +1,156 @@
define(["events", "globalize", "dom", "datetime", "userSettings", "serverNotifications", "connectionManager", "emby-button", "listViewStyle"], function(events, globalize, dom, datetime, userSettings, serverNotifications, connectionManager) { define(["events", "globalize", "dom", "datetime", "userSettings", "serverNotifications", "connectionManager", "emby-button", "listViewStyle"], function (events, globalize, dom, datetime, userSettings, serverNotifications, connectionManager) {
"use strict"; "use strict";
function getEntryHtml(entry, apiClient) { function getEntryHtml(entry, apiClient) {
var html = ""; var html = "";
html += '<div class="listItem listItem-border">'; html += '<div class="listItem listItem-border">';
var color = "#00a4dc"; var color = "#00a4dc";
var icon = "notifications"; var icon = "notifications";
if ("Error" == entry.Severity || "Fatal" == entry.Severity || "Warn" == entry.Severity) { if ("Error" == entry.Severity || "Fatal" == entry.Severity || "Warn" == entry.Severity) {
color = "#cc0000"; color = "#cc0000";
icon = "notification_important"; icon = "notification_important";
} }
if (entry.UserId && entry.UserPrimaryImageTag) { if (entry.UserId && entry.UserPrimaryImageTag) {
html += '<i class="listItemIcon md-icon" style="width:2em!important;height:2em!important;padding:0;color:transparent;background-color:' + color + ";background-image:url('" + apiClient.getUserImageUrl(entry.UserId, { html += '<i class="listItemIcon md-icon" style="width:2em!important;height:2em!important;padding:0;color:transparent;background-color:' + color + ";background-image:url('" + apiClient.getUserImageUrl(entry.UserId, {
type: "Primary", type: "Primary",
tag: entry.UserPrimaryImageTag, tag: entry.UserPrimaryImageTag,
height: 40 height: 40
}) + "');background-repeat:no-repeat;background-position:center center;background-size: cover;\">dvr</i>" }) + "');background-repeat:no-repeat;background-position:center center;background-size: cover;\">dvr</i>";
} else { } else {
html += '<i class="listItemIcon md-icon" style="background-color:' + color + '">' + icon + '</i>'; html += '<i class="listItemIcon md-icon" style="background-color:' + color + '">' + icon + '</i>';
} }
html += '<div class="listItemBody three-line">', html += '<div class="listItemBodyText">', html += entry.Name, html += "</div>", html += '<div class="listItemBodyText secondary">';
var date = datetime.parseISO8601Date(entry.Date, !0); html += '<div class="listItemBody three-line">';
return html += datetime.toLocaleString(date).toLowerCase(), html += "</div>", html += '<div class="listItemBodyText secondary listItemBodyText-nowrap">', html += entry.ShortOverview || "", html += "</div>", html += "</div>", entry.Overview && (html += '<button type="button" is="paper-icon-button-light" class="btnEntryInfo" data-id="' + entry.Id + '" title="' + globalize.translate("Info") + '"><i class="md-icon">info</i></button>'), html += "</div>" html += '<div class="listItemBodyText">';
html += entry.Name;
html += "</div>";
html += '<div class="listItemBodyText secondary">';
var date = datetime.parseISO8601Date(entry.Date, true);
html += datetime.toLocaleString(date).toLowerCase();
html += "</div>";
html += '<div class="listItemBodyText secondary listItemBodyText-nowrap">';
html += entry.ShortOverview || "";
html += "</div>";
html += "</div>";
if (entry.Overview) {
html += '<button type="button" is="paper-icon-button-light" class="btnEntryInfo" data-id="' + entry.Id + '" title="' + globalize.translate("Info") + '"><i class="md-icon">info</i></button>';
}
return html += "</div>";
} }
function renderList(elem, apiClient, result, startIndex, limit) { function renderList(elem, apiClient, result, startIndex, limit) {
elem.innerHTML = result.Items.map(function(i) { elem.innerHTML = result.Items.map(function (i) {
return getEntryHtml(i, apiClient) return getEntryHtml(i, apiClient);
}).join("") }).join("");
} }
function reloadData(instance, elem, apiClient, startIndex, limit) { function reloadData(instance, elem, apiClient, startIndex, limit) {
null == startIndex && (startIndex = parseInt(elem.getAttribute("data-activitystartindex") || "0")), limit = limit || parseInt(elem.getAttribute("data-activitylimit") || "7"); if (null == startIndex) {
var minDate = new Date, startIndex = parseInt(elem.getAttribute("data-activitystartindex") || "0");
hasUserId = "false" !== elem.getAttribute("data-useractivity"); }
hasUserId ? minDate.setTime(minDate.getTime() - 864e5) : minDate.setTime(minDate.getTime() - 6048e5), ApiClient.getJSON(ApiClient.getUrl("System/ActivityLog/Entries", {
limit = limit || parseInt(elem.getAttribute("data-activitylimit") || "7");
var minDate = new Date();
var hasUserId = "false" !== elem.getAttribute("data-useractivity");
if (hasUserId) {
minDate.setTime(minDate.getTime() - 864e5);
} else {
minDate.setTime(minDate.getTime() - 6048e5);
}
ApiClient.getJSON(ApiClient.getUrl("System/ActivityLog/Entries", {
startIndex: startIndex, startIndex: startIndex,
limit: limit, limit: limit,
minDate: minDate.toISOString(), minDate: minDate.toISOString(),
hasUserId: hasUserId hasUserId: hasUserId
})).then(function(result) { })).then(function (result) {
if (elem.setAttribute("data-activitystartindex", startIndex), elem.setAttribute("data-activitylimit", limit), !startIndex) { if (elem.setAttribute("data-activitystartindex", startIndex), elem.setAttribute("data-activitylimit", limit), !startIndex) {
var activityContainer = dom.parentWithClass(elem, "activityContainer"); var activityContainer = dom.parentWithClass(elem, "activityContainer");
activityContainer && (result.Items.length ? activityContainer.classList.remove("hide") : activityContainer.classList.add("hide"))
if (activityContainer) {
if (result.Items.length) {
activityContainer.classList.remove("hide");
} else {
activityContainer.classList.add("hide");
}
}
} }
instance.items = result.Items, renderList(elem, apiClient, result, startIndex, limit)
}) instance.items = result.Items;
renderList(elem, apiClient, result, startIndex, limit);
});
} }
function onActivityLogUpdate(e, apiClient, data) { function onActivityLogUpdate(e, apiClient, data) {
var options = this.options; var options = this.options;
options && options.serverId === apiClient.serverId() && reloadData(this, options.element, apiClient)
if (options && options.serverId === apiClient.serverId()) {
reloadData(this, options.element, apiClient);
}
} }
function onListClick(e) { function onListClick(e) {
var btnEntryInfo = dom.parentWithClass(e.target, "btnEntryInfo"); var btnEntryInfo = dom.parentWithClass(e.target, "btnEntryInfo");
if (btnEntryInfo) { if (btnEntryInfo) {
var id = btnEntryInfo.getAttribute("data-id"), var id = btnEntryInfo.getAttribute("data-id");
items = this.items; var items = this.items;
if (items) { if (items) {
var item = items.filter(function(i) { var item = items.filter(function (i) {
return i.Id.toString() === id return i.Id.toString() === id;
})[0]; })[0];
item && showItemOverview(item)
if (item) {
showItemOverview(item);
}
} }
} }
} }
function showItemOverview(item) { function showItemOverview(item) {
require(["alert"], function(alert) { require(["alert"], function (alert) {
alert({ alert({
text: item.Overview text: item.Overview
}) });
}) });
} }
function ActivityLog(options) { function ActivityLog(options) {
this.options = options; this.options = options;
var element = options.element; var element = options.element;
element.classList.add("activityLogListWidget"), element.addEventListener("click", onListClick.bind(this)); element.classList.add("activityLogListWidget");
element.addEventListener("click", onListClick.bind(this));
var apiClient = connectionManager.getApiClient(options.serverId); var apiClient = connectionManager.getApiClient(options.serverId);
reloadData(this, element, apiClient); reloadData(this, element, apiClient);
var onUpdate = onActivityLogUpdate.bind(this); var onUpdate = onActivityLogUpdate.bind(this);
this.updateFn = onUpdate, events.on(serverNotifications, "ActivityLogEntry", onUpdate), apiClient.sendMessage("ActivityLogEntryStart", "0,1500") this.updateFn = onUpdate;
events.on(serverNotifications, "ActivityLogEntry", onUpdate);
apiClient.sendMessage("ActivityLogEntryStart", "0,1500");
} }
return ActivityLog.prototype.destroy = function() {
ActivityLog.prototype.destroy = function () {
var options = this.options; var options = this.options;
if (options) { if (options) {
options.element.classList.remove("activityLogListWidget"); options.element.classList.remove("activityLogListWidget");
connectionManager.getApiClient(options.serverId).sendMessage("ActivityLogEntryStop", "0,1500") connectionManager.getApiClient(options.serverId).sendMessage("ActivityLogEntryStop", "0,1500");
} }
var onUpdate = this.updateFn; var onUpdate = this.updateFn;
onUpdate && events.off(serverNotifications, "ActivityLogEntry", onUpdate), this.items = null, this.options = null
}, ActivityLog if (onUpdate) {
events.off(serverNotifications, "ActivityLogEntry", onUpdate);
}
this.items = null;
this.options = null;
};
return ActivityLog;
}); });