mirror of
https://github.com/the-djmaze/snappymail.git
synced 2024-12-29 11:01:34 +08:00
Bugfix/Improved AdvancedSearch popup by prefill the values
This commit is contained in:
parent
9bd3049ba0
commit
9559986499
2 changed files with 33 additions and 44 deletions
|
@ -1,6 +1,7 @@
|
|||
import { koComputable } from 'External/ko';
|
||||
|
||||
import { i18n, trigger as translatorTrigger } from 'Common/Translator';
|
||||
import { pString } from 'Common/Utils';
|
||||
|
||||
import { MessagelistUserStore } from 'Stores/User/Messagelist';
|
||||
|
||||
|
@ -70,55 +71,38 @@ export class AdvancedSearchPopupView extends AbstractViewPopup {
|
|||
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() {
|
||||
const
|
||||
self = this,
|
||||
data = new FormData(),
|
||||
append = (key, value) => value.length && data.append(key, value);
|
||||
|
||||
append('from', this.from().trim());
|
||||
append('to', this.to().trim());
|
||||
append('subject', this.subject().trim());
|
||||
append('text', this.text().trim());
|
||||
append('in', this.selectedTreeValue());
|
||||
if (-1 < this.selectedDateValue()) {
|
||||
append('from', self.from().trim());
|
||||
append('to', self.to().trim());
|
||||
append('subject', self.subject().trim());
|
||||
append('text', self.text().trim());
|
||||
append('in', self.selectedTreeValue());
|
||||
if (-1 < self.selectedDateValue()) {
|
||||
let d = new Date();
|
||||
d.setDate(d.getDate() - this.selectedDateValue());
|
||||
d.setDate(d.getDate() - self.selectedDateValue());
|
||||
append('since', d.toISOString().split('T')[0]);
|
||||
}
|
||||
|
||||
let result = new URLSearchParams(data).toString();
|
||||
|
||||
if (this.hasAttachment()) {
|
||||
if (self.hasAttachment()) {
|
||||
result += '&attachment';
|
||||
}
|
||||
if (this.unseen()) {
|
||||
if (self.unseen()) {
|
||||
result += '&unseen';
|
||||
}
|
||||
if (this.starred()) {
|
||||
if (self.starred()) {
|
||||
result += '&flagged';
|
||||
}
|
||||
if (1 == this.repliedValue()) {
|
||||
if (1 == self.repliedValue()) {
|
||||
result += '&answered';
|
||||
}
|
||||
if (0 == this.repliedValue()) {
|
||||
if (0 == self.repliedValue()) {
|
||||
result += '&unanswered';
|
||||
}
|
||||
|
||||
|
@ -126,17 +110,22 @@ export class AdvancedSearchPopupView extends AbstractViewPopup {
|
|||
}
|
||||
|
||||
onShow(search) {
|
||||
this.from('');
|
||||
this.to('');
|
||||
this.subject('');
|
||||
this.text('');
|
||||
|
||||
this.repliedValue(-1);
|
||||
this.selectedDateValue(-1);
|
||||
this.hasAttachment(false);
|
||||
this.starred(false);
|
||||
this.unseen(false);
|
||||
|
||||
this.parseSearchStringValue(search);
|
||||
const self = this,
|
||||
params = new URLSearchParams('?'+search);
|
||||
self.from(pString(params.get('from')));
|
||||
self.to(pString(params.get('to')));
|
||||
self.subject(pString(params.get('subject')));
|
||||
self.text(pString(params.get('text')));
|
||||
self.selectedTreeValue(pString(params.get('in')));
|
||||
// self.selectedDateValue(params.get('since'));
|
||||
self.selectedDateValue(-1);
|
||||
self.hasAttachment(params.has('attachment'));
|
||||
self.starred(params.has('flagged'));
|
||||
self.unseen(params.has('unseen'));
|
||||
if (params.has('answered')) {
|
||||
self.repliedValue(1);
|
||||
} else if (params.has('unanswered')) {
|
||||
self.repliedValue(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -387,7 +387,7 @@ abstract class SearchCriterias
|
|||
$aCache = array();
|
||||
|
||||
$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();
|
||||
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])) {
|
||||
foreach ($mMatch[0] as $sToken) {
|
||||
$sSearch = \str_replace($sToken, '', $sSearch);
|
||||
|
|
Loading…
Reference in a new issue