Skip to content

Commit 6c88932

Browse files
authored
Item details & Items list: Add Copy DSL Definition button (#3084)
Add Copy DSL Definition for items, both in Item Details and Items List using the definition provided by openhab/openhab-core#4569. Resolves openhab/openhab-core#4509. --------- Signed-off-by: Jimmy Tanagra <[email protected]>
1 parent 40a8de5 commit 6c88932

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

bundles/org.openhab.ui/web/src/pages/settings/items/item-details.vue

+17
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@
9090
<f7-list-button color="blue" @click="duplicateItem">
9191
Duplicate Item
9292
</f7-list-button>
93+
<f7-list-button color="blue" @click="copyItemDslDefinition">
94+
Copy DSL Definition
95+
</f7-list-button>
9396
<f7-list-button v-if="item.editable" color="red" @click="deleteItem">
9497
Remove Item
9598
</f7-list-button>
@@ -217,6 +220,20 @@ export default {
217220
}
218221
})
219222
},
223+
copyItemDslDefinition () {
224+
this.$oh.api.getPlain({
225+
url: '/rest/file-format/items/' + this.item.name,
226+
headers: { accept: 'text/vnd.openhab.dsl.item' }
227+
}).then(definition => {
228+
if (this.$clipboard(definition)) {
229+
this.$f7.toast.create({
230+
text: `DSL Item definition for '${this.item.name}' copied to clipboard`,
231+
destroyOnClose: true,
232+
closeTimeout: 2000
233+
}).open()
234+
}
235+
})
236+
},
220237
deleteItem () {
221238
this.$f7.dialog.confirm(
222239
`Are you sure you want to delete ${this.item.label || this.item.name}?`,

bundles/org.openhab.ui/web/src/pages/settings/items/items-list-vlist.vue

+27-3
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,19 @@
1818
</f7-subnavbar>
1919
</f7-navbar>
2020
<f7-toolbar class="contextual-toolbar" :class="{ 'navbar': $theme.md }" v-if="showCheckboxes" bottom-ios bottom-aurora>
21-
<f7-link color="red" v-show="selectedItems.length" v-if="!$theme.md" class="delete" icon-ios="f7:trash" icon-aurora="f7:trash" @click="removeSelected">
21+
<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">
2222
Remove {{ selectedItems.length }}
2323
</f7-link>
24+
<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">
25+
&nbsp;Copy DSL Definitions
26+
</f7-link>
2427
<f7-link v-if="$theme.md" icon-md="material:close" icon-color="white" @click="showCheckboxes = false" />
2528
<div class="title" v-if="$theme.md">
2629
{{ selectedItems.length }} selected
2730
</div>
28-
<div class="right" v-if="$theme.md">
29-
<f7-link v-show="selectedItems.length" icon-md="material:delete" icon-color="white" @click="removeSelected" />
31+
<div class="right" v-if="$theme.md && selectedItems.length">
32+
<f7-link icon-md="material:delete" icon-color="white" @click="removeSelected" />
33+
<f7-link icon-md="material:content_copy" icon-color="white" @click="copySelected" />
3034
</div>
3135
</f7-toolbar>
3236

@@ -135,6 +139,11 @@
135139
</style>
136140

137141
<script>
142+
import Vue from 'vue'
143+
import Clipboard from 'v-clipboard'
144+
145+
Vue.use(Clipboard)
146+
138147
import ItemMixin from '@/components/item/item-mixin'
139148
140149
export default {
@@ -273,6 +282,21 @@ export default {
273282
this.selectedItems.push(item)
274283
}
275284
},
285+
copySelected () {
286+
const promises = this.selectedItems.map((itemName) => this.$oh.api.getPlain({
287+
url: '/rest/file-format/items/' + itemName,
288+
headers: { accept: 'text/vnd.openhab.dsl.item' }
289+
}))
290+
Promise.all(promises).then((data) => {
291+
if (this.$clipboard(data.join('\n'))) {
292+
this.$f7.toast.create({
293+
text: 'DSL definitions copied to clipboard',
294+
destroyOnClose: true,
295+
closeTimeout: 2000
296+
}).open()
297+
}
298+
})
299+
},
276300
removeSelected () {
277301
const vm = this
278302

bundles/org.openhab.ui/web/src/pages/settings/things/thing-details.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
<f7-list-button v-if="thing.statusInfo.statusDetail === 'HANDLER_MISSING_ERROR'" color="blue" title="Install Binding" @click="installBinding" />
140140
<f7-list-button v-if="!error" color="blue" title="Duplicate Thing" @click="duplicateThing" />
141141
<f7-list-button v-if="!error" color="blue" title="Copy DSL Definition" @click="copyThingDsl" />
142-
<f7-list-button v-if="editable" color="red" title="Remove Thing" @click="deleteThing"/>
142+
<f7-list-button v-if="editable" color="red" title="Remove Thing" @click="deleteThing" />
143143
</f7-list>
144144
</f7-col>
145145
</f7-block>

0 commit comments

Comments
 (0)