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: {},
init: function () {
// Setup the date locale
moment.locale(LANGUAGE);
$(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:
PHPCensor.getBuilds();
PHPCensor.intervals.getBuilds = setInterval(PHPCensor.getBuilds, 5000);
@ -27,8 +17,6 @@ var PHPCensor = {
PHPCensor.intervals.getDashboard = setInterval(PHPCensor.getDashboard, 10000);
PHPCensor.intervals.getTimeline = setInterval(PHPCensor.getTimeline, 10000);
}
PHPCensor.uiUpdated();
});
$(window).on('builds-updated', function (e, data) {
@ -123,7 +111,6 @@ var PHPCensor = {
success: function (data) {
success();
PHPCensor.uiUpdated();
},
error: PHPCensor.handleFailedAjax
@ -134,28 +121,6 @@ var PHPCensor = {
if (xhr.status == 401) {
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;
}
};
moment.locale(LANGUAGE);

View file

@ -1,6 +1,6 @@
var codeceptionPlugin = ActiveBuild.UiPlugin.extend({
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'),
lastData: null,
lastMeta: null,

View file

@ -1,6 +1,6 @@
var phpspecPlugin = ActiveBuild.UiPlugin.extend({
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'),
lastData: null,
displayOnUpdate: false,

View file

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

View file

@ -237,10 +237,12 @@ class BuildController extends Controller
if (!$build) {
$response->setResponseCode(404);
$response->setContent([]);
return $response;
}
$response->setContent($this->getBuildData($build));
return $response;
}
@ -257,6 +259,7 @@ class BuildController extends Controller
$response = new JsonResponse();
$response->setContent($data);
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_synopsis' => '<strong>%1$d</strong> tests carried out in <strong>%2$f</strong> seconds.
<strong>%3$d</strong> failures.',
'suite' => 'Suite',
'test' => 'Test',
'file' => 'File',
'line' => 'Line',
'class' => 'Class',

View file

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

View file

@ -32,8 +32,8 @@
<tr>
<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>
</tr>
</table>
@ -89,20 +89,22 @@
<table class="table">
<tr>
<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>
</tr>
<tr>
<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>
</tr>
<tr>
<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>
</tr>
</table>
@ -170,7 +172,7 @@
<?php
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/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/moment/min/moment-with-locales.min.js"></script>
<script src="<?php print APP_URL; ?>assets/js/app.js" type="text/javascript"></script>
</head>
<body class="hold-transition skin-black layout-top-nav">

View file

@ -39,12 +39,12 @@ if (count($builds)) {
break;
case 2:
$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;
case 3:
$failures++;
$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;
}
}
@ -62,7 +62,7 @@ if ($buildCount > 0) {
$message = Lang::get('x_of_x_failed', $failures, $buildCount);
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 {
$message .= Lang::get('never_built_successfully');
}
@ -71,7 +71,7 @@ if ($buildCount > 0) {
$shortMessage = Lang::get('all_builds_passed_short', $buildCount, $buildCount);
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 {
$message .= Lang::get('never_failed_build');
}

View file

@ -38,7 +38,7 @@
?>
<li class="time-label">
<span class="bg-gray">
<?php print Lang::formatDateTime($last, 'll'); ?>
<?= $last->format('Y-m-d'); ?>
</span>
</li>
<?php endif; ?>
@ -48,7 +48,7 @@
<li>
<i class="fa fa-<?php print $build->getProject()->getIcon(); ?> bg-<?php print $color; ?>"></i>
<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">
<a href="<?php print APP_URL; ?>project/view/<?php print $build->getProjectId(); ?>">
<?php print $build->getProject()->getTitle(); ?>

View file

@ -40,12 +40,12 @@ foreach($projects as $project):
break;
case 2:
$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;
case 3:
$failures++;
$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;
}
}
@ -63,7 +63,7 @@ foreach($projects as $project):
$message = Lang::get('x_of_x_failed', $failures, $buildCount);
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 {
$message .= Lang::get('never_built_successfully');
}
@ -72,7 +72,7 @@ foreach($projects as $project):
$shortMessage = Lang::get('all_builds_passed_short', $buildCount, $buildCount);
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 {
$message .= Lang::get('never_failed_build');
}

View file

@ -64,7 +64,7 @@
?>
<li class="time-label">
<span class="bg-gray">
<?php print Lang::formatDateTime($last, 'll'); ?>
<?= $last->format('Y-m-d'); ?>
</span>
</li>
<?php endif; ?>
@ -74,7 +74,7 @@
<li>
<i class="fa fa-<?php print $build->getProject()->getIcon(); ?> bg-<?php print $color; ?>"></i>
<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">
<a href="<?php print APP_URL; ?>project/view/<?php print $build->getProjectId(); ?>">
<?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/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/moment/min/moment-with-locales.min.js"></script>
<script src="<?php print APP_URL; ?>assets/js/app.js" type="text/javascript"></script>
</head>

View file

@ -16,24 +16,6 @@ use Tests\PHPCensor\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
*/