Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 59 additions & 1 deletion Wavelog/Wavelog.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,64 @@

namespace App\SupportedApps\Wavelog;

class Wavelog extends \App\SupportedApps
class Wavelog extends \App\SupportedApps implements \App\EnhancedApps
{
public $config;

public function test(): void
{
$attrs = $this->getRequestAttrs();
$test = parent::appTest($this->url("token"), $attrs);
echo $test->status;
}

public function livestats()
{
$status = "inactive";
$data = [];
$attrs = $this->getRequestAttrs();

$stats = json_decode(
parent::execute($this->url("statistic?profile=qso"), $attrs)->getBody()
);

$data = [
"qsosToday" => $stats?->data?->qso?->activity?->today ?? 0,
"totalQSOs" => $stats?->data?->qso?->total ?? 0,
];

return parent::getLiveStats($status, $data);
}

public function url($endpoint): string
{
$api_url = parent::normaliseurl($this->config->url) .
'index.php/api/v2/' .
$endpoint;

return $api_url;
}

private function getConfigValue(string $key, $default = null)
{
return isset($this->config) && isset($this->config->{$key})
? $this->config->{$key}
: $default;
}

private function getRequestAttrs(): array
{
$attrs = [
'headers' => [
'Accept' => 'application/json',
],
];

$apikey = $this->getConfigValue('apikey');
if ($apikey !== null) {
$attrs['headers']['Authorization'] = 'Bearer ' . $apikey;
}

return $attrs;
}
}
2 changes: 1 addition & 1 deletion Wavelog/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"website": "https://www.wavelog.org/",
"license": "MIT License",
"description": "Wavelog is an open source and self-hosted logging software for amateur radio operators. It serves as a log book for QSOs (connections in the amateur radio world) and tracks their confirmation via external websites.",
"enhanced": false,
"enhanced": true,
"tile_background": "dark",
"icon": "wavelog.png"
}
18 changes: 18 additions & 0 deletions Wavelog/config.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<h2>{{ __('app.apps.config') }} ({{ __('app.optional') }}) @include('items.enable')</h2>
<div class="items">
<div class="input">
<label for="config[override_url]">{{ strtoupper(__('app.url')) }}</label>
{!! Form::text('config[override_url]', isset($item) ? $item->getconfig()->override_url : null, ['placeholder' => __('app.apps.override'), 'id' => 'override_url', 'class' => 'form-control']) !!}
</div>
<div class="input">
<label for="config[apikey]">{{ __('app.apps.apikey') }}</label>
{!! Form::text('config[apikey]', isset($item) ? $item->getconfig()->apikey : null, ['placeholder' => __('app.apps.apikey'), 'data-config' => 'apikey', 'class' => 'form-control config-item']) !!}
<small>
Requires a key for the Wavelog API v2 with scope <code>statistic:read</code>.
See the <a href="https://docs.wavelog.org/developer/api-v2/#scopes" target="_blank">Wavelog docs</a>.
</small>
</div>
<div class="input">
<button style="margin-top: 32px;" class="btn test" id="test_config">Test</button>
</div>
</div>
10 changes: 10 additions & 0 deletions Wavelog/livestats.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<ul class="livestats">
<li>
<span class="title">QSOs today</span>
<strong>{!! $qsosToday !!}</strong>
</li>
<li>
<span class="title">Total QSOs</span>
<strong>{!! $totalQSOs !!}</strong>
</li>
</ul>