Skip to content

Commit 67c5d00

Browse files
lucaslraLucas Araujo
andauthored
feat(Memos): add livestats and config support for Memos app (#867)
* feat(Memos): add livestats and config support for Memos app Implement livestats functionality to display memo count and add config support for API access. Enable enhanced app features in app.json. * style(Memos): improve code formatting and readability * style: remove empty line in Memos constructor --------- Co-authored-by: Lucas Araujo <[email protected]>
1 parent ece131b commit 67c5d00

File tree

4 files changed

+74
-2
lines changed

4 files changed

+74
-2
lines changed

Memos/Memos.php

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,57 @@
22

33
namespace App\SupportedApps\Memos;
44

5-
class Memos extends \App\SupportedApps
5+
class Memos extends \App\SupportedApps implements \App\EnhancedApps
66
{
7+
public $config;
8+
9+
public function __construct() {
10+
}
11+
12+
public function test()
13+
{
14+
$test = parent::appTest(
15+
$this->url('api/v1/auth/sessions/current'),
16+
$this->attrs()
17+
);
18+
echo $test->status;
19+
}
20+
21+
public function livestats()
22+
{
23+
$status = 'inactive';
24+
$res = parent::execute(
25+
$this->url('api/v1/memos'),
26+
$this->attrs()
27+
);
28+
$details = json_decode($res->getBody());
29+
30+
$data = [];
31+
32+
if ($details) {
33+
$status = 'active';
34+
$data['memo_count'] = count($details->memos);
35+
}
36+
37+
return parent::getLiveStats($status, $data);
38+
}
39+
40+
public function url($endpoint)
41+
{
42+
$api_url = parent::normaliseurl($this->config->url) . $endpoint;
43+
return $api_url;
44+
}
45+
46+
47+
public function attrs()
48+
{
49+
$access_token = $this->config->access_token;
50+
$attrs = [
51+
"headers" => [
52+
"content-type" => "application/json",
53+
"Authorization" => "Bearer " . $access_token,
54+
],
55+
];
56+
return $attrs;
57+
}
758
}

Memos/app.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"website": "https://github.com/usememos/memos",
55
"license": "MIT License",
66
"description": "A privacy-first, lightweight note-taking service. Easily capture and share your great thoughts.",
7-
"enhanced": false,
7+
"enhanced": true,
88
"tile_background": "light",
99
"icon": "memos.png"
1010
}

Memos/config.blade.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<h2>{{ __('app.apps.config') }} ({{ __('app.optional') }}) @include('items.enable')</h2>
2+
<div class="items">
3+
<div class="input">
4+
<label>{{ strtoupper(__('app.url')) }}</label>
5+
{!! Form::text('config[override_url]', null, array('placeholder' => __('app.apps.override'), 'id' => 'override_url', 'class' => 'form-control')) !!}
6+
</div>
7+
<div class="input">
8+
<label>{{ __('app.apps.apikey') }} (Access Token)</label>
9+
{!! Form::text('config[access_token]', null, array('placeholder' => __('app.apps.apikey'), 'data-config' => 'access_token', 'class' => 'form-control config-item')) !!}
10+
</div>
11+
<div class="input">
12+
<button style="margin-top: 32px;" class="btn test" id="test_config">Test</button>
13+
</div>
14+
</div>
15+

Memos/livestats.blade.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<ul class="livestats">
2+
<li>
3+
<span class="title">Memos</span>
4+
<strong>{!! $memo_count !!}</strong>
5+
</li>
6+
</ul>

0 commit comments

Comments
 (0)