Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Platform
Commits
dec0d481
Commit
dec0d481
authored
Aug 04, 2017
by
Mehedi Hassan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make TranslationController slim
parent
f06b6a2d
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
99 additions
and
64 deletions
+99
-64
TranslationController.php
...ranslation/Http/Controllers/Api/TranslationController.php
+9
-64
translations.php
...ranslation/Resources/lang/translation/en/translations.php
+1
-0
revision.blade.php
...rces/views/admin/translations/partials/revision.blade.php
+29
-0
TranslationRevisions.php
Modules/Translation/Services/TranslationRevisions.php
+60
-0
No files found.
Modules/Translation/Http/Controllers/Api/TranslationController.php
View file @
dec0d481
...
...
@@ -2,12 +2,13 @@
namespace
Modules\Translation\Http\Controllers\Api
;
use
Cartalyst\Sentinel\Laravel\Facades\Sentinel
;
use
Illuminate\Database\Eloquent\Collection
;
use
Illuminate\Http\Request
;
use
Illuminate\Routing\Controller
;
use
Modules\Translation\Repositories\TranslationRepository
;
use
Illuminate\Database\Eloquent\Collection
;
use
Cartalyst\Sentinel\Laravel\Facades\Sentinel
;
use
Modules\User\Traits\CanFindUserWithBearerToken
;
use
Modules\Translation\Services\TranslationRevisions
;
use
Modules\Translation\Repositories\TranslationRepository
;
class
TranslationController
extends
Controller
{
...
...
@@ -38,67 +39,11 @@ class TranslationController extends Controller
$this
->
translation
->
clearCache
();
}
public
function
revisions
(
Request
$request
)
{
$translation
=
$this
->
translation
->
findTranslationByKey
(
$request
->
get
(
'key'
));
$translation
=
$translation
->
translate
(
$request
->
get
(
'locale'
));
if
(
null
===
$translation
)
{
return
response
()
->
json
([
'<tr><td>'
.
trans
(
'translation::translations.No Revisions yet'
)
.
'</td></tr>'
]);
}
return
response
()
->
json
(
$this
->
formatRevisionHistory
(
$translation
->
revisionHistory
));
}
private
function
formatRevisionHistory
(
Collection
$revisionHistory
)
{
$formattedHistory
=
[];
foreach
(
$revisionHistory
as
$history
)
{
if
(
$history
->
key
==
'created_at'
&&
!
$history
->
old_value
)
{
$formattedHistory
[]
=
$this
->
getCreatedRevisionTemplate
(
$history
);
}
else
{
$formattedHistory
[]
=
$this
->
getRevisionTemplate
(
$history
);
}
}
return
array_reverse
(
$formattedHistory
);
}
private
function
getRevisionTemplate
(
$history
)
public
function
revisions
(
TranslationRevisions
$revisions
,
Request
$request
)
{
$timeAgo
=
$history
->
created_at
->
diffForHumans
();
$revertRoute
=
route
(
'admin.translation.translation.update'
,
[
$history
->
revisionable_id
,
'oldValue'
=>
$history
->
oldValue
()]);
$edited
=
trans
(
'translation::translations.edited'
);
$firstName
=
$history
->
userResponsible
()
?
$history
->
userResponsible
()
->
first_name
:
''
;
$lastName
=
$history
->
userResponsible
()
?
$history
->
userResponsible
()
->
last_name
:
''
;
return
<<<HTML
<tr>
<td>{$history->oldValue()}</td>
<td>{$firstName} {$lastName}</td>
<td>$edited</td>
<td><a data-toggle="tooltip" title="{$history->created_at}">{$timeAgo}</a></td>
<td><a href="{$revertRoute}"><i class="fa fa-history"></i></a></td>
</tr>
HTML;
}
private
function
getCreatedRevisionTemplate
(
$history
)
{
$timeAgo
=
$history
->
created_at
->
diffForHumans
();
$created
=
trans
(
'translation::translations.created'
);
$firstName
=
$history
->
userResponsible
()
?
$history
->
userResponsible
()
->
first_name
:
''
;
$lastName
=
$history
->
userResponsible
()
?
$history
->
userResponsible
()
->
last_name
:
''
;
return
<<<HTML
<tr>
<td></td>
<td>{$firstName} {$lastName}</td>
<td>$created</td>
<td><a data-toggle="tooltip" title="{$history->created_at}">{$timeAgo}</a></td>
<td></td>
</tr>
HTML;
return
$revisions
->
get
(
$request
->
get
(
'key'
),
$request
->
get
(
'locale'
)
);
}
}
Modules/Translation/Resources/lang/translation/en/translations.php
View file @
dec0d481
...
...
@@ -32,6 +32,7 @@ return [
'event'
=>
'Event'
,
'created'
=>
'Created'
,
'edited'
=>
'Edited'
,
'revert history'
=>
'Revert History'
,
'list resource'
=>
'List translations'
,
'edit resource'
=>
'Edit translations'
,
'import resource'
=>
'Import translations'
,
...
...
Modules/Translation/Resources/views/admin/translations/partials/revision.blade.php
0 → 100644
View file @
dec0d481
<tr>
<td>
@if ($history->oldValue() !== null)
{{ $history->oldValue() }}
@endif
</td>
<td>
{{ $history->userResponsible()->present()->fullname() }}
</td>
<td>
@if ($history->oldValue() === null)
{{ trans('translation::translations.created') }}
@else
{{ trans('translation::translations.edited') }}
@endif
</td>
<td>
<span
data-toggle=
"tooltip"
title=
"{{ $history->created_at }}"
>
{{ $history->created_at->diffForHumans() }}
</span>
</td>
<td>
@if ($history->oldValue() !== null)
<span
data-toggle=
"tooltip"
title=
"{{ trans('translation::translations.revert history') }}"
>
<a
href=
"{{ route('admin.translation.translation.update', [$history->revisionable_id, 'oldValue' => $history->oldValue()]) }}"
>
<i
class=
"fa fa-history"
></i>
</a>
</span>
@endif
</td>
</tr>
Modules/Translation/Services/TranslationRevisions.php
0 → 100644
View file @
dec0d481
<?php
namespace
Modules\Translation\Services
;
use
Illuminate\Database\Eloquent\Collection
;
use
Modules\Translation\Repositories\TranslationRepository
;
class
TranslationRevisions
{
/**
* @var TranslationRepository
*/
private
$translation
;
/**
* @param TranslationRepository $translation
*/
public
function
__construct
(
TranslationRepository
$translation
)
{
$this
->
translation
=
$translation
;
}
/**
* Get revisions for the given key and locale.
*
* @param string $key
* @param string $locale
* @return \Illuminate\Http\JsonResponse
*/
public
function
get
(
$key
,
$locale
)
{
$translation
=
$this
->
translation
->
findTranslationByKey
(
$key
);
$translation
=
$translation
->
translate
(
$locale
);
if
(
$translation
===
null
)
{
return
response
()
->
json
([
'<tr><td>'
.
trans
(
'translation::translations.No Revisions yet'
)
.
'</td></tr>'
]);
}
return
response
()
->
json
(
$this
->
formatRevisionHistory
(
$translation
->
revisionHistory
->
reverse
()
)
);
}
/**
* Format revision history.
*
* @param Collection $revisionHistory
* @return array
*/
private
function
formatRevisionHistory
(
Collection
$revisionHistory
)
{
return
$revisionHistory
->
reduce
(
function
(
$formattedHistory
,
$history
)
{
$formattedHistory
[]
=
view
(
'translation::admin.translations.partials.revision'
,
compact
(
'history'
))
->
render
();
return
$formattedHistory
;
});
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment