Compare commits

..

No commits in common. "7aba27e5f960db78067bc6a0c0ad25ce7d874dd2" and "47df424138a2529fb228610d54633399e0b35090" have entirely different histories.

20 changed files with 76 additions and 185 deletions

View File

@ -1,6 +0,0 @@
package consts
const DEFAULT_FONT_SIZE = 14
const DEFAULT_ASIDE_WIDTH = 300
const DEFAULT_WINDOW_WIDTH = 1024
const DEFAULT_WINDOW_HEIGHT = 768

View File

@ -508,15 +508,12 @@ func (c *connectionService) GetKeyValue(connName string, db int, key string) (re
}
var value any
var size int64
var cursor uint64
switch strings.ToLower(keyType) {
case "string":
value, err = rdb.Get(ctx, key).Result()
size, _ = rdb.StrLen(ctx, key).Result()
case "list":
value, err = rdb.LRange(ctx, key, 0, -1).Result()
size, _ = rdb.LLen(ctx, key).Result()
case "hash":
//value, err = rdb.HGetAll(ctx, key).Result()
items := map[string]string{}
@ -535,7 +532,6 @@ func (c *connectionService) GetKeyValue(connName string, db int, key string) (re
}
}
value = items
size, _ = rdb.HLen(ctx, key).Result()
case "set":
//value, err = rdb.SMembers(ctx, key).Result()
items := []string{}
@ -552,7 +548,6 @@ func (c *connectionService) GetKeyValue(connName string, db int, key string) (re
}
}
value = items
size, _ = rdb.SCard(ctx, key).Result()
case "zset":
//value, err = rdb.ZRangeWithScores(ctx, key, 0, -1).Result()
var items []types.ZSetItem
@ -577,7 +572,6 @@ func (c *connectionService) GetKeyValue(connName string, db int, key string) (re
}
}
value = items
size, _ = rdb.ZCard(ctx, key).Result()
case "stream":
var msgs []redis.XMessage
items := []types.StreamItem{}
@ -593,7 +587,6 @@ func (c *connectionService) GetKeyValue(connName string, db int, key string) (re
})
}
value = items
size, _ = rdb.XLen(ctx, key).Result()
}
if err != nil {
resp.Msg = err.Error()
@ -604,7 +597,6 @@ func (c *connectionService) GetKeyValue(connName string, db int, key string) (re
"type": keyType,
"ttl": ttl,
"value": value,
"size": size,
}
return
}

View File

