1
0
Fork 0
mirror of https://github.com/pawelmalak/flame.git synced 2025-08-02 17:35:17 +02:00

automatically create new category when category in integrations is not found (#11)

automatically create new category when category in docker or kubernetes labels is not found
This commit is contained in:
François Darveau 2021-09-19 11:18:49 -04:00 committed by François Darveau
parent 4280511372
commit 349d63c3e3
4 changed files with 52 additions and 31 deletions

View file

@ -217,6 +217,12 @@ async function retrieveDockerApps(apps, orderType, unpinStoppedApps) {
for (let i = 0; i < names.length; i++) {
const category = categoriesLabels[i] ? categories.find(category => category.name.toUpperCase() === categoriesLabels[i].toUpperCase()) : dockerDefaultCategory;
if (!category) {
category = await createNewCategory(categoriesLabels[i]);
if (category) {
categories.push(category);
}
}
dockerApps.push({
name: names[i] || names[0],
@ -250,6 +256,15 @@ async function retrieveDockerApps(apps, orderType, unpinStoppedApps) {
return apps;
}
async function createNewCategory(newCategoryName) {
return await Category.create({
name: newCategoryName,
type: 'apps',
isPinned: true,
orderId: Number.MAX_SAFE_INTEGER //New category will always be last and can then be re-ordered manually by user
});
}
async function retrieveKubernetesApps(apps, orderType, unpinStoppedApps) {
let ingresses = null;
@ -295,6 +310,12 @@ async function retrieveKubernetesApps(apps, orderType, unpinStoppedApps) {
for (let i = 0; i < names.length; i++) {
const category = categoriesLabels[i] ? categories.find(category => category.name.toUpperCase() === categoriesLabels[i].toUpperCase()) : kubernetesDefaultCategory;
if (!category) {
category = await createNewCategory(categoriesLabels[i]);
if (category) {
categories.push(category);
}
}
kubernetesApps.push({
name: names[i] || names[0],