From 540bead0db3cf8d0faa35f98f1e7a60845cf6a93 Mon Sep 17 00:00:00 2001 From: Kode Date: Sun, 21 Oct 2018 13:23:23 +0100 Subject: [PATCH] Fix test button --- app/Http/Controllers/ItemController.php | 4 ++-- app/Item.php | 8 ++++++-- app/SupportedApps.php | 18 ++++++++++++++++-- resources/views/item.blade.php | 2 +- resources/views/items/form.blade.php | 4 ++-- 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/ItemController.php b/app/Http/Controllers/ItemController.php index 84da8a74..e65041d3 100644 --- a/app/Http/Controllers/ItemController.php +++ b/app/Http/Controllers/ItemController.php @@ -313,14 +313,14 @@ class ItemController extends Controller $app_details = new $app(); $app_details->config = (object)$data; - $app_details->testConfig(); + $app_details->test(); } public function getStats($id) { $item = Item::find($id); - $config = $item->config(); + $config = $item->getconfig(); if(isset($config->type)) { $application = new $config->type; $application->config = $config; diff --git a/app/Item.php b/app/Item.php index 286804bf..3c5715e9 100644 --- a/app/Item.php +++ b/app/Item.php @@ -140,15 +140,19 @@ class Item extends Model public function enhanced() { - $details = $this->config(); + $details = $this->getconfig(); $class = $details->type; $app = new $class; return (bool)($app instanceof \App\EnhancedApps); } - public function config() + public function getconfig() { $config = json_decode($this->description); + + $explode = explode('\\', $config->type); + $config->name = end($explode); + $config->url = $this->url; if(isset($config->override_url) && !empty($config->override_url)) { diff --git a/app/SupportedApps.php b/app/SupportedApps.php index 338868bd..e99be134 100644 --- a/app/SupportedApps.php +++ b/app/SupportedApps.php @@ -6,9 +6,23 @@ use GuzzleHttp\Client; abstract class SupportedApps { - public function test($url, $requiresLoginFirst=false) + public function appTest($url, $requiresLoginFirst=false) { - + $res = $this->execute($url, $requiresLoginFirst); + switch($res->getStatusCode()) { + case 200: + echo 'Successfully connected to the API'; + break; + case 401: + echo 'Failed: Invalid credentials'; + break; + case 404: + echo 'Failed: Please make sure your URL is correct and that there is a trailing slash'; + break; + default: + echo 'Something went wrong... Code: '.$res->getStatusCode(); + break; + } } public function execute($url, $requiresLoginFirst=false) diff --git a/resources/views/item.blade.php b/resources/views/item.blade.php index bb8b15cf..2b2d543e 100644 --- a/resources/views/item.blade.php +++ b/resources/views/item.blade.php @@ -8,7 +8,7 @@
{{ $app->title }}
@if($app->enhanced()) -
+
@endif
link_target !!} href="{{ $app->link }}"> diff --git a/resources/views/items/form.blade.php b/resources/views/items/form.blade.php index 278247c7..c6657efc 100644 --- a/resources/views/items/form.blade.php +++ b/resources/views/items/form.blade.php @@ -58,10 +58,10 @@ - @if(isset($item) && isset($item->config->view)) + @if($item->enhanced())
@if(isset($item)) - @include('supportedapps.'.$item->config->view) + @include('SupportedApps::'.$item->getconfig()->name.'.config') @endif
@else