BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
476b28a1
Unverified
Commit
476b28a1
authored
Nov 13, 2017
by
Filipa Lacerda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Formats bytes to human reabale number in registry table
parent
c8d594e0
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
65 additions
and
2 deletions
+65
-2
number_utils.js
app/assets/javascripts/lib/utils/number_utils.js
+28
-0
table_registry.vue
...assets/javascripts/registry/components/table_registry.vue
+6
-1
40092-fix-cluster-size.yml
changelogs/unreleased/40092-fix-cluster-size.yml
+5
-0
number_utility_spec.js
spec/javascripts/lib/utils/number_utility_spec.js
+26
-1
No files found.
app/assets/javascripts/lib/utils/number_utils.js
View file @
476b28a1
...
...
@@ -52,3 +52,31 @@ export function bytesToKiB(number) {
export
function
bytesToMiB
(
number
)
{
return
number
/
(
BYTES_IN_KIB
*
BYTES_IN_KIB
);
}
/**
* Utility function that calculates GiB of the given bytes.
* @param {Number} number
* @returns {Number}
*/
export
function
bytesToGiB
(
number
)
{
return
number
/
(
BYTES_IN_KIB
*
BYTES_IN_KIB
*
BYTES_IN_KIB
);
}
/**
* Port of rails number_to_human_size
* Formats the bytes in number into a more understandable
* representation (e.g., giving it 1500 yields 1.5 KB).
*
* @param {Number} size
* @returns {String}
*/
export
function
numberToHumanSize
(
size
)
{
if
(
size
<
BYTES_IN_KIB
)
{
return
`
${
size
}
bytes`
;
}
else
if
(
size
<
BYTES_IN_KIB
*
BYTES_IN_KIB
)
{
return
`
${
bytesToKiB
(
size
).
toFixed
(
2
)}
KiB`
;
}
else
if
(
size
<
BYTES_IN_KIB
*
BYTES_IN_KIB
*
BYTES_IN_KIB
)
{
return
`
${
bytesToMiB
(
size
).
toFixed
(
2
)}
MiB`
;
}
return
`
${
bytesToGiB
(
size
).
toFixed
(
2
)}
GiB`
;
}
app/assets/javascripts/registry/components/table_registry.vue
View file @
476b28a1
...
...
@@ -8,6 +8,7 @@
import
tooltip
from
'../../vue_shared/directives/tooltip'
;
import
timeagoMixin
from
'../../vue_shared/mixins/timeago'
;
import
{
errorMessages
,
errorMessagesTypes
}
from
'../constants'
;
import
{
numberToHumanSize
}
from
'../../lib/utils/number_utils'
;
export
default
{
props
:
{
...
...
@@ -41,6 +42,10 @@
return
item
.
layers
?
n__
(
'%d layer'
,
'%d layers'
,
item
.
layers
)
:
''
;
},
formatSize
(
size
)
{
return
numberToHumanSize
(
size
);
},
handleDeleteRegistry
(
registry
)
{
this
.
deleteRegistry
(
registry
)
.
then
(()
=>
this
.
fetchList
({
repo
:
this
.
repo
}))
...
...
@@ -97,7 +102,7 @@
</span>
</td>
<td>
{{
item
.
size
}}
{{
formatSize
(
item
.
size
)
}}
<template
v-if=
"item.size && item.layers"
>
·
</
template
>
...
...
changelogs/unreleased/40092-fix-cluster-size.yml
0 → 100644
View file @
476b28a1
---
title
:
Formats bytes to human reabale number in registry table
merge_request
:
author
:
type
:
fixed
spec/javascripts/lib/utils/number_utility_spec.js
View file @
476b28a1
import
{
formatRelevantDigits
,
bytesToKiB
,
bytesToMiB
}
from
'~/lib/utils/number_utils'
;
import
{
formatRelevantDigits
,
bytesToKiB
,
bytesToMiB
,
bytesToGiB
,
numberToHumanSize
}
from
'~/lib/utils/number_utils'
;
describe
(
'Number Utils'
,
()
=>
{
describe
(
'formatRelevantDigits'
,
()
=>
{
...
...
@@ -52,4 +52,29 @@ describe('Number Utils', () => {
expect
(
bytesToMiB
(
1000000
)).
toEqual
(
0.95367431640625
);
});
});
describe
(
'bytesToGiB'
,
()
=>
{
it
(
'calculates GiB for the given bytes'
,
()
=>
{
expect
(
bytesToGiB
(
1073741824
)).
toEqual
(
1
);
expect
(
bytesToGiB
(
10737418240
)).
toEqual
(
10
);
});
});
describe
(
'numberToHumanSize'
,
()
=>
{
it
(
'should return bytes'
,
()
=>
{
expect
(
numberToHumanSize
(
654
)).
toEqual
(
'654 bytes'
);
});
it
(
'should return KiB'
,
()
=>
{
expect
(
numberToHumanSize
(
1079
)).
toEqual
(
'1.05 KiB'
);
});
it
(
'should return MiB'
,
()
=>
{
expect
(
numberToHumanSize
(
10485764
)).
toEqual
(
'10.00 MiB'
);
});
it
(
'should return GiB'
,
()
=>
{
expect
(
numberToHumanSize
(
10737418240
)).
toEqual
(
'10.00 GiB'
);
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment