Skip to content

Commit 23305c4

Browse files
committed
feat: introduce switchVersion option in view manager
Allows to reload the view with a version of the visualizer matching the view.
1 parent 6ce4b43 commit 23305c4

File tree

4 files changed

+60
-20
lines changed

4 files changed

+60
-20
lines changed

src/index-lactame.html

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>Visualizer</title>
6+
<script type="module">
7+
const visualizer = document.getElementById('ci-visualizer');
8+
const {searchParams, origin } = new URL(window.location.href);
9+
const viewURL = searchParams.get('viewURL');
10+
let version = searchParams.get('v') || 'latest';
11+
12+
const script = document.createElement("script");
13+
script.src = `https://www.lactame.com/visualizer/${version}/components/requirejs/require.js`;
14+
script.dataset.main = `https://www.lactame.com/visualizer/${version}/init.js`;
15+
16+
document.head.appendChild(script);
17+
</script>
18+
19+
<style>
20+
#ci-visualizer {
21+
min-height: 100vh;
22+
}
23+
body {
24+
margin: 0;
25+
}
26+
</style>
27+
</head>
28+
<body>
29+
<div id="ci-visualizer" data-ci-config="./usr/config/default.json"></div>
30+
</body>
31+
</html>

src/src/header/components/roc-views.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,10 +1124,28 @@ define([
11241124

11251125
loadNode(node) {
11261126
this.setLoadedNode(node);
1127-
var view = node.data.view;
1128-
Versioning.switchView(view.getViewSwitcher(), true, {
1129-
withCredentials: true,
1130-
});
1127+
const nodeView = node.data.view;
1128+
1129+
if (this.options.switchVersion) {
1130+
// When `switchVersion` is on, reload the page with the matching version of the visualizer
1131+
// This option is supported since v3.1.0
1132+
// It only works if the reloaded page supports the `v` query parameter. See `src/index-lactam.html`.
1133+
// ⚠️ After the switch of view, you might have loaded a version which does not support this.
1134+
const { view, data } = nodeView.getViewSwitcher();
1135+
const url = new URL(window.location.href);
1136+
url.searchParams.set('viewURL', view.url);
1137+
if (data.url) {
1138+
url.searchParams.set('dataURL', data.url);
1139+
}
1140+
if (node.data.view.view.$content.version) {
1141+
url.searchParams.set('v', `v${node.data.view.view.$content.version}`);
1142+
}
1143+
window.location.href = url.toString();
1144+
} else {
1145+
Versioning.switchView(nodeView.getViewSwitcher(), true, {
1146+
withCredentials: true,
1147+
});
1148+
}
11311149
}
11321150

11331151
getTree(views) {

src/usr/config/default.json

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,27 +83,18 @@
8383
"label": "Blank view"
8484
},
8585
{
86-
"type": "pouchloadview",
87-
"label": "Load local view"
88-
},
89-
{
90-
"type": "pouchsaveview",
91-
"label": "Save local view"
92-
},
93-
{
94-
"type": "pouchloaddata",
95-
"label": "Load local data"
96-
},
97-
{
98-
"type": "pouchsavedata",
99-
"label": "Save local data"
86+
"type": "versionselector",
87+
"label": "Switch version",
88+
"url": "https://www.lactame.com/visualizer/versions.json",
89+
"minVersion": "2.170.0"
10090
},
10191
{
10292
"type": "roc-views",
10393
"label": "View manager",
10494
"database": "visualizer",
10595
"url": "http://localhost:3000",
106-
"hidePublicToggle": false
96+
"hidePublicToggle": false,
97+
"switchVersion": true
10798
}
10899
]
109100
}

testcase/config/multiview.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@
3131
}
3232
]
3333
}
34-
}
34+
}

0 commit comments

Comments
 (0)