mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-07 15:25:01 +01:00
WebSockets: update index page to use JS client lib, cleanup code
This commit is contained in:
parent
01e25a3199
commit
40a03e4cf5
2 changed files with 25 additions and 41 deletions
|
|
@ -32,7 +32,6 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script src="shared/ardour.js"></script>
|
<script type="module" src="index/main.js"></script>
|
||||||
<script src="index/main.js"></script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
|
|
@ -16,48 +16,45 @@
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { Ardour } from '../shared/ardour.js';
|
||||||
|
|
||||||
(() => {
|
(() => {
|
||||||
|
|
||||||
const INDEX_RESOURCE = 'index.json';
|
async function main () {
|
||||||
|
try {
|
||||||
async function fetchIndex (url) {
|
const index = await new Ardour().getAvailableSurfaces();
|
||||||
const response = await fetch(url);
|
printIndex(index);
|
||||||
|
} catch (err) {
|
||||||
if (response.status == 200) {
|
printError(`Error loading index: ${err.message}`);
|
||||||
return await response.json();
|
|
||||||
} else {
|
|
||||||
throw new Error(`HTTP response status ${response.status}`);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function buildItem (groupPath, surface) {
|
document.getElementById('loading').style.display = 'none';
|
||||||
const li = document.createElement('li');
|
|
||||||
li.innerHTML = `<li>
|
|
||||||
<a href="${groupPath}/${surface.path}/">${surface.name}</a>
|
|
||||||
<p>${surface.description}</p>
|
|
||||||
</li>`;
|
|
||||||
return li;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function printIndex (index) {
|
function printIndex (index) {
|
||||||
for (let group of index) {
|
for (const group of index) {
|
||||||
const path = group['path'];
|
const surfaces = group.surfaces;
|
||||||
const span = document.querySelector(`#${path} span`);
|
const groupPath = group['path'];
|
||||||
span.innerHTML = group['diskPath'];
|
const groupPathSpan = document.querySelector(`#${groupPath} span`);
|
||||||
|
|
||||||
let surfaces = group.surfaces;
|
groupPathSpan.innerHTML = group['diskPath'];
|
||||||
|
|
||||||
if (surfaces.length > 0) {
|
if (surfaces.length > 0) {
|
||||||
const ul = document.querySelector(`#${path} > ul`);
|
const ul = document.querySelector(`#${groupPath} > ul`);
|
||||||
surfaces.sort((a, b) => a.name.localeCompare(b.name));
|
surfaces.sort((a, b) => a.name.localeCompare(b.name));
|
||||||
|
|
||||||
for (surface of surfaces) {
|
for (const surface of surfaces) {
|
||||||
ul.appendChild(buildItem(path, surface));
|
const li = document.createElement('li');
|
||||||
|
li.innerHTML = `<li>
|
||||||
|
<a href="${groupPath}/${surface.path}/">${surface.name}</a>
|
||||||
|
<p>${surface.description}</p>
|
||||||
|
</li>`;
|
||||||
|
ul.appendChild(li);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const p = document.createElement('p');
|
const p = document.createElement('p');
|
||||||
p.innerHTML = '<p>No surfaces found</p>';
|
p.innerHTML = '<p>No surfaces found</p>';
|
||||||
document.getElementById(path).appendChild(p);
|
document.getElementById(groupPath).appendChild(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -70,18 +67,6 @@
|
||||||
error.style.display = 'inline';
|
error.style.display = 'inline';
|
||||||
}
|
}
|
||||||
|
|
||||||
async function main () {
|
|
||||||
try {
|
|
||||||
const indexUrl = `${location.protocol}//${location.host}/${INDEX_RESOURCE}`;
|
|
||||||
const index = await fetchIndex (indexUrl);
|
|
||||||
printIndex(index);
|
|
||||||
} catch (err) {
|
|
||||||
printError(`Error loading ${INDEX_RESOURCE}: ${err.message}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
document.getElementById('loading').style.display = 'none';
|
|
||||||
}
|
|
||||||
|
|
||||||
main();
|
main();
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue