Skip to content

Commit 949ad0d

Browse files
committed
🔧 Make template api more consistent
1 parent 270be92 commit 949ad0d

21 files changed

+92
-129
lines changed

plugins/csp-fly-to-locations/gui/fly-to-locations-grid-button.html

-21
This file was deleted.

plugins/csp-fly-to-locations/gui/fly-to-locations-list-item.html

-30
This file was deleted.

plugins/csp-fly-to-locations/gui/fly-to-locations-tab.html

+44-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,47 @@
2121
Add new Bookmark
2222
</a>
2323
</div>
24-
</div>
24+
</div>
25+
26+
<template id="fly-to-locations-list-item-template">
27+
<div class="row px-0 mx-0">
28+
<div class="flex-grow-1 py-2">
29+
<span class="flytolocations-bookmarks-name">%NAME%</span>
30+
</div>
31+
<div class="px-1">
32+
<a class="btn glass block px-3" data-toggle="tooltip" title="Edit Bookmark"
33+
data-boundary="window" onclick="CosmoScout.callbacks.bookmark.edit(%ID%)">
34+
<i class="material-icons">edit</i>
35+
</a>
36+
</div>
37+
<div class="px-1 flytolocations-bookmarks-time-button">
38+
<a class="btn glass block px-3" data-toggle="tooltip" title="Go to Bookmark time"
39+
data-boundary="window" onclick="CosmoScout.callbacks.bookmark.gotoTime(%ID%)">
40+
<i class="material-icons">update</i>
41+
</a>
42+
</div>
43+
<div class="px-1">
44+
<a class="btn glass block px-3" data-toggle="tooltip" title="Go to Bookmark location"
45+
data-boundary="window" onclick="CosmoScout.callbacks.bookmark.gotoLocation(%ID%)">
46+
<i class="material-icons">place</i>
47+
</a>
48+
</div>
49+
</div>
50+
</template>
51+
52+
<template id="fly-to-locations-grid-button-template">
53+
<div class="col-3 center flytolocations-bookmarks-grid-body-button p-1">
54+
<a class="block btn glass" onclick="CosmoScout.callbacks.bookmark.gotoLocation(%ID%)">
55+
<img src="../icons/%ICON%" height="80" width="80">
56+
<span class="flytolocations-bookmarks-name">%NAME%</span>
57+
<a class="flytolocations-bookmarks-grid-edit-button btn light-glass px-1"
58+
onclick="CosmoScout.callbacks.bookmark.edit(%ID%)">
59+
<i class="material-icons">edit</i>
60+
</a>
61+
<a class="flytolocations-bookmarks-grid-delete-button btn light-glass px-1"
62+
onclick="CosmoScout.callbacks.bookmark.remove(%ID%)">
63+
<i class="material-icons">close</i>
64+
</a>
65+
</a>
66+
</div>
67+
</template>

