chore: add prettier frontent linter

This commit is contained in:
Oleg Lobanov
2021-03-21 12:51:58 +01:00
parent a721dc1f31
commit c44b37c50c
73 changed files with 18898 additions and 4499 deletions

View File

@@ -1,16 +1,16 @@
const getters = {
isLogged: state => state.user !== null,
isFiles: state => !state.loading && state.route.name === 'Files',
isLogged: (state) => state.user !== null,
isFiles: (state) => !state.loading && state.route.name === "Files",
isListing: (state, getters) => getters.isFiles && state.req.isDir,
selectedCount: state => state.selected.length,
progress : state => {
selectedCount: (state) => state.selected.length,
progress: (state) => {
if (state.upload.progress.length == 0) {
return 0;
}
let sum = state.upload.progress.reduce((acc, val) => acc + val)
return Math.ceil(sum / state.upload.size * 100);
}
}
let sum = state.upload.progress.reduce((acc, val) => acc + val);
return Math.ceil((sum / state.upload.size) * 100);
},
};
export default getters
export default getters;

View File

@@ -1,20 +1,20 @@
import Vue from 'vue'
import Vuex from 'vuex'
import mutations from './mutations'
import getters from './getters'
import upload from './modules/upload'
import Vue from "vue";
import Vuex from "vuex";
import mutations from "./mutations";
import getters from "./getters";
import upload from "./modules/upload";
Vue.use(Vuex)
Vue.use(Vuex);
const state = {
user: null,
req: {},
oldReq: {},
clipboard: {
key: '',
items: []
key: "",
items: [],
},
jwt: '',
jwt: "",
progress: 0,
loading: false,
reload: false,
@@ -22,13 +22,13 @@ const state = {
multiple: false,
show: null,
showShell: false,
showConfirm: null
}
showConfirm: null,
};
export default new Vuex.Store({
strict: true,
state,
getters,
mutations,
modules: { upload }
})
modules: { upload },
});

View File

@@ -1,7 +1,7 @@
import Vue from 'vue'
import { files as api } from '@/api'
import throttle from 'lodash.throttle'
import buttons from '@/utils/buttons'
import Vue from "vue";
import { files as api } from "@/api";
import throttle from "lodash.throttle";
import buttons from "@/utils/buttons";
const UPLOADS_LIMIT = 5;
@@ -10,93 +10,100 @@ const state = {
size: 0,
progress: [],
queue: [],
uploads: {}
}
uploads: {},
};
const mutations = {
setProgress(state, { id, loaded }) {
Vue.set(state.progress, id, loaded)
Vue.set(state.progress, id, loaded);
},
reset: (state) => {
state.id = 0
state.size = 0
state.progress = []
state.id = 0;
state.size = 0;
state.progress = [];
},
addJob: (state, item) => {
state.queue.push(item)
state.size += item.file.size
state.id++
state.queue.push(item);
state.size += item.file.size;
state.id++;
},
moveJob(state) {
const item = state.queue[0]
state.queue.shift()
Vue.set(state.uploads, item.id, item)
const item = state.queue[0];
state.queue.shift();
Vue.set(state.uploads, item.id, item);
},
removeJob(state, id) {
delete state.uploads[id]
}
}
delete state.uploads[id];
},
};
const beforeUnload = (event) => {
event.preventDefault()
event.returnValue = ''
}
event.preventDefault();
event.returnValue = "";
};
const actions = {
upload: (context, item) => {
let uploadsCount = Object.keys(context.state.uploads).length;
let isQueueEmpty = context.state.queue.length == 0
let isUploadsEmpty = uploadsCount == 0
let isQueueEmpty = context.state.queue.length == 0;
let isUploadsEmpty = uploadsCount == 0;
if (isQueueEmpty && isUploadsEmpty) {
window.addEventListener('beforeunload', beforeUnload)
buttons.loading('upload')
window.addEventListener("beforeunload", beforeUnload);
buttons.loading("upload");
}
context.commit('addJob', item)
context.dispatch('processUploads')
context.commit("addJob", item);
context.dispatch("processUploads");
},
finishUpload: (context, item) => {
context.commit('setProgress', { id: item.id, loaded: item.file.size })
context.commit('removeJob', item.id)
context.dispatch('processUploads')
context.commit("setProgress", { id: item.id, loaded: item.file.size });
context.commit("removeJob", item.id);
context.dispatch("processUploads");
},
processUploads: async (context) => {
let uploadsCount = Object.keys(context.state.uploads).length;
let isBellowLimit = uploadsCount < UPLOADS_LIMIT
let isQueueEmpty = context.state.queue.length == 0
let isUploadsEmpty = uploadsCount == 0
let isBellowLimit = uploadsCount < UPLOADS_LIMIT;
let isQueueEmpty = context.state.queue.length == 0;
let isUploadsEmpty = uploadsCount == 0;
let isFinished = isQueueEmpty && isUploadsEmpty
let canProcess = isBellowLimit && !isQueueEmpty
let isFinished = isQueueEmpty && isUploadsEmpty;
let canProcess = isBellowLimit && !isQueueEmpty;
if (isFinished) {
window.removeEventListener('beforeunload', beforeUnload)
buttons.success('upload')
context.commit('reset')
context.commit('setReload', true, { root: true })
window.removeEventListener("beforeunload", beforeUnload);
buttons.success("upload");
context.commit("reset");
context.commit("setReload", true, { root: true });
}
if (canProcess) {
const item = context.state.queue[0];
context.commit('moveJob')
context.commit("moveJob");
if (item.file.isDir) {
await api.post(item.path).catch(Vue.prototype.$showError)
await api.post(item.path).catch(Vue.prototype.$showError);
} else {
let onUpload = throttle(
(event) => context.commit('setProgress', { id: item.id, loaded: event.loaded }),
100, { leading: true, trailing: false }
)
(event) =>
context.commit("setProgress", {
id: item.id,
loaded: event.loaded,
}),
100,
{ leading: true, trailing: false }
);
await api.post(item.path, item.file, item.overwrite, onUpload).catch(Vue.prototype.$showError)
await api
.post(item.path, item.file, item.overwrite, onUpload)
.catch(Vue.prototype.$showError);
}
context.dispatch('finishUpload', item)
context.dispatch("finishUpload", item);
}
}
}
},
};
export default { state, mutations, actions, namespaced: true }
export default { state, mutations, actions, namespaced: true };

