diff --git a/waltz-ng/client/report-grid/components/svelte/ReportGridCloneConfirmation.svelte b/waltz-ng/client/report-grid/components/svelte/ReportGridCloneConfirmation.svelte
new file mode 100644
index 0000000000..22e8fa6214
--- /dev/null
+++ b/waltz-ng/client/report-grid/components/svelte/ReportGridCloneConfirmation.svelte
@@ -0,0 +1,47 @@
+
+
+
+
Cloning report grid: {grid.definition.name}
+
+ - Please provide a name for the new grid
+ - All columns will be copied to the newly created grid
+ - You will be an owner of the new grid, able to edit columns and members
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/waltz-ng/client/report-grid/components/svelte/ReportGridOverview.svelte b/waltz-ng/client/report-grid/components/svelte/ReportGridOverview.svelte
index 8ed0d95dd9..e99f1fdc98 100644
--- a/waltz-ng/client/report-grid/components/svelte/ReportGridOverview.svelte
+++ b/waltz-ng/client/report-grid/components/svelte/ReportGridOverview.svelte
@@ -5,6 +5,7 @@
import {ownedReportIds, selectedGrid} from "./report-grid-store";
import {reportGridKinds} from "./report-grid-utils";
import ReportGridEditor from "./ReportGridEditor.svelte";
+ import ReportGridCloneConfirmation from "./ReportGridCloneConfirmation.svelte";
import {reportGridMemberStore} from "../../../svelte-stores/report-grid-member-store";
import {reportGridStore} from "../../../svelte-stores/report-grid-store";
import toasts from "../../../svelte-stores/toast-store";
@@ -19,7 +20,8 @@
const Modes = {
VIEW: "VIEW",
EDIT: "EDIT",
- REMOVE: "REMOVE"
+ REMOVE: "REMOVE",
+ CLONE: "CLONE"
};
let activeMode = Modes.VIEW;
@@ -76,7 +78,19 @@
.catch(e => toasts.error("Could not update grid. " + e.error));
}
- function remove(grid){
+ function clone(gridId, cloneCmd) {
+ let savePromise = reportGridStore.clone(gridId, cloneCmd);
+ Promise.resolve(savePromise)
+ .then(r => {
+ toasts.success("Grid cloned successfully")
+ const grid = r.data;
+ selectGrid(grid);
+ reportGridCall = reportGridStore.findForUser(true);
+ })
+ .catch(e => toasts.error("Could not clone grid. " + e.error));
+ }
+
+ function remove(grid) {
let rmPromise = reportGridStore.remove(grid.id);
Promise.resolve(rmPromise)
@@ -141,6 +155,10 @@
+ {:else if activeMode === Modes.CLONE}
+
{:else if activeMode === Modes.VIEW || activeMode === Modes.REMOVE}
{#if $selectedGrid?.definition?.id}
@@ -235,20 +253,34 @@
{#if activeMode === Modes.VIEW}
+
- To edit the columns for the grid use the 'Column Editor' tab above.
+
+ To edit the columns for the grid use the 'Column Editor' tab above.
{/if}
{:else}
- You cannot edit this grid as you are not an owner.
+
+ You cannot edit this grid as you are not an owner.
+
{/if}
{:else}
Waiting for grid selection
diff --git a/waltz-ng/client/svelte-stores/report-grid-store.js b/waltz-ng/client/svelte-stores/report-grid-store.js
index 5d0d2aae28..06586d001b 100644
--- a/waltz-ng/client/svelte-stores/report-grid-store.js
+++ b/waltz-ng/client/svelte-stores/report-grid-store.js
@@ -51,6 +51,10 @@ export function mkReportGridStore() {
return remote.execute("DELETE", `api/report-grid/id/${id}`);
};
+ const clone = (id, cloneCmd) => {
+ return remote.execute("POST", `api/report-grid/id/${id}/clone`, cloneCmd);
+ };
+
return {
findAll,
@@ -60,7 +64,8 @@ export function mkReportGridStore() {
updateColumnDefinitions,
create,
update,
- remove
+ remove,
+ clone
};
}
diff --git a/waltz-service/src/main/java/org/finos/waltz/service/report_grid/ReportGridService.java b/waltz-service/src/main/java/org/finos/waltz/service/report_grid/ReportGridService.java
index ceaa8b2404..72cb10bf79 100644
--- a/waltz-service/src/main/java/org/finos/waltz/service/report_grid/ReportGridService.java
+++ b/waltz-service/src/main/java/org/finos/waltz/service/report_grid/ReportGridService.java
@@ -283,4 +283,26 @@ public Set findAdditionalColumnOptionsForKind(EntityKin
public ReportGridDefinition getGridDefinitionByExtId(String gridExtId) {
return reportGridDao.getGridDefinitionByExternalId(gridExtId);
}
+
+ public ReportGridDefinition clone(long id, ReportGridUpdateCommand updateCommand, String username) {
+
+ ReportGridDefinition gridToClone = reportGridDao.getGridDefinitionById(id);
+
+ ImmutableReportGridCreateCommand newGridCreateCommand = ImmutableReportGridCreateCommand.builder()
+ .name(updateCommand.name())
+ .description(updateCommand.description())
+ .subjectKind(gridToClone.subjectKind())
+ .build();
+
+ ReportGridDefinition newGrid = create(newGridCreateCommand, username);
+
+ ImmutableReportGridColumnDefinitionsUpdateCommand updateColsCmd = ImmutableReportGridColumnDefinitionsUpdateCommand.builder()
+ .fixedColumnDefinitions(gridToClone.fixedColumnDefinitions())
+ .derivedColumnDefinitions(gridToClone.derivedColumnDefinitions())
+ .build();
+
+ reportGridDao.updateColumnDefinitions(newGrid.id().get(), updateColsCmd);
+
+ return newGrid;
+ }
}
diff --git a/waltz-web/src/main/java/org/finos/waltz/web/endpoints/api/ReportGridEndpoint.java b/waltz-web/src/main/java/org/finos/waltz/web/endpoints/api/ReportGridEndpoint.java
index 1be5aa9ba7..55aa7b4992 100644
--- a/waltz-web/src/main/java/org/finos/waltz/web/endpoints/api/ReportGridEndpoint.java
+++ b/waltz-web/src/main/java/org/finos/waltz/web/endpoints/api/ReportGridEndpoint.java
@@ -55,6 +55,7 @@ public void register() {
String createPath = mkPath(BASE_URL, "create");
String updatePath = mkPath(BASE_URL, "id", ":id", "update");
String removalPath = mkPath(BASE_URL, "id", ":id");
+ String clonePath = mkPath(BASE_URL, "id", ":id", "clone");
String findForOwnerPath = mkPath(BASE_URL, "owner");
String getViewByIdPath = mkPath(BASE_URL, "view", "id", ":id");
String getDefinitionByIdPath = mkPath(BASE_URL, "definition", "id", ":id");
@@ -70,6 +71,7 @@ public void register() {
postForDatum(updateColumnDefsPath, this::updateColumnDefsRoute);
postForDatum(createPath, this::createRoute);
postForDatum(updatePath, this::updateRoute);
+ postForDatum(clonePath, this::cloneRoute);
deleteForDatum(removalPath, this::removalRoute);
}
@@ -118,6 +120,12 @@ public ReportGridDefinition updateRoute(Request req,
update(getId(req), readBody(req, ReportGridUpdateCommand.class), getUsername(req));
}
+ public ReportGridDefinition cloneRoute(Request req,
+ Response resp) throws IOException, InsufficientPrivelegeException {
+ return reportGridService
+ .clone(getId(req), readBody(req, ReportGridUpdateCommand.class), getUsername(req));
+ }
+
public Set findForOwnerRoute(Request req,
Response resp) {