Skip to content

Commit 16c4455

Browse files
committed
Modify upload function to accept only yml files on folder upload. Adding breadcrumbs, adding feature to create folder
1 parent fe71536 commit 16c4455

4 files changed

Lines changed: 135 additions & 115 deletions

File tree

frontend/src/components/Sidebar.vue

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,34 @@
22
<nav :class="{ active }">
33
<template v-if="isLogged">
44
<router-link
5-
class="action"
6-
to="/files/"
7-
:aria-label="$t('sidebar.myFiles')"
8-
:title="$t('sidebar.myFiles')"
5+
class="action"
6+
to="/files/"
7+
:aria-label="$t('sidebar.myFiles')"
8+
:title="$t('sidebar.myFiles')"
99
>
1010
<i class="material-icons">folder</i>
1111
<span>{{ $t("sidebar.myFiles") }}</span>
1212
</router-link>
1313

14-
<div v-if="user.perm.create">
14+
<div v-if="user.perm.create">
1515
<button
16-
@click="$store.commit('showHover', 'newFile')"
17-
class="action"
18-
:aria-label="$t('sidebar.newFile')"
19-
:title="$t('sidebar.newFile')"
16+
@click="$store.commit('showHover', 'newDir')"
17+
class="action"
18+
:aria-label="$t('sidebar.newFolder')"
19+
:title="$t('sidebar.newFolder')"
20+
>
21+
<i class="material-icons">create_new_folder</i>
22+
<span>{{ $t("sidebar.newFolder") }}</span>
23+
</button>
24+
</div>
25+
26+
27+
<div v-if="user.perm.create">
28+
<button
29+
@click="$store.commit('showHover', 'newFile')"
30+
class="action"
31+
:aria-label="$t('sidebar.newFile')"
32+
:title="$t('sidebar.newFile')"
2033
>
2134
<i class="material-icons">note_add</i>
2235
<span>{{ $t("sidebar.newFile") }}</span>
@@ -28,9 +41,9 @@
2841
</template>
2942

3043
<script>
31-
import { mapGetters, mapState } from "vuex";
44+
import {mapGetters, mapState} from "vuex";
3245
import * as auth from "@/utils/auth";
33-
import { authMethod, disableExternal, noAuth, signup, version } from "@/utils/constants";
46+
import {authMethod, disableExternal, noAuth, signup, version} from "@/utils/constants";
3447
3548
export default {
3649
name: "sidebar",

frontend/src/css/listing.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
width: 100%;
113113
max-width: 100%;
114114
margin: 0;
115-
margin-top: 64px;
115+
margin-top: 0;
116116
}
117117

118118
#listing.list .item {

frontend/src/utils/upload.js

Lines changed: 109 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -2,126 +2,132 @@ import store from "@/store";
22
import url from "@/utils/url";
33

