forked from galaxyproject/galaxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for multiple quota sources
This will hopefully simplify future integration with galaxyproject#10977
- Loading branch information
Showing
6 changed files
with
176 additions
and
37 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
48 changes: 48 additions & 0 deletions
48
client/src/components/User/DiskUsage/Quota/QuotaUsageBar.vue
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,48 @@ | ||
<template> | ||
<div class="quota-usage-bar w-75 mx-auto my-5"> | ||
<h2 v-if="!isDefaultQuota"> | ||
<b>{{ quotaUsage.sourceLabel }}</b> storage source | ||
</h2> | ||
<h3> | ||
<b>{{ quotaUsage.niceTotalDiskUsage }}</b> of {{ quotaUsage.niceQuota }} used | ||
</h3> | ||
<h5 v-if="quotaHasLimit">{{ quotaUsage.quotaPercent }}% of disk quota used</h5> | ||
<b-progress :value="quotaUsage.quotaPercent" :variant="progressVariant" max="100" /> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import _l from "utils/localization"; | ||
import { DEFAULT_QUOTA_SOURCE_LABEL } from "./model/QuotaUsage"; | ||
export default { | ||
props: { | ||
quotaUsage: { | ||
type: Object, | ||
required: true, | ||
}, | ||
}, | ||
computed: { | ||
/** @returns {Boolean} */ | ||
isDefaultQuota() { | ||
return this.quotaUsage.sourceLabel === DEFAULT_QUOTA_SOURCE_LABEL; | ||
}, | ||
/** @returns {Boolean} */ | ||
quotaHasLimit() { | ||
return !this.quotaUsage.isUnlimited; | ||
}, | ||
/** @returns {String} */ | ||
progressVariant() { | ||
const percent = this.quotaUsage.quotaPercent; | ||
if (percent < 50) { | ||
return "success"; | ||
} else if (percent >= 50 && percent < 80) { | ||
return "primary"; | ||
} else if (percent >= 80 && percent < 95) { | ||
return "warning"; | ||
} | ||
return "danger"; | ||
}, | ||
}, | ||
}; | ||
</script> |
24 changes: 24 additions & 0 deletions
24
client/src/components/User/DiskUsage/Quota/QuotaUsageProvider.js
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,24 @@ | ||
import axios from "axios"; | ||
import { SingleQueryProvider } from "components/providers/SingleQueryProvider"; | ||
import { getAppRoot } from "onload/loadConfig"; | ||
import { rethrowSimple } from "utils/simple-error"; | ||
import { QuotaUsage } from "./model"; | ||
|
||
// TODO: replace this with the proper provider and API call after | ||
// https://github.com/galaxyproject/galaxy/pull/10977 is available | ||
|
||
/** | ||
* Fetches the disk usage by the user across all ObjectStores. | ||
* @returns {Array<QuotaUsage>} | ||
*/ | ||
async function fetchQuotaUsage() { | ||
const url = `${getAppRoot()}api/users/current`; | ||
try { | ||
const { data } = await axios.get(url); | ||
return [new QuotaUsage(data)]; | ||
} catch (e) { | ||
rethrowSimple(e); | ||
} | ||
} | ||
|
||
export const QuotaUsageProvider = SingleQueryProvider(fetchQuotaUsage); |
58 changes: 22 additions & 36 deletions
58
client/src/components/User/DiskUsage/Quota/QuotaUsageSummary.vue
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
71 changes: 71 additions & 0 deletions
71
client/src/components/User/DiskUsage/Quota/model/QuotaUsage.js
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,71 @@ | ||
import { bytesToString } from "utils/utils"; | ||
|
||
export const DEFAULT_QUOTA_SOURCE_LABEL = "Default"; | ||
|
||
/** | ||
* Contains information about quota usage for a particular ObjectStore. | ||
*/ | ||
export class QuotaUsage { | ||
constructor(data) { | ||
this.data = data; | ||
} | ||
|
||
/** | ||
* The name of the ObjectStore associated with the quota. | ||
* @returns {String} | ||
*/ | ||
get sourceLabel() { | ||
return this.data.quota_source_label || DEFAULT_QUOTA_SOURCE_LABEL; | ||
} | ||
|
||
/** | ||
* The maximum allowed disk usage in bytes. | ||
* @returns {Number} | ||
*/ | ||
get quotaInBytes() { | ||
return this.data.quota_bytes; | ||
} | ||
|
||
/** | ||
* The total amount of bytes used in this ObjectStore. | ||
* @returns {Number} | ||
*/ | ||
get totalDiskUsageInBytes() { | ||
return this.data.total_disk_usage; | ||
} | ||
|
||
/** | ||
* The percentage of used quota. | ||
* @returns {Number} | ||
*/ | ||
get quotaPercent() { | ||
return this.data.quota_percent; | ||
} | ||
|
||
/** | ||
* The maximum allowed disk usage as human readable size. | ||
* @returns {String} | ||
*/ | ||
get niceQuota() { | ||
if (this.isUnlimited) { | ||
return "unlimited"; | ||
} | ||
return bytesToString(this.quotaInBytes, true); | ||
} | ||
|
||
/** | ||
* The total amount of disk used in this ObjectStore as human readable size. | ||
* @returns {String} | ||
*/ | ||
get niceTotalDiskUsage() { | ||
return bytesToString(this.totalDiskUsageInBytes, true); | ||
} | ||
|
||
/** | ||
* Whether this ObjectStore has unlimited quota | ||
* @returns {Boolean} | ||
*/ | ||
get isUnlimited() { | ||
return !this.quotaInBytes; | ||
} | ||
} |
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 @@ | ||
export { QuotaUsage } from "./QuotaUsage"; |