mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Update page updatedAt when updating labels
This commit is contained in:
parent
00f38d1134
commit
c08afe6451
1 changed files with 18 additions and 8 deletions
|
|
@ -15,13 +15,16 @@ export const addLabelInPage = async (
|
|||
body: {
|
||||
script: {
|
||||
source: `if (ctx._source.labels == null) {
|
||||
ctx._source.labels = [params.label]
|
||||
ctx._source.labels = [params.label];
|
||||
ctx._source.updatedAt = params.updatedAt
|
||||
} else if (!ctx._source.labels.any(label -> label.name == params.label.name)) {
|
||||
ctx._source.labels.add(params.label)
|
||||
ctx._source.labels.add(params.label) ;
|
||||
ctx._source.updatedAt = params.updatedAt
|
||||
} else { ctx.op = 'none' }`,
|
||||
lang: 'painless',
|
||||
params: {
|
||||
label: label,
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -99,20 +102,22 @@ export const deleteLabel = async (
|
|||
ctx: PageContext
|
||||
): Promise<boolean> => {
|
||||
try {
|
||||
console.log('deleting label', label)
|
||||
const { body } = await client.updateByQuery({
|
||||
index: INDEX_ALIAS,
|
||||
body: {
|
||||
script: {
|
||||
source: `if (ctx._source.highlights != null && ctx._source.highlights[0].labels != null) {
|
||||
ctx._source.highlights[0].labels.removeIf(label -> label.name == params.label)
|
||||
ctx._source.highlights[0].labels.removeIf(label -> label.name == params.label);
|
||||
ctx._source.updatedAt = params.updatedAt
|
||||
}
|
||||
if (ctx._source.labels != null) {
|
||||
ctx._source.labels.removeIf(label -> label.name == params.label)
|
||||
ctx._source.labels.removeIf(label -> label.name == params.label);
|
||||
ctx._source.updatedAt = params.updatedAt
|
||||
}`,
|
||||
lang: 'painless',
|
||||
params: {
|
||||
label: label,
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
},
|
||||
query: {
|
||||
|
|
@ -178,15 +183,18 @@ export const updateLabel = async (
|
|||
script: {
|
||||
source: `if (ctx._source.labels != null) {
|
||||
ctx._source.labels.removeIf(l -> l.id == params.label.id);
|
||||
ctx._source.labels.add(params.label)
|
||||
ctx._source.labels.add(params.label);
|
||||
ctx._source.updatedAt = params.updatedAt
|
||||
}
|
||||
if (ctx._source.highlights != null) {
|
||||
ctx._source.highlights[0].labels.removeIf(l -> l.id == params.label.id);
|
||||
ctx._source.highlights[0].labels.add(params.label)
|
||||
ctx._source.highlights[0].labels.add(params.label);
|
||||
ctx._source.updatedAt = params.updatedAt
|
||||
}`,
|
||||
lang: 'painless',
|
||||
params: {
|
||||
label: label,
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
},
|
||||
query: {
|
||||
|
|
@ -252,10 +260,12 @@ export const setLabelsForHighlight = async (
|
|||
index: INDEX_ALIAS,
|
||||
body: {
|
||||
script: {
|
||||
source: `ctx._source.highlights[0].labels = params.labels`,
|
||||
source: `ctx._source.highlights[0].labels = params.labels;
|
||||
ctx._source.updatedAt = params.updatedAt`,
|
||||
lang: 'painless',
|
||||
params: {
|
||||
labels: labels,
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
},
|
||||
query: {
|
||||
|
|
|
|||
Loading…
Reference in a new issue