44
export function checkConflict(files, items) {
5-
if (typeof items === "undefined" || items === null) {
6-
items = [];
7-
}
8-
9-
let folder_upload = files[0].fullPath !== undefined;
10-
11-
let conflict = false;
12-
for (let i = 0; i < files.length; i++) {
13-
let file = files[i];
14-
let name = file.name;
15-
16-
if (folder_upload) {
17-
let dirs = file.fullPath.split("/");
18-
if (dirs.length > 1) {
19-
name = dirs[0];
20-
}
5+
if (typeof items === "undefined" || items === null) {
6+
items = [];
217
}
228

23-
let res = items.findIndex(function hasConflict(element) {
24-
return element.name === this;
25-
}, name);
9+
let folder_upload = files[0].fullPath !== undefined;
2610

27-
if (res >= 0) {
28-
conflict = true;
29-
break;
11+
let conflict = false;
12+
for (let i = 0; i < files.length; i++) {
13+
let file = files[i];
14+
let name = file.name;
15+
16+
if (folder_upload) {
17+
let dirs = file.fullPath.split("/");
18+
if (dirs.length > 1) {
19+
name = dirs[0];
20+
}
21+
}
22+
23+
let res = items.findIndex(function hasConflict(element) {
24+
return element.name === this;
25+
}, name);
26+
27+
if (res >= 0) {
28+
conflict = true;
29+
break;
30+
}
3031
}
31-
}
3232

33-
return conflict;
33+
return conflict;
3434
}
3535

3636
export function scanFiles(dt) {
37-
return new Promise((resolve) => {
38-
let reading = 0;
39-
const contents = [];
40-
41-
if (dt.items !== undefined) {
42-
for (let item of dt.items) {
43-
if (
44-
item.kind === "file" &&
45-
typeof item.webkitGetAsEntry === "function"
46-
) {
47-
const entry = item.webkitGetAsEntry();
48-
readEntry(entry);
37+
return new Promise((resolve) => {
38+
let reading = 0;
39+
const contents = [];
40+
41+
if (dt.items !== undefined) {
42+
for (let item of dt.items) {
43+
if (
44+
item.kind === "file" &&
45+
typeof item.webkitGetAsEntry === "function"
46+
) {
47+
const entry = item.webkitGetAsEntry();
48+
readEntry(entry);
49+
}
50+
}
51+
} else {
52+
resolve(dt.files);
4953
}
50-
}
51-
} else {
52-
resolve(dt.files);
53-
}
5454

55-
function readEntry(entry, directory = "") {
56-
if (entry.isFile) {
57-
reading++;
58-
entry.file((file) => {
59-
reading--;
60-
61-
file.fullPath = `${directory}${file.name}`;
62-
contents.push(file);
63-
64-
if (reading === 0) {
65-
resolve(contents);
66-
}
67-
});
68-
} else if (entry.isDirectory) {
69-
const dir = {
70-
isDir: true,
71-
size: 0,
72-
fullPath: `${directory}${entry.name}`,
73-
};
74-
75-
contents.push(dir);
76-
77-
readReaderContent(entry.createReader(), `${directory}${entry.name}`);
78-
}
79-
}
55+
function readEntry(entry, directory = "") {
56+
if (entry.isFile) {
57+
reading++;
58+
entry.file((file) => {
59+
reading--;
60+
61+
file.fullPath = `${directory}${file.name}`;
62+
contents.push(file);
63+
64+
if (reading === 0) {
65+
resolve(contents);
66+
}
67+
});
68+
} else if (entry.isDirectory) {
69+
const dir = {
70+
isDir: true,
71+
size: 0,
72+
fullPath: `${directory}${entry.name}`,
73+
};
74+
75+
contents.push(dir);
76+
77+
readReaderContent(entry.createReader(), `${directory}${entry.name}`);
78+
}
79+
}
8080

81-
function readReaderContent(reader, directory) {
82-
reading++;
81+
function readReaderContent(reader, directory) {
82+
reading++;
8383

84-
reader.readEntries(function (entries) {
85-
reading--;
86-
if (entries.length > 0) {
87-
for (const entry of entries) {
88-
readEntry(entry, `${directory}/`);
89-
}
84+
reader.readEntries(function (entries) {
85+
reading--;
86+
if (entries.length > 0) {
87+
for (const entry of entries) {
88+
readEntry(entry, `${directory}/`);
89+
}
9090

91-
readReaderContent(reader, `${directory}/`);
92-
}
91+
readReaderContent(reader, `${directory}/`);
92+
}
9393

94-
if (reading === 0) {
95-
resolve(contents);
94+
if (reading === 0) {
95+
resolve(contents);
96+
}
97+
});
9698
}
97-
});
98-
}
99-
});
99+
});
100100
}
101101

102102
export function handleFiles(files, base, overwrite = false) {
103-
for (let i = 0; i < files.length; i++) {
104-
let id = store.state.upload.id;
105-
let path = base;
106-
let file = files[i];
107-
108-
if (file.fullPath !== undefined) {
109-
path += url.encodePath(file.fullPath);
110-
} else {
111-
path += url.encodeRFC5987ValueChars(file.name);
112-
}
113-
114-
if (file.isDir) {
115-
path += "/";
103+
for (let i = 0; i < files.length; i++) {
104+
105+
let id = store.state.upload.id;
106+
let path = base;
107+
let file = files[i];
108+
console.log(file);
109+
var re = /(?:\.([^.]+))?$/;
110+
console.log(re.exec(file.name)[1]);
111+
if (re.exec(file.name)[1] === 'yml') {
112+
console.log('Is yml file')
113+
if (file.fullPath !== undefined) {
114+
path += url.encodePath(file.fullPath);
115+
} else {
116+
path += url.encodeRFC5987ValueChars(file.name);
117+
}
118+
119+
if (file.isDir) {
120+
path += "/";
121+
}
122+
123+
const item = {
124+
id,
125+
path,
126+
file,
127+
overwrite,
128+
};
129+
130+
store.dispatch("upload/upload", item);
131+
}
116132
}
117-
118-
const item = {
119-
id,
120-
path,
121-
file,
122-
overwrite,
123-
};
124-
125-
store.dispatch("upload/upload", item);
126-
}
127133
}

frontend/src/views/Files.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<template>
22
<div>
33
<header-bar v-if="error || req.type == null" showMenu showLogo />
4+
<breadcrumbs base="/files" />
45
<errors v-if="error" :errorCode="error.message" />
56
<component v-else-if="currentView" :is="currentView"></component>
67
<div v-else>

0 commit comments

Comments
 (0)