feat:explore 自动提示框增加history记录
This commit is contained in:
@@ -242,6 +242,7 @@ const cn = {
|
|||||||
title: "探索",
|
title: "探索",
|
||||||
inputTip:'输入PromQL查询语句',
|
inputTip:'输入PromQL查询语句',
|
||||||
runQuery:'查询',
|
runQuery:'查询',
|
||||||
|
historyTip:'{hour}小时内查询了{time}次',
|
||||||
},
|
},
|
||||||
refresh: "刷新",
|
refresh: "刷新",
|
||||||
edit: "编辑",
|
edit: "编辑",
|
||||||
|
|||||||
@@ -247,6 +247,7 @@ const en = {
|
|||||||
title:'Explore',
|
title:'Explore',
|
||||||
inputTip:'Enter a PromQL query',
|
inputTip:'Enter a PromQL query',
|
||||||
runQuery:'Run query',
|
runQuery:'Run query',
|
||||||
|
historyTip:'Queried {time} times in the last {hour}h',
|
||||||
},
|
},
|
||||||
refresh:'Refresh',//'刷新'
|
refresh:'Refresh',//'刷新'
|
||||||
edit:'Edit',//'编辑'
|
edit:'Edit',//'编辑'
|
||||||
|
|||||||
@@ -29,7 +29,8 @@
|
|||||||
props: {
|
props: {
|
||||||
value: String,
|
value: String,
|
||||||
metricList:{type:Array},
|
metricList:{type:Array},
|
||||||
styleType: Number
|
styleType: Number,
|
||||||
|
historyParam:Object
|
||||||
},
|
},
|
||||||
model:{
|
model:{
|
||||||
prop:'value',
|
prop:'value',
|
||||||
@@ -66,16 +67,12 @@
|
|||||||
detailItem:{},
|
detailItem:{},
|
||||||
formatTimer:null,
|
formatTimer:null,
|
||||||
userChangeTimer:null,
|
userChangeTimer:null,
|
||||||
keyDownTimer:null,
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created(){
|
created(){
|
||||||
this.queryMetrics();
|
this.queryMetrics();
|
||||||
},
|
},
|
||||||
methods:{
|
methods:{
|
||||||
test() {
|
|
||||||
console.info(1)
|
|
||||||
},
|
|
||||||
userChange:function(char,operation,newContent,oldContent){
|
userChange:function(char,operation,newContent,oldContent){
|
||||||
this.changeSuggestions('type')
|
this.changeSuggestions('type')
|
||||||
this.dealSpecilChar(char,operation);
|
this.dealSpecilChar(char,operation);
|
||||||
@@ -86,7 +83,7 @@
|
|||||||
}
|
}
|
||||||
this.filterItems(newContent);
|
this.filterItems(newContent);
|
||||||
},
|
},
|
||||||
dealSpecilChar:function(char,operation){
|
dealSpecilChar:function(char,operation){//控制括号的成对添加和删除
|
||||||
// console.log('specil char',char)
|
// console.log('specil char',char)
|
||||||
if(/^[\{\(\[\,]$/g.test(char)){
|
if(/^[\{\(\[\,]$/g.test(char)){
|
||||||
if(operation=='insert'){
|
if(operation=='insert'){
|
||||||
@@ -251,6 +248,15 @@
|
|||||||
},
|
},
|
||||||
queryTypeInfos:function(){
|
queryTypeInfos:function(){
|
||||||
this.noStyleSuggestions={};
|
this.noStyleSuggestions={};
|
||||||
|
if(this.historyParam&&this.historyParam.useHistory){
|
||||||
|
let username=sessionStorage.getItem("nz-username");
|
||||||
|
let historyJson=localStorage.getItem(this.historyParam.key);
|
||||||
|
if(historyJson && historyJson != 'undefined' && historyJson != ''){
|
||||||
|
let historyObj=JSON.parse(historyJson);
|
||||||
|
let history = historyObj[username];
|
||||||
|
this.$set(this.noStyleSuggestions,'history',history);
|
||||||
|
}
|
||||||
|
}
|
||||||
this.$set(this.noStyleSuggestions,'metrics',this.tempStoreMetric)
|
this.$set(this.noStyleSuggestions,'metrics',this.tempStoreMetric)
|
||||||
// this.$set(this.noStyleSuggestions,'operators',suggestions.getOperators())
|
// this.$set(this.noStyleSuggestions,'operators',suggestions.getOperators())
|
||||||
this.$set(this.noStyleSuggestions,'functions',suggestions.getFunctions())
|
this.$set(this.noStyleSuggestions,'functions',suggestions.getFunctions())
|
||||||
@@ -377,8 +383,19 @@
|
|||||||
this.handleFunctionClick(item);
|
this.handleFunctionClick(item);
|
||||||
}else if(type == 'range'){
|
}else if(type == 'range'){
|
||||||
this.handleRangeClick(item);
|
this.handleRangeClick(item);
|
||||||
|
}else if(type == 'history'){
|
||||||
|
this.handleHistoryClick(item)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
handleHistoryClick:function(item){
|
||||||
|
this.setContent(item.insertText);
|
||||||
|
|
||||||
|
this.showType=false;
|
||||||
|
this.quill.blur();
|
||||||
|
this.$nextTick(()=>{
|
||||||
|
this.$emit('on-blur');
|
||||||
|
})
|
||||||
|
},
|
||||||
handleRangeClick:function(item){
|
handleRangeClick:function(item){
|
||||||
this.quill.setSelection(this.pivotalCursorIndex,this.cursorIndex-this.pivotalCursorIndex,'api');
|
this.quill.setSelection(this.pivotalCursorIndex,this.cursorIndex-this.pivotalCursorIndex,'api');
|
||||||
this.deleteTextInRange(this.pivotalCursorIndex,this.cursorIndex)
|
this.deleteTextInRange(this.pivotalCursorIndex,this.cursorIndex)
|
||||||
@@ -499,12 +516,14 @@
|
|||||||
this.handleRangeClick({insertText:insertText})
|
this.handleRangeClick({insertText:insertText})
|
||||||
}else if(type == 'functions'){
|
}else if(type == 'functions'){
|
||||||
this.handleFunctionClick({insertText:insertText})
|
this.handleFunctionClick({insertText:insertText})
|
||||||
|
}else if(type == 'history'){
|
||||||
|
this.handleHistoryClick({insertText:insertText})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
filterItems:function(input){
|
filterItems:function(input){ //过滤下拉选显示
|
||||||
let suggestions=this.deepClone(this.noStyleSuggestions)
|
let suggestions=this.deepClone(this.noStyleSuggestions)
|
||||||
|
|
||||||
for(let key in suggestions){
|
for(let key in suggestions){
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
:expression-list="expressions"
|
:expression-list="expressions"
|
||||||
:index="index-1"
|
:index="index-1"
|
||||||
:styleType="1"
|
:styleType="1"
|
||||||
|
:history-param="historyParam"
|
||||||
:plugins="['metric-selector', 'metric-input', 'add', 'remove']"
|
:plugins="['metric-selector', 'metric-input', 'add', 'remove']"
|
||||||
@change="expressionChange"
|
@change="expressionChange"
|
||||||
@addExpression="addExpression"
|
@addExpression="addExpression"
|
||||||
@@ -236,7 +237,7 @@ instance_cpu_time_ns{app="fox", proc="widget", rev="4d3a513", env="prod", job="c
|
|||||||
promqlKeys: [],
|
promqlKeys: [],
|
||||||
expressions: [''],
|
expressions: [''],
|
||||||
filterTime: [
|
filterTime: [
|
||||||
bus.timeFormate(new Date(bus.computeTimezone(new Date().getTime())).setMinutes(new Date(bus.computeTimezone(new Date().getTime())).getMinutes() - 5),'yyyy-MM-dd hh:mm:ss'),
|
bus.timeFormate(new Date(bus.computeTimezone(new Date().getTime())).setHours(new Date(bus.computeTimezone(new Date().getTime())).getHours() - 1),'yyyy-MM-dd hh:mm:ss'),
|
||||||
bus.timeFormate(new Date(bus.computeTimezone(new Date().getTime())),'yyyy-MM-dd hh:mm:ss')
|
bus.timeFormate(new Date(bus.computeTimezone(new Date().getTime())),'yyyy-MM-dd hh:mm:ss')
|
||||||
],
|
],
|
||||||
showIntroduce: true,
|
showIntroduce: true,
|
||||||
@@ -257,6 +258,7 @@ instance_cpu_time_ns{app="fox", proc="widget", rev="4d3a513", env="prod", job="c
|
|||||||
saveDisabled: true,
|
saveDisabled: true,
|
||||||
panelData: [],
|
panelData: [],
|
||||||
chartUnit:0,
|
chartUnit:0,
|
||||||
|
historyParam:{useHistory:true,key:'expore-history'}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
@@ -426,9 +428,89 @@ instance_cpu_time_ns{app="fox", proc="widget", rev="4d3a513", env="prod", job="c
|
|||||||
}, 200)
|
}, 200)
|
||||||
},
|
},
|
||||||
expressionChange: function () {
|
expressionChange: function () {
|
||||||
|
console.log(this.filterTime)
|
||||||
if (this.expressions && this.expressions.length >= 1) {
|
if (this.expressions && this.expressions.length >= 1) {
|
||||||
this.queryTableData();
|
this.queryTableData();
|
||||||
this.queryChartData()
|
this.queryChartData()
|
||||||
|
this.storeHistory();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
storeHistory:function(){
|
||||||
|
let expire=24;
|
||||||
|
let historyJson=localStorage.getItem(this.historyParam.key);
|
||||||
|
let expressions=this.expressions.filter(item=>{
|
||||||
|
return item&&item != '';
|
||||||
|
})
|
||||||
|
let username=sessionStorage.getItem("nz-username");
|
||||||
|
if(historyJson && historyJson != 'undefined' && historyJson != ''){
|
||||||
|
let historyObj=JSON.parse(historyJson);
|
||||||
|
let history = historyObj[username];
|
||||||
|
if(history){
|
||||||
|
//过滤过期表达式
|
||||||
|
history=history.filter(item=>{
|
||||||
|
return item.time + item.expire >= new Date().getTime();
|
||||||
|
})
|
||||||
|
let repeat=history.filter(item=>{
|
||||||
|
return expressions.includes(item.insertText)
|
||||||
|
})
|
||||||
|
let old=history.filter(item=>{
|
||||||
|
return !expressions.includes(item.insertText)
|
||||||
|
})
|
||||||
|
|
||||||
|
let freshExpression=expressions.filter(item=>{
|
||||||
|
let find=history.find(t=>{return t.insertText == item});
|
||||||
|
return !find
|
||||||
|
})
|
||||||
|
|
||||||
|
repeat=repeat.map(item=>{
|
||||||
|
item.time=new Date().getTime();
|
||||||
|
item.num+=1;
|
||||||
|
item.documentation=this.$t('dashboard.metricPreview.historyTip',{time:item.num,hour:24});
|
||||||
|
return item;
|
||||||
|
})
|
||||||
|
|
||||||
|
let fresh=freshExpression.map(item=>{
|
||||||
|
return{
|
||||||
|
label:item,
|
||||||
|
insertText:item,
|
||||||
|
documentation:this.$t('dashboard.metricPreview.historyTip',{time:1,hour:24}),
|
||||||
|
num:1,
|
||||||
|
time:new Date().getTime(),
|
||||||
|
expire:expire * 60 * 60 * 1000
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
historyObj[username]=fresh.concat(repeat).concat(old);
|
||||||
|
}else{
|
||||||
|
let history=expressions.map(item=>{
|
||||||
|
return {
|
||||||
|
label:item,
|
||||||
|
insertText:item,
|
||||||
|
documentation:this.$t('dashboard.metricPreview.historyTip',{time:1,hour:24}),
|
||||||
|
num:1,
|
||||||
|
time:new Date().getTime(),
|
||||||
|
expire:expire * 60 * 60 * 1000
|
||||||
|
}
|
||||||
|
})
|
||||||
|
historyObj[username]=history;
|
||||||
|
}
|
||||||
|
localStorage.setItem(this.historyParam.key,JSON.stringify(historyObj))
|
||||||
|
}else{
|
||||||
|
let history=expressions.map(item=>{
|
||||||
|
return {
|
||||||
|
label:item,
|
||||||
|
insertText:item,
|
||||||
|
documentation:this.$t('dashboard.metricPreview.historyTip',{time:1,hour:24}),
|
||||||
|
num:1,
|
||||||
|
time:new Date().getTime(),
|
||||||
|
expire:expire * 60 * 60 * 1000
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if(history&&history.length>0){
|
||||||
|
let stored={};
|
||||||
|
stored[username]=history;
|
||||||
|
localStorage.setItem(this.historyParam.key,JSON.stringify(stored))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
addExpression: function (index) {
|
addExpression: function (index) {
|
||||||
|
|||||||
@@ -8,12 +8,12 @@
|
|||||||
<el-dropdown class="metric-selector">
|
<el-dropdown class="metric-selector">
|
||||||
<el-dropdown-menu style="display: none"></el-dropdown-menu>
|
<el-dropdown-menu style="display: none"></el-dropdown-menu>
|
||||||
<el-button class="metric-btn nz-btn nz-btn-size-normal nz-btn-style-light" @click="toggleDropdown">Metric <i class="el-icon-arrow-down"></i></el-button>
|
<el-button class="metric-btn nz-btn nz-btn-size-normal nz-btn-style-light" @click="toggleDropdown">Metric <i class="el-icon-arrow-down"></i></el-button>
|
||||||
<el-cascader-panel v-show="dropDownVisible" v-model="cascaderValue" slot="dropdown" ref="metricSelector" :props="{emitPath:false}" :options="metricOptions" @change="metricChange"></el-cascader-panel>
|
<el-cascader-panel v-show="dropDownVisible" v-model="cascaderValue" slot="dropdown" ref="metricSelector" :props="{emitPath:false}" :options="metricOptions" @change="metricChange" ></el-cascader-panel>
|
||||||
</el-dropdown>
|
</el-dropdown>
|
||||||
</div>
|
</div>
|
||||||
<div class="input-box" @click="dropDownVisible=false" v-if="plugins.indexOf('metric-input') > -1">
|
<div class="input-box" @click="dropDownVisible=false" v-if="plugins.indexOf('metric-input') > -1">
|
||||||
<!-- <el-autocomplete :placeholder="$t('dashboard.metricPreview.inputTip')" :fetch-suggestions="filterInput" clearable @clear="clearExpression" :trigger-on-focus="false" v-model="expressionList[index]" @blur="expressionChange" style="width: 100%;height:36px"></el-autocomplete>-->
|
<!-- <el-autocomplete :placeholder="$t('dashboard.metricPreview.inputTip')" :fetch-suggestions="filterInput" clearable @clear="clearExpression" :trigger-on-focus="false" v-model="expressionList[index]" @blur="expressionChange" style="width: 100%;height:36px"></el-autocomplete>-->
|
||||||
<editor :styleType="styleType" :metric-list="metricStore" v-model="expressionList[index]" ref="editor" @on-enter="expressionChange" @on-blur="expressionChange" ></editor>
|
<editor :styleType="styleType" :metric-list="metricStore" :history-param="historyParam" v-model="expressionList[index]" ref="editor" @on-enter="expressionChange" @on-blur="expressionChange" ></editor>
|
||||||
<div class="append-msg error" v-if="errorMsg"><span>{{errorMsg}}</span></div>
|
<div class="append-msg error" v-if="errorMsg"><span>{{errorMsg}}</span></div>
|
||||||
<div class="append-msg error" v-if="appendMsg"><span>{{appendMsg}}</span></div>
|
<div class="append-msg error" v-if="appendMsg"><span>{{appendMsg}}</span></div>
|
||||||
</div>
|
</div>
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
</el-col>
|
</el-col>
|
||||||
<el-col style="width: calc(100% - 120px); height: 100%;">
|
<el-col style="width: calc(100% - 120px); height: 100%;">
|
||||||
<div class="input-box" @click="dropDownVisible=false" v-if="plugins.indexOf('metric-input') > -1">
|
<div class="input-box" @click="dropDownVisible=false" v-if="plugins.indexOf('metric-input') > -1">
|
||||||
<editor :styleType="styleType" :metric-list="metricStore" v-model="expressionList[index]" ref="editor" @on-enter="expressionChange" @on-blur="expressionChange" ></editor>
|
<editor :styleType="styleType" :metric-list="metricStore" :historyParam="historyParam" v-model="expressionList[index]" ref="editor" @on-enter="expressionChange" @on-blur="expressionChange" ></editor>
|
||||||
<div class="append-msg error" v-if="errorMsg"><span>{{errorMsg}}</span></div>
|
<div class="append-msg error" v-if="errorMsg"><span>{{errorMsg}}</span></div>
|
||||||
<div class="append-msg error" v-if="appendMsg"><span>{{appendMsg}}</span></div>
|
<div class="append-msg error" v-if="appendMsg"><span>{{appendMsg}}</span></div>
|
||||||
</div>
|
</div>
|
||||||
@@ -64,7 +64,8 @@
|
|||||||
index:{type:Number},
|
index:{type:Number},
|
||||||
expressionList:{},
|
expressionList:{},
|
||||||
plugins: {type: Array},
|
plugins: {type: Array},
|
||||||
styleType: Number
|
styleType: Number,
|
||||||
|
historyParam:{type:Object}
|
||||||
},
|
},
|
||||||
data(){
|
data(){
|
||||||
return {
|
return {
|
||||||
@@ -79,7 +80,6 @@
|
|||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.queryMetrics();
|
this.queryMetrics();
|
||||||
|
|
||||||
},
|
},
|
||||||
methods:{
|
methods:{
|
||||||
clearExpression:function(){
|
clearExpression:function(){
|
||||||
@@ -170,6 +170,10 @@
|
|||||||
dropDownVisible:function(n,o){
|
dropDownVisible:function(n,o){
|
||||||
if(this.$refs.metricSelector){
|
if(this.$refs.metricSelector){
|
||||||
this.$refs.metricSelector.dropDownVisible=n;
|
this.$refs.metricSelector.dropDownVisible=n;
|
||||||
|
console.log(this.cascaderValue)
|
||||||
|
if(!this.expressionList[this.index]||this.expressionList[this.index] == ''){
|
||||||
|
this.cascaderValue="";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user