import Vue from "vue"; import App from "./App.vue"; import store from "./store"; import axios from "axios"; import UIkit from "uikit"; import VueObserveVisibility from "vue-observe-visibility"; // Import MD icons import "material-symbols/outlined.css"; import version from "./version.js"; // UIKit overrides UIkit.mixin( { data: { animation: false, }, }, "accordion", ); // Use visibility observer Vue.use(VueObserveVisibility); Vue.config.productionTip = false; Vue.mixin({ methods: { app_version() { return version; }, thingDescription(thing) { return this.$store.getters["wot/thingDescription"](thing); }, thingAvailable(thing) { return this.$store.getters["wot/thingAvailable"](thing); }, async readThingProperty(thing, property, silence_errors = false) { let url = this.$store.getters["wot/thingPropertyUrl"](thing, property, "readproperty", false); try { let response = await axios.get(url); return response.data; } catch (error) { if (!silence_errors) this.modalError(error); return undefined; } }, async writeThingProperty(thing, property, value) { let url = this.$store.getters["wot/thingPropertyUrl"]( thing, property, "writeproperty", false, ); // `false` fails because axios somehow eats it! // Other values should not be stringified or pydantic // can't parse them. if ((value === false) | (value === true)) { value = JSON.stringify(value); } await axios.put(url, value); }, async invokeAction(thing, action, data) { let url = this.$store.getters["wot/thingActionUrl"](thing, action, "invokeaction", false); try { let response = await axios.post(url, data); return response; } catch (error) { this.modalError(error); return undefined; } }, thingActionUrl(thing, action, allow_missing = false) { let url = this.$store.getters["wot/thingActionUrl"]( thing, action, "invokeaction", allow_missing, ); return url; }, modalConfirm: function (modalText) { var context = this; // Stop GPU preview to show modal context.$root.$emit("globalTogglePreview", false); // force OK to be capitalised UIkit.modal.i18n = { ok: "OK", cancel: "Cancel" }; var showModal = function (resolve, reject) { UIkit.modal .confirm(modalText, { stack: true }) .then( function () { resolve(); }, function () { reject(); }, ) .finally(function () { // Re-enable the GPU preview, if it was active before the modal if (context.$store.state.autoGpuPreview) { context.$root.$emit("globalTogglePreview", true); } context.$root.$emit("modalClosed"); }); }; return new Promise(showModal); }, modalNotify: function (message, status = "success") { UIkit.notification({ message: message, status: status, }); }, modalDialog: function (title, message) { UIkit.modal.dialog( `
${message}