2023-06-05 22:18:48 +00:00
|
|
|
<template>
|
|
|
|
<Transition name="fade">
|
2023-06-07 19:44:16 +00:00
|
|
|
<div>
|
2023-06-14 10:48:29 +00:00
|
|
|
<div class="flex items-center p-1 px-2 mt-1 overflow-hidden transition-all transform rounded cursor-pointer bg-coolgray-200"
|
2023-06-05 22:18:48 +00:00
|
|
|
@click="showCommandPalette = true">
|
2023-06-06 11:48:20 +00:00
|
|
|
<svg xmlns="http://www.w3.org/2000/svg" class="w-6 h-6 icon" viewBox="0 0 24 24" stroke-width="2"
|
|
|
|
stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
|
|
|
|
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
|
|
|
<path d="M10 10m-7 0a7 7 0 1 0 14 0a7 7 0 1 0 -14 0" />
|
|
|
|
<path d="M21 21l-6 -6" />
|
|
|
|
</svg>
|
2023-06-07 08:33:45 +00:00
|
|
|
<span class="ml-2 kbd-custom">/</span>
|
2023-06-05 22:18:48 +00:00
|
|
|
</div>
|
2023-06-06 09:35:50 +00:00
|
|
|
<div class="relative" role="dialog" aria-modal="true" v-if="showCommandPalette" @keyup.esc="resetState">
|
2023-06-07 19:44:16 +00:00
|
|
|
<div class="fixed inset-0 transition-opacity bg-opacity-90 bg-coolgray-100" @click.self="resetState">
|
2023-06-06 11:48:20 +00:00
|
|
|
</div>
|
2023-06-13 08:11:11 +00:00
|
|
|
<div class="fixed inset-0 p-4 mx-auto overflow-y-auto lg:w-[70rem] sm:p-10 md:px-20"
|
2023-06-06 09:35:50 +00:00
|
|
|
@click.self="resetState">
|
2023-06-06 11:48:20 +00:00
|
|
|
<div class="overflow-hidden transition-all transform bg-coolgray-200 ring-1 ring-black ring-opacity-5">
|
2023-06-05 22:18:48 +00:00
|
|
|
<div class="relative">
|
|
|
|
<svg class="absolute w-5 h-5 text-gray-400 pointer-events-none left-3 top-2.5"
|
|
|
|
viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
|
|
|
|
<path fill-rule="evenodd"
|
|
|
|
d="M9 3.5a5.5 5.5 0 100 11 5.5 5.5 0 000-11zM2 9a7 7 0 1112.452 4.391l3.328 3.329a.75.75 0 11-1.06 1.06l-3.329-3.328A7 7 0 012 9z"
|
|
|
|
clip-rule="evenodd" />
|
|
|
|
</svg>
|
2023-06-07 13:08:35 +00:00
|
|
|
<input type="text" v-model="search" ref="searchInput" @keydown.down="focusNext(magic.length)"
|
|
|
|
@keydown.up="focusPrev(magic.length)" @keyup.enter="callAction"
|
2023-06-06 09:35:50 +00:00
|
|
|
class="w-full h-10 pr-4 text-white rounded outline-none bg-coolgray-400 pl-11 placeholder:text-neutral-700 sm:text-sm focus:outline-none"
|
2023-06-06 12:11:11 +00:00
|
|
|
placeholder="Search, jump or create... magically... 🪄" role="combobox"
|
2023-06-06 09:35:50 +00:00
|
|
|
aria-expanded="false" aria-controls="options">
|
2023-06-05 22:18:48 +00:00
|
|
|
</div>
|
2023-06-06 09:35:50 +00:00
|
|
|
|
2023-06-07 19:44:16 +00:00
|
|
|
<ul class="px-4 pb-2 overflow-y-auto max-h-96 scroll-py-10 scroll-pb-2 scrollbar" id="options"
|
|
|
|
role="listbox">
|
2023-06-07 13:08:35 +00:00
|
|
|
<li v-if="sequenceState.sequence.length !== 0">
|
|
|
|
<h2 v-if="sequenceState.sequence[sequenceState.currentActionIndex] && possibleSequences[sequenceState.sequence[sequenceState.currentActionIndex]]"
|
|
|
|
class="mt-4 mb-2 text-xs font-semibold text-neutral-500">{{
|
|
|
|
possibleSequences[sequenceState.sequence[sequenceState.currentActionIndex]].newTitle }}
|
|
|
|
</h2>
|
2023-06-06 09:35:50 +00:00
|
|
|
<ul class="mt-2 -mx-4 text-sm text-white ">
|
|
|
|
<li class="flex items-center px-4 py-2 cursor-pointer select-none group hover:bg-coolgray-400"
|
2023-06-07 13:08:35 +00:00
|
|
|
id="option-1" role="option" tabindex="-1"
|
|
|
|
@click="addNew(sequenceState.sequence[sequenceState.currentActionIndex])">
|
|
|
|
<svg xmlns=" http://www.w3.org/2000/svg" class="w-6 h-6" viewBox="0 0 24 24"
|
2023-06-06 09:35:50 +00:00
|
|
|
stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round"
|
|
|
|
stroke-linejoin="round">
|
|
|
|
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
|
|
|
<path d="M12 5l0 14" />
|
|
|
|
<path d="M5 12l14 0" />
|
|
|
|
</svg>
|
2023-06-07 13:08:35 +00:00
|
|
|
<span class="flex-auto ml-3 truncate">
|
|
|
|
<span v-if="search"><span class="capitalize ">{{
|
|
|
|
sequenceState.sequence[sequenceState.currentActionIndex] }}</span> name
|
|
|
|
will be:
|
|
|
|
<span class="text-warning">{{ search
|
|
|
|
}}</span></span>
|
|
|
|
<span v-else><span class="capitalize ">{{
|
|
|
|
sequenceState.sequence[sequenceState.currentActionIndex] }}</span> name
|
|
|
|
will be:
|
|
|
|
<span class="text-warning">randomly generated (type to change)</span>
|
|
|
|
</span>
|
|
|
|
</span>
|
2023-06-06 09:35:50 +00:00
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</li>
|
2023-06-05 22:18:48 +00:00
|
|
|
<li>
|
2023-06-07 13:08:35 +00:00
|
|
|
<ul v-if="magic.length == 0" class="mt-2 -mx-4 text-sm text-white">
|
2023-06-06 09:35:50 +00:00
|
|
|
<li class="flex items-center px-4 py-2 select-none group">
|
|
|
|
<svg xmlns="http://www.w3.org/2000/svg" class="w-6 h-6 icon" viewBox="0 0 24 24"
|
|
|
|
stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round"
|
|
|
|
stroke-linejoin="round">
|
|
|
|
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
|
|
|
<path d="M12 12m-9 0a9 9 0 1 0 18 0a9 9 0 1 0 -18 0" />
|
|
|
|
<path d="M9 10l.01 0" />
|
|
|
|
<path d="M15 10l.01 0" />
|
|
|
|
<path d="M9 15l6 0" />
|
|
|
|
</svg>
|
|
|
|
<span class="flex-auto ml-3 truncate">Nothing found. Ooops.</span>
|
|
|
|
</li>
|
|
|
|
</ul>
|
2023-06-07 13:08:35 +00:00
|
|
|
<h2 v-if="magic.length !== 0 && sequenceState.sequence[sequenceState.currentActionIndex] && possibleSequences[sequenceState.sequence[sequenceState.currentActionIndex]]"
|
2023-06-06 11:48:20 +00:00
|
|
|
class="mt-4 mb-2 text-xs font-semibold text-neutral-500">{{
|
2023-06-07 13:08:35 +00:00
|
|
|
possibleSequences[sequenceState.sequence[sequenceState.currentActionIndex]].title }}
|
2023-06-06 09:35:50 +00:00
|
|
|
</h2>
|
2023-06-07 13:08:35 +00:00
|
|
|
<ul v-if="magic.length != 0" class="mt-2 -mx-4 text-sm text-white">
|
|
|
|
<li class="flex items-center px-4 py-2 transition-all cursor-pointer select-none group hover:bg-coolgray-400"
|
2023-06-07 15:11:21 +00:00
|
|
|
:class="{ 'bg-coollabs': currentFocus === index }" id="option-1" role="option"
|
2023-06-08 06:18:14 +00:00
|
|
|
tabindex="-1" v-for="action, index in magic" @click="goThroughSequence(index)"
|
|
|
|
ref="magicItems">
|
2023-06-07 13:08:35 +00:00
|
|
|
<div class="relative">
|
|
|
|
<svg xmlns="http://www.w3.org/2000/svg" class="w-6 h-6 icon" viewBox="0 0 24 24"
|
|
|
|
stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round"
|
|
|
|
stroke-linejoin="round">
|
|
|
|
<template
|
|
|
|
v-if="action.icon === 'git' || sequenceState.sequence[sequenceState.currentActionIndex] === 'git'">
|
|
|
|
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
|
|
|
<path d="M16 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0" />
|
|
|
|
<path d="M12 8m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0" />
|
|
|
|
<path d="M12 16m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0" />
|
|
|
|
<path d="M12 15v-6" />
|
|
|
|
<path d="M15 11l-2 -2" />
|
|
|
|
<path d="M11 7l-1.9 -1.9" />
|
|
|
|
<path
|
|
|
|
d="M13.446 2.6l7.955 7.954a2.045 2.045 0 0 1 0 2.892l-7.955 7.955a2.045 2.045 0 0 1 -2.892 0l-7.955 -7.955a2.045 2.045 0 0 1 0 -2.892l7.955 -7.955a2.045 2.045 0 0 1 2.892 0z" />
|
|
|
|
</template>
|
|
|
|
<template
|
|
|
|
v-if="action.icon === 'server' || sequenceState.sequence[sequenceState.currentActionIndex] === 'server'">
|
|
|
|
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
|
|
|
<path
|
|
|
|
d="M3 4m0 3a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v2a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3z" />
|
|
|
|
<path d="M15 20h-9a3 3 0 0 1 -3 -3v-2a3 3 0 0 1 3 -3h12" />
|
|
|
|
<path d="M7 8v.01" />
|
|
|
|
<path d="M7 16v.01" />
|
|
|
|
<path d="M20 15l-2 3h3l-2 3" />
|
|
|
|
</template>
|
|
|
|
<template
|
|
|
|
v-if="action.icon === 'destination' || sequenceState.sequence[sequenceState.currentActionIndex] === 'destination'">
|
|
|
|
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
|
|
|
<path
|
|
|
|
d="M22 12.54c-1.804 -.345 -2.701 -1.08 -3.523 -2.94c-.487 .696 -1.102 1.568 -.92 2.4c.028 .238 -.32 1 -.557 1h-14c0 5.208 3.164 7 6.196 7c4.124 .022 7.828 -1.376 9.854 -5c1.146 -.101 2.296 -1.505 2.95 -2.46z" />
|
|
|
|
<path d="M5 10h3v3h-3z" />
|
|
|
|
<path d="M8 10h3v3h-3z" />
|
|
|
|
<path d="M11 10h3v3h-3z" />
|
|
|
|
<path d="M8 7h3v3h-3z" />
|
|
|
|
<path d="M11 7h3v3h-3z" />
|
|
|
|
<path d="M11 4h3v3h-3z" />
|
|
|
|
<path d="M4.571 18c1.5 0 2.047 -.074 2.958 -.78" />
|
|
|
|
<path d="M10 16l0 .01" />
|
|
|
|
</template>
|
|
|
|
<template
|
|
|
|
v-if="action.icon === 'project' || sequenceState.sequence[sequenceState.currentActionIndex] === 'project'">
|
|
|
|
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
|
|
|
<path
|
|
|
|
d="M9 4h3l2 2h5a2 2 0 0 1 2 2v7a2 2 0 0 1 -2 2h-10a2 2 0 0 1 -2 -2v-9a2 2 0 0 1 2 -2" />
|
|
|
|
<path
|
|
|
|
d="M17 17v2a2 2 0 0 1 -2 2h-10a2 2 0 0 1 -2 -2v-9a2 2 0 0 1 2 -2h2" />
|
|
|
|
</template>
|
|
|
|
<template
|
|
|
|
v-if="action.icon === 'environment' || sequenceState.sequence[sequenceState.currentActionIndex] === 'environment'">
|
|
|
|
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
|
|
|
<path d="M16 5l3 3l-2 1l4 4l-3 1l4 4h-9" />
|
|
|
|
<path d="M15 21l0 -3" />
|
|
|
|
<path d="M8 13l-2 -2" />
|
|
|
|
<path d="M8 12l2 -2" />
|
|
|
|
<path d="M8 21v-13" />
|
|
|
|
<path
|
|
|
|
d="M5.824 16a3 3 0 0 1 -2.743 -3.69a3 3 0 0 1 .304 -4.833a3 3 0 0 1 4.615 -3.707a3 3 0 0 1 4.614 3.707a3 3 0 0 1 .305 4.833a3 3 0 0 1 -2.919 3.695h-4z" />
|
|
|
|
</template>
|
|
|
|
<template
|
|
|
|
v-if="action.icon === 'key' || sequenceState.sequence[sequenceState.currentActionIndex] === 'key'">
|
|
|
|
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
|
|
|
<path d="M14 10m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0" />
|
|
|
|
<path d="M21 12a9 9 0 1 1 -18 0a9 9 0 0 1 18 0z" />
|
|
|
|
<path d="M12.5 11.5l-4 4l1.5 1.5" />
|
|
|
|
<path d="M12 15l-1.5 -1.5" />
|
|
|
|
</template>
|
|
|
|
<template
|
|
|
|
v-if="action.icon === 'goto' || sequenceState.sequence[sequenceState.currentActionIndex] === 'goto'">
|
|
|
|
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
|
|
|
<path d="M10 18h4" />
|
|
|
|
<path
|
|
|
|
d="M3 8a9 9 0 0 1 9 9v1l1.428 -4.285a12 12 0 0 1 6.018 -6.938l.554 -.277" />
|
|
|
|
<path d="M15 6h5v5" />
|
|
|
|
</template>
|
|
|
|
</svg>
|
|
|
|
<div v-if="action.new"
|
|
|
|
class="absolute top-0 right-0 -mt-2 -mr-2 font-bold text-warning">+
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-06-05 22:18:48 +00:00
|
|
|
<span class="flex-auto ml-3 truncate">{{ action.name }}</span>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Transition>
|
|
|
|
</template>
|
|
|
|
<script setup>
|
2023-06-06 11:48:20 +00:00
|
|
|
import { ref, computed, onMounted, onUnmounted, watch, nextTick } from 'vue'
|
2023-06-05 22:18:48 +00:00
|
|
|
import axios from "axios";
|
2023-06-07 13:14:49 +00:00
|
|
|
const currentFocus = ref(0)
|
2023-06-08 06:18:14 +00:00
|
|
|
const magicItems = ref()
|
2023-06-07 13:08:35 +00:00
|
|
|
function focusNext(length) {
|
|
|
|
if (currentFocus.value === undefined) {
|
|
|
|
currentFocus.value = 0
|
|
|
|
} else {
|
|
|
|
if (length > currentFocus.value + 1) {
|
|
|
|
currentFocus.value = currentFocus.value + 1
|
|
|
|
}
|
|
|
|
}
|
2023-06-08 06:18:14 +00:00
|
|
|
if (currentFocus.value > 4) {
|
|
|
|
magicItems.value[currentFocus.value].scrollIntoView({ block: "center", inline: "center", behavior: 'auto' })
|
|
|
|
}
|
2023-06-07 13:08:35 +00:00
|
|
|
}
|
|
|
|
function focusPrev(length) {
|
|
|
|
if (currentFocus.value === undefined) {
|
|
|
|
currentFocus.value = length - 1
|
|
|
|
} else {
|
|
|
|
if (currentFocus.value > 0) {
|
|
|
|
currentFocus.value = currentFocus.value - 1
|
|
|
|
}
|
|
|
|
}
|
2023-06-08 06:18:14 +00:00
|
|
|
if (currentFocus.value < length - 4) {
|
|
|
|
magicItems.value[currentFocus.value].scrollIntoView({ block: "center", inline: "center", behavior: 'auto' })
|
|
|
|
}
|
2023-06-07 13:08:35 +00:00
|
|
|
}
|
|
|
|
async function callAction() {
|
|
|
|
await goThroughSequence(currentFocus.value)
|
|
|
|
}
|
2023-06-05 22:18:48 +00:00
|
|
|
const showCommandPalette = ref(false)
|
2023-06-06 09:35:50 +00:00
|
|
|
const search = ref()
|
|
|
|
const searchInput = ref()
|
2023-06-07 13:08:35 +00:00
|
|
|
|
2023-06-06 09:35:50 +00:00
|
|
|
const baseUrl = '/magic'
|
2023-06-05 22:18:48 +00:00
|
|
|
|
2023-06-07 13:08:35 +00:00
|
|
|
const uuidSelector = ['project', 'destination']
|
|
|
|
const nameSelector = ['environment']
|
|
|
|
const possibleSequences = {
|
|
|
|
server: {
|
2023-06-07 15:11:21 +00:00
|
|
|
newTitle: 'Create a new Server',
|
2023-06-07 13:08:35 +00:00
|
|
|
title: 'Select a server'
|
|
|
|
},
|
|
|
|
destination: {
|
2023-06-07 15:11:21 +00:00
|
|
|
newTitle: 'Create a new Destination',
|
2023-06-07 13:08:35 +00:00
|
|
|
title: 'Select a destination'
|
|
|
|
},
|
|
|
|
project: {
|
2023-06-07 15:11:21 +00:00
|
|
|
newTitle: 'Create a new Project',
|
2023-06-07 13:08:35 +00:00
|
|
|
title: 'Select a project'
|
|
|
|
},
|
|
|
|
environment: {
|
2023-06-07 15:11:21 +00:00
|
|
|
newTitle: 'Create a new Environment',
|
2023-06-07 13:08:35 +00:00
|
|
|
title: 'Select an environment'
|
|
|
|
},
|
|
|
|
}
|
|
|
|
const magicActions = [{
|
2023-06-12 20:09:43 +00:00
|
|
|
id: 1,
|
2023-06-07 14:47:10 +00:00
|
|
|
name: 'Deploy: Public Repository',
|
2023-06-07 13:08:35 +00:00
|
|
|
tags: 'git,github,public',
|
2023-06-05 22:18:48 +00:00
|
|
|
icon: 'git',
|
2023-06-07 13:08:35 +00:00
|
|
|
new: true,
|
|
|
|
sequence: ['main', 'server', 'destination', 'project', 'environment', 'redirect']
|
2023-06-05 22:18:48 +00:00
|
|
|
},
|
|
|
|
{
|
2023-06-12 20:09:43 +00:00
|
|
|
id: 2,
|
2023-06-07 14:47:10 +00:00
|
|
|
name: 'Deploy: Private Repository (with GitHub Apps)',
|
2023-06-07 13:08:35 +00:00
|
|
|
tags: 'git,github,private',
|
2023-06-05 22:18:48 +00:00
|
|
|
icon: 'git',
|
2023-06-07 13:08:35 +00:00
|
|
|
new: true,
|
|
|
|
sequence: ['main', 'server', 'destination', 'project', 'environment', 'redirect']
|
2023-06-05 22:18:48 +00:00
|
|
|
},
|
|
|
|
{
|
2023-06-12 20:09:43 +00:00
|
|
|
id: 3,
|
2023-06-07 14:47:10 +00:00
|
|
|
name: 'Deploy: Private Repository (with Deploy Key)',
|
2023-06-07 13:08:35 +00:00
|
|
|
tags: 'git,github,private,deploy,key',
|
2023-06-05 22:18:48 +00:00
|
|
|
icon: 'git',
|
2023-06-07 13:08:35 +00:00
|
|
|
new: true,
|
|
|
|
sequence: ['main', 'server', 'destination', 'project', 'environment', 'redirect']
|
|
|
|
},
|
|
|
|
{
|
2023-06-12 20:09:43 +00:00
|
|
|
id: 4,
|
2023-06-12 20:02:10 +00:00
|
|
|
name: 'Create: Server',
|
|
|
|
tags: 'server,ssh,new,create',
|
|
|
|
icon: 'server',
|
2023-06-07 13:08:35 +00:00
|
|
|
new: true,
|
|
|
|
sequence: ['main', 'redirect']
|
|
|
|
},
|
|
|
|
{
|
2023-06-12 20:09:43 +00:00
|
|
|
id: 5,
|
2023-06-12 20:02:10 +00:00
|
|
|
name: 'Create: Source',
|
|
|
|
tags: 'source,git,gitlab,github,bitbucket,gitea,new,create',
|
|
|
|
icon: 'git',
|
|
|
|
new: true,
|
|
|
|
sequence: ['main', 'redirect']
|
|
|
|
},
|
|
|
|
{
|
2023-06-12 20:09:43 +00:00
|
|
|
id: 6,
|
2023-06-12 20:02:10 +00:00
|
|
|
name: 'Create: Private Key',
|
|
|
|
tags: 'private,key,ssh,new,create',
|
|
|
|
icon: 'key',
|
2023-06-07 13:08:35 +00:00
|
|
|
new: true,
|
|
|
|
sequence: ['main', 'redirect']
|
|
|
|
},
|
|
|
|
{
|
2023-06-12 20:09:43 +00:00
|
|
|
id: 7,
|
2023-06-07 14:47:10 +00:00
|
|
|
name: 'Create: Destination',
|
2023-06-07 13:08:35 +00:00
|
|
|
tags: 'destination,docker,network,new,create',
|
|
|
|
icon: 'destination',
|
|
|
|
new: true,
|
|
|
|
sequence: ['main', 'server', 'redirect']
|
|
|
|
},
|
|
|
|
{
|
2023-06-12 20:09:43 +00:00
|
|
|
id: 8,
|
2023-06-07 14:47:10 +00:00
|
|
|
name: 'Goto: Dashboard',
|
2023-06-07 13:08:35 +00:00
|
|
|
icon: 'goto',
|
|
|
|
sequence: ['main', 'redirect']
|
|
|
|
},
|
|
|
|
{
|
2023-06-12 20:09:43 +00:00
|
|
|
id: 9,
|
2023-06-07 14:47:10 +00:00
|
|
|
name: 'Goto: Servers',
|
2023-06-07 13:08:35 +00:00
|
|
|
icon: 'goto',
|
|
|
|
sequence: ['main', 'redirect']
|
|
|
|
},
|
|
|
|
{
|
2023-06-12 20:09:43 +00:00
|
|
|
id: 10,
|
2023-06-15 07:58:17 +00:00
|
|
|
name: 'Goto: Private Keys',
|
2023-06-15 13:46:19 +00:00
|
|
|
tags: 'destination,docker,network,new,create',
|
2023-06-07 13:08:35 +00:00
|
|
|
icon: 'goto',
|
|
|
|
sequence: ['main', 'redirect']
|
|
|
|
},
|
|
|
|
{
|
2023-06-12 20:09:43 +00:00
|
|
|
id: 11,
|
2023-06-15 07:58:17 +00:00
|
|
|
name: 'Goto: Projects',
|
2023-06-12 20:09:43 +00:00
|
|
|
icon: 'goto',
|
|
|
|
sequence: ['main', 'redirect']
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 12,
|
2023-06-15 07:58:17 +00:00
|
|
|
name: 'Goto: Sources',
|
2023-06-07 13:08:35 +00:00
|
|
|
icon: 'goto',
|
|
|
|
sequence: ['main', 'redirect']
|
|
|
|
},
|
|
|
|
{
|
2023-06-12 20:09:43 +00:00
|
|
|
id: 13,
|
2023-06-15 07:58:17 +00:00
|
|
|
name: 'Goto: Destinations',
|
2023-06-07 13:08:35 +00:00
|
|
|
icon: 'goto',
|
|
|
|
sequence: ['main', 'redirect']
|
2023-06-07 15:32:59 +00:00
|
|
|
},
|
|
|
|
{
|
2023-06-12 20:09:43 +00:00
|
|
|
id: 14,
|
2023-06-15 07:58:17 +00:00
|
|
|
name: 'Goto: Settings',
|
2023-06-07 15:32:59 +00:00
|
|
|
icon: 'goto',
|
|
|
|
sequence: ['main', 'redirect']
|
|
|
|
},
|
|
|
|
{
|
2023-06-12 20:09:43 +00:00
|
|
|
id: 15,
|
2023-06-15 07:58:17 +00:00
|
|
|
name: 'Goto: Command Center',
|
2023-06-07 15:32:59 +00:00
|
|
|
icon: 'goto',
|
|
|
|
sequence: ['main', 'redirect']
|
|
|
|
},
|
|
|
|
{
|
2023-06-12 20:09:43 +00:00
|
|
|
id: 16,
|
2023-06-15 07:58:17 +00:00
|
|
|
name: 'Goto: Notifications',
|
2023-06-07 15:32:59 +00:00
|
|
|
icon: 'goto',
|
|
|
|
sequence: ['main', 'redirect']
|
|
|
|
},
|
|
|
|
{
|
2023-06-12 20:09:43 +00:00
|
|
|
id: 17,
|
2023-06-15 07:58:17 +00:00
|
|
|
name: 'Goto: Profile',
|
2023-06-13 08:02:58 +00:00
|
|
|
icon: 'goto',
|
|
|
|
sequence: ['main', 'redirect']
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 18,
|
2023-06-15 07:58:17 +00:00
|
|
|
name: 'Goto: Teams',
|
|
|
|
icon: 'goto',
|
|
|
|
sequence: ['main', 'redirect']
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 19,
|
2023-06-07 15:32:59 +00:00
|
|
|
name: 'Goto: Switch Teams',
|
|
|
|
icon: 'goto',
|
|
|
|
sequence: ['main', 'redirect']
|
2023-06-06 12:11:11 +00:00
|
|
|
}
|
|
|
|
]
|
2023-06-06 09:35:50 +00:00
|
|
|
const initialState = {
|
2023-06-07 13:08:35 +00:00
|
|
|
sequence: [],
|
|
|
|
currentActionIndex: 0,
|
|
|
|
magicActions,
|
|
|
|
selected: {}
|
2023-06-06 09:35:50 +00:00
|
|
|
}
|
2023-06-07 13:08:35 +00:00
|
|
|
const sequenceState = ref({ ...initialState })
|
2023-06-06 11:48:20 +00:00
|
|
|
|
|
|
|
function focusSearch(event) {
|
|
|
|
if (event.target.nodeName === 'BODY') {
|
|
|
|
if (event.key === '/') {
|
|
|
|
event.preventDefault();
|
|
|
|
showCommandPalette.value = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
window.addEventListener("keydown", focusSearch);
|
|
|
|
})
|
|
|
|
onUnmounted(() => {
|
|
|
|
window.removeEventListener("keydown", focusSearch);
|
|
|
|
})
|
|
|
|
|
|
|
|
watch(showCommandPalette, async (value) => {
|
|
|
|
if (value) {
|
|
|
|
await nextTick();
|
|
|
|
searchInput.value.focus();
|
|
|
|
}
|
|
|
|
})
|
2023-06-07 13:14:49 +00:00
|
|
|
watch(search, async () => {
|
|
|
|
currentFocus.value = 0
|
|
|
|
})
|
2023-06-07 13:08:35 +00:00
|
|
|
const magic = computed(() => {
|
|
|
|
if (search.value) {
|
|
|
|
return sequenceState.value.magicActions.filter(action => {
|
|
|
|
return action.name.toLowerCase().includes(search.value.toLowerCase()) || action.tags?.toLowerCase().includes(search.value.toLowerCase())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return sequenceState.value.magicActions
|
|
|
|
})
|
|
|
|
async function addNew(name) {
|
|
|
|
let targetUrl = new URL(window.location.origin)
|
|
|
|
let newUrl = new URL(`${window.location.origin}${baseUrl}/${name}/new`);
|
|
|
|
if (search.value) {
|
|
|
|
targetUrl.searchParams.append('name', search.value)
|
|
|
|
newUrl.searchParams.append('name', search.value)
|
|
|
|
}
|
|
|
|
switch (name) {
|
|
|
|
case 'server':
|
|
|
|
targetUrl.pathname = '/server/new'
|
|
|
|
window.location.href = targetUrl.href
|
|
|
|
break;
|
|
|
|
case 'destination':
|
|
|
|
targetUrl.pathname = '/destination/new'
|
|
|
|
window.location.href = targetUrl.href
|
|
|
|
break;
|
|
|
|
case 'project':
|
|
|
|
const { data: { project_uuid } } = await axios(newUrl.href)
|
|
|
|
search.value = ''
|
|
|
|
sequenceState.value.selected['project'] = project_uuid
|
|
|
|
sequenceState.value.magicActions = await getEnvironments(project_uuid)
|
|
|
|
sequenceState.value.currentActionIndex += 1
|
|
|
|
break;
|
|
|
|
case 'environment':
|
|
|
|
newUrl.searchParams.append('project_uuid', sequenceState.value.selected.project)
|
|
|
|
const { data: { environment_name } } = await axios(newUrl.href)
|
|
|
|
search.value = ''
|
|
|
|
sequenceState.value.selected['environment'] = environment_name
|
|
|
|
redirect()
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2023-06-06 09:35:50 +00:00
|
|
|
function resetState() {
|
|
|
|
showCommandPalette.value = false
|
2023-06-07 13:08:35 +00:00
|
|
|
sequenceState.value = { ...initialState }
|
2023-06-06 12:11:11 +00:00
|
|
|
search.value = ''
|
2023-06-06 09:35:50 +00:00
|
|
|
}
|
2023-06-07 13:08:35 +00:00
|
|
|
async function goThroughSequence(actionId) {
|
|
|
|
let currentSequence = null;
|
|
|
|
let nextSequence = null;
|
|
|
|
if (sequenceState.value.selected.main === undefined) {
|
|
|
|
const { sequence, id } = magic.value[actionId];
|
|
|
|
currentSequence = sequence[sequenceState.value.currentActionIndex]
|
|
|
|
nextSequence = sequence[sequenceState.value.currentActionIndex + 1]
|
|
|
|
sequenceState.value.sequence = sequence
|
|
|
|
sequenceState.value.selected = {
|
2023-06-12 20:09:43 +00:00
|
|
|
main: id
|
2023-06-06 09:35:50 +00:00
|
|
|
}
|
|
|
|
} else {
|
2023-06-07 13:08:35 +00:00
|
|
|
currentSequence = sequenceState.value.sequence[sequenceState.value.currentActionIndex]
|
|
|
|
nextSequence = sequenceState.value.sequence[sequenceState.value.currentActionIndex + 1]
|
2023-06-12 20:09:43 +00:00
|
|
|
let selectedId = sequenceState.value.magicActions[actionId].id
|
2023-06-07 13:08:35 +00:00
|
|
|
if (uuidSelector.includes(currentSequence)) {
|
|
|
|
selectedId = sequenceState.value.magicActions[actionId].uuid
|
|
|
|
}
|
|
|
|
if (nameSelector.includes(currentSequence)) {
|
|
|
|
selectedId = sequenceState.value.magicActions[actionId].name
|
2023-06-06 09:35:50 +00:00
|
|
|
}
|
2023-06-07 13:08:35 +00:00
|
|
|
sequenceState.value.selected = {
|
|
|
|
...sequenceState.value.selected,
|
|
|
|
[currentSequence]: selectedId
|
2023-06-06 09:35:50 +00:00
|
|
|
}
|
|
|
|
}
|
2023-06-07 13:08:35 +00:00
|
|
|
switch (nextSequence) {
|
|
|
|
case 'server':
|
|
|
|
sequenceState.value.magicActions = await getServers();
|
|
|
|
break;
|
|
|
|
case 'destination':
|
|
|
|
sequenceState.value.magicActions = await getDestinations(sequenceState.value.selected[currentSequence]);
|
|
|
|
break;
|
|
|
|
case 'project':
|
|
|
|
sequenceState.value.magicActions = await getProjects()
|
|
|
|
break;
|
|
|
|
case 'environment':
|
|
|
|
sequenceState.value.magicActions = await getEnvironments(sequenceState.value.selected[currentSequence])
|
|
|
|
break;
|
|
|
|
case 'redirect':
|
|
|
|
redirect()
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sequenceState.value.currentActionIndex += 1
|
2023-06-06 09:35:50 +00:00
|
|
|
search.value = ''
|
|
|
|
searchInput.value.focus()
|
2023-06-07 15:11:21 +00:00
|
|
|
currentFocus.value = 0
|
2023-06-06 09:35:50 +00:00
|
|
|
}
|
2023-06-07 13:08:35 +00:00
|
|
|
async function getServers() {
|
|
|
|
const { data: { servers } } = await axios.get(`${baseUrl}/servers`);
|
|
|
|
return servers;
|
|
|
|
}
|
|
|
|
async function getDestinations(serverId) {
|
|
|
|
const { data: { destinations } } = await axios.get(`${baseUrl}/destinations?server_id=${serverId}`);
|
|
|
|
return destinations;
|
|
|
|
}
|
|
|
|
async function getProjects() {
|
|
|
|
const { data: { projects } } = await axios.get(`${baseUrl}/projects`);
|
|
|
|
return projects;
|
|
|
|
}
|
|
|
|
async function getEnvironments(project_uuid) {
|
|
|
|
const { data: { environments } } = await axios.get(`${baseUrl}/environments?project_uuid=${project_uuid}`);
|
|
|
|
return environments;
|
|
|
|
}
|
2023-06-05 22:18:48 +00:00
|
|
|
|
2023-06-06 09:35:50 +00:00
|
|
|
async function redirect() {
|
|
|
|
let targetUrl = new URL(window.location.origin)
|
2023-06-07 13:08:35 +00:00
|
|
|
const selected = sequenceState.value.selected
|
|
|
|
const { main, destination = null, project = null, environment = null, server = null } = selected
|
|
|
|
switch (main) {
|
2023-06-12 20:02:10 +00:00
|
|
|
case 1:
|
2023-06-07 13:08:35 +00:00
|
|
|
targetUrl.pathname = `/project/${project}/${environment}/new`
|
2023-06-06 09:35:50 +00:00
|
|
|
targetUrl.searchParams.append('type', 'public')
|
2023-06-07 13:08:35 +00:00
|
|
|
targetUrl.searchParams.append('destination', destination)
|
2023-06-05 22:18:48 +00:00
|
|
|
break;
|
2023-06-12 20:02:10 +00:00
|
|
|
case 2:
|
2023-06-07 13:08:35 +00:00
|
|
|
targetUrl.pathname = `/project/${project}/${environment}/new`
|
2023-06-06 09:35:50 +00:00
|
|
|
targetUrl.searchParams.append('type', 'private-gh-app')
|
2023-06-07 13:08:35 +00:00
|
|
|
targetUrl.searchParams.append('destination', destination)
|
2023-06-05 22:18:48 +00:00
|
|
|
break;
|
2023-06-12 20:02:10 +00:00
|
|
|
case 3:
|
2023-06-07 13:08:35 +00:00
|
|
|
targetUrl.pathname = `/project/${project}/${environment}/new`
|
2023-06-06 09:35:50 +00:00
|
|
|
targetUrl.searchParams.append('type', 'private-deploy-key')
|
2023-06-07 13:08:35 +00:00
|
|
|
targetUrl.searchParams.append('destination', destination)
|
2023-06-05 22:18:48 +00:00
|
|
|
break;
|
2023-06-07 13:08:35 +00:00
|
|
|
case 4:
|
2023-06-07 14:47:10 +00:00
|
|
|
targetUrl.pathname = `/server/new`
|
2023-06-07 13:08:35 +00:00
|
|
|
break;
|
|
|
|
case 5:
|
2023-06-12 20:02:10 +00:00
|
|
|
targetUrl.pathname = `/source/new`
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
targetUrl.pathname = `/private-key/new`
|
|
|
|
break;
|
|
|
|
case 7:
|
2023-06-07 14:47:10 +00:00
|
|
|
targetUrl.pathname = `/destination/new`
|
2023-06-07 13:08:35 +00:00
|
|
|
targetUrl.searchParams.append('server', server)
|
|
|
|
break;
|
2023-06-12 20:02:10 +00:00
|
|
|
case 8:
|
2023-06-07 13:08:35 +00:00
|
|
|
targetUrl.pathname = `/`
|
|
|
|
break;
|
2023-06-12 20:02:10 +00:00
|
|
|
case 9:
|
2023-06-07 13:08:35 +00:00
|
|
|
targetUrl.pathname = `/servers`
|
|
|
|
break;
|
2023-06-12 20:02:10 +00:00
|
|
|
case 10:
|
2023-06-15 07:58:17 +00:00
|
|
|
targetUrl.pathname = `/private-keys`
|
2023-06-06 12:11:11 +00:00
|
|
|
break;
|
2023-06-12 20:02:10 +00:00
|
|
|
case 11:
|
2023-06-15 07:58:17 +00:00
|
|
|
targetUrl.pathname = `/projects`
|
2023-06-07 13:08:35 +00:00
|
|
|
break;
|
2023-06-12 20:02:10 +00:00
|
|
|
case 12:
|
2023-06-15 07:58:17 +00:00
|
|
|
targetUrl.pathname = `/sources`
|
2023-06-07 13:08:35 +00:00
|
|
|
break;
|
2023-06-12 20:02:10 +00:00
|
|
|
case 13:
|
2023-06-15 07:58:17 +00:00
|
|
|
targetUrl.pathname = `/destinations`
|
2023-06-07 15:32:59 +00:00
|
|
|
break;
|
2023-06-12 20:02:10 +00:00
|
|
|
case 14:
|
2023-06-15 07:58:17 +00:00
|
|
|
targetUrl.pathname = `/settings`
|
2023-06-07 15:32:59 +00:00
|
|
|
break;
|
2023-06-12 20:02:10 +00:00
|
|
|
case 15:
|
2023-06-15 07:58:17 +00:00
|
|
|
targetUrl.pathname = `/command-center`
|
2023-06-07 15:32:59 +00:00
|
|
|
break;
|
2023-06-12 20:02:10 +00:00
|
|
|
case 16:
|
2023-06-15 07:58:17 +00:00
|
|
|
targetUrl.pathname = `/profile/team/notifications`
|
2023-06-07 15:32:59 +00:00
|
|
|
break;
|
2023-06-12 20:09:43 +00:00
|
|
|
case 17:
|
2023-06-15 07:58:17 +00:00
|
|
|
targetUrl.pathname = `/profile`
|
2023-06-12 20:09:43 +00:00
|
|
|
break;
|
2023-06-13 08:02:58 +00:00
|
|
|
case 18:
|
|
|
|
targetUrl.pathname = `/profile/team`
|
|
|
|
break;
|
2023-06-15 07:58:17 +00:00
|
|
|
case 19:
|
|
|
|
targetUrl.pathname = `/profile/team`
|
|
|
|
break;
|
2023-06-05 22:18:48 +00:00
|
|
|
}
|
2023-06-06 12:11:11 +00:00
|
|
|
window.location.href = targetUrl;
|
2023-06-05 22:18:48 +00:00
|
|
|
}
|
|
|
|
</script>
|