Filter improvements

This commit is contained in:
RainLoop Team 2015-05-13 02:53:01 +04:00
parent f91f74fe7c
commit 05b1c1dfe5
14 changed files with 222 additions and 68 deletions

View file

@ -321,7 +321,9 @@
Enums.FilterConditionField = {
'From': 'From',
'Recipient': 'Recipient',
'Subject': 'Subject'
'Subject': 'Subject',
'Header': 'Header',
'Size': 'Size'
};
/**
@ -331,7 +333,9 @@
'Contains': 'Contains',
'NotContains': 'NotContains',
'EqualTo': 'EqualTo',
'NotEqualTo': 'NotEqualTo'
'NotEqualTo': 'NotEqualTo',
'Over': 'Over',
'Under': 'Under'
};
/**

View file

@ -25,11 +25,20 @@
this.value = ko.observable('');
this.value.error = ko.observable(false);
this.valueSecond = ko.observable('');
this.valueSecond.error = ko.observable(false);
this.template = ko.computed(function () {
var sTemplate = '';
switch (this.type())
switch (this.field())
{
case Enums.FilterConditionField.Size:
sTemplate = 'SettingsFiltersConditionSize';
break;
case Enums.FilterConditionField.Header:
sTemplate = 'SettingsFiltersConditionMore';
break;
default:
sTemplate = 'SettingsFiltersConditionDefault';
break;
@ -39,6 +48,11 @@
}, this);
this.field.subscribe(function () {
this.value('');
this.valueSecond('');
}, this);
this.regDisposables([this.template]);
}
@ -52,6 +66,12 @@
return false;
}
if (Enums.FilterConditionField.Header === this.field() && '' === this.valueSecond())
{
this.valueSecond.error(true);
return false;
}
return true;
};
@ -62,6 +82,7 @@
this.field(Utils.pString(oItem['Field']));
this.type(Utils.pString(oItem['Type']));
this.value(Utils.pString(oItem['Value']));
this.valueSecond(Utils.pString(oItem['ValueSecond']));
return true;
}
@ -74,7 +95,8 @@
return {
'Field': this.field(),
'Type': this.type(),
'Value': this.value()
'Value': this.value(),
'ValueSecond': this.valueSecond()
};
};
@ -85,6 +107,7 @@
oClone.field(this.field());
oClone.type(this.type());
oClone.value(this.value());
oClone.valueSecond(this.valueSecond());
return oClone;
};

View file

@ -78,6 +78,7 @@
this.actionTypeOptions = ko.observableArray([]);
this.fieldOptions = ko.observableArray([]);
this.typeOptions = ko.observableArray([]);
this.typeOptionsSize = ko.observableArray([]);
Translator.initOnStartOrLangChange(this.populateOptions, this);
@ -136,7 +137,9 @@
this.fieldOptions([
{'id': Enums.FilterConditionField.From, 'name': Translator.i18n('POPUPS_FILTER/SELECT_FIELD_FROM')},
{'id': Enums.FilterConditionField.Recipient, 'name': Translator.i18n('POPUPS_FILTER/SELECT_FIELD_RECIPIENTS')},
{'id': Enums.FilterConditionField.Subject, 'name': Translator.i18n('POPUPS_FILTER/SELECT_FIELD_SUBJECT')}
{'id': Enums.FilterConditionField.Subject, 'name': Translator.i18n('POPUPS_FILTER/SELECT_FIELD_SUBJECT')},
{'id': Enums.FilterConditionField.Size, 'name': Translator.i18n('POPUPS_FILTER/SELECT_FIELD_SIZE')},
{'id': Enums.FilterConditionField.Header, 'name': Translator.i18n('POPUPS_FILTER/SELECT_FIELD_HEADER')}
]);
this.typeOptions([
@ -145,6 +148,11 @@
{'id': Enums.FilterConditionType.EqualTo, 'name': Translator.i18n('POPUPS_FILTER/SELECT_TYPE_EQUAL_TO')},
{'id': Enums.FilterConditionType.NotEqualTo, 'name': Translator.i18n('POPUPS_FILTER/SELECT_TYPE_NOT_EQUAL_TO')}
]);
this.typeOptionsSize([
{'id': Enums.FilterConditionType.Over, 'name': Translator.i18n('POPUPS_FILTER/SELECT_TYPE_OVER')},
{'id': Enums.FilterConditionType.Under, 'name': Translator.i18n('POPUPS_FILTER/SELECT_TYPE_UNDER')}
]);
};

View file

@ -47,6 +47,11 @@ abstract class Driver
*/
protected $bTypedPrefix;
/**
* @var string
*/
protected $sNewLine;
/**
* @var int
*/
@ -79,6 +84,7 @@ abstract class Driver
{
$this->sDatePattern = 'H:i:s';
$this->sName = 'INFO';
$this->sNewLine = "\r\n";
$this->bTimePrefix = true;
$this->bTypedPrefix = true;
$this->bGuidPrefix = true;
@ -246,15 +252,44 @@ abstract class Driver
return isset($this->aPrefixes[$iType]) ? $sName.$this->aPrefixes[$iType].': ' : '';
}
/**
* @param string|array $mDesc
* @param bool $bDiplayCrLf = false
*
* @return string
*/
protected function localWriteImplementation($mDesc, $bDiplayCrLf = false)
{
if ($bDiplayCrLf)
{
if (\is_array($mDesc))
{
foreach ($mDesc as &$sLine)
{
$sLine = \strtr($sLine, array("\r" => '\r', "\n" => '\n'.$this->sNewLine));
$sLine = \rtrim($mDesc);
}
}
else
{
$mDesc = \strtr($mDesc, array("\r" => '\r', "\n" => '\n'.$this->sNewLine));
$mDesc = \rtrim($mDesc);
}
}
return $this->writeImplementation($mDesc);
}
/**
* @final
* @param string $sDesc
* @param int $iType = \MailSo\Log\Enumerations\Type::INFO
* @param string $sName = ''
* @param bool $bDiplayCrLf = false
*
* @return bool
*/
final public function Write($sDesc, $iType = \MailSo\Log\Enumerations\Type::INFO, $sName = '')
final public function Write($sDesc, $iType = \MailSo\Log\Enumerations\Type::INFO, $sName = '', $bDiplayCrLf = false)
{
$bResult = true;
if (!$this->bFlushCache && ($this->bWriteOnErrorOnly || $this->bWriteOnPhpErrorOnly || 0 < $this->iWriteOnTimeoutOnly))
@ -285,18 +320,18 @@ abstract class Driver
if (isset($this->aCache[0]) && empty($this->aCache[0]))
{
$this->aCache[0] = $sFlush;
array_unshift($this->aCache, '');
\array_unshift($this->aCache, '');
}
else
{
array_unshift($this->aCache, $sFlush);
\array_unshift($this->aCache, $sFlush);
}
$this->aCache[] = '--- FlushLogCache: Trigger';
$this->aCache[] = $this->loggerLineImplementation($this->getTimeWithMicroSec(), $sDesc, $iType, $sName);
$this->bFlushCache = true;
$bResult = $this->writeImplementation($this->aCache);
$bResult = $this->localWriteImplementation($this->aCache, $bDiplayCrLf);
$this->aCache = array();
}
else if (0 < $this->iWriteOnTimeoutOnly && \time() - APP_START_TIME > $this->iWriteOnTimeoutOnly)
@ -305,18 +340,18 @@ abstract class Driver
if (isset($this->aCache[0]) && empty($this->aCache[0]))
{
$this->aCache[0] = $sFlush;
array_unshift($this->aCache, '');
\array_unshift($this->aCache, '');
}
else
{
array_unshift($this->aCache, $sFlush);
\array_unshift($this->aCache, $sFlush);
}
$this->aCache[] = '--- FlushLogCache: Trigger';
$this->aCache[] = $this->loggerLineImplementation($this->getTimeWithMicroSec(), $sDesc, $iType, $sName);
$this->bFlushCache = true;
$bResult = $this->writeImplementation($this->aCache);
$bResult = $this->localWriteImplementation($this->aCache, $bDiplayCrLf);
$this->aCache = array();
}
else
@ -326,13 +361,21 @@ abstract class Driver
}
else
{
$bResult = $this->writeImplementation(
$this->loggerLineImplementation($this->getTimeWithMicroSec(), $sDesc, $iType, $sName));
$bResult = $this->localWriteImplementation(
$this->loggerLineImplementation($this->getTimeWithMicroSec(), $sDesc, $iType, $sName), $bDiplayCrLf);
}
return $bResult;
}
/**
* @return string
*/
public function GetNewLine()
{
return $this->sNewLine;
}
/**
* @final
* @return bool

View file

@ -23,23 +23,18 @@ class File extends \MailSo\Log\Driver
*/
private $sLoggerFileName;
/**
* @var string
*/
private $sCrLf;
/**
* @access protected
*
* @param string $sLoggerFileName
* @param string $sCrLf = "\r\n"
* @param string $sNewLine = "\r\n"
*/
protected function __construct($sLoggerFileName, $sCrLf = "\r\n")
protected function __construct($sLoggerFileName, $sNewLine = "\r\n")
{
parent::__construct();
$this->sLoggerFileName = $sLoggerFileName;
$this->sCrLf = $sCrLf;
$this->sNewLine = $sNewLine;
}
/**
@ -52,13 +47,13 @@ class File extends \MailSo\Log\Driver
/**
* @param string $sLoggerFileName
* @param string $sCrLf = "\r\n"
* @param string $sNewLine = "\r\n"
*
* @return \MailSo\Log\Drivers\File
*/
public static function NewInstance($sLoggerFileName, $sCrLf = "\r\n")
public static function NewInstance($sLoggerFileName, $sNewLine = "\r\n")
{
return new self($sLoggerFileName, $sCrLf);
return new self($sLoggerFileName, $sNewLine);
}
/**
@ -86,11 +81,11 @@ class File extends \MailSo\Log\Driver
*/
private function writeToLogFile($mDesc)
{
if (is_array($mDesc))
if (\is_array($mDesc))
{
$mDesc = \implode($this->sCrLf, $mDesc);
$mDesc = \implode($this->sNewLine, $mDesc);
}
return \error_log($mDesc.$this->sCrLf, 3, $this->sLoggerFileName);
return \error_log($mDesc.$this->sNewLine, 3, $this->sLoggerFileName);
}
}

