import { formatUptime, deployEngineActiveRows, deployEngineQueuedRows, deployEngineRecentRows } from "../format.js";
document.addEventListener("alpine:init", () => {
Alpine.data("deployEngine", () => ({
get store() {
return Alpine.store("app");
},
tab: "fila",
dragId: null,
overId: null,
dragStart(dragEvent, deploymentId) {
this.dragId = deploymentId;
dragEvent.dataTransfer.effectAllowed = "move";
dragEvent.dataTransfer.setData("text/plain", deploymentId);
},
dragEnd() {
this.dragId = null;
this.overId = null;
},
async dropOn(targetId) {
const from = this.dragId;
this.dragEnd();
if (!from || from === targetId) return;
const order = this.queued.map((queuedItem) => queuedItem.deploymentId).filter((candidateId) => candidateId !== from);
order.splice(order.indexOf(targetId), 0, from);
await this.store.queueReorder(order);
},
get engine() {
return this.store.snap?.engine || null;
},
get active() {
return deployEngineActiveRows(this.engine?.active);
},
detailId: null,
get detail() {
return this.detailId ? this.active.find((activeDeployment) => activeDeployment.serviceId === this.detailId) || null : null;
},
openDetail(deploymentId) {
this.detailId = deploymentId;
},
closeDetail() {
this.detailId = null;
},
get queued() {
return deployEngineQueuedRows(this.engine?.queued);
},
get recent() {
return deployEngineRecentRows(this.engine?.recent);
},
get paused() {
return !!this.engine?.paused;
},
get uptime() {
return this.engine ? formatUptime(this.engine.uptime_secs) : "…";
},
get successCount() {
return this.engine?.successful_24h ?? 0;
},
get failedCount() {
return this.engine?.failed_24h ?? 0;
},
get totalCount() {
return this.engine?.total_24h ?? 0;
},
}));
});