Bugfix/Improved AdvancedSearch popup by prefill the values

This commit is contained in:
the-djmaze 2022-08-03 22:23:32 +02:00
parent 9bd3049ba0
commit 9559986499
2 changed files with 33 additions and 44 deletions

View file

@ -1,6 +1,7 @@
import { koComputable } from 'External/ko'; import { koComputable } from 'External/ko';
import { i18n, trigger as translatorTrigger } from 'Common/Translator'; import { i18n, trigger as translatorTrigger } from 'Common/Translator';
import { pString } from 'Common/Utils';
import { MessagelistUserStore } from 'Stores/User/Messagelist'; import { MessagelistUserStore } from 'Stores/User/Messagelist';
@ -70,55 +71,38 @@ export class AdvancedSearchPopupView extends AbstractViewPopup {
this.close(); this.close();
} }
parseSearchStringValue(search) {
const parts = (search || '').split(/[\s]+/g);
parts.forEach(part => {
switch (part) {
case 'has:attachment':
this.hasAttachment(true);
break;
case 'is:unseen,flagged':
this.starred(true);
/* falls through */
case 'is:unseen':
this.unseen(true);
break;
// no default
}
});
}
buildSearchString() { buildSearchString() {
const const
self = this,
data = new FormData(), data = new FormData(),
append = (key, value) => value.length && data.append(key, value); append = (key, value) => value.length && data.append(key, value);
append('from', this.from().trim()); append('from', self.from().trim());
append('to', this.to().trim()); append('to', self.to().trim());
append('subject', this.subject().trim()); append('subject', self.subject().trim());
append('text', this.text().trim()); append('text', self.text().trim());
append('in', this.selectedTreeValue()); append('in', self.selectedTreeValue());
if (-1 < this.selectedDateValue()) { if (-1 < self.selectedDateValue()) {
let d = new Date(); let d = new Date();
d.setDate(d.getDate() - this.selectedDateValue()); d.setDate(d.getDate() - self.selectedDateValue());
append('since', d.toISOString().split('T')[0]); append('since', d.toISOString().split('T')[0]);
} }
let result = new URLSearchParams(data).toString(); let result = new URLSearchParams(data).toString();
if (this.hasAttachment()) { if (self.hasAttachment()) {
result += '&attachment'; result += '&attachment';
} }
if (this.unseen()) { if (self.unseen()) {
result += '&unseen'; result += '&unseen';
} }
if (this.starred()) { if (self.starred()) {
result += '&flagged'; result += '&flagged';
} }
if (1 == this.repliedValue()) { if (1 == self.repliedValue()) {
result += '&answered'; result += '&answered';
} }
if (0 == this.repliedValue()) { if (0 == self.repliedValue()) {
result += '&unanswered'; result += '&unanswered';
} }
@ -126,17 +110,22 @@ export class AdvancedSearchPopupView extends AbstractViewPopup {
} }
onShow(search) { onShow(search) {
this.from(''); const self = this,
this.to(''); params = new URLSearchParams('?'+search);
this.subject(''); self.from(pString(params.get('from')));
this.text(''); self.to(pString(params.get('to')));
self.subject(pString(params.get('subject')));
this.repliedValue(-1); self.text(pString(params.get('text')));
this.selectedDateValue(-1); self.selectedTreeValue(pString(params.get('in')));
this.hasAttachment(false); // self.selectedDateValue(params.get('since'));
this.starred(false); self.selectedDateValue(-1);
this.unseen(false); self.hasAttachment(params.has('attachment'));
self.starred(params.has('flagged'));
this.parseSearchStringValue(search); self.unseen(params.has('unseen'));
if (params.has('answered')) {
self.repliedValue(1);
} else if (params.has('unanswered')) {
self.repliedValue(0);
}
} }
} }

View file

@ -387,7 +387,7 @@ abstract class SearchCriterias
$aCache = array(); $aCache = array();
$sSearch = \MailSo\Base\Utils::StripSpaces($sSearch); $sSearch = \MailSo\Base\Utils::StripSpaces($sSearch);
$sSearch = \trim(\preg_replace('/('.static::RegEx.'): /i', '\\1:', $sSearch)); $sSearch = \trim(\preg_replace('/('.static::RegEx.'):\\s+/i', '\\1:', $sSearch));
$mMatch = array(); $mMatch = array();
if (\preg_match_all('/".*?(?<!\\\)"/', $sSearch, $mMatch)) { if (\preg_match_all('/".*?(?<!\\\)"/', $sSearch, $mMatch)) {
@ -414,7 +414,7 @@ abstract class SearchCriterias
} }
} }
if (\preg_match_all('/('.static::RegEx.'):([^\s]*)/i', $sSearch, $mMatch)) { if (\preg_match_all('/('.static::RegEx.'):([^\\s]*)/i', $sSearch, $mMatch)) {
if (\is_array($mMatch[0])) { if (\is_array($mMatch[0])) {
foreach ($mMatch[0] as $sToken) { foreach ($mMatch[0] as $sToken) {
$sSearch = \str_replace($sToken, '', $sSearch); $sSearch = \str_replace($sToken, '', $sSearch);