UNPKG

@5minds/node-red-dashboard-2-processcube-ui-page-navigation

Version:

A node to handle the navigation between pages in the Node-RED Dashboard

2 lines (1 loc) 1.35 kB
(function(t,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("vuex")):typeof define=="function"&&define.amd?define(["exports","vuex"],i):(t=typeof globalThis<"u"?globalThis:t||self,i(t["ui-page-navigation"]={},t.vuex))})(this,function(t,i){"use strict";const n={name:"DBUIEvent",inject:["$socket","$dataTracker"],props:{id:{type:String,required:!0},props:{type:Object,default:()=>({})}},data(){return{page:null}},computed:{...i.mapState("ui",["pages"]),pagename(){return this.props.pagename}},watch:{"$route.meta.id":{handler(e,s){const a=this.pages[s],r=this.pages[e];console.log(`handler: ${a.name} ${r.name} --> ${this.pagename}`),this.trigger("$pageleave",a),this.trigger("$pageview",r)}}},created(){this.$dataTracker(this.id),this.page=this.pages[this.$route.meta.id],this.pageview()},unmounted(){this.pageleave()},methods:{pageview(){this.trigger("$pageview",this.page)},pageleave(){this.trigger("$pageleave",this.page)},trigger(e,s){const a=this.page.name==this.pagename;if(console.log(`trigger: fire ${a} ${e} ${s.name} ${this.pagename}`),!a)return;const r=this.createPayload(s);this.$socket.emit("widget-send",this.id,{topic:e,payload:r})},createPayload(e){return e={...e},e._groups=e._users,delete e._users,{page:e,query:this.$route.query}}}};t.UIPageNavigation=n,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});