Browse Source

Fixes

pull/282/head
Kode 6 years ago
parent
commit
6e9f25d680
  1. 9
      app/Application.php
  2. 2
      app/EnhancedApps.php
  3. 24
      app/Http/Controllers/ItemController.php
  4. 40
      app/Item.php
  5. 29
      app/SupportedApps.php
  6. 4
      resources/views/item.blade.php
  7. 2
      resources/views/items/scripts.blade.php

9
app/Application.php

@ -9,7 +9,12 @@ class Application extends Model
//
public function icon()
{
return asset($this->icon);
return $this->icon;
}
public function iconView()
{
return asset('storage/'.$this->icon);
}
public function defaultColour()
@ -24,4 +29,6 @@ class Application extends Model
$class = '\App\SupportedApps\\'.$this->name.'\\'.$this->name;
return $class;
}
}

2
app/EnhancedApps.php

@ -5,6 +5,6 @@ use GuzzleHttp\Client;
interface EnhancedApps
{
public function livestats();
}

24
app/Http/Controllers/ItemController.php

@ -291,6 +291,7 @@ class ItemController extends Controller
// basic details
$output['icon'] = $app_details->icon();
$output['iconview'] = $app_details->iconView();
$output['colour'] = $app_details->defaultColour();
// live details
@ -319,15 +320,11 @@ class ItemController extends Controller
{
$item = Item::find($id);
$config = json_decode($item->description);
$config = $item->config();
if(isset($config->type)) {
$config->url = $item->url;
if(isset($config->override_url) && !empty($config->override_url)) {
$config->url = $config->override_url;
}
$app_details = new $config->type;
$app_details->config = $config;
echo $app_details->executeConfig();
$application = new $config->type;
$application->config = $config;
echo $application->livestats();
}
}
@ -345,9 +342,14 @@ class ItemController extends Controller
} else {
// check if there has been an update for this app
$localapp = $localapps->where('name', $app->name)->first();
if($localapp->sha !== $app->sha) {
SupportedApps::getFiles($app);
SupportedApps::saveApp($app, $localapp);
if($localapp) {
if($localapp->sha !== $app->sha) {
SupportedApps::getFiles($app);
SupportedApps::saveApp($app, $localapp);
}
} else { // local folder, add to database
$application = new Application;
SupportedApps::saveApp($app, $application);
}
}
}

40
app/Item.php

@ -45,24 +45,6 @@ class Item extends Model
return $query->where('pinned', 1);
}
public function getConfigAttribute()
{
$output = null;
$view = null;
if(isset($this->description) && !empty($this->description)){
$output = json_decode($this->description);
$output = is_object($output) ? $output : new \stdClass();
if(isset($output->type) && !empty($output->type)) {
$class = $output->type;
$sap = new $class();
$view = $sap->configDetails();
$output->view = $view;
}
if(!isset($output->dataonly)) $output->dataonly = '0';
}
return (object)$output;
}
public static function checkConfig($config)
{
if(empty($config)) {
@ -156,6 +138,28 @@ class Item extends Model
return $query->where('type', $typeid);
}
public function enhanced()
{
$details = $this->config();
$class = $details->type;
$app = new $class;
return (bool)($app instanceof \App\EnhancedApps);
}
public function config()
{
$config = json_decode($this->description);
$config->url = $this->url;
if(isset($config->override_url) && !empty($config->override_url)) {
$config->url = $config->override_url;
}
return $config;
}
/**
* Get the user that owns the item.
*/

29
app/SupportedApps.php

@ -5,7 +5,6 @@ use GuzzleHttp\Client;
abstract class SupportedApps
{
public $config;
public function test($url, $requiresLoginFirst=false)
{
@ -14,7 +13,12 @@ abstract class SupportedApps
public function execute($url, $requiresLoginFirst=false)
{
if($requiresLoginFirst) {
}
$client = new Client(['http_errors' => false, 'timeout' => 15, 'connect_timeout' => 15]);
return $client->request('GET', $url);
}
public function login()
@ -27,6 +31,18 @@ abstract class SupportedApps
}
public function getLiveStats($status, $data)
{
$className = get_class($this);
$explode = explode('\\', $className);
$name = end($explode);
$html = view('SupportedApps::'.$name.'.livestats', $data)->with('data', $data)->render();
return json_encode(['status' => $status, 'html' => $html]);
//return
}
public static function getList()
{
$list_url = 'https://apps.heimdall.site/list';
@ -60,11 +76,16 @@ abstract class SupportedApps
$app->name = $details->name;
$app->sha = $details->sha;
$app->icon = 'storage/supportedapps/'.$details->icon;
$app->icon = 'supportedapps/'.$details->icon;
$app->website = $details->website;
$app->license = $details->license;
$app->description = $details->description;
$app->enhanced = $details->enhanced;
$appclass = $app->class();
$application = new $appclass;
$enhanced = (bool)($application instanceof \App\EnhancedApps);
$app->enhanced = $enhanced;
$app->tile_background = $details->tile_background;
$app->save();
}

4
resources/views/item.blade.php

@ -7,8 +7,8 @@
@endif
<div class="details">
<div class="title{{ title_color($app->colour) }}">{{ $app->title }}</div>
@if(isset($app->config->enabled) && ((bool)$app->config->enabled === true))
<div data-id="{{ $app->id }}" data-dataonly="{{ $app->config->dataonly or '0' }}" class="livestats-container"></div>
@if($app->enhanced())
<div data-id="{{ $app->id }}" data-dataonly="{{ $app->config()->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>

2
resources/views/items/scripts.blade.php

@ -13,7 +13,7 @@
source: availableTags,
select: function( event, ui ) {
$.post('/appload', { app: ui.item.value }, function(data) {
$('#appimage').html("<img src='"+data.icon+"' /><input type='hidden' name='icon' value='"+data.icon+"' />");
$('#appimage').html("<img src='"+data.iconview+"' /><input type='hidden' name='icon' value='"+data.icon+"' />");
$('input[name=colour]').val(data.colour);
hueb.setColor( data.colour );
$('input[name=pinned]').prop('checked', true);

Loading…
Cancel
Save