fix: Update tag counts when changes are saved in the tag drawer

* fix: courseAuthoringUrl on message listener
This commit is contained in:
XnpioChV
2024-02-12 16:36:17 -05:00
committed by David Ormsbee
parent 5f44c2ceb2
commit b9da8969e6
2 changed files with 10 additions and 12 deletions

View File

@@ -376,15 +376,14 @@ function($, _, gettext, BaseView, ViewUtils, XBlockViewUtils, MoveXBlockUtils, H
"message", (event) => {
// Listen any message from Manage tags drawer.
var data = event.data;
var courseAuthoringUrl = this.model.get("course_authoring_url")
var courseAuthoringUrl = new URL(this.model.get("course_authoring_url")).origin;
if (event.origin == courseAuthoringUrl
&& data.includes('[Manage tags drawer] Tags updated:')) {
&& data.type == 'authoring.events.tags.updated') {
// This message arrives when there is a change in the tag list.
// The message contains the new list of tags.
let jsonData = data.replace(/\[Manage tags drawer\] Tags updated: /g, "");
jsonData = JSON.parse(jsonData);
if (jsonData.contentId == this.model.id) {
this.model.set('tags', this.buildTaxonomyTree(jsonData));
data = data.data
if (data.contentId == this.model.id) {
this.model.set('tags', this.buildTaxonomyTree(data));
this.render();
}
}

View File

@@ -21,15 +21,14 @@ function($, _, BaseView, HtmlUtils) {
'message', (event) => {
// Listen any message from Manage tags drawer.
var data = event.data;
var courseAuthoringUrl = this.model.get("course_authoring_url")
var courseAuthoringUrl = new URL(this.model.get("course_authoring_url")).origin;
if (event.origin == courseAuthoringUrl
&& data.includes('[Manage tags drawer] Count updated:')) {
&& data.type == 'authoring.events.tags.count.updated') {
// This message arrives when there is a change in the tag list.
// The message contains the new count of tags.
let jsonData = data.replace(/\[Manage tags drawer\] Count updated: /g, "");
jsonData = JSON.parse(jsonData);
if (jsonData.contentId == this.model.get("content_id")) {
this.model.set('tags_count', jsonData.count);
data = data.data
if (data.contentId == this.model.get("content_id")) {
this.model.set('tags_count', data.count);
this.render();
}
}