-
-
-
+
+
+
{{ $t('informations') }}
+
+ {{ $t('documents') }}
+
+
+
+
diff --git a/client/src/pages/MaterialView/index.js b/client/src/pages/MaterialView/index.js
index 38ed5fe99..007793e8b 100644
--- a/client/src/pages/MaterialView/index.js
+++ b/client/src/pages/MaterialView/index.js
@@ -2,6 +2,7 @@ import { Tabs, Tab } from 'vue-slim-tabs';
import store from '@/store';
import Help from '@/components/Help/Help.vue';
import Infos from './Infos/Infos.vue';
+import Documents from './Documents/Documents.vue';
export default {
name: 'MaterialView',
@@ -10,24 +11,38 @@ export default {
Tab,
Help,
Infos,
+ Documents,
},
data() {
return {
help: '',
error: null,
isLoading: false,
+ tabsIndexes: ['#infos', '#documents'],
+ selectedTabIndex: 0,
material: {
id: this.$route.params.id,
attributes: [],
},
};
},
+ created() {
+ const { hash } = this.$route;
+ if (hash && this.tabsIndexes.includes(hash)) {
+ this.selectedTabIndex = this.tabsIndexes.findIndex((tab) => tab === hash);
+ }
+ },
mounted() {
store.dispatch('categories/fetch');
this.fetchMaterial();
},
methods: {
+ onSelectTab(e, index) {
+ this.selectedTabIndex = index;
+ this.$router.push(this.tabsIndexes[index]);
+ },
+
fetchMaterial() {
const { id } = this.material;
@@ -48,7 +63,6 @@ export default {
},
displayError(error) {
- console.log(error);
this.error = error;
this.isLoading = false;
diff --git a/client/src/utils/formatBytes.js b/client/src/utils/formatBytes.js
new file mode 100644
index 000000000..81609e5f0
--- /dev/null
+++ b/client/src/utils/formatBytes.js
@@ -0,0 +1,15 @@
+const formatBytes = (sizeInBytes) => {
+ if (sizeInBytes === 0) {
+ return '0 Bytes';
+ }
+
+ const kilo = 1024;
+ const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
+
+ const rangeIndex = Math.floor(Math.log(sizeInBytes) / Math.log(kilo));
+ const size = parseFloat((sizeInBytes / (kilo ** rangeIndex)).toFixed(1));
+
+ return `${size} ${sizes[rangeIndex]}`;
+};
+
+export default formatBytes;
diff --git a/client/src/utils/hasIncludes.js b/client/src/utils/hasIncludes.js
new file mode 100644
index 000000000..20919dd82
--- /dev/null
+++ b/client/src/utils/hasIncludes.js
@@ -0,0 +1,5 @@
+const hasIncludes = (needle, searches) => searches.some(
+ (search) => needle.includes(search),
+);
+
+export default hasIncludes;
diff --git a/client/tests/unit/utils/formatBytes.spec.js b/client/tests/unit/utils/formatBytes.spec.js
new file mode 100644
index 000000000..a6d9659f0
--- /dev/null
+++ b/client/tests/unit/utils/formatBytes.spec.js
@@ -0,0 +1,33 @@
+import formatBytes from '@/utils/formatBytes';
+
+describe('formatBytes', () => {
+ it('returns 0 Bytes when 0', () => {
+ expect(formatBytes(0)).toBe('0 Bytes');
+ });
+
+ it('returns the size in bytes', () => {
+ expect(formatBytes(100)).toBe('100 Bytes');
+ expect(formatBytes(1000)).toBe('1000 Bytes');
+ });
+
+ it('returns the size in kilobytes', () => {
+ expect(formatBytes(1024)).toBe('1 KB');
+ expect(formatBytes(1148)).toBe('1.1 KB');
+ expect(formatBytes(1048575)).toBe('1024 KB');
+ });
+
+ it('returns the size in megabytes', () => {
+ expect(formatBytes(1048576)).toBe('1 MB');
+ expect(formatBytes(1500000)).toBe('1.4 MB');
+ expect(formatBytes(1073741823)).toBe('1024 MB');
+ });
+
+ it('returns the size in megabytes', () => {
+ expect(formatBytes(1073741824)).toBe('1 GB');
+ expect(formatBytes(1099511627770)).toBe('1024 GB');
+ });
+
+ it('returns the size in terabytes', () => {
+ expect(formatBytes(1099511627780)).toBe('1 TB');
+ });
+});
diff --git a/client/tests/unit/utils/hasIncludes.spec.js b/client/tests/unit/utils/hasIncludes.spec.js
new file mode 100644
index 000000000..06921246e
--- /dev/null
+++ b/client/tests/unit/utils/hasIncludes.spec.js
@@ -0,0 +1,15 @@
+import hasIncludes from '@/utils/hasIncludes';
+
+describe('hasIncludes', () => {
+ it('returns true when value is present in one of the search strings', () => {
+ const searches = ['test', 'something'];
+ const result = hasIncludes('A string to be tested', searches);
+ expect(result).toBe(true);
+ });
+
+ it('returns false when none of the search strings are found in value', () => {
+ const searches = ['test', 'something'];
+ const result = hasIncludes('A simple string', searches);
+ expect(result).toBe(false);
+ });
+});