Skip to content

Commit 48e2ab3

Browse files
ta3mmvdkleijn
andauthored
Add Budibase Enhanced Plugin (#822)
* Add Budibase Enhanced Plugin - Add Budibase API - Icon run through tinify - Shows Total Apps and Active Apps - Uses var test to active * php-cs-fix * phplint * Camel case fix * Delete yarn.lock * Delete .php-cs-fixer.cache --------- Co-authored-by: Trent AE. Maydew <ta3m@users.noreply.github.com> Co-authored-by: Martijn van der Kleijn <martijn.niji@gmail.com>
1 parent a56b812 commit 48e2ab3

File tree

5 files changed

+121
-0
lines changed

5 files changed

+121
-0
lines changed

Budibase/Budibase.php

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
namespace App\SupportedApps\Budibase;
4+
5+
class Budibase extends \App\SupportedApps implements \App\EnhancedApps
6+
{
7+
public $config;
8+
9+
//protected $login_first = true; // Uncomment if api requests need to be authed first
10+
//protected $method = 'POST'; // Uncomment if requests to the API should be set by POST
11+
12+
public function __construct()
13+
{
14+
//$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set
15+
}
16+
17+
public function test()
18+
{
19+
$attrs = [
20+
"headers" => [
21+
"x-budibase-api-key" => $this->config->apikey
22+
],
23+
];
24+
$test = parent::appTest($this->url('metrics'), $attrs);
25+
echo $test->status;
26+
}
27+
28+
public function decodeResponse($response)
29+
{
30+
$response = explode(PHP_EOL, $response);
31+
$data = [];
32+
foreach ($response as $x) {
33+
$y = explode(' ', $x);
34+
if (is_array($y) && count($y) == 2) {
35+
$data[$y[0]] = $y[1];
36+
}
37+
}
38+
return $data;
39+
}
40+
41+
public function livestats()
42+
{
43+
$attrs = [
44+
"headers" => [
45+
"x-budibase-api-key" => $this->config->apikey
46+
],
47+
];
48+
$status = 'inactive';
49+
$res = parent::execute($this->url('metrics'), $attrs);
50+
$info = $this->decodeResponse($res->getBody());
51+
52+
$data = [
53+
"total" => $info['budibase_tenant_app_count'],
54+
"active" => $info['budibase_tenant_production_app_count']
55+
];
56+
if ($info['budibase_quota_limit_automations'] > 0) {
57+
$status = "active";
58+
}
59+
60+
return parent::getLiveStats($status, $data);
61+
}
62+
63+
public function url($endpoint)
64+
{
65+
$api_url = parent::normaliseurl($this->config->url, true) . "api/public/v1/" . $endpoint;
66+
return $api_url;
67+
}
68+
}

Budibase/app.json

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"appid": "6c51d4f37f544b0327d327d1bade045a7809a4d9",
3+
"name": "Budibase",
4+
"website": "https://budibase.com/",
5+
"license": "GNU General Public License v3.0 or later",
6+
"description": "Budibase is an open-source low-code platform that saves engineers 100s of hours building forms, portals, and approval apps, securely.",
7+
"enhanced": true,
8+
"tile_background": "dark",
9+
"icon": "budibase.png",
10+
"config": {
11+
"type": "apikey",
12+
"stat1": {
13+
"name": "Total Apps",
14+
"url": ":url:api/public/v1/metrics",
15+
"key": "budibase_tenant_app_count",
16+
"filter": "none",
17+
"updateOnChange": "no",
18+
"suffix": ""
19+
},
20+
"stat2": {
21+
"name": "Active Apps",
22+
"url": ":url:api/public/v1/metrics",
23+
"key": "budibase_tenant_production_app_count",
24+
"filter": "none",
25+
"updateOnChange": "no",
26+
"suffix": ""
27+
}
28+
}
29+
}

Budibase/budibase.png

1.75 KB
Loading

Budibase/config.blade.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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]', isset($item) ? $item->getconfig()->override_url : null, ['placeholder' => __('app.apps.override'), 'id' => 'override_url', 'class' => 'form-control']) !!}
6+
</div>
7+
<div class="input">
8+
<label>{{ __('app.apps.apikey') }}</label>
9+
{!! Form::text('config[apikey]', isset($item) ? $item->getconfig()->apikey : null, ['placeholder' => __('app.apps.apikey'), 'data-config' => 'apikey', '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>

Budibase/livestats.blade.php

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<ul class="livestats">
2+
<li>
3+
<span class="title">Total Apps</span>
4+
<strong>{!! $total !!}</strong>
5+
</li>
6+
<li>
7+
<span class="title">Active Apps</span>
8+
<strong>{!! $active !!}</strong>
9+
</li>
10+
</ul>

0 commit comments

Comments
 (0)