feat: add Tab on the dashboard

This commit is contained in:
Qiuxia Fan 2022-01-07 15:19:30 +08:00
parent edda37078a
commit 59ea77d65c
13 changed files with 201 additions and 105 deletions

View File

@ -0,0 +1,18 @@
<!-- Licensed to the 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.
The 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. -->
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
<title>all_inbox</title>
<path d="M15 15.984h6v3q0 0.797-0.609 1.406t-1.406 0.609h-13.969q-0.797 0-1.406-0.609t-0.609-1.406v-3h6q0 1.219 0.891 2.109t2.109 0.891 2.109-0.891 0.891-2.109zM18.984 9v-3.984h-13.969v3.984h3.984q0 1.219 0.891 2.109t2.109 0.891 2.109-0.891 0.891-2.109h3.984zM18.984 3q0.797 0 1.406 0.609t0.609 1.406v6.984q0 0.797-0.609 1.406t-1.406 0.609h-13.969q-0.797 0-1.406-0.609t-0.609-1.406v-6.984q0-0.797 0.609-1.406t1.406-0.609h13.969z"></path>
</svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -0,0 +1,18 @@
<!-- Licensed to the 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.
The 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. -->
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
<title>insert_image</title>
<path d="M8.484 13.5l-3.469 4.5h13.969l-4.5-6-3.469 4.5zM21 18.984q0 0.797-0.609 1.406t-1.406 0.609h-13.969q-0.797 0-1.406-0.609t-0.609-1.406v-13.969q0-0.797 0.609-1.406t1.406-0.609h13.969q0.797 0 1.406 0.609t0.609 1.406v13.969z"></path>
</svg>

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -0,0 +1,18 @@
<!-- Licensed to the 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.
The 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. -->
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
<title>library_add</title>
<path d="M18.984 11.016v-2.016h-3.984v-3.984h-2.016v3.984h-3.984v2.016h3.984v3.984h2.016v-3.984h3.984zM20.016 2.016q0.797 0 1.383 0.586t0.586 1.383v12q0 0.797-0.586 1.406t-1.383 0.609h-12q-0.797 0-1.406-0.609t-0.609-1.406v-12q0-0.797 0.609-1.383t1.406-0.586h12zM3.984 6v14.016h14.016v1.969h-14.016q-0.797 0-1.383-0.586t-0.586-1.383v-14.016h1.969z"></path>
</svg>

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -49,6 +49,34 @@ export const dashboardStore = defineStore({
w: 24, w: 24,
h: 12, h: 12,
i: String(this.layout.length), i: String(this.layout.length),
type: "Widget",
widget: {},
graph: {},
standard: {},
};
this.layout = this.layout.map((d: LayoutConfig) => {
d.y = d.y + newWidget.h;
return d;
});
this.layout.push(newWidget);
},
addTab() {
const newWidget: LayoutConfig = {
x: 0,
y: 0,
w: 24,
h: 12,
i: String(this.layout.length),
type: "Tab",
children: [
{
name: "Tab1",
children: [],
},
],
widget: {},
graph: {},
standard: {},
}; };
this.layout = this.layout.map((d: LayoutConfig) => { this.layout = this.layout.map((d: LayoutConfig) => {
d.y = d.y + newWidget.h; d.y = d.y + newWidget.h;

View File

@ -14,8 +14,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import { LayoutConfig } from "@/types/dashboard"; export const ConfigData = {
export const ConfigData: LayoutConfig = {
x: 0, x: 0,
y: 0, y: 0,
w: 8, w: 8,
@ -23,7 +22,7 @@ export const ConfigData: LayoutConfig = {
i: "0", i: "0",
metrics: ["service_resp_time"], metrics: ["service_resp_time"],
queryMetricType: "readMetricsValues", queryMetricType: "readMetricsValues",
chart: "Line", type: "Widget",
widget: { widget: {
title: "Title123", title: "Title123",
tips: "Tooltip123", tips: "Tooltip123",
@ -31,6 +30,7 @@ export const ConfigData: LayoutConfig = {
graph: { graph: {
showBackground: true, showBackground: true,
barWidth: 30, barWidth: 30,
type: "Line",
}, },
standard: { standard: {
sortOrder: "DEC", sortOrder: "DEC",

View File

@ -20,12 +20,13 @@ export interface LayoutConfig {
w: number; w: number;
h: number; h: number;
i: string; i: string;
widget?: WidgetConfig; widget: WidgetConfig;
graph?: GraphConfig; graph: GraphConfig;
standard?: StandardConfig; standard: StandardConfig;
metrics?: string[]; metrics?: string[];
chart?: string; type?: string;
queryMetricType?: string; queryMetricType?: string;
children?: any[];
} }
export interface WidgetConfig { export interface WidgetConfig {
@ -34,6 +35,7 @@ export interface WidgetConfig {
} }
export interface GraphConfig { export interface GraphConfig {
type?: string;
showBackground?: boolean; showBackground?: boolean;
barWidth?: number; barWidth?: number;
} }

View File

@ -98,7 +98,6 @@ import { ValuesTypes, MetricQueryTypes, ChartTypes } from "../data";
import { Option } from "@/types/app"; import { Option } from "@/types/app";
import Loading from "@/utils/loading"; import Loading from "@/utils/loading";
import graphs from "../graphs"; import graphs from "../graphs";
import controls from "../controls";
import configs from "./graph-styles"; import configs from "./graph-styles";
import WidgetOptions from "./WidgetOptions.vue"; import WidgetOptions from "./WidgetOptions.vue";
import StandardOptions from "./StandardOptions.vue"; import StandardOptions from "./StandardOptions.vue";
@ -107,7 +106,6 @@ export default defineComponent({
name: "ConfigEdit", name: "ConfigEdit",
components: { components: {
...graphs, ...graphs,
...controls,
...configs, ...configs,
WidgetOptions, WidgetOptions,
StandardOptions, StandardOptions,
@ -135,7 +133,7 @@ export default defineComponent({
valueTypes: [], valueTypes: [],
valueType: "", valueType: "",
metricQueryType: "", metricQueryType: "",
chartType: selectedWidget.chart, chartType: selectedWidget.graph.type,
activeNames: "1", activeNames: "1",
source: {}, source: {},
index: selectedWidget.i, index: selectedWidget.i,

View File

@ -13,8 +13,11 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. --> limitations under the License. -->
<template> <template>
<div v-if="data.children.length">
<div class="tabs"> <div class="tabs">
<span v-for="(item, idx) in data" :key="idx">{{ item.name }}</span> <span v-for="(item, idx) in data.children || []" :key="idx">{{
item.name
}}</span>
</div> </div>
<grid-layout <grid-layout
v-model:layout="state.layout" v-model:layout="state.layout"
@ -36,24 +39,41 @@ limitations under the License. -->
<Widget :item="item" /> <Widget :item="item" />
</grid-item> </grid-item>
</grid-layout> </grid-layout>
</div>
<div class="tabs" v-else>Please add Widgets</div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { defineProps, reactive } from "vue"; import { defineProps, reactive } from "vue";
import type { PropType } from "vue"; import type { PropType } from "vue";
import Widget from "../panel/Widget.vue"; import Widget from "./Widget.vue";
import { LayoutConfig } from "@/types/dashboard"; import { LayoutConfig } from "@/types/dashboard";
defineProps({ defineProps({
data: { type: Array as PropType<{ name: string }[]>, default: () => [] }, data: {
type: Object as PropType<{ type: string; children: any[] }>,
default: () => ({ children: [] }),
},
}); });
const state = reactive<{ layout: any }>({ const state = reactive<{ layout: any }>({
layout: {}, layout: [],
}); });
function layoutUpdatedEvent(newLayout: LayoutConfig) { function layoutUpdatedEvent(newLayout: LayoutConfig) {
state.layout = newLayout; state.layout = newLayout;
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.tabs {
height: 30px;
border-bottom: 1px solid #eee;
span {
display: inline-block;
width: auto;
padding: 5px 10px;
border-right: 1px solid #ccc;
}
}
.vue-grid-layout { .vue-grid-layout {
background: #f7f9fa; background: #f7f9fa;
height: auto !important; height: auto !important;

View File

@ -15,7 +15,7 @@ limitations under the License. -->
<template> <template>
<div class="widget"> <div class="widget">
<div class="header flex-h"> <div class="header flex-h">
<div>{{ item.widget.title || "" }}</div> <div>{{ data.widget.title || "" }}</div>
<div class="operations"> <div class="operations">
<Icon <Icon
class="mr-5" class="mr-5"
@ -28,7 +28,7 @@ limitations under the License. -->
</div> </div>
<div class="body" :style="{ height: '200px', width: '400px' }"> <div class="body" :style="{ height: '200px', width: '400px' }">
<component <component
:is="item.chart" :is="data.graph.type"
:intervalTime="appStoreWithOut.intervalTime" :intervalTime="appStoreWithOut.intervalTime"
:data="state.source" :data="state.source"
/> />
@ -47,7 +47,7 @@ import Loading from "@/utils/loading";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
const props = { const props = {
item: { data: {
type: Object as PropType<LayoutConfig>, type: Object as PropType<LayoutConfig>,
default: () => ({ widget: {} }), default: () => ({ widget: {} }),
}, },
@ -62,7 +62,7 @@ export default defineComponent({
const state = reactive({ const state = reactive({
source: {}, source: {},
}); });
const { item } = toRefs(props); const { data } = toRefs(props);
const appStoreWithOut = useAppStoreWithOut(); const appStoreWithOut = useAppStoreWithOut();
const dashboardStore = useDashboardStore(); const dashboardStore = useDashboardStore();
queryMetrics(); queryMetrics();
@ -71,7 +71,7 @@ export default defineComponent({
text: t("loading"), text: t("loading"),
fullscreen: false, fullscreen: false,
}); });
const json = await dashboardStore.fetchMetricValue(props.item); const json = await dashboardStore.fetchMetricValue(props.data);
loadingInstance.close(); loadingInstance.close();
if (json.error) { if (json.error) {
@ -81,7 +81,7 @@ export default defineComponent({
const metricVal = json.data.readMetricsValues.values.values.map( const metricVal = json.data.readMetricsValues.values.values.map(
(d: any) => d.value (d: any) => d.value
); );
const m = props.item.metrics && props.item.metrics[0]; const m = props.data.metrics && props.data.metrics[0];
if (!m) { if (!m) {
return; return;
} }
@ -91,18 +91,18 @@ export default defineComponent({
} }
function removeWidget() { function removeWidget() {
dashboardStore.removeWidget(item); dashboardStore.removeWidget(data);
} }
function setConfig() { function setConfig() {
dashboardStore.setConfigPanel(true); dashboardStore.setConfigPanel(true);
dashboardStore.selectWidget(item); dashboardStore.selectWidget(data);
} }
return { return {
state, state,
appStoreWithOut, appStoreWithOut,
removeWidget, removeWidget,
setConfig, setConfig,
item, data,
}; };
}, },
}); });

View File

@ -1,24 +0,0 @@
/**
* Licensed to the 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.
* The 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.
*/
import Image from "./Image.vue";
import Tabs from "./Tabs.vue";
export default {
Image,
Tabs,
};

View File

@ -25,8 +25,8 @@ export const ChartTypes = [
{ label: "Table", value: "Table" }, { label: "Table", value: "Table" },
{ label: "Endpoint List", value: "EndpointList" }, { label: "Endpoint List", value: "EndpointList" },
{ label: "Instance List", value: "InstanceList" }, { label: "Instance List", value: "InstanceList" },
{ label: "Image", value: "Image" }, // { label: "Image", value: "Image" },
{ label: "Tab", value: "Tabs" }, // { label: "Tab", value: "Tabs" },
]; ];
export enum MetricQueryTypes { export enum MetricQueryTypes {
ReadMetricsValue = "readMetricsValue", ReadMetricsValue = "readMetricsValue",
@ -120,6 +120,15 @@ export const SortOrder = [
{ label: "DES", value: "DES" }, { label: "DES", value: "DES" },
{ label: "ASC", value: "ASC" }, { label: "ASC", value: "ASC" },
]; ];
export const ToolIcons = [
{ name: "playlist_add", content: "Add Widget", id: "addWidget" },
{ name: "all_inbox", content: "Add Tab", id: "addTab" },
{ name: "insert_image", content: "Add Image", id: "addImage" },
{ name: "save_alt", content: "Export", id: "export" },
{ name: "folder_open", content: "Import", id: "import" },
{ name: "settings", content: "Settings", id: "settings" },
{ name: "save", content: "Apply", id: "applay" },
];
export const Options = [ export const Options = [
{ {
value: "Option1", value: "Option1",

View File

@ -30,19 +30,30 @@ limitations under the License. -->
:i="item.i" :i="item.i"
:key="item.i" :key="item.i"
> >
<Widget :item="item" /> <component :is="item.type" :data="item" />
</grid-item> </grid-item>
</grid-layout> </grid-layout>
</template> </template>
<script lang="ts" setup> <script lang="ts">
import { defineComponent } from "vue";
import { useDashboardStore } from "@/store/modules/dashboard"; import { useDashboardStore } from "@/store/modules/dashboard";
import { LayoutConfig } from "@/types/dashboard"; import { LayoutConfig } from "@/types/dashboard";
import Widget from "./Widget.vue"; import Widget from "../controls/Widget.vue";
import Tab from "../controls/Tab.vue";
const dashboardStore = useDashboardStore(); export default defineComponent({
function layoutUpdatedEvent(newLayout: LayoutConfig) { name: "Layout",
components: { Widget, Tab },
setup() {
const dashboardStore = useDashboardStore();
function layoutUpdatedEvent(newLayout: LayoutConfig) {
dashboardStore.setLayout(newLayout); dashboardStore.setLayout(newLayout);
} }
return {
dashboardStore,
layoutUpdatedEvent,
};
},
});
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.vue-grid-layout { .vue-grid-layout {

View File

@ -62,33 +62,14 @@ limitations under the License. -->
</div> </div>
<div class="tool-icons"> <div class="tool-icons">
<el-tooltip <el-tooltip
v-for="(t, index) in ToolIcons"
:key="index"
class="item" class="item"
effect="dark" :content="t.content"
content="Add Widget"
placement="top" placement="top"
> >
<span class="icon-btn" @click="dashboardStore.addWidget"> <span class="icon-btn" @click="clickIcons(t)">
<Icon size="sm" iconName="playlist_add" /> <Icon size="sm" :iconName="t.name" />
</span>
</el-tooltip>
<el-tooltip class="item" effect="dark" content="Settings" placement="top">
<span class="icon-btn" @click="dashboardStore.setConfigPanel(true)">
<Icon size="sm" iconName="settings" />
</span>
</el-tooltip>
<el-tooltip class="item" effect="dark" content="Import" placement="top">
<span class="icon-btn">
<Icon size="sm" iconName="folder_open" />
</span>
</el-tooltip>
<el-tooltip class="item" effect="dark" content="Export" placement="top">
<span class="icon-btn">
<Icon size="sm" iconName="save_alt" />
</span>
</el-tooltip>
<el-tooltip class="item" effect="dark" content="Apply" placement="top">
<span class="icon-btn">
<Icon size="sm" iconName="save" />
</span> </span>
</el-tooltip> </el-tooltip>
</div> </div>
@ -100,7 +81,7 @@ import { reactive } from "vue";
import { useRoute } from "vue-router"; import { useRoute } from "vue-router";
import { ElTooltip, ElCascader } from "element-plus"; import { ElTooltip, ElCascader } from "element-plus";
import { useDashboardStore } from "@/store/modules/dashboard"; import { useDashboardStore } from "@/store/modules/dashboard";
import { Options, SelectOpts, EntityType } from "../data"; import { Options, SelectOpts, EntityType, ToolIcons } from "../data";
const dashboardStore = useDashboardStore(); const dashboardStore = useDashboardStore();
const params = useRoute().params; const params = useRoute().params;
@ -128,11 +109,28 @@ dashboardStore.setEntity(states.entity);
function changeService(val: { value: string; label: string }) { function changeService(val: { value: string; label: string }) {
states.service = val.value; states.service = val.value;
} }
function clickIcons(t: { id: string; content: string; name: string }) {
switch (t.id) {
case "addWidget":
dashboardStore.addWidget();
break;
case "addTab":
dashboardStore.addTab();
break;
case "addImage":
dashboardStore.addWidget();
break;
case "settings":
dashboardStore.setConfigPanel(true);
break;
}
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.dashboard-tool { .dashboard-tool {
text-align: right; text-align: right;
padding: 5px 10px; padding: 5px;
background: rgb(240, 242, 245); background: rgb(240, 242, 245);
border-bottom: 1px solid #dfe4e8; border-bottom: 1px solid #dfe4e8;
justify-content: space-between; justify-content: space-between;
@ -153,7 +151,7 @@ function changeService(val: { value: string; label: string }) {
text-align: center; text-align: center;
border: 1px solid #ccc; border: 1px solid #ccc;
border-radius: 3px; border-radius: 3px;
margin-left: 8px; margin-left: 6px;
cursor: pointer; cursor: pointer;
background-color: #eee; background-color: #eee;
color: #666; color: #666;