Toutes les app sur les cotés
This commit is contained in:
1 parent
455988e49c
commit
93dcf514d2
5 files changed
+262
-132
No files matched your search
+143
-14
@@ -1,6 +1,8 @@
|
||||
let state = null;
|
||||
let dirty = false;
|
||||
let dragSource = null; // { appId } or { groupId } currently being dragged
|
||||
let dragSource = null; // { appId }, { groupId } or { catalogApp } currently being dragged
|
||||
let catalog = []; // apps YunoHost pas encore dans le portail (voir /__catalog)
|
||||
let catalogError = null;
|
||||
|
||||
const PALETTE = [
|
||||
"#1db9c3", "#ff5a1f", "#2094f3", "#ffc230", "#00a651", "#e6721a",
|
||||
@@ -147,7 +149,7 @@ function renderAddTile(onAdd) {
|
||||
|
||||
function attachGridDropzone(gridEl, targetListGetter) {
|
||||
gridEl.addEventListener("dragover", (e) => {
|
||||
if (!dragSource || !dragSource.appId) return;
|
||||
if (!dragSource || (!dragSource.appId && !dragSource.catalogApp)) return;
|
||||
e.preventDefault();
|
||||
gridEl.classList.add("drag-over");
|
||||
});
|
||||
@@ -157,19 +159,112 @@ function attachGridDropzone(gridEl, targetListGetter) {
|
||||
gridEl.addEventListener("drop", (e) => {
|
||||
e.preventDefault();
|
||||
gridEl.classList.remove("drag-over");
|
||||
if (!dragSource || !dragSource.appId) return;
|
||||
const appId = dragSource.appId;
|
||||
const loc = findAppLocation(appId);
|
||||
if (!loc) return;
|
||||
const [app] = loc.list.splice(loc.index, 1);
|
||||
if (!dragSource) return;
|
||||
const targetList = targetListGetter();
|
||||
const dropIndex = computeDropIndexGrid(gridEl, e.clientX, e.clientY);
|
||||
targetList.splice(Math.min(dropIndex, targetList.length), 0, app);
|
||||
markDirty();
|
||||
render();
|
||||
|
||||
if (dragSource.catalogApp) {
|
||||
const app = { ...dragSource.catalogApp };
|
||||
targetList.splice(Math.min(dropIndex, targetList.length), 0, app);
|
||||
catalog = catalog.filter((a) => a.id !== app.id);
|
||||
markDirty();
|
||||
render();
|
||||
return;
|
||||
}
|
||||
|
||||
if (dragSource.appId) {
|
||||
const loc = findAppLocation(dragSource.appId);
|
||||
if (!loc) return;
|
||||
const [app] = loc.list.splice(loc.index, 1);
|
||||
targetList.splice(Math.min(dropIndex, targetList.length), 0, app);
|
||||
markDirty();
|
||||
render();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function addCatalogAppTo(app, targetList) {
|
||||
targetList.push({ ...app });
|
||||
catalog = catalog.filter((a) => a.id !== app.id);
|
||||
markDirty();
|
||||
render();
|
||||
}
|
||||
|
||||
function renderCatalogTile(app) {
|
||||
const tile = document.createElement("div");
|
||||
tile.className = "app-tile catalog-tile";
|
||||
tile.draggable = true;
|
||||
tile.title = "Glisser dans le portail, ou cliquer pour ajouter dans \"Sans groupe\"";
|
||||
|
||||
tile.addEventListener("dragstart", (e) => {
|
||||
e.stopPropagation();
|
||||
dragSource = { catalogApp: app };
|
||||
e.dataTransfer.effectAllowed = "copy";
|
||||
e.dataTransfer.setData("text/plain", app.id);
|
||||
tile.classList.add("dragging");
|
||||
});
|
||||
tile.addEventListener("dragend", (e) => {
|
||||
e.stopPropagation();
|
||||
tile.classList.remove("dragging");
|
||||
dragSource = null;
|
||||
});
|
||||
tile.addEventListener("click", () => {
|
||||
state.ungrouped = state.ungrouped || [];
|
||||
addCatalogAppTo(app, state.ungrouped);
|
||||
});
|
||||
|
||||
const icon = document.createElement("div");
|
||||
icon.className = "tile-icon";
|
||||
if (app.icon) {
|
||||
const img = document.createElement("img");
|
||||
img.src = app.icon;
|
||||
img.alt = "";
|
||||
icon.appendChild(img);
|
||||
} else {
|
||||
icon.style.background = app.color || "#8e8e8e";
|
||||
icon.textContent = app.initials || initialsOf(app.name);
|
||||
}
|
||||
|
||||
const name = document.createElement("div");
|
||||
name.className = "tile-name";
|
||||
name.textContent = app.name;
|
||||
|
||||
tile.appendChild(icon);
|
||||
tile.appendChild(name);
|
||||
return tile;
|
||||
}
|
||||
|
||||
function renderCatalogColumn(title, apps) {
|
||||
const column = document.createElement("aside");
|
||||
column.className = "catalog-column";
|
||||
|
||||
const heading = document.createElement("h2");
|
||||
heading.textContent = title;
|
||||
column.appendChild(heading);
|
||||
|
||||
if (catalogError) {
|
||||
const msg = document.createElement("p");
|
||||
msg.className = "catalog-message catalog-error";
|
||||
msg.textContent = catalogError;
|
||||
column.appendChild(msg);
|
||||
return column;
|
||||
}
|
||||
|
||||
if (apps.length === 0) {
|
||||
const msg = document.createElement("p");
|
||||
msg.className = "catalog-message";
|
||||
msg.textContent = "Aucune app à ajouter.";
|
||||
column.appendChild(msg);
|
||||
return column;
|
||||
}
|
||||
|
||||
const list = document.createElement("div");
|
||||
list.className = "catalog-list";
|
||||
apps.forEach((app) => list.appendChild(renderCatalogTile(app)));
|
||||
column.appendChild(list);
|
||||
return column;
|
||||
}
|
||||
|
||||
function openAppForm(onSubmit) {
|
||||
const backdrop = document.createElement("div");
|
||||
backdrop.className = "app-form-backdrop";
|
||||
@@ -326,6 +421,21 @@ function render() {
|
||||
const root = document.getElementById("editor-root");
|
||||
root.innerHTML = "";
|
||||
|
||||
const layout = document.createElement("div");
|
||||
layout.className = "editor-layout";
|
||||
|
||||
const half = Math.ceil(catalog.length / 2);
|
||||
const leftCatalog = renderCatalogColumn("Catalogue YunoHost", catalog.slice(0, half));
|
||||
const rightCatalog = renderCatalogColumn("Catalogue YunoHost", catalog.slice(half));
|
||||
|
||||
const center = document.createElement("div");
|
||||
center.className = "editor-center";
|
||||
|
||||
layout.appendChild(leftCatalog);
|
||||
layout.appendChild(center);
|
||||
layout.appendChild(rightCatalog);
|
||||
root.appendChild(layout);
|
||||
|
||||
const pinnedSection = document.createElement("section");
|
||||
pinnedSection.className = "pinned-section";
|
||||
const pinnedHeading = document.createElement("h2");
|
||||
@@ -345,13 +455,13 @@ function render() {
|
||||
}));
|
||||
attachGridDropzone(pinnedGrid, () => (state.pinned = state.pinned || []));
|
||||
pinnedSection.appendChild(pinnedGrid);
|
||||
root.appendChild(pinnedSection);
|
||||
center.appendChild(pinnedSection);
|
||||
|
||||
const groupsList = document.createElement("div");
|
||||
groupsList.id = "groups-list";
|
||||
state.groups.forEach((group, i) => groupsList.appendChild(renderGroup(group, i)));
|
||||
attachGroupsDropzone(groupsList);
|
||||
root.appendChild(groupsList);
|
||||
center.appendChild(groupsList);
|
||||
|
||||
const addGroupBtn = document.createElement("button");
|
||||
addGroupBtn.className = "add-group-btn";
|
||||
@@ -362,7 +472,7 @@ function render() {
|
||||
markDirty();
|
||||
render();
|
||||
});
|
||||
root.appendChild(addGroupBtn);
|
||||
center.appendChild(addGroupBtn);
|
||||
|
||||
const ungroupedSection = document.createElement("section");
|
||||
ungroupedSection.className = "ungrouped-section";
|
||||
@@ -383,12 +493,31 @@ function render() {
|
||||
attachGridDropzone(ungroupedGrid, () => state.ungrouped);
|
||||
ungroupedSection.appendChild(ungroupedGrid);
|
||||
|
||||
root.appendChild(ungroupedSection);
|
||||
center.appendChild(ungroupedSection);
|
||||
}
|
||||
|
||||
async function loadCatalog() {
|
||||
try {
|
||||
const res = await fetch("/__catalog", { cache: "no-store" });
|
||||
const data = await res.json();
|
||||
if (data.error) {
|
||||
catalog = [];
|
||||
catalogError = data.error;
|
||||
} else {
|
||||
catalog = data.apps || [];
|
||||
catalogError = null;
|
||||
}
|
||||
} catch (err) {
|
||||
catalog = [];
|
||||
catalogError = "Catalogue indisponible (aperçu local requis).";
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
async function load() {
|
||||
const res = await fetch("config.json", { cache: "no-store" });
|
||||
state = await res.json();
|
||||
await loadCatalog();
|
||||
render();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user