From 84c3b6db953208ccaf94c02a8a21108e6b017fa4 Mon Sep 17 00:00:00 2001 From: Dominik Hebeler <dominik@suma-ev.de> Date: Tue, 16 Mar 2021 12:09:13 +0100 Subject: [PATCH] added countdown to next change --- app/Http/Controllers/KeyController.php | 6 ++++++ app/Models/Key.php | 5 +++-- resources/lang/de/key.php | 1 + resources/lang/en/key.php | 1 + resources/views/key.blade.php | 10 ++++++++-- 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/KeyController.php b/app/Http/Controllers/KeyController.php index a62d24942..f75d54971 100644 --- a/app/Http/Controllers/KeyController.php +++ b/app/Http/Controllers/KeyController.php @@ -17,10 +17,16 @@ class KeyController extends Controller public function index(\App\Models\Key $key, Request $request) { $cookieLink = LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), route('loadSettings', Cookie::get())); + $key->canChange(); + $changedAt = $key->keyinfo->KeyChangedAt; + if(!empty($changedAt)){ + $changedAt = new Carbon($changedAt); + } return view('key') ->with('title', trans('titles.key')) ->with('keystatus', $key->getStatus()) ->with('cookie', $key->key) + ->with('changedAt', $changedAt) ->with('cookieLink', $cookieLink); } diff --git a/app/Models/Key.php b/app/Models/Key.php index f078b3e56..e1fb7f3d2 100644 --- a/app/Models/Key.php +++ b/app/Models/Key.php @@ -11,7 +11,8 @@ class Key public $key; public $status; # Null If Key invalid | false if valid but has no adFreeSearches | true if valid and has adFreeSearches private $keyserver = "https://key.metager.de/"; - private $keyinfo; + public $keyinfo; + const CHANGE_EVERY = 1 * 24 * 60 * 60; public function __construct($key, $status = null) { @@ -200,7 +201,7 @@ class Key if(!empty($this->keyinfo->KeyChangedAt)){ // "2021-03-09T09:19:44.000Z" $keyChangedAt = Carbon::createFromTimeString($this->keyinfo->KeyChangedAt, 'Europe/London'); - if($keyChangedAt->diffInSeconds(Carbon::now()) > (2 * 24 * 60 * 60)){ + if($keyChangedAt->diffInSeconds(Carbon::now()) > self::CHANGE_EVERY){ return true; }else{ return false; diff --git a/resources/lang/de/key.php b/resources/lang/de/key.php index 3c8076ed4..494d46a8f 100644 --- a/resources/lang/de/key.php +++ b/resources/lang/de/key.php @@ -16,5 +16,6 @@ return [ 'backLink' => 'Zurück zur letzten Seite', 'custom.h3' => 'Wunsch-Schlüssel', 'custom.p1' => 'Mitglieder des SUMA-EV haben die Möglichkeit, sich einen eigenen Schlüssel auszusuchen.', + 'custom.p2' => 'Der nächste Wechsel Ihres Schlüssels ist in :nextchange möglich.', 'custom.a1' => 'Wunsch Schlüssel einrichten' ]; diff --git a/resources/lang/en/key.php b/resources/lang/en/key.php index 663e31900..299c18da2 100644 --- a/resources/lang/en/key.php +++ b/resources/lang/en/key.php @@ -16,5 +16,6 @@ return [ "backLink" => "Back to the last page", "custom.h3" => "Favorite Key", "custom.p1" => "Members of the SUMA-EV have the opportunity to choose their own key.", + 'custom.p2' => 'The next change of your key is possible in :nextchange.', "custom.a1" => "Set up the favorite key" ]; diff --git a/resources/views/key.blade.php b/resources/views/key.blade.php index 7edb1652b..dc10430c5 100644 --- a/resources/views/key.blade.php +++ b/resources/views/key.blade.php @@ -40,13 +40,19 @@ </ol> @endif </div> - @if(app('App\Models\Key')->canChange()) + <div class="section"> <h3>@lang('key.custom.h3')</h3> <p>@lang('key.custom.p1')</p> + @if(app('App\Models\Key')->canChange()) <a class="btn btn-default" href="{{ LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), route('changeKeyOne')) }}">@lang('key.custom.a1')</a> + @elseif(!empty($changedAt)) + <p>@lang('key.custom.p2', [ + 'nextchange' => trim(str_replace(" später", "", $changedAt->addSeconds(\App\Models\Key::CHANGE_EVERY)->longRelativeDiffForHumans(Carbon::now("Europe/London"), 2))) + ])</p> + @endif </div> - @endif + <div class="section"> @if(isset($keystatus) && $keystatus === false) <p class="error">@lang('key.empty')</p> -- GitLab