Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] main from AzuraCast:main #63

Merged
merged 2 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 114 additions & 16 deletions frontend/components/Admin/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,94 @@
</div>
</template>

<script lang="ts">
interface AdminCpuCore {
name: string,
usage: string,
idle: string,
io_wait: string,
steal: string,
}

interface AdminCpuStats {
total: AdminCpuCore,
cores: AdminCpuCore[],
load: number[],
}

interface AdminMemoryStats {
bytes: {
total: string,
free: string,
buffers: string,
cached: string,
sReclaimable: string,
shmem: string,
used: string,
},
readable: {
total: string,
free: string,
buffers: string,
cached: string,
sReclaimable: string,
shmem: string,
used: string,
}
}

interface AdminStorageStats {
bytes: {
total: string,
free: string,
used: string,
},
readable: {
total: string,
free: string,
used: string,
}
}

interface AdminNetworkInterfaceStats {
interface_name: string,
received: {
speed: {
bytes: string,
readable: string,
},
packets: string,
errs: string,
drop: string,
fifo: string,
frame: string,
compressed: string,
multicast: string,
},
transmitted: {
speed: {
bytes: string
readable: string
},
packets: string,
errs: string,
drop: string,
fifo: string,
frame: string,
carrier: string,
compressed: string,
}
}

export interface AdminStats {
cpu: AdminCpuStats,
memory: AdminMemoryStats,
swap: AdminStorageStats,
disk: AdminStorageStats,
network: AdminNetworkInterfaceStats[]
}
</script>

<script setup lang="ts">
import Icon from '~/components/Common/Icon.vue';
import {useAxios} from "~/vendor/axios";
Expand All @@ -110,7 +198,7 @@ const menuItems = useAdminMenu();

const {axiosSilent} = useAxios();

const {state: stats, isLoading} = useAutoRefreshingAsyncState(
const {state: stats, isLoading} = useAutoRefreshingAsyncState<AdminStats>(
() => axiosSilent.get(statsUrl.value).then(r => r.data),
{
cpu: {
Expand All @@ -121,32 +209,42 @@ const {state: stats, isLoading} = useAutoRefreshingAsyncState(
usage: 0
},
cores: [],
load: [
0,
0,
0
]
load: [0, 0, 0]
},
memory: {
bytes: {
total: 0,
used: 0,
cached: 0
total: "0",
used: "0",
cached: "0"
},
readable: {
total: "",
used: "",
cached: ""
}
},
swap: {
bytes: {
total: "0",
free: "0",
used: "0",
},
readable: {
total: '',
used: '',
cached: ''
total: "",
free: "",
used: "",
}
},
disk: {
bytes: {
total: 0,
used: 0
total: "0",
free: "0",
used: "0",
},
readable: {
total: '',
used: ''
total: "",
free: "",
used: "",
}
},
network: []
Expand Down
3 changes: 2 additions & 1 deletion frontend/components/Admin/Index/CpuStatsPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,10 @@ import {ref} from "vue";
import CpuStatsHelpModal from "~/components/Admin/Index/CpuStatsHelpModal.vue";
import {upperFirst} from "lodash";
import {IconInfo} from "~/components/Common/icons.ts";
import {AdminStats} from "~/components/Admin/Index.vue";

const props = defineProps<{
stats: object, // TODO
stats: AdminStats,
}>();

const $cpuStatsHelpModal = ref<InstanceType<typeof CpuStatsHelpModal> | null>(null);
Expand Down
6 changes: 4 additions & 2 deletions frontend/components/Admin/Index/DiskUsagePanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@
</template>

<script setup lang="ts">
import {AdminStats} from "~/components/Admin/Index.vue";

const props = defineProps<{
stats: object, // TODO
}>;
stats: AdminStats,
}>();

const getPercent = (amount, total) => {
return ((amount / total) * 100) + '%';
Expand Down
5 changes: 3 additions & 2 deletions frontend/components/Admin/Index/MemoryStatsPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ import Icon from "~/components/Common/Icon.vue";
import {ref} from "vue";
import MemoryStatsHelpModal from "~/components/Admin/Index/MemoryStatsHelpModal.vue";
import {IconInfo} from "~/components/Common/icons.ts";
import {AdminStats} from "~/components/Admin/Index.vue";

const props = defineProps<{
stats: object, // TODO
}>;
stats: AdminStats,
}>();

const $memoryStatsHelpModal = ref<InstanceType<typeof MemoryStatsHelpModal> | null>(null);
const showMemoryStatsHelpModal = () => {
Expand Down
3 changes: 2 additions & 1 deletion frontend/components/Admin/Index/NetworkStatsPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ import Tab from "~/components/Common/Tab.vue";
import Tabs from "~/components/Common/Tabs.vue";
import {isObject} from "lodash";
import NetworkStatsTable from "~/components/Admin/Index/NetworkStatsTable.vue";
import {AdminStats} from "~/components/Admin/Index.vue";

const props = defineProps<{
stats: object
stats: AdminStats
}>();

const getNetworkInterfaceTableFields = (interfaceData) => Object.keys(interfaceData);
Expand Down
4 changes: 2 additions & 2 deletions frontend/components/Admin/Index/NetworkStatsTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import {get} from "lodash";

const props = defineProps<{
fields: object, // TODO,
data: Array<any>, // TODO
fields: string[],
data: Record<string, any>,
}>();
</script>
2 changes: 1 addition & 1 deletion frontend/components/Admin/Index/ServicesPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const {state: services, isLoading} = useAutoRefreshingAsyncState(

const {notifySuccess} = useNotify();

const doRestart = (serviceUrl) => {
const doRestart = (serviceUrl: string) => {
axios.post(serviceUrl).then((resp) => {
notifySuccess(resp.data.message);
});
Expand Down
1 change: 1 addition & 0 deletions frontend/components/Stations/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export function useStationsMenu(): ReactiveMenu {
// Reuse this variable to avoid multiple calls.
const userCanManageMedia = userAllowedForStation(StationPermission.Media);

// @ts-expect-error This is proper, TS just messes it up
const menu: ReactiveMenu = reactive([
{
key: 'profile',
Expand Down
26 changes: 15 additions & 11 deletions frontend/functions/filterMenu.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
import {cloneDeep, filter, get, map} from "lodash";
import {ComputedRef, Reactive} from "vue";
import {ComputedRef, Reactive, toRaw} from "vue";
import {Icon} from "../components/Common/icons";
import {RouteLocationRaw} from "vue-router";
import {reactiveComputed} from "@vueuse/core";

export type ReactiveMenu = Reactive<Array<MenuCategory>>;
export type ReactiveMenu = Reactive<MenuCategory[]>;

interface RouteBasedUrl {
name: string,
params?: Record<string, any>
}

export interface MenuSubCategory {
key: string,
label: ComputedRef<string>,
url?: RouteLocationRaw | string | null,
icon?: Icon | null,
visible?: boolean | null,
external?: boolean | null,
url?: string | RouteBasedUrl,
icon?: Icon,
visible?: boolean,
external?: boolean,
title?: string,
class?: string,
"class"?: string,
}

export interface MenuCategory extends MenuSubCategory {
items?: MenuSubCategory[] | null
items?: MenuSubCategory[]
}

export default function filterMenu(menuItems: ReactiveMenu): ReactiveMenu {
return reactiveComputed(
() => filter(
map(
cloneDeep(menuItems),
(menuRow: MenuCategory): MenuCategory | null => {
cloneDeep(toRaw(menuItems as unknown as MenuCategory[])),
(menuRow): MenuCategory | null => {
const itemIsVisible: boolean = get(menuRow, 'visible', true);
if (!itemIsVisible) {
return null;
Expand Down
7 changes: 3 additions & 4 deletions frontend/functions/mergeExisting.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import isObject from "./isObject";
import {toRaw} from "vue";
import {cloneDeep} from "lodash";

/*
* A "deep" merge that only merges items from the source into the destination that already exist in the destination.
* Useful for merging in form values with API returns.
*/
export default function mergeExisting<T extends object>(
export default function mergeExisting<T extends Record<any, any>>(
destRaw: T,
sourceRaw: Partial<T>
): T {
const dest = toRaw(destRaw);
const source = toRaw(sourceRaw);

const ret = {};
const ret: T = cloneDeep(dest);
for (const destKey in dest) {
if (destKey in source) {
const destVal = dest[destKey];
Expand All @@ -23,8 +24,6 @@ export default function mergeExisting<T extends object>(
} else {
ret[destKey] = sourceVal;
}
} else {
ret[destKey] = dest[destKey];
}
}

Expand Down
Loading