@ -7,7 +7,6 @@ import (
"sort"
"strings"
"sync"
"tinyrdm/backend/consts"
storage2 "tinyrdm/backend/storage"
"tinyrdm/backend/types"
"tinyrdm/backend/utils/coll"
@ -102,28 +101,6 @@ func (p *preferencesService) GetAppVersion() (resp types.JSResp) {
return
}
func (p *preferencesService) SaveWindowSize(width, height int) {
p.SetPreferences(map[string]any{
"behavior": map[string]any{
"window_width": width,
"window_height": height,
},
})
}
func (p *preferencesService) GetWindowSize() (width, height int) {
data := p.pref.GetPreferences()
w, h := data["behavior.window_width"], data["behavior.window_height"]
var ok bool
if width, ok = w.(int); !ok {
return consts.DEFAULT_WINDOW_WIDTH, consts.DEFAULT_WINDOW_HEIGHT
}
if height, ok = h.(int); !ok {
return consts.DEFAULT_WINDOW_WIDTH, consts.DEFAULT_WINDOW_HEIGHT
}
return
}
type latestRelease struct {
Name string `json:"name"`
TagName string `json:"tag_name"`

View File

@ -5,7 +5,6 @@ import (
"gopkg.in/yaml.v3"
"strings"
"sync"
"tinyrdm/backend/consts"
)
type PreferencesStorage struct {
@ -21,19 +20,15 @@ func NewPreferences() *PreferencesStorage {
func (p *PreferencesStorage) DefaultPreferences() map[string]any {
return map[string]any{
"behavior": map[string]any{
"aside_width": consts.DEFAULT_ASIDE_WIDTH,
"window_width": consts.DEFAULT_WINDOW_WIDTH,
"window_height": consts.DEFAULT_WINDOW_HEIGHT,
},
"general": map[string]any{
"language": "auto",
"font": "",
"font_size": consts.DEFAULT_FONT_SIZE,
"font_size": 14,
"use_sys_proxy": false,
"use_sys_proxy_http": false,
"check_update": true,
"skip_version": "",
"aside_width": 300,
},
"editor": map[string]any{
"font": "",

View File

@ -59,7 +59,7 @@ const startResize = () => {
}
const asideWidthVal = computed(() => {
return prefStore.behavior.asideWidth + 'px'
return prefStore.general.asideWidth + 'px'
})
const dragging = computed(() => {
@ -115,7 +115,7 @@ const border = computed(() => {
<div
id="app-toolbar-title"
:style="{
width: `${data.navMenuWidth + prefStore.behavior.asideWidth - 4}px`,
width: `${data.navMenuWidth + prefStore.general.asideWidth - 4}px`,
paddingLeft: isMacOS() ? '70px' : '10px',
}">
<n-space align="center" :wrap-item="false" :wrap="false" :size="3">

View File

@ -97,7 +97,6 @@ const tabContent = computed(() => {
keyPath: tab.key,
ttl: tab.ttl,
value: tab.value,
size: tab.size || 0,
}
})
@ -152,8 +151,7 @@ const onReloadKey = async () => {
:key-path="tabContent.keyPath"
:name="tabContent.name"
:ttl="tabContent.ttl"
:value="tabContent.value"
:size="tabContent.size" />
:value="tabContent.value" />
</div>
</template>

View File

@ -19,7 +19,6 @@ const props = defineProps({
default: -1,
},
value: Object,
size: Number,
})
const filterOption = [
@ -258,9 +257,7 @@ const onUpdateFilter = (filters, sourceColumn) => {
@update:value="onFilterInput" />
</n-input-group>
</div>
<div class="tb2-extra-info flex-item-expand">
<n-tag size="large">{{ $t('interface.total', { size: props.size }) }}</n-tag>
</div>
<div class="flex-item-expand"></div>
<n-button plain :focusable="false" @click="onAddRow">
<template #icon>
<n-icon :component="AddLink" size="18" />

View File

@ -20,7 +20,6 @@ const props = defineProps({
default: -1,
},
value: Object,
size: Number,
})
const connectionStore = useConnectionStore()
@ -182,9 +181,7 @@ const onUpdateFilter = (filters, sourceColumn) => {
@clear="clearFilter"
@update:value="onFilterInput" />
</div>
<div class="tb2-extra-info flex-item-expand">
<n-tag size="large">{{ $t('interface.total', { size: props.size }) }}</n-tag>
</div>
<div class="flex-item-expand"></div>
<n-button plain :focusable="false" @click="onAddValue">
<template #icon>
<n-icon :component="AddLink" size="18" />

View File

@ -20,7 +20,6 @@ const props = defineProps({
default: -1,
},
value: Array,
size: Number,
})
const connectionStore = useConnectionStore()
@ -178,9 +177,7 @@ const onUpdateFilter = (filters, sourceColumn) => {
@clear="clearFilter"
@update:value="onFilterInput" />
</div>
<div class="tb2-extra-info flex-item-expand">
<n-tag size="large">{{ $t('interface.total', { size: props.size }) }}</n-tag>
</div>
<div class="flex-item-expand"></div>
<n-button plain :focusable="false" @click="onAddValue">
<template #icon>
<n-icon :component="AddLink" size="18" />

View File

@ -20,7 +20,6 @@ const props = defineProps({
default: -1,
},
value: Object,
size: Number,
})
const filterOption = [
@ -171,9 +170,7 @@ const onUpdateFilter = (filters, sourceColumn) => {
@update:value="onFilterInput" />
</n-input-group>
</div>
<div class="tb2-extra-info flex-item-expand">
<n-tag size="large">{{ $t('interface.total', { size: props.size }) }}</n-tag>
</div>
<div class="flex-item-expand"></div>
<n-button plain :focusable="false" @click="onAddRow">
<template #icon>
<n-icon :component="AddLink" size="18" />

View File

@ -27,7 +27,6 @@ const props = defineProps({
default: -1,
},
value: String,
size: Number,
})
const viewOption = computed(() =>

View File

@ -20,7 +20,6 @@ const props = defineProps({
default: -1,
},
value: Object,
size: Number,
})
const filterOption = [
@ -289,9 +288,7 @@ const onUpdateFilter = (filters, sourceColumn) => {
</n-tooltip>
</n-input-group>
</div>
<div class="tb2-extra-info flex-item-expand">
<n-tag size="large">{{ $t('interface.total', { size: props.size }) }}</n-tag>
</div>
<div class="flex-item-expand"></div>
<n-button plain :focusable="false" @click="onAddRow">
<template #icon>
<n-icon :component="AddLink" size="18" />

View File

@ -4,7 +4,7 @@ import { ConnectionType } from '@/consts/connection_type.js'
import { NIcon, NSpace, NTag } from 'naive-ui'
import Key from '@/components/icons/Key.vue'
import ToggleDb from '@/components/icons/ToggleDb.vue'
import { find, get, includes, indexOf, isEmpty, pull, remove, size } from 'lodash'
import { find, get, includes, indexOf, isEmpty, remove } from 'lodash'
import { useI18n } from 'vue-i18n'
import Refresh from '@/components/icons/Refresh.vue'
import CopyLink from '@/components/icons/CopyLink.vue'
@ -300,24 +300,14 @@ const onUpdateExpanded = (value, option, meta) => {
if (!meta.node) {
return
}
// keep expand or collapse children while they own more than 1 child
let node = meta.node
while (node != null && size(node.children) === 1) {
const key = node.children[0].key
switch (meta.action) {
case 'expand':
node.expanded = true
if (!includes(expandedKeys.value, key)) {
expandedKeys.value.push(key)
}
break
case 'collapse':
node.expanded = false
remove(expandedKeys.value, (v) => v === key)
break
}
node = node.children[0]
// console.log(JSON.stringify(meta))
switch (meta.action) {
case 'expand':
meta.node.expanded = true
break
case 'collapse':
meta.node.expanded = false
break
}
}

View File

@ -87,8 +87,7 @@
"empty_server_list": "No redis server",
"action": "Action",
"type": "Type",
"score": "Score",
"total": "Length: {size}"
"score": "Score"
},
"ribbon": {
"server": "Server",

View File

@ -87,8 +87,7 @@
"empty_server_list": "还没添加Redis服务器",
"action": "操作",
"type": "类型",
"score": "分值",
"total": "总数:{size}"
"score": "分值"
},
"ribbon": {
"server": "服务器",

View File

@ -532,7 +532,7 @@ const useConnectionStore = defineStore('connections', {
if (!isEmpty(key)) {
const { data, success, msg } = await GetKeyValue(server, db, key)
if (success) {
const { type, ttl, value, size } = data
const { type, ttl, value } = data
tab.upsertTab({
server,
db,
@ -540,7 +540,6 @@ const useConnectionStore = defineStore('connections', {
ttl,
key,
value,
size,
})
return
} else {
@ -556,7 +555,6 @@ const useConnectionStore = defineStore('connections', {
ttl: -1,
key: null,
value: null,
size: 0,
})
} finally {
}
@ -749,10 +747,10 @@ const useConnectionStore = defineStore('connections', {
*/
_tidyNode(connName, db, key, skipResort) {
const nodeMap = this._getNodeMap(connName, db)
const dbNode = get(this.databases, [connName, db], {})
const separator = this._getSeparator(connName)
const keyParts = split(key, separator)
const totalParts = size(keyParts)
const dbNode = get(this.databases, [connName, db], {})
let node
// find last exists ancestor key
let i = totalParts - 1
@ -1252,7 +1250,7 @@ const useConnectionStore = defineStore('connections', {
*
* @param {string} connName
* @param {number} db
* @param {string} [key]
* @param {string} key
* @param {boolean} [isLayer]
* @private
*/
@ -1265,52 +1263,46 @@ const useConnectionStore = defineStore('connections', {
}
const nodeMap = this._getNodeMap(connName, db)
const keyParts = split(key, separator)
const totalParts = size(keyParts)
if (isLayer === true) {
this._deleteChildrenKeyNodes(nodeMap, key)
}
if (isEmpty(key)) {
// clear all key nodes
dbRoot.children = []
dbRoot.keys = 0
// remove from parent in tree node
const parentKey = slice(keyParts, 0, totalParts - 1)
let parentNode
if (isEmpty(parentKey)) {
parentNode = dbRoot
} else {
const keyParts = split(key, separator)
const totalParts = size(keyParts)
// remove from parent in tree node
const parentKey = slice(keyParts, 0, totalParts - 1)
let parentNode
if (isEmpty(parentKey)) {
parentNode = dbRoot
} else {
parentNode = nodeMap.get(`${ConnectionType.RedisKey}/${join(parentKey, separator)}`)
}
parentNode = nodeMap.get(`${ConnectionType.RedisKey}/${join(parentKey, separator)}`)
}
// not found parent node
if (parentNode == null) {
return false
}
remove(parentNode.children, {
type: isLayer ? ConnectionType.RedisKey : ConnectionType.RedisValue,
redisKey: key,
})
// not found parent node
if (parentNode == null) {
return false
}
remove(parentNode.children, {
type: isLayer ? ConnectionType.RedisKey : ConnectionType.RedisValue,
redisKey: key,
})
// check and remove empty layer node
let i = totalParts - 1
for (; i >= 0; i--) {
const anceKey = join(slice(keyParts, 0, i), separator)
if (i > 0) {
const anceNode = nodeMap.get(`${ConnectionType.RedisKey}/${anceKey}`)
const redisKey = join(slice(keyParts, 0, i + 1), separator)
remove(anceNode.children, { type: ConnectionType.RedisKey, redisKey })
// check and remove empty layer node
let i = totalParts - 1
for (; i >= 0; i--) {
const anceKey = join(slice(keyParts, 0, i), separator)
if (i > 0) {
const anceNode = nodeMap.get(`${ConnectionType.RedisKey}/${anceKey}`)
const redisKey = join(slice(keyParts, 0, i + 1), separator)
remove(anceNode.children, { type: ConnectionType.RedisKey, redisKey })
if (isEmpty(anceNode.children)) {
nodeMap.delete(`${ConnectionType.RedisKey}/${anceKey}`)
} else {
break
}
if (isEmpty(anceNode.children)) {
nodeMap.delete(`${ConnectionType.RedisKey}/${anceKey}`)
} else {
// last one, remove from db node
remove(dbRoot.children, { type: ConnectionType.RedisKey, redisKey: keyParts[0] })
break
}
} else {
// last one, remove from db node
remove(dbRoot.children, { type: ConnectionType.RedisKey, redisKey: keyParts[0] })
}
}
@ -1319,28 +1311,24 @@ const useConnectionStore = defineStore('connections', {
/**
* delete node and all it's children from nodeMap
* @param {Map<string, DatabaseItem>} nodeMap
* @param {string} [key] clean nodeMap if key is empty
* @param nodeMap
* @param key
* @private
*/
_deleteChildrenKeyNodes(nodeMap, key) {
if (isEmpty(key)) {
nodeMap.clear()
} else {
const mapKey = `${ConnectionType.RedisKey}/${key}`
const node = nodeMap.get(mapKey)
for (const child of node.children || []) {
if (child.type === ConnectionType.RedisValue) {
if (!nodeMap.delete(`${ConnectionType.RedisValue}/${child.redisKey}`)) {
console.warn('delete:', `${ConnectionType.RedisValue}/${child.redisKey}`)
}
} else if (child.type === ConnectionType.RedisKey) {
this._deleteChildrenKeyNodes(nodeMap, child.redisKey)
const mapKey = `${ConnectionType.RedisKey}/${key}`
const node = nodeMap.get(mapKey)
for (const child of node.children || []) {
if (child.type === ConnectionType.RedisValue) {
if (!nodeMap.delete(`${ConnectionType.RedisValue}/${child.redisKey}`)) {
console.warn('delete:', `${ConnectionType.RedisValue}/${child.redisKey}`)
}
} else if (child.type === ConnectionType.RedisKey) {
this._deleteChildrenKeyNodes(nodeMap, child.redisKey)
}
if (!nodeMap.delete(mapKey)) {
console.warn('delete map key', mapKey)
}
}
if (!nodeMap.delete(mapKey)) {
console.warn('delete map key', mapKey)
}
},

View File

@ -31,11 +31,6 @@ const usePreferencesStore = defineStore('preferences', {
* @returns {Preferences}
*/
state: () => ({
behavior: {
asideWidth: 300,
windowWidth: 0,
windowHeight: 0,
},
general: {
theme: 'auto',
language: 'en',
@ -45,6 +40,7 @@ const usePreferencesStore = defineStore('preferences', {
useSysProxyHttp: false,
checkUpdate: false,
skipVersion: '',
asideWidth: 300,
},
editor: {
font: '',
@ -215,12 +211,7 @@ const usePreferencesStore = defineStore('preferences', {
}
return result
}
const pf = Object.assign(
{},
obj2Map('behavior', this.behavior),
obj2Map('general', this.general),
obj2Map('editor', this.editor),
)
const pf = Object.assign({}, obj2Map('general', this.general), obj2Map('editor', this.editor))
const { success, msg } = await SetPreferences(pf)
return success === true
},
@ -250,7 +241,7 @@ const usePreferencesStore = defineStore('preferences', {
},
setAsideWidth(width) {
this.behavior.asideWidth = width
this.general.asideWidth = width
},
async checkForUpdate(manual = false) {

View File

@ -83,10 +83,9 @@ const useTabStore = defineStore('tab', {
* @param {number} [type]
* @param {number} [ttl]
* @param {string} [key]
* @param {number} [size]
* @param {*} [value]
*/
upsertTab({ server, db, type, ttl, key, size, value }) {
upsertTab({ server, db, type, ttl, key, value }) {
let tabIndex = findIndex(this.tabList, { name: server })
if (tabIndex === -1) {
this.tabList.push({
@ -96,7 +95,6 @@ const useTabStore = defineStore('tab', {
type,
ttl,
key,
size,
value,
})
tabIndex = this.tabList.length - 1
@ -110,7 +108,6 @@ const useTabStore = defineStore('tab', {
tab.type = type
tab.ttl = ttl
tab.key = key
tab.size = size
tab.value = value
this._setActivatedIndex(tabIndex, true)
// this.activatedTab = tab.name

View File

@ -86,10 +86,6 @@ body {
gap: 5px;
justify-content: flex-end;
align-items: center;
.tb2-extra-info {
padding: 0 5px;
}
}
.value-wrapper {

17
main.go
View File

@ -10,9 +10,7 @@ import (
"github.com/wailsapp/wails/v2/pkg/options/linux"
"github.com/wailsapp/wails/v2/pkg/options/mac"
"github.com/wailsapp/wails/v2/pkg/options/windows"
runtime2 "github.com/wailsapp/wails/v2/pkg/runtime"
"runtime"
"tinyrdm/backend/consts"
"tinyrdm/backend/services"
)
@ -30,7 +28,6 @@ func main() {
connSvc := services.Connection()
prefSvc := services.Preferences()
prefSvc.SetAppVersion(version)
windowWidth, windowHeight := prefSvc.GetWindowSize()
// menu
appMenu := menu.NewMenu()
@ -43,10 +40,10 @@ func main() {
// Create application with options
err := wails.Run(&options.App{
Title: "Tiny RDM",
Width: windowWidth,
Height: windowHeight,
MinWidth: consts.DEFAULT_WINDOW_WIDTH,
MinHeight: consts.DEFAULT_WINDOW_HEIGHT,
Width: 1024,
Height: 768,
MinWidth: 1024,
MinHeight: 768,
Frameless: runtime.GOOS != "darwin",
Menu: appMenu,
AssetServer: &assetserver.Options{
@ -58,12 +55,6 @@ func main() {
connSvc.Start(ctx)
},
OnShutdown: func(ctx context.Context) {
// save current window size
width, height := runtime2.WindowGetSize(ctx)
if width > 0 && height > 0 {
prefSvc.SaveWindowSize(width, height)
}
connSvc.Stop(ctx)
},
Bind: []interface{}{