Skip to content

Commit

Permalink
added new bundle option instead of testing env == dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Cédric Girard committed Aug 7, 2015
1 parent 79b1432 commit 568183e
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 20 deletions.
5 changes: 4 additions & 1 deletion DependencyInjection/LexikTranslationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ protected function buildDevServicesDefinition(ContainerBuilder $container)

$tokenFinderDefinition = new Definition();
$tokenFinderDefinition->setClass(new Parameter('lexik_translation.token_finder.class'));
$tokenFinderDefinition->setArguments(array(new Reference('profiler')));
$tokenFinderDefinition->setArguments(array(
new Reference('profiler'),
new Parameter('lexik_translation.token_finder.limit'),
));

$container->setDefinition('lexik_translation.token_finder', $tokenFinderDefinition);
}
Expand Down
1 change: 1 addition & 0 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<parameter key="lexik_translation.token_finder.class">Lexik\Bundle\TranslationBundle\Util\Profiler\TokenFinder</parameter>

<parameter key="lexik_translation.importer.case_insensitive">false</parameter>
<parameter key="lexik_translation.token_finder.limit">15</parameter>
</parameters>

<services>
Expand Down
26 changes: 21 additions & 5 deletions Resources/public/js/translation.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ app.factory('translationApiManager', ['$http', function ($http) {
parameters['page'] = params.page();
parameters['rows'] = params.count();

var url = this.token ? translationCfg.url.listByToken.replace('-token-', this.token) : translationCfg.url.list;
var url = (null != this.token) ? translationCfg.url.listByToken.replace('-token-', this.token) : translationCfg.url.list;

return $http.get(url, {'params': parameters});
},
Expand Down Expand Up @@ -150,7 +150,7 @@ app.controller('TranslationController', [
}
};

// go the top of the grid on page change
// go to the top of the grid on page change
$scope.changePage = function (pageNumber) {
$scope.tableParams.page(pageNumber);
$location.hash('translation-grid');
Expand Down Expand Up @@ -184,16 +184,32 @@ app.controller('TranslationController', [
// toggle all columns
$scope.toggleAllColumns = function () {
$scope.areAllColumnsSelected = !$scope.areAllColumnsSelected;
angular.forEach($scope.columns, function(column){
angular.forEach($scope.columns, function(column) {
column.visible = $scope.areAllColumnsSelected;
});
};

// set the translations source
$scope.changeSource = function (selectedToken) {
// use the given profile token as translations source
$scope.changeToken = function (selectedToken) {
translationApiManager.setToken(selectedToken);
$scope.tableParams.reload();
};

$scope.resetSource = function () {
$scope.selectedToken = null;
translationApiManager.setToken($scope.selectedToken);
$scope.tableParams.reload();
};

$scope.useTokenAsSource = function () {
if ($scope.profilerTokens.length) {
$scope.selectedToken = $scope.profilerTokens[0].token;
translationApiManager.setToken($scope.selectedToken);
$scope.tableParams.reload();
} else {
$scope.selectedToken = '';
}
};
}]);

/**
Expand Down
33 changes: 24 additions & 9 deletions Resources/views/Translation/_ngGrid.html.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
{# Raw block to display the AngularJS template #}
{% verbatim %}
<div id="translation-grid" ng-app="translationApp" ng-controller="TranslationController">
<div class="row" ng-if="profilerTokens != null">
<div class="col-md-2">
<label>{{ labels.dataSource }}:&nbsp;</label>
<div class="btn-group" role="group">
<button type="button" class="btn" ng-class="{'btn-info': (null == selectedToken), 'btn-default': (null != selectedToken)}" ng-click="resetSource()">
{{ labels.allTranslations }}
</button>
<button type="button" class="btn" ng-class="{'btn-info': (null != selectedToken), 'btn-default': (null == selectedToken)}" ng-click="useTokenAsSource()">
{{ labels.profiler }}
</button>
</div>
</div>
<div class="col-md-5" ng-show="selectedToken != null">
<label>{{ labels.latestProfiles }}:&nbsp;</label>
<select ng-model="selectedToken" ng-change="changeToken(selectedToken)" ng-options="p.token as p.token+' - '+p.url for p in profilerTokens" class="form-control"></select>
</div>
<div class="col-md-2" ng-show="selectedToken != null">
<label>{{ labels.profile }}:&nbsp;</label>
<input type="text" ng-model="selectedToken" ng-change="changeToken(selectedToken)" class="form-control" />
</div>
</div>

<hr ng-if="profilerTokens != null" />

<div class="row margin-row grid-action-bar">
<div class="col-md-12">
<a ng-click="hideColSelector = !hideColSelector" class="btn btn-default btn-sm btn-manage-col">
Expand All @@ -19,15 +43,6 @@
</div>
</div>
</div>
<div class="row" ng-if="profilerTokens.length">
<div class="col-md-5">
<form>
<select ng-model="selectedToken" ng-change="changeSource(selectedToken)" ng-options="p.token as p.token for p in profilerTokens" class="form-control">
<option value="">{{ labels.allTranslations }}</option>
</select>
</form>
</div>
</div>

<div ng-show="hideColSelector" class="row">
<div class="col-md-12">
Expand Down
6 changes: 5 additions & 1 deletion Resources/views/Translation/grid.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
locales: {{ locales | json_encode | raw }},
inputType: '{{ inputType }}',
autoCacheClean: {{ autoCacheClean ? 'true' : 'false' }},
profilerTokens: {{ tokens | json_encode | raw }},
profilerTokens: {{ tokens is not null ? (tokens | json_encode | raw) : 'null' }},
toggleSimilar: '{{ toggleSimilar }}',
url: {
list: '{{ path('lexik_translation_list') }}',
Expand All @@ -51,6 +51,10 @@
toggleAllCol: '{{ 'translations.toggle_all_columns'|trans }}',
invalidateCache: '{{ 'translations.invalidate_cache'|trans }}',
allTranslations: '{{ 'translations.all_translations'|trans }}',
profiler: '{{ 'translations.profiler'|trans }}',
dataSource: '{{ 'translations.data_source'|trans }}',
latestProfiles: '{{ 'translations.latest_profiles'|trans }}',
profile: '{{ 'translations.profile'|trans }}',
saveRow: '{{ 'translations.save_row'|trans }}',
domain: '{{ 'translations.domain'|trans }}',
key: '{{ 'translations.key'|trans }}',
Expand Down
2 changes: 1 addition & 1 deletion Util/DataGrid/DataGridRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function getPage(Request $request)
public function getByToken($token)
{
if (null === $this->profiler) {
throw new \RuntimeException('This feature is only enable in DEV environment.');
throw new \RuntimeException('Invalid profiler instance.');
}

$profile = $this->profiler->loadProfile($token);
Expand Down
12 changes: 9 additions & 3 deletions Util/Profiler/TokenFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,19 @@ class TokenFinder
*/
private $profiler;

/**
* @var int
*/
private $defaultLimit;

/**
* @param Profiler $profiler
* @param int $defaultLimit
*/
public function __construct(Profiler $profiler)
public function __construct(Profiler $profiler, $defaultLimit)
{
$this->profiler = $profiler;
$this->defaultLimit = $defaultLimit;
}

/**
Expand All @@ -33,8 +40,7 @@ public function __construct(Profiler $profiler)
*/
public function find($ip = null, $url = null, $limit = null, $method = null, $start = null, $end = null)
{
$limit = $limit ?: 10;
$method = $method ?: 'GET';
$limit = $limit ?: $this->defaultLimit;

return $this->profiler->find($ip, $url, $limit, $method, $start, $end);
}
Expand Down

0 comments on commit 568183e

Please sign in to comment.