Reactive state cookie
This commit is contained in:
parent
030487d728
commit
6ae57cfd79
@ -44,7 +44,6 @@
|
||||
</style>
|
||||
|
||||
<script>
|
||||
import cookie from './cookie.mjs';
|
||||
import vistax from './vistax.mjs';
|
||||
|
||||
export default {
|
||||
@ -74,7 +73,7 @@
|
||||
data() {
|
||||
return {
|
||||
show: false,
|
||||
host: cookie.get('host'),
|
||||
host: vistax.state.host,
|
||||
x_client: this.client,
|
||||
x_server: this.server,
|
||||
x_user: this.user,
|
||||
@ -85,7 +84,7 @@
|
||||
},
|
||||
watch: {
|
||||
host(value) {
|
||||
cookie.set('host', value);
|
||||
vistax.state.host = value;
|
||||
this.logout();
|
||||
},
|
||||
client(value) { this.x_client = value; },
|
||||
|
@ -45,7 +45,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import cookie from './cookie.mjs';
|
||||
import { state } from './vistax.mjs';
|
||||
import { groupByArray, strtr_unscramble, strHashHSL, strftime_vista, debounce } from './util.mjs';
|
||||
|
||||
import ViewResourceLookup from './ViewResourceLookup.vue';
|
||||
@ -62,7 +62,7 @@
|
||||
client: Object
|
||||
},
|
||||
data() {
|
||||
var resources = cookie.get('vista.resources');
|
||||
var resources = state.resources;
|
||||
var today = dateonly(new Date());
|
||||
return {
|
||||
selection: resources ? (resources.split(',').filter(x => x) || []) : [],
|
||||
@ -95,7 +95,7 @@
|
||||
},
|
||||
created() {
|
||||
this.debounced_selection = debounce(async function(value) {
|
||||
cookie.set('vista.resources', value.join(','), 7);
|
||||
state.resources = value.join(',');
|
||||
var patients = this.selection.length > 0 ? groupByArray(await this.client.SDEC_CLINLET(this.selection.join('|') + '|', strftime_vista(this.date_begin), strftime_vista(this.date_end)), x => x.HRN) : [], now = new Date(), group, values, appt;
|
||||
for(var i = patients.length - 1; i >= 0; --i) {
|
||||
group = patients[i];
|
||||
|
@ -19,7 +19,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import cookie from './cookie.mjs';
|
||||
import { state } from './vistax.mjs';
|
||||
|
||||
import ViewResourceLookup from './ViewResourceLookup.vue';
|
||||
import DateRangePicker from './DateRangePicker.vue';
|
||||
@ -37,7 +37,7 @@
|
||||
client: Object
|
||||
},
|
||||
data() {
|
||||
var resources = cookie.get('vista.resources');
|
||||
var resources = state.resources;
|
||||
return {
|
||||
selection: resources ? (resources.split(',').filter(x => x) || []) : [],
|
||||
date: dateonly(new Date()),
|
||||
@ -46,7 +46,7 @@
|
||||
},
|
||||
watch: {
|
||||
selection(value, oldvalue) {
|
||||
cookie.set('vista.resources', value.join(','), 7);
|
||||
state.resources = value.join(',');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -17,7 +17,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import cookie from './cookie.mjs';
|
||||
import { state } from './vistax.mjs';
|
||||
import { uniq, strtr_unscramble, strHashHSL, strfdate_vista, debounce } from './util.mjs';
|
||||
|
||||
import Autocomplete from './Autocomplete.vue';
|
||||
@ -60,15 +60,15 @@
|
||||
strtr_unscramble,
|
||||
set_practitioner(patient, practitioner) {
|
||||
this.practitioner[patient] = practitioner;
|
||||
cookie.set('vista.practitioner', JSON.stringify(this.practitioner), 1);
|
||||
state.practitioner = this.practitioner;
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.debounced_params = debounce(async function(value) { this.appointments = value.selection.length > 0 ? (await this.client.SDEC_CLINLET(value.selection.join('|') + '|', strfdate_vista(value.date_begin), strfdate_vista(value.date_end))).sort((a, b) => (new Date(a.ApptDate)) - (new Date(b.ApptDate))) : []; }, 500);
|
||||
},
|
||||
async mounted() {
|
||||
var practitioner = cookie.get('vista.practitioner');
|
||||
if(practitioner) this.practitioner = JSON.parse(practitioner);
|
||||
var practitioner = state.practitioner;
|
||||
if(practitioner) this.practitioner = practitioner;
|
||||
this.production = (await this.client.serverinfo()).result.production == '1';
|
||||
}
|
||||
};
|
||||
|
@ -1,8 +1,16 @@
|
||||
import { reactive, watch } from 'vue';
|
||||
|
||||
import vista from './vista.mjs';
|
||||
import cookie from './cookie.mjs';
|
||||
import { lab_parse, lab_reparse_results, measurement_parse } from './reportparser.mjs';
|
||||
|
||||
const COOKIE_TIME = 45;
|
||||
export const state = reactive(cookie.get('state') ? JSON.parse(cookie.get('state')) : {});
|
||||
if((!state.secret) && (cookie.get('secret'))) state.resources = cookie.get('secret');
|
||||
if((!state.cid) && (cookie.get('cid'))) state.resources = cookie.get('cid');
|
||||
if((!state.host) && (cookie.get('host'))) state.resources = cookie.get('host');
|
||||
if((!state.resources) && (cookie.get('vista.resources'))) state.resources = cookie.get('vista.resources');
|
||||
if((!state.practitioner) && (cookie.get('vista.practitioner'))) state.practitioner = JSON.parse(cookie.get('vista.practitioner'));
|
||||
watch(state, value => cookie.set('state', JSON.stringify(value), 45), { immediate: true, deep: true });
|
||||
|
||||
function RPCError(type, ...args) {
|
||||
this.name = type;
|
||||
@ -131,57 +139,57 @@ Client.fromScratch = async function(secret, host='vista.northport.med.va.gov', p
|
||||
};
|
||||
|
||||
Client.fromCookie = async function(secret, defaulthost='vista.northport.med.va.gov:19209') {
|
||||
if(!secret) secret = cookie.get('secret');
|
||||
if(!secret) secret = state.secret;
|
||||
if(secret) {
|
||||
var host = cookie.get('host');
|
||||
var host = state.host;
|
||||
host = (host || defaulthost).split(':');
|
||||
if(secret != cookie.get('secret')) {
|
||||
if(secret != state.secret) {
|
||||
console.log('Using new secret', secret);
|
||||
var client = await Client.fromScratch(secret, host[0], host[1]);
|
||||
if(client) {
|
||||
cookie.set('host', host.join(':'), COOKIE_TIME);
|
||||
cookie.set('secret', secret);
|
||||
cookie.set('cid', client.cid);
|
||||
state.host = host.join(':');
|
||||
state.secret = secret;
|
||||
state.cid = client.cid;
|
||||
console.log('Established connection', client.cid);
|
||||
return client;
|
||||
} else {
|
||||
cookie.reset('secret');
|
||||
cookie.reset('cid');
|
||||
delete state.secret;
|
||||
delete state.cid;
|
||||
console.log('Failed to connect');
|
||||
return null;
|
||||
}
|
||||
} else if(!cookie.get('cid')) {
|
||||
} else if(!state.cid) {
|
||||
console.log('Using saved secret', secret);
|
||||
var client = await Client.fromScratch(secret, host[0], host[1]);
|
||||
if(client) {
|
||||
cookie.set('host', host.join(':'), COOKIE_TIME);
|
||||
cookie.set('secret', secret);
|
||||
cookie.set('cid', client.cid);
|
||||
state.host = host.join(':');
|
||||
state.secret = secret;
|
||||
state.cid = client.cid;
|
||||
console.log('Established connection', client.cid);
|
||||
return client;
|
||||
} else {
|
||||
cookie.reset('secret');
|
||||
cookie.reset('cid');
|
||||
delete state.secret;
|
||||
delete state.cid;
|
||||
console.log('Failed connection');
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
console.log('Using saved secret and connection', secret);
|
||||
var cid = cookie.get('cid');
|
||||
var cid = state.cid;
|
||||
var client = Client.fromID(cid, secret);
|
||||
if((await vista.call(cid, 'XWB_IM_HERE')).result == '1') {
|
||||
var server = await client.serverinfo();
|
||||
if((host[0] == server.result.host) && (host[1] == server.result.port)) {
|
||||
cookie.set('host', host.join(':'), COOKIE_TIME);
|
||||
state.host = host.join(':');
|
||||
return client;
|
||||
} else console.log('Rejecting previous connection to different server', server);
|
||||
}
|
||||
cookie.reset('cid');
|
||||
delete state.cid;
|
||||
return await Client.fromCookie(secret, host.join(':'));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default window.vistax = {
|
||||
RPCError, Client, connect: Client.fromCookie
|
||||
state, RPCError, Client, connect: Client.fromCookie
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user