|
| 1 | +<template> |
| 2 | + <v-container fluid> |
| 3 | + <v-row v-if="error"> |
| 4 | + <v-col cols="12"> |
| 5 | + <v-alert type="error" dense outlined> |
| 6 | + {{ error }} |
| 7 | + </v-alert> |
| 8 | + </v-col> |
| 9 | + </v-row> |
| 10 | + <v-row v-if="loading"> |
| 11 | + <v-col cols="12"> |
| 12 | + <v-progress-linear |
| 13 | + color="primary" |
| 14 | + indeterminate |
| 15 | + height="6" |
| 16 | + rounded |
| 17 | + class="mb-2" |
| 18 | + /> |
| 19 | + </v-col> |
| 20 | + </v-row> |
| 21 | + <v-row v-else> |
| 22 | + <v-col cols="12"> |
| 23 | + <v-card outlined> |
| 24 | + <v-card-title class="py-2 d-flex justify-space-between align-center"> |
| 25 | + <span>{{ path }} {{ totalSize ? ` (${totalSize})` : '' }}</span> |
| 26 | + <v-btn |
| 27 | + icon |
| 28 | + small |
| 29 | + :disabled="!canGoUp" |
| 30 | + @click="goUp" |
| 31 | + > |
| 32 | + <v-icon>mdi-arrow-up</v-icon> |
| 33 | + </v-btn> |
| 34 | + </v-card-title> |
| 35 | + <v-divider /> |
| 36 | + <v-card-text class="pa-0"> |
| 37 | + <v-simple-table dense> |
| 38 | + <thead> |
| 39 | + <tr> |
| 40 | + <th class="text-left"> |
| 41 | + Name |
| 42 | + </th> |
| 43 | + <th class="text-right"> |
| 44 | + Size |
| 45 | + </th> |
| 46 | + <th class="text-center"> |
| 47 | + Type |
| 48 | + </th> |
| 49 | + <th class="text-center"> |
| 50 | + Actions |
| 51 | + </th> |
| 52 | + </tr> |
| 53 | + </thead> |
| 54 | + <tbody> |
| 55 | + <tr v-if="!usage || usage.root.children.length === 0"> |
| 56 | + <td colspan="4" class="text-center grey--text text--darken-1"> |
| 57 | + No entries. |
| 58 | + </td> |
| 59 | + </tr> |
| 60 | + <tr |
| 61 | + v-for="child in sortedChildren" |
| 62 | + :key="child.path" |
| 63 | + :class="{ 'clickable-row': child.is_dir }" |
| 64 | + @click="navigate(child)" |
| 65 | + > |
| 66 | + <td> |
| 67 | + <v-icon left small> |
| 68 | + {{ child.is_dir ? 'mdi-folder' : 'mdi-file' }} |
| 69 | + </v-icon> |
| 70 | + {{ child.name }} |
| 71 | + </td> |
| 72 | + <td class="text-right"> |
| 73 | + {{ prettifySize(child.size_bytes / 1024) }} |
| 74 | + </td> |
| 75 | + <td class="text-center"> |
| 76 | + {{ child.is_dir ? 'Dir' : 'File' }} |
| 77 | + </td> |
| 78 | + <td class="text-center"> |
| 79 | + <v-btn |
| 80 | + icon |
| 81 | + small |
| 82 | + color="red" |
| 83 | + :loading="deleting" |
| 84 | + @click.stop="confirmDelete(child)" |
| 85 | + > |
| 86 | + <v-icon small> |
| 87 | + mdi-delete |
| 88 | + </v-icon> |
| 89 | + </v-btn> |
| 90 | + </td> |
| 91 | + </tr> |
| 92 | + </tbody> |
| 93 | + </v-simple-table> |
| 94 | + </v-card-text> |
| 95 | + </v-card> |
| 96 | + </v-col> |
| 97 | + </v-row> |
| 98 | + </v-container> |
| 99 | +</template> |
| 100 | + |
| 101 | +<script lang="ts"> |
| 102 | +import Vue from 'vue' |
| 103 | +
|
| 104 | +import disk_store from '@/store/disk' |
| 105 | +import { DiskNode } from '@/types/disk' |
| 106 | +import { prettifySize } from '@/utils/helper_functions' |
| 107 | +
|
| 108 | +export default Vue.extend({ |
| 109 | + data() { |
| 110 | + return { |
| 111 | + path: '/', |
| 112 | + depth: 2, |
| 113 | + includeFiles: true, |
| 114 | + minSizeKb: 0, |
| 115 | + } |
| 116 | + }, |
| 117 | + computed: { |
| 118 | + usage() { |
| 119 | + return disk_store.usage |
| 120 | + }, |
| 121 | + loading(): boolean { |
| 122 | + return disk_store.loading |
| 123 | + }, |
| 124 | + deleting(): boolean { |
| 125 | + return disk_store.deleting |
| 126 | + }, |
| 127 | + error(): string | null { |
| 128 | + return disk_store.error |
| 129 | + }, |
| 130 | + sortedChildren(): DiskNode[] { |
| 131 | + if (!this.usage) { |
| 132 | + return [] |
| 133 | + } |
| 134 | + return [...this.usage.root.children].sort((a, b) => b.size_bytes - a.size_bytes) |
| 135 | + }, |
| 136 | + canGoUp(): boolean { |
| 137 | + const currentPath = this.path as string |
| 138 | + return currentPath !== '/' |
| 139 | + }, |
| 140 | + totalSize(): string { |
| 141 | + if (!this.usage?.root?.size_bytes) { |
| 142 | + return '' |
| 143 | + } |
| 144 | + return prettifySize(this.usage.root.size_bytes / 1024) |
| 145 | + }, |
| 146 | + }, |
| 147 | + mounted(): void { |
| 148 | + this.fetchUsage() |
| 149 | + }, |
| 150 | + methods: { |
| 151 | + async fetchUsage(): Promise<void> { |
| 152 | + const currentPath = this.path as string |
| 153 | + const currentDepth = this.depth as number |
| 154 | + const currentIncludeFiles = this.includeFiles as boolean |
| 155 | + const currentMinSizeKb = this.minSizeKb as number |
| 156 | + await disk_store.fetchUsage({ |
| 157 | + path: currentPath || '/', |
| 158 | + depth: Math.max(currentDepth, 0), |
| 159 | + include_files: currentIncludeFiles, |
| 160 | + min_size_bytes: Math.max(0, currentMinSizeKb * 1024), |
| 161 | + }) |
| 162 | + }, |
| 163 | + goUp(): void { |
| 164 | + if (!this.canGoUp) { |
| 165 | + return |
| 166 | + } |
| 167 | + const currentPath = this.path as string |
| 168 | + const trimmed = currentPath.endsWith('/') ? currentPath.slice(0, -1) : currentPath |
| 169 | + const parent = trimmed.substring(0, trimmed.lastIndexOf('/')) || '/' |
| 170 | + this.path = parent |
| 171 | + this.fetchUsage() |
| 172 | + }, |
| 173 | + navigate(node: DiskNode): void { |
| 174 | + if (!node.is_dir) { |
| 175 | + return |
| 176 | + } |
| 177 | + this.path = node.path |
| 178 | + this.fetchUsage() |
| 179 | + }, |
| 180 | + async confirmDelete(node: DiskNode): Promise<void> { |
| 181 | + const confirmed = window.confirm(`Delete ${node.path}? This cannot be undone.`) |
| 182 | + if (!confirmed) { |
| 183 | + return |
| 184 | + } |
| 185 | + await disk_store.deletePath(node.path) |
| 186 | + }, |
| 187 | + prettifySize, |
| 188 | + }, |
| 189 | +}) |
| 190 | +</script> |
| 191 | + |
| 192 | +<style scoped> |
| 193 | +.clickable-row { |
| 194 | + cursor: pointer; |
| 195 | +} |
| 196 | +.clickable-row:hover { |
| 197 | + background-color: rgba(0, 0, 0, 0.05); |
| 198 | +} |
| 199 | +</style> |
0 commit comments