未验证 提交 b35fb063 编写于 作者: Q Qiuxia Fan 提交者: GitHub

Feat: Create a dashboard template using the default template (#326)

上级 3a44ace6
...@@ -28,7 +28,7 @@ const m = { ...@@ -28,7 +28,7 @@ const m = {
currentEndpoint: 'Current Endpoint', currentEndpoint: 'Current Endpoint',
currentInstance: 'Current Instance', currentInstance: 'Current Instance',
currentDatabase: 'Current Database', currentDatabase: 'Current Database',
templateConfig: 'Template Config', templateConfig: 'Template Configuration',
copy: 'Copy', copy: 'Copy',
reset: 'Reset', reset: 'Reset',
apply: 'Apply', apply: 'Apply',
......
...@@ -39,7 +39,7 @@ limitations under the License. --> ...@@ -39,7 +39,7 @@ limitations under the License. -->
</router-link> </router-link>
<router-link class="nav-link mr-20" to="/profile"> <router-link class="nav-link mr-20" to="/profile">
<svg class="icon sm vm"> <svg class="icon sm vm">
<use xlink:href="#merge"></use> <use xlink:href="#timeline"></use>
</svg> </svg>
<span class="vm hide-xs ml-5">{{ this.$t('profile') }}</span> <span class="vm hide-xs ml-5">{{ this.$t('profile') }}</span>
</router-link> </router-link>
......
...@@ -23,6 +23,7 @@ export interface State { ...@@ -23,6 +23,7 @@ export interface State {
group: number; group: number;
index: number; index: number;
tree: CompsTree[]; tree: CompsTree[];
templates: CompsTree[];
} }
export const initState: State = { export const initState: State = {
...@@ -42,6 +43,7 @@ export const initState: State = { ...@@ -42,6 +43,7 @@ export const initState: State = {
children: [], children: [],
}, },
], ],
templates: [],
}; };
// mutations // mutations
...@@ -70,17 +72,17 @@ const mutations: MutationTree<State> = { ...@@ -70,17 +72,17 @@ const mutations: MutationTree<State> = {
state.group = index; state.group = index;
state.current = current; state.current = current;
}, },
[types.ADD_COMPS_GROUP](state: State, params: { type: string; name: string }) { [types.ADD_COMPS_GROUP](state: State, params: { type: string; name: string; templateName: string }) {
if (!params.name) { if (!params.name) {
return; return;
} }
const template = state.templates.filter((item) => item.name === params.templateName && params.type === item.type);
let group = { name: params.name, type: params.type, query: {}, children: [{ name: 'demo', children: [] }] };
const newTree = []; if (template.length) {
Object.keys(state.tree).forEach((i: any) => { group = { ...group, children: template[0].children };
newTree.push(state.tree[i]); }
}); state.tree.push(group);
newTree.push({ name: params.name, type: params.type, query: {}, children: [{ name: 'demo', children: [] }] });
state.tree = newTree;
window.localStorage.setItem('dashboard', JSON.stringify(state.tree)); window.localStorage.setItem('dashboard', JSON.stringify(state.tree));
}, },
...@@ -131,6 +133,9 @@ const mutations: MutationTree<State> = { ...@@ -131,6 +133,9 @@ const mutations: MutationTree<State> = {
state.tree[state.group].children[state.current].children[params.index] = { ...temp, ...params.values }; state.tree[state.group].children[state.current].children[params.index] = { ...temp, ...params.values };
window.localStorage.setItem('dashboard', JSON.stringify(state.tree)); window.localStorage.setItem('dashboard', JSON.stringify(state.tree));
}, },
[types.SET_TEMPLATES](state: State, templates) {
state.templates = templates;
},
}; };
export default { export default {
......
...@@ -34,6 +34,7 @@ export const SET_INSTANCES = 'SET_INSTANCES'; ...@@ -34,6 +34,7 @@ export const SET_INSTANCES = 'SET_INSTANCES';
export const SET_CURRENT_INSTANCE = 'SET_CURRENT_INSTANCE'; export const SET_CURRENT_INSTANCE = 'SET_CURRENT_INSTANCE';
export const SET_INSTANCE_INFO = 'SET_INSTANCE_INFO'; export const SET_INSTANCE_INFO = 'SET_INSTANCE_INFO';
export const SET_KEYWORDSERVICE = 'SET_KEYWORDSERVICE'; export const SET_KEYWORDSERVICE = 'SET_KEYWORDSERVICE';
export const SET_TEMPLATES = 'SET_TEMPLATES';
// comp // comp
export const SET_CURRENT_GROUP = 'SET_CURRENT_GROUP'; export const SET_CURRENT_GROUP = 'SET_CURRENT_GROUP';
......
...@@ -44,6 +44,11 @@ limitations under the License. --> ...@@ -44,6 +44,11 @@ limitations under the License. -->
<option :value="DASHBOARDTYPE.METRIC">{{ $t('metricsView') }}</option> <option :value="DASHBOARDTYPE.METRIC">{{ $t('metricsView') }}</option>
<option :value="DASHBOARDTYPE.DATABASE">{{ $t('databaseView') }}</option> <option :value="DASHBOARDTYPE.DATABASE">{{ $t('databaseView') }}</option>
</select> </select>
<div class="sm grey mb-5 mr-10" v-show="type !== DASHBOARDTYPE.METRIC">{{ $t('templateConfig') }}</div>
<select v-model="templateName" class="rk-dashboard-group-sel" v-show="type !== DASHBOARDTYPE.METRIC">
<option :value="''">None</option>
<option v-for="template in templates" :key="template.name" :value="template.name">{{ template.name }}</option>
</select>
<div class="sm grey mb-5 mr-10">{{ $t('templateName') }}</div> <div class="sm grey mb-5 mr-10">{{ $t('templateName') }}</div>
<input class="mb-5 rk-dashboard-group-input" type="text" v-model="name" /> <input class="mb-5 rk-dashboard-group-input" type="text" v-model="name" />
<a class="rk-btn r vm long tc confirm" @click="handleCreate">{{ $t('confirm') }}</a> <a class="rk-btn r vm long tc confirm" @click="handleCreate">{{ $t('confirm') }}</a>
...@@ -74,6 +79,7 @@ limitations under the License. --> ...@@ -74,6 +79,7 @@ limitations under the License. -->
private type: string = DASHBOARDTYPE.SERVICE; private type: string = DASHBOARDTYPE.SERVICE;
private show: boolean = false; private show: boolean = false;
private DASHBOARDTYPE = DASHBOARDTYPE; private DASHBOARDTYPE = DASHBOARDTYPE;
private templateName: string = '';
private get compType() { private get compType() {
return ( return (
...@@ -81,7 +87,31 @@ limitations under the License. --> ...@@ -81,7 +87,31 @@ limitations under the License. -->
'service' 'service'
); );
} }
private handleOption(index: any) { private get servicesTemplates() {
const templates = this.rocketComps.templates.filter(
(item: { type: string; name: string; children: any[] }) => item.type === DASHBOARDTYPE.SERVICE,
);
return templates;
}
private get databaseTemplates() {
const templates = this.rocketComps.templates.filter(
(item: { type: string; name: string; children: any[] }) => item.type === DASHBOARDTYPE.DATABASE,
);
return templates;
}
private get templates() {
let templates = [];
if (this.type === DASHBOARDTYPE.SERVICE) {
templates = this.servicesTemplates;
} else if (this.type === DASHBOARDTYPE.DATABASE) {
templates = this.databaseTemplates;
}
return templates;
}
private handleOption(index: number) {
this.MIXHANDLE_CHANGE_GROUP(index); this.MIXHANDLE_CHANGE_GROUP(index);
return this.MIXHANDLE_GET_OPTION({ return this.MIXHANDLE_GET_OPTION({
compType: this.compType, compType: this.compType,
...@@ -92,9 +122,10 @@ limitations under the License. --> ...@@ -92,9 +122,10 @@ limitations under the License. -->
this.name = ''; this.name = '';
this.type = DASHBOARDTYPE.SERVICE; this.type = DASHBOARDTYPE.SERVICE;
this.show = false; this.show = false;
this.templateName = '';
} }
private handleCreate() { private handleCreate() {
this.ADD_COMPS_GROUP({ name: this.name, type: this.type }); this.ADD_COMPS_GROUP({ name: this.name, type: this.type, templateName: this.templateName });
this.handleHide(); this.handleHide();
} }
} }
......
/** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the <!-- Licensed to the Apache Software Foundation (ASF) under one or more
NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses contributor license agreements. See the NOTICE file distributed with
this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance this work for additional information regarding copyright ownership.
with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless The ASF licenses this file to You under the Apache License, Version 2.0
required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS (the "License"); you may not use this file except in compliance with
IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific the License. You may obtain a copy of the License at
language governing permissions and * limitations under the License. */
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. -->
<template> <template>
<div class="topo-group"> <div class="topo-group">
......
...@@ -78,6 +78,7 @@ limitations under the License. --> ...@@ -78,6 +78,7 @@ limitations under the License. -->
@Mutation('SET_COMPS_TREE') private SET_COMPS_TREE: any; @Mutation('SET_COMPS_TREE') private SET_COMPS_TREE: any;
@Mutation('ADD_COMP') private ADD_COMP: any; @Mutation('ADD_COMP') private ADD_COMP: any;
@Mutation('SET_EDIT') private SET_EDIT: any; @Mutation('SET_EDIT') private SET_EDIT: any;
@Mutation('SET_TEMPLATES') private SET_TEMPLATES: any;
private ObjectsType = ObjectsType; private ObjectsType = ObjectsType;
...@@ -110,17 +111,24 @@ limitations under the License. --> ...@@ -110,17 +111,24 @@ limitations under the License. -->
// }).then((data: any) => { // }).then((data: any) => {
// console.log(data); // console.log(data);
// }); // });
if (window.localStorage.getItem('version') !== '8.0') { this.GET_ALL_TEMPLATES().then((allTemplate: ITemplate[]) => {
this.GET_ALL_TEMPLATES().then((allTemplate: ITemplate[]) => { const dashboardTemplate = allTemplate.filter((item: ITemplate) => item.type === 'DASHBOARD');
const templatesConfig = dashboardTemplate.map((item: ITemplate) => JSON.parse(item.configuration)).flat(1);
this.SET_TEMPLATES(templatesConfig);
if (window.localStorage.getItem('version') !== '8.0') {
window.localStorage.removeItem('dashboard'); window.localStorage.removeItem('dashboard');
this.setDashboardTemplates(allTemplate); const template = allTemplate.filter((item: ITemplate) => item.type === 'DASHBOARD' && item.activated);
const templatesConfiguration = template.map((item: ITemplate) => JSON.parse(item.configuration)).flat(1);
this.SET_COMPS_TREE(templatesConfiguration || []);
window.localStorage.setItem('version', '8.0');
window.localStorage.setItem('dashboard', JSON.stringify(templatesConfiguration));
this.handleOption(); this.handleOption();
}); } else {
} else { const data: string = `${window.localStorage.getItem('dashboard')}`;
const data: string = `${window.localStorage.getItem('dashboard')}`; this.SET_COMPS_TREE(JSON.parse(data));
this.SET_COMPS_TREE(JSON.parse(data)); this.handleOption();
} }
this.handleOption(); });
} }
private setDashboardTemplates(allTemplate: ITemplate[]) { private setDashboardTemplates(allTemplate: ITemplate[]) {
const template = allTemplate.filter((item: ITemplate) => item.type === 'DASHBOARD' && item.activated); const template = allTemplate.filter((item: ITemplate) => item.type === 'DASHBOARD' && item.activated);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册