Skip to content

Commit

Permalink
FIX: Refresh preview pane on deletion of templates (#42)
Browse files Browse the repository at this point in the history
See #39 and #41
  • Loading branch information
jaidevd authored Feb 10, 2020
1 parent 90983a5 commit 08c54ef
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
17 changes: 7 additions & 10 deletions nlg/app/nlg.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,22 +271,19 @@ function refreshTemplates() {
// Refresh the output of all templates in the current narrative.
templates = []
$.getJSON(`${nlg_base}/narratives`).done((e) => {
for (let i=0; i<e.narrative.length;i++) {
refreshTemplate(i)
if (e.narrative.length > 0) {
for (let i=0; i<e.narrative.length;i++) {
refreshTemplate(i)
}
} else {
renderPreview(null)
}
})
}

function deleteTemplate(n) {
// Delete a template
$.getJSON(`${nlg_base}/nuggets/${n}?delete`).done((e) => {
templates = []
for (i=0; i<e.length; i++) {
templates[i] = new Template(e[i])
$('#tmpl-setting-preview').html(templates[i].previewHTML())
}
renderPreview(null)
})
$.getJSON(`${nlg_base}/nuggets/${n}?delete`).done(refreshTemplates)
}

function triggerTemplateSettings(sentid) {
Expand Down
9 changes: 6 additions & 3 deletions nlg/webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def get_nugget(handler):
nugget_id = int(handler.path_args[0])
if 'delete' in handler.args:
del NARRATIVE_CACHE[handler.current_user.id][nugget_id]
return json.dumps(NARRATIVE_CACHE[handler.current_user.id].to_dict())
return NARRATIVE_CACHE[handler.current_user.id].to_dict()
else:
nugget = NARRATIVE_CACHE[handler.current_user.id][nugget_id]
nugget = nugget.to_dict()
Expand Down Expand Up @@ -200,8 +200,11 @@ def render_narrative(handler):
narrative = NARRATIVE_CACHE.get(handler.current_user.id, False)
if narrative:
style_kwargs = get_style_kwargs(handler.args)
return {'render': narrative.to_html(**style_kwargs, df=orgdf),
'style': narrative.html_style}
pl = {'render': narrative.to_html(**style_kwargs, df=orgdf),
'style': narrative.html_style}
else:
pl = {'render': '', 'style': Narrative.default_style}
return pl


def get_original_df(handler):
Expand Down

0 comments on commit 08c54ef

Please sign in to comment.