1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2025-01-08 04:03:48 +02:00

Implement date pattern negating on the UI: #660

This commit is contained in:
Patrik J. Braun 2023-08-04 19:24:55 +02:00
parent 891c155cce
commit a14c2ff45d
3 changed files with 19 additions and 7 deletions

View File

@ -45,6 +45,7 @@ export class MetadataLoader {
try {
for (const stream of data.streams) {
console.log(stream);
if (stream.width) {
metadata.size.width = stream.width;
metadata.size.height = stream.height;

View File

@ -357,7 +357,8 @@ export class SearchQueryParser {
if (kwStartsWith(str, this.keywords.sameDay) ||
new RegExp('^' + SearchQueryParser.humanToRegexpStr(this.keywords.lastNDays) + '!?:').test(str)) {
const freqStr = str.slice(str.indexOf(':') + 1);
const freqStr = str.indexOf('!:') === -1 ? str.slice(str.indexOf(':') + 1) : str.slice(str.indexOf('!:') + 2);
let freq: DatePatternFrequency = null;
let ago;
if (freqStr == this.keywords.every_week) {
@ -381,15 +382,16 @@ export class SearchQueryParser {
}
if (freq) {
const ret = {
return {
type: SearchQueryTypes.date_pattern,
daysLength: kwStartsWith(str, this.keywords.sameDay) ? 0 : intFromRegexp(str),
frequency: freq
frequency: freq,
...((new RegExp('^' + SearchQueryParser.humanToRegexpStr(this.keywords.lastNDays) + '!:').test(str) ||
str.startsWith(this.keywords.sameDay + '!:')) && {
negate: true
}),
...(ago && {agoNumber: ago})
} as DatePatternSearch;
if (ago) {
ret.agoNumber = ago;
}
return ret;
}
}
@ -586,6 +588,9 @@ export class SearchQueryParser {
} else {
strBuilder += this.keywords.lastNDays.replace(/%d/g, q.daysLength.toString());
}
if (q.negate === true) {
strBuilder += '!';
}
strBuilder += ':';
switch (q.frequency) {
case DatePatternFrequency.every_week:

View File

@ -153,6 +153,12 @@ describe('SearchQueryParser', () => {
frequency: DatePatternFrequency.years_ago,
agoNumber: 1
} as DatePatternSearch);
check({
type: SearchQueryTypes.date_pattern, daysLength: i,
frequency: DatePatternFrequency.years_ago,
agoNumber: 1,
negate: true
} as DatePatternSearch);
}
});
it('Default logical operator should be AND', () => {