displaying storage used by accounts

This commit is contained in:
Roland Osborne 2023-07-10 22:15:02 -07:00
parent a9b1876ee6
commit ead73db759
7 changed files with 27 additions and 2 deletions

View File

@ -3975,6 +3975,9 @@ components:
type: boolean
seal:
type: string
storageUsed:
type: integer
format: int64
Profile:
type: object

View File

@ -14,13 +14,18 @@ func GetNodeAccounts(w http.ResponseWriter, r *http.Request) {
}
var accounts []store.Account
if err := store.DB.Preload("AccountDetail").Find(&accounts).Error; err != nil {
if err := store.DB.Preload("Assets").Preload("AccountDetail").Find(&accounts).Error; err != nil {
ErrResponse(w, http.StatusInternalServerError, err)
return
}
profiles := []AccountProfile{}
for _, account := range accounts {
var size int64
for _, asset := range account.Assets {
size += asset.Size
}
profiles = append(profiles, AccountProfile{
AccountID: uint32(account.ID),
GUID: account.GUID,
@ -30,6 +35,7 @@ func GetNodeAccounts(w http.ResponseWriter, r *http.Request) {
Location: account.AccountDetail.Location,
ImageSet: account.AccountDetail.Image != "",
Disabled: account.Disabled,
StorageUsed: size,
})
}

View File

@ -19,6 +19,8 @@ type AccountProfile struct {
Seal string `json:"seal,emitempty"`
Disabled bool `json:"disabled"`
StorageUsed int64 `json:"storageUsed"`
}
//AccountStatus server settings for account

View File

@ -84,6 +84,7 @@ type Account struct {
Forward string
AccountDetail AccountDetail
Apps []App
Assets []Asset
}
type AccountDetail struct {

View File

@ -75,7 +75,12 @@ export function AccountItem({ item, remove }) {
<Logo url={state.imageUrl} width={32} height={32} radius={4} />
</div>
<div className={state.activeClass}>
<div className="handle">{ state.handle }</div>
<div className="handle">
<span>{ state.handle }</span>
{ state?.storage > 0 && (
<span className="storage">{ state.storage } { state.storageUnit }</span>
)}
</div>
<div className="guid">{ state.guid }</div>
</div>
<div className="control">

View File

@ -51,6 +51,11 @@ export const AccountItemWrapper = styled.div`
overflow: hidden;
}
.storage {
color: #555555;
padding-left: 8px;
}
.guid {
font-size: 0.8em;
font-weight: bold;

View File

@ -22,6 +22,7 @@ export function useAccountItem(item, remove) {
}
useEffect(() => {
updateState({
disabled: item?.disabled,
activeClass: item?.disabled ? 'inactive' : 'active',
@ -29,6 +30,8 @@ export function useAccountItem(item, remove) {
name: item?.name,
guid: item?.guid,
handle: item?.handle,
storage: Math.floor(item?.storageUsed > 1073741824 ? item?.storageUsed / 1073741824 : item?.storageUsed / 1048576),
storageUnit: item?.storageUsed > 1073741824 ? "GB" : "MB",
imageUrl: item?.imageSet ? getAccountImageUrl(app.state.adminToken, item?.accountId) : null,
});
}, [app.state.adminToken, item]);