Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: request body params #98

Merged
merged 3 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 58 additions & 13 deletions frontend/src/components/Http/CodeEditor.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts" setup>
import { watch, ref, onMounted } from 'vue'

import { DocumentDuplicateIcon, SparklesIcon } from '@heroicons/vue/24/outline'
import { DocumentDuplicateIcon, SparklesIcon, ArrowPathRoundedSquareIcon } from '@heroicons/vue/24/outline'
import { HighlightHTTP, HighlightBody, FormatCode } from '../../../wailsjs/go/backend/App'
import { ClipboardSetText } from '../../../wailsjs/runtime'

Expand Down Expand Up @@ -104,27 +104,72 @@ function formatCode() {
updateCode()
})
}

function encodeParams(rawParams: string) {
const lines = rawParams.split('\n')
const params = lines.map((line: string) => {
const [key, value] = line.split(': ').map(str => str.trim())
return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`
})
buffer.value = params.join('&')
}

function decodeParams(encodedParams: string) {
const params = new URLSearchParams(encodedParams)
let result = ''
params.forEach((value, key) => {
result += `${key}: ${value}\n`
})
buffer.value = result.trim()
}

function transformCode() {
const input = buffer.value.trim()

// presence of & or = means it's an encoded string
if (input.includes('&') || input.includes('=')) {
decodeParams(input)
} else {
encodeParams(input)
}
updateCode()
}
</script>

<template>
<div class="absolute flex h-7 w-full border border-polar-night-3">
<button class="rounded px-1 text-snow-storm-1/70 hover:bg-polar-night-3 hover:text-snow-storm-1"
@click="copyToClipboard">
<DocumentDuplicateIcon class="h-6 w-6" aria-hidden="true"/>
<DocumentDuplicateIcon class="h-6 w-6"
aria-hidden="true" />
</button>
<button class="rounded px-1 text-snow-storm-1/70 hover:bg-polar-night-3 hover:text-snow-storm-1"
@click="formatCode">
<SparklesIcon class="h-6 w-6" aria-hidden="true"/>
<SparklesIcon class="h-6 w-6" aria-hidden="true" />
</button>
<button class="rounded px-1 text-snow-storm-1/70 hover:bg-polar-night-3 hover:text-snow-storm-1"
@click="transformCode">
<ArrowPathRoundedSquareIcon class="h-6 w-6"
aria-hidden="true" />
</button>
</div>
<div class="h-full w-full border border-polar-night-3 px-1 pt-9">
<div style="min-height: 100px;" :class="[
'wrapper h-full w-full overflow-x-auto',
busy ? 'wrapper plain text-left' : 'wrapper highlighted min-h-full text-left',
]">
<pre ref="pre" class="h-full min-h-full w-full" aria-hidden="true"><code v-html="highlighted"></code></pre>
<textarea class="h-full w-full" :readonly="readonly" spellcheck="false" ref="textarea" @input="updateCode"
@scroll="syncScroll" @keydown="onKeydown" v-model="buffer"></textarea>
<div class="h-full w-full border border-polar-night-3 bg-neutral-800/50 p-8 px-1 pb-2">
<div style="min-height: 100px;"
:class="[
'wrapper h-full w-full overflow-x-auto',
busy ? 'wrapper plain text-left' : 'wrapper highlighted min-h-full text-left',
]">
<pre ref="pre"
class="h-full min-h-full w-full"
aria-hidden="true"><code v-html="highlighted"></code></pre>
<textarea class="h-full w-full"
:readonly="readonly"
spellcheck="false"
ref="textarea"
@input="updateCode"
@scroll="syncScroll"
@keydown="onKeydown"
v-model="buffer"></textarea>
</div>
</div>
</template>
Expand Down Expand Up @@ -160,9 +205,9 @@ pre {

textarea,
code {
font-size: 1.05em !important;
font-size: 0.9em !important;
font-family: monospace !important;
line-height: 1.2em !important;
line-height: 1.5em !important;
tab-size: 2;
word-spacing: 0;
letter-spacing: 0;
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/components/Shared/ScrollingOutput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ onMounted(scrollToBottom)

<template>
<div class="h-full bg-black p-1">
<pre ref="terminal" class="h-full overflow-auto whitespace-pre-wrap text-xs">
<pre ref="terminal"
class="h-full overflow-auto whitespace-pre-wrap text-xs"><code><template v-for="line in lines">{{ line }}</template></code></pre>
<pre ref="terminal"
class="h-full overflow-auto whitespace-pre-wrap text-xs">
<code>
<template v-for="line in lines">{{ line }}</template>
</code>
Expand Down
16 changes: 8 additions & 8 deletions frontend/src/components/Workflow/WorkflowEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -639,13 +639,13 @@ function trackMover(id: string, el: any) {
:style="getPosition(node.id, i)"
draggable="true" @mousedown="dragStart(node.id, $event)"
>
<div class="flex items-center">
<div class="flex items-center text-sm">
<div class="flex-shrink">
<div @mousedown.prevent.stop="startLinkFromInput(node.id, input.name)"
v-for="input in node.vars?.inputs?.filter((inp) => inp.linkable)"
:key="input.name"
class="group my-0 flex items-center py-0 pr-2 leading-4">
<div class="mr-2 flex-grow text-right opacity-60">
<div id="input-label" class="mr-2 flex-grow text-right font-medium text-green-300 opacity-60">
{{ input.name }}
</div>
<div :data-node="node.id" :data-connector="input.name"
Expand Down Expand Up @@ -688,15 +688,15 @@ function trackMover(id: string, el: any) {
</div>
</div>
</div>
<div class="flex-shrink">
<div class="flex-shrink text-sm">
<div @mousedown.prevent.stop="startLinkFromOutput(node.id, output.name)"
v-for="output in node.vars?.outputs"
:key="output.name"
class="group my-0 flex items-center py-0 pl-2 leading-4">
<div :data-node="node.id" :data-connector="output.name"
class="connector output h-2 w-2 flex-shrink rounded-full border border-frost group-hover:border-4">
</div>
<div class="ml-2 flex-grow text-right opacity-60">
<div id="output-label" class="ml-2 flex-grow text-left text-fuchsia-300 opacity-60">
{{ output.name }}
</div>

Expand Down Expand Up @@ -791,10 +791,10 @@ function trackMover(id: string, el: any) {
.stripy {
background: repeating-linear-gradient(
45deg,
#242933,
#242933 10px,
#212630 10px,
#212630 20px
#222,
#222 10px,
#232323 10px,
#232323 20px
);
}
</style>
2 changes: 1 addition & 1 deletion frontend/src/components/Workflow/WorkflowGUI.vue
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function exportWorkflow(id: string) {

<InputBox v-if="creating" title="New Workflow" message="Enter the workflow name." @cancel="creating = false"
@confirm="addWorkflow($event)"/>
<div ref="leftPanel" class="box-border h-full w-64 shrink overflow-y-auto pr-2 text-right">
<div ref="leftPanel" class="box-border h-full w-48 shrink overflow-y-auto pr-2 text-right">
<button type="button" @click="creating = true"
class="mb-1 rounded-full bg-frost-4 p-1.5 text-white shadow-sm hover:bg-frost-1 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600">
<PlusIcon class="h-5 w-5" aria-hidden="true"/>
Expand Down
22 changes: 13 additions & 9 deletions frontend/src/components/Workflow/WorkflowList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,23 @@ function renameWorkflow(name: string) {
</div>
</div>
<ul v-else class="block w-full flex-auto text-left">
<li v-for="flow in flows" :key="flow.id"
<li v-for="flow in flows" :key="flow.id" class="group"
:class="[flow.id === selected ? 'border-b border-frost-2 bg-polar-night-1': 'border-polar-night-3 hover:border-polar-night-4', 'flex w-full border-t']">
<a @click="emit('select', flow.id)"
class="my-1 block grow cursor-pointer pl-2">
class="my-1 block grow cursor-pointer truncate pl-2">
{{ flow.name }}
<p class="text-polar-night-4">{{ flow.id.substring(0, 18) }}</p>
<div class="flex items-center justify-between">
<div class="py-1 text-xs text-polar-night-4">{{ flow.id.substring(0, 8) }}</div>
<div class="hidden group-hover:flex">
<button class="shrink pr-2" @click="renaming = flow.id">
<PencilSquareIcon class="h-5 w-5 text-polar-night-4 hover:text-frost-1" aria-hidden="true"/>
</button>
<button class="shrink pr-2" @click="deleting = flow.id">
<TrashIcon class="h-4 w-4 text-polar-night-4 hover:text-aurora-1" aria-hidden="true"/>
</button>
</div>
</div>
</a>
<button class="shrink pr-2" @click="renaming = flow.id">
<PencilSquareIcon class="h-5 w-5 text-polar-night-4 hover:text-frost-1" aria-hidden="true"/>
</button>
<button class="shrink pr-2" @click="deleting = flow.id">
<TrashIcon class="h-5 w-5 text-polar-night-4 hover:text-aurora-1" aria-hidden="true"/>
</button>
</li>
</ul>
</div>
Expand Down