Skip to content

Commit

Permalink
Merge pull request #790 from IDEMSInternational/fix/rerendering
Browse files Browse the repository at this point in the history
Fix/rerendering
  • Loading branch information
smborio authored Jun 1, 2021
2 parents 7ec1b53 + 80fff28 commit e463ccd
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class TemplateNavService {
params: INavQueryParams,
container: TemplateContainerComponent
) {
log(`[Query Param Change] - ${container.name}`, { ...params });
log(`[Query Param Change] - ${container.name}`, { params, container });
const { nav_child, nav_parent, popup_child, popup_parent } = params;
const { parent, name } = container;
// handle nav delegation
Expand All @@ -42,6 +42,12 @@ export class TemplateNavService {
if (popup_child && popup_child === name) {
await this.handlePopupActionsFromChild(params, container);
}
// HACK - handle rerender on return
// TODO - merge with hacks folder on merge
// TODO - CC 2021-06-01 this will require refactor after nav-actions.service merge
if (!popup_child && !popup_parent && container.template) {
await container.forceRerender(true);
}
}
/*****************************************************************************************************
* Nav Actions
Expand Down
36 changes: 36 additions & 0 deletions src/app/shared/components/template/template-container.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ export class TemplateContainerComponent implements OnInit, OnDestroy, ITemplateC
// write completions to the database for data tracking
await this.templateService.recordEvent(template, "emit", emit_value);
}
// Handle a forced rerender
// TODO - CC 2021-06-01 merge with refactored code after nav-actions.service pr merge
if (emit_value === "force_rerender") {
await this.forceRerender(args[1] === "full");
}
if (parent) {
// continue to emit any actions to parent where defined
log(
Expand Down Expand Up @@ -276,6 +281,37 @@ export class TemplateContainerComponent implements OnInit, OnDestroy, ITemplateC
log_groupEnd();
}

/**
* Brute force method to force all parent and child templates to rerender
* e.g. in case where a nested child sets a field that needs to be shown on parent
* @param shouldProcess by default we only start processing after we have reached
* the top-most parent template, and then render down
* @param full specify whether to re-render fully as if template first load
* (including set_variable statements) or just to reprocess existing rows
*/
public async forceRerender(full = false, shouldProcess = false) {
if (shouldProcess) {
console.log("[Force Rerender]", this.name, full);
if (full) {
this.renderedRows = [];
await this.renderTemplate();
} else {
await this.processRowUpdates();
}
for (const child of Object.values(this.children || {})) {
await child.forceRerender(full, shouldProcess);
}
} else {
// ensure we start from the top-most parent template for rendering
if (this.parent) {
return this.parent.forceRerender(full, shouldProcess);
} else {
shouldProcess = true;
return this.forceRerender(full, shouldProcess);
}
}
}

/***************************************************************************************
* Template Initialisation
**************************************************************************************/
Expand Down

0 comments on commit e463ccd

Please sign in to comment.