Skip to content

Commit

Permalink
Update category filter when scenarios update (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
jggoebel authored Feb 16, 2024
1 parent e8e5081 commit c198542
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
25 changes: 20 additions & 5 deletions src/app/data/scenario.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,25 +109,40 @@ export class ScenarioService {
);
}

public update(iScenario: Scenario) {
var s = <Scenario>deepCopy(iScenario);
public update(s: Scenario) {
var steps = <Step[]>deepCopy(s.steps);
// step by step, re-encode to b64
s.steps.forEach((st: Step) => {
steps.forEach((st: Step) => {
st.title = utoa(st.title);
st.content = utoa(st.content);
});

var params = new HttpParams({ encoder: new CustomEncoder() })
.set('name', utoa(s.name))
.set('description', utoa(s.description))
.set('steps', JSON.stringify(s.steps))
.set('steps', JSON.stringify(steps))
.set('categories', JSON.stringify(s.categories))
.set('tags', JSON.stringify(s.tags))
.set('virtualmachines', JSON.stringify(s.virtualmachines))
.set('pause_duration', s.pause_duration)
.set('keepalive_duration', s.keepalive_duration);

return this.http.put(environment.server + '/a/scenario/' + s.id, params);
return this.http
.put(environment.server + '/a/scenario/' + s.id, params)
.pipe(
tap(() => {
// Find the index of the scenario in the cached list
const index = this.cachedScenarioList.findIndex(
(scenario) => scenario.id === s.id
);
if (index !== -1) {
// Replace the old scenario with the updated one
this.cachedScenarioList[index] = s;
}
// Update the cache with the new list
this.set(this.cachedScenarioList);
})
);
}

public create(s: Scenario) {
Expand Down
16 changes: 12 additions & 4 deletions src/app/filter-scenarios/filter-scenarios.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,12 @@ export class FilterScenariosComponent implements OnInit {
this.selectRbac = allowed;
});

this.scenarioService.watch().subscribe((s: Scenario[]) => {
this.updateScenarios(s);
});

this.scenarioService.list().subscribe((s: Scenario[]) => {
this.scenarios = s;
this.calculateCategories();
this.filterScenarioList();
this.emitScenarios(this.scenarios);
this.updateScenarios(s);
});

this.rbacService
Expand All @@ -111,4 +112,11 @@ export class FilterScenariosComponent implements OnInit {
this.emitScenarios(this.filteredScenarios);
});
}

updateScenarios(s: Scenario[]) {
this.scenarios = s;
this.calculateCategories();
this.filterScenarioList();
this.emitScenarios(this.scenarios);
}
}

0 comments on commit c198542

Please sign in to comment.