Skip to content

Commit

Permalink
license and tabs component
Browse files Browse the repository at this point in the history
  • Loading branch information
lorypelli committed Mar 21, 2024
1 parent 752f9f6 commit 18a7b36
Show file tree
Hide file tree
Showing 6 changed files with 234 additions and 161 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) LoryPelli

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 1 addition & 1 deletion app.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/wailsapp/wails/v2/pkg/runtime"
)

const APP_VERSION = "1.1.1"
const APP_VERSION = "1.1.2"

// App struct
type App struct {
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<script setup lang="ts">
import { ElMessageBox, ElNotification, ElTabPane, ElTabs } from 'element-plus';
import HTTP, { handleTab as HTTPTab } from './components/HTTP.vue';
import WS, { handleTab as WSTab } from './components/WS.vue';
import HTTP from './components/HTTP.vue';
import WS from './components/WS.vue';
import { httpTabHandle as HTTPTab, wsTabHandle as WSTab } from './components/Tabs.vue';
import Updater from './components/Updater.vue';
import 'element-plus/dist/index.css';
import 'primevue/resources/themes/aura-light-green/theme.css';
Expand Down
115 changes: 36 additions & 79 deletions frontend/src/components/HTTP.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script setup lang="ts">
import { ElButton, ElInput, ElNotification, ElOption, ElSelect, ElTabPane, ElTabs, TabPaneName } from 'element-plus';
import { ElButton, ElInput, ElNotification, ElOption, ElSelect } from 'element-plus';
import { HTTP } from '../../wailsjs/go/main/App.js';
import Split from './Split.vue';
import { ref } from 'vue';
import Tabs from './Tabs.vue';
defineOptions({
name: 'HTTP',
components: {
Expand All @@ -11,8 +11,7 @@ defineOptions({
ElOption,
ElSelect,
Split,
ElTabs,
ElTabPane
Tabs,
}
});
</script>
Expand Down Expand Up @@ -71,53 +70,11 @@ export default {
}
}
};
let tabIndex = 1;
const selectedTab = ref('1');
const tabs = ref([
{
name: '1',
select: 'GET',
input: ''
}
]);
export function handleTab(targetName: TabPaneName | undefined, action: 'add' | 'remove') {
switch (action) {
case 'add': {
const newTabIndex = `${++tabIndex}`;
tabs.value.push({
name: newTabIndex,
select: 'GET',
input: ''
});
selectedTab.value = newTabIndex;
break;
}
case 'remove': {
const t = tabs.value;
if (t.length > 1) {
let activeTab = selectedTab.value;
if (activeTab == targetName) {
t.forEach((tab, index) => {
if (tab.name == targetName) {
const nextTab = t[index + 1] || t[index - 1];
if (nextTab) {
activeTab = nextTab.name;
}
}
});
}
selectedTab.value = activeTab;
tabs.value = t.filter((tab) => tab.name != targetName);
}
break;
}
}
}
</script>

<template>
<ElTabs v-model="selectedTab" tab-position="left" editable v-on:edit="handleTab">
<ElTabPane :label="item.name" v-for="(item, index) in tabs" :name="item.name" :key="index">
<Tabs type="http">
<template #default="{ item }">
<div class="flex p-1 space-x-1">
<ElSelect class="w-32" v-model="item.select">
<ElOption value="GET" />
Expand All @@ -132,39 +89,39 @@ export function handleTab(targetName: TabPaneName | undefined, action: 'add' | '
</ElSelect>
<ElInput v-model="item.input" placeholder="echo.zuplo.io"></ElInput>
<ElButton class="w-20" v-on:click="() => {
if (item.input) {
if (!item.input.startsWith('http://') && !item.input.startsWith('https://')) {
item.input = 'https://' + item.input
}
}
else {
item.input = 'https://echo.zuplo.io'
}
try {
HTTP(item.select, item.input, headers, query, body).then((res) => {
if (res.Error) {
ElNotification({
title: 'Something went wrong!',
message: res.Error,
type: 'error',
position: 'bottom-right'
})
return
if (item.input) {
if (!item.input.startsWith('http://') && !item.input.startsWith('https://')) {
item.input = 'https://' + item.input
}
update(res)
})
}
catch {
ElNotification({
title: 'Something went wrong!',
type: 'error',
position: 'bottom-right'
})
}
}">Send</ElButton>
}
else {
item.input = 'https://echo.zuplo.io'
}
try {
HTTP(item.select, item.input, headers, query, body).then((res) => {
if (res.Error) {
ElNotification({
title: 'Something went wrong!',
message: res.Error,
type: 'error',
position: 'bottom-right'
})
return
}
update(res)
})
}
catch {
ElNotification({
title: 'Something went wrong!',
type: 'error',
position: 'bottom-right'
})
}
}">Send</ElButton>
</div>
<Split :url="url" :status="status" :header="header" :response="response" type='http'
v-on:headers="handleHeader" v-on:query="handleQuery" v-on:body="handleBody" />
</ElTabPane>
</ElTabs>
</template>
</Tabs>
</template>
137 changes: 137 additions & 0 deletions frontend/src/components/Tabs.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<script setup lang="ts">
import { ElTabs, ElTabPane, TabPaneName } from 'element-plus';
import { ref } from 'vue';
defineOptions({
// eslint-disable-next-line vue/multi-word-component-names
name: 'Tabs',
components: {
ElTabs,
ElTabPane
}
});
const props = defineProps<{
type: 'http' | 'ws'
}>();
</script>

<script lang="ts">
let httpTabIndex = 1;
const httpSelectedTab = ref('1');
const httpTab = ref([
{
name: '1',
select: 'GET',
input: ''
}
]);
let wsTabIndex = 1;
const wsSelectedTab = ref('1');
const wsTab = ref([
{
name: '1',
input: '',
connected: false
}
]);
export function httpTabHandle(targetName: TabPaneName | undefined, action: 'add' | 'remove') {
switch (action) {
case 'add': {
const newTabIndex = `${++httpTabIndex}`;
httpTab.value.push({
name: newTabIndex,
select: 'GET',
input: ''
});
httpSelectedTab.value = newTabIndex;
break;
}
case 'remove': {
const t = httpTab.value;
if (t.length > 1) {
let activeTab = httpSelectedTab.value;
if (activeTab == targetName) {
t.forEach((tab, index) => {
if (tab.name == targetName) {
const nextTab = t[index + 1] || t[index - 1];
if (nextTab) {
activeTab = nextTab.name;
}
}
});
}
httpSelectedTab.value = activeTab;
httpTab.value = t.filter((tab) => tab.name != targetName);
}
break;
}
}
}
export function wsTabHandle(targetName: TabPaneName | undefined, action: 'add' | 'remove') {
switch (action) {
case 'add': {
const newTabIndex = `${++wsTabIndex}`;
wsTab.value.push({
name: newTabIndex,
input: '',
connected: false
});
wsSelectedTab.value = newTabIndex;
break;
}
case 'remove': {
const t = wsTab.value;
if (t.length > 1) {
let activeTab = wsSelectedTab.value;
if (activeTab == targetName) {
t.forEach((tab, index) => {
if (tab.name == targetName) {
const nextTab = t[index + 1] || t[index - 1];
if (nextTab) {
activeTab = nextTab.name;
}
}
});
}
wsSelectedTab.value = activeTab;
wsTab.value = t.filter((tab) => tab.name != targetName);
}
break;
}
}
}
interface CompleteItem {
name: string,
select: string,
input: string,
connected: boolean
}
export default {
computed: {
selectedTab: {
get() {
return this.type == 'http' ? httpSelectedTab.value : wsSelectedTab.value;
},
set(value: string) {
if (this.type == 'http') {
httpSelectedTab.value = value;
}
else {
wsSelectedTab.value = value;
}
return this.type == 'http' ? httpSelectedTab.value : wsSelectedTab.value;
}
},
tabHandle: function() {
return this.type == 'http' ? httpTabHandle : wsTabHandle;
}
},
};
</script>

<template>
<ElTabs v-model="selectedTab" tab-position="left" editable v-on:edit="tabHandle">
<ElTabPane :label="item.name" v-for="(item, index) in (props.type == 'http' ? httpTab : props.type == 'ws' ? wsTab : null)" :name="item.name" :key="index">
<slot :item="item as CompleteItem"></slot>
</ElTabPane>
</ElTabs>
</template>
Loading

0 comments on commit 18a7b36

Please sign in to comment.