|
|
@ -10,10 +10,12 @@ export class Topic { |
|
|
|
this.closeTopicId = 'close-topic'; |
|
|
|
this.closeTopicId = 'close-topic'; |
|
|
|
this.contributionTextId = 'contrib-meta'; |
|
|
|
this.contributionTextId = 'contrib-meta'; |
|
|
|
|
|
|
|
|
|
|
|
this.activeRoadmapId = null; |
|
|
|
this.activeResourceType = null; |
|
|
|
|
|
|
|
this.activeResourceId = null; |
|
|
|
this.activeTopicId = null; |
|
|
|
this.activeTopicId = null; |
|
|
|
|
|
|
|
|
|
|
|
this.handleTopicClick = this.handleTopicClick.bind(this); |
|
|
|
this.handleRoadmapTopicClick = this.handleRoadmapTopicClick.bind(this); |
|
|
|
|
|
|
|
this.handleBestPracticeTopicClick = this.handleBestPracticeTopicClick.bind(this); |
|
|
|
|
|
|
|
|
|
|
|
this.close = this.close.bind(this); |
|
|
|
this.close = this.close.bind(this); |
|
|
|
this.resetDOM = this.resetDOM.bind(this); |
|
|
|
this.resetDOM = this.resetDOM.bind(this); |
|
|
@ -86,7 +88,7 @@ export class Topic { |
|
|
|
close() { |
|
|
|
close() { |
|
|
|
this.resetDOM(true); |
|
|
|
this.resetDOM(true); |
|
|
|
|
|
|
|
|
|
|
|
this.activeRoadmapId = null; |
|
|
|
this.activeResourceId = null; |
|
|
|
this.activeTopicId = null; |
|
|
|
this.activeTopicId = null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -115,11 +117,8 @@ export class Topic { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fetchTopicHtml(roadmapId, topicId) { |
|
|
|
renderTopicFromUrl(url) { |
|
|
|
const topicPartial = topicId.replace(/^\d+-/, '').replaceAll(/:/g, '/'); |
|
|
|
return fetch(url) |
|
|
|
const fullUrl = `/${roadmapId}/${topicPartial}`; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return fetch(fullUrl) |
|
|
|
|
|
|
|
.then((res) => { |
|
|
|
.then((res) => { |
|
|
|
return res.text(); |
|
|
|
return res.text(); |
|
|
|
}) |
|
|
|
}) |
|
|
@ -129,33 +128,45 @@ export class Topic { |
|
|
|
const node = new DOMParser().parseFromString(topicHtml, 'text/html'); |
|
|
|
const node = new DOMParser().parseFromString(topicHtml, 'text/html'); |
|
|
|
|
|
|
|
|
|
|
|
return node.getElementById('main-content'); |
|
|
|
return node.getElementById('main-content'); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.then((content) => { |
|
|
|
|
|
|
|
this.populate(content); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.catch((e) => { |
|
|
|
|
|
|
|
console.error(e); |
|
|
|
|
|
|
|
this.populate('Error loading the content!'); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
handleTopicClick(e) { |
|
|
|
handleBestPracticeTopicClick(e) { |
|
|
|
const { roadmapId, topicId } = e.detail; |
|
|
|
const { resourceId: bestPracticeId, topicId } = e.detail; |
|
|
|
if (!topicId || !roadmapId) { |
|
|
|
if (!topicId || !bestPracticeId) { |
|
|
|
console.log('Missing topic or roadmap: ', e.detail); |
|
|
|
console.log('Missing topic or bestPracticeId: ', e.detail); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.activeRoadmapId = roadmapId; |
|
|
|
this.activeResourceType = 'best-practice'; |
|
|
|
|
|
|
|
this.activeResourceId = bestPracticeId; |
|
|
|
this.activeTopicId = topicId; |
|
|
|
this.activeTopicId = topicId; |
|
|
|
|
|
|
|
|
|
|
|
if (/^ext_link/.test(topicId)) { |
|
|
|
this.resetDOM(); |
|
|
|
window.open(`https://${topicId.replace('ext_link:', '')}`); |
|
|
|
|
|
|
|
|
|
|
|
alert('Best practices are not yet implemented!'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
handleRoadmapTopicClick(e) { |
|
|
|
|
|
|
|
const { resourceId: roadmapId, topicId } = e.detail; |
|
|
|
|
|
|
|
if (!topicId || !roadmapId) { |
|
|
|
|
|
|
|
console.log('Missing topic or roadmap: ', e.detail); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.activeResourceType = 'roadmap'; |
|
|
|
|
|
|
|
this.activeResourceId = roadmapId; |
|
|
|
|
|
|
|
this.activeTopicId = topicId; |
|
|
|
|
|
|
|
|
|
|
|
this.resetDOM(); |
|
|
|
this.resetDOM(); |
|
|
|
this.fetchTopicHtml(roadmapId, topicId) |
|
|
|
this.renderTopicFromUrl(`/${roadmapId}/${topicId.replaceAll(':', '/')}`); |
|
|
|
.then((content) => { |
|
|
|
|
|
|
|
this.populate(content); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.catch((e) => { |
|
|
|
|
|
|
|
console.error(e); |
|
|
|
|
|
|
|
this.populate('Error loading the content!'); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
queryRoadmapElementsByTopicId(topicId) { |
|
|
|
queryRoadmapElementsByTopicId(topicId) { |
|
|
@ -219,7 +230,8 @@ export class Topic { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
init() { |
|
|
|
init() { |
|
|
|
window.addEventListener('topic.click', this.handleTopicClick); |
|
|
|
window.addEventListener('roadmap.topic.click', this.handleRoadmapTopicClick); |
|
|
|
|
|
|
|
window.addEventListener('best-practice.topic.click', this.handleBestPracticeTopicClick); |
|
|
|
window.addEventListener('click', this.handleOverlayClick); |
|
|
|
window.addEventListener('click', this.handleOverlayClick); |
|
|
|
window.addEventListener('contextmenu', this.rightClickListener); |
|
|
|
window.addEventListener('contextmenu', this.rightClickListener); |
|
|
|
|
|
|
|
|
|
|
|