Skip to content

Commit

Permalink
Add save as copy to module and chart resources
Browse files Browse the repository at this point in the history
  • Loading branch information
kelanik8 committed Oct 19, 2023
1 parent 0073c0b commit 78a8dc1
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
23 changes: 21 additions & 2 deletions client/web/compose/src/views/Admin/Charts/Edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,11 @@
:processing="processing"
:hide-delete="hideDelete"
:hide-save="hideSave"
hide-clone
:hide-clone="!isEdit"
:disable-save="disableSave"
@delete="handleDelete()"
@save="handleSave()"
@clone="handleClone()"
@saveAndClose="handleSave({ closeOnSuccess: true })"
@back="$router.push(previousPage || { name: 'admin.charts' })"
/>
Expand Down Expand Up @@ -527,7 +528,9 @@ export default {
const { namespaceID } = this.namespace
if (chartID === NoID) {
let c = new compose.Chart({ namespaceID: this.namespace.namespaceID })
const chartClone = this.$attrs.chart || {}
let c = new compose.Chart({ namespaceID: this.namespace.namespaceID, ...chartClone })
switch (this.category) {
case 'gauge':
c = new compose.GaugeChart(c)
Expand Down Expand Up @@ -651,6 +654,22 @@ export default {
}).catch(this.toastErrorHandler(this.$t('notification:chart.deleteFailed')))
},
handleClone () {
const chart = this.chart.clone()
chart.chartID = NoID
chart.name = `${this.chart.name} (copy)`
chart.handle = `${this.chart.handle}_copy`
this.$router.push({
name: 'admin.charts.create',
params: {
chartID: NoID,
category: this.category || 'generic',
chart,
},
})
},
redirect () {
this.$router.push(this.previousPage || { name: 'admin.charts' })
},
Expand Down
25 changes: 20 additions & 5 deletions client/web/compose/src/views/Admin/Modules/Edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -440,12 +440,13 @@
<editor-toolbar
:processing="processing"
:hide-delete="hideDelete"
hide-clone
:hide-clone="!isEdit"
:hide-save="hideSave"
:disable-save="disableSave"
@delete="handleDelete"
@save="handleSave()"
@saveAndClose="handleSave({ closeOnSuccess: true })"
@clone="handleClone"
@back="$router.push(previousPage || { name: 'admin.modules' })"
/>
</portal>
Expand Down Expand Up @@ -657,10 +658,15 @@ export default {
this.activeTab = 0
if (moduleID === NoID) {
this.module = new compose.Module(
{ fields: [new compose.ModuleFieldString({ fieldID: NoID, name: this.$t('general.placeholder.sample') })] },
this.namespace,
)
if (this.$attrs.module) {
this.module = new compose.Module(this.$attrs.module, this.namespace)
} else {
this.module = new compose.Module(
{ fields: [new compose.ModuleFieldString({ fieldID: NoID, name: this.$t('general.placeholder.sample') })] },
this.namespace,
)
}
this.initialModuleState = this.module.clone()
} else {
const params = {
Expand Down Expand Up @@ -840,6 +846,15 @@ export default {
})
},
handleClone () {
const module = this.module.clone()
module.moduleID = NoID
module.name = `${this.module.name} (copy)`
module.handle = `${this.module.handle}_copy`
this.$router.push({ name: 'admin.modules.create', params: { module, moduleID: NoID } })
},
async fetchConnection (connectionID) {
if (connectionID && connectionID !== NoID) {
this.$SystemAPI.dalConnectionRead({ connectionID })
Expand Down
4 changes: 4 additions & 0 deletions lib/js/src/compose/types/chart/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,10 @@ export class BaseChart {
get resourceType (): string {
return 'compose:chart'
}

clone (): BaseChart {
return new BaseChart(JSON.parse(JSON.stringify(this)))
}
}

export { chartUtil } from './util'

0 comments on commit 78a8dc1

Please sign in to comment.