mirror of
https://github.com/Macrame-App/Macrame
synced 2025-12-29 07:19:26 +00:00
Edit functionality added to frontend.
This commit is contained in:
parent
9e0337a2be
commit
05a5cb8325
5 changed files with 88 additions and 30 deletions
|
|
@ -12,7 +12,7 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { computed, onMounted } from 'vue'
|
import { computed } from 'vue'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
href: String,
|
href: String,
|
||||||
|
|
@ -83,10 +83,10 @@ button,
|
||||||
}
|
}
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
@apply !text-white;
|
@apply text-white;
|
||||||
|
|
||||||
svg {
|
svg {
|
||||||
@apply !stroke-white;
|
@apply stroke-current;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,15 +5,39 @@
|
||||||
<LoadComp :loading="macros.loading" text="Loading macros..." />
|
<LoadComp :loading="macros.loading" text="Loading macros..." />
|
||||||
<div class="macro-item" v-for="(macro, i) in macros.list" :key="i">
|
<div class="macro-item" v-for="(macro, i) in macros.list" :key="i">
|
||||||
<ButtonComp
|
<ButtonComp
|
||||||
variant="dark"
|
:variant="macroRecorder.macroName === macro.name ? 'secondary' : 'dark'"
|
||||||
class="overview__macro-button"
|
class="overview__macro-open"
|
||||||
size="sm"
|
size="sm"
|
||||||
@click="macroRecorder.open(macro.macroname, macro.name)"
|
@click="macroRecorder.openMacro(macro.macroname, macro.name)"
|
||||||
>
|
>
|
||||||
<IconKeyboard /> <span>{{ macro.name }}</span>
|
<IconKeyboard /> <span>{{ macro.name }}</span>
|
||||||
</ButtonComp>
|
</ButtonComp>
|
||||||
|
<div class="overview__macro-delete">
|
||||||
|
<ButtonComp
|
||||||
|
class="!text-red-500 hover:!text-red-300"
|
||||||
|
variant="ghost"
|
||||||
|
size="sm"
|
||||||
|
@click="startDelete(macro.name)"
|
||||||
|
>
|
||||||
|
<IconTrash />
|
||||||
|
</ButtonComp>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<DialogComp ref="deleteDialog">
|
||||||
|
<template #content>
|
||||||
|
<div class="grid gap-2">
|
||||||
|
<h4 class="pr-4">Are you sure you want to delete:</h4>
|
||||||
|
<h3 class="mb-2 text-center text-sky-500">{{ macroToBeDeleted }}</h3>
|
||||||
|
<div class="flex justify-between">
|
||||||
|
<ButtonComp size="sm" variant="subtle" @click="deleteDialog.toggleDialog(false)">
|
||||||
|
No
|
||||||
|
</ButtonComp>
|
||||||
|
<ButtonComp size="sm" variant="danger" @click="deleteMacro()">Yes</ButtonComp>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</DialogComp>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
@ -21,12 +45,13 @@
|
||||||
// TODO
|
// TODO
|
||||||
// - delete macro
|
// - delete macro
|
||||||
|
|
||||||
import { IconKeyboard } from '@tabler/icons-vue'
|
import { IconKeyboard, IconTrash } from '@tabler/icons-vue'
|
||||||
import ButtonComp from '../base/ButtonComp.vue'
|
import ButtonComp from '../base/ButtonComp.vue'
|
||||||
import { onMounted, reactive } from 'vue'
|
import { onMounted, reactive, ref } from 'vue'
|
||||||
import { GetMacroList } from '@/services/MacroService'
|
import { GetMacroList } from '@/services/MacroService'
|
||||||
import LoadComp from '../base/LoadComp.vue'
|
import LoadComp from '../base/LoadComp.vue'
|
||||||
import { useMacroRecorderStore } from '@/stores/macrorecorder'
|
import { useMacroRecorderStore } from '@/stores/macrorecorder'
|
||||||
|
import DialogComp from '../base/DialogComp.vue'
|
||||||
|
|
||||||
const macros = reactive({
|
const macros = reactive({
|
||||||
loading: true,
|
loading: true,
|
||||||
|
|
@ -35,6 +60,9 @@ const macros = reactive({
|
||||||
|
|
||||||
const macroRecorder = useMacroRecorderStore()
|
const macroRecorder = useMacroRecorderStore()
|
||||||
|
|
||||||
|
const macroToBeDeleted = ref('')
|
||||||
|
const deleteDialog = ref()
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
loadMacroList()
|
loadMacroList()
|
||||||
})
|
})
|
||||||
|
|
@ -44,6 +72,24 @@ const loadMacroList = async () => {
|
||||||
macros.list = list
|
macros.list = list
|
||||||
macros.loading = false
|
macros.loading = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const startDelete = (macroFilename) => {
|
||||||
|
macroToBeDeleted.value = macroFilename
|
||||||
|
deleteDialog.value.toggleDialog(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
const deleteMacro = async () => {
|
||||||
|
const resp = await macroRecorder.deleteMacro(macroToBeDeleted.value)
|
||||||
|
|
||||||
|
if (resp) {
|
||||||
|
deleteDialog.value.toggleDialog(false)
|
||||||
|
|
||||||
|
if (macroToBeDeleted.value === macroRecorder.macroName) macroRecorder.resetMacro()
|
||||||
|
|
||||||
|
macroToBeDeleted.value = ''
|
||||||
|
loadMacroList()
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|
@ -68,21 +114,30 @@ const loadMacroList = async () => {
|
||||||
@apply flex
|
@apply flex
|
||||||
flex-col
|
flex-col
|
||||||
pr-1
|
pr-1
|
||||||
|
-mr-1
|
||||||
gap-1
|
gap-1
|
||||||
h-[calc(100vh-11.7rem)]
|
h-[calc(100vh-11.7rem)]
|
||||||
overflow-auto;
|
overflow-auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.macro-item {
|
.macro-item {
|
||||||
@apply flex items-center;
|
@apply grid items-center grid-cols-[1fr_0fr] transition-[grid-template-columns] delay-0 duration-300;
|
||||||
|
|
||||||
button.overview__macro-button {
|
&:hover {
|
||||||
|
@apply grid-cols-[1fr_auto] delay-500;
|
||||||
|
}
|
||||||
|
|
||||||
|
button.overview__macro-open {
|
||||||
@apply w-full grid grid-cols-[1rem_1fr] justify-items-start;
|
@apply w-full grid grid-cols-[1rem_1fr] justify-items-start;
|
||||||
|
|
||||||
span {
|
span {
|
||||||
@apply truncate w-full text-left;
|
@apply truncate w-full text-left;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
div.overview__macro-delete {
|
||||||
|
@apply grid overflow-hidden transition;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
<ButtonComp
|
<ButtonComp
|
||||||
v-if="macroRecorder.steps.length > 0"
|
v-if="macroRecorder.steps.length > 0"
|
||||||
variant="danger"
|
variant="danger"
|
||||||
size="sm"
|
|
||||||
@click="macroRecorder.reset()"
|
@click="macroRecorder.reset()"
|
||||||
>
|
>
|
||||||
<IconRestore /> Reset
|
<IconRestore /> Reset
|
||||||
|
|
@ -20,10 +19,10 @@
|
||||||
<h4 class="pr-4">Are you sure you want to overwrite:</h4>
|
<h4 class="pr-4">Are you sure you want to overwrite:</h4>
|
||||||
<h3 class="mb-2 text-center text-sky-500">{{ macroRecorder.macroName }}</h3>
|
<h3 class="mb-2 text-center text-sky-500">{{ macroRecorder.macroName }}</h3>
|
||||||
<div class="flex justify-between">
|
<div class="flex justify-between">
|
||||||
<ButtonComp variant="subtle" @click="overwriteDialog.toggleDialog(false)"
|
<ButtonComp size="sm" variant="subtle" @click="overwriteDialog.toggleDialog(false)"
|
||||||
>No</ButtonComp
|
>No</ButtonComp
|
||||||
>
|
>
|
||||||
<ButtonComp variant="primary" @click="saveMacro()">Yes</ButtonComp>
|
<ButtonComp size="sm" variant="primary" @click="saveMacro()">Yes</ButtonComp>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
@ -33,7 +32,6 @@
|
||||||
v-if="macroRecorder.steps.length > 0"
|
v-if="macroRecorder.steps.length > 0"
|
||||||
:disabled="macroRecorder.state.record || macroRecorder.state.edit"
|
:disabled="macroRecorder.state.record || macroRecorder.state.edit"
|
||||||
variant="success"
|
variant="success"
|
||||||
size="sm"
|
|
||||||
@click="startCheck()"
|
@click="startCheck()"
|
||||||
>
|
>
|
||||||
<IconDeviceFloppy />
|
<IconDeviceFloppy />
|
||||||
|
|
@ -65,7 +63,7 @@ onMounted(() => {
|
||||||
})
|
})
|
||||||
|
|
||||||
const startCheck = async () => {
|
const startCheck = async () => {
|
||||||
const checkResp = await macroRecorder.check()
|
const checkResp = await macroRecorder.checkMacro()
|
||||||
|
|
||||||
if (checkResp) overwriteDialog.value.toggleDialog(true)
|
if (checkResp) overwriteDialog.value.toggleDialog(true)
|
||||||
else saveMacro()
|
else saveMacro()
|
||||||
|
|
@ -74,7 +72,7 @@ const startCheck = async () => {
|
||||||
const saveMacro = async () => {
|
const saveMacro = async () => {
|
||||||
overwriteDialog.value.toggleDialog(false)
|
overwriteDialog.value.toggleDialog(false)
|
||||||
|
|
||||||
const saveResp = await macroRecorder.save()
|
const saveResp = await macroRecorder.saveMacro()
|
||||||
|
|
||||||
if (!saveResp) errorDialog.value.toggleDialog(true)
|
if (!saveResp) errorDialog.value.toggleDialog(true)
|
||||||
else window.location.reload()
|
else window.location.reload()
|
||||||
|
|
|
||||||
|
|
@ -76,8 +76,6 @@ onUpdated(() => {
|
||||||
})
|
})
|
||||||
|
|
||||||
function changeName(name) {
|
function changeName(name) {
|
||||||
console.log(name)
|
|
||||||
|
|
||||||
macroRecorder.changeName(name)
|
macroRecorder.changeName(name)
|
||||||
nameSet.value = name.length > 0
|
nameSet.value = name.length > 0
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,8 +74,6 @@ export const useMacroRecorderStore = defineStore('macrorecorder', () => {
|
||||||
|
|
||||||
if (key !== false) steps.value[key] = stepVal
|
if (key !== false) steps.value[key] = stepVal
|
||||||
else steps.value.push(stepVal)
|
else steps.value.push(stepVal)
|
||||||
|
|
||||||
console.log(steps.value)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const recordDelay = () => {
|
const recordDelay = () => {
|
||||||
|
|
@ -167,15 +165,16 @@ export const useMacroRecorderStore = defineStore('macrorecorder', () => {
|
||||||
state.value.editDelay = false
|
state.value.editDelay = false
|
||||||
}
|
}
|
||||||
|
|
||||||
const reset = () => {
|
const resetMacro = () => {
|
||||||
state.value.record = false
|
state.value.record = false
|
||||||
delay.value.start = 0
|
delay.value.start = 0
|
||||||
|
macroName.value = ''
|
||||||
steps.value = []
|
steps.value = []
|
||||||
|
|
||||||
if (state.value.edit) resetEdit()
|
if (state.value.edit) resetEdit()
|
||||||
}
|
}
|
||||||
|
|
||||||
const check = async () => {
|
const checkMacro = async () => {
|
||||||
const resp = await axios.post(appUrl() + '/macro/check', {
|
const resp = await axios.post(appUrl() + '/macro/check', {
|
||||||
macro: macroName.value,
|
macro: macroName.value,
|
||||||
})
|
})
|
||||||
|
|
@ -183,7 +182,7 @@ export const useMacroRecorderStore = defineStore('macrorecorder', () => {
|
||||||
return resp.data
|
return resp.data
|
||||||
}
|
}
|
||||||
|
|
||||||
const save = async () => {
|
const saveMacro = async () => {
|
||||||
state.value.validationErrors = invalidMacro(steps.value)
|
state.value.validationErrors = invalidMacro(steps.value)
|
||||||
|
|
||||||
if (state.value.validationErrors) return false
|
if (state.value.validationErrors) return false
|
||||||
|
|
@ -196,15 +195,22 @@ export const useMacroRecorderStore = defineStore('macrorecorder', () => {
|
||||||
return resp.status == 200
|
return resp.status == 200
|
||||||
}
|
}
|
||||||
|
|
||||||
const open = async (macroFileName, name) => {
|
const deleteMacro = async (macroFilename) => {
|
||||||
|
const resp = await axios.post(appUrl() + '/macro/delete', {
|
||||||
|
macro: macroFilename,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (resp.status == 200) return resp.data
|
||||||
|
else return false
|
||||||
|
}
|
||||||
|
|
||||||
|
const openMacro = async (macroFileName, name) => {
|
||||||
const openResp = await axios.post(appUrl() + '/macro/open', {
|
const openResp = await axios.post(appUrl() + '/macro/open', {
|
||||||
macro: macroFileName,
|
macro: macroFileName,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (openResp.data) steps.value = translateJSON(openResp.data)
|
if (openResp.data) steps.value = translateJSON(openResp.data)
|
||||||
|
|
||||||
// console.log(macroName)
|
|
||||||
|
|
||||||
macroName.value = name
|
macroName.value = name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -224,9 +230,10 @@ export const useMacroRecorderStore = defineStore('macrorecorder', () => {
|
||||||
changeDelay,
|
changeDelay,
|
||||||
toggleEdit,
|
toggleEdit,
|
||||||
resetEdit,
|
resetEdit,
|
||||||
reset,
|
resetMacro,
|
||||||
check,
|
checkMacro,
|
||||||
save,
|
saveMacro,
|
||||||
open,
|
deleteMacro,
|
||||||
|
openMacro,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue