|
@@ -105,6 +105,10 @@ async function createCard (details) {
|
|
state_color = 'orange';
|
|
state_color = 'orange';
|
|
trigger = 'data-hx-trigger="load"';
|
|
trigger = 'data-hx-trigger="load"';
|
|
break;
|
|
break;
|
|
|
|
+ case 'installing':
|
|
|
|
+ state_color = 'blue';
|
|
|
|
+ trigger = 'data-hx-trigger="load"';
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
// if (name.startsWith('dweebui')) { disable = 'disabled=""'; }
|
|
// if (name.startsWith('dweebui')) { disable = 'disabled=""'; }
|
|
let card = readFileSync('./views/partials/containerCard.html', 'utf8');
|
|
let card = readFileSync('./views/partials/containerCard.html', 'utf8');
|
|
@@ -124,6 +128,30 @@ let [ cardList, newCards, containersArray, sentArray, updatesArray ] = [ '', '',
|
|
let hidden = await Container.findAll({ where: {visibility:false}});
|
|
let hidden = await Container.findAll({ where: {visibility:false}});
|
|
hidden = hidden.map((container) => container.name);
|
|
hidden = hidden.map((container) => container.name);
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+export async function addCard (name, state) {
|
|
|
|
+ console.log(`Adding card for ${name}: ${state}`);
|
|
|
|
+
|
|
|
|
+ let details = {
|
|
|
|
+ name: name,
|
|
|
|
+ image: name,
|
|
|
|
+ service: name,
|
|
|
|
+ state: 'installing',
|
|
|
|
+ external_port: 0,
|
|
|
|
+ internal_port: 0,
|
|
|
|
+ ports: [],
|
|
|
|
+ link: 'localhost',
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ createCard(details).then(card => {
|
|
|
|
+ cardList += card;
|
|
|
|
+ });
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
// HTMX server-side events
|
|
// HTMX server-side events
|
|
export const SSE = (req, res) => {
|
|
export const SSE = (req, res) => {
|
|
res.writeHead(200, { 'Content-Type': 'text/event-stream', 'Cache-Control': 'no-cache', 'Connection': 'keep-alive' });
|
|
res.writeHead(200, { 'Content-Type': 'text/event-stream', 'Cache-Control': 'no-cache', 'Connection': 'keep-alive' });
|
|
@@ -180,7 +208,7 @@ export const SSE = (req, res) => {
|
|
sentArray = containersArray.slice();
|
|
sentArray = containersArray.slice();
|
|
}
|
|
}
|
|
|
|
|
|
- }, 1000);
|
|
|
|
|
|
+ }, 500);
|
|
|
|
|
|
|
|
|
|
req.on('close', () => {
|
|
req.on('close', () => {
|
|
@@ -211,14 +239,6 @@ export const Chart = async (req, res) => {
|
|
res.send(chart);
|
|
res.send(chart);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-export const Installs = async (req, res) => {
|
|
|
|
- let name = req.header('hx-trigger-name');
|
|
|
|
- let all_containers = '';
|
|
|
|
- res.send('ok');
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
export const updateCards = async (req, res) => {
|
|
export const updateCards = async (req, res) => {
|
|
console.log('updateCards called');
|
|
console.log('updateCards called');
|
|
res.send(newCards);
|
|
res.send(newCards);
|
|
@@ -232,13 +252,21 @@ export const Containers = async (req, res) => {
|
|
|
|
|
|
export const Card = async (req, res) => {
|
|
export const Card = async (req, res) => {
|
|
let name = req.header('hx-trigger-name');
|
|
let name = req.header('hx-trigger-name');
|
|
- console.log(`Updated card for ${name}`);
|
|
|
|
- let details = await containerInfo(name);
|
|
|
|
- let card = await createCard(details);
|
|
|
|
- res.send(card);
|
|
|
|
|
|
+ console.log(`${name} requesting updated card`);
|
|
|
|
+ // return nothing if in hidden or not found in containersArray
|
|
|
|
+ if (hidden.includes(name) || !containersArray.find(c => c.container === name)) {
|
|
|
|
+ res.send('');
|
|
|
|
+ return;
|
|
|
|
+ } else {
|
|
|
|
+ let details = await containerInfo(name);
|
|
|
|
+ let card = await createCard(details);
|
|
|
|
+ res.send(card);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
function status (state) {
|
|
function status (state) {
|
|
let status = `<span class="text-yellow align-items-center lh-1">
|
|
let status = `<span class="text-yellow align-items-center lh-1">
|
|
<svg xmlns="http://www.w3.org/2000/svg" class="icon-tabler icon-tabler-point-filled" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"> <path stroke="none" d="M0 0h24v24H0z" fill="none"></path> <path d="M12 7a5 5 0 1 1 -4.995 5.217l-.005 -.217l.005 -.217a5 5 0 0 1 4.995 -4.783z" stroke-width="0" fill="currentColor"></path></svg>
|
|
<svg xmlns="http://www.w3.org/2000/svg" class="icon-tabler icon-tabler-point-filled" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"> <path stroke="none" d="M0 0h24v24H0z" fill="none"></path> <path d="M12 7a5 5 0 1 1 -4.995 5.217l-.005 -.217l.005 -.217a5 5 0 0 1 4.995 -4.783z" stroke-width="0" fill="currentColor"></path></svg>
|
|
@@ -322,6 +350,10 @@ export const Action = async (req, res) => {
|
|
} else if ((action == 'pause') && (state == 'paused')) {
|
|
} else if ((action == 'pause') && (state == 'paused')) {
|
|
var containerName = docker.getContainer(name);
|
|
var containerName = docker.getContainer(name);
|
|
containerName.unpause();
|
|
containerName.unpause();
|
|
|
|
+ res.send(status('starting'));
|
|
|
|
+ } else if ((action == 'pause') && (state == 'running')) {
|
|
|
|
+ var containerName = docker.getContainer(name);
|
|
|
|
+ containerName.pause();
|
|
res.send(status('pausing'));
|
|
res.send(status('pausing'));
|
|
// Restart
|
|
// Restart
|
|
} else if (action == 'restart') {
|
|
} else if (action == 'restart') {
|