Skip to content

Commit 02ce648

Browse files
author
Mantas Jonušas
committed
Added translation history UI
1 parent 28f9d91 commit 02ce648

File tree

6 files changed

+136
-10
lines changed

6 files changed

+136
-10
lines changed

Resources/public/js/app-translations.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ angular
1313
'ngTagsInput',
1414
'controller.list',
1515
'controller.export',
16+
'controller.history',
1617
'directive.inline',
1718
'service.tag',
1819
'util.asset'
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* This file is part of the ONGR package.
3+
*
4+
* (c) NFQ Technologies UAB <info@nfq.com>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
angular
11+
.module('controller.history', [])
12+
.controller('history', ['$scope', '$modalInstance', '$http', 'STATUS', 'history',
13+
function ($scope, $modalInstance, $http, STATUS, history) {
14+
15+
/**
16+
* @type {Array}
17+
*/
18+
$scope.data = [];
19+
20+
/**
21+
* @type {object}
22+
*/
23+
var ladda = null;
24+
25+
setTimeout(function() {
26+
ladda = Ladda.create(document.querySelector('.ladda-button'));
27+
ladda.start();
28+
29+
$scope.$watch('data', function(newValue, oldValue) {
30+
newValue.length > 0 ? ladda.enable() : ladda.disable();
31+
});
32+
}, 50);
33+
34+
/**
35+
* Retrieves history though post http request.
36+
*
37+
* @returns {Promise}
38+
*/
39+
$scope.httpTranslations = function () {
40+
return $http.post(
41+
Routing.generate('ongr_translations_api_history'),
42+
{
43+
key: history[0],
44+
locale: history[1],
45+
domain: history[2]
46+
}
47+
)
48+
}
49+
50+
/**
51+
* Normalizes and sets translations into scope.
52+
*/
53+
$scope.getNormalizedTranslations = function() {
54+
$scope.httpTranslations()
55+
.success(function(data) {
56+
for (messageKey in data) {
57+
$scope.data.push(
58+
{
59+
message: data[messageKey].message,
60+
created_at: data[messageKey].created_at
61+
}
62+
);
63+
}
64+
});
65+
}
66+
67+
$scope.getNormalizedTranslations();
68+
69+
/**
70+
* Closes modal.
71+
*/
72+
$scope.close = function () {
73+
$modalInstance.dismiss('cancel');
74+
}
75+
}]);

Resources/public/js/directive/InlineDirective.js

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,18 @@
99

1010
angular
1111
.module('directive.inline', [])
12-
.directive('inline', ['$http', 'asset', 'STATUS', function ($http, $asset, STATUS) {
12+
.directive('inline', ['$http', 'asset', 'STATUS', '$modal',
13+
function ($http, $asset, STATUS, $modal) {
1314
return {
1415
restrict: "A",
15-
scope: {
16-
translation: "="
16+
scope: {
17+
translation: "="
1718
},
1819
templateUrl: $asset.getLink('template/inline.html'),
1920
link: function(scope, element, attr) {
2021

2122
var inputElement = angular.element(element[0].children[1].children[1])[0];
22-
23+
2324
element.addClass('inline-edit');
2425

2526
/**
@@ -39,18 +40,18 @@ angular
3940

4041
/**
4142
* Acts as empty value if it is null.
42-
*
43+
*
4344
* @returns {boolean}
4445
*/
4546
scope.tryActEmpty = function() {
4647
if (scope.message.message == null || scope.message.message == '') {
4748
scope.acting = true;
4849
scope.message.message = 'Empty field.';
4950
element.parent().addClass('bg-danger');
50-
51+
5152
return true;
5253
}
53-
54+
5455
return false;
5556
}
5657

@@ -71,7 +72,7 @@ angular
7172
if (scope.acting) {
7273
scope.message.message = '';
7374
}
74-
75+
7576
scope.oldValue = scope.message.message;
7677
element.addClass('active');
7778
inputElement.focus();
@@ -84,7 +85,7 @@ angular
8485
if (scope.error !== 0 || scope.error === null) {
8586
scope.message.message = scope.oldValue;
8687
}
87-
88+
8889
scope.error = null;
8990
element.removeClass('active');
9091
scope.tryActEmpty();
@@ -107,7 +108,7 @@ angular
107108

108109
/**
109110
* Validates translation message through http.
110-
*
111+
*
111112
* @returns {Promise}
112113
*/
113114
scope.httpValidate = function() {
@@ -161,6 +162,35 @@ angular
161162
break;
162163
}
163164
}
165+
166+
/**
167+
* Returns locale, key, domain of the message.
168+
*
169+
* @returns {*[]|*}
170+
*/
171+
scope.getMessageParams = function() {
172+
locale = scope.$parent.locale;
173+
key = scope.translation.key;
174+
domain = scope.translation.domain;
175+
arr = [key, locale, domain];
176+
177+
return arr
178+
};
179+
180+
/**
181+
* Opens up modal for history.
182+
*/
183+
scope.history = function() {
184+
$modal.open({
185+
controller: 'history',
186+
templateUrl: $asset.getLink('template/historyModal.html'),
187+
resolve: {
188+
history: function () {
189+
return scope.getMessageParams();
190+
}
191+
}
192+
});
193+
}
164194
}
165195
}
166196
}]);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<div class="modal-header">
2+
<h3 class="modal-title">History</h3>
3+
</div>
4+
<div class="modal-body">
5+
<table class="table">
6+
<tr>
7+
<th>Message</th>
8+
<th>Created at</th>
9+
</tr>
10+
<tr ng-repeat="translation in data">
11+
<td>{{ translation.message }}</td>
12+
<td>{{ translation.created_at | date : 'yyyy-MM-dd HH:mm:ss' }}</td>
13+
</tr>
14+
</table>
15+
</div>
16+
<div class="modal-footer">
17+
<button class="btn btn-warning ladda-button" data-size="xs" data-style="expand-right" ng-click="close()">Close</button>
18+
</div>

Resources/public/js/template/inline.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<span class="input-group-btn">
44
<button ng-click="save()" ng-class="error == null ? 'btn-default' : (error == 0 ? 'btn-success' : 'btn-danger')" class="btn"><i class="glyphicon glyphicon-ok"></i></button>
55
<button ng-click="close()" class="btn btn-default"><i class="glyphicon glyphicon-remove"></i></button>
6+
<button ng-click="history()" class="btn btn-default"><i class="glyphicon glyphicon-header"></i></button>
67
</span>
78
<input type="text" class="form-control" ng-model="message.message" ng-keydown="keyPress($event)"/>
89
</div>

Resources/views/List/list.html.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999

100100
<script src="{{ asset('bundles/ongrtranslations/js/controller/listController.js') }}"></script>
101101
<script src="{{ asset('bundles/ongrtranslations/js/controller/exportController.js') }}"></script>
102+
<script src="{{ asset('bundles/ongrtranslations/js/controller/historyController.js') }}"></script>
102103
<script src="{{ asset('bundles/ongrtranslations/js/directive/InlineDirective.js') }}"></script>
103104
<script src="{{ asset('bundles/ongrtranslations/js/service/TagService.js') }}"></script>
104105
<script src="{{ asset('bundles/ongrtranslations/js/utils/AssetService.js') }}"></script>

0 commit comments

Comments
 (0)