1
0
mirror of https://github.com/hrfee/jfa-go.git synced 2024-12-22 17:10:10 +00:00

switch accounts tab to unix times

should now respect the client's locale.
This commit is contained in:
Harvey Tindall 2021-04-06 20:53:30 +01:00
parent 7dcc9b20a1
commit 6ec2186bdf
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2
4 changed files with 34 additions and 12 deletions

5
api.go
View File

@ -1041,16 +1041,15 @@ func (app *appContext) GetUsers(gc *gin.Context) {
Admin: jfUser.Policy.IsAdministrator, Admin: jfUser.Policy.IsAdministrator,
Disabled: jfUser.Policy.IsDisabled, Disabled: jfUser.Policy.IsDisabled,
} }
user.LastActive = "n/a"
if !jfUser.LastActivityDate.IsZero() { if !jfUser.LastActivityDate.IsZero() {
user.LastActive = app.formatDatetime(jfUser.LastActivityDate.Time) user.LastActive = jfUser.LastActivityDate.Unix()
} }
if email, ok := app.storage.emails[jfUser.ID]; ok { if email, ok := app.storage.emails[jfUser.ID]; ok {
user.Email = email.(string) user.Email = email.(string)
} }
expiry, ok := app.storage.users[jfUser.ID] expiry, ok := app.storage.users[jfUser.ID]
if ok { if ok {
user.Expiry = app.formatDatetime(expiry) user.Expiry = expiry.Unix()
} }
resp.UserList[i] = user resp.UserList[i] = user

View File

@ -112,9 +112,9 @@ type respUser struct {
ID string `json:"id" example:"fdgsdfg45534fa"` // userID of user ID string `json:"id" example:"fdgsdfg45534fa"` // userID of user
Name string `json:"name" example:"jeff"` // Username of user Name string `json:"name" example:"jeff"` // Username of user
Email string `json:"email,omitempty" example:"jeff@jellyf.in"` // Email address of user (if available) Email string `json:"email,omitempty" example:"jeff@jellyf.in"` // Email address of user (if available)
LastActive string `json:"last_active"` // Time of last activity on Jellyfin LastActive int64 `json:"last_active" example:"1617737207510"` // Time of last activity on Jellyfin
Admin bool `json:"admin" example:"false"` // Whether or not the user is Administrator Admin bool `json:"admin" example:"false"` // Whether or not the user is Administrator
Expiry string `json:"expiry" example:"01/02/21 12:00"` // Expiry time of user, if applicable. Expiry int64 `json:"expiry" example:"1617737207510"` // Expiry time of user as Epoch/Unix time.
Disabled bool `json:"disabled"` // Whether or not the user is disabled. Disabled bool `json:"disabled"` // Whether or not the user is disabled.
} }

View File

@ -1,13 +1,13 @@
import { _get, _post, _delete, toggleLoader } from "../modules/common.js"; import { _get, _post, _delete, toggleLoader, toDateString } from "../modules/common.js";
interface User { interface User {
id: string; id: string;
name: string; name: string;
email: string | undefined; email: string | undefined;
last_active: string; last_active: number;
admin: boolean; admin: boolean;
disabled: boolean; disabled: boolean;
expiry: string; expiry: number;
} }
class user implements User { class user implements User {
@ -20,7 +20,9 @@ class user implements User {
private _emailAddress: string; private _emailAddress: string;
private _emailEditButton: HTMLElement; private _emailEditButton: HTMLElement;
private _expiry: HTMLTableDataCellElement; private _expiry: HTMLTableDataCellElement;
private _expiryUnix: number;
private _lastActive: HTMLTableDataCellElement; private _lastActive: HTMLTableDataCellElement;
private _lastActiveUnix: number;
id: string; id: string;
private _selected: boolean; private _selected: boolean;
@ -67,11 +69,25 @@ class user implements User {
} }
} }
get expiry(): string { return this._expiry.textContent; } get expiry(): number { return this._expiryUnix; }
set expiry(value: string) { this._expiry.textContent = value; } set expiry(unix: number) {
this._expiryUnix = unix;
if (unix == 0) {
this._expiry.textContent = "";
} else {
this._expiry.textContent = toDateString(new Date(unix*1000));
}
}
get last_active(): string { return this._lastActive.textContent; } get last_active(): number { return this._lastActiveUnix; }
set last_active(value: string) { this._lastActive.textContent = value; } set last_active(unix: number) {
this._lastActiveUnix = unix;
if (unix == 0) {
this._lastActive.textContent == "";
} else {
this._lastActive.textContent = toDateString(new Date(unix*1000));
}
}
private _checkEvent = new CustomEvent("accountCheckEvent"); private _checkEvent = new CustomEvent("accountCheckEvent");
private _uncheckEvent = new CustomEvent("accountUncheckEvent"); private _uncheckEvent = new CustomEvent("accountUncheckEvent");

View File

@ -6,6 +6,13 @@ export function createEl(html: string): HTMLElement {
return div.firstElementChild as HTMLElement; return div.firstElementChild as HTMLElement;
} }
export function toDateString(date: Date): string {
return date.toLocaleDateString() + " " + date.toLocaleString([], {
hour: "2-digit",
minute: "2-digit"
})
}
export function serializeForm(id: string): Object { export function serializeForm(id: string): Object {
const form = document.getElementById(id) as HTMLFormElement; const form = document.getElementById(id) as HTMLFormElement;
let formData = {}; let formData = {};