-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mehedi Hassan
authored and
Mehedi Hassan
committed
Aug 3, 2017
1 parent
f06b6a2
commit dec0d48
Showing
4 changed files
with
99 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
Modules/Translation/Resources/views/admin/translations/partials/revision.blade.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?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; | ||
}); | ||
} | ||
} |