Skip to content

Commit

Permalink
added clone functionality to scenarios (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
ebauman authored Dec 18, 2024
1 parent 2e323c7 commit f2ab2bf
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/app/data/scenario.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ export class ScenarioService {
);
}

public clone(scenarioId: string) {
return this.gargAdmin.post(`/copy/${scenarioId}`, null).pipe(
catchError((e: HttpErrorResponse) => {
return throwError(() => e.error);
}),
)
}

public update(s: Scenario) {
var steps = structuredClone(s.steps);
// step by step, re-encode to b64
Expand Down
1 change: 1 addition & 0 deletions src/app/scenario/scenario.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ <h3>Scenarios</h3>
>
Delete
</button>
<button class="action-item" (click)="cloneScenario(s.id)" *rbac="['scenarios.get', 'scenarios.create']; op: 'AND'">Clone</button>
</clr-dg-action-overflow>
}
<clr-dg-cell>{{ s.id }}</clr-dg-cell>
Expand Down
14 changes: 14 additions & 0 deletions src/app/scenario/scenario.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@ export class ScenarioComponent implements OnInit {
});
}

cloneScenario(scenarioId: string) {
this.scenarioService.clone(scenarioId).subscribe({
next: (_s: ServerResponse) => {
const alertMsg = 'Scenario cloned';
this.alert.success(alertMsg, true, DEFAULT_ALERT_SUCCESS_DURATION);
this.refresh();
},
error: (e: HttpErrorResponse) => {
const alertMsg = 'Error cloning scenario: ' + e.error.message;
this.alert.danger(alertMsg, true, DEFAULT_ALERT_ERROR_DURATION);
},
})
}

deleteScenario(scenarioId: string) {
this.scenarioService.delete(scenarioId).subscribe({
next: (_s: ServerResponse) => {
Expand Down

0 comments on commit f2ab2bf

Please sign in to comment.