2022-09-16 12:47:59 -04:00
|
|
|
import type { UserDto } from '@jellyfin/sdk/lib/generated-client';
|
2023-03-29 00:38:22 -04:00
|
|
|
import React, { FunctionComponent, useEffect, useState, useRef } from 'react';
|
2022-06-29 23:35:56 +03:00
|
|
|
import Dashboard from '../../utils/dashboard';
|
|
|
|
import globalize from '../../scripts/globalize';
|
|
|
|
import loading from '../../components/loading/loading';
|
|
|
|
import dom from '../../scripts/dom';
|
|
|
|
import confirm from '../../components/confirm/confirm';
|
|
|
|
import UserCardBox from '../../components/dashboard/users/UserCardBox';
|
|
|
|
import SectionTitleContainer from '../../elements/SectionTitleContainer';
|
|
|
|
import '../../elements/emby-button/emby-button';
|
|
|
|
import '../../elements/emby-button/paper-icon-button-light';
|
2022-06-29 23:44:30 +03:00
|
|
|
import '../../components/cardbuilder/card.scss';
|
|
|
|
import '../../components/indicators/indicators.scss';
|
2023-02-26 01:01:31 +02:00
|
|
|
import '../../styles/flexstyles.scss';
|
2022-06-29 23:35:56 +03:00
|
|
|
import Page from '../../components/Page';
|
2021-10-02 16:46:46 +03:00
|
|
|
|
|
|
|
type MenuEntry = {
|
|
|
|
name?: string;
|
|
|
|
id?: string;
|
|
|
|
icon?: string;
|
|
|
|
}
|
|
|
|
|
2022-06-29 23:35:56 +03:00
|
|
|
const UserProfiles: FunctionComponent = () => {
|
2022-02-15 23:49:46 +03:00
|
|
|
const [ users, setUsers ] = useState<UserDto[]>([]);
|
2021-10-02 16:46:46 +03:00
|
|
|
|
2022-02-15 23:47:59 +03:00
|
|
|
const element = useRef<HTMLDivElement>(null);
|
2021-10-02 16:46:46 +03:00
|
|
|
|
|
|
|
const loadData = () => {
|
|
|
|
loading.show();
|
|
|
|
window.ApiClient.getUsers().then(function (result) {
|
|
|
|
setUsers(result);
|
|
|
|
loading.hide();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
useEffect(() => {
|
2022-02-16 00:37:06 +03:00
|
|
|
const page = element.current;
|
|
|
|
|
|
|
|
if (!page) {
|
|
|
|
console.error('Unexpected null reference');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-10-02 16:46:46 +03:00
|
|
|
loadData();
|
|
|
|
|
2022-02-18 14:27:39 +03:00
|
|
|
const showUserMenu = (elem: HTMLElement) => {
|
2021-10-02 16:46:46 +03:00
|
|
|
const card = dom.parentWithClass(elem, 'card');
|
|
|
|
const userId = card.getAttribute('data-userid');
|
|
|
|
|
2022-02-18 13:36:02 +03:00
|
|
|
if (!userId) {
|
|
|
|
console.error('Unexpected null user id');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-10-02 16:46:46 +03:00
|
|
|
const menuItems: MenuEntry[] = [];
|
|
|
|
|
|
|
|
menuItems.push({
|
|
|
|
name: globalize.translate('ButtonOpen'),
|
|
|
|
id: 'open',
|
|
|
|
icon: 'mode_edit'
|
|
|
|
});
|
|
|
|
menuItems.push({
|
|
|
|
name: globalize.translate('ButtonLibraryAccess'),
|
|
|
|
id: 'access',
|
|
|
|
icon: 'lock'
|
|
|
|
});
|
|
|
|
menuItems.push({
|
|
|
|
name: globalize.translate('ButtonParentalControl'),
|
|
|
|
id: 'parentalcontrol',
|
|
|
|
icon: 'person'
|
|
|
|
});
|
|
|
|
menuItems.push({
|
|
|
|
name: globalize.translate('Delete'),
|
|
|
|
id: 'delete',
|
|
|
|
icon: 'delete'
|
|
|
|
});
|
|
|
|
|
2023-03-29 00:38:22 -04:00
|
|
|
import('../../components/actionSheet/actionSheet').then(({ default: actionsheet }) => {
|
2021-10-02 16:46:46 +03:00
|
|
|
actionsheet.show({
|
|
|
|
items: menuItems,
|
|
|
|
positionTo: card,
|
2022-02-18 14:27:39 +03:00
|
|
|
callback: function (id: string) {
|
2021-10-02 16:46:46 +03:00
|
|
|
switch (id) {
|
|
|
|
case 'open':
|
|
|
|
Dashboard.navigate('useredit.html?userId=' + userId);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'access':
|
|
|
|
Dashboard.navigate('userlibraryaccess.html?userId=' + userId);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'parentalcontrol':
|
|
|
|
Dashboard.navigate('userparentalcontrol.html?userId=' + userId);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'delete':
|
|
|
|
deleteUser(userId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-02-18 14:27:39 +03:00
|
|
|
const deleteUser = (id: string) => {
|
2021-10-02 16:46:46 +03:00
|
|
|
const msg = globalize.translate('DeleteUserConfirmation');
|
|
|
|
|
|
|
|
confirm({
|
|
|
|
title: globalize.translate('DeleteUser'),
|
|
|
|
text: msg,
|
|
|
|
confirmText: globalize.translate('Delete'),
|
|
|
|
primary: 'delete'
|
|
|
|
}).then(function () {
|
|
|
|
loading.show();
|
|
|
|
window.ApiClient.deleteUser(id).then(function () {
|
|
|
|
loadData();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-02-16 00:37:06 +03:00
|
|
|
page.addEventListener('click', function (e) {
|
2022-02-16 00:45:59 +03:00
|
|
|
const btnUserMenu = dom.parentWithClass(e.target as HTMLElement, 'btnUserMenu');
|
2021-10-02 16:46:46 +03:00
|
|
|
|
|
|
|
if (btnUserMenu) {
|
|
|
|
showUserMenu(btnUserMenu);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-06-29 02:17:10 +03:00
|
|
|
(page.querySelector('#btnAddUser') as HTMLButtonElement).addEventListener('click', function() {
|
2021-10-02 16:46:46 +03:00
|
|
|
Dashboard.navigate('usernew.html');
|
|
|
|
});
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return (
|
2022-06-29 03:08:53 +03:00
|
|
|
<Page
|
|
|
|
id='userProfilesPage'
|
|
|
|
className='mainAnimatedPage type-interior userProfilesPage fullWidthContent'
|
|
|
|
>
|
|
|
|
<div ref={element} className='content-primary'>
|
2022-06-29 02:17:10 +03:00
|
|
|
<div className='verticalSection'>
|
|
|
|
<SectionTitleContainer
|
|
|
|
title={globalize.translate('HeaderUsers')}
|
|
|
|
isBtnVisible={true}
|
|
|
|
btnId='btnAddUser'
|
|
|
|
btnClassName='fab submit sectionTitleButton'
|
|
|
|
btnTitle='ButtonAddUser'
|
|
|
|
btnIcon='add'
|
2022-10-22 13:23:04 +02:00
|
|
|
url='https://jellyfin.org/docs/general/server/users/adding-managing-users'
|
2022-06-29 02:17:10 +03:00
|
|
|
/>
|
|
|
|
</div>
|
2022-05-07 23:27:33 +03:00
|
|
|
|
|
|
|
<div className='localUsers itemsContainer vertical-wrap'>
|
|
|
|
{users.map(user => {
|
|
|
|
return <UserCardBox key={user.Id} user={user} />;
|
|
|
|
})}
|
2021-10-02 16:46:46 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-06-29 03:08:53 +03:00
|
|
|
</Page>
|
|
|
|
|
2021-10-02 16:46:46 +03:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-06-29 23:35:56 +03:00
|
|
|
export default UserProfiles;
|