From 9fba7a05c1aba4b8d3be892c8b29c604ba4ae484 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Thu, 12 May 2022 23:38:37 +0200 Subject: [PATCH 1/1] add aos seed retry button --- app/Http/Controllers/AosSeedController.php | 13 +++++++++++++ resources/js/components/aos/Seed.js | 13 ++++++++++++- resources/js/components/pages/AosSeed.js | 7 ++++++- resources/js/i18n/de.js | 1 + resources/js/i18n/en.js | 1 + routes/api.php | 1 + 6 files changed, 34 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/AosSeedController.php b/app/Http/Controllers/AosSeedController.php index 3e3a2b0..9d35bc0 100644 --- a/app/Http/Controllers/AosSeedController.php +++ b/app/Http/Controllers/AosSeedController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\Jobs\GenerateAosSeed; use App\Models\AosSeed; use Illuminate\Http\Request; @@ -21,4 +22,16 @@ class AosSeedController extends Controller return $seed->toJson(); } + public function retry($hash) { + $seed = AosSeed::where('hash', '=', $hash)->firstOrFail(); + + if ($seed->status == 'error') { + $seed->status = 'pending'; + $seed->save(); + GenerateAosSeed::dispatch($seed)->onConnection('database'); + } + + return $seed->toJson(); + } + } diff --git a/resources/js/components/aos/Seed.js b/resources/js/components/aos/Seed.js index 3e6ac4a..a035e60 100644 --- a/resources/js/components/aos/Seed.js +++ b/resources/js/components/aos/Seed.js @@ -65,7 +65,7 @@ const isDefaultSetting = (name, value) => { } }; -const Seed = ({ patch, seed }) => { +const Seed = ({ onRetry, patch, seed }) => { const { rom } = useAosBaseRom(); return @@ -125,6 +125,16 @@ const Seed = ({ patch, seed }) => { {i18n.t(`aosSeeds.statuses.${seed.status}`)}

} + {seed.status === 'error' ? +

+ +

+ : null}

{i18n.t('aosSeeds.generator')}

@@ -151,6 +161,7 @@ const Seed = ({ patch, seed }) => { }; Seed.propTypes = { + onRetry: PropTypes.func, patch: PropTypes.instanceOf(ArrayBuffer), seed: PropTypes.shape({ generator: PropTypes.string, diff --git a/resources/js/components/pages/AosSeed.js b/resources/js/components/pages/AosSeed.js index e3cfda8..165a2be 100644 --- a/resources/js/components/pages/AosSeed.js +++ b/resources/js/components/pages/AosSeed.js @@ -78,6 +78,11 @@ const AosSeed = () => { }; }, [hash, seed]); + const retry = useCallback(async () => { + await axios.post(`/api/aos-seed/${hash}/retry`); + setSeed(seed => ({ ...seed, status: 'pending' })); + }); + if (loading) { return ; } @@ -91,7 +96,7 @@ const AosSeed = () => { } return - + ; }; diff --git a/resources/js/i18n/de.js b/resources/js/i18n/de.js index a8445bd..a51c846 100644 --- a/resources/js/i18n/de.js +++ b/resources/js/i18n/de.js @@ -198,6 +198,7 @@ export default { logout: 'Logout', new: 'Neu', protocol: 'Protokoll', + retry: 'Neu versuchen', save: 'Speichern', search: 'Suche', settings: 'Einstellungen', diff --git a/resources/js/i18n/en.js b/resources/js/i18n/en.js index 510d68b..64d38bb 100644 --- a/resources/js/i18n/en.js +++ b/resources/js/i18n/en.js @@ -198,6 +198,7 @@ export default { logout: 'Logout', new: 'New', protocol: 'Protocol', + retry: 'Retry', save: 'Save', search: 'Search', settings: 'Settings', diff --git a/routes/api.php b/routes/api.php index e3a5ad8..f43505a 100644 --- a/routes/api.php +++ b/routes/api.php @@ -19,6 +19,7 @@ Route::middleware('auth:sanctum')->get('/user', function (Request $request) { }); Route::get('aos-seed/{hash}', 'App\Http\Controllers\AosSeedController@byHash'); +Route::post('aos-seed/{hash}/retry', 'App\Http\Controllers\AosSeedController@retry'); Route::post('application/{application}/accept', 'App\Http\Controllers\ApplicationController@accept'); Route::post('application/{application}/reject', 'App\Http\Controllers\ApplicationController@reject'); -- 2.39.2