Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1205 from njam/log-cmp
Browse files Browse the repository at this point in the history
Add LogList cmp, EmailPreview cmp and Error pages
  • Loading branch information
njam committed May 11, 2014
2 parents 0d8b665 + ae42edb commit 4ff78ae
Show file tree
Hide file tree
Showing 24 changed files with 369 additions and 0 deletions.
5 changes: 5 additions & 0 deletions layout/default/Component/EmailPreview/default.tpl
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>
26 changes: 26 additions & 0 deletions layout/default/Component/LogList/default.less
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
}
52 changes: 52 additions & 0 deletions layout/default/Component/LogList/default.tpl
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}
5 changes: 5 additions & 0 deletions layout/default/Page/Error_AuthRequired/default.tpl
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}
1 change: 1 addition & 0 deletions layout/default/Page/Error_AuthRequired/title.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{translate 'Authentication required'}
5 changes: 5 additions & 0 deletions layout/default/Page/Error_NotAllowed/default.tpl
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}
1 change: 1 addition & 0 deletions layout/default/Page/Error_NotAllowed/title.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{translate 'Not Allowed'}
5 changes: 5 additions & 0 deletions layout/default/Page/Error_NotFound/default.tpl
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}
1 change: 1 addition & 0 deletions layout/default/Page/Error_NotFound/title.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{translate 'Page Not Found'}
76 changes: 76 additions & 0 deletions layout/default/css/menu.less
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,79 @@
}
}
}

.menu-pills {
margin-bottom: 5px;
line-height: 0;

&.select {
> li {
margin: 0 5px 5px 0;

> a {
box-shadow: 1px 1px lighten(@colorFg, 20);
background-color: @colorBg;
}

&.active > a {
.transform(translate(1px, 1px));
background-color: @colorBgEmphasize3;
}
}
}

> li {
display: inline-block;
position: relative;
white-space: nowrap;

&:not(:first-child) {
margin-left: -1px;
}

> a {
position: relative;
display: block;
max-width: 150px;
.nowrap;
padding: 0 15px;
z-index: 1;
line-height: 38px;
border: 1px solid @colorFgBorderEmphasize3;
background-color: @colorBgEmphasize1;
text-decoration: none;
color: @colorFg;

&:hover {
background-color: @colorBgEmphasize2;
}

.icon, .label {
vertical-align: top;
}

.icon {
display: inline-block;
font-size: 1.2em;
color: @colorFgSubtle;
}
}

&.hasIcon.hasLabel .label {
margin-left: 7px;
}

&.active {
> a {
border: 1px solid darken(@colorFgBorderEmphasize3, 5);
background-color: @colorBg;
box-shadow: none;
z-index: auto;

.icon {
color: @colorFgHeading;
}
}
}
}
}
14 changes: 14 additions & 0 deletions library/CM/Component/EmailPreview.js
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));
}
});
21 changes: 21 additions & 0 deletions library/CM/Component/EmailPreview.php
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);
}
}
19 changes: 19 additions & 0 deletions library/CM/Component/LogList.js
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});
}
});
55 changes: 55 additions & 0 deletions library/CM/Component/LogList.php
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();
}
}
9 changes: 9 additions & 0 deletions library/CM/Page/Error/AuthRequired.js
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'
});
5 changes: 5 additions & 0 deletions library/CM/Page/Error/AuthRequired.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

class CM_Page_Error_AuthRequired extends CM_Page_Abstract {

}
9 changes: 9 additions & 0 deletions library/CM/Page/Error/NotAllowed.js
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'
});
5 changes: 5 additions & 0 deletions library/CM/Page/Error/NotAllowed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

class CM_Page_Error_NotAllowed extends CM_Page_Abstract {

}
9 changes: 9 additions & 0 deletions library/CM/Page/Error/NotFound.js
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'
});
8 changes: 8 additions & 0 deletions library/CM/Page/Error/NotFound.php
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();
}
}
5 changes: 5 additions & 0 deletions library/CM/SmartyPlugins/modifier.varline.php
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);
}
11 changes: 11 additions & 0 deletions tests/library/CM/Page/Error/AuthRequiredTest.php
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());
}
}
11 changes: 11 additions & 0 deletions tests/library/CM/Page/Error/NotAllowedTest.php
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'));
}
}
11 changes: 11 additions & 0 deletions tests/library/CM/Page/Error/NotFoundTest.php
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'));
}
}

0 comments on commit 4ff78ae

Please sign in to comment.