2022-01-27 13:31:46 +00:00
|
|
|
<script lang="ts" context="module">
|
|
|
|
async function openTextFile(fileName, fileType, folderName, tabComponent, icon) {
|
|
|
|
const connProps: any = {};
|
|
|
|
let tooltip = undefined;
|
|
|
|
|
2022-01-28 16:36:40 +00:00
|
|
|
const savedFile = fileType == 'vfk.json' ? fileName : fileName + '.' + fileType;
|
|
|
|
|
2022-01-27 13:31:46 +00:00
|
|
|
const resp = await apiCall('files/load', {
|
|
|
|
folder: 'app:' + folderName,
|
2022-01-28 16:36:40 +00:00
|
|
|
file: savedFile,
|
2022-01-27 13:31:46 +00:00
|
|
|
format: 'text',
|
|
|
|
});
|
|
|
|
|
|
|
|
openNewTab(
|
|
|
|
{
|
|
|
|
title: fileName,
|
|
|
|
icon,
|
|
|
|
tabComponent,
|
|
|
|
tooltip,
|
|
|
|
props: {
|
2022-01-28 16:36:40 +00:00
|
|
|
savedFile,
|
2022-01-27 13:31:46 +00:00
|
|
|
savedFolder: 'app:' + folderName,
|
|
|
|
savedFormat: 'text',
|
|
|
|
appFolder: folderName,
|
|
|
|
...connProps,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{ editor: resp }
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export const extractKey = data => data.fileName;
|
|
|
|
export const createMatcher = ({ fileName }) => filter => filterName(filter, fileName);
|
|
|
|
const APP_ICONS = {
|
2022-01-28 16:36:40 +00:00
|
|
|
'vfk.json': 'img json',
|
2022-01-27 13:31:46 +00:00
|
|
|
'command.sql': 'img app-command',
|
|
|
|
'query.sql': 'img app-query',
|
|
|
|
};
|
|
|
|
|
2022-01-27 16:01:58 +00:00
|
|
|
function getAppIcon(data) {
|
2022-01-27 13:31:46 +00:00
|
|
|
return APP_ICONS[data.fileType];
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import _ from 'lodash';
|
|
|
|
import { filterName } from 'dbgate-tools';
|
|
|
|
import { showModal } from '../modals/modalTools';
|
|
|
|
|
|
|
|
import openNewTab from '../utility/openNewTab';
|
|
|
|
import AppObjectCore from './AppObjectCore.svelte';
|
|
|
|
import InputTextModal from '../modals/InputTextModal.svelte';
|
|
|
|
import ConfirmModal from '../modals/ConfirmModal.svelte';
|
|
|
|
import { apiCall } from '../utility/api';
|
2022-01-27 16:01:58 +00:00
|
|
|
import { currentDatabase, currentDatabase } from '../stores';
|
2022-01-27 13:31:46 +00:00
|
|
|
|
|
|
|
export let data;
|
|
|
|
|
|
|
|
const handleRename = () => {
|
|
|
|
showModal(InputTextModal, {
|
|
|
|
value: data.fileName,
|
|
|
|
label: 'New file name',
|
|
|
|
header: 'Rename file',
|
|
|
|
onConfirm: newFile => {
|
|
|
|
apiCall('apps/rename-file', {
|
|
|
|
file: data.fileName,
|
|
|
|
folder: data.folderName,
|
|
|
|
fileType: data.fileType,
|
|
|
|
newFile,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleDelete = () => {
|
|
|
|
showModal(ConfirmModal, {
|
|
|
|
message: `Really delete file ${data.fileName}?`,
|
|
|
|
onConfirm: () => {
|
|
|
|
apiCall('apps/delete-file', {
|
|
|
|
file: data.fileName,
|
|
|
|
folder: data.folderName,
|
|
|
|
fileType: data.fileType,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
const handleClick = () => {
|
|
|
|
if (data.fileType.endsWith('.sql')) {
|
|
|
|
handleOpenSqlFile();
|
|
|
|
}
|
2022-01-28 16:36:40 +00:00
|
|
|
if (data.fileType.endsWith('.json')) {
|
|
|
|
handleOpenJsonFile();
|
|
|
|
}
|
2022-01-27 13:31:46 +00:00
|
|
|
};
|
|
|
|
const handleOpenSqlFile = () => {
|
|
|
|
openTextFile(data.fileName, data.fileType, data.folderName, 'QueryTab', 'img sql-file');
|
|
|
|
};
|
2022-01-28 16:36:40 +00:00
|
|
|
const handleOpenJsonFile = () => {
|
|
|
|
openTextFile(data.fileName, data.fileType, data.folderName, 'JsonEditorTab', 'img json');
|
2022-01-27 13:31:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function createMenu() {
|
|
|
|
return [
|
|
|
|
{ text: 'Delete', onClick: handleDelete },
|
|
|
|
{ text: 'Rename', onClick: handleRename },
|
|
|
|
data.fileType.endsWith('.sql') && { text: 'Open SQL', onClick: handleOpenSqlFile },
|
2022-01-28 16:36:40 +00:00
|
|
|
data.fileType.endsWith('.json') && { text: 'Open JSON', onClick: handleOpenJsonFile },
|
2022-01-27 16:01:58 +00:00
|
|
|
|
2022-01-27 13:31:46 +00:00
|
|
|
// data.fileType.endsWith('.yaml') && { text: 'Open YAML', onClick: handleOpenYamlFile },
|
|
|
|
];
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<AppObjectCore
|
|
|
|
{...$$restProps}
|
|
|
|
{data}
|
|
|
|
title={data.fileLabel}
|
2022-01-27 16:01:58 +00:00
|
|
|
icon={getAppIcon(data)}
|
2022-01-27 13:31:46 +00:00
|
|
|
menu={createMenu}
|
|
|
|
on:click={handleClick}
|
|
|
|
/>
|