Preparation for custom sorting

This commit is contained in:
unknown 2021-06-17 10:56:27 +02:00
parent ce173f2c42
commit 8974fb3b49
7 changed files with 42 additions and 7 deletions

View file

@ -9,4 +9,21 @@
.TableAction:hover {
cursor: pointer;
}
.Message {
width: 100%;
display: flex;
justify-content: center;
align-items: baseline;
color: var(--color-primary);
margin-bottom: 20px;
}
.Message span {
color: var(--color-accent);
}
.Message span:hover {
cursor: pointer;
}

View file

@ -44,6 +44,7 @@ const Apps = (props: ComponentProps): JSX.Element => {
url: 'string',
icon: 'string',
isPinned: false,
orderId: 0,
id: 0,
createdAt: new Date(),
updatedAt: new Date()

View file

@ -5,6 +5,7 @@ export interface App extends Model {
url: string;
icon: string;
isPinned: boolean;
orderId: number;
}
export interface NewApp {

View file

@ -10,4 +10,5 @@ export interface SettingsForm {
pinAppsByDefault: number;
pinCategoriesByDefault: number;
hideHeader: number;
useOrdering: string;
}

View file

@ -18,7 +18,7 @@ export const searchConfig = (key: string, _default: any) => {
} else {
return pair.value;
}
} else {
return _default;
}
return _default;
}

View file

@ -36,13 +36,24 @@ exports.createApp = asyncWrapper(async (req, res, next) => {
// @route GET /api/apps
// @access Public
exports.getApps = asyncWrapper(async (req, res, next) => {
// const apps = await App.findAll({
// order: [[ Sequelize.fn('lower', Sequelize.col('name')), 'ASC' ]]
// });
const apps = await App.findAll({
order: [[ 'orderId', 'ASC' ]]
// Get config from database
const useOrdering = await Config.findOne({
where: { key: 'useOrdering' }
});
const orderType = useOrdering ? useOrdering.value : 'createdAt';
let apps;
if (orderType == 'name') {
apps = await App.findAll({
order: [[ Sequelize.fn('lower', Sequelize.col('name')), 'ASC' ]]
});
} else {
apps = await App.findAll({
order: [[ orderType, 'ASC' ]]
});
}
res.status(200).json({
success: true,
data: apps

View file

@ -31,6 +31,10 @@
{
"key": "hideHeader",
"value": false
},
{
"key": "useOrdering",
"value": "createdAt"
}
]
}