plugins/csp-fly-to-locations/gui/js/csp-fly-to-locations.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* @param bookmarkIcon {string}
2525
*/
2626
addGridBookmark(bookmarkID, bookmarkName, bookmarkIcon) {
27-
let button = CosmoScout.gui.loadTemplateContent('fly-to-locations-grid-button');
27+
let button = CosmoScout.gui.loadTemplateContent('fly-to-locations-grid-button-template');
2828
button.innerHTML = button.innerHTML.replace(/%NAME%/g, bookmarkName)
2929
.replace(/%ICON%/g, bookmarkIcon)
3030
.replace(/%ID%/g, bookmarkID)
@@ -43,7 +43,7 @@
4343
* @param bookmarkHasTime {boolean}
4444
*/
4545
addListBookmark(bookmarkID, bookmarkName, bookmarkHasTime) {
46-
let listItem = CosmoScout.gui.loadTemplateContent('fly-to-locations-list-item');
46+
let listItem = CosmoScout.gui.loadTemplateContent('fly-to-locations-list-item-template');
4747
listItem.innerHTML =
4848
listItem.innerHTML.replace(/%NAME%/g, bookmarkName).replace(/%ID%/g, bookmarkID).trim();
4949
listItem.id = `flytolocations-bookmark-${bookmarkID}`;

plugins/csp-fly-to-locations/src/Plugin.cpp

+1-10
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ void Plugin::init() {
3333

3434
logger().info("Loading plugin...");
3535

36-
mGuiManager->addTemplate(
37-
"fly-to-locations-grid-button", "../share/resources/gui/fly-to-locations-grid-button.html");
38-
mGuiManager->addTemplate(
39-
"fly-to-locations-list-item", "../share/resources/gui/fly-to-locations-list-item.html");
40-
4136
mGuiManager->executeJavascriptFile("../share/resources/gui/js/csp-fly-to-locations.js");
4237
mGuiManager->addCSS("css/csp-fly-to-locations.css");
4338

@@ -95,11 +90,7 @@ void Plugin::deInit() {
9590
mGuiManager->onBookmarkAdded().disconnect(mOnBookmarkAddedConnection);
9691
mGuiManager->onBookmarkRemoved().disconnect(mOnBookmarkRemovedConnection);
9792

98-
mGuiManager->removeTemplate("fly-to-locations-grid-button");
99-
mGuiManager->removeTemplate("fly-to-locations-list-item");
100-
101-
mGuiManager->getGui()->callJavascript(
102-
"CosmoScout.gui.unregisterCss", "css/csp-fly-to-locations.css");
93+
mGuiManager->removeCSS("css/csp-fly-to-locations.css");
10394

10495
mSolarSystem->pActiveObject.disconnect(mActiveBodyConnection);
10596

plugins/csp-measurement-tools/gui/js/csp-measurement-tools.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
add(name, icon) {
2525
const area = document.getElementById('measurement-tools');
2626

27-
const tool = CosmoScout.gui.loadTemplateContent('measurement-tools');
27+
const tool = CosmoScout.gui.loadTemplateContent('measurement-tool-template');
2828

2929
tool.innerHTML = tool.innerHTML.replace(/%CONTENT%/g, name).replace(/%ICON%/g, icon).trim();
3030

plugins/csp-measurement-tools/gui/measurement-tool-template.html

-17
This file was deleted.

plugins/csp-measurement-tools/gui/measurement-tools-tab.html

+14-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,17 @@
44
-->
55

66
<div id="measurement-tools" class="row">
7-
</div>
7+
</div>
8+
9+
<template id="measurement-tool-template">
10+
<div class="col-4 center measurement-tool">
11+
<label>
12+
<input id="set_tool_%ICON%" type="checkbox" name="measurement-tool" class="radio-button" />
13+
<span class="block btn glass">
14+
<i class="material-icons">%ICON%</i>
15+
<br>
16+
<span>%CONTENT%</span>
17+
</span>
18+
</label>
19+
</div>
20+
</template>

plugins/csp-measurement-tools/src/Plugin.cpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,6 @@ void Plugin::init() {
264264
mOnLoadConnection = mAllSettings->onLoad().connect([this]() { onLoad(); });
265265
mOnSaveConnection = mAllSettings->onSave().connect([this]() { onSave(); });
266266

267-
mGuiManager->addTemplate(
268-
"measurement-tools", "../share/resources/gui/measurement-tool-template.html");
269-
270267
mGuiManager->addPluginTabToSideBarFromHTML(
271268
"Measurement Tools", "multiline_chart", "../share/resources/gui/measurement-tools-tab.html");
272269

@@ -406,9 +403,7 @@ void Plugin::deInit() {
406403
mGuiManager->removePluginTab("Measurement Tools");
407404

408405
mGuiManager->getGui()->unregisterCallback("measurementTools.setNext");
409-
mGuiManager->getGui()->callJavascript("CosmoScout.gui.removeTemplate", "measurement-tools");
410-
mGuiManager->getGui()->callJavascript(
411-
"CosmoScout.gui.unregisterCss", "css/csp-measurement-tools-sidebar.css");
406+
mGuiManager->removeCSS("css/csp-measurement-tools-sidebar.css");
412407

413408
mInputManager->pButtons[0].disconnect(mOnClickConnection);
414409
mInputManager->sOnDoubleClick.disconnect(mOnDoubleClickConnection);

plugins/csp-minimap/gui/js/csp-minimap.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105

106106
init() {
107107
// Add the minimap window.
108-
this._mapDiv = CosmoScout.gui.loadTemplateContent('minimap');
108+
this._mapDiv = CosmoScout.gui.loadTemplateContent('minimap-template');
109109
document.getElementById('cosmoscout').appendChild(this._mapDiv);
110110

111111
// Create the Leaflet map.
@@ -184,6 +184,10 @@
184184
this._resizeObserver.observe(this._mapDiv);
185185
}
186186

187+
deinit() {
188+
document.getElementById('cosmoscout').removeChild(this._mapDiv);
189+
}
190+
187191
// Update minimap based on observer state.
188192
update() {
189193
if (this._mapDiv.classList.contains("visible")) {

plugins/csp-minimap/src/Plugin.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ void Plugin::init() {
102102
mGuiManager->addCSS("third-party/css/leaflet.css");
103103

104104
mGuiManager->addCSS("css/csp-minimap.css");
105-
mGuiManager->addTemplate("minimap", "../share/resources/gui/csp-minimap-template.html");
105+
mGuiManager->addTemplate("minimap-template", "../share/resources/gui/csp-minimap-template.html");
106106
mGuiManager->executeJavascriptFile("../share/resources/gui/js/csp-minimap.js");
107107

108108
// Register a callback to toggle the minimap.
@@ -172,8 +172,10 @@ void Plugin::deInit() {
172172
mGuiManager->onBookmarkAdded().disconnect(mOnBookmarkAddedConnection);
173173
mGuiManager->onBookmarkRemoved().disconnect(mOnBookmarkRemovedConnection);
174174

175-
mGuiManager->removeTemplate("minimap");
175+
mGuiManager->getGui()->callJavascript("CosmoScout.minimap.deinit");
176+
mGuiManager->removeTemplate("minimap-template");
176177
mGuiManager->removeCSS("css/csp-minimap.css");
178+
mGuiManager->removeCSS("third-party/css/leaflet.css");
177179

178180
mGuiManager->removeTimelineButton("Toggle Minimap");
179181
mGuiManager->getGui()->unregisterCallback("minimap.toggle");

plugins/csp-sharad/gui/js/csp-sharad.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222
add(file, time) {
2323
const sharadList = document.getElementById('list-sharad');
24-
const sharad = CosmoScout.gui.loadTemplateContent('sharad');
24+
const sharad = CosmoScout.gui.loadTemplateContent('sharad-template');
2525

2626
sharad.innerHTML = sharad.innerHTML.replace(/%FILE%/g, file).replace(/%TIME%/g, time).trim();
2727

plugins/csp-sharad/gui/sharad-tab.html

+12-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,15 @@
2626
<div id="list-sharad" class="item-list scroll-box-content">
2727
</div>
2828
</div>
29-
</div>
29+
</div>
30+
31+
<template id="sharad-template">
32+
<div class="row">
33+
<div class="col-8">%FILE%</div>
34+
<div class="col-4">
35+
<a class="btn glass block" onclick="CosmoScout.callbacks.time.set(%TIME%)">
36+
<i class="material-icons">restore</i>
37+
</a>
38+
</div>
39+
</div>
40+
</template>

plugins/csp-sharad/gui/sharad-template.html

-15
This file was deleted.

plugins/csp-sharad/src/Plugin.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ void Plugin::init() {
5757
mOnLoadConnection = mAllSettings->onLoad().connect([this]() { onLoad(); });
5858
mOnSaveConnection = mAllSettings->onSave().connect([this]() { onSave(); });
5959

60-
mGuiManager->addTemplate("sharad", "../share/resources/gui/sharad-template.html");
61-
6260
mGuiManager->executeJavascriptFile("../share/resources/gui/js/csp-sharad.js");
6361

6462
mGuiManager->addPluginTabToSideBarFromHTML(
@@ -149,7 +147,6 @@ void Plugin::deInit() {
149147

150148
mSolarSystem->pActiveObject.disconnect(mActiveObjectConnection);
151149
mGuiManager->getGui()->unregisterCallback("sharad.setEnabled");
152-
mGuiManager->getGui()->callJavascript("CosmoScout.gui.removeTemplate", "sharad");
153150

154151
mAllSettings->onLoad().disconnect(mOnLoadConnection);
155152
mAllSettings->onSave().disconnect(mOnSaveConnection);

plugins/csp-wms-overlays/gui/js/csp-wms-overlays.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* @inheritDoc
2020
*/
2121
init() {
22-
this._infoWindow = CosmoScout.gui.loadTemplateContent("wmsOverlays-infoWindow");
22+
this._infoWindow = CosmoScout.gui.loadTemplateContent("wmsOverlays-infoWindow-template");
2323
document.getElementById("cosmoscout").appendChild(this._infoWindow);
2424

2525
this._layerSelect = document.querySelector(`[data-callback="wmsOverlays.setLayer"]`);

plugins/csp-wms-overlays/src/Plugin.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,7 @@ void Plugin::deInit() {
432432
mGuiManager->removePluginTab("WMS Overlays");
433433
mGuiManager->removeSettingsSection("WMS Overlays");
434434

435-
mGuiManager->getGui()->callJavascript(
436-
"CosmoScout.gui.unregisterCss", "css/csp-simple-wms-bodies.css");
435+
mGuiManager->removeCSS("css/csp-wms-overlays.css");
437436

438437
mGuiManager->getGui()->unregisterCallback("wmsOverlays.setEnableTimeInterpolation");
439438
mGuiManager->getGui()->unregisterCallback("wmsOverlays.setEnableAutomaticBoundsUpdate");

resources/gui/js/apis/gui.js

+1-10
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,6 @@ class GuiApi extends IApi {
2424
*/
2525
_templates = new Map();
2626

27-
/**
28-
* Registered html parts
29-
*
30-
* @see {addTemplate}
31-
* @type {Map<string, DocumentFragment>}
32-
* @private
33-
*/
34-
_html = new Map();
35-
3627
/**
3728
* Initialize third party drop downs,
3829
* add input event listener,
@@ -343,7 +334,7 @@ class GuiApi extends IApi {
343334
template = this._templates.get(id);
344335

345336
if (!template) {
346-
template = document.getElementById(id + "-template");
337+
template = document.getElementById(id);
347338

348339
if (template) {
349340
template = template.content;

resources/gui/js/apis/notification.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class NotificationApi extends IApi {
9292
* @private
9393
*/
9494
_makeNotification(title, content, icon = '') {
95-
const notification = CosmoScout.gui.loadTemplateContent('notification');
95+
const notification = CosmoScout.gui.loadTemplateContent('notification-template');
9696

9797
if (notification === false) {
9898
throw new Error(

resources/gui/js/apis/sidebar.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class SidebarApi extends IApi {
4949
* @param content {string}
5050
*/
5151
addPluginTab(tabName, icon, content) {
52-
const tab = CosmoScout.gui.loadTemplateContent('sidebar-plugin-tab');
52+
const tab = CosmoScout.gui.loadTemplateContent('sidebar-plugin-tab-template');
5353
if (tab === false) {
5454
console.warn('"#sidebar-plugin-tab-template" could not be loaded!');
5555
return;
@@ -72,7 +72,7 @@ class SidebarApi extends IApi {
7272
* @param content {string}
7373
*/
7474
addSettingsSection(sectionName, icon, content) {
75-
const tab = CosmoScout.gui.loadTemplateContent('sidebar-settings-section');
75+
const tab = CosmoScout.gui.loadTemplateContent('sidebar-settings-section-template');
7676
if (tab === false) {
7777
console.warn('"#sidebar-settings-section-template" could not be loaded!');
7878
return;

0 commit comments

Comments
 (0)