This repository has been archived by the owner on Jan 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1205 from njam/log-cmp
Add LogList cmp, EmailPreview cmp and Error pages
- Loading branch information
Showing
24 changed files
with
369 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<iframe class="htmlPreview" src="" width="100%" height="530" frameborder="1"></iframe> | ||
<hr /> | ||
<pre> | ||
{$plainText} | ||
</pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
.flushLog { | ||
float: right; | ||
} | ||
|
||
.logList { | ||
.log { | ||
font-family: monospace; | ||
font-size: 10px; | ||
|
||
&.header { | ||
font-size: 13px; | ||
} | ||
|
||
.message { | ||
white-space: pre-line; | ||
margin-right: 5px; | ||
overflow-x: auto; | ||
overflow-y: hidden; | ||
} | ||
.counter { | ||
float: right; | ||
} | ||
} | ||
|
||
.log | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{button_link icon='delete' iconConfirm='delete-confirm' label='Flush' class='warning flushLog' data=['click-confirmed' => 'true']} | ||
|
||
<ul class="aggregationPeriodList menu-pills"> | ||
<li class="aggregationPeriod {if null === $aggregate}active{/if}"> | ||
<a href="{linkUrl page=$urlPage type=$type}">No aggregation</a> | ||
</li> | ||
<li class="aggregationPeriod {if 0 === $aggregate}active{/if}"> | ||
<a href="{linkUrl page=$urlPage type=$type aggregate=0}">Last Release</a> | ||
</li> | ||
{foreach $aggregationPeriodList as $aggregationPeriodItem} | ||
<li class="aggregationPeriod {if $aggregationPeriodItem === $aggregate}active{/if}"> | ||
<a href="{linkUrl page=$urlPage type=$type aggregate=$aggregationPeriodItem}">{date_period period=$aggregationPeriodItem}</a> | ||
</li> | ||
{/foreach} | ||
</ul> | ||
|
||
<ul class="logList dataTable"> | ||
<li class="log header"> | ||
<div class="counter"> | ||
{if isset($aggregationPeriod)} | ||
Count | ||
{else} | ||
Time | ||
{/if} | ||
</div> | ||
<div class="message">Message</div> | ||
</li> | ||
{foreach $logList as $log} | ||
<li class="log"> | ||
<div class="counter"> | ||
{if $aggregationPeriod} | ||
{$log.count} | ||
{else} | ||
{date_timeago time=$log.timeStamp} | ||
{/if} | ||
</div> | ||
<div class="message">{$log.msg|escape}</div> | ||
{if !empty($log.metaInfo)} | ||
<div class="toggleNext">Meta Info</div> | ||
<div class="toggleNext-content"> | ||
{foreach $log.metaInfo as $key => $value} | ||
<div class="tableField clearfix"> | ||
<div class="label">{$key|escape}</div> | ||
<div class="value">{$value|@varline|escape}</div> | ||
</div> | ||
{/foreach} | ||
</div> | ||
{/if} | ||
</li> | ||
{/foreach} | ||
|
||
</ul>{paging paging=$logList urlPage=$urlPage urlParams=$urlParams} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{extends file=$render->getLayoutPath('Page/Abstract/default.tpl')} | ||
|
||
{block name='content-main'} | ||
{translate 'Authentication required'} | ||
{/block} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{translate 'Authentication required'} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{extends file=$render->getLayoutPath('Page/Abstract/default.tpl')} | ||
|
||
{block name='content-main'} | ||
{component name='CM_Component_NotAllowed'} | ||
{/block} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{translate 'Not Allowed'} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{extends file=$render->getLayoutPath('Page/Abstract/default.tpl')} | ||
|
||
{block name='content-main'} | ||
{component name='CM_Component_Notfound'} | ||
{/block} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{translate 'Page Not Found'} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* @class CM_Component_EmailPreview | ||
* @extends CM_Component_Abstract | ||
*/ | ||
var CM_Component_EmailPreview = CM_Component_Abstract.extend({ | ||
_class: 'CM_Component_EmailPreview', | ||
|
||
html: null, | ||
|
||
ready: function() { | ||
var $iframe = this.$('.htmlPreview'); | ||
$iframe.attr('src', 'data:text/html;charset=utf-8,' + encodeURI(this.html)); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
class CM_Component_EmailPreview extends CM_Component_Abstract { | ||
|
||
public function checkAccessible(CM_Render $render) { | ||
} | ||
|
||
public function prepare() { | ||
$email = $this->_params->get('email'); | ||
if (!$email instanceof CM_Mail) { | ||
throw new CM_Exception_InvalidParam('Invalid `email` param'); | ||
} | ||
$userDefault = $this->_getViewer(); | ||
$user = $this->_params->has('user') ? $this->_params->getUser('user') : $userDefault; | ||
|
||
$render = new CM_Render(null, $user); | ||
list($subject, $html, $plainText) = $render->render($email); | ||
$this->setTplParam('plainText', $plainText); | ||
$this->_setJsParam('html', $html); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* @class CM_Component_LogList | ||
* @extends CM_Component_Abstract | ||
*/ | ||
var CM_Component_LogList = CM_Component_Abstract.extend({ | ||
|
||
/** @type String */ | ||
_class: 'CM_Component_LogList', | ||
|
||
type: null, | ||
|
||
events: { | ||
'click .flushLog': 'flushLog' | ||
}, | ||
|
||
flushLog: function() { | ||
this.ajaxModal('flushLog', {'type': this.type}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
class CM_Component_LogList extends CM_Component_Abstract { | ||
|
||
public function checkAccessible(CM_Render $render) { | ||
if (!CM_Bootloader::getInstance()->isDebug()) { | ||
throw new CM_Exception_NotAllowed(); | ||
} | ||
} | ||
|
||
public function prepare() { | ||
$type = $this->_params->getInt('type'); | ||
$aggregate = $this->_params->has('aggregate') ? $this->_params->getInt('aggregate') : null; | ||
$urlPage = $this->_params->has('urlPage') ? $this->_params->getString('urlPage') : null; | ||
$urlParams = $this->_params->has('urlParams') ? $this->_params->getArray('urlParams') : null; | ||
|
||
$aggregationPeriod = $aggregate; | ||
if (0 === $aggregationPeriod) { | ||
$deployStamp = CM_App::getInstance()->getDeployVersion(); | ||
$aggregationPeriod = time() - $deployStamp; | ||
} | ||
$logList = CM_Paging_Log_Abstract::factory($type, (bool) $aggregationPeriod, $aggregationPeriod); | ||
$logList->setPage($this->_params->getPage(), $this->_params->getInt('count', 50)); | ||
|
||
$this->setTplParam('type', $type); | ||
$this->setTplParam('logList', $logList); | ||
$this->setTplParam('aggregate', $aggregate); | ||
$this->setTplParam('aggregationPeriod', $aggregationPeriod); | ||
$this->setTplParam('aggregationPeriodList', array(3600, 86400, 7 * 86400, 31 * 86400)); | ||
$this->setTplParam('urlPage', $urlPage); | ||
$this->setTplParam('urlParams', $urlParams); | ||
|
||
$this->_setJsParam('type', $type); | ||
} | ||
|
||
public static function ajax_flushLog(CM_Params $params, CM_ComponentFrontendHandler $handler, CM_Response_View_Ajax $response) { | ||
if (!static::_getAllowedFlush($response->getRender())) { | ||
throw new CM_Exception_NotAllowed(); | ||
} | ||
|
||
$type = $params->getInt('type'); | ||
$logList = CM_Paging_Log_Abstract::factory($type); | ||
$logList->flush(); | ||
|
||
$response->reloadComponent(); | ||
} | ||
|
||
/** | ||
* @param CM_Render $render | ||
* @return bool | ||
*/ | ||
protected static function _getAllowedFlush(CM_Render $render) { | ||
return CM_Bootloader::getInstance()->isDebug(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* @class CM_Page_Error_AuthRequired | ||
* @extends CM_Page_Abstract | ||
*/ | ||
var CM_Page_Error_AuthRequired = CM_Page_Abstract.extend({ | ||
|
||
/** @type String */ | ||
_class: 'CM_Page_Error_AuthRequired' | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
class CM_Page_Error_AuthRequired extends CM_Page_Abstract { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* @class CM_Page_Error_NotAllowed | ||
* @extends CM_Page_Abstract | ||
*/ | ||
var CM_Page_Error_NotAllowed = CM_Page_Abstract.extend({ | ||
|
||
/** @type String */ | ||
_class: 'CM_Page_Error_NotAllowed' | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
class CM_Page_Error_NotAllowed extends CM_Page_Abstract { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* @class CM_Page_Error_NotFound | ||
* @extends CM_Page_Abstract | ||
*/ | ||
var CM_Page_Error_NotFound = CM_Page_Abstract.extend({ | ||
|
||
/** @type String */ | ||
_class: 'CM_Page_Error_NotFound' | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
class CM_Page_Error_NotFound extends CM_Page_Abstract { | ||
|
||
public function prepareResponse(CM_Response_Page $response) { | ||
$response->setHeaderNotfound(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
function smarty_modifier_varline($var) { | ||
return CM_Util::var_line($var); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
class CM_Page_Error_AuthRequiredTest extends CMTest_TestCase { | ||
|
||
public function testGuest() { | ||
$page = $this->_createPage('CM_Page_Error_AuthRequired'); | ||
$html = $this->_renderPage($page); | ||
|
||
$this->assertContains('Authentication required', $html->getText()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
class CM_Page_Error_NotAllowedTest extends CMTest_TestCase { | ||
|
||
public function testGuest() { | ||
$page = $this->_createPage('CM_Page_Error_NotAllowed'); | ||
$html = $this->_renderPage($page); | ||
|
||
$this->assertTrue($html->exists('.CM_Component_NotAllowed')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
class CM_Page_Error_NotFoundTest extends CMTest_TestCase { | ||
|
||
public function testGuest() { | ||
$page = $this->_createPage('CM_Page_Error_NotFound'); | ||
$html = $this->_renderPage($page); | ||
|
||
$this->assertTrue($html->exists('.CM_Component_Notfound')); | ||
} | ||
} |