Repository navigation
Expand file tree
/
Copy pathlive-docs.js
More file actions
236 lines (205 loc) · 9.18 KB
/
Copy pathlive-docs.js
File metadata and controls
236 lines (205 loc) · 9.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
// $(document).foundation();
import { init as redocInit } from 'https://cdn.redoc.ly/redoc/v3.x/bundles/redoc.standalone.js';
const BRANCH_TEMPLATE_STR = "{{ branch }}"
let urlParams = new URLSearchParams(location.search);
let currentBranch = urlParams.get('branch');
class Api {
constructor(name, urlTemplate, defaultBranch) {
this.name = name;
this.urlTemplate = urlTemplate;
this.defaultBranch = defaultBranch;
}
getUrlForCurrentBranch = () => {
return this.urlTemplate.replace(BRANCH_TEMPLATE_STR, currentBranch || this.defaultBranch)
}
}
// list of APIS
var apis = [
{
name: 'Actors',
urlTemplate: 'https://raw.githubusercontent.com/TACC/abaco/dev-v3/docs/specs/openapi_v3.yml',
defaultBranch: "prod",
},
{
name: 'Apps',
urlTemplate: `https://raw.githubusercontent.com/tapis-project/openapi-apps/${BRANCH_TEMPLATE_STR}/AppsAPI.yaml`,
defaultBranch: "prod",
},
{
name: 'Authenticator',
urlTemplate: `https://raw.githubusercontent.com/tapis-project/authenticator/${BRANCH_TEMPLATE_STR}/service/resources/openapi_v3.yml`,
defaultBranch: "prod",
},
{
name: 'Files',
urlTemplate: `https://raw.githubusercontent.com/tapis-project/openapi-files/${BRANCH_TEMPLATE_STR}/FilesAPI.yaml`,
defaultBranch: "prod",
},
{
name: 'GlobusProxy',
urlTemplate: `https://raw.githubusercontent.com/tapis-project/globus-proxy/${BRANCH_TEMPLATE_STR}/service/resources/openapi_v3.yml`,
defaultBranch: "prod",
},
{
name: 'Jobs',
urlTemplate: `https://raw.githubusercontent.com/tapis-project/openapi-jobs/${BRANCH_TEMPLATE_STR}/JobsAPI.yaml`,
defaultBranch: "prod",
},
{
name: 'Meta',
urlTemplate: `https://raw.githubusercontent.com/tapis-project/tapis-client-java/${BRANCH_TEMPLATE_STR}/meta-client/src/main/resources/metav3-openapi.yaml`,
defaultBranch: "prod",
},
{
name: "Notifications",
urlTemplate: `https://raw.githubusercontent.com/tapis-project/openapi-notifications/${BRANCH_TEMPLATE_STR}/NotificationsAPI.yaml`,
defaultBranch: "prod",
},
{
name: 'PgREST',
urlTemplate: `https://raw.githubusercontent.com/TACC/paas/${BRANCH_TEMPLATE_STR}/pgrest/resources/openapi_v3.yml`,
defaultBranch: "prod",
},
{
name: 'Pods',
urlTemplate: `https://raw.githubusercontent.com/tapis-project/pods_service/${BRANCH_TEMPLATE_STR}/docs/openapi_v3-pods.yml`,
defaultBranch: "prod",
},
{
name: 'SK',
urlTemplate: `https://raw.githubusercontent.com/tapis-project/openapi-security/${BRANCH_TEMPLATE_STR}/SkAPI.yaml`,
defaultBranch: "prod",
},
{
name: 'Streams',
urlTemplate: `https://raw.githubusercontent.com/tapis-project/streams-api/${BRANCH_TEMPLATE_STR}/service/resources/openapi_v3.yml`,
defaultBranch: "prod",
},
{
name: 'Systems',
urlTemplate: `https://raw.githubusercontent.com/tapis-project/openapi-systems/${BRANCH_TEMPLATE_STR}/SystemsAPI.yaml`,
defaultBranch: "prod",
},
{
name: 'Tenants',
urlTemplate: `https://raw.githubusercontent.com/tapis-project/tenants-api/${BRANCH_TEMPLATE_STR}/service/resources/openapi_v3.yml`,
defaultBranch: "prod",
},
{
name: 'Tokens',
urlTemplate: `https://raw.githubusercontent.com/tapis-project/tokens-api/${BRANCH_TEMPLATE_STR}/service/resources/openapi_v3.yml`,
defaultBranch: "prod",
},
{
name: 'Workflows',
urlTemplate: `https://raw.githubusercontent.com/tapis-project/tapis-workflows/${BRANCH_TEMPLATE_STR}/src/api/specs/WorkflowsAPI.yaml`,
defaultBranch: "prod",
},
{
name: 'MLHub Models',
urlTemplate: `https://raw.githubusercontent.com/tapis-project/ml-hub-rust/refs/heads/${BRANCH_TEMPLATE_STR}/specs/models/openapi.json`,
defaultBranch: "main",
},
{
name: 'MLHub Deployments',
urlTemplate: `https://raw.githubusercontent.com/tapis-project/ml-hub-rust/refs/heads/${BRANCH_TEMPLATE_STR}/services/deployments/spec/v1/openapi.json`,
defaultBranch: "main"
},
].map((api) => new Api(api.name, api.urlTemplate, api.defaultBranch));
function init() {
let service = urlParams.get("service");
if (!!service) {
apis.forEach((api) => {
if (api.name.toLowerCase() == service.toLowerCase()) {
console.log(`${api.getUrlForCurrentBranch()}`)
redocInit(api.getUrlForCurrentBranch());
}
});
return
}
// initially render first API
redocInit(apis[0].getUrlForCurrentBranch());
}
$(document).ready(function ($) {
function onClick() {
var url = this.getAttribute('data-link');
let serviceName = this.getAttribute('service');
redocInit(url);
var queryParams = new URLSearchParams(window.location.search);
queryParams.set("service", serviceName);
let hashFragment = window.location.hash;
// Consolidated history management
updateHistory(queryParams, hashFragment);
}
function updateHistory(queryParams, hashFragment) {
// Construct the new state
let newState = "?" + queryParams.toString() + hashFragment;
// Push the new state to history
history.pushState(null, null, newState);
//console.log("Updated history state:", newState);
//console.log("Current history state:", history.state);
}
// dynamically building navigation items
var $list = document.getElementById('links_container');
apis.forEach(function (api) {
var $listitem = document.createElement('li');
$listitem.setAttribute('data-link', api.getUrlForCurrentBranch());
$listitem.setAttribute('service', api.name);
$listitem.innerText = api.name;
$listitem.addEventListener('click', onClick);
$list.appendChild($listitem);
});
var queryParams = new URLSearchParams(window.location.search);
init(queryParams);
$(window).on('popstate', function () {
// Get parameters before the popstate event
var beforeService = window.location.search;
var beforeHash = window.location.hash;
// Get current parameters after the popstate event
var afterService = this.location.search;
var afterHash = this.location.hash;
//console.log("Service at popstate:", beforeService, " --> ", afterService);
//console.log("Hash at popstate:", beforeHash, " --> ", afterHash);
if (beforeService !== afterService || beforeHash !== afterHash) {
// This history logic helps a bit, but not great.
redocInit(afterService + afterHash); // Initialize with the new query parameters and hash
}
});
})
// This block is an attempt at getting back and forward buttons working between different api pages
// each redoc page manages state. Moving between them causes issues with the code below, but might
// be useful for future debugging of the issue.
// History is deprioritized currently to get rid of error messages to user.
// $(window).on('popstate', function(event) {
// console.log("state change detected");
// var url = this.location.search + this.location.hash; // Include hash fragment
// console.log("url: " + url);
// var queryParams = new URLSearchParams(this.location.search);
// console.log("Query parameters after back button:", Object.fromEntries(queryParams.entries()));
// let serviceName = queryParams.get("service");
// console.log("serviceName: " + serviceName);
// const matchingApi = apis.find(d => d.name.toLowerCase() === serviceName?.toLowerCase());
// // Only initialize Redoc if a matching API is found and it's different from current one
// if (matchingApi) {
// // Get the currently displayed API name (from document or a global variable)
// const currentApiName = document.querySelector('#links_container li.active')?.getAttribute('service');
// //const currentApiName = this.location.search("service");
// // Only reinitialize if the API is changing
// if (!currentApiName || currentApiName.toLowerCase() !== matchingApi.name.toLowerCase()) {
// console.log("Changing to service: " + matchingApi.name + " from " + currentApiName);
// Redoc.init(matchingApi.url + this.location.hash); // Pass hash fragment to Redoc
// // Update active state in navigation
// const listItems = document.querySelectorAll('#links_container li');
// listItems.forEach(item => {
// item.classList.remove('active');
// if (item.getAttribute('service').toLowerCase() === matchingApi.name.toLowerCase()) {
// item.classList.add('active');
// }
// });
// } else {
// console.log("Same service requested, no need to reinitialize");
// }
// } else {
// console.log("Service not found: " + serviceName);
// }
//});