View File

@@ -1,83 +1,87 @@
import * as i18n from '@/i18n'
import moment from 'moment'
import * as i18n from "@/i18n";
import moment from "moment";
const mutations = {
closeHovers: state => {
state.show = null
state.showConfirm = null
closeHovers: (state) => {
state.show = null;
state.showConfirm = null;
},
toggleShell: (state) => {
state.showShell = !state.showShell
state.showShell = !state.showShell;
},
showHover: (state, value) => {
if (typeof value !== 'object') {
state.show = value
return
if (typeof value !== "object") {
state.show = value;
return;
}
state.show = value.prompt
state.showConfirm = value.confirm
state.show = value.prompt;
state.showConfirm = value.confirm;
},
showError: (state) => {
state.show = 'error'
state.show = "error";
},
showSuccess: (state) => {
state.show = 'success'
state.show = "success";
},
setLoading: (state, value) => {
state.loading = value;
},
setReload: (state, value) => {
state.reload = value;
},
setLoading: (state, value) => { state.loading = value },
setReload: (state, value) => { state.reload = value },
setUser: (state, value) => {
if (value === null) {
state.user = null
return
state.user = null;
return;
}
let locale = value.locale
let locale = value.locale;
if (locale === '') {
locale = i18n.detectLocale()
if (locale === "") {
locale = i18n.detectLocale();
}
moment.locale(locale)
i18n.default.locale = locale
state.user = value
moment.locale(locale);
i18n.default.locale = locale;
state.user = value;
},
setJWT: (state, value) => (state.jwt = value),
multiple: (state, value) => (state.multiple = value),
addSelected: (state, value) => (state.selected.push(value)),
addSelected: (state, value) => state.selected.push(value),
removeSelected: (state, value) => {
let i = state.selected.indexOf(value)
if (i === -1) return
state.selected.splice(i, 1)
let i = state.selected.indexOf(value);
if (i === -1) return;
state.selected.splice(i, 1);
},
resetSelected: (state) => {
state.selected = []
state.selected = [];
},
updateUser: (state, value) => {
if (typeof value !== 'object') return
if (typeof value !== "object") return;
for (let field in value) {
if (field === 'locale') {
moment.locale(value[field])
i18n.default.locale = value[field]
if (field === "locale") {
moment.locale(value[field]);
i18n.default.locale = value[field];
}
state.user[field] = value[field]
state.user[field] = value[field];
}
},
updateRequest: (state, value) => {
state.oldReq = state.req
state.req = value
state.oldReq = state.req;
state.req = value;
},
updateClipboard: (state, value) => {
state.clipboard.key = value.key
state.clipboard.items = value.items
state.clipboard.path = value.path
state.clipboard.key = value.key;
state.clipboard.items = value.items;
state.clipboard.path = value.path;
},
resetClipboard: (state) => {
state.clipboard.key = ''
state.clipboard.items = []
}
}
state.clipboard.key = "";
state.clipboard.items = [];
},
};
export default mutations
export default mutations;