Browse Source

Fix test button

pull/282/head
Kode 6 years ago
parent
commit
540bead0db
  1. 4
      app/Http/Controllers/ItemController.php
  2. 8
      app/Item.php
  3. 18
      app/SupportedApps.php
  4. 2
      resources/views/item.blade.php
  5. 4
      resources/views/items/form.blade.php

4
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;

8
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)) {

18
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)

2
resources/views/item.blade.php

@ -8,7 +8,7 @@
<div class="details">
<div class="title{{ title_color($app->colour) }}">{{ $app->title }}</div>
@if($app->enhanced())
<div data-id="{{ $app->id }}" data-dataonly="{{ $app->config()->dataonly ?? '0' }}" class="livestats-container"></div>
<div data-id="{{ $app->id }}" data-dataonly="{{ $app->getconfig()->dataonly ?? '0' }}" class="livestats-container"></div>
@endif
</div>
<a class="link{{ title_color($app->colour) }}"{!! $app->link_target !!} href="{{ $app->link }}"><i class="fas {{ $app->link_icon }}"></i></a>

4
resources/views/items/form.blade.php

@ -58,10 +58,10 @@
</div>
</div>
@if(isset($item) && isset($item->config->view))
@if($item->enhanced())
<div id="sapconfig" style="display: block;">
@if(isset($item))
@include('supportedapps.'.$item->config->view)
@include('SupportedApps::'.$item->getconfig()->name.'.config')
@endif
</div>
@else

Loading…
Cancel
Save