Move everything back to vue SFCs

This commit is contained in:
Dane Everitt 2019-02-09 21:14:58 -08:00
parent 761704408e
commit 5bff8d99cc
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
58 changed files with 2558 additions and 2518 deletions

View file

@ -1,48 +0,0 @@
import Vue from 'vue';
import {mapState} from 'vuex';
import Status from '../../../helpers/statuses';
import {Socketio} from "@/mixins/socketio";
export default Vue.component('power-buttons', {
computed: {
...mapState('socket', ['connected', 'status']),
},
mixins: [Socketio],
data: function () {
return {
statuses: Status,
};
},
methods: {
sendPowerAction: function (action: string) {
this.$socket().instance().emit('set status', action)
},
},
template: `
<div>
<div v-if="connected">
<transition name="slide-fade" mode="out-in">
<button class="btn btn-green uppercase text-xs px-4 py-2"
v-if="status === statuses.STATUS_OFF"
v-on:click.prevent="sendPowerAction('start')"
>Start</button>
<div v-else>
<button class="btn btn-red uppercase text-xs px-4 py-2" v-on:click.prevent="sendPowerAction('stop')">Stop</button>
<button class="btn btn-secondary uppercase text-xs px-4 py-2" v-on:click.prevent="sendPowerAction('restart')">Restart</button>
<button class="btn btn-secondary btn-red uppercase text-xs px-4 py-2" v-on:click.prevent="sendPowerAction('kill')">Kill</button>
</div>
</transition>
</div>
<div v-else>
<div class="text-center">
<div class="spinner"></div>
<div class="pt-2 text-xs text-neutral-400">Connecting to node</div>
</div>
</div>
</div>
`
});

View file

@ -0,0 +1,51 @@
<template>
<div>
<div v-if="connected">
<transition name="slide-fade" mode="out-in">
<button class="btn btn-green uppercase text-xs px-4 py-2"
v-if="status === statuses.STATUS_OFF"
v-on:click.prevent="sendPowerAction('start')"
>Start</button>
<div v-else>
<button class="btn btn-red uppercase text-xs px-4 py-2" v-on:click.prevent="sendPowerAction('stop')">Stop</button>
<button class="btn btn-secondary uppercase text-xs px-4 py-2" v-on:click.prevent="sendPowerAction('restart')">Restart</button>
<button class="btn btn-secondary btn-red uppercase text-xs px-4 py-2" v-on:click.prevent="sendPowerAction('kill')">Kill</button>
</div>
</transition>
</div>
<div v-else>
<div class="text-center">
<div class="spinner"></div>
<div class="pt-2 text-xs text-neutral-400">Connecting to node</div>
</div>
</div>
</div>
</template>
<script lang="ts">
import Vue from 'vue';
import {mapState} from 'vuex';
import Status from '../../../helpers/statuses';
import {Socketio} from "@/mixins/socketio";
export default Vue.extend({
name: 'PowerButtons',
computed: {
...mapState('socket', ['connected', 'status']),
},
mixins: [Socketio],
data: function () {
return {
statuses: Status,
};
},
methods: {
sendPowerAction: function (action: string) {
this.$socket().instance().emit('set status', action)
},
},
});
</script>

View file

@ -1,42 +0,0 @@
import Vue from 'vue';
export default Vue.component('progress-bar', {
props: {
percent: {type: Number, default: 0},
title: {type: String}
},
computed: {
backgroundColor: function () {
if (this.percent < 70) {
return "bg-green-600";
} else if (this.percent >= 70 && this.percent < 90) {
return "bg-yellow-dark";
} else {
return "bg-red-600";
}
},
borderColor: function () {
if (this.percent < 70) {
return "border-green-600";
} else if (this.percent >= 70 && this.percent < 90) {
return "border-yellow-dark";
} else {
return "border-red-600";
}
}
},
template: `
<div>
<div class="text-right mb-1" v-if="title.length > 0">
<span class="text-neutral-600 text-xs uppercase">{{ title }}</span>
</div>
<div class="w-full border rounded h-4" :class="borderColor">
<div class="h-full w-1/3 text-center" :style="{ width: percent + '%' }" :class="backgroundColor">
<span class="mt-1 text-xs text-white leading-none">{{ percent }} %</span>
</div>
</div>
</div>
`,
});

