mirror of
https://github.com/pawelmalak/flame.git
synced 2025-07-22 04:49:36 +02:00
Support for app categories in docker integration (#8)
* initial support for app categories in docker integration * fixed readme examples for docker integration and some fixes to integration * fix obtaining category from container label * hide edit actions for default categories (such as Docker)
This commit is contained in:
parent
14fbc7e221
commit
ccdb477ac4
8 changed files with 53 additions and 12 deletions
|
@ -159,6 +159,7 @@ labels:
|
||||||
- flame.type=application # "app" works too
|
- flame.type=application # "app" works too
|
||||||
- flame.name=My container
|
- flame.name=My container
|
||||||
- flame.url=https://example.com
|
- flame.url=https://example.com
|
||||||
|
- flame.category=My category # Optional, default is "Docker"
|
||||||
- flame.icon=icon-name # Optional, default is "docker"
|
- flame.icon=icon-name # Optional, default is "docker"
|
||||||
# - flame.icon=custom to make changes in app. ie: custom icon upload
|
# - flame.icon=custom to make changes in app. ie: custom icon upload
|
||||||
```
|
```
|
||||||
|
|
|
@ -98,7 +98,7 @@ const AppForm = (props: ComponentProps): JSX.Element => {
|
||||||
if (appData.categoryId === -1) {
|
if (appData.categoryId === -1) {
|
||||||
props.createNotification({
|
props.createNotification({
|
||||||
title: 'Error',
|
title: 'Error',
|
||||||
message: 'Please select category'
|
message: 'Please select a category'
|
||||||
})
|
})
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,7 +162,7 @@ const AppTable = (props: ComponentProps): JSX.Element => {
|
||||||
style={style}
|
style={style}
|
||||||
>
|
>
|
||||||
<td>{category.name}</td>
|
<td>{category.name}</td>
|
||||||
{!snapshot.isDragging && (
|
{!snapshot.isDragging && category.id >= 0 && (
|
||||||
<td className={classes.TableActions}>
|
<td className={classes.TableActions}>
|
||||||
<div
|
<div
|
||||||
className={classes.TableAction}
|
className={classes.TableAction}
|
||||||
|
|
|
@ -94,7 +94,7 @@ const Apps = (props: ComponentProps): JSX.Element => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const instanceOfCategory = (object: any): object is Category => {
|
const instanceOfCategory = (object: any): object is Category => {
|
||||||
return "apps" in object;
|
return !("categoryId" in object);
|
||||||
};
|
};
|
||||||
|
|
||||||
const goToUpdateMode = (data: Category | App): void => {
|
const goToUpdateMode = (data: Category | App): void => {
|
||||||
|
|
|
@ -152,7 +152,7 @@ const Home = (props: ComponentProps): JSX.Element => {
|
||||||
<AppGrid
|
<AppGrid
|
||||||
categories={
|
categories={
|
||||||
!localSearch
|
!localSearch
|
||||||
? appCategories.filter((category: Category) => category.isPinned)
|
? appCategories.filter((category: Category) => category.isPinned && category.apps.length > 0)
|
||||||
: searchInCategories(localSearch, appCategories)
|
: searchInCategories(localSearch, appCategories)
|
||||||
}
|
}
|
||||||
apps={
|
apps={
|
||||||
|
@ -181,7 +181,7 @@ const Home = (props: ComponentProps): JSX.Element => {
|
||||||
<BookmarkGrid
|
<BookmarkGrid
|
||||||
categories={
|
categories={
|
||||||
!localSearch
|
!localSearch
|
||||||
? bookmarkCategories.filter((category: Category) => category.isPinned)
|
? bookmarkCategories.filter((category: Category) => category.isPinned && category.bookmarks.length > 0)
|
||||||
: searchInCategories(localSearch, bookmarkCategories)
|
: searchInCategories(localSearch, bookmarkCategories)
|
||||||
}
|
}
|
||||||
bookmarks={
|
bookmarks={
|
||||||
|
|
|
@ -5,6 +5,8 @@ const Config = require('../models/Config');
|
||||||
const { Sequelize } = require('sequelize');
|
const { Sequelize } = require('sequelize');
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
const Logger = require('../utils/Logger');
|
const Logger = require('../utils/Logger');
|
||||||
|
const Category = require('../models/Category');
|
||||||
|
const { dockerDefaultCategory } = require('./category');
|
||||||
const logger = new Logger();
|
const logger = new Logger();
|
||||||
const k8s = require('@kubernetes/client-node');
|
const k8s = require('@kubernetes/client-node');
|
||||||
|
|
||||||
|
@ -89,7 +91,18 @@ exports.getApps = asyncWrapper(async (req, res, next) => {
|
||||||
order: [[orderType, 'ASC']],
|
order: [[orderType, 'ASC']],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
containers = containers.filter((e) => Object.keys(e.Labels).length !== 0);
|
containers = containers.filter((e) => Object.keys(e.Labels).length !== 0);
|
||||||
|
=======
|
||||||
|
const categories = await Category.findAll({
|
||||||
|
where: {
|
||||||
|
type: 'apps'
|
||||||
|
},
|
||||||
|
order: [[orderType, 'ASC']]
|
||||||
|
});
|
||||||
|
|
||||||
|
containers = containers.filter(e => Object.keys(e.Labels).length !== 0);
|
||||||
|
>>>>>>> e1a46b7 (Support for app categories in docker integration (#8))
|
||||||
const dockerApps = [];
|
const dockerApps = [];
|
||||||
for (const container of containers) {
|
for (const container of containers) {
|
||||||
const labels = container.Labels;
|
const labels = container.Labels;
|
||||||
|
@ -99,6 +112,7 @@ exports.getApps = asyncWrapper(async (req, res, next) => {
|
||||||
'flame.url' in labels &&
|
'flame.url' in labels &&
|
||||||
/^app/.test(labels['flame.type'])
|
/^app/.test(labels['flame.type'])
|
||||||
) {
|
) {
|
||||||
|
<<<<<<< HEAD
|
||||||
for (let i = 0; i < labels['flame.name'].split(';').length; i++) {
|
for (let i = 0; i < labels['flame.name'].split(';').length; i++) {
|
||||||
const names = labels['flame.name'].split(';');
|
const names = labels['flame.name'].split(';');
|
||||||
const urls = labels['flame.url'].split(';');
|
const urls = labels['flame.url'].split(';');
|
||||||
|
@ -114,6 +128,19 @@ exports.getApps = asyncWrapper(async (req, res, next) => {
|
||||||
icon: icons[i] || 'docker',
|
icon: icons[i] || 'docker',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
=======
|
||||||
|
const app = {
|
||||||
|
name: labels['flame.name'],
|
||||||
|
url: labels['flame.url'],
|
||||||
|
icon: labels['flame.icon'] || 'docker',
|
||||||
|
categoryId: dockerDefaultCategory.id
|
||||||
|
}
|
||||||
|
if (labels['flame.category']) {
|
||||||
|
const category = categories.find(category => category.name.toUpperCase() === labels['flame.category'].toUpperCase());
|
||||||
|
app.categoryId = category ? category.id : dockerDefaultCategory.id
|
||||||
|
}
|
||||||
|
dockerApps.push(app);
|
||||||
|
>>>>>>> e1a46b7 (Support for app categories in docker integration (#8))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,14 @@ const Bookmark = require('../models/Bookmark');
|
||||||
const Config = require('../models/Config');
|
const Config = require('../models/Config');
|
||||||
const { Sequelize } = require('sequelize');
|
const { Sequelize } = require('sequelize');
|
||||||
|
|
||||||
|
exports.dockerDefaultCategory = {
|
||||||
|
id: -2,
|
||||||
|
name: "Docker",
|
||||||
|
type: "apps",
|
||||||
|
isPinned: true,
|
||||||
|
orderId: 99,
|
||||||
|
};
|
||||||
|
|
||||||
// @desc Create new category
|
// @desc Create new category
|
||||||
// @route POST /api/categories
|
// @route POST /api/categories
|
||||||
// @access Public
|
// @access Public
|
||||||
|
@ -73,6 +81,7 @@ exports.getCategories = asyncWrapper(async (req, res, next) => {
|
||||||
],
|
],
|
||||||
order: [[orderType, 'ASC']],
|
order: [[orderType, 'ASC']],
|
||||||
});
|
});
|
||||||
|
categories.push(exports.dockerDefaultCategory);
|
||||||
}
|
}
|
||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
|
@ -100,12 +109,16 @@ exports.getCategory = asyncWrapper(async (req, res, next) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!category) {
|
if (!category) {
|
||||||
return next(
|
if (req.params.id === exports.dockerDefaultCategory.id) {
|
||||||
new ErrorResponse(
|
category = exports.dockerDefaultCategory;
|
||||||
`Category with id of ${req.params.id} was not found`,
|
} else {
|
||||||
404
|
return next(
|
||||||
)
|
new ErrorResponse(
|
||||||
);
|
`Category with id of ${req.params.id} was not found`,
|
||||||
|
404
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
|
|
|
@ -9,7 +9,7 @@ const Category = sequelize.define('Category', {
|
||||||
type: {
|
type: {
|
||||||
type: DataTypes.STRING,
|
type: DataTypes.STRING,
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
defaultValue: 'bookmark' // Default value for database migration only
|
defaultValue: 'bookmarks' // Default value for database migration only
|
||||||
},
|
},
|
||||||
isPinned: {
|
isPinned: {
|
||||||
type: DataTypes.BOOLEAN,
|
type: DataTypes.BOOLEAN,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue