Skip to content

Commit f1ec968

Browse files
committed
Add beginning of the file manager
1 parent ce77ab2 commit f1ec968

File tree

4 files changed

+147
-6
lines changed

4 files changed

+147
-6
lines changed

resources/assets/scripts/components/server/Server.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@
4141
</div>
4242
</div>
4343
<div class="h-full w-full">
44+
<!--
4445
<div class="mb-6 bg-white border rounded" v-if="$router.currentRoute.name !== 'server'">
4546
<div class="flex">
4647
<progress-bar title="Memory" percent="33" class="flex-1 p-4 pb-6"></progress-bar>
4748
<progress-bar title="CPU" percent="80" class="flex-1 p-4 pb-6"></progress-bar>
4849
<progress-bar title="Disk" percent="97" class="flex-1 p-4 pb-6"></progress-bar>
4950
</div>
5051
</div>
52+
-->
5153
<div class="bg-white p-6 rounded border border-grey-light">
5254
<router-view></router-view>
5355
</div>
Lines changed: 116 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,123 @@
11
<template>
2-
2+
<div>
3+
<div v-if="loading">
4+
<div class="spinner spinner-xl blue"></div>
5+
</div>
6+
<div class="filemanager" v-else>
7+
<div class="header">
8+
<div class="flex-none w-8"></div>
9+
<div class="flex-1">Name</div>
10+
<div class="flex-1 text-right">Size</div>
11+
<div class="flex-1 text-right">Modified</div>
12+
<div class="flex-none w-1/6">Actions</div>
13+
</div>
14+
<div class="row" v-for="folder in folders">
15+
<div class="flex-none icon"><folder-icon/></div>
16+
<div class="flex-1">{{folder.name}}</div>
17+
<div class="flex-1 text-right text-grey-dark"></div>
18+
<div class="flex-1 text-right text-grey-dark">{{formatDate(folder.modified)}}</div>
19+
<div class="flex-none w-1/6"></div>
20+
</div>
21+
<div class="row" v-for="file in files">
22+
<div class="flex-none icon">
23+
<file-text-icon v-if="!file.symlink"/>
24+
<link2-icon v-else/>
25+
</div>
26+
<div class="flex-1">{{file.name}}</div>
27+
<div class="flex-1 text-right text-grey-dark">{{readableSize(file.size)}}</div>
28+
<div class="flex-1 text-right text-grey-dark">{{formatDate(file.modified)}}</div>
29+
<div class="flex-none w-1/6"></div>
30+
</div>
31+
</div>
32+
</div>
333
</template>
434

535
<script>
36+
import filter from 'lodash/filter';
37+
import format from 'date-fns/format';
38+
import { mapState } from 'vuex';
39+
import { FileTextIcon, FolderIcon, Link2Icon } from 'vue-feather-icons';
40+
641
export default {
7-
name: 'file-manager-page'
8-
};
9-
</script>
42+
name: 'file-manager-page',
43+
components: { FileTextIcon, FolderIcon, Link2Icon },
44+
45+
computed: {
46+
...mapState('server', ['server', 'credentials']),
47+
},
48+
49+
data: function () {
50+
return {
51+
directory: '/',
52+
loading: true,
53+
54+
files: [],
55+
folders: [],
56+
};
57+
},
58+
59+
mounted: function () {
60+
this.listDirectory();
61+
},
1062
11-
<style scoped>
63+
methods: {
64+
/**
65+
* List the contents of a directory.
66+
*/
67+
listDirectory: function () {
68+
window.axios.get(`${this.credentials.node}/v1/server/directory/${this.directory}`, {
69+
headers: {
70+
'X-Access-Server': this.server.uuid,
71+
'X-Access-Token': this.credentials.key,
72+
}
73+
})
74+
.then((response) => {
75+
this.files = filter(response.data, function (o) {
76+
return o.file;
77+
});
1278
13-
</style>
79+
this.folders = filter(response.data, function (o) {
80+
return o.directory;
81+
});
82+
})
83+
.catch(console.error)
84+
.finally(() => {
85+
this.loading = false;
86+
});
87+
},
88+
89+
/**
90+
* Return the human readable filesize for a given number of bytes. This
91+
* uses 1024 as the base, so the response is denoted accordingly.
92+
*
93+
* @param {Number} bytes
94+
* @return {String}
95+
*/
96+
readableSize: function (bytes) {
97+
if (Math.abs(bytes) < 1024) {
98+
return `${bytes} Bytes`;
99+
}
100+
101+
let u = -1;
102+
const units = ['KiB', 'MiB', 'GiB', 'TiB'];
103+
104+
do {
105+
bytes /= 1024;
106+
u++;
107+
} while (Math.abs(bytes) >= 1024 && u < units.length - 1);
108+
109+
return `${bytes.toFixed(1)} ${units[u]}`
110+
},
111+
112+
/**
113+
* Format the given date as a human readable string.
114+
*
115+
* @param {String} date
116+
* @return {String}
117+
*/
118+
formatDate: function (date) {
119+
return format(date, 'MMM D, YYYY [at] HH:MM');
120+
},
121+
}
122+
};
123+
</script>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
.filemanager {
2+
& > .header {
3+
@apply .flex .text-sm .pb-4 .font-bold .border-b .border-grey-light .mb-3;
4+
5+
& > div {
6+
@apply .pr-4;
7+
}
8+
}
9+
10+
& > .row {
11+
@apply .flex .text-sm .py-3 .text-sm .rounded .cursor-pointer .border .border-transparent;
12+
13+
& > div {
14+
@apply .pr-4;
15+
}
16+
17+
&:hover {
18+
@apply .bg-grey-lightest .border-blue-light .text-blue-dark;
19+
}
20+
21+
& > .icon {
22+
@apply .w-8 .text-center;
23+
& > svg {
24+
@apply .h-4;
25+
}
26+
}
27+
}
28+
}

resources/assets/styles/main.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
@import "components/navigation.css";
1717
@import "components/notifications.css";
1818
@import "components/spinners.css";
19+
@import "components/filemanager.css";
1920

2021
/**
2122
* Tailwind Utilities

0 commit comments

Comments
 (0)