View file

@ -18,11 +18,6 @@ namespace MailSo\Log\Drivers;
*/
class Inline extends \MailSo\Log\Driver
{
/**
* @var string
*/
private $sNewLine;
/**
* @var bool
*/

View file

@ -296,11 +296,13 @@ class Logger extends \MailSo\Base\Collection
* @param string $sDesc
* @param int $iType = \MailSo\Log\Enumerations\Type::INFO
* @param string $sName = ''
* @param bool $bSearchWords = false
* @param bool $bSearchSecretWords = true
* @param bool $bDiplayCrLf = false
*
* @return bool
*/
public function Write($sDesc, $iType = \MailSo\Log\Enumerations\Type::INFO, $sName = '', $bSearchWords = false)
public function Write($sDesc, $iType = \MailSo\Log\Enumerations\Type::INFO,
$sName = '', $bSearchSecretWords = true, $bDiplayCrLf = false)
{
if (isset($this->aForbiddenTypes[$iType]) && true === $this->aForbiddenTypes[$iType])
{
@ -313,7 +315,7 @@ class Logger extends \MailSo\Base\Collection
$aLoggers = array();
$iResult = 1;
if ($bSearchWords && !$this->bShowSecter && 0 < \count($this->aSecretWords))
if ($bSearchSecretWords && !$this->bShowSecter && 0 < \count($this->aSecretWords))
{
$sDesc = \str_replace($this->aSecretWords, '*******', $sDesc);
}
@ -321,7 +323,7 @@ class Logger extends \MailSo\Base\Collection
$aLoggers =& $this->GetAsArray();
foreach ($aLoggers as /* @var $oLogger \MailSo\Log\Driver */ $oLogger)
{
$iResult &= $oLogger->Write($sDesc, $iType, $sName);
$iResult &= $oLogger->Write($sDesc, $iType, $sName, $bDiplayCrLf);
}
return (bool) $iResult;
@ -332,12 +334,14 @@ class Logger extends \MailSo\Base\Collection
* @param int $iType = \MailSo\Log\Enumerations\Type::INFO
* @param string $sName = ''
* @param bool $bSearchSecretWords = false
* @param bool $bDiplayCrLf = false
*
* @return bool
*/
public function WriteDump($oValue, $iType = \MailSo\Log\Enumerations\Type::INFO, $sName = '', $bSearchSecretWords = false)
public function WriteDump($oValue, $iType = \MailSo\Log\Enumerations\Type::INFO, $sName = '',
$bSearchSecretWords = false, $bDiplayCrLf = false)
{
return $this->Write(\print_r($oValue, true), $iType, $sName, $bSearchSecretWords);
return $this->Write(\print_r($oValue, true), $iType, $sName, $bSearchSecretWords, $bDiplayCrLf);
}
/**
@ -345,10 +349,12 @@ class Logger extends \MailSo\Base\Collection
* @param int $iType = \MailSo\Log\Enumerations\Type::NOTICE
* @param string $sName = ''
* @param bool $bSearchSecretWords = true
* @param bool $bDiplayCrLf = false
*
* @return bool
*/
public function WriteException($oException, $iType = \MailSo\Log\Enumerations\Type::NOTICE, $sName = '', $bSearchSecretWords = true)
public function WriteException($oException, $iType = \MailSo\Log\Enumerations\Type::NOTICE, $sName = '',
$bSearchSecretWords = true, $bDiplayCrLf = false)
{
if ($oException instanceof \Exception)
{
@ -359,7 +365,7 @@ class Logger extends \MailSo\Base\Collection
$oException->__LOGINNED__ = true;
return $this->Write((string) $oException, $iType, $sName, $bSearchSecretWords);
return $this->Write((string) $oException, $iType, $sName, $bSearchSecretWords, $bDiplayCrLf);
}
return false;
@ -370,10 +376,12 @@ class Logger extends \MailSo\Base\Collection
* @param int $iType = \MailSo\Log\Enumerations\Type::NOTICE
* @param string $sName = ''
* @param bool $bSearchSecretWords = true
* @param bool $bDiplayCrLf = false
*
* @return bool
*/
public function WriteMixed($mData, $iType = null, $sName = '', $bSearchSecretWords = true)
public function WriteMixed($mData, $iType = null, $sName = '',
$bSearchSecretWords = true, $bDiplayCrLf = false)
{
$iType = null === $iType ? \MailSo\Log\Enumerations\Type::INFO : $iType;
if (\is_array($mData) || \is_object($mData))
@ -381,16 +389,16 @@ class Logger extends \MailSo\Base\Collection
if ($mData instanceof \Exception)
{
$iType = null === $iType ? \MailSo\Log\Enumerations\Type::NOTICE : $iType;
return $this->WriteException($mData, $iType, $sName, $bSearchSecretWords);
return $this->WriteException($mData, $iType, $sName, $bSearchSecretWords, $bDiplayCrLf);
}
else
{
return $this->WriteDump($mData, $iType, $sName, $bSearchSecretWords);
return $this->WriteDump($mData, $iType, $sName, $bSearchSecretWords, $bDiplayCrLf);
}
}
else
{
return $this->Write($mData, $iType, $sName, $bSearchSecretWords);
return $this->Write($mData, $iType, $sName, $bSearchSecretWords, $bDiplayCrLf);
}
return false;

View file

@ -557,11 +557,11 @@ abstract class NetClient
*
* @return void
*/
protected function writeLog($sDesc, $iDescType = \MailSo\Log\Enumerations\Type::INFO)
protected function writeLog($sDesc, $iDescType = \MailSo\Log\Enumerations\Type::INFO, $bDiplayCrLf = false)
{
if ($this->oLogger)
{
$this->oLogger->Write($sDesc, $iDescType, $this->getLogName());
$this->oLogger->Write($sDesc, $iDescType, $this->getLogName(), true, $bDiplayCrLf);
}
}
@ -573,7 +573,7 @@ abstract class NetClient
*/
protected function writeLogWithCrlf($sDesc, $iDescType = \MailSo\Log\Enumerations\Type::INFO)
{
$this->writeLog(\strtr($sDesc, array("\r" => '\r', "\n" => '\n')), $iDescType);
$this->writeLog($sDesc, $iDescType, true);
}
/**

View file

@ -19,6 +19,11 @@ class FilterCondition
*/
private $sValue;
/**
* @var string
*/
private $sValueSecond;
public function __construct()
{
$this->Clear();
@ -29,6 +34,7 @@ class FilterCondition
$this->sField = \RainLoop\Providers\Filters\Enumerations\ConditionField::FROM;
$this->sType = \RainLoop\Providers\Filters\Enumerations\ConditionType::EQUAL_TO;
$this->sValue = '';
$this->sValueSecond = '';
}
/**
@ -55,6 +61,14 @@ class FilterCondition
return $this->sValue;
}
/**
* @return string
*/
public function ValueSecond()
{
return $this->sValueSecond;
}
/**
* @param array $aData
*
@ -70,7 +84,8 @@ class FilterCondition
$this->sType = isset($aData['Type']) ? $aData['Type'] :
\RainLoop\Providers\Filters\Enumerations\ConditionType::EQUAL_TO;
$this->sValue = isset($aData['Value']) ? $aData['Value'] : '';
$this->sValue = isset($aData['Value']) ? (string) $aData['Value'] : '';
$this->sValueSecond = isset($aData['ValueSecond']) ? (string) $aData['ValueSecond'] : '';
return true;
}
@ -88,7 +103,8 @@ class FilterCondition
return array(
'Field' => $this->Field(),
'Type' => $this->Type(),
'Value' => $this->Value()
'Value' => $this->Value(),
'ValueSecond' => $this->ValueSecond()
);
}

View file

@ -7,4 +7,6 @@ class ConditionField
const FROM = 'From';
const RECIPIENT = 'Recipient';
const SUBJECT = 'Subject';
const HEADER = 'Header';
const SIZE = 'Size';
}

View file

@ -8,4 +8,6 @@ class ConditionType
const NOT_EQUAL_TO = 'NotEqualTo';
const CONTAINS = 'Contains';
const NOT_CONTAINS = 'NotContains';
const OVER = 'Over';
const UNDER = 'Under';
}

View file

@ -163,12 +163,23 @@ class SieveStorage implements \RainLoop\Providers\Filters\FiltersInterface
{
$sResult = '';
$sTypeWord = '';
$bTrue = true;
$sValue = \trim($oCondition->Value());
if (0 < strlen($sValue))
$sValueSecond = \trim($oCondition->ValueSecond());
if (0 < \strlen($sValue) ||
(0 < \strlen($sValue) && 0 < \strlen($sValueSecond) &&
\RainLoop\Providers\Filters\Enumerations\ConditionField::HEADER === $oCondition->Field()))
{
switch ($oCondition->Type())
{
case \RainLoop\Providers\Filters\Enumerations\ConditionType::OVER:
$sTypeWord = ':over';
break;
case \RainLoop\Providers\Filters\Enumerations\ConditionType::UNDER:
$sTypeWord = ':under';
break;
case \RainLoop\Providers\Filters\Enumerations\ConditionType::NOT_EQUAL_TO:
$sResult .= 'not ';
case \RainLoop\Providers\Filters\Enumerations\ConditionType::EQUAL_TO:
@ -179,6 +190,10 @@ class SieveStorage implements \RainLoop\Providers\Filters\FiltersInterface
case \RainLoop\Providers\Filters\Enumerations\ConditionType::CONTAINS:
$sTypeWord = ':contains';
break;
default:
$bTrue = false;
$sResult = '/* @Error: unknown type value */ false';
break;
}
switch ($oCondition->Field())
@ -192,26 +207,43 @@ class SieveStorage implements \RainLoop\Providers\Filters\FiltersInterface
case \RainLoop\Providers\Filters\Enumerations\ConditionField::SUBJECT:
$sResult .= 'header '.$sTypeWord.' ["Subject"]';
break;
case \RainLoop\Providers\Filters\Enumerations\ConditionField::HEADER:
$sResult .= 'header '.$sTypeWord.' ["'.$this->quote($sValueSecond).'"]';
break;
case \RainLoop\Providers\Filters\Enumerations\ConditionField::SIZE:
$sResult .= 'size '.$sTypeWord;
break;
default:
$bTrue = false;
$sResult = '/* @Error: unknown field value */ false';
break;
}
if (\in_array($oCondition->Field(), array(
\RainLoop\Providers\Filters\Enumerations\ConditionField::FROM,
\RainLoop\Providers\Filters\Enumerations\ConditionField::RECIPIENT
)) && false !== \strpos($sValue, ','))
if ($bTrue)
{
$self = $this;
$aValue = \array_map(function ($sValue) use ($self) {
return '"'.$self->quote(\trim($sValue)).'"';
}, \explode(',', $sValue));
if (\in_array($oCondition->Field(), array(
\RainLoop\Providers\Filters\Enumerations\ConditionField::FROM,
\RainLoop\Providers\Filters\Enumerations\ConditionField::RECIPIENT
)) && false !== \strpos($sValue, ','))
{
$self = $this;
$aValue = \array_map(function ($sValue) use ($self) {
return '"'.$self->quote(\trim($sValue)).'"';
}, \explode(',', $sValue));
$sResult .= ' ['.\trim(\implode(', ', $aValue)).']';
}
else
{
$sResult .= ' "'.$this->quote($sValue).'"';
}
$sResult .= ' ['.\trim(\implode(', ', $aValue)).']';
}
else if (\RainLoop\Providers\Filters\Enumerations\ConditionField::SIZE === $oCondition->Field())
{
$sResult .= ' '.$this->quote($sValue);
}
else
{
$sResult .= ' "'.$this->quote($sValue).'"';
}
$sResult = \preg_replace('/[\s]+/u', ' ', $sResult);
$sResult = \preg_replace('/[\s]+/u', ' ', $sResult);
}
}
else
{

View file

@ -0,0 +1,14 @@
<div class="control-group" data-bind="css: {'error': value.error}" style="margin-bottom: 0">
<select class="span2" data-bind="options: $root.fieldOptions, value: field, optionsText: 'name', optionsValue: 'id'"></select>
&nbsp;
<input class="span2" type="text" data-bind="value: valueSecond" />
&nbsp;
<select class="span2" data-bind="options: $root.typeOptions, value: type, optionsText: 'name', optionsValue: 'id'"></select>
&nbsp;
<input class="span3" type="text" data-bind="value: value" />
&nbsp;
<span class="delete-action button-delete pull-right" style="margin-top: 5px;"
data-bind="click: function (oCondition) { $root.removeCondition(oCondition); }">
<i class="icon-trash"></i>
</span>
</div>

View file

@ -0,0 +1,12 @@
<div class="control-group" data-bind="css: {'error': value.error}" style="margin-bottom: 0">
<select class="span3" data-bind="options: $root.fieldOptions, value: field, optionsText: 'name', optionsValue: 'id'"></select>
&nbsp;
<select class="span2" data-bind="options: $root.typeOptionsSize, value: type, optionsText: 'name', optionsValue: 'id'"></select>
&nbsp;
<input class="span3" type="text" data-bind="value: value" />
&nbsp;
<span class="delete-action button-delete pull-right" style="margin-top: 5px;"
data-bind="click: function (oCondition) { $root.removeCondition(oCondition); }">
<i class="icon-trash"></i>
</span>
</div>