View file

@ -1,86 +0,0 @@
import Vue from 'vue';
import MessageBox from "@/components/MessageBox";
import {createDatabase} from "@/api/server/createDatabase";
export default Vue.component('CreateDatabaseModal', {
components: {MessageBox},
data: function () {
return {
loading: false,
showSpinner: false,
database: '',
remote: '%',
errorMessage: '',
};
},
computed: {
canSubmit: function () {
return this.database.length && this.remote.length;
},
},
methods: {
submit: function () {
this.showSpinner = true;
this.errorMessage = '';
this.loading = true;
createDatabase(this.$route.params.id, this.database, this.remote)
.then((response) => {
this.$emit('database', response);
this.$emit('close');
})
.catch((err: Error | string): void => {
if (typeof err === 'string') {
this.errorMessage = err;
return;
}
console.error('A network error was encountered while processing this request.', { err });
})
.then(() => {
this.loading = false;
this.showSpinner = false;
});
}
},
template: `
<div>
<message-box class="alert error mb-6" :message="errorMessage" v-show="errorMessage.length"/>
<h2 class="font-medium text-neutral-900 mb-6">Create a new database</h2>
<div class="mb-6">
<label class="input-label" for="grid-database-name">Database name</label>
<input id="grid-database-name" type="text" class="input" name="database_name" required
v-model="database"
v-validate="{ alpha_dash: true, max: 100 }"
:class="{ error: errors.has('database_name') }"
>
<p class="input-help error" v-show="errors.has('database_name')">{{ errors.first('database_name') }}</p>
</div>
<div class="mb-6">
<label class="input-label" for="grid-database-remote">Allow connections from</label>
<input id="grid-database-remote" type="text" class="input" name="remote" required
v-model="remote"
v-validate="{ regex: /^[0-9%.]{1,15}$/ }"
:class="{ error: errors.has('remote') }"
>
<p class="input-help error" v-show="errors.has('remote')">{{ errors.first('remote') }}</p>
</div>
<div class="text-right">
<button class="btn btn-secondary btn-sm mr-2" v-on:click.once="$emit('close')">Cancel</button>
<button class="btn btn-primary btn-sm"
:disabled="errors.any() || !canSubmit || showSpinner"
v-on:click="submit"
>
<span class="spinner white" v-bind:class="{ hidden: !showSpinner }">&nbsp;</span>
<span :class="{ hidden: showSpinner }">
Create
</span>
</button>
</div>
</div>
`
});

View file

@ -0,0 +1,89 @@
<template>
<div>
<MessageBox class="alert error mb-6" :message="errorMessage" v-show="errorMessage.length"/>
<h2 class="font-medium text-neutral-900 mb-6">Create a new database</h2>
<div class="mb-6">
<label class="input-label" for="grid-database-name">Database name</label>
<input id="grid-database-name" type="text" class="input" name="database_name" required
v-model="database"
v-validate="{ alpha_dash: true, max: 100 }"
:class="{ error: errors.has('database_name') }"
>
<p class="input-help error" v-show="errors.has('database_name')">{{ errors.first('database_name') }}</p>
</div>
<div class="mb-6">
<label class="input-label" for="grid-database-remote">Allow connections from</label>
<input id="grid-database-remote" type="text" class="input" name="remote" required
v-model="remote"
v-validate="{ regex: /^[0-9%.]{1,15}$/ }"
:class="{ error: errors.has('remote') }"
>
<p class="input-help error" v-show="errors.has('remote')">{{ errors.first('remote') }}</p>
</div>
<div class="text-right">
<button class="btn btn-secondary btn-sm mr-2" v-on:click.once="$emit('close')">Cancel</button>
<button class="btn btn-primary btn-sm"
:disabled="errors.any() || !canSubmit || showSpinner"
v-on:click="submit"
>
<span class="spinner white" v-bind:class="{ hidden: !showSpinner }">&nbsp;</span>
<span :class="{ hidden: showSpinner }">
Create
</span>
</button>
</div>
</div>
</template>
<script lang="ts">
import Vue from 'vue';
import MessageBox from "@/components/MessageBox.vue";
import {createDatabase} from "@/api/server/createDatabase";
export default Vue.extend({
name: 'CreateDatabaseModal',
components: {MessageBox},
data: function () {
return {
loading: false,
showSpinner: false,
database: '',
remote: '%',
errorMessage: '',
};
},
computed: {
canSubmit: function () {
return this.database.length && this.remote.length;
},
},
methods: {
submit: function () {
this.showSpinner = true;
this.errorMessage = '';
this.loading = true;
createDatabase(this.$route.params.id, this.database, this.remote)
.then((response) => {
this.$emit('database', response);
this.$emit('close');
})
.catch((err: Error | string): void => {
if (typeof err === 'string') {
this.errorMessage = err;
return;
}
console.error('A network error was encountered while processing this request.', {err});
})
.then(() => {
this.loading = false;
this.showSpinner = false;
});
}
},
});
</script>

