Dates localization

This commit is contained in:
Dmitry Khomutov 2017-01-15 17:28:15 +07:00
parent b7ff480e17
commit d0a46ee8ab
No known key found for this signature in database
GPG key ID: 7EB36C9576F9ECB9
17 changed files with 35 additions and 106 deletions

View file

@ -3,17 +3,7 @@ var PHPCensor = {
intervals: {}, intervals: {},
init: function () { init: function () {
// Setup the date locale
moment.locale(LANGUAGE);
$(document).ready(function () { $(document).ready(function () {
// Format datetimes
$('time[datetime]').each(function() {
var thisDate = $(this).attr('datetime');
var formattedDate = moment(thisDate).format($(this).data('format') || 'lll');
$(this).text(formattedDate);
});
// Update latest builds every 5 seconds: // Update latest builds every 5 seconds:
PHPCensor.getBuilds(); PHPCensor.getBuilds();
PHPCensor.intervals.getBuilds = setInterval(PHPCensor.getBuilds, 5000); PHPCensor.intervals.getBuilds = setInterval(PHPCensor.getBuilds, 5000);
@ -27,8 +17,6 @@ var PHPCensor = {
PHPCensor.intervals.getDashboard = setInterval(PHPCensor.getDashboard, 10000); PHPCensor.intervals.getDashboard = setInterval(PHPCensor.getDashboard, 10000);
PHPCensor.intervals.getTimeline = setInterval(PHPCensor.getTimeline, 10000); PHPCensor.intervals.getTimeline = setInterval(PHPCensor.getTimeline, 10000);
} }
PHPCensor.uiUpdated();
}); });
$(window).on('builds-updated', function (e, data) { $(window).on('builds-updated', function (e, data) {
@ -123,7 +111,6 @@ var PHPCensor = {
success: function (data) { success: function (data) {
success(); success();
PHPCensor.uiUpdated();
}, },
error: PHPCensor.handleFailedAjax error: PHPCensor.handleFailedAjax
@ -134,28 +121,6 @@ var PHPCensor = {
if (xhr.status == 401) { if (xhr.status == 401) {
window.location.href = window.APP_URL + 'session/login'; window.location.href = window.APP_URL + 'session/login';
} }
},
uiUpdated: function () {
$('.duration').each(function () {
var seconds = $(this).data('duration');
if (seconds == 0) {
return;
}
$(this).text(moment.duration(seconds, 'seconds').humanize());
});
$('.datetime').each(function () {
var dateString = $(this).data('date');
if (!dateString) {
return;
}
$(this).text(moment(dateString).format('lll'));
});
} }
}; };
@ -506,5 +471,3 @@ var Lang = {
return string; return string;
} }
}; };
moment.locale(LANGUAGE);

View file

@ -1,6 +1,6 @@
var codeceptionPlugin = ActiveBuild.UiPlugin.extend({ var codeceptionPlugin = ActiveBuild.UiPlugin.extend({
id: 'build-codeception-errors', id: 'build-codeception-errors',
css: 'col-lg-12 col-md-12 col-sm-12 col-xs-12', css: 'col-xs-12',
title: Lang.get('codeception'), title: Lang.get('codeception'),
lastData: null, lastData: null,
lastMeta: null, lastMeta: null,

View file

@ -1,6 +1,6 @@
var phpspecPlugin = ActiveBuild.UiPlugin.extend({ var phpspecPlugin = ActiveBuild.UiPlugin.extend({
id: 'build-phpspec-errors', id: 'build-phpspec-errors',
css: 'col-lg-12 col-md-12 col-sm-12 col-xs-12', css: 'col-xs-12',
title: Lang.get('phpspec'), title: Lang.get('phpspec'),
lastData: null, lastData: null,
displayOnUpdate: false, displayOnUpdate: false,

View file

@ -1,6 +1,6 @@
var phptalPlugin = ActiveBuild.UiPlugin.extend({ var phptalPlugin = ActiveBuild.UiPlugin.extend({
id: 'build-phptal', id: 'build-phptal',
css: 'col-lg-6 col-md-12 col-sm-12 col-xs-12', css: 'col-xs-12',
title: 'PHPTAL Lint', title: 'PHPTAL Lint',
lastData: null, lastData: null,
box: true, box: true,
@ -25,9 +25,9 @@ var phptalPlugin = ActiveBuild.UiPlugin.extend({
return $('<div class="table-responsive"><table class="table" id="phptal-data">' + return $('<div class="table-responsive"><table class="table" id="phptal-data">' +
'<thead>' + '<thead>' +
'<tr>' + '<tr>' +
' <th>File</th>' + ' <th>' + Lang.get('file') + '</th>' +
' <th>Line</th>' + ' <th>' + Lang.get('line') + '</th>' +
' <th>Message</th>' + ' <th>' + Lang.get('message') + '</th>' +
'</tr>' + '</tr>' +
'</thead><tbody></tbody></table></div>'); '</thead><tbody></tbody></table></div>');
}, },

View file

@ -65,8 +65,6 @@ var Build = Class.extend({
} }
} }
PHPCensor.uiUpdated();
}); });
}, },
@ -179,7 +177,7 @@ var Build = Class.extend({
UiPlugin: Class.extend({ UiPlugin: Class.extend({
id: null, id: null,
css: 'col-lg-4 col-md-6 col-sm-12 col-xs-12', css: 'col-xs-12',
box: false, box: false,
init: function(){ init: function(){

View file

@ -237,10 +237,12 @@ class BuildController extends Controller
if (!$build) { if (!$build) {
$response->setResponseCode(404); $response->setResponseCode(404);
$response->setContent([]); $response->setContent([]);
return $response; return $response;
} }
$response->setContent($this->getBuildData($build)); $response->setContent($this->getBuildData($build));
return $response; return $response;
} }
@ -257,6 +259,7 @@ class BuildController extends Controller
$response = new JsonResponse(); $response = new JsonResponse();
$response->setContent($data); $response->setContent($data);
return $response; return $response;
} }

View file

@ -194,24 +194,4 @@ class Lang
} }
} }
} }
/**
* Create a time tag for localization.
*
* See http://momentjs.com/docs/#/displaying/format/ for a list of supported formats.
*
* @param \DateTime $dateTime The dateTime to represent.
* @param string $format The moment.js format to use.
*
* @return string The formatted tag.
*/
public static function formatDateTime(\DateTime $dateTime, $format = 'lll')
{
return sprintf(
'<time datetime="%s" data-format="%s">%s</time>',
$dateTime->format(\DateTime::ISO8601),
$format,
$dateTime->format(\DateTime::RFC2822)
);
}
} }

View file

@ -213,7 +213,8 @@ PHP Censor',
'codeception_time' => 'Time', 'codeception_time' => 'Time',
'codeception_synopsis' => '<strong>%1$d</strong> tests carried out in <strong>%2$f</strong> seconds. 'codeception_synopsis' => '<strong>%1$d</strong> tests carried out in <strong>%2$f</strong> seconds.
<strong>%3$d</strong> failures.', <strong>%3$d</strong> failures.',
'suite' => 'Suite',
'test' => 'Test',
'file' => 'File', 'file' => 'File',
'line' => 'Line', 'line' => 'Line',
'class' => 'Class', 'class' => 'Class',

View file

@ -204,6 +204,8 @@ PHP Censor',
'codeception_time' => 'Время', 'codeception_time' => 'Время',
'codeception_synopsis' => 'Тестов выполнено: <strong>%1$d</strong> (за <strong>%2$f</strong> сек.). Провалов: <strong>%3$d</strong>.', 'codeception_synopsis' => 'Тестов выполнено: <strong>%1$d</strong> (за <strong>%2$f</strong> сек.). Провалов: <strong>%3$d</strong>.',
'suite' => 'Набор',
'test' => 'Тест',
'file' => 'Файл', 'file' => 'Файл',
'line' => 'Строка', 'line' => 'Строка',
'class' => 'Класс', 'class' => 'Класс',

View file

@ -32,8 +32,8 @@
<tr> <tr>
<th><?php Lang::out('duration'); ?></th> <th><?php Lang::out('duration'); ?></th>
<td style="text-align: right" class="build-duration duration" data-duration="<?php print $build->getDuration(); ?>"> <td style="text-align: right" class="build-duration duration">
<?php print $build->getDuration(); ?> <?= Lang::get('seconds'); ?>
</td> </td>
</tr> </tr>
</table> </table>
@ -89,20 +89,22 @@
<table class="table"> <table class="table">
<tr> <tr>
<th><?php Lang::out('created'); ?></th> <th><?php Lang::out('created'); ?></th>
<td style="text-align: right" class="build-created datetime" data-date="<?php print $build->getCreated() ? $build->getCreated()->format('Y-m-d H:i:s') : ''; ?>"> <td style="text-align: right" class="build-created datetime">
<?php print $build->getCreated() ? $build->getCreated()->format('Y-m-d H:i:s') : ''; ?>
</td> </td>
</tr> </tr>
<tr> <tr>
<th><?php Lang::out('started'); ?></th> <th><?php Lang::out('started'); ?></th>
<td style="text-align: right" class="build-started datetime" data-date="<?php print $build->getStarted() ? $build->getStarted()->format('Y-m-d H:i:s') : ''; ?>"> <td style="text-align: right" class="build-started datetime">
<?php print $build->getStarted() ? $build->getStarted()->format('Y-m-d H:i:s') : ''; ?>
</td> </td>
</tr> </tr>
<tr> <tr>
<th><?php Lang::out('finished'); ?></th> <th><?php Lang::out('finished'); ?></th>
<td style="text-align: right" class="build-finished datetime" data-date="<?php print $build->getFinished() ? $build->getFinished()->format('Y-m-d H:i:s') : ''; ?>"> <td style="text-align: right" class="build-finished datetime">
<?php print $build->getFinished() ? $build->getFinished()->format('Y-m-d H:i:s') : ''; ?>
</td> </td>
</tr> </tr>
</table> </table>
@ -170,7 +172,7 @@
<?php <?php
foreach ($plugins as $plugin) { foreach ($plugins as $plugin) {
print '<script src="'.APP_URL.'assets/js/build-plugins/' . $plugin . '"></script>' . PHP_EOL; print '<script src="' . APP_URL . 'assets/js/build-plugins/' . $plugin . '"></script>' . PHP_EOL;
} }
?> ?>

View file

@ -18,7 +18,6 @@
<script src="<?php print APP_URL; ?>assets/vendor/admin-lte/plugins/jQuery/jquery-2.2.3.min.js"></script> <script src="<?php print APP_URL; ?>assets/vendor/admin-lte/plugins/jQuery/jquery-2.2.3.min.js"></script>
<script src="<?php print APP_URL; ?>assets/js/class.js"></script> <script src="<?php print APP_URL; ?>assets/js/class.js"></script>
<script src="<?php print APP_URL; ?>assets/vendor/sprintf-js/dist/sprintf.min.js"></script> <script src="<?php print APP_URL; ?>assets/vendor/sprintf-js/dist/sprintf.min.js"></script>
<script src="<?php print APP_URL; ?>assets/vendor/moment/min/moment-with-locales.min.js"></script>
<script src="<?php print APP_URL; ?>assets/js/app.js" type="text/javascript"></script> <script src="<?php print APP_URL; ?>assets/js/app.js" type="text/javascript"></script>
</head> </head>
<body class="hold-transition skin-black layout-top-nav"> <body class="hold-transition skin-black layout-top-nav">

View file

@ -39,12 +39,12 @@ if (count($builds)) {
break; break;
case 2: case 2:
$statuses[] = 'ok'; $statuses[] = 'ok';
$success = is_null($success) && !is_null($build->getFinished()) ? Lang::formatDateTime($build->getFinished()) : $success; $success = is_null($success) && !is_null($build->getFinished()) ? $build->getFinished()->format('Y-m-d H:i:s') : $success;
break; break;
case 3: case 3:
$failures++; $failures++;
$statuses[] = 'failed'; $statuses[] = 'failed';
$failure = is_null($failure) && !is_null($build->getFinished()) ? Lang::formatDateTime($build->getFinished()) : $failure; $failure = is_null($failure) && !is_null($build->getFinished()) ? $build->getFinished()->format('Y-m-d H:i:s') : $failure;
break; break;
} }
} }
@ -62,7 +62,7 @@ if ($buildCount > 0) {
$message = Lang::get('x_of_x_failed', $failures, $buildCount); $message = Lang::get('x_of_x_failed', $failures, $buildCount);
if (!is_null($lastSuccess) && !is_null($lastSuccess->getFinished())) { if (!is_null($lastSuccess) && !is_null($lastSuccess->getFinished())) {
$message .= Lang::get('last_successful_build', Lang::formatDateTime($lastSuccess->getFinished())); $message .= Lang::get('last_successful_build', $lastSuccess->getFinished()->format('Y-m-d H:i:s'));
} else { } else {
$message .= Lang::get('never_built_successfully'); $message .= Lang::get('never_built_successfully');
} }
@ -71,7 +71,7 @@ if ($buildCount > 0) {
$shortMessage = Lang::get('all_builds_passed_short', $buildCount, $buildCount); $shortMessage = Lang::get('all_builds_passed_short', $buildCount, $buildCount);
if (!is_null($lastFailure) && !is_null($lastFailure->getFinished())) { if (!is_null($lastFailure) && !is_null($lastFailure->getFinished())) {
$message .= Lang::get('last_failed_build', Lang::formatDateTime($lastFailure->getFinished())); $message .= Lang::get('last_failed_build', $lastFailure->getFinished()->format('Y-m-d H:i:s'));
} else { } else {
$message .= Lang::get('never_failed_build'); $message .= Lang::get('never_failed_build');
} }

View file

@ -38,7 +38,7 @@
?> ?>
<li class="time-label"> <li class="time-label">
<span class="bg-gray"> <span class="bg-gray">
<?php print Lang::formatDateTime($last, 'll'); ?> <?= $last->format('Y-m-d'); ?>
</span> </span>
</li> </li>
<?php endif; ?> <?php endif; ?>
@ -48,7 +48,7 @@
<li> <li>
<i class="fa fa-<?php print $build->getProject()->getIcon(); ?> bg-<?php print $color; ?>"></i> <i class="fa fa-<?php print $build->getProject()->getIcon(); ?> bg-<?php print $color; ?>"></i>
<div class="timeline-item"> <div class="timeline-item">
<span class="time"><i class="fa fa-clock-o"></i> <?php print Lang::formatDateTime($updated, 'LT'); ?></span> <span class="time"><i class="fa fa-clock-o"></i> <?= $updated->format('H:i:s'); ?></span>
<h3 class="timeline-header"> <h3 class="timeline-header">
<a href="<?php print APP_URL; ?>project/view/<?php print $build->getProjectId(); ?>"> <a href="<?php print APP_URL; ?>project/view/<?php print $build->getProjectId(); ?>">
<?php print $build->getProject()->getTitle(); ?> <?php print $build->getProject()->getTitle(); ?>

View file

@ -40,12 +40,12 @@ foreach($projects as $project):
break; break;
case 2: case 2:
$statuses[] = 'ok'; $statuses[] = 'ok';
$success = is_null($success) && !is_null($build->getFinished()) ? Lang::formatDateTime($build->getFinished()) : $success; $success = is_null($success) && !is_null($build->getFinished()) ? $build->getFinished()->format('Y-m-d H:i:s') : $success;
break; break;
case 3: case 3:
$failures++; $failures++;
$statuses[] = 'failed'; $statuses[] = 'failed';
$failure = is_null($failure) && !is_null($build->getFinished()) ? Lang::formatDateTime($build->getFinished()) : $failure; $failure = is_null($failure) && !is_null($build->getFinished()) ? $build->getFinished()->format('Y-m-d H:i:s') : $failure;
break; break;
} }
} }
@ -63,7 +63,7 @@ foreach($projects as $project):
$message = Lang::get('x_of_x_failed', $failures, $buildCount); $message = Lang::get('x_of_x_failed', $failures, $buildCount);
if (!is_null($lastSuccess) && !is_null($lastSuccess->getFinished())) { if (!is_null($lastSuccess) && !is_null($lastSuccess->getFinished())) {
$message .= Lang::get('last_successful_build', Lang::formatDateTime($lastSuccess->getFinished())); $message .= Lang::get('last_successful_build', $lastSuccess->getFinished()->format('Y-m-d H:i:s'));
} else { } else {
$message .= Lang::get('never_built_successfully'); $message .= Lang::get('never_built_successfully');
} }
@ -72,7 +72,7 @@ foreach($projects as $project):
$shortMessage = Lang::get('all_builds_passed_short', $buildCount, $buildCount); $shortMessage = Lang::get('all_builds_passed_short', $buildCount, $buildCount);
if (!is_null($lastFailure) && !is_null($lastFailure->getFinished())) { if (!is_null($lastFailure) && !is_null($lastFailure->getFinished())) {
$message .= Lang::get('last_failed_build', Lang::formatDateTime($lastFailure->getFinished())); $message .= Lang::get('last_failed_build', $lastFailure->getFinished()->format('Y-m-d H:i:s'));
} else { } else {
$message .= Lang::get('never_failed_build'); $message .= Lang::get('never_failed_build');
} }

