-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! feat(files): Quota in navigation
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
- Loading branch information
Showing
14 changed files
with
1,869 additions
and
748 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
<template> | ||
<NcAppNavigationItem v-if="storageStats" | ||
:aria-label="t('files', 'Storage informations')" | ||
:class="{ 'app-navigation-entry__settings-quota--not-unlimited': storageStats.quota >= 0}" | ||
:loading="loadingStorageStats" | ||
:name="storageStatsTitle" | ||
:title="storageStatsTooltip" | ||
class="app-navigation-entry__settings-quota" | ||
data-cy-files-navigation-settings-quota | ||
@click="updateStorageStats"> | ||
<ChartPie slot="icon" :size="20" /> | ||
|
||
<!-- Progress bar --> | ||
<NcProgressBar v-if="storageStats.quota >= 0" | ||
slot="extra" | ||
:error="storageStats.relative > 80" | ||
:value="Math.min(storageStats.relative, 100)" /> | ||
</NcAppNavigationItem> | ||
</template> | ||
|
||
<script> | ||
import { formatFileSize } from '@nextcloud/files' | ||
import { generateUrl } from '@nextcloud/router' | ||
import { loadState } from '@nextcloud/initial-state' | ||
import { showError } from '@nextcloud/dialogs' | ||
import { translate } from '@nextcloud/l10n' | ||
import axios from '@nextcloud/axios' | ||
import ChartPie from 'vue-material-design-icons/ChartPie.vue' | ||
import NcAppNavigationItem from '@nextcloud/vue/dist/Components/NcAppNavigationItem.js' | ||
import NcProgressBar from '@nextcloud/vue/dist/Components/NcProgressBar.js' | ||
import logger from '../logger.js' | ||
export default { | ||
name: 'NavigationQuota', | ||
components: { | ||
ChartPie, | ||
NcAppNavigationItem, | ||
NcProgressBar, | ||
}, | ||
data() { | ||
return { | ||
loadingStorageStats: false, | ||
storageStats: loadState('files', 'storageStats', null), | ||
} | ||
}, | ||
computed: { | ||
storageStatsTitle() { | ||
const usedQuotaByte = formatFileSize(this.storageStats?.used) | ||
const quotaByte = formatFileSize(this.storageStats?.quota) | ||
// If no quota set | ||
if (this.storageStats?.quota < 0) { | ||
return this.t('files', '{usedQuotaByte} used', { usedQuotaByte }) | ||
} | ||
return this.t('files', '{used} of {quota} used', { | ||
used: usedQuotaByte, | ||
quota: quotaByte, | ||
}) | ||
}, | ||
storageStatsTooltip() { | ||
if (!this.storageStats.relative) { | ||
return '' | ||
} | ||
return this.t('files', '{relative}% used', this.storageStats) | ||
}, | ||
}, | ||
beforeMount() { | ||
/** | ||
* Update storage stats every minute | ||
* TODO: remove when all views are migrated to Vue | ||
*/ | ||
setTimeout(this.updateStorageStats, 60 * 1000) | ||
}, | ||
methods: { | ||
/** | ||
* Update the storage stats | ||
* | ||
* @param {Event} [event = null] if user interaction | ||
*/ | ||
async updateStorageStats(event = null) { | ||
event?.preventDefault() | ||
event?.stopPropagation() | ||
if (this.loadingStorageStats) { | ||
return | ||
} | ||
this.loadingStorageStats = true | ||
try { | ||
const response = await axios.get(generateUrl('/apps/files/api/v1/stats')) | ||
if (!response?.data?.data) { | ||
throw new Error('Invalid storage stats') | ||
} | ||
this.storageStats = response.data.data | ||
this.$el.querySelector('.app-navigation-entry__title').title = this.storageStatsTooltip | ||
} catch (error) { | ||
logger.error('Could not refresh storage stats', error) | ||
if (event) { | ||
showError(t('files', 'Could not refresh storage stats')) | ||
} | ||
} finally { | ||
this.loadingStorageStats = false | ||
} | ||
}, | ||
t: translate, | ||
}, | ||
} | ||
</script> | ||
<style lang="scss" scoped> | ||
// User storage stats display | ||
.app-navigation-entry__settings-quota { | ||
// Align title with progress and icon | ||
&--not-unlimited::v-deep .app-navigation-entry__title { | ||
margin-top: -4px; | ||
} | ||
progress { | ||
position: absolute; | ||
bottom: 10px; | ||
margin-left: 44px; | ||
width: calc(100% - 44px - 22px); | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.