This commit is contained in:
Kode 2018-10-28 10:59:59 +00:00
parent d1956c4e88
commit 4351f55225
11 changed files with 59 additions and 27 deletions

View file

@ -7,6 +7,6 @@ interface EnhancedApps
{
public function test();
public function livestats();
public function apiUrl($endpoint);
public function url($endpoint);
}

View file

@ -335,8 +335,8 @@ class ItemController extends Controller
$item = Item::find($id);
$config = $item->getconfig();
if(isset($config->type)) {
$application = new $config->type;
if(isset($item->class)) {
$application = new $item->class;
$application->config = $config;
echo $application->livestats();
}

View file

@ -159,7 +159,7 @@ class Item extends Model
$config = json_decode($this->description);
$explode = explode('\\', $config->type);
$explode = explode('\\', $this->class);
$config->name = end($explode);

View file

@ -6,33 +6,47 @@ use GuzzleHttp\Client;
abstract class SupportedApps
{
public function appTest($url, $requiresLoginFirst=false)
protected $jar = false;
protected $method = 'GET';
public function appTest($url, $attrs = [])
{
$res = $this->execute($url, $requiresLoginFirst);
$res = $this->execute($url, $attrs);
switch($res->getStatusCode()) {
case 200:
echo 'Successfully connected to the API';
$status = 'Successfully communicated with the API';
break;
case 401:
echo 'Failed: Invalid credentials';
$status = 'Failed: Invalid credentials';
break;
case 404:
echo 'Failed: Please make sure your URL is correct and that there is a trailing slash';
$status = 'Failed: Please make sure your URL is correct and that there is a trailing slash';
break;
default:
echo 'Something went wrong... Code: '.$res->getStatusCode();
$status = 'Something went wrong... Code: '.$res->getStatusCode();
break;
}
return (object)[
'code' => $res->getStatusCode(),
'status' => $status,
'response' => $res->getBody(),
];
}
public function execute($url, $requiresLoginFirst=false)
public function execute($url, $attrs = [])
{
if($requiresLoginFirst) {
$vars = [
'http_errors' => false,
'timeout' => 15,
'connect_timeout' => 15,
];
$client = new Client($vars);
}
$client = new Client(['http_errors' => false, 'timeout' => 15, 'connect_timeout' => 15]);
return $client->request('GET', $url);
try {
return $client->request($this->method, $url, $attrs);
} catch (\GuzzleHttp\Exception\ServerException $e) {
echo (string) $e->getResponse()->getBody();
}
}
public function login()
@ -61,14 +75,14 @@ abstract class SupportedApps
{
$list_url = 'https://apps.heimdall.site/list';
$client = new Client(['http_errors' => false, 'timeout' => 15, 'connect_timeout' => 15]);
return $client->request('GET', $list_url);
return $client->request($this->method, $list_url);
}
public static function getFiles($app)
{
$zipurl = $app->files;
$client = new Client(['http_errors' => false, 'timeout' => 60, 'connect_timeout' => 15]);
$res = $client->request('GET', $zipurl);
$res = $client->request($this->method, $zipurl);
if(!file_exists(app_path('SupportedApps'))) {
mkdir(app_path('SupportedApps'), 0777, true);

15
public/css/app.css vendored
View file

@ -1252,7 +1252,7 @@ hr {
}
.livestats-container .livestats {
margin: 5px 0px -5px;
margin: 5px 0px 0px;
padding: 0;
display: -webkit-box;
display: -ms-flexbox;
@ -1277,11 +1277,24 @@ hr {
font-weight: 500;
opacity: 0.5;
line-height: 1;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
}
.livestats-container .livestats strong {
display: block;
line-height: 1;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
.livestats-container .livestats strong span {
margin-left: 4px;
}
input:-webkit-autofill,

2
public/js/app.js vendored
View file

@ -135,7 +135,7 @@ $.when( $.ready ).then(function() {
var data = {};
data['url'] = apiurl;
$('input.config-item').each(function(index){
$('.config-item').each(function(index){
var config = $(this).data('config');
data[config] = $(this).val();
});

View file

@ -1,4 +1,4 @@
{
"/css/app.css": "/css/app.css?id=d501edaf8c9cc02c173d",
"/js/app.js": "/js/app.js?id=32cbf6f4924b46ae7e05"
"/css/app.css": "/css/app.css?id=22a39cc94a111a82ce68",
"/js/app.js": "/js/app.js?id=8dc4a6ea723d0df7469d"
}

View file

@ -126,7 +126,7 @@ $.when( $.ready ).then(function() {
var data = {};
data['url'] = apiurl;
$('input.config-item').each(function(index){
$('.config-item').each(function(index){
var config = $(this).data('config');
data[config] = $(this).val();
});

View file

@ -852,7 +852,7 @@ hr {
.livestats-container {
.livestats {
margin: 5px 0px -5px;
margin: 5px 0px 0px;
padding: 0;
display: flex;
list-style: none;
@ -871,10 +871,16 @@ hr {
font-weight: 500;
opacity: 0.5;
line-height: 1;
display: flex;
}
strong {
display: block;
line-height: 1;
display: flex;
align-items: center;
span {
margin-left: 4px;
}
}
}

View file

@ -22,14 +22,13 @@
</header>
<div id="create" class="create">
{!! csrf_field() !!}
{!! Form::hidden('class', '') !!}
<div class="input">
<label>{{ __('app.apps.application_name') }} *</label>
{!! Form::text('title', null, array('placeholder' => __('app.apps.title'), 'id' => 'appname', 'class' => 'form-control')) !!}
</div>
<div class="input">
<label>{{ __('app.apps.apptype') }} *</label>
{!! Form::select('class', App\Application::applist(), null, array('class' => 'form-control')) !!}
{!! Form::select('class', App\Application::applist(), null, array('class' => 'form-control config-item', 'data-config' => 'type')) !!}
</div>
<div class="input">

View file

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