View file

@ -1,70 +0,0 @@
import Vue from 'vue';
import Icon from "@/components/core/Icon";
import Modal from "@/components/core/Modal";
import {ServerDatabase} from "@/api/server/types";
import DeleteDatabaseModal from "@/components/server/components/database/DeleteDatabaseModal";
export default Vue.component('DatabaseRow', {
components: {DeleteDatabaseModal, Modal, Icon},
props: {
database: {
type: Object as () => ServerDatabase,
required: true,
}
},
data: function () {
return {
showDeleteModal: false,
};
},
methods: {
revealPassword: function () {
this.database.showPassword = !this.database.showPassword;
},
},
template: `
<div class="content-box mb-6 hover:border-neutral-200">
<div class="flex items-center text-neutral-800">
<icon name="database" class="flex-none text-green-500"></icon>
<div class="flex-1 px-4">
<p class="uppercase text-xs text-neutral-500 pb-1 select-none">Database Name</p>
<p>{{database.name}}</p>
</div>
<div class="flex-1 px-4">
<p class="uppercase text-xs text-neutral-500 pb-1 select-none">Username</p>
<p>{{database.username}}</p>
</div>
<div class="flex-1 px-4">
<p class="uppercase text-xs text-neutral-500 pb-1 select-none">Password</p>
<p>
<code class="text-sm cursor-pointer" v-on:click="revealPassword">
<span class="select-none" v-if="!database.showPassword">
<icon name="lock" class="h-3"/> &bull;&bull;&bull;&bull;&bull;&bull;
</span>
<span v-else>{{database.password}}</span>
</code>
</p>
</div>
<div class="flex-1 px-4">
<p class="uppercase text-xs text-neutral-500 pb-1 select-none">Server</p>
<p><code class="text-sm">{{database.host.address}}:{{database.host.port}}</code></p>
</div>
<div class="flex-none px-4">
<button class="btn btn-xs btn-secondary btn-red" v-on:click="showDeleteModal = true">
<icon name="trash-2" class="w-3 h-3 mx-1"/>
</button>
</div>
</div>
<modal :show="showDeleteModal" v-on:close="showDeleteModal = false">
<DeleteDatabaseModal
:database="database"
v-on:close="showDeleteModal = false"
v-if="showDeleteModal"
/>
</modal>
</div>
`,
})

View file

