import BsModal from "../Bootstrap/Modal.js"; import HeightTransition from "../Tranistion/HeightTransition.js"; import { enableDragDropTouch } from "../../../../vendor/drag-drop-touch-js/dragdroptouch/dist/drag-drop-touch.esm.min.js"; if (!document.dragDropTouchActive) { enableDragDropTouch(); document.dragDropTouchActive = true; } export default { name: 'Item', components: { BsModal, HeightTransition }, data: () => ({ component: "", arguments: null, tmpConfig: {}, isLoading: false, hasConfig: false, sharedData: null }), emits: [ "change", "remove", "configOpened", "configClosed", "pinItem", "unPinItem" ], props: [ "id", "config", "width", "height", "custom", "hidden", "editMode", "loading", // widget got added and is waiting for backend to save in db "item_data", "place", "widgetTemplate", "source" ], computed: { sourceInfoTooltip() { switch (this.source) { case null: return ''; case 'general': return this.$p.t('dashboard', 'widgetFromGeneralSection'); case 'custom': return this.$p.t('dashboard', 'widgetFromCustomSection'); default: return this.$p.t('dashboard', 'widgetFromFunktionSection', [this.source]); } }, isResizeableHorizontal() { if (this.widgetTemplate.setup.width === undefined) return true; if (Object.prototype.toString.call(this.widgetTemplate.setup.width) == "[object Number]") return false; if (this.widgetTemplate.setup.width.min === undefined) { if (this.widgetTemplate.setup.width.max === undefined) return true; return this.widgetTemplate.setup.width.max > 1; } if (this.widgetTemplate.setup.width.max === undefined) return true; return this.widgetTemplate.setup.width.max > this.widgetTemplate.setup.width.min; }, isResizeableVertical() { if (this.widgetTemplate.setup.height === undefined) return true; if (Object.prototype.toString.call(this.widgetTemplate.setup.height) == "[object Number]") return false; if (this.widgetTemplate.setup.height.min === undefined) { if (this.widgetTemplate.setup.height.max === undefined) return true; return this.widgetTemplate.setup.height.max > 1; } if (this.widgetTemplate.setup.height.max === undefined) return true; return this.widgetTemplate.setup.height.max > this.widgetTemplate.setup.height.min; }, isResizeable() { return this.isResizeableVertical || this.isResizeableHorizontal; }, resizeClasses() { const classes = { icon: 'fa-up-right-and-down-left-from-center mirror-x', button: 'cursor-nw-resize' }; if (!this.isResizeableHorizontal) { classes.icon = 'fa-up-down pe-2'; classes.button = 'cursor-ns-resize'; } else if (!this.isResizeableVertical) { classes.icon = 'fa-left-right pe-2'; classes.button = 'cursor-ew-resize'; } return classes; }, isPinned() { return this.place?.pinned ? true : false; }, ready() { return this.component && this.arguments !== null; }, visible: { get() { return !this.hidden; }, set(value) { this.$emit('remove', this.hidden); } } }, methods: { unpin() { // Unpinning is only possible in edit mode if (!this.editMode) return; let result = { item: this.item_data, pinned: false }; this.$emit('unPinItem', [result]); }, pinItem() { let result = { item: this.item_data, pinned: true }; this.$emit('pinItem', [result]); }, getWidgetC4Link(widget) { return (FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + widget.setup.cis4link) }, handleShowBsModal() { this.$emit('configOpened') }, handleHideBsModal() { this.$emit('configClosed') }, openConfig() { this.tmpConfig = { ...this.arguments }; this.$refs.config.show(); }, setConfig(hasConfig) { this.hasConfig = hasConfig; }, changeConfig() { this.isLoading = true; let config = { ...this.tmpConfig }; this.sendChangeConfig(config); }, changeConfigManually() { let config = { ...this.arguments }; this.sendChangeConfig(config); }, sendChangeConfig(config) { for (var k in config) { if (this.widgetTemplate.arguments[k] == config[k]) { delete config[k]; } } this.$emit("change", config); }, async initializeComponent() { if ( this.widgetTemplate && this.widgetTemplate.setup && this.widgetTemplate.widget_id && this.widgetTemplate.arguments ) { let component = (await import(this.widgetTemplate.setup.file)).default; this.$options.components["widget" + this.widgetTemplate.widget_id] = component; this.component = "widget" + this.widgetTemplate.widget_id; this.arguments = { ...this.widgetTemplate.arguments, ...this.config }; this.tmpConfig = { ...this.arguments }; } } }, watch: { config() { this.arguments = { ...this.widgetTemplate?.arguments, ...this.config }; this.tmpConfig = { ...this.arguments }; this.$refs.config && this.$refs.config.hide(); this.isLoading = false; }, widgetTemplate() { this.initializeComponent(); } }, created() { this.initializeComponent(); }, template: /*html*/ `
`, };