mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-30 10:36:35 +02:00
Server: Display max size info in dashboard
This commit is contained in:
parent
7447793e77
commit
3d18514c3c
@ -18,3 +18,16 @@ export function getMaxTotalItemSize(user: User): number {
|
||||
const account = accountByType(user.account_type);
|
||||
return user.max_total_item_size !== null ? user.max_total_item_size : account.max_total_item_size;
|
||||
}
|
||||
|
||||
export function totalSizePercent(user: User): number {
|
||||
const maxTotalSize = getMaxTotalItemSize(user);
|
||||
if (!maxTotalSize) return 0;
|
||||
return user.total_item_size / maxTotalSize;
|
||||
}
|
||||
|
||||
export function totalSizeClass(user: User) {
|
||||
const d = totalSizePercent(user);
|
||||
if (d >= 1) return 'is-danger';
|
||||
if (d >= .7) return 'is-warning';
|
||||
return '';
|
||||
}
|
||||
|
@ -5,8 +5,9 @@ import { AppContext } from '../../utils/types';
|
||||
import { contextSessionId } from '../../utils/requestUtils';
|
||||
import { ErrorMethodNotAllowed } from '../../utils/errors';
|
||||
import defaultView from '../../utils/defaultView';
|
||||
import { accountByType, accountTypeToString } from '../../models/UserModel';
|
||||
import { formatMaxItemSize, yesOrNo } from '../../utils/strings';
|
||||
import { accountTypeToString } from '../../models/UserModel';
|
||||
import { formatMaxItemSize, formatMaxTotalSize, formatTotalSize, formatTotalSizePercent, yesOrNo } from '../../utils/strings';
|
||||
import { getCanShareFolder, totalSizeClass } from '../../models/utils/user';
|
||||
|
||||
const router: Router = new Router(RouteType.Web);
|
||||
|
||||
@ -14,24 +15,35 @@ router.get('home', async (_path: SubPath, ctx: AppContext) => {
|
||||
contextSessionId(ctx);
|
||||
|
||||
if (ctx.method === 'GET') {
|
||||
const accountProps = accountByType(ctx.joplin.owner.account_type);
|
||||
const user = ctx.joplin.owner;
|
||||
|
||||
const view = defaultView('home', 'Home');
|
||||
view.content = {
|
||||
userProps: [
|
||||
{
|
||||
label: 'Account Type',
|
||||
value: accountTypeToString(accountProps.account_type),
|
||||
value: accountTypeToString(user.account_type),
|
||||
show: true,
|
||||
},
|
||||
{
|
||||
label: 'Is Admin',
|
||||
value: yesOrNo(ctx.joplin.owner.is_admin),
|
||||
show: !!ctx.joplin.owner.is_admin,
|
||||
value: yesOrNo(user.is_admin),
|
||||
show: !!user.is_admin,
|
||||
},
|
||||
{
|
||||
label: 'Max Item Size',
|
||||
value: formatMaxItemSize(ctx.joplin.owner),
|
||||
value: formatMaxItemSize(user),
|
||||
show: true,
|
||||
},
|
||||
{
|
||||
label: 'Total Size',
|
||||
classes: [totalSizeClass(user)],
|
||||
value: `${formatTotalSize(user)} (${formatTotalSizePercent(user)})`,
|
||||
show: true,
|
||||
},
|
||||
{
|
||||
label: 'Max Total Size',
|
||||
value: formatMaxTotalSize(user),
|
||||
show: true,
|
||||
},
|
||||
{
|
||||
@ -41,7 +53,7 @@ router.get('home', async (_path: SubPath, ctx: AppContext) => {
|
||||
},
|
||||
{
|
||||
label: 'Can Share Notebook',
|
||||
value: yesOrNo(accountProps.can_share_folder),
|
||||
value: yesOrNo(getCanShareFolder(user)),
|
||||
show: true,
|
||||
},
|
||||
],
|
||||
|
@ -12,8 +12,8 @@ import { AclAction } from '../../models/BaseModel';
|
||||
import { NotificationKey } from '../../models/NotificationModel';
|
||||
import { accountTypeOptions, accountTypeToString } from '../../models/UserModel';
|
||||
import uuidgen from '../../utils/uuidgen';
|
||||
import { formatMaxItemSize, formatMaxTotalSize, formatTotalSize, yesOrNo } from '../../utils/strings';
|
||||
import { getCanShareFolder, getMaxTotalItemSize } from '../../models/utils/user';
|
||||
import { formatMaxItemSize, formatMaxTotalSize, formatTotalSize, formatTotalSizePercent, yesOrNo } from '../../utils/strings';
|
||||
import { getCanShareFolder, totalSizeClass } from '../../models/utils/user';
|
||||
import { yesNoDefaultOptions } from '../../utils/views/select';
|
||||
|
||||
interface CheckPasswordInput {
|
||||
@ -84,19 +84,6 @@ function userIsMe(path: SubPath): boolean {
|
||||
|
||||
const router = new Router(RouteType.Web);
|
||||
|
||||
function totalSizePercent(user: User): number {
|
||||
const maxTotalSize = getMaxTotalItemSize(user);
|
||||
if (!maxTotalSize) return 0;
|
||||
return user.total_item_size / maxTotalSize;
|
||||
}
|
||||
|
||||
function totalSizeClass(user: User) {
|
||||
const d = totalSizePercent(user);
|
||||
if (d >= 1) return 'is-danger';
|
||||
if (d >= .7) return 'is-warning';
|
||||
return '';
|
||||
}
|
||||
|
||||
router.get('users', async (_path: SubPath, ctx: AppContext) => {
|
||||
const userModel = ctx.joplin.models.user();
|
||||
await userModel.checkIfAllowed(ctx.joplin.owner, AclAction.List);
|
||||
@ -117,7 +104,7 @@ router.get('users', async (_path: SubPath, ctx: AppContext) => {
|
||||
formattedItemMaxSize: formatMaxItemSize(user),
|
||||
formattedTotalSize: formatTotalSize(user),
|
||||
formattedMaxTotalSize: formatMaxTotalSize(user),
|
||||
formattedTotalSizePercent: `${Math.round(totalSizePercent(user) * 100)}%`,
|
||||
formattedTotalSizePercent: formatTotalSizePercent(user),
|
||||
totalSizeClass: totalSizeClass(user),
|
||||
formattedAccountType: accountTypeToString(user.account_type),
|
||||
formattedCanShareFolder: yesOrNo(getCanShareFolder(user)),
|
||||
|
@ -7,8 +7,6 @@ const logger = Logger.create('cron');
|
||||
export default class CronService extends BaseService {
|
||||
|
||||
public async runInBackground() {
|
||||
await this.models.item().updateTotalSizes();
|
||||
|
||||
cron.schedule('0 */6 * * *', async () => {
|
||||
const startTime = Date.now();
|
||||
logger.info('Deleting expired tokens...');
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { User } from '../db';
|
||||
import { getMaxItemSize, getMaxTotalItemSize } from '../models/utils/user';
|
||||
import { getMaxItemSize, getMaxTotalItemSize, totalSizePercent } from '../models/utils/user';
|
||||
import { formatBytes } from './bytes';
|
||||
|
||||
export function yesOrNo(value: any): string {
|
||||
@ -20,6 +20,10 @@ export function formatMaxTotalSize(user: User): string {
|
||||
return size ? formatBytes(size) : '∞';
|
||||
}
|
||||
|
||||
export function formatTotalSizePercent(user: User): string {
|
||||
return `${Math.round(totalSizePercent(user) * 100)}%`;
|
||||
}
|
||||
|
||||
export function formatTotalSize(user: User): string {
|
||||
return formatBytes(user.total_item_size);
|
||||
}
|
||||
|
@ -6,10 +6,10 @@
|
||||
{{#userProps}}
|
||||
{{#show}}
|
||||
<tr>
|
||||
<td>
|
||||
<td class="{{#classes}}{{.}}{{/classes}}">
|
||||
<strong>{{label}}</strong>
|
||||
</td>
|
||||
<td>
|
||||
<td class="{{#classes}}{{.}}{{/classes}}">
|
||||
{{value}}
|
||||
</td>
|
||||
</tr>
|
||||
|
Loading…
Reference in New Issue
Block a user