Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Item details & Items list: Add Copy DSL Definition button #3084

Merged
merged 2 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@
<f7-list-button color="blue" @click="duplicateItem">
Duplicate Item
</f7-list-button>
<f7-list-button color="blue" @click="copyItemDslDefinition">
Copy DSL Definition
</f7-list-button>
<f7-list-button v-if="item.editable" color="red" @click="deleteItem">
Remove Item
</f7-list-button>
Expand Down Expand Up @@ -217,6 +220,20 @@ export default {
}
})
},
copyItemDslDefinition () {
this.$oh.api.getPlain({
url: '/rest/file-format/items/' + this.item.name,
headers: { accept: 'text/vnd.openhab.dsl.item' }
}).then(definition => {
if (this.$clipboard(definition)) {
this.$f7.toast.create({
text: `DSL Item definition for '${this.item.name}' copied to clipboard`,
destroyOnClose: true,
closeTimeout: 2000
}).open()
}
})
},
deleteItem () {
this.$f7.dialog.confirm(
`Are you sure you want to delete ${this.item.label || this.item.name}?`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,19 @@
</f7-subnavbar>
</f7-navbar>
<f7-toolbar class="contextual-toolbar" :class="{ 'navbar': $theme.md }" v-if="showCheckboxes" bottom-ios bottom-aurora>
<f7-link color="red" v-show="selectedItems.length" v-if="!$theme.md" class="delete" icon-ios="f7:trash" icon-aurora="f7:trash" @click="removeSelected">
<f7-link color="red" v-show="selectedItems.length" v-if="!$theme.md" class="delete right-margin" icon-ios="f7:trash" icon-aurora="f7:trash" @click="removeSelected">
Remove {{ selectedItems.length }}
</f7-link>
<f7-link color="blue" v-show="selectedItems.length" v-if="!$theme.md" class="copy" icon-ios="f7:square_on_square" icon-aurora="f7:square_on_square" @click="copySelected">
&nbsp;Copy DSL Definitions
</f7-link>
<f7-link v-if="$theme.md" icon-md="material:close" icon-color="white" @click="showCheckboxes = false" />
<div class="title" v-if="$theme.md">
{{ selectedItems.length }} selected
</div>
<div class="right" v-if="$theme.md">
<f7-link v-show="selectedItems.length" icon-md="material:delete" icon-color="white" @click="removeSelected" />
<div class="right" v-if="$theme.md && selectedItems.length">
<f7-link icon-md="material:delete" icon-color="white" @click="removeSelected" />
<f7-link icon-md="material:content_copy" icon-color="white" @click="copySelected" />
</div>
</f7-toolbar>

Expand Down Expand Up @@ -135,6 +139,11 @@
</style>

<script>
import Vue from 'vue'
import Clipboard from 'v-clipboard'

Vue.use(Clipboard)

import ItemMixin from '@/components/item/item-mixin'

export default {
Expand Down Expand Up @@ -273,6 +282,21 @@ export default {
this.selectedItems.push(item)
}
},
copySelected () {
const promises = this.selectedItems.map((itemName) => this.$oh.api.getPlain({
url: '/rest/file-format/items/' + itemName,
headers: { accept: 'text/vnd.openhab.dsl.item' }
}))
Promise.all(promises).then((data) => {
if (this.$clipboard(data.join('\n'))) {
this.$f7.toast.create({
text: 'DSL definitions copied to clipboard',
destroyOnClose: true,
closeTimeout: 2000
}).open()
}
})
},
removeSelected () {
const vm = this

Expand Down
Loading