@ -0,0 +1,73 @@
<template>
<div class="content-box mb-6 hover:border-neutral-200">
<div class="flex items-center text-neutral-800">
<Icon name="database" class="flex-none text-green-500"></icon>
<div class="flex-1 px-4">
<p class="uppercase text-xs text-neutral-500 pb-1 select-none">Database Name</p>
<p>{{database.name}}</p>
</div>
<div class="flex-1 px-4">
<p class="uppercase text-xs text-neutral-500 pb-1 select-none">Username</p>
<p>{{database.username}}</p>
</div>
<div class="flex-1 px-4">
<p class="uppercase text-xs text-neutral-500 pb-1 select-none">Password</p>
<p>
<code class="text-sm cursor-pointer" v-on:click="revealPassword">
<span class="select-none" v-if="!database.showPassword">
<Icon name="lock" class="h-3"/> &bull;&bull;&bull;&bull;&bull;&bull;
</span>
<span v-else>{{database.password}}</span>
</code>
</p>
</div>
<div class="flex-1 px-4">
<p class="uppercase text-xs text-neutral-500 pb-1 select-none">Server</p>
<p><code class="text-sm">{{database.host.address}}:{{database.host.port}}</code></p>
</div>
<div class="flex-none px-4">
<button class="btn btn-xs btn-secondary btn-red" v-on:click="showDeleteModal = true">
<Icon name="trash-2" class="w-3 h-3 mx-1"/>
</button>
</div>
</div>
<Modal :show="showDeleteModal" v-on:close="showDeleteModal = false">
<DeleteDatabaseModal
:database="database"
v-on:close="showDeleteModal = false"
v-if="showDeleteModal"
/>
</modal>
</div>
</template>
<script lang="ts">
import Vue from 'vue';
import Icon from "@/components/core/Icon.vue";
import Modal from "@/components/core/Modal.vue";
import {ServerDatabase} from "@/api/server/types";
import DeleteDatabaseModal from "@/components/server/components/database/DeleteDatabaseModal.vue";
export default Vue.extend({
name: 'DatabaseRow',
components: {DeleteDatabaseModal, Modal, Icon},
props: {
database: {
type: Object as () => ServerDatabase,
required: true,
}
},
data: function () {
return {
showDeleteModal: false,
};
},
methods: {
revealPassword: function () {
this.database.showPassword = !this.database.showPassword;
},
},
})
</script>

View file

@ -1,84 +0,0 @@
import Vue from 'vue';
import {ServerDatabase} from "@/api/server/types";
export default Vue.component('DeleteDatabaseModal', {
props: {
database: {
type: Object as () => ServerDatabase,
required: true
},
},
data: function () {
return {
showSpinner: false,
nameConfirmation: '',
};
},
computed: {
/**
* Determine if the 'Delete' button should be enabled or not. This requires the user
* to enter the database name before actually deleting the DB.
*/
disabled: function () {
const splits: Array<string> = this.database.name.split('_');
return (
this.nameConfirmation !== this.database.name && this.nameConfirmation !== splits.slice(1).join('_')
);
}
},
methods: {
/**
* Handle deleting the database for the server instance.
*/
deleteDatabase: function () {
this.nameConfirmation = '';
this.showSpinner = true;
window.axios.delete(this.route('api.client.servers.databases.delete', {
server: this.$route.params.id,
database: this.database.id,
}))
.then(() => {
window.events.$emit('server:deleted-database', this.database.id);
})
.catch(err => {
this.$flash.clear();
console.error({ err });
const response = err.response;
if (response.data && typeof response.data.errors === 'object') {
response.data.errors.forEach((error: any) => {
this.$flash.error(error.detail);
});
}
})
.then(() => {
this.$emit('close');
})
},
},
template: `
<div>
<h2 class="font-medium text-neutral-900 mb-6">Delete this database?</h2>
<p class="text-neutral-900 text-sm">This action <strong>cannot</strong> be undone. This will permanetly delete the <strong>{{database.name}}</strong> database and remove all associated data.</p>
<div class="mt-6">
<label class="input-label">Confirm database name</label>
<input type="text" class="input" v-model="nameConfirmation"/>
</div>
<div class="mt-6 text-right">
<button class="btn btn-sm btn-secondary mr-2" v-on:click="$emit('close')">Cancel</button>
<button class="btn btn-sm btn-red" :disabled="disabled" v-on:click="deleteDatabase">
<span class="spinner white" v-bind:class="{ hidden: !showSpinner }">&nbsp;</span>
<span :class="{ hidden: showSpinner }">
Confirm Deletion
</span>
</button>
</div>
</div>
`,
});

View file

