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

filter categories in server instead of the client and small fixes following latest rebase

This commit is contained in:
François Darveau 2021-09-06 11:45:10 -04:00
parent cb794daf73
commit 64a9dabdd6
6 changed files with 35 additions and 34 deletions

View file

@ -201,7 +201,7 @@ async function retrieveDockerApps(apps, orderType, unpinStoppedApps) {
order: [[orderType, 'ASC']]
});
containers = containers.filter(e => Object.keys(e.Labels).length !== 0);
containers = containers.filter((e) => Object.keys(e.Labels).length !== 0);
const dockerApps = [];
for (const container of containers) {
const labels = container.Labels;
@ -270,7 +270,15 @@ async function retrieveKubernetesApps(apps, orderType, unpinStoppedApps) {
order: [[orderType, 'ASC']]
});
ingresses = ingresses.filter(e => Object.keys(e.metadata.annotations).length !== 0);
const categories = await Category.findAll({
where: {
type: 'apps'
},
order: [[orderType, 'ASC']]
});
ingresses = ingresses.filter((e) => Object.keys(e.metadata.annotations).length !== 0);
const kubernetesApps = [];
for (const ingress of ingresses) {
const annotations = ingress.metadata.annotations;
@ -286,7 +294,7 @@ async function retrieveKubernetesApps(apps, orderType, unpinStoppedApps) {
const icons = annotations['flame.pawelmalak/icon'] ? annotations['flame.pawelmalak/icon'].split(';') : [];;
for (let i = 0; i < names.length; i++) {
const category = categoriesLabels[i] ? categories.find(category => category.name.toUpperCase() === categoriesLabels[i].toUpperCase()) : dockerDefaultCategory;
const category = categoriesLabels[i] ? categories.find(category => category.name.toUpperCase() === categoriesLabels[i].toUpperCase()) : kubernetesDefaultCategory;
kubernetesApps.push({
name: names[i] || names[0],

View file

@ -21,6 +21,8 @@ exports.kubernetesDefaultCategory = {
orderId: 999,
};
const defaultCategories = [exports.dockerDefaultCategory, exports.kubernetesDefaultCategory];
// @desc Create new category
// @route POST /api/categories
// @access Public
@ -60,37 +62,26 @@ exports.getCategories = asyncWrapper(async (req, res, next) => {
const orderType = useOrdering ? useOrdering.value : "createdAt";
let categories;
let categoryTypes = []
if (!req.params.type || req.params.type === 'apps') {
categoryTypes.push({model: App, as: "apps"});
}
if (!req.params.type || req.params.type === 'bookmarks') {
categoryTypes.push({model: Bookmark, as: "bookmarks"});
}
if (orderType == "name") {
categories = await Category.findAll({
include: [
{
model: App,
as: 'apps',
},
{
model: Bookmark,
as: 'bookmarks',
},
],
include: categoryTypes,
order: [[Sequelize.fn('lower', Sequelize.col('Category.name')), 'ASC']],
});
} else {
categories = await Category.findAll({
include: [
{
model: App,
as: 'apps',
},
{
model: Bookmark,
as: 'bookmarks',
},
],
include: categoryTypes,
order: [[orderType, 'ASC']],
});
categories.push(exports.dockerDefaultCategory);
}
categories.push(defaultCategories.filter((category) => categoryTypes.findIndex((includedType) => category.type === includedType.as) > -1));
res.status(200).json({
success: true,
@ -119,6 +110,8 @@ exports.getCategory = asyncWrapper(async (req, res, next) => {
if (!category) {
if (req.params.id === exports.dockerDefaultCategory.id) {
category = exports.dockerDefaultCategory;
} else if (req.params.id === exports.kubernetesDefaultCategory.id) {
category = exports.kubernetesDefaultCategory;
} else {
return next(
new ErrorResponse(