View file

@ -64,7 +64,7 @@
?> ?>
<li class="time-label"> <li class="time-label">
<span class="bg-gray"> <span class="bg-gray">
<?php print Lang::formatDateTime($last, 'll'); ?> <?= $last->format('Y-m-d'); ?>
</span> </span>
</li> </li>
<?php endif; ?> <?php endif; ?>
@ -74,7 +74,7 @@
<li> <li>
<i class="fa fa-<?php print $build->getProject()->getIcon(); ?> bg-<?php print $color; ?>"></i> <i class="fa fa-<?php print $build->getProject()->getIcon(); ?> bg-<?php print $color; ?>"></i>
<div class="timeline-item"> <div class="timeline-item">
<span class="time"><i class="fa fa-clock-o"></i> <?php print Lang::formatDateTime($updated, 'LT'); ?></span> <span class="time"><i class="fa fa-clock-o"></i> <?= $updated->format('H:i:s'); ?></span>
<h3 class="timeline-header"> <h3 class="timeline-header">
<a href="<?php print APP_URL; ?>project/view/<?php print $build->getProjectId(); ?>"> <a href="<?php print APP_URL; ?>project/view/<?php print $build->getProjectId(); ?>">
<?php print $build->getProject()->getTitle(); ?> <?php print $build->getProject()->getTitle(); ?>

View file

@ -30,7 +30,6 @@
<script src="<?php print APP_URL; ?>assets/vendor/admin-lte/plugins/jQuery/jquery-2.2.3.min.js"></script> <script src="<?php print APP_URL; ?>assets/vendor/admin-lte/plugins/jQuery/jquery-2.2.3.min.js"></script>
<script src="<?php print APP_URL; ?>assets/js/class.js"></script> <script src="<?php print APP_URL; ?>assets/js/class.js"></script>
<script src="<?php print APP_URL; ?>assets/vendor/sprintf-js/dist/sprintf.min.js"></script> <script src="<?php print APP_URL; ?>assets/vendor/sprintf-js/dist/sprintf.min.js"></script>
<script src="<?php print APP_URL; ?>assets/vendor/moment/min/moment-with-locales.min.js"></script>
<script src="<?php print APP_URL; ?>assets/js/app.js" type="text/javascript"></script> <script src="<?php print APP_URL; ?>assets/js/app.js" type="text/javascript"></script>
</head> </head>

View file

@ -16,24 +16,6 @@ use Tests\PHPCensor\LocalizationTestCase;
class LangTest extends LocalizationTestCase class LangTest extends LocalizationTestCase
{ {
public function testLang_UsePassedParameters()
{
$dateTime = $this->prophesize('DateTime');
$dateTime->format(DateTime::ISO8601)->willReturn("ISODATE");
$dateTime->format(DateTime::RFC2822)->willReturn("RFCDATE");
$this->assertEquals('<time datetime="ISODATE" data-format="FORMAT">RFCDATE</time>', Lang::formatDateTime($dateTime->reveal(), 'FORMAT'));
}
public function testLang_UseDefaultFormat()
{
$dateTime = $this->prophesize('DateTime');
$dateTime->format(DateTime::ISO8601)->willReturn("ISODATE");
$dateTime->format(DateTime::RFC2822)->willReturn("RFCDATE");
$this->assertEquals('<time datetime="ISODATE" data-format="lll">RFCDATE</time>', Lang::formatDateTime($dateTime->reveal()));
}
/** /**
* @return array * @return array
*/ */