mirror of
https://github.com/Fabio286/antares.git
synced 2025-06-05 21:59:22 +02:00
feat: buttons to save and access to saved queryes from query tab
This commit is contained in:
@ -180,7 +180,7 @@ const { t } = useI18n();
|
|||||||
const applicationStore = useApplicationStore();
|
const applicationStore = useApplicationStore();
|
||||||
const scratchpadStore = useScratchpadStore();
|
const scratchpadStore = useScratchpadStore();
|
||||||
|
|
||||||
const { connectionNotes } = storeToRefs(scratchpadStore);
|
const { connectionNotes, selectedTag } = storeToRefs(scratchpadStore);
|
||||||
const { changeNotes } = scratchpadStore;
|
const { changeNotes } = scratchpadStore;
|
||||||
const { hideScratchpad } = applicationStore;
|
const { hideScratchpad } = applicationStore;
|
||||||
const { getConnectionName } = useConnectionsStore();
|
const { getConnectionName } = useConnectionsStore();
|
||||||
@ -202,7 +202,6 @@ const showArchived = ref(false);
|
|||||||
const isAddModal = ref(false);
|
const isAddModal = ref(false);
|
||||||
const isEditModal = ref(false);
|
const isEditModal = ref(false);
|
||||||
const noteToEdit: Ref<ConnectionNote> = ref(null);
|
const noteToEdit: Ref<ConnectionNote> = ref(null);
|
||||||
const selectedTag = ref('all');
|
|
||||||
const selectedNote = ref(null);
|
const selectedNote = ref(null);
|
||||||
|
|
||||||
const noteTags: ComputedRef<{code: TagCode; name: string}[]> = computed(() => [
|
const noteTags: ComputedRef<{code: TagCode; name: string}[]> = computed(() => [
|
||||||
|
@ -65,7 +65,7 @@
|
|||||||
content: t('application.note', 2)
|
content: t('application.note', 2)
|
||||||
}"
|
}"
|
||||||
class="settingbar-element btn btn-link"
|
class="settingbar-element btn btn-link"
|
||||||
@click="showScratchpad"
|
@click="showScratchpad()"
|
||||||
>
|
>
|
||||||
<BaseIcon
|
<BaseIcon
|
||||||
icon-name="mdiNotebookOutline"
|
icon-name="mdiNotebookOutline"
|
||||||
|
@ -89,27 +89,37 @@
|
|||||||
<button
|
<button
|
||||||
class="btn btn-dark btn-sm"
|
class="btn btn-dark btn-sm"
|
||||||
:disabled="!query || isQuering"
|
:disabled="!query || isQuering"
|
||||||
|
:title="t('general.format')"
|
||||||
@click="beautify()"
|
@click="beautify()"
|
||||||
>
|
>
|
||||||
<BaseIcon
|
<BaseIcon icon-name="mdiBrush" :size="24" />
|
||||||
class="mr-1"
|
|
||||||
icon-name="mdiBrush"
|
|
||||||
:size="24"
|
|
||||||
/>
|
|
||||||
<span>{{ t('general.format') }}</span>
|
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
class="btn btn-dark btn-sm"
|
class="btn btn-dark btn-sm"
|
||||||
:disabled="isQuering"
|
:disabled="isQuering"
|
||||||
|
:title="t('general.history')"
|
||||||
@click="openHistoryModal()"
|
@click="openHistoryModal()"
|
||||||
>
|
>
|
||||||
<BaseIcon
|
<BaseIcon icon-name="mdiHistory" :size="24" />
|
||||||
class="mr-1"
|
|
||||||
icon-name="mdiHistory"
|
|
||||||
:size="24"
|
|
||||||
/>
|
|
||||||
<span>{{ t('general.history') }}</span>
|
|
||||||
</button>
|
</button>
|
||||||
|
<div class="btn-group">
|
||||||
|
<button
|
||||||
|
class="btn btn-dark btn-sm mr-0"
|
||||||
|
:disabled="isQuering || (isQuerySaved || query.length < 5)"
|
||||||
|
:title="t('general.save')"
|
||||||
|
@click="saveQuery()"
|
||||||
|
>
|
||||||
|
<BaseIcon icon-name="mdiContentSaveOutline" :size="24" />
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
class="btn btn-dark btn-sm"
|
||||||
|
:disabled="isQuering"
|
||||||
|
:title="t('database.savedQueries')"
|
||||||
|
@click="openSavedModal()"
|
||||||
|
>
|
||||||
|
<BaseIcon icon-name="mdiStarOutline" :size="24" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
<div class="dropdown table-dropdown pr-2">
|
<div class="dropdown table-dropdown pr-2">
|
||||||
<button
|
<button
|
||||||
:disabled="!hasResults || isQuering"
|
:disabled="!hasResults || isQuering"
|
||||||
@ -237,6 +247,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { Ace } from 'ace-builds';
|
import { Ace } from 'ace-builds';
|
||||||
import { ConnectionParams } from 'common/interfaces/antares';
|
import { ConnectionParams } from 'common/interfaces/antares';
|
||||||
|
import { uidGen } from 'common/libs/uidGen';
|
||||||
import { ipcRenderer } from 'electron';
|
import { ipcRenderer } from 'electron';
|
||||||
import { storeToRefs } from 'pinia';
|
import { storeToRefs } from 'pinia';
|
||||||
import { format } from 'sql-formatter';
|
import { format } from 'sql-formatter';
|
||||||
@ -252,9 +263,11 @@ import WorkspaceTabQueryEmptyState from '@/components/WorkspaceTabQueryEmptyStat
|
|||||||
import WorkspaceTabQueryTable from '@/components/WorkspaceTabQueryTable.vue';
|
import WorkspaceTabQueryTable from '@/components/WorkspaceTabQueryTable.vue';
|
||||||
import { useResultTables } from '@/composables/useResultTables';
|
import { useResultTables } from '@/composables/useResultTables';
|
||||||
import Schema from '@/ipc-api/Schema';
|
import Schema from '@/ipc-api/Schema';
|
||||||
|
import { useApplicationStore } from '@/stores/application';
|
||||||
import { useConsoleStore } from '@/stores/console';
|
import { useConsoleStore } from '@/stores/console';
|
||||||
import { useHistoryStore } from '@/stores/history';
|
import { useHistoryStore } from '@/stores/history';
|
||||||
import { useNotificationsStore } from '@/stores/notifications';
|
import { useNotificationsStore } from '@/stores/notifications';
|
||||||
|
import { useScratchpadStore } from '@/stores/scratchpad';
|
||||||
import { useSettingsStore } from '@/stores/settings';
|
import { useSettingsStore } from '@/stores/settings';
|
||||||
import { useWorkspacesStore } from '@/stores/workspaces';
|
import { useWorkspacesStore } from '@/stores/workspaces';
|
||||||
|
|
||||||
@ -279,6 +292,8 @@ const {
|
|||||||
const { saveHistory } = useHistoryStore();
|
const { saveHistory } = useHistoryStore();
|
||||||
const { addNotification } = useNotificationsStore();
|
const { addNotification } = useNotificationsStore();
|
||||||
const workspacesStore = useWorkspacesStore();
|
const workspacesStore = useWorkspacesStore();
|
||||||
|
const { showScratchpad } = useApplicationStore();
|
||||||
|
const { addNote } = useScratchpadStore();
|
||||||
|
|
||||||
const { consoleHeight } = storeToRefs(useConsoleStore());
|
const { consoleHeight } = storeToRefs(useConsoleStore());
|
||||||
const { executeSelected } = storeToRefs(useSettingsStore());
|
const { executeSelected } = storeToRefs(useSettingsStore());
|
||||||
@ -304,6 +319,7 @@ const resultsCount = ref(0);
|
|||||||
const durationsCount = ref(0);
|
const durationsCount = ref(0);
|
||||||
const affectedCount = ref(null);
|
const affectedCount = ref(null);
|
||||||
const editorHeight = ref(200);
|
const editorHeight = ref(200);
|
||||||
|
const isQuerySaved = ref(false);
|
||||||
const isHistoryOpen = ref(false);
|
const isHistoryOpen = ref(false);
|
||||||
const debounceTimeout = ref(null);
|
const debounceTimeout = ref(null);
|
||||||
|
|
||||||
@ -329,6 +345,7 @@ watch(query, (val) => {
|
|||||||
schema: selectedSchema.value,
|
schema: selectedSchema.value,
|
||||||
content: val
|
content: val
|
||||||
});
|
});
|
||||||
|
isQuerySaved.value = false;
|
||||||
}, 200);
|
}, 200);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -496,6 +513,22 @@ const openHistoryModal = () => {
|
|||||||
isHistoryOpen.value = true;
|
isHistoryOpen.value = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const saveQuery = () => {
|
||||||
|
addNote({
|
||||||
|
uid: uidGen('N'),
|
||||||
|
cUid: workspace.value.uid,
|
||||||
|
type: 'query',
|
||||||
|
date: new Date(),
|
||||||
|
note: query.value,
|
||||||
|
isArchived: false
|
||||||
|
});
|
||||||
|
isQuerySaved.value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const openSavedModal = () => {
|
||||||
|
showScratchpad('query');
|
||||||
|
};
|
||||||
|
|
||||||
const selectQuery = (sql: string) => {
|
const selectQuery = (sql: string) => {
|
||||||
if (queryEditor.value)
|
if (queryEditor.value)
|
||||||
queryEditor.value.editor.session.setValue(sql);
|
queryEditor.value.editor.session.setValue(sql);
|
||||||
|
@ -280,7 +280,8 @@ export const enUS = {
|
|||||||
targetTable: 'Target table',
|
targetTable: 'Target table',
|
||||||
switchDatabase: 'Switch the database',
|
switchDatabase: 'Switch the database',
|
||||||
searchForElements: 'Search for elements',
|
searchForElements: 'Search for elements',
|
||||||
searchForSchemas: 'Search for schemas'
|
searchForSchemas: 'Search for schemas',
|
||||||
|
savedQueries: 'Saved queries'
|
||||||
},
|
},
|
||||||
application: { // Application related terms
|
application: { // Application related terms
|
||||||
settings: 'Settings',
|
settings: 'Settings',
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import { Ace } from 'ace-builds';
|
import { Ace } from 'ace-builds';
|
||||||
import * as Store from 'electron-store';
|
import * as Store from 'electron-store';
|
||||||
import { defineStore } from 'pinia';
|
import { defineStore, storeToRefs } from 'pinia';
|
||||||
|
|
||||||
|
import { useScratchpadStore } from './scratchpad';
|
||||||
|
|
||||||
const persistentStore = new Store({ name: 'settings' });
|
const persistentStore = new Store({ name: 'settings' });
|
||||||
export type UpdateStatus = 'noupdate' | 'available' | 'checking' | 'nocheck' | 'downloading' | 'downloaded' | 'disabled' | 'link';
|
export type UpdateStatus = 'noupdate' | 'available' | 'checking' | 'nocheck' | 'downloading' | 'downloaded' | 'disabled' | 'link';
|
||||||
@ -51,8 +53,12 @@ export const useApplicationStore = defineStore('application', {
|
|||||||
hideSettingModal () {
|
hideSettingModal () {
|
||||||
this.isSettingModal = false;
|
this.isSettingModal = false;
|
||||||
},
|
},
|
||||||
showScratchpad () {
|
showScratchpad (tag?: string) {
|
||||||
this.isScratchpad = true;
|
this.isScratchpad = true;
|
||||||
|
if (tag) {
|
||||||
|
const { selectedTag } = storeToRefs(useScratchpadStore());
|
||||||
|
selectedTag.value = tag;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
hideScratchpad () {
|
hideScratchpad () {
|
||||||
this.isScratchpad = false;
|
this.isScratchpad = false;
|
||||||
|
@ -16,6 +16,7 @@ export interface ConnectionNote {
|
|||||||
|
|
||||||
export const useScratchpadStore = defineStore('scratchpad', {
|
export const useScratchpadStore = defineStore('scratchpad', {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
|
selectedTag: 'all',
|
||||||
/** Global notes */
|
/** Global notes */
|
||||||
notes: persistentStore.get('notes', '# HOW TO SUPPORT ANTARES\n\n- [ ] Leave a star to Antares [GitHub repo](https://github.com/antares-sql/antares)\n- [ ] Send feedbacks and advices\n- [ ] Report for bugs\n- [ ] If you enjoy, share Antares with friends\n\n# ABOUT SCRATCHPAD\n\nThis is a scratchpad where you can save your **personal notes**. It supports `markdown` format, but you are free to use plain text.\nThis content is just a placeholder, feel free to clear it to make space for your notes.\n') as string,
|
notes: persistentStore.get('notes', '# HOW TO SUPPORT ANTARES\n\n- [ ] Leave a star to Antares [GitHub repo](https://github.com/antares-sql/antares)\n- [ ] Send feedbacks and advices\n- [ ] Report for bugs\n- [ ] If you enjoy, share Antares with friends\n\n# ABOUT SCRATCHPAD\n\nThis is a scratchpad where you can save your **personal notes**. It supports `markdown` format, but you are free to use plain text.\nThis content is just a placeholder, feel free to clear it to make space for your notes.\n') as string,
|
||||||
/** Connection specific notes */
|
/** Connection specific notes */
|
||||||
|
Reference in New Issue
Block a user