mirror of https://github.com/rancher/ui.git
Update Graph on interval
https://github.com/rancher/rancher/issues/16920
This commit is contained in:
parent
cf5d9b5429
commit
c4fac6615f
|
|
@ -118,22 +118,26 @@ export default Component.extend({
|
||||||
let from;
|
let from;
|
||||||
let to;
|
let to;
|
||||||
let interval;
|
let interval;
|
||||||
|
let isCustom;
|
||||||
|
|
||||||
if ( period !== CUSTOM ) {
|
if ( period !== CUSTOM ) {
|
||||||
const params = PERIODS.findBy('value', get(this, 'selected'));
|
const params = PERIODS.findBy('value', get(this, 'selected'));
|
||||||
|
|
||||||
from = period,
|
from = period;
|
||||||
to = 'now',
|
to = 'now';
|
||||||
interval = get(params, 'interval')
|
interval = get(params, 'interval');
|
||||||
|
isCustom = false;
|
||||||
} else {
|
} else {
|
||||||
from = get(this, 'from').toString();
|
from = get(this, 'from').toString();
|
||||||
to = get(this, 'to').toString() || new Date().getTime().toString();
|
to = get(this, 'to').toString() || new Date().getTime().toString();
|
||||||
interval = `${ Math.round((to - from) / 120000) }s`
|
interval = `${ Math.round((to - from) / 120000) }s`;
|
||||||
|
isCustom = true;
|
||||||
}
|
}
|
||||||
setProperties(get(this, 'state'), {
|
setProperties(get(this, 'state'), {
|
||||||
from,
|
from,
|
||||||
to,
|
to,
|
||||||
interval,
|
interval,
|
||||||
|
isCustom
|
||||||
});
|
});
|
||||||
|
|
||||||
if ( period === CUSTOM ) {
|
if ( period === CUSTOM ) {
|
||||||
|
|
|
||||||
|
|
@ -228,6 +228,7 @@ export default Mixin.create({
|
||||||
state: null,
|
state: null,
|
||||||
projectScope: false,
|
projectScope: false,
|
||||||
metricParams: null,
|
metricParams: null,
|
||||||
|
timeOutAnchor: null,
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
this._super(...arguments);
|
this._super(...arguments);
|
||||||
|
|
@ -236,12 +237,18 @@ export default Mixin.create({
|
||||||
loading: false,
|
loading: false,
|
||||||
detail: true,
|
detail: true,
|
||||||
noGraphs: false,
|
noGraphs: false,
|
||||||
|
isCustom: false,
|
||||||
from: null,
|
from: null,
|
||||||
to: null,
|
to: null,
|
||||||
interval: null,
|
interval: null,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
willDestroyElement() {
|
||||||
|
this.clearTimeOut();
|
||||||
|
this._super();
|
||||||
|
},
|
||||||
|
|
||||||
updateData(out) {
|
updateData(out) {
|
||||||
const single = [];
|
const single = [];
|
||||||
const graphs = [];
|
const graphs = [];
|
||||||
|
|
@ -259,13 +266,38 @@ export default Mixin.create({
|
||||||
graphs,
|
graphs,
|
||||||
single
|
single
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if ( !get(this, 'state.isCustom') ) {
|
||||||
|
const interval = get(this, 'state.interval');
|
||||||
|
|
||||||
|
let timeout = parseInt(interval.substr(0, get(interval, 'length') - 1), 10);
|
||||||
|
|
||||||
|
timeout = timeout > 5 ? timeout : 5;
|
||||||
|
const timeOutAnchor = setTimeout(() => {
|
||||||
|
this.send('query', false);
|
||||||
|
}, timeout * 1000);
|
||||||
|
|
||||||
|
set(this, 'timeOutAnchor', timeOutAnchor);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
clearTimeOut() {
|
||||||
|
const timeOutAnchor = get(this, 'timeOutAnchor');
|
||||||
|
|
||||||
|
if (timeOutAnchor){
|
||||||
|
clearTimeout(timeOutAnchor);
|
||||||
|
set(this, 'timeOutAnchor', timeOutAnchor);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
query(){
|
query(showLoading = true){
|
||||||
|
this.clearTimeOut();
|
||||||
const gs = get(this, 'globalStore');
|
const gs = get(this, 'globalStore');
|
||||||
|
|
||||||
set(this, 'state.loading', true);
|
if ( showLoading ) {
|
||||||
|
set(this, 'state.loading', true);
|
||||||
|
}
|
||||||
|
|
||||||
let metricParams = {};
|
let metricParams = {};
|
||||||
|
|
||||||
|
|
@ -344,7 +376,9 @@ export default Mixin.create({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
set(this, 'state.loading', false);
|
if ( showLoading ) {
|
||||||
|
set(this, 'state.loading', false);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue