including some more dashboard components
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace App\SupportedApps\Bookstack;
|
||||
|
||||
class Bookstack extends \App\SupportedApps implements \App\EnhancedApps
|
||||
{
|
||||
public $config;
|
||||
|
||||
//protected $login_first = true; // Uncomment if api requests need to be authed first
|
||||
//protected $method = 'POST'; // Uncomment if requests to the API should be set by POST
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
//$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set
|
||||
}
|
||||
|
||||
public function getHeaders()
|
||||
{
|
||||
$api_token = $this->config->api_token . ":" . $this->config->api_secret;
|
||||
|
||||
$attrs["headers"] = ["Authorization" => "Token " . $api_token];
|
||||
return $attrs;
|
||||
}
|
||||
|
||||
public function test()
|
||||
{
|
||||
$test = parent::appTest(
|
||||
$this->url("api/shelves?count=0"),
|
||||
$this->getHeaders()
|
||||
);
|
||||
echo $test->status;
|
||||
}
|
||||
|
||||
public function livestats()
|
||||
{
|
||||
$status = "inactive";
|
||||
|
||||
$attrs = $this->getHeaders();
|
||||
|
||||
$data = ["visiblestats" => []];
|
||||
|
||||
foreach ($this->config->availablestats as $stat) {
|
||||
if (!isset(self::getAvailableStats()[$stat])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$res = parent::execute(
|
||||
$this->url("api/" . $stat . "?count=0"),
|
||||
$attrs
|
||||
);
|
||||
$details = json_decode($res->getBody());
|
||||
|
||||
$newstat = new \stdClass();
|
||||
$newstat->title = self::getAvailableStats()[$stat];
|
||||
$newstat->value = isset($details->total)
|
||||
? number_format($details->total)
|
||||
: "N/A";
|
||||
|
||||
$data["visiblestats"][] = $newstat;
|
||||
}
|
||||
|
||||
return parent::getLiveStats($status, $data);
|
||||
}
|
||||
|
||||
public function url($endpoint)
|
||||
{
|
||||
$api_url =
|
||||
rtrim(parent::normaliseurl($this->config->url), "/") .
|
||||
"/" .
|
||||
ltrim($endpoint, "/");
|
||||
return $api_url;
|
||||
}
|
||||
|
||||
public static function getAvailableStats()
|
||||
{
|
||||
return [
|
||||
"shelves" => "Shelves",
|
||||
"books" => "Books",
|
||||
"chapters" => "Chapters",
|
||||
"pages" => "Pages",
|
||||
];
|
||||
}
|
||||
}
|
||||
10
stacks/dashboard/config/www/SupportedApps/Bookstack/app.json
Normal file
10
stacks/dashboard/config/www/SupportedApps/Bookstack/app.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"appid": "348c49dd03dddd418929316668d2e67bf2d9ae88",
|
||||
"name": "Bookstack",
|
||||
"website": "https://www.bookstackapp.com",
|
||||
"license": "MIT License",
|
||||
"description": "BookStack is a simple, self-hosted, easy-to-use platform for organising and storing information.",
|
||||
"enhanced": true,
|
||||
"tile_background": "dark",
|
||||
"icon": "bookstack.svg"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<h2>{{ __('app.apps.config') }} ({{ __('app.optional') }}) @include('items.enable')</h2>
|
||||
<div class="items">
|
||||
<div class="input">
|
||||
<label>{{ strtoupper(__('app.url')) }}</label>
|
||||
{!! Form::text('config[override_url]', isset($item) ? $item->getConfig()->override_url ?? null : null, ['placeholder' => __('app.apps.override'), 'id' => 'override_url', 'class' => 'form-control']) !!}
|
||||
</div>
|
||||
<div class="input">
|
||||
<label>Token ID</label>
|
||||
{!! Form::text('config[api_token]', isset($item) ? $item->getconfig()->api_token : null, ['placeholder' => 'Token ID', 'data-config' => 'api_token', 'class' => 'form-control config-item']) !!}
|
||||
</div>
|
||||
<div class="input">
|
||||
<label>Token Secret</label>
|
||||
{!! Form::text('config[api_secret]', isset($item) ? $item->getconfig()->api_secret : null, ['placeholder' => 'Token Secret', 'data-config' => 'api_secret', 'class' => 'form-control config-item']) !!}
|
||||
</div>
|
||||
<div class="input">
|
||||
<label>Stats to show</label>
|
||||
{!! Form::select('config[availablestats][]', App\SupportedApps\Bookstack\Bookstack::getAvailableStats(), isset($item) ? $item->getConfig()->availablestats ?? null : null, ['multiple' => 'multiple']) !!}
|
||||
</div>
|
||||
<div class="input">
|
||||
<button style="margin-top: 32px;" class="btn test" id="test_config">Test</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,8 @@
|
||||
<ul class="livestats">
|
||||
@foreach ($visiblestats as $stat)
|
||||
<li>
|
||||
<span class="title">{!! $stat->title !!}</span>
|
||||
<strong>{!! $stat->value !!}</strong>
|
||||
</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
Reference in New Issue
Block a user