Added quick alert buttons to entity and tag headers.

This commit is contained in:
2025-03-09 06:00:18 +01:00
parent 61ed171c9d
commit c6c4dcad7c
9 changed files with 118 additions and 61 deletions

View File

@@ -485,10 +485,6 @@ async function queryManticoreSql(filters, options, _reqUser) {
export async function fetchActors(filters, rawOptions, reqUser) {
const options = curateOptions(rawOptions);
console.log('filters', filters);
console.log('options', options);
const result = await queryManticoreSql(filters, options, reqUser);
// console.log('result', result);

View File

@@ -175,8 +175,6 @@ export async function removeAlert(alertId, reqUser) {
.groupBy('alerts.id')
.first();
console.log(alertId, alert);
await knex('alerts')
.where('id', alertId)
.where('user_id', reqUser.id)

View File

@@ -26,6 +26,10 @@ export function curateEntity(entity, context) {
parameters: entity.affiliate.parameters,
} : null,
...context?.append?.[entity.id],
alerts: {
only: context?.alerts?.filter((alert) => alert.is_only).flatMap((alert) => alert.alert_ids) || [],
multi: context?.alerts?.filter((alert) => !alert.is_only).flatMap((alert) => alert.alert_ids) || [],
},
};
}
@@ -74,8 +78,8 @@ export async function fetchEntities(options = {}) {
return entities.map((entityEntry) => curateEntity(entityEntry));
}
export async function fetchEntitiesById(entityIds, options = {}) {
const [entities, children] = await Promise.all([
export async function fetchEntitiesById(entityIds, options = {}, reqUser) {
const [entities, children, alerts] = await Promise.all([
knex('entities')
.select(
'entities.*',
@@ -95,12 +99,18 @@ export async function fetchEntitiesById(entityIds, options = {}) {
.whereIn('entities.parent_id', entityIds)
.whereNot('type', 'info')
.orderBy('slug') : [],
reqUser
? knex('alerts_users_entities')
.where('user_id', reqUser.id)
.whereIn('entity_id', entityIds)
: [],
]);
if (options.order) {
return entities.map((entityEntry) => curateEntity(entityEntry, {
append: options.append,
children,
children: children.filter((channel) => channel.parent_id === entityEntry.id),
alerts: alerts.filter((alert) => alert.entity_id === entityEntry.id),
}));
}
@@ -114,7 +124,8 @@ export async function fetchEntitiesById(entityIds, options = {}) {
return curateEntity(entity, {
append: options.append,
children,
children: children.filter((channel) => channel.parent_id === entity.id),
alerts: alerts.filter((alert) => alert.entity_id === entity.id),
});
}).filter(Boolean);

View File

@@ -25,6 +25,10 @@ function curateTag(tag, context) {
parent: tag.poster.entity_parent,
}),
},
alerts: {
only: context?.alerts?.filter((alert) => alert.is_only).flatMap((alert) => alert.alert_ids) || [],
multi: context?.alerts?.filter((alert) => !alert.is_only).flatMap((alert) => alert.alert_ids) || [],
},
...context?.append?.[tag.id],
};
}
@@ -75,8 +79,8 @@ export async function fetchTags(options = {}) {
}));
}
export async function fetchTagsById(tagIds, options = {}) {
const [tags, posters] = await Promise.all([
export async function fetchTagsById(tagIds, options = {}, reqUser) {
const [tags, posters, alerts] = await Promise.all([
knex('tags')
.whereIn('tags.id', tagIds.filter((tagId) => typeof tagId === 'number'))
.orWhereIn('tags.slug', tagIds.filter((tagId) => typeof tagId === 'string'))
@@ -93,6 +97,17 @@ export async function fetchTagsById(tagIds, options = {}) {
.leftJoin('entities as parents', 'parents.id', 'entities.parent_id')
.whereIn('tags.id', tagIds.filter((tagId) => typeof tagId === 'number'))
.orWhereIn('tags.slug', tagIds.filter((tagId) => typeof tagId === 'string')),
reqUser
? knex('alerts_users_tags')
.select('alerts_users_tags.*')
.leftJoin('tags', 'tags.id', 'alerts_users_tags.tag_id')
.where('user_id', reqUser.id)
.where((whereBuilder) => {
whereBuilder
.whereIn('tags.id', tagIds.filter((tagId) => typeof tagId === 'number'))
.orWhereIn('tags.slug', tagIds.filter((tagId) => typeof tagId === 'string'));
})
: [],
]);
const postersByTagId = Object.fromEntries(posters.map((poster) => [poster.tag_id, poster]));
@@ -101,7 +116,10 @@ export async function fetchTagsById(tagIds, options = {}) {
return tags.map((tagEntry) => curateTag({
...tagEntry,
poster: postersByTagId[tagEntry.id],
}, { append: options.append }));
}, {
alerts: alerts.filter((alert) => alert.tag_id === tagEntry.id),
append: options.append,
}));
}
const curatedTags = tagIds.map((tagId) => {
@@ -115,7 +133,10 @@ export async function fetchTagsById(tagIds, options = {}) {
return curateTag({
...tag,
poster: postersByTagId[tag.id],
}, { append: options.append });
}, {
alerts: alerts.filter((alert) => alert.tag_id === tag.id),
append: options.append,
});
}).filter(Boolean);
return curatedTags;