@ -0,0 +1,89 @@
<template>
<div>
<h2 class="font-medium text-neutral-900 mb-6">Delete this database?</h2>
<p class="text-neutral-900 text-sm">This action
<strong>cannot</strong> be undone. This will permanetly delete the
<strong>{{database.name}}</strong> database and remove all associated data.</p>
<div class="mt-6">
<label class="input-label">Confirm database name</label>
<input type="text" class="input" v-model="nameConfirmation"/>
</div>
<div class="mt-6 text-right">
<button class="btn btn-sm btn-secondary mr-2" v-on:click="$emit('close')">Cancel</button>
<button class="btn btn-sm btn-red" :disabled="disabled" v-on:click="deleteDatabase">
<span class="spinner white" v-bind:class="{ hidden: !showSpinner }">&nbsp;</span>
<span :class="{ hidden: showSpinner }">
Confirm Deletion
</span>
</button>
</div>
</div>
</template>
<script lang="ts">
import Vue from 'vue';
import {ServerDatabase} from "@/api/server/types";
export default Vue.extend({
name: 'DeleteDatabaseModal',
props: {
database: {
type: Object as () => ServerDatabase,
required: true
},
},
data: function () {
return {
showSpinner: false,
nameConfirmation: '',
};
},
computed: {
/**
* Determine if the 'Delete' button should be enabled or not. This requires the user
* to enter the database name before actually deleting the DB.
*/
disabled: function () {
const splits: Array<string> = this.database.name.split('_');
return (
this.nameConfirmation !== this.database.name && this.nameConfirmation !== splits.slice(1).join('_')
);
}
},
methods: {
/**
* Handle deleting the database for the server instance.
*/
deleteDatabase: function () {
this.nameConfirmation = '';
this.showSpinner = true;
window.axios.delete(this.route('api.client.servers.databases.delete', {
server: this.$route.params.id,
database: this.database.id,
}))
.then(() => {
window.events.$emit('server:deleted-database', this.database.id);
})
.catch(err => {
this.$flash.clear();
console.error({err});
const response = err.response;
if (response.data && typeof response.data.errors === 'object') {
response.data.errors.forEach((error: any) => {
this.$flash.error(error.detail);
});
}
})
.then(() => {
this.$emit('close');
})
},
},
});
</script>

View file

@ -1,59 +0,0 @@
import Vue from 'vue';
import Icon from "../../../core/Icon";
export default Vue.component('file-context-menu', {
components: { Icon },
template: `
<div class="context-menu">
<div>
<div class="context-row">
<div class="icon">
<icon name="edit-3"/>
</div>
<div class="action"><span>Rename</span></div>
</div>
<div class="context-row">
<div class="icon">
<icon name="corner-up-left" class="h-4"/>
</div>
<div class="action"><span class="text-left">Move</span></div>
</div>
<div class="context-row">
<div class="icon">
<icon name="copy" class="h-4"/>
</div>
<div class="action">Copy</div>
</div>
<div class="context-row">
<div class="icon">
<icon name="download" class="h-4"/>
</div>
<div class="action">Download</div>
</div>
</div>
<div>
<div class="context-row">
<div class="icon">
<icon name="file-plus" class="h-4"/>
</div>
<div class="action">New File</div>
</div>
<div class="context-row">
<div class="icon">
<icon name="folder-plus" class="h-4"/>
</div>
<div class="action">New Folder</div>
</div>
</div>
<div>
<div class="context-row danger">
<div class="icon">
<icon name="delete" class="h-4"/>
</div>
<div class="action">Delete</div>
</div>
</div>
</div>
`,
})

View file

@ -0,0 +1,62 @@
<template>
<div class="context-menu">
<div>
<div class="context-row">
<div class="icon">
<Icon name="edit-3"/>
</div>
<div class="action"><span>Rename</span></div>
</div>
<div class="context-row">
<div class="icon">
<Icon name="corner-up-left" class="h-4"/>
</div>
<div class="action"><span class="text-left">Move</span></div>
</div>
<div class="context-row">
<div class="icon">
<Icon name="copy" class="h-4"/>
</div>
<div class="action">Copy</div>
</div>
<div class="context-row">
<div class="icon">
<Icon name="download" class="h-4"/>
</div>
<div class="action">Download</div>
</div>
</div>
<div>
<div class="context-row">
<div class="icon">
<Icon name="file-plus" class="h-4"/>
</div>
<div class="action">New File</div>
</div>
<div class="context-row">
<div class="icon">
<Icon name="folder-plus" class="h-4"/>
</div>
<div class="action">New Folder</div>
</div>
</div>
<div>
<div class="context-row danger">
<div class="icon">
<Icon name="delete" class="h-4"/>
</div>
<div class="action">Delete</div>
</div>
</div>
</div>
</template>
<script lang="ts">
import Vue from 'vue';
import Icon from "../../../core/Icon.vue";
export default Vue.extend({
name: 'FileContextMenu',
components: { Icon },
});
</script>

