Skip to content

Commit

Permalink
Adding the oh dear widget
Browse files Browse the repository at this point in the history
  • Loading branch information
jonassiewertsen committed Mar 6, 2020
1 parent aaf1d59 commit 85884b9
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 2 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Check your monitored uptime, SSL certificates, mixed content and broken links ea
To use this addon, you need to have an [OhDear](https://ohdear.app) account.

## Installation
### Step 1
### Step 1
Pull in your package with composer
```bash
composer require jonassiewertsen/statamic-oh-dear
Expand All @@ -25,3 +25,12 @@ Add your [Oh Dear API](https://ohdear.app/docs/integrations/api/authentication#g
OH_DEAR_API_KEY="XXXXXXXX"
OH_DEAR_SITE_ID=XXXXXXXXX
```
## Add the Widget
To add a small widget to the dashboard, you need to tell your config file.
Open `config/statamic/cp.php` and look for the "Dashboard widgets" section and add it.

```php
'widgets' => [
'oh_dear',
// mabye other widgets
],
1 change: 1 addition & 0 deletions resources/lang/en/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
'past_months' => 'Past :months months',
'probem_occurred' => 'A Problem occurred. Please try again later.',
'secure' => 'Secure',
'show_more' => 'Show more',
'site_up' => 'Site is up',
'site_down' => 'Site is down',
'status_code' => 'Status Code',
Expand Down
39 changes: 39 additions & 0 deletions resources/views/widget/index.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
@component('oh-dear::partials.card')
<div class="flex flex-col lg:flex-row justify-between pr-3">
<a class="mb-1 lg:mb-0" href="{{ cp_route('oh-dear.uptime') }}">
@include('oh-dear::overview._label', [
'check' => $checks['uptime'],
'message_success' => __('oh-dear::lang.uptime'),
'message_failed' => __('oh-dear::lang.uptime'),
])
</a>

<a class="mb-1 lg:mb-0" href="{{ cp_route('oh-dear.broken-links') }}">
@include('oh-dear::overview._label', [
'check' => $checks['broken_links'],
'message_success' => __('oh-dear::lang.broken_links'),
'message_failed' => __('oh-dear::lang.broken_links'),
])
</a>

<a class="mb-1 lg:mb-0" href="{{ cp_route('oh-dear.mixed-content') }}">
@include('oh-dear::overview._label', [
'check' => $checks['mixed_content'],
'message_success' => __('oh-dear::lang.mixed_content'),
'message_failed' => __('oh-dear::lang.mixed_content')
])
</a>

<a class="mb-1 lg:mb-0" href="{{ cp_route('oh-dear.certificate-health') }}">
@include('oh-dear::overview._label', [
'check' => $checks['certificate'],
'message_success' => __('oh-dear::lang.certificate_health'),
'message_failed' => __('oh-dear::lang.certificate_health'),
])
</a>
</div>

<a class="block text-grey-70 mt-1 md:mt-2 -mb-2 text-right mr-3" href="{{ cp_route('oh-dear.index') }}">
{{ __('oh-dear::lang.show_more') }}
</a>
@endcomponent
2 changes: 1 addition & 1 deletion src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ServiceProvider extends AddonServiceProvider
];

protected $widgets = [
// TODO: Add a widget for the dashboard
\Jonassiewertsen\OhDear\Widgets\OhDear::class,
];

public function boot()
Expand Down
32 changes: 32 additions & 0 deletions src/WIdgets/OhDear.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Jonassiewertsen\OhDear\Widgets;

use Statamic\Widgets\Widget;
use Jonassiewertsen\OhDear\OhDear as OhDearInstance;

class OhDear extends Widget
{
/**
* The HTML that should be shown in the widget
*
* @return \Illuminate\View\View
*/
public function html()
{
$ohdear = new OhDearInstance();

if ($ohdear->ohDear === null || $ohdear->site === null) {
return;
}

$checks = [
'uptime' => $ohdear->uptimeCheck(),
'broken_links' => $ohdear->brokenLinksCheck(),
'mixed_content' => $ohdear->mixedContentCheck(),
'certificate' => $ohdear->certificateCheck(),
];

return view('oh-dear::widget.index', compact('checks'));
}
}

0 comments on commit 85884b9

Please sign in to comment.