Cache-aware schedule view
This commit is contained in:
parent
a83e8cb22c
commit
fdc7ed4c05
@ -1,5 +1,8 @@
|
|||||||
<template>
|
<template>
|
||||||
<div v-if="(age === undefined) || (age > 0)" class="alert alert-warning">⚠ update error<template v-if="age >= 90000">; last updated {{Math.round(age/60000)}} minutes ago</template></div>
|
<template v-if="age !== undefined">
|
||||||
|
<div v-if="age == Infinity" class="alert alert-danger">❌ update error</div>
|
||||||
|
<div v-else-if="age >= 90000" class="alert alert-warning">⚠ last updated <template v-if="age < 3600000">{{ts.toLocaleString()}}</template><template v-else>{{ts.toLocaleString()}}</template></div>
|
||||||
|
</template>
|
||||||
<table class="table" style="font-family: monospace;" v-if="appointments && appointments.length > 0">
|
<table class="table" style="font-family: monospace;" v-if="appointments && appointments.length > 0">
|
||||||
<thead>
|
<thead>
|
||||||
<tr><th style="width: 7rem;">Time</th><th>Clinic</th><th>Patient</th><th>Note</th><th style="width: 16rem;">Assignee</th></tr>
|
<tr><th style="width: 7rem;">Time</th><th>Clinic</th><th>Patient</th><th>Note</th><th style="width: 16rem;">Assignee</th></tr>
|
||||||
@ -71,7 +74,7 @@
|
|||||||
return {
|
return {
|
||||||
appointments: [],
|
appointments: [],
|
||||||
ts: null,
|
ts: null,
|
||||||
age: 0
|
age: undefined
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -87,11 +90,14 @@
|
|||||||
async update() {
|
async update() {
|
||||||
try {
|
try {
|
||||||
this.appointments = (await this.client.SDEC_CRSCHED(this.selection.join('|') + '|', strfdate_vista(this.date_begin), strfdate_vista(this.date_end) + '@2359')).sort((a, b) => (new Date(a.START_TIME)) - (new Date(b.START_TIME)));
|
this.appointments = (await this.client.SDEC_CRSCHED(this.selection.join('|') + '|', strfdate_vista(this.date_begin), strfdate_vista(this.date_end) + '@2359')).sort((a, b) => (new Date(a.START_TIME)) - (new Date(b.START_TIME)));
|
||||||
this.ts = new Date();
|
var now = new Date();
|
||||||
this.age = 0;
|
this.ts = this.appointments._ts ? new Date(1000*this.appointments._ts) : now;
|
||||||
|
this.age = now - this.ts;
|
||||||
|
this.timer = window.setTimeout(this.update, Math.max(60000 - this.age, 10000));
|
||||||
} catch(ex) {
|
} catch(ex) {
|
||||||
this.age = this.ts ? (new Date()) - this.ts : undefined;
|
this.age = this.ts ? (new Date()) - this.ts : Infinity;
|
||||||
console.warn(ex);
|
console.warn(ex);
|
||||||
|
this.timer = window.setTimeout(this.update, 30000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -99,14 +105,13 @@
|
|||||||
this.$watch(
|
this.$watch(
|
||||||
() => (this.client, this.selection, this.date_begin, this.date_end, {}),
|
() => (this.client, this.selection, this.date_begin, this.date_end, {}),
|
||||||
debounce(async () => {
|
debounce(async () => {
|
||||||
window.clearInterval(this.timer);
|
window.clearTimeout(this.timer);
|
||||||
this.update();
|
this.update();
|
||||||
this.timer = window.setInterval(this.update, 60000);
|
|
||||||
}, 500)
|
}, 500)
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
unmounted() {
|
unmounted() {
|
||||||
window.clearInterval(this.timer);
|
window.clearTimeout(this.timer);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
Reference in New Issue
Block a user