View file

@ -1,99 +0,0 @@
import Vue from 'vue';
import Icon from "../../../core/Icon";
import {Vue as VueType} from "vue/types/vue";
import { readableSize, formatDate } from '../../../../helpers'
import FileContextMenu from "./FileContextMenu";
export default Vue.component('file-row', {
components: {
Icon,
FileContextMenu,
},
props: {
file: {type: Object, required: true},
editable: {type: Array, required: true}
},
data: function () {
return {
contextMenuVisible: false,
};
},
mounted: function () {
document.addEventListener('click', this._clickListener);
// If the parent component emits the collapse menu event check if the unique ID of the component
// is this one. If not, collapse the menu (we right clicked into another element).
this.$parent.$on('collapse-menus', (uid: string) => {
// @ts-ignore
if (this._uid !== uid) {
this.contextMenuVisible = false;
}
})
},
beforeDestroy: function () {
document.removeEventListener('click', this._clickListener, false);
},
methods: {
/**
* Handle a right-click action on a file manager row.
*/
showContextMenu: function (e: MouseEvent) {
e.preventDefault();
// @ts-ignore
this.$parent.$emit('collapse-menus', this._uid);
this.contextMenuVisible = true;
const menuWidth = (this.$refs.contextMenu as VueType).$el.clientWidth;
const positionElement = e.clientX - Math.round(menuWidth / 2);
(this.$refs.contextMenu as VueType).$el.setAttribute('style', `left: ${positionElement}; top: ${e.clientY}`);
},
/**
* Determine if a file can be edited on the Panel.
*/
canEdit: function (file: any): boolean {
return this.editable.indexOf(file.mime) >= 0;
},
/**
* Handle a click anywhere in the document and hide the context menu if that click is not
* a right click and isn't occurring somewhere in the currently visible context menu.
*
* @private
*/
_clickListener: function (e: MouseEvent) {
if (e.button !== 2 && this.contextMenuVisible) {
if (e.target !== (this.$refs.contextMenu as VueType).$el && !(this.$refs.contextMenu as VueType).$el.contains(e.target as Node)) {
this.contextMenuVisible = false;
}
}
},
readableSize: readableSize,
formatDate: formatDate,
},
template: `
<div>
<div class="row" :class="{ clickable: canEdit(file), 'active-selection': contextMenuVisible }" v-on:contextmenu="showContextMenu">
<div class="flex-none icon">
<icon name="file-text" v-if="!file.symlink"/>
<icon name="link2" v-else/>
</div>
<div class="flex-1">{{file.name}}</div>
<div class="flex-1 text-right text-neutral-600">{{readableSize(file.size)}}</div>
<div class="flex-1 text-right text-neutral-600">{{formatDate(file.modified)}}</div>
<div class="flex-none w-1/6"></div>
</div>
<file-context-menu class="context-menu" v-show="contextMenuVisible" ref="contextMenu"/>
</div>
`
});

View file

@ -0,0 +1,102 @@
<template>
<div>
<div class="row" :class="{ clickable: canEdit(file), 'active-selection': contextMenuVisible }" v-on:contextmenu="showContextMenu">
<div class="flex-none icon">
<Icon name="file-text" v-if="!file.symlink"/>
<Icon name="link2" v-else/>
</div>
<div class="flex-1">{{file.name}}</div>
<div class="flex-1 text-right text-neutral-600">{{readableSize(file.size)}}</div>
<div class="flex-1 text-right text-neutral-600">{{formatDate(file.modified)}}</div>
<div class="flex-none w-1/6"></div>
</div>
<FileContextMenu class="context-menu" v-show="contextMenuVisible" ref="contextMenu"/>
</div>
</template>
<script lang="ts">
import Vue from 'vue';
import Icon from "../../../core/Icon.vue";
import {Vue as VueType} from "vue/types/vue";
import {formatDate, readableSize} from '../../../../helpers'
import FileContextMenu from "./FileContextMenu.vue";
export default Vue.extend({
name: 'FileRow',
components: {
Icon,
FileContextMenu,
},
props: {
file: {type: Object, required: true},
editable: {type: Array, required: true}
},
data: function () {
return {
contextMenuVisible: false,
};
},
mounted: function () {
document.addEventListener('click', this._clickListener);
// If the parent component emits the collapse menu event check if the unique ID of the component
// is this one. If not, collapse the menu (we right clicked into another element).
this.$parent.$on('collapse-menus', (uid: string) => {
// @ts-ignore
if (this._uid !== uid) {
this.contextMenuVisible = false;
}
})
},
beforeDestroy: function () {
document.removeEventListener('click', this._clickListener, false);
},
methods: {
/**
* Handle a right-click action on a file manager row.
*/
showContextMenu: function (e: MouseEvent) {
e.preventDefault();
// @ts-ignore
this.$parent.$emit('collapse-menus', this._uid);
this.contextMenuVisible = true;
const menuWidth = (this.$refs.contextMenu as VueType).$el.clientWidth;
const positionElement = e.clientX - Math.round(menuWidth / 2);
(this.$refs.contextMenu as VueType).$el.setAttribute('style', `left: ${positionElement}; top: ${e.clientY}`);
},
/**
* Determine if a file can be edited on the Panel.
*/
canEdit: function (file: any): boolean {
return this.editable.indexOf(file.mime) >= 0;
},
/**
* Handle a click anywhere in the document and hide the context menu if that click is not
* a right click and isn't occurring somewhere in the currently visible context menu.
*
* @private
*/
_clickListener: function (e: MouseEvent) {
if (e.button !== 2 && this.contextMenuVisible) {
if (e.target !== (this.$refs.contextMenu as VueType).$el && !(this.$refs.contextMenu as VueType).$el.contains(e.target as Node)) {
this.contextMenuVisible = false;
}
}
},
readableSize: readableSize,
formatDate: formatDate,
},
});
</script>

View file

@ -1,44 +0,0 @@
import Vue from 'vue';
import { formatDate } from "@/helpers";
import Icon from "@/components/core/Icon";
export default Vue.component('folder-row', {
components: { Icon },
props: {
directory: {type: Object, required: true},
},
data: function () {
return {
currentDirectory: this.$route.params.path || '/',
};
},
methods: {
/**
* Return a formatted directory path that is used to switch to a nested directory.
*/
getClickablePath (directory: string): string {
return `${this.currentDirectory.replace(/\/$/, '')}/${directory}`;
},
formatDate: formatDate,
},
template: `
<div>
<router-link class="row clickable"
:to="{ name: 'server-files', params: { path: getClickablePath(directory.name).replace(/^\\//, '') }}"
>
<div class="flex-none icon text-primary-700">
<icon name="folder"/>
</div>
<div class="flex-1">{{directory.name}}</div>
<div class="flex-1 text-right text-neutral-600"></div>
<div class="flex-1 text-right text-neutral-600">{{formatDate(directory.modified)}}</div>
<div class="flex-none w-1/6"></div>
</router-link>
</div>
`
});

View file

@ -0,0 +1,47 @@
<template>
<div>
<router-link class="row clickable"
:to="{ name: 'server-files', params: { path: getClickablePath(directory.name) }}"
>
<div class="flex-none icon text-primary-700">
<Icon name="folder"/>
</div>
<div class="flex-1">{{directory.name}}</div>
<div class="flex-1 text-right text-neutral-600"></div>
<div class="flex-1 text-right text-neutral-600">{{formatDate(directory.modified)}}</div>
<div class="flex-none w-1/6"></div>
</router-link>
</div>
</template>
<script lang="ts">
import Vue from 'vue';
import { formatDate } from "@/helpers";
import Icon from "@/components/core/Icon.vue";
export default Vue.extend({
name: 'FolderRow',
components: { Icon },
props: {
directory: {type: Object, required: true},
},
data: function () {
return {
currentDirectory: this.$route.params.path || '/',
};
},
methods: {
/**
* Return a formatted directory path that is used to switch to a nested directory.
*/
getClickablePath (directory: string): string {
return `${this.currentDirectory.replace(/\/$/, '')}/${directory}`;
},
formatDate: formatDate,
},
});
</script>