Skip to content

Commit

Permalink
Add a transformations menu and editor (#1448)
Browse files Browse the repository at this point in the history
Depends on openhab/openhab-core#3036

--
Signed-off-by: Jan N. Klug <github@klug.nrw>
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
  • Loading branch information
J-N-K authored Apr 5, 2023
1 parent 5415abb commit dedd3f8
Show file tree
Hide file tree
Showing 10 changed files with 653 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default {
SNIPPETS: {
SCRIPT: {
'application/vnd.openhab.dsl.rule': 'var returnValue = "String has " + input.length + " characters"\n\nreturnValue',
'application/javascript': '(function(data) {\n var returnValue = "String has " + data.length + " characters"\n return returnValue\n})(input)',
'application/javascript;version=ECMAScript-5.1': '(function(data) {\n var returnValue = "String has " + data.length + " characters"\n return returnValue\n})(input)',
'application/x-ruby': '"String has #{input.length} characters"'
}
},
EDITOR_MODES: {
MAP: 'text/x-properties',
SCALE: 'text/x-properties'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import 'codemirror/mode/groovy/groovy.js'
import 'codemirror/mode/python/python.js'
import 'codemirror/mode/ruby/ruby.js'
import 'codemirror/mode/yaml/yaml.js'
import 'codemirror/mode/properties/properties.js'
// theme css
import 'codemirror/theme/gruvbox-dark.css'
Expand Down Expand Up @@ -174,6 +175,7 @@ export default {
if (this.mode && this.mode.indexOf('ruby') >= 0) return 'text/x-ruby'
if (this.mode && this.mode.indexOf('groovy') >= 0) return 'text/x-groovy'
if (this.mode && this.mode === 'rb') return 'text/x-ruby'
if (this.mode && this.mode === 'properties') return 'text/x-properties'
return this.mode
},
ternComplete (file, query) {
Expand Down
14 changes: 14 additions & 0 deletions bundles/org.openhab.ui/web/src/js/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ const AddThingPage = () => import(/* webpackChunkName: "admin-config" */ '../pag

const InboxListPage = () => import(/* webpackChunkName: "admin-config" */ '../pages/settings/things/inbox/inbox-list.vue')

const TransformationsListPage = () => import(/* webpackChunkName: "admin-config" */ '../pages/settings/transformations/transformations-list.vue')
const TransformationsEditPage = () => import(/* webpackChunkName: "admin-rules" */ '../pages/settings/transformations/transformation-edit.vue')

const SemanticModelPage = () => import(/* webpackChunkName: "admin-config" */ '../pages/settings/model/model.vue')

const PagesListPage = () => import(/* webpackChunkName: "admin-pages" */ '../pages/settings/pages/pages-list.vue')
Expand Down Expand Up @@ -176,6 +179,17 @@ export default [
}
]
},
{
path: 'transformations/',
async: loadAsync(TransformationsListPage),
routes: [
{
path: ':transformationId',
beforeLeave: checkDirtyBeforeLeave,
async: loadAsync(TransformationsEditPage, (routeTo) => (routeTo.params.transformationId === 'add') ? { createMode: true } : {})
}
]
},
{
path: 'things/',
beforeEnter: [enforceAdminForRoute],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
import YAML from 'yaml'
import { strOptions } from 'yaml/types'
import BlocklyEditor from '@/pages/settings/rules/script/blockly-editor.vue'
import BlocklyEditor from '@/components/config/controls/blockly-editor.vue'
import BlockPreview from './block-preview.vue'
import ConfigSheet from '@/components/config/config-sheet.vue'
import DirtyMixin from '@/pages/settings/dirty-mixin'
Expand All @@ -115,7 +115,7 @@ export default {
mixins: [DirtyMixin],
components: {
'editor': () => import(/* webpackChunkName: "script-editor" */ '@/components/config/controls/script-editor.vue'),
BlocklyEditor, // 'blockly-editor': () => import(/* webpackChunkName: "blockly-editor" */ '@/pages/settings/rules/script/blockly-editor.vue'),
BlocklyEditor, // 'blockly-editor': () => import(/* webpackChunkName: "blockly-editor" */ '@/components/config/controls/blockly-editor.vue'),
BlockPreview // 'block-preview': () => import(/* webpackChunkName: "blockly-editor" */ './block-preview.vue')
},
props: ['uid', 'createMode'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export default {
components: {
ScriptGeneralSettings,
'editor': () => import(/* webpackChunkName: "script-editor" */ '@/components/config/controls/script-editor.vue'),
'blockly-editor': () => import(/* webpackChunkName: "blockly-editor" */ './blockly-editor.vue')
'blockly-editor': () => import(/* webpackChunkName: "blockly-editor" */ '@/components/config/controls/blockly-editor.vue')
},
props: ['ruleId', 'moduleId', 'createMode'],
data () {
Expand Down
13 changes: 13 additions & 0 deletions bundles/org.openhab.ui/web/src/pages/settings/settings-menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@
:footer="objectsSubtitles.pages">
<f7-icon slot="media" f7="tv" color="gray" />
</f7-list-item>
<f7-list-item
v-if="$store.getters.apiEndpoint('transformations')"
media-item
link="transformations/"
title="Transformations"
:after="transformationsCount"
badge-color="blue"
:footer="objectsSubtitles.transform">
<f7-icon slot="media" f7="arrow_2_squarepath" color="gray" />
</f7-list-item>
</f7-list>
<f7-block-title v-if="$store.getters.apiEndpoint('rules')">
Automation
Expand Down Expand Up @@ -157,6 +167,7 @@ export default {
model: 'The semantic model of your home',
items: 'Manage the functional layer',
pages: 'Design displays for user control & monitoring',
transform: 'Manage transformations',
rules: 'Automate with triggers and actions',
scenes: 'Store a set of desired states as a scene',
scripts: 'Rules dedicated to running code',
Expand All @@ -165,6 +176,7 @@ export default {
inboxCount: '',
thingsCount: '',
itemsCount: '',
transformationsCount: '',
sitemapsCount: 0
}
},
Expand Down Expand Up @@ -199,6 +211,7 @@ export default {
if (this.$store.getters.apiEndpoint('things')) this.$oh.api.get('/rest/things?summary=true').then((data) => { this.thingsCount = data.length.toString() })
if (this.$store.getters.apiEndpoint('items')) this.$oh.api.get('/rest/items').then((data) => { this.itemsCount = data.length.toString() })
if (this.$store.getters.apiEndpoint('ui')) this.$oh.api.get('/rest/ui/components/system:sitemap?summary=true').then((data) => { this.sitemapsCount = data.length })
if (this.$store.getters.apiEndpoint('transformations')) this.$oh.api.get('/rest/transformations').then((data) => { this.transformationsCount = data.length })
},
navigateToStore (tab) {
this.$f7.views.main.router.navigate('addons', { props: { initialTab: tab } })
Expand Down
Loading

0 comments on commit dedd3f8

Please sign in to comment.