You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2024/12/13 10:01:27 UTC
(skywalking-banyandb) branch main updated: Refactor Groups Tree in the UI (#572)
This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-banyandb.git
The following commit(s) were added to refs/heads/main by this push:
new 212b6e04 Refactor Groups Tree in the UI (#572)
212b6e04 is described below
commit 212b6e04266a4cc135c58f6e1ba67ef6194a3afc
Author: Fine0830 <fa...@gmail.com>
AuthorDate: Fri Dec 13 18:01:22 2024 +0800
Refactor Groups Tree in the UI (#572)
---
CHANGES.md | 1 +
ui/src/components/Aside/index.vue | 1165 --------------------
ui/src/components/GroupTree/index.vue | 850 ++++++++++++++
ui/src/components/Header/components/header.vue | 40 +-
.../RightMenu/components/right-menu-item.vue | 67 --
ui/src/components/RightMenu/index.vue | 38 -
ui/src/components/TopNav/index.vue | 2 +-
ui/src/views/Measure/index.vue | 4 +-
ui/src/views/Property/index.vue | 4 +-
ui/src/views/Stream/index.vue | 4 +-
10 files changed, 860 insertions(+), 1315 deletions(-)
diff --git a/CHANGES.md b/CHANGES.md
index f6f5f718..d7a36463 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -22,6 +22,7 @@ Release Notes.
- UI: Polish Index Rule Binding Page and Index Page.
- Fix: View configuration on Property page.
- UI: Add `indexMode` to display on the measure page.
+- UI: Refactor Groups Tree to optimize style and fix bugs.
- UI: Add `NoSort` Field to IndexRule page.
- Metadata: Fix the bug that the cache load nil value that is the unknown index rule on the index rule binding.
- Queue: Fix the bug that the client remove a registered node in the eviction list. The node is controlled by the recovery loop, doesn't need to be removed in the failover process.
diff --git a/ui/src/components/Aside/index.vue b/ui/src/components/Aside/index.vue
deleted file mode 100644
index d82eb49a..00000000
--- a/ui/src/components/Aside/index.vue
+++ /dev/null
@@ -1,1165 +0,0 @@
-<!--
- ~ Licensed to Apache Software Foundation (ASF) under one or more contributor
- ~ license agreements. See the NOTICE file distributed with
- ~ this work for additional information regarding copyright
- ~ ownership. Apache Software Foundation (ASF) licenses this file to you under
- ~ the Apache License, Version 2.0 (the "License"); you may
- ~ not use this file except in compliance with the License.
- ~ You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing,
- ~ software distributed under the License is distributed on an
- ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- ~ KIND, either express or implied. See the License for the
- ~ specific language governing permissions and limitations
- ~ under the License.
--->
-
-<script setup>
-import RigheMenu from '@/components/RightMenu/index.vue'
-import { deleteSecondaryDataModel, getindexRuleList, getindexRuleBindingList, getGroupList, getTopNAggregationList, getStreamOrMeasureList, deleteStreamOrMeasure, deleteGroup, createGroup, editGroup } from '@/api/index'
-import { ElMessage, ElMessageBox } from 'element-plus'
-import { watch, getCurrentInstance } from "@vue/runtime-core"
-import { useRouter, useRoute } from 'vue-router'
-import { ref, reactive } from 'vue'
-import { Search } from '@element-plus/icons-vue'
-
-const router = useRouter()
-const route = useRoute()
-const { proxy } = getCurrentInstance()
-
-// ref
-const ruleForm = ref()
-
-// Loading
-const $loadingCreate = getCurrentInstance().appContext.config.globalProperties.$loadingCreate
-const $loadingClose = proxy.$loadingClose
-
-// catalog to group type
-const catalogToGroupType = {
- 'CATALOG_MEASURE': 'measure',
- 'CATALOG_STREAM': 'stream',
- 'CATALOG_UNSPECIFIED': 'property'
-}
-
-// group type to catalog
-const groupTypeToCatalog = {
- 'measure': 'CATALOG_MEASURE',
- 'stream': 'CATALOG_STREAM',
- 'property': 'CATALOG_UNSPECIFIED'
-}
-
-// Data
-const data = reactive({
- groupLists: [],
- groupListsCopy: [],
- showSearch: false,
- isShrink: false,
- isCollapse: false,
- // right menu
- showRightMenu: false,
- rightMenuList: [],
- top: 0,
- left: 0,
- clickIndex: 0,
- clickChildIndex: 0,
- rightClickType: 'group',
- // create/edit group
- dialogGroupVisible: false,
- setGroup: 'create',
- groupForm: {
- name: null,
- catalog: 'CATALOG_STREAM',
- shardNum: 1,
- segmentIntervalUnit: "UNIT_DAY",
- segmentIntervalNum: 1,
- ttlUnit: "UNIT_DAY",
- ttlNum: 3
- },
- activeMenu: '',
- search: '',
- formLabelWidth: "170px"
-})
-
-watch(() => data.search, () => {
- debounce(searchGroup, 300)()
-})
-
-// menu config
-const groupMenu = [
- {
- icon: "el-icon-folder",
- name: "new group",
- id: "create Group"
- }, {
- icon: "el-icon-folder",
- name: "edit group",
- id: "edit Group"
- }, {
- icon: "el-icon-refresh-right",
- name: "refresh",
- id: "refresh Group"
- }, {
- icon: "el-icon-delete",
- name: "delete",
- id: "delete Group"
- }
-]
-const resourceMenu = [
- {
- icon: "el-icon-document",
- name: "edit resources",
- id: "edit resources"
- },
- {
- icon: "el-icon-delete",
- name: "delete",
- id: "delete resources"
- }
-]
-const StreamMenu = [
- {
- icon: "el-icon-document",
- name: "new resources",
- id: "create resources"
- },
-]
-const indexRuleMenu = [
- {
- icon: "el-icon-document",
- name: "new index-rule",
- id: "create index-rule"
- }
-]
-const indexRuleBindMenu = [
- {
- icon: "el-icon-document",
- name: "new index-rule-binding",
- id: "create index-rule-binding"
- }
-]
-const topNAggregationMenu = [
- {
- icon: "el-icon-document",
- name: "new topn-agg",
- id: "create topn-agg"
- }
-]
-const indexRuleItemMenu = [
- {
- icon: "el-icon-document",
- name: "edit index-rule",
- id: "edit index-rule"
- },
- {
- icon: "el-icon-delete",
- name: "delete",
- id: "delete index-rule"
- }
-]
-const indexRuleBindingItemMenu = [
- {
- icon: "el-icon-document",
- name: "edit index-rule-binding",
- id: "edit index-rule-binding"
- },
- {
- icon: "el-icon-delete",
- name: "delete",
- id: "delete index-rule-binding"
- }
-]
-const topNAggregationItemMenu = [
- {
- icon: "el-icon-document",
- name: "edit topn-agg",
- id: "edit topn-agg"
- },
- {
- icon: "el-icon-delete",
- name: "delete",
- id: "delete topn-agg"
- }
-]
-const menuItemFunction = {
- "new group": openCreateGroup,
- "edit group": openEditGroup,
- "new resources": openCreateResource,
- "refresh": getGroupLists,
- "delete": openDeletaDialog,
- "edit resources": openEditResource,
- 'new index-rule': openCreateSecondaryDataModel,
- 'edit index-rule': openEditSecondaryDataModel,
- 'new index-rule-binding': openCreateSecondaryDataModel,
- 'edit index-rule-binding': openEditSecondaryDataModel,
- 'new topn-agg': openCreateSecondaryDataModel,
- 'edit topn-agg': openEditSecondaryDataModel
-}
-
-// rules
-const rules = {
- name: [
- {
- required: true, message: 'Please enter the name of the group', trigger: 'blur'
- }
- ],
- catalog: [
- {
- required: true, message: 'Please select the type of the group', trigger: 'blur'
- }
- ],
- shardNum: [
- {
- required: true, message: 'Please select the shard num of the group', trigger: 'blur'
- }
- ],
- segmentIntervalUnit: [
- {
- required: true, message: 'Please select the segment interval unit of the group', trigger: 'blur'
- }
- ],
- segmentIntervalNum: [
- {
- required: true, message: 'Please select the segment Interval num of the group', trigger: 'blur'
- }
- ],
- ttlUnit: [
- {
- required: true, message: 'Please select the ttl unit of the group', trigger: 'blur'
- }
- ],
- ttlNum: [
- {
- required: true, message: 'Please select the ttl num of the group', trigger: 'blur'
- }
- ]
-}
-
-// Eventbus
-const $bus = getCurrentInstance().appContext.config.globalProperties.mittBus
-
-// props data
-const props = defineProps({
- type: {
- type: String,
- required: true,
- default: ''
- }
-})
-
-// emit event
-const emit = defineEmits(['setWidth'])
-
-// function
-// search group
-function debounce(event, delay) {
- let timer = null
- return function (...args) {
- clearTimeout(timer)
- timer = setTimeout(() => {
- event(args)
- }, delay)
- }
-}
-
-function searchGroup() {
- if (!data.search) {
- return data.groupLists = JSON.parse(JSON.stringify(data.groupListsCopy))
- }
- let groupLists = []
- data.groupListsCopy.forEach(item => {
- let itemCache = JSON.parse(JSON.stringify(item))
- let matched = false
- if (Array.isArray(itemCache.children)) {
- itemCache.children = itemCache.children.filter(child => {
- return child.metadata.name.indexOf(data.search) > -1
- })
- if (itemCache.children.length > 0) {
- groupLists.push(itemCache)
- matched = true
- }
- }
-
- // check the group name if no child items matched
- if (!matched && itemCache.metadata.name.indexOf(data.search) > -1) {
- groupLists.push(itemCache)
- }
- })
- data.groupLists = JSON.parse(JSON.stringify(groupLists))
-}
-// init data
-function getGroupLists() {
- $loadingCreate()
- data.showSearch = false
- data.search = ''
- getGroupList()
- .then(res => {
- if (res.status == 200) {
- let group = res.data.group
- data.groupLists = group
- deleteOtherGroup()
- if (props.type == 'property') {
- data.showSearch = true
- $loadingClose()
- return
- }
- let promise = data.groupLists.map((item) => {
- let type = props.type
- let name = item.metadata.name
- return new Promise((resolve, reject) => {
- getStreamOrMeasureList(type, name)
- .then(res => {
- if (res.status == 200) {
- item.children = res.data[type]
- resolve()
- }
- })
- .catch((err) => {
- reject(err)
- })
- })
- })
- if (props.type == 'stream' || props.type == 'measure') {
- let promiseIndexRule = data.groupLists.map((item) => {
- let name = item.metadata.name
- return new Promise((resolve, reject) => {
- getindexRuleList(name)
- .then(res => {
- if (res.status == 200) {
- item.indexRule = res.data.indexRule
- resolve()
- }
- })
- .catch((err) => {
- reject(err)
- })
- })
- })
- let promiseIndexRuleBinding = data.groupLists.map((item) => {
- let name = item.metadata.name
- return new Promise((resolve, reject) => {
- getindexRuleBindingList(name)
- .then(res => {
- if (res.status == 200) {
- item.indexRuleBinding = res.data.indexRuleBinding
- resolve()
- }
- })
- .catch((err) => {
- reject(err)
- })
- })
- })
- promise = promise.concat(promiseIndexRule)
- promise = promise.concat(promiseIndexRuleBinding)
- }
- if (props.type == 'measure') {
- let TopNAggregationRule = data.groupLists.map((item) => {
- let name = item.metadata.name
- return new Promise((resolve, reject) => {
- getTopNAggregationList(name)
- .then(res => {
- if (res.status == 200) {
- item.topNAggregation = res.data.topNAggregation
- resolve()
- }
- })
- .catch((err) => {
- reject(err)
- })
- })
- })
- promise = promise.concat(TopNAggregationRule)
- }
- Promise.all(promise).then(() => {
- data.showSearch = true
- data.groupListsCopy = JSON.parse(JSON.stringify(data.groupLists))
- }).catch((err) => {
- ElMessage({
- message: 'An error occurred while obtaining group data. Please refresh and try again. Error: ' + err,
- type: "error",
- duration: 3000
- })
- }).finally(() => {
- $loadingClose()
- })
- }else{
- $loadingClose()
- }
- })
- $loadingClose()
-}
-function deleteOtherGroup() {
- for (let i = 0; i < data.groupLists.length; i++) {
- let type = catalogToGroupType[data.groupLists[i].catalog]
- if (type !== props.type) {
- data.groupLists.splice(i, 1)
- i--
- }
- }
-}
-// to resources
-function openResources(index, childIndex) {
- if (props.type == 'property') {
- const group = data.groupLists[index].metadata.name
- const route = {
- name: 'property',
- params: {
- group: group,
- operator: 'read',
- type: props.type
- }
- }
- router.push(route)
- const add = {
- label: group,
- type: 'Read',
- route
- }
- data.active = `${group}`
- return $bus.emit('AddTabs', add)
- }
- const group = data.groupLists[index].children[childIndex].metadata.group
- const name = data.groupLists[index].children[childIndex].metadata.name
- const route = {
- name: props.type,
- params: {
- group: group,
- name: name,
- operator: 'read',
- type: props.type
- }
- }
- router.push(route)
- const add = {
- label: name,
- type: 'Read',
- route
- }
- data.activeMenu = `${group}-${name}`
- $bus.emit('AddTabs', add)
-}
-// open or close Aide
-function shrinkMove(e) {
- e.preventDefault()
- if (data.isShrink) {
- let wid = e.screenX + 5
- if (wid <= 65) {
- $bus.emit('changeIsCollapse', {
- isCollapse: true,
- width: '65px'
- })
- } else {
- $bus.emit('changeIsCollapse', {
- isCollapse: false,
- width: `${wid > 450 ? 450 : wid}px`
- })
- }
- }
-}
-function shrinkUp(e) {
- e.stopPropagation()
- data.isShrink = false
- document.getElementById('app').onmousemove = null
- document.getElementById('app').onmouseup = null
- document.getElementById('app').onmouseleave = null
- document.getElementById('app').ondragover = null
-}
-function shrinkDown(e) {
- data.isShrink = true
- document.getElementById('app').onmousemove = shrinkMove
- document.getElementById('app').onmouseup = shrinkUp
- document.getElementById('app').onmouseleave = shrinkUp
- document.getElementById('app').ondragover = shrinkUp
- e.preventDefault()
-}
-// right click menu
-function rightClickGroup(e, index) {
- data.rightMenuList = groupMenu
- data.clickIndex = index
- data.rightClickType = 'group'
- openRightMenu(e)
-}
-function rightClickResources(e, index, childIndex) {
- data.rightMenuList = resourceMenu
- data.clickIndex = index
- data.clickChildIndex = childIndex
- data.rightClickType = 'resources'
- openRightMenu(e)
-}
-function rightClickResourcesFolder(e, index) {
- data.rightMenuList = StreamMenu
- data.clickIndex = index
- data.rightClickType = 'group'
- openRightMenu(e)
-}
-function rightClickIndexRule(e, index, schema) {
- data.rightMenuList = indexRuleMenu
- data.clickIndex = index
- data.rightClickType = 'index-rule'
- data.schema = schema
- openRightMenu(e)
-}
-function rightClickIndexRuleBinding(e, index, schema) {
- data.rightMenuList = indexRuleBindMenu
- data.clickIndex = index
- data.rightClickType = 'index-rule-binding'
- data.schema = schema
- openRightMenu(e)
-}
-function rightClickTopNAggregation(e, index, schema) {
- data.rightMenuList = topNAggregationMenu
- data.clickIndex = index
- data.rightClickType = 'topn-agg'
- data.schema = schema
- openRightMenu(e)
-}
-function rightClickIndexRuleItem(e, index, childIndex, schema) {
- data.rightMenuList = indexRuleItemMenu
- data.clickIndex = index
- data.clickChildIndex = childIndex
- data.rightClickType = 'index-rule'
- data.schema = schema
- openRightMenu(e)
-}
-function rightClickIndexRuleBindingItem(e, index, childIndex, schema) {
- data.rightMenuList = indexRuleBindingItemMenu
- data.clickIndex = index
- data.clickChildIndex = childIndex
- data.rightClickType = 'index-rule-binding'
- data.schema = schema
- openRightMenu(e)
-}
-function rightClickTopNAggregationItem(e, index, childIndex, schema) {
- data.rightMenuList = topNAggregationItemMenu
- data.clickIndex = index
- data.clickChildIndex = childIndex
- data.rightClickType = 'topn-agg'
- data.schema = schema
- openRightMenu(e)
-}
-function openRightMenu(e) {
- data.showRightMenu = true
- data.top = e.pageY
- data.left = e.pageX
- document.getElementById('app').onclick = closeRightMenu
- stopPropagation()
-}
-function closeRightMenu() {
- data.showRightMenu = false
- document.getElementById('app').onclick = null
- stopPropagation()
-}
-function handleRightItem(index) {
- const name = data.rightMenuList[index].name
- return menuItemFunction[name]()
-}
-function stopPropagation(e) {
- e = e || window.event;
- if (e.stopPropagation) {
- e.stopPropagation();
- } else {
- e.cancelBubble = true;
- }
-}
-
-// CRUD operator
-function openCreateSecondaryDataModel() {
- const route = {
- name: `${data.schema}-create-${data.rightClickType}`,
- params: {
- operator: 'create',
- group: data.groupLists[data.clickIndex].metadata.name,
- type: data.rightClickType,
- schema: data.schema
- }
- }
- router.push(route)
- const add = {
- label: data.groupLists[data.clickIndex].metadata.name,
- type: `Create-${data.rightClickType}`,
- route
- }
- data.activeMenu = ''
- $bus.emit('AddTabs', add)
-}
-
-function openEditSecondaryDataModel() {
- const typeFlag = {
- 'topn-agg': 'topNAggregation',
- 'index-rule': 'indexRule',
- 'index-rule-binding': 'indexRuleBinding'
- }
- const route = {
- name: `${data.schema}-edit-${data.rightClickType}`,
- params: {
- operator: 'edit',
- group: data.groupLists[data.clickIndex].metadata.name,
- name: data.groupLists[data.clickIndex][typeFlag[data.rightClickType]][data.clickChildIndex].metadata.name,
- type: data.rightClickType,
- schema: data.schema
- }
- }
- router.push(route)
- const add = {
- label: data.groupLists[data.clickIndex][typeFlag[data.rightClickType]][data.clickChildIndex].metadata.name,
- type: `Edit-${data.rightClickType}`,
- route
- }
- $bus.emit('AddTabs', add)
-}
-function openSecondaryDataModel(index, childIndex, type, schema) {
- const typeFlag = {
- 'topNAggregation': 'topn-agg',
- 'indexRule': 'index-rule',
- 'indexRuleBinding': 'index-rule-binding'
- }
- const group = data.groupLists[index][type][childIndex].metadata.group
- const name = data.groupLists[index][type][childIndex].metadata.name
- const route = {
- name: `${schema}-${typeFlag[type]}`,
- params: {
- group: group,
- name: name,
- operator: 'read',
- type: typeFlag[type]
- }
- }
- router.push(route)
- const add = {
- label: name,
- type: `Read-${typeFlag[type]}`,
- route
- }
- data.activeMenu = `${group}-${name}`
- $bus.emit('AddTabs', add)
-}
-function openCreateGroup() {
- data.setGroup = 'create'
- data.groupForm.catalog = groupTypeToCatalog[props.type]
- data.dialogGroupVisible = true
-}
-function openEditGroup() {
- data.groupForm.name = data.groupLists[data.clickIndex].metadata.name
- data.groupForm.catalog = data.groupLists[data.clickIndex].catalog
- data.groupForm.shardNum = data.groupLists[data.clickIndex].resourceOpts?.shardNum
- data.groupForm.segmentIntervalUnit = data.groupLists[data.clickIndex].resourceOpts?.segmentInterval?.unit
- data.groupForm.segmentIntervalNum = data.groupLists[data.clickIndex].resourceOpts?.segmentInterval?.num
- data.groupForm.ttlUnit = data.groupLists[data.clickIndex].resourceOpts?.ttl?.unit
- data.groupForm.ttlNum = data.groupLists[data.clickIndex].resourceOpts?.ttl?.num
- data.dialogGroupVisible = true
- data.setGroup = 'edit'
-}
-function openCreateResource() {
- const route = {
- name: `create-${props.type}`,
- params: {
- operator: 'create',
- group: data.groupLists[data.clickIndex].metadata.name,
- name: '',
- type: props.type
- }
- }
- router.push(route)
- const add = {
- label: data.groupLists[data.clickIndex].metadata.name,
- type: 'Create',
- route
- }
- data.activeMenu = ''
- $bus.emit('AddTabs', add)
-}
-function openEditResource() {
- const route = {
- name: `edit-${props.type}`,
- params: {
- operator: 'edit',
- group: data.groupLists[data.clickIndex].metadata.name,
- name: data.groupLists[data.clickIndex].children[data.clickChildIndex].metadata.name,
- type: props.type
- }
- }
- router.push(route)
- const add = {
- label: data.groupLists[data.clickIndex].children[data.clickChildIndex].metadata.name,
- type: 'Edit',
- route
- }
- $bus.emit('AddTabs', add)
-}
-function openDeletaDialog() {
- ElMessageBox.confirm('Are you sure to delete?')
- .then(() => {
- let group = data.groupLists[data.clickIndex].metadata.name
- if (data.rightClickType == 'group') {
- return deleteGroupFunction(group)
- } else if (data.rightClickType == 'index-rule') {
- return deleteSecondaryDataModelFunction("index-rule")
- } else if (data.rightClickType == 'index-rule-binding') {
- return deleteSecondaryDataModelFunction("index-rule-binding")
- } else if (data.rightClickType == 'topn-agg') {
- return deleteSecondaryDataModelFunction("topn-agg")
- }
- return deleteResource(group)
- })
- .catch(() => {
- // catch error
- })
-}
-function deleteSecondaryDataModelFunction(type) {
- $loadingCreate()
- const flag = {
- 'index-rule': 'indexRule',
- 'index-rule-binding': 'indexRuleBinding',
- 'topn-agg': 'topNAggregation'
- }
- let group = data.groupLists[data.clickIndex].metadata.name
- let name = data.groupLists[data.clickIndex][flag[type]][data.clickChildIndex].metadata.name
- deleteSecondaryDataModel(type, group, name)
- .then((res) => {
- if (res.status == 200) {
- if (res.data.deleted) {
- ElMessage({
- message: 'Delete succeeded',
- type: "success",
- duration: 5000
- })
- getGroupLists()
- $bus.emit('deleteResource', name)
- }
- }
- })
- .finally(() => {
- $loadingClose()
- })
-}
-function deleteGroupFunction(group) {
- // delete group
- $loadingCreate()
- deleteGroup(group)
- .then((res) => {
- if (res.status == 200) {
- if (res.data.deleted) {
- ElMessage({
- message: 'Delete succeeded',
- type: "success",
- duration: 5000
- })
- getGroupLists()
- }
- $bus.emit('deleteGroup', data.groupLists[data.clickIndex].metadata.name)
- }
- })
- .finally(() => {
- $loadingClose()
- })
-}
-function deleteResource(group) {
- let name = data.groupLists[data.clickIndex].children[data.clickChildIndex].metadata.name
- // delete Resources
- $loadingCreate()
- deleteStreamOrMeasure(props.type, group, name)
- .then((res) => {
- if (res.status == 200) {
- if (res.data.deleted) {
- ElMessage({
- message: 'Delete succeeded',
- type: "success",
- duration: 5000
- })
- getGroupLists()
- }
- $bus.emit('deleteResource', name)
- }
- })
- .finally(() => {
- $loadingClose()
- })
-}
-
-// create/edit group
-function confirmForm() {
- data.setGroup == 'create' ? createGroupFunction() : editGroupFunction()
-}
-function createGroupFunction() {
- ruleForm.value.validate((valid) => {
- if (valid) {
- let dataList = {
- group: {
- metadata: {
- group: "",
- name: data.groupForm.name
- },
- catalog: data.groupForm.catalog,
- resourceOpts: {
- shardNum: data.groupForm.shardNum,
- segmentInterval: {
- unit: data.groupForm.segmentIntervalUnit,
- num: data.groupForm.segmentIntervalNum
- },
- ttl: {
- unit: data.groupForm.ttlUnit,
- num: data.groupForm.ttlNum
- }
- }
- }
- }
- $loadingCreate()
- createGroup(dataList)
- .then((res) => {
- if (res.status == 200) {
- getGroupLists()
- ElMessage({
- message: 'Created successfully',
- type: "success",
- duration: 3000
- })
- }
- })
- .finally(() => {
- data.dialogGroupVisible = false
- $loadingClose()
- })
- }
- })
-}
-function editGroupFunction() {
- let name = data.groupLists[data.clickIndex].metadata.name
- ruleForm.value.validate((valid) => {
- if (valid) {
- let dataList = {
- group: {
- metadata: {
- group: "",
- name: data.groupForm.name
- },
- catalog: data.groupForm.catalog,
- resourceOpts: {
- shardNum: data.groupForm.shardNum,
- segmentInterval: {
- unit: data.groupForm.segmentIntervalUnit,
- num: data.groupForm.segmentIntervalNum
- },
- ttl: {
- unit: data.groupForm.ttlUnit,
- num: data.groupForm.ttlNum
- }
- }
- }
- }
- $loadingCreate()
- editGroup(name, dataList)
- .then((res) => {
- if (res.status == 200) {
- getGroupLists()
- ElMessage({
- message: 'Update succeeded',
- type: "success",
- duration: 3000
- })
- }
- })
- .finally(() => {
- data.dialogGroupVisible = false
- $loadingClose()
- })
- }
- })
-}
-function cancelCreateEditDialog() {
- clearGroupForm()
- data.dialogGroupVisible = false
-}
-// init form data
-function clearGroupForm() {
- data.groupForm = {
- name: null,
- catalog: 'CATALOG_STREAM',
- shardNum: 1,
- segmentIntervalUnit: "UNIT_DAY",
- segmentIntervalNum: 1,
- ttlUnit: "UNIT_DAY",
- ttlNum: 3
- }
-}
-function initActiveMenu() {
- const group = route.params.group
- const name = route.params.name
- if (group && name) {
-
- data.activeMenu = `${group}-${name}`
- }
-}
-// Eventbus, change isCollapse
-$bus.on('changeIsCollapse', (obj) => {
- data.isCollapse = obj.isCollapse
- emit('setWidth', obj.width)
-})
-$bus.on('changeAside', (obj) => {
- if (obj.group && obj.name)
- data.activeMenu = `${obj.group}-${obj.name}`
- else
- data.activeMenu = `${obj.group}`
-})
-$bus.on('resetAside', () => {
- data.activeMenu = ''
- router.push({
- name: `${props.type}Start`
- })
-})
-$bus.on('refreshAside', () => {
- getGroupLists()
-})
-getGroupLists()
-initActiveMenu()
-
-
-</script>
-
-<template>
- <div style="display: flex; flex-direction: column; width: 100%;">
- <div class="size flex" style="display: flex; flex-direction: column; width: 100%;">
- <el-input v-if="data.showSearch && props.type != 'stream'" class="aside-search" v-model="data.search"
- placeholder="Search" :prefix-icon="Search" clearable />
- <el-menu v-if="data.groupLists.length > 0" :collapse="data.isCollapse" :default-active="data.activeMenu">
- <div v-for="(item, index) in data.groupLists" :key="item.metadata.name"
- @contextmenu.prevent="rightClickGroup($event, index)">
- <el-menu-item v-if="props.type == 'property'" @click="openResources(index)"
- :index="`${item.metadata.name}`">
- <template #title>
- <el-icon>
- <Document />
- </el-icon>
- <span slot="title" :title="item.metadata.name" style="width: 70%" class="text-overflow-hidden">
- {{ item.metadata.name }}
- </span>
- </template>
- </el-menu-item>
- <el-sub-menu v-else :index="`${item.metadata.name}-${index}`">
- <template #title>
- <el-icon>
- <Folder />
- </el-icon>
- <span slot="title" :title="item.metadata.name" style="width: 70%" class="text-overflow-hidden">
- {{ item.metadata.name }}
- </span>
- </template>
- <el-sub-menu :index="`${item.metadata.name}-${index}-index-rule`"
- @contextmenu.prevent="rightClickIndexRule($event, index, props.type)">
- <template #title>
- <el-icon>
- <Folder />
- </el-icon>
- <span slot="title" title="Index-Rule" style="width: 70%" class="text-overflow-hidden">
- Index-Rule
- </span>
- </template>
- <div v-for="(child, childIndex) in item.indexRule" :key="child.metadata.name">
- <div @contextmenu.prevent="rightClickIndexRuleItem($event, index, childIndex, props.type)">
- <el-menu-item @click="openSecondaryDataModel(index, childIndex, 'indexRule', props.type)"
- :index="`${child.metadata.group}-${child.metadata.name}`">
- <template #title>
- <el-icon>
- <Document />
- </el-icon>
- <span slot="title" :title="child.metadata.name" style="width: 90%"
- class="text-overflow-hidden">
- {{ child.metadata.name }}
- </span>
- </template>
- </el-menu-item>
- </div>
- </div>
- </el-sub-menu>
- <el-sub-menu
- :index="`${item.metadata.name}-${index}-index-rule-binding`"
- @contextmenu.prevent="rightClickIndexRuleBinding($event, index, props.type)">
- <template #title>
- <el-icon>
- <Folder />
- </el-icon>
- <span slot="title" title="Index-Rule-Binding" style="width: 70%"
- class="text-overflow-hidden">
- Index-Rule-Binding
- </span>
- </template>
- <div v-for="(child, childIndex) in item.indexRuleBinding" :key="child.metadata.name">
- <div @contextmenu.prevent="rightClickIndexRuleBindingItem($event, index, childIndex, props.type)">
- <el-menu-item
- @click="openSecondaryDataModel(index, childIndex, 'indexRuleBinding', props.type)"
- :index="`${child.metadata.group}-${child.metadata.name}`">
- <template #title>
- <el-icon>
- <Document />
- </el-icon>
- <span slot="title" :title="child.metadata.name" style="width: 90%"
- class="text-overflow-hidden">
- {{ child.metadata.name }}
- </span>
- </template>
- </el-menu-item>
- </div>
- </div>
- </el-sub-menu>
- <el-sub-menu
- v-if="props.type == 'measure'"
- :index="`${item.metadata.name}-${index}-topn-agg`"
- @contextmenu.prevent="rightClickTopNAggregation($event, index, props.type)">
- <template #title>
- <el-icon>
- <Folder />
- </el-icon>
- <span slot="title" title="Top-N-Aggregation" style="width: 70%"
- class="text-overflow-hidden">
- Top-N-Aggregation
- </span>
- </template>
- <div v-for="(child, childIndex) in item.topNAggregation" :key="child.metadata.name">
- <div @contextmenu.prevent="rightClickTopNAggregationItem($event, index, childIndex, props.type)">
- <el-menu-item
- @click="openSecondaryDataModel(index, childIndex, 'topNAggregation', props.type)"
- :index="`${child.metadata.group}-${child.metadata.name}`">
- <template #title>
- <el-icon>
- <Document />
- </el-icon>
- <span slot="title" :title="child.metadata.name" style="width: 90%"
- class="text-overflow-hidden">
- {{ child.metadata.name }}
- </span>
- </template>
- </el-menu-item>
- </div>
- </div>
- </el-sub-menu>
- <el-sub-menu @contextmenu.prevent="rightClickResourcesFolder($event, index)"
- :index="`${item.metadata.name}-${index}-stream`">
- <template #title>
- <el-icon>
- <Folder />
- </el-icon>
- <span v-if="props.type == 'stream'" slot="title" title="Stream" style="width: 70%" class="text-overflow-hidden">
- Stream
- </span>
- <span v-if="props.type == 'measure'" slot="title" title="Measure" style="width: 70%" class="text-overflow-hidden">
- Measure
- </span>
- </template>
- <div v-for="(child, childIndex) in item.children" :key="child.metadata.name">
- <div @contextmenu.prevent="rightClickResources($event, index, childIndex)">
- <el-menu-item :index="`${child.metadata.group}-${child.metadata.name}`"
- @click="openResources(index, childIndex)">
- <template #title>
- <el-icon>
- <Document />
- </el-icon>
- <span slot="title" :title="child.metadata.name" style="width: 90%"
- class="text-overflow-hidden">
- {{ child.metadata.name }}
- </span>
- </template>
- </el-menu-item>
- </div>
- </div>
- </el-sub-menu>
- </el-sub-menu>
- </div>
- </el-menu>
- <div class="resize" @mousedown="shrinkDown" title="Shrink sidebar"></div>
- </div>
- <div class="flex center add" @click="openCreateGroup" style="height: 50px; width: 100%;"
- v-if="data.groupLists.length == 0">
- <el-icon>
- <Plus />
- </el-icon>
- </div>
- <el-dialog width="25%" center :title="`${data.setGroup} group`" v-model="data.dialogGroupVisible"
- :show-close="false">
- <el-form ref="ruleForm" :rules="rules" :model="data.groupForm" label-position="left">
- <el-form-item label="group name" :label-width="data.formLabelWidth" prop="name">
- <el-input :disabled="data.setGroup == 'edit'" v-model="data.groupForm.name" autocomplete="off">
- </el-input>
- </el-form-item>
- <el-form-item label="group type" :label-width="data.formLabelWidth" prop="catalog">
- <el-select v-model="data.groupForm.catalog" placeholder="please select" style="width: 100%">
- <el-option label="Stream" value="CATALOG_STREAM"></el-option>
- <el-option label="Measure" value="CATALOG_MEASURE"></el-option>
- <el-option label="Unspecified(Property)" value="CATALOG_UNSPECIFIED"></el-option>
- </el-select>
- </el-form-item>
- <el-form-item label="shard num" :label-width="data.formLabelWidth" prop="shardNum">
- <el-input-number v-model="data.groupForm.shardNum" :min="1" />
- </el-form-item>
- <el-form-item label="segment interval unit" :label-width="data.formLabelWidth" prop="segmentIntervalUnit">
- <el-select v-model="data.groupForm.segmentIntervalUnit" placeholder="please select" style="width: 100%">
- <el-option label="Hour" value="UNIT_HOUR"></el-option>
- <el-option label="Day" value="UNIT_DAY"></el-option>
- </el-select>
- </el-form-item>
- <el-form-item label="segment interval num" :label-width="data.formLabelWidth" prop="segmentIntervalNum">
- <el-input-number v-model="data.groupForm.segmentIntervalNum" :min="1" />
- </el-form-item>
- <el-form-item label="ttl unit" :label-width="data.formLabelWidth" prop="ttlUnit">
- <el-select v-model="data.groupForm.ttlUnit" placeholder="please select" style="width: 100%">
- <el-option label="Hour" value="UNIT_HOUR"></el-option>
- <el-option label="Day" value="UNIT_DAY"></el-option>
- </el-select>
- </el-form-item>
- <el-form-item label="ttl num" :label-width="data.formLabelWidth" prop="ttlNum">
- <el-input-number v-model="data.groupForm.ttlNum" :min="1" />
- </el-form-item>
- </el-form>
- <div slot="footer" class="dialog-footer footer">
- <el-button @click="cancelCreateEditDialog">cancel</el-button>
- <el-button type="primary" @click="confirmForm">{{ data.setGroup }}
- </el-button>
- </div>
- </el-dialog>
- <div v-if="data.showRightMenu" class="right-menu box-shadow"
- :style="{ top: `${data.top}px`, left: `${data.left}px` }">
- <RigheMenu @handleRightItem="handleRightItem" :rightMenuList="data.rightMenuList">
- </RigheMenu>
- </div>
- </div>
-</template>
-
-<style lang="scss" scoped>
-.aside-search {
- margin: 10px;
- width: calc(100% - 20px);
-}
-
-.el-menu {
- width: 100%;
- border-right: none;
- text-align: start;
- text-justify: middle;
-}
-
-.resize {
- cursor: col-resize;
- position: absolute;
- right: 0;
- height: 100%;
- width: 5px;
-}
-
-.right-menu {
- width: 170px;
- position: fixed;
- z-index: 9999999999999999999999999999 !important;
- background-color: white;
-}
-
-.footer {
- width: 100%;
- display: flex;
- justify-content: center;
-}
-
-.add {
- cursor: pointer;
-}
-</style>
\ No newline at end of file
diff --git a/ui/src/components/GroupTree/index.vue b/ui/src/components/GroupTree/index.vue
new file mode 100644
index 00000000..1995d640
--- /dev/null
+++ b/ui/src/components/GroupTree/index.vue
@@ -0,0 +1,850 @@
+<!--
+ ~ Licensed to Apache Software Foundation (ASF) under one or more contributor
+ ~ license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright
+ ~ ownership. Apache Software Foundation (ASF) licenses this file to you under
+ ~ the Apache License, Version 2.0 (the "License"); you may
+ ~ not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+-->
+
+<script setup>
+import { deleteSecondaryDataModel, getindexRuleList, getindexRuleBindingList, getGroupList, getTopNAggregationList, getStreamOrMeasureList, deleteStreamOrMeasure, deleteGroup, createGroup, editGroup } from '@/api/index'
+import { ElMessage, ElMessageBox } from 'element-plus'
+import { watch, getCurrentInstance } from "@vue/runtime-core"
+import { useRouter, useRoute } from 'vue-router'
+import { ref, reactive } from 'vue'
+import { Search } from '@element-plus/icons-vue'
+
+const router = useRouter()
+const route = useRoute()
+const { proxy } = getCurrentInstance()
+
+// ref
+const ruleForm = ref()
+const loading= ref(false)
+const treeRef = ref()
+const filterText = ref('')
+const currentNode = ref({})
+const resizable = ref()
+// Data
+const data = reactive({
+ groupLists: [],
+ isCollapse: false,
+ treeWidth: '100%',
+ // right menu
+ showOperationMenus: false,
+ operationMenus: [],
+ top: 0,
+ left: 0,
+ // create/edit group
+ dialogGroupVisible: false,
+ setGroup: 'create',
+ groupForm: {
+ name: null,
+ catalog: 'CATALOG_STREAM',
+ shardNum: 1,
+ segmentIntervalUnit: "UNIT_DAY",
+ segmentIntervalNum: 1,
+ ttlUnit: "UNIT_DAY",
+ ttlNum: 3
+ },
+ activeMenu: '',
+ formLabelWidth: "170px"
+})
+
+const defaultProps = {
+ children: 'children',
+ label: 'name',
+}
+
+const TargetTypes = {
+ Group: 'group',
+ Resources: 'resources'
+}
+// catalog to group type
+const catalogToGroupType = {
+ 'CATALOG_MEASURE': 'measure',
+ 'CATALOG_STREAM': 'stream',
+ 'CATALOG_UNSPECIFIED': 'property'
+}
+
+// group type to catalog
+const groupTypeToCatalog = {
+ 'measure': 'CATALOG_MEASURE',
+ 'stream': 'CATALOG_STREAM',
+ 'property': 'CATALOG_UNSPECIFIED'
+}
+
+const TypeMap = {
+ 'topNAggregation': 'topn-agg',
+ 'indexRule': 'index-rule',
+ 'indexRuleBinding': 'index-rule-binding',
+ 'children': 'children'
+}
+
+// rules
+const rules = {
+ name: [
+ {
+ required: true, message: 'Please enter the name of the group', trigger: 'blur'
+ }
+ ],
+ catalog: [
+ {
+ required: true, message: 'Please select the type of the group', trigger: 'blur'
+ }
+ ],
+ shardNum: [
+ {
+ required: true, message: 'Please select the shard num of the group', trigger: 'blur'
+ }
+ ],
+ segmentIntervalUnit: [
+ {
+ required: true, message: 'Please select the segment interval unit of the group', trigger: 'blur'
+ }
+ ],
+ segmentIntervalNum: [
+ {
+ required: true, message: 'Please select the segment Interval num of the group', trigger: 'blur'
+ }
+ ],
+ ttlUnit: [
+ {
+ required: true, message: 'Please select the ttl unit of the group', trigger: 'blur'
+ }
+ ],
+ ttlNum: [
+ {
+ required: true, message: 'Please select the ttl num of the group', trigger: 'blur'
+ }
+ ]
+}
+
+// Eventbus
+const $bus = getCurrentInstance().appContext.config.globalProperties.mittBus
+
+// props data
+const props = defineProps({
+ type: {
+ type: String,
+ required: true,
+ default: ''
+ }
+})
+
+// emit event
+const emit = defineEmits(['setWidth'])
+
+// init data
+function getGroupLists() {
+ filterText.value = ''
+ loading.value = true
+ getGroupList()
+ .then(res => {
+ if (res.status == 200) {
+ let group = res.data.group
+ data.groupLists = group
+ for (let i = 0; i < data.groupLists.length; i++) {
+ let type = catalogToGroupType[data.groupLists[i].catalog]
+ if (type !== props.type) {
+ data.groupLists.splice(i, 1)
+ i--
+ }
+ }
+ if (props.type == 'property') {
+ return
+ }
+ let promise = data.groupLists.map((item) => {
+ let type = props.type
+ let name = item.metadata.name
+ return new Promise((resolve, reject) => {
+ getStreamOrMeasureList(type, name)
+ .then(res => {
+ if (res.status == 200) {
+ item.children = res.data[type]
+ resolve()
+ }
+ })
+ .catch((err) => {
+ reject(err)
+ })
+ })
+ })
+ if (props.type == 'stream' || props.type == 'measure') {
+ let promiseIndexRule = data.groupLists.map((item) => {
+ let name = item.metadata.name
+ return new Promise((resolve, reject) => {
+ getindexRuleList(name)
+ .then(res => {
+ if (res.status == 200) {
+ item.indexRule = res.data.indexRule
+ resolve()
+ }
+ })
+ .catch((err) => {
+ reject(err)
+ })
+ })
+ })
+ let promiseIndexRuleBinding = data.groupLists.map((item) => {
+ let name = item.metadata.name
+ return new Promise((resolve, reject) => {
+ getindexRuleBindingList(name)
+ .then(res => {
+ if (res.status == 200) {
+ item.indexRuleBinding = res.data.indexRuleBinding
+ resolve()
+ }
+ })
+ .catch((err) => {
+ reject(err)
+ })
+ })
+ })
+ promise = promise.concat(promiseIndexRule)
+ promise = promise.concat(promiseIndexRuleBinding)
+ }
+ if (props.type == 'measure') {
+ let TopNAggregationRule = data.groupLists.map((item) => {
+ let name = item.metadata.name
+ return new Promise((resolve, reject) => {
+ getTopNAggregationList(name)
+ .then(res => {
+ if (res.status == 200) {
+ item.topNAggregation = res.data.topNAggregation
+ resolve()
+ }
+ })
+ .catch((err) => {
+ reject(err)
+ })
+ })
+ })
+ promise = promise.concat(TopNAggregationRule)
+ }
+ Promise.all(promise).then(() => {
+ data.groupLists = processGroupTree()
+ }).catch((err) => {
+ ElMessage({
+ message: 'An error occurred while obtaining group data. Please refresh and try again. Error: ' + err,
+ type: "error",
+ duration: 3000
+ })
+ }).finally(() => {
+ loading.value = false
+ })
+ }else{
+ loading.value = false
+ }
+ })
+}
+
+function processGroupTree() {
+ const trees = [];
+ for (const group of data.groupLists) {
+ const g = {
+ ...group.metadata,
+ children: [],
+ catalog: group.catalog,
+ type: TargetTypes.Group,
+ key: group.metadata.name,
+ icon: `el-icon-folder`
+ }
+ const keys = Object.keys(TypeMap);
+ for (const key of keys) {
+ if (group[key]) {
+ const n = key === 'children' ? props.type : key
+ const list = {
+ name: n.charAt(0).toUpperCase() + n.slice(1),
+ children: [],
+ type: n,
+ key: `${group.metadata.name}_${n}`,
+ group: group.metadata.name,
+ }
+ for (const item of group[key]) {
+ list.children.push({
+ ...item.metadata,
+ type: TargetTypes.Resources,
+ key: `${group.metadata.name}_${n}_${item.metadata.name}`,
+ parent: TypeMap[n] || n,
+ catalog: group.catalog,
+ resourceOpts: group.resourceOpts
+ })
+ }
+ g.children.push(list);
+ }
+ }
+ trees.push(g);
+ }
+ return trees;
+}
+
+// to resources
+function viewResources(node) {
+ currentNode.value = node;
+ if (node.type !== TargetTypes.Resources) {
+ return
+ }
+ const {name, group, parent} = node
+ const values = Object.values(TypeMap)
+
+ if (values.includes(parent)) {
+ const route = {
+ name: `${props.type}-${parent}`,
+ params: {
+ group: group,
+ name: name,
+ operator: 'read',
+ type: parent
+ }
+ }
+ router.push(route)
+ const add = {
+ label: name,
+ type: `Read-${parent}`,
+ route
+ }
+ data.activeMenu = `${group}-${name}`
+ return $bus.emit('AddTabs', add)
+ }
+ if (props.type == 'property') {
+ const route = {
+ name: 'property',
+ params: {
+ group: name,
+ operator: 'read',
+ type: props.type
+ }
+ }
+ router.push(route)
+ const add = {
+ label: name,
+ type: 'Read',
+ route
+ }
+ data.active = `${name}`
+ return $bus.emit('AddTabs', add)
+ }
+ const route = {
+ name: props.type,
+ params: {
+ group: group,
+ name: name,
+ operator: 'read',
+ type: props.type
+ }
+ }
+ router.push(route)
+ const add = {
+ label: name,
+ type: 'Read',
+ route
+ }
+ data.activeMenu = `${group}-${name}`
+ $bus.emit('AddTabs', add)
+}
+
+function openOperationMenus(e, node) {
+ currentNode.value = node
+ data.showOperationMenus = true
+ data.top = e.pageY
+ data.left = e.pageX
+ document.getElementById('app').onclick = closeRightMenu
+ e.stopPropagation()
+ const AllMenus = [
+ {label: 'Create', fn: createTarget},
+ {label: 'Edit', fn: editTarget},
+ {label: `Refresh`, fn: getGroupLists},
+ {label: 'Delete', fn: openDeleteDialog}
+ ]
+ if (node.type === TargetTypes.Group) {
+ data.operationMenus = AllMenus
+ return;
+ }
+ if (node.type === TargetTypes.Resources) {
+ data.operationMenus = [AllMenus[1], AllMenus[3]]
+ return;
+ }
+ data.operationMenus = [AllMenus[0]]
+ if (Object.keys(TypeMap).includes(currentNode.value.type)) {
+ data.operationMenus.push(AllMenus[3])
+ }
+}
+function closeRightMenu() {
+ data.showOperationMenus = false
+ document.getElementById('app').onclick = null
+}
+// CRUD operator
+function editTarget() {
+ if (currentNode.value.type === TargetTypes.Group) {
+ openEditGroup()
+ return
+ }
+ if (currentNode.value.type === TargetTypes.Resources && Object.values(TypeMap).includes(currentNode.value.parent)) {
+ openEditSecondaryDataModel()
+ return
+ }
+ openEditResource()
+}
+function createTarget() {
+ if (currentNode.value.type === TargetTypes.Group) {
+ openCreateGroup()
+ return
+ }
+ if (currentNode.value.type.toLowerCase() === props.type) {
+ openCreateResource()
+ return
+ }
+ openCreateSecondaryDataModel()
+}
+function openCreateSecondaryDataModel() {
+ const type = TypeMap[currentNode.value.type]
+ const route = {
+ name: `${props.type}-create-${type}`,
+ params: {
+ operator: 'create',
+ group: currentNode.value.group,
+ type,
+ schema: props.type
+ }
+ }
+ router.push(route)
+ const add = {
+ label: currentNode.value.group,
+ type: `Create-${type}`,
+ route
+ }
+ $bus.emit('AddTabs', add)
+}
+
+function openEditSecondaryDataModel() {
+ const type = currentNode.value.parent
+ const route = {
+ name: `${props.type}-edit-${type}`,
+ params: {
+ operator: 'edit',
+ group: currentNode.value.group,
+ name: currentNode.value.name,
+ type,
+ schema: props.type
+ }
+ }
+ router.push(route)
+ const add = {
+ label: currentNode.value.name,
+ type: `Edit-${type}`,
+ route
+ }
+ $bus.emit('AddTabs', add)
+}
+
+function openCreateGroup() {
+ data.setGroup = 'create'
+ data.groupForm.catalog = groupTypeToCatalog[props.type]
+ data.dialogGroupVisible = true
+}
+function openEditGroup() {
+ data.groupForm.name = currentNode.value.name
+ data.groupForm.catalog = currentNode.value.catalog
+ data.groupForm.shardNum = currentNode.value.resourceOpts?.shardNum
+ data.groupForm.segmentIntervalUnit = currentNode.value.resourceOpts?.segmentInterval?.unit
+ data.groupForm.segmentIntervalNum = currentNode.value.resourceOpts?.segmentInterval?.num
+ data.groupForm.ttlUnit = currentNode.value.resourceOpts?.ttl?.unit
+ data.groupForm.ttlNum = currentNode.value.resourceOpts?.ttl?.num
+ data.dialogGroupVisible = true
+ data.setGroup = 'edit'
+}
+function openCreateResource() {
+ const route = {
+ name: `create-${props.type}`,
+ params: {
+ operator: 'create',
+ group: currentNode.value.group,
+ type: props.type
+ }
+ }
+ router.push(route)
+ const add = {
+ label: currentNode.value.group,
+ type: 'Create',
+ route
+ }
+ $bus.emit('AddTabs', add)
+}
+function openEditResource() {
+ const route = {
+ name: `edit-${props.type}`,
+ params: {
+ operator: 'edit',
+ group: currentNode.value.group,
+ name: currentNode.value.name,
+ type: props.type
+ }
+ }
+ router.push(route)
+ const add = {
+ label: currentNode.value.name,
+ type: 'Edit',
+ route
+ }
+ $bus.emit('AddTabs', add)
+}
+
+function openDeleteDialog() {
+ ElMessageBox.confirm('Are you sure to delete?')
+ .then(() => {
+ if (Object.keys(TypeMap).includes(currentNode.value.type)) {
+ return deleteSecondaryDataModelFunction(TypeMap[currentNode.value.type])
+ }
+ if (type === TargetTypes.Group) {
+ return deleteGroupFunction()
+ }
+ return deleteResource()
+ })
+}
+function deleteSecondaryDataModelFunction(param) {
+ deleteSecondaryDataModel(param, currentNode.value.group, currentNode.value.type)
+ .then((res) => {
+ if (res.status == 200) {
+ if (res.data.deleted) {
+ ElMessage({
+ message: 'Delete succeeded',
+ type: "success",
+ duration: 5000
+ })
+ getGroupLists()
+ $bus.emit('deleteResource', currentNode.value.type)
+ }
+ }
+ })
+}
+function deleteGroupFunction() {
+ // delete group
+ deleteGroup(currentNode.value.name)
+ .then((res) => {
+ if (res.status == 200) {
+ if (res.data.deleted) {
+ ElMessage({
+ message: 'Delete succeeded',
+ type: "success",
+ duration: 5000
+ })
+ getGroupLists()
+ }
+ $bus.emit('deleteGroup', currentNode.value.name)
+ }
+ })
+}
+function deleteResource() {
+ // delete Resources
+ deleteStreamOrMeasure(props.type, currentNode.value.group, currentNode.value.name)
+ .then((res) => {
+ if (res.status == 200) {
+ if (res.data.deleted) {
+ ElMessage({
+ message: 'Delete succeeded',
+ type: "success",
+ duration: 5000
+ })
+ getGroupLists()
+ }
+ $bus.emit('deleteResource', currentNode.value.name)
+ }
+ })
+}
+
+// create/edit group
+function confirmForm() {
+ data.setGroup == 'create' ? createGroupFunction() : editGroupFunction()
+}
+function createGroupFunction() {
+ ruleForm.value.validate((valid) => {
+ if (valid) {
+ const dataList = {
+ group: {
+ metadata: {
+ group: "",
+ name: data.groupForm.name
+ },
+ catalog: data.groupForm.catalog,
+ resourceOpts: {
+ shardNum: data.groupForm.shardNum,
+ segmentInterval: {
+ unit: data.groupForm.segmentIntervalUnit,
+ num: data.groupForm.segmentIntervalNum
+ },
+ ttl: {
+ unit: data.groupForm.ttlUnit,
+ num: data.groupForm.ttlNum
+ }
+ }
+ }
+ }
+ createGroup(dataList)
+ .then((res) => {
+ if (res.status == 200) {
+ getGroupLists()
+ ElMessage({
+ message: 'Created successfully',
+ type: "success",
+ duration: 3000
+ })
+ }
+ })
+ .finally(() => {
+ data.dialogGroupVisible = false
+ })
+ }
+ })
+}
+function editGroupFunction() {
+ let name = data.groupLists[data.clickIndex].metadata.name
+ ruleForm.value.validate((valid) => {
+ if (valid) {
+ const dataList = {
+ group: {
+ metadata: {
+ group: "",
+ name: data.groupForm.name
+ },
+ catalog: data.groupForm.catalog,
+ resourceOpts: {
+ shardNum: data.groupForm.shardNum,
+ segmentInterval: {
+ unit: data.groupForm.segmentIntervalUnit,
+ num: data.groupForm.segmentIntervalNum
+ },
+ ttl: {
+ unit: data.groupForm.ttlUnit,
+ num: data.groupForm.ttlNum
+ }
+ }
+ }
+ }
+ editGroup(name, dataList)
+ .then((res) => {
+ if (res.status == 200) {
+ getGroupLists()
+ ElMessage({
+ message: 'Update succeeded',
+ type: "success",
+ duration: 3000
+ })
+ }
+ })
+ .finally(() => {
+ data.dialogGroupVisible = false
+ })
+ }
+ })
+}
+// init form data
+function clearGroupForm() {
+ data.dialogGroupVisible = false
+ data.groupForm = {
+ name: null,
+ catalog: 'CATALOG_STREAM',
+ shardNum: 1,
+ segmentIntervalUnit: "UNIT_DAY",
+ segmentIntervalNum: 1,
+ ttlUnit: "UNIT_DAY",
+ ttlNum: 3
+ }
+}
+function initActiveMenu() {
+ const group = route.params.group
+ const name = route.params.name
+ if (group && name) {
+
+ data.activeMenu = `${group}-${name}`
+ }
+}
+const filterNode = (value, data) => {
+ if (!value) return true
+ return data.name.includes(value)
+}
+function mouseDown(e) {
+ e.preventDefault();
+ document.addEventListener('mousemove', onMouseMove);
+ document.addEventListener('mouseup', onMouseUp);
+}
+
+function onMouseMove(e) {
+ e.preventDefault();
+ const newWidth = e.clientX - resizable.value.getBoundingClientRect().left;
+ if (newWidth < 60) {
+ return;
+ }
+ if (newWidth > 700) {
+ return;
+ }
+ data.treeWidth = `${newWidth}px`
+ emit('setWidth', String(newWidth))
+}
+
+function onMouseUp(e) {
+ e.preventDefault();
+ document.removeEventListener('mousemove', onMouseMove);
+ document.removeEventListener('mouseup', onMouseUp);
+}
+
+// Eventbus, change isCollapse
+$bus.on('resetAside', () => {
+ data.activeMenu = ''
+ router.push({
+ name: `${props.type}Start`
+ })
+})
+
+getGroupLists()
+initActiveMenu()
+
+watch(filterText, (val) => {
+ treeRef.value?.filter(val)
+})
+</script>
+
+<template>
+ <div :style="{display: 'flex', flexDirection: 'column', width: `${data.treeWidth}`, height: `100%`}" ref="resizable" >
+ <div style="display: flex; flex-direction: row; width: 100%; height: 100%; justify-content: space-between;">
+ <div class="size flex" style="display: flex; flex-direction: column; width: calc(100% - 10px); overflow: auto;">
+ <el-input v-if="props.type !== 'stream'" class="group-search" v-model="filterText"
+ placeholder="Search" :prefix-icon="Search" clearable />
+ <el-tree
+ ref="treeRef"
+ v-loading="loading"
+ :data="data.groupLists"
+ :props="defaultProps"
+ :filter-node-method="filterNode"
+ @node-click="viewResources"
+ @node-contextmenu="openOperationMenus"
+ class="group-tree"
+ icon=""
+ >
+ <template #default="{ _, data }">
+ <div class="node-icon">
+ <el-icon class="el-icon" v-if="data.type !== TargetTypes.Group">
+ <Histogram v-if="data.type===`${Object.keys(TypeMap)[0]}`" />
+ <Collection v-else-if="data.type===`${Object.keys(TypeMap)[1]}`" />
+ <Management v-else-if="data.type===`${Object.keys(TypeMap)[2]}`" />
+ <Tickets v-else-if="data.type=== TargetTypes.Resources" />
+ <DataAnalysis v-else />
+ </el-icon>
+ <div>{{ data.name }}</div>
+ </div>
+ </template>
+ </el-tree>
+ </div>
+ <div class="resizer" @mousedown="mouseDown"></div>
+ </div>
+ <el-dialog width="25%" center :title="`${data.setGroup} group`" v-model="data.dialogGroupVisible"
+ :show-close="false">
+ <el-form ref="ruleForm" :rules="rules" :model="data.groupForm" label-position="left">
+ <el-form-item label="group name" :label-width="data.formLabelWidth" prop="name">
+ <el-input :disabled="data.setGroup == 'edit'" v-model="data.groupForm.name" autocomplete="off">
+ </el-input>
+ </el-form-item>
+ <el-form-item label="group type" :label-width="data.formLabelWidth" prop="catalog">
+ <el-select v-model="data.groupForm.catalog" placeholder="please select" style="width: 100%">
+ <el-option label="Stream" value="CATALOG_STREAM"></el-option>
+ <el-option label="Measure" value="CATALOG_MEASURE"></el-option>
+ <el-option label="Unspecified(Property)" value="CATALOG_UNSPECIFIED"></el-option>
+ </el-select>
+ </el-form-item>
+ <el-form-item label="shard num" :label-width="data.formLabelWidth" prop="shardNum">
+ <el-input-number v-model="data.groupForm.shardNum" :min="1" />
+ </el-form-item>
+ <el-form-item label="segment interval unit" :label-width="data.formLabelWidth" prop="segmentIntervalUnit">
+ <el-select v-model="data.groupForm.segmentIntervalUnit" placeholder="please select" style="width: 100%">
+ <el-option label="Hour" value="UNIT_HOUR"></el-option>
+ <el-option label="Day" value="UNIT_DAY"></el-option>
+ </el-select>
+ </el-form-item>
+ <el-form-item label="segment interval num" :label-width="data.formLabelWidth" prop="segmentIntervalNum">
+ <el-input-number v-model="data.groupForm.segmentIntervalNum" :min="1" />
+ </el-form-item>
+ <el-form-item label="ttl unit" :label-width="data.formLabelWidth" prop="ttlUnit">
+ <el-select v-model="data.groupForm.ttlUnit" placeholder="please select" style="width: 100%">
+ <el-option label="Hour" value="UNIT_HOUR"></el-option>
+ <el-option label="Day" value="UNIT_DAY"></el-option>
+ </el-select>
+ </el-form-item>
+ <el-form-item label="ttl num" :label-width="data.formLabelWidth" prop="ttlNum">
+ <el-input-number v-model="data.groupForm.ttlNum" :min="1" />
+ </el-form-item>
+ </el-form>
+ <div slot="footer" class="dialog-footer footer">
+ <el-button @click="clearGroupForm">cancel</el-button>
+ <el-button type="primary" @click="confirmForm">{{ data.setGroup }}
+ </el-button>
+ </div>
+ </el-dialog>
+ <div v-if="data.showOperationMenus" class="right-menu box-shadow" :style="{ top: `${data.top}px`, left: `${data.left}px` }">
+ <div v-for="m in data.operationMenus" @click="m.fn">{{ m.label }}</div>
+ </div>
+ </div>
+</template>
+
+<style lang="scss" scoped>
+.group-search {
+ margin: 20px 0 0 10px;
+ width: calc(100% - 15px);
+}
+
+.group-tree {
+ padding-top: 10px;
+}
+
+.resizer {
+ width: 5px;
+ cursor: ew-resize;
+ background-color: #bbb;
+ height: 100%;
+}
+
+.right-menu {
+ width: 120px;
+ position: fixed;
+ z-index: 9999 !important;
+ padding: 10px;
+ font-size: 14px;
+ div {
+ height: 30px;
+ line-height: 30px;
+ padding-left: 20px;
+ cursor: pointer;
+ &:hover {
+ background-color: #eee;
+ }
+
+ }
+}
+
+.footer {
+ width: 100%;
+ display: flex;
+ justify-content: center;
+}
+
+.node-icon {
+ display: flex;
+ flex-direction: row;
+}
+
+.el-icon {
+ height: 20px;
+ line-height: 20px;
+ margin-right: 10px;
+}
+</style>
\ No newline at end of file
diff --git a/ui/src/components/Header/components/header.vue b/ui/src/components/Header/components/header.vue
index 1df66364..059faf52 100644
--- a/ui/src/components/Header/components/header.vue
+++ b/ui/src/components/Header/components/header.vue
@@ -19,7 +19,7 @@
<script setup>
import { reactive } from "vue";
-import { ElImage, ElTooltip, ElMenu, ElMenuItem } from 'element-plus'
+import { ElImage, ElMenu, ElMenuItem } from 'element-plus'
import { useRoute } from 'vue-router'
import { watch, getCurrentInstance } from '@vue/runtime-core'
import userImg from '@/assets/banyandb_small.jpg'
@@ -33,8 +33,6 @@ const route = useRoute()
// data
const data = reactive({
activeMenu: '/banyandb/dashboard',
- isCollapse: false,
- showButton: false
})
// watch
@@ -45,34 +43,13 @@ watch(() => route, () => {
immediate: true,
deep: true
})
-watch(() => data.activeMenu, () => {
- data.showButton = data.activeMenu == '/banyandb/stream' || data.activeMenu == '/banyandb/measure' ? true : false
-}, {
- immediate: true,
- deep: true
-})
// function
function initData() {
let arr = route.path.split('/')
data.activeMenu = `/${arr[1]}/${arr[2]}`
}
-function changeAsideWidth() {
- if (data.isCollapse) {
- $bus.emit('changeIsCollapse', {
- isCollapse: false,
- width: '200px'
- })
- } else {
- $bus.emit('changeIsCollapse', {
- isCollapse: true,
- width: '65px'
- })
- }
-}
-$bus.on('changeIsCollapse', (obj) => {
- data.isCollapse = obj.isCollapse
-})
+
initData()
</script>
@@ -85,19 +62,6 @@ initData()
</div>
</el-image>
<div class="title text-main-color text-title text-family text-weight-lt">BanyanDB Manager</div>
- <!-- open aside menu -->
- <div class="flex center pointer icon-size" v-if="data.showButton" @click="changeAsideWidth">
- <el-tooltip class="item" effect="dark" :content="!data.isCollapse ? 'Collapse menu' : 'Expand menu'"
- placement="bottom">
- <el-icon v-if="!data.isCollapse" class="icon">
- <Fold />
- </el-icon>
- <el-icon class="icon" v-else>
- <Expand />
- </el-icon>
- </el-tooltip>
- </div>
- <div v-else class="icon-size"></div>
<!-- stream/measure sources url -->
<div style="width:380px;" class="margin-left-small"></div>
</div>
diff --git a/ui/src/components/RightMenu/components/right-menu-item.vue b/ui/src/components/RightMenu/components/right-menu-item.vue
deleted file mode 100644
index b9b1ed29..00000000
--- a/ui/src/components/RightMenu/components/right-menu-item.vue
+++ /dev/null
@@ -1,67 +0,0 @@
-<!--
- ~ Licensed to Apache Software Foundation (ASF) under one or more contributor
- ~ license agreements. See the NOTICE file distributed with
- ~ this work for additional information regarding copyright
- ~ ownership. Apache Software Foundation (ASF) licenses this file to you under
- ~ the Apache License, Version 2.0 (the "License"); you may
- ~ not use this file except in compliance with the License.
- ~ You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing,
- ~ software distributed under the License is distributed on an
- ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- ~ KIND, either express or implied. See the License for the
- ~ specific language governing permissions and limitations
- ~ under the License.
--->
-
-<script setup>
-defineProps({
- icon: String,
- name: String
-})
-</script>
-
-<template>
- <div class="flex right-menu-item align-item-center pointer" @click="$emit('handleRightItem')">
- <i :class="icon"></i>
- <el-icon>
- <Folder v-if="icon === 'el-icon-folder'" />
- <Document v-if="icon === 'el-icon-document'" />
- <RefreshRight v-if="icon === 'el-icon-refresh-right'" />
- <Delete v-if="icon === 'el-icon-delete'" />
- </el-icon>
- <div style="width: 70%;" class="text-overflow-hidden margin-left-small">
- <span :title="name">{{ name }}</span>
- </div>
- </div>
-</template>
-
-<style lang="scss" scoped>
-.right-menu-item {
- padding: 3px 6px 3px 6px;
- width: calc(100% - 12px);
- line-height: 30px;
- height: 30px;
- text-align: start;
- background-color: white;
- color: var(--color-main-font);
-
- &:hover {
- background-color: #ecf5ff;
- color: var(--color-main);
- }
-}
-
-i {
- font-size: 20px;
- line-height: 30px;
- height: 30px;
-
- &:hover {
- color: var(--color-main);
- }
-}
-</style>
\ No newline at end of file
diff --git a/ui/src/components/RightMenu/index.vue b/ui/src/components/RightMenu/index.vue
deleted file mode 100644
index 5bd9b9b5..00000000
--- a/ui/src/components/RightMenu/index.vue
+++ /dev/null
@@ -1,38 +0,0 @@
-<!--
- ~ Licensed to Apache Software Foundation (ASF) under one or more contributor
- ~ license agreements. See the NOTICE file distributed with
- ~ this work for additional information regarding copyright
- ~ ownership. Apache Software Foundation (ASF) licenses this file to you under
- ~ the Apache License, Version 2.0 (the "License"); you may
- ~ not use this file except in compliance with the License.
- ~ You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing,
- ~ software distributed under the License is distributed on an
- ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- ~ KIND, either express or implied. See the License for the
- ~ specific language governing permissions and limitations
- ~ under the License.
--->
-
-<script setup>
-import RightMenuItem from './components/right-menu-item.vue'
-defineProps({
- rightMenuList: Array
-})
-</script>
-
-<template>
- <div style="width: 100%;" class="border-radius-little">
- <div style="width: 100%;" v-for="(item, index) in rightMenuList" :key="item.name">
- <right-menu-item @handleRightItem="$emit('handleRightItem', index)" :icon="item.icon" :name="item.name">
- </right-menu-item>
- </div>
- </div>
-</template>
-
-<style lang="scss" scoped>
-
-</style>
\ No newline at end of file
diff --git a/ui/src/components/TopNav/index.vue b/ui/src/components/TopNav/index.vue
index c24d2208..b0623b83 100644
--- a/ui/src/components/TopNav/index.vue
+++ b/ui/src/components/TopNav/index.vue
@@ -47,7 +47,7 @@ function removeTab(index) {
return
}
data.tabsList.splice(index, 1)
- if (activeTabIndex != 0) {
+ if (activeTabIndex) {
data.activeTabIndex--
}
router.push(data.tabsList[data.activeTabIndex].route)
diff --git a/ui/src/views/Measure/index.vue b/ui/src/views/Measure/index.vue
index 752494ec..8f9f0bd2 100644
--- a/ui/src/views/Measure/index.vue
+++ b/ui/src/views/Measure/index.vue
@@ -18,7 +18,7 @@
-->
<script setup>
-import Aside from '@/components/Aside/index.vue'
+import GroupTree from '@/components/GroupTree/index.vue'
import TopNav from '@/components/TopNav/index.vue'
import { reactive } from 'vue';
@@ -35,7 +35,7 @@ function setWidth(width) {
<div class="size">
<el-container>
<el-aside :width="data.width" class="bd-top flex" style="position:relative; background-color: white;">
- <Aside type="measure" @setWidth="setWidth"></Aside>
+ <GroupTree type="measure" @setWidth="setWidth" />
</el-aside>
<el-main>
<TopNav></TopNav>
diff --git a/ui/src/views/Property/index.vue b/ui/src/views/Property/index.vue
index 4f66dcb8..3dae1df2 100644
--- a/ui/src/views/Property/index.vue
+++ b/ui/src/views/Property/index.vue
@@ -18,7 +18,7 @@
-->
<script setup>
-import Aside from '@/components/Aside/index.vue'
+import GroupTree from '@/components/GroupTree/index.vue'
import TopNav from '@/components/TopNav/index.vue'
import { reactive } from 'vue';
@@ -35,7 +35,7 @@ function setWidth(width) {
<div class="size">
<el-container>
<el-aside :width="data.width" class="bd-top flex" style="position:relative; background-color: white;">
- <Aside type="property" @setWidth="setWidth"></Aside>
+ <GroupTree type="property" @setWidth="setWidth" />
</el-aside>
<el-main>
<TopNav></TopNav>
diff --git a/ui/src/views/Stream/index.vue b/ui/src/views/Stream/index.vue
index 0a1a093b..76b8229c 100644
--- a/ui/src/views/Stream/index.vue
+++ b/ui/src/views/Stream/index.vue
@@ -18,7 +18,7 @@
-->
<script setup>
-import Aside from '@/components/Aside/index.vue'
+import GroupTree from '@/components/GroupTree/index.vue'
import TopNav from '@/components/TopNav/index.vue'
import { reactive } from 'vue';
@@ -35,7 +35,7 @@ function setWidth(width) {
<div class="size">
<el-container>
<el-aside :width="data.width" class="bd-top flex box-shadow" style="position:relative; background-color: white;">
- <Aside type="stream" @setWidth="setWidth"></Aside>
+ <GroupTree type="stream" @setWidth="setWidth" />
</el-aside>
<el-main>
<TopNav></TopNav>