Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
Kussie committed Apr 6, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 55dd600 commit 5a37cbe
Showing 19 changed files with 413 additions and 1 deletion.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/.idea
/vendor
/node_modules
package-lock.json
composer.phar
composer.lock
phpunit.xml
.phpunit.result.cache
.DS_Store
Thumbs.db
48 changes: 47 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,47 @@
# nova-version-card
# Nova Version Card (Laravel Nova 4.0+)

Get the versions of the basic system services of the server running your web application right from your Nova dashboard. This is based on the work of [Chris Bautista](https://github.com/CoreProc/nova-system-info-card)

![version card screenshot](https://github.com/Kussie/nova-version-card/blob/main/screenshot.png?raw=true)

## Installation

You can install the package in to a Laravel app that uses [Nova](https://nova.laravel.com) via composer:

```bash
composer require kussie/nova-version-card
```

## Usage

Register the card within your Dashboard in Nova. This is typically done in the `cards` method of your Dashboard file for example `Dashboard/Main.php`.

```php
// ...
public function cards()
{
return [
// ...
new \Kussie\VersionCard\VersionCard(),
];
}
```

### Testing

``` bash
composer test
```

### Security

If you discover any security related issues, please email ben@kussie.com.au instead of using the issue tracker.

## Credits

- [Chris Bautista](https://github.com/chrisbjr)
- [All Contributors](../../contributors)

## License

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
46 changes: 46 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "kussie/nova-version-card",
"description": "A Laravel Nova card to show some system versions.",
"keywords": [
"laravel",
"nova"
],
"license": "MIT",
"authors": [
{
"name": "Ben Kuskopf",
"email": "ben@kussie.com.au",
"role": "Developer"
}
],
"require": {
"php": "^7.3|^8.0",
"laravel/nova": "^4.0"
},
"require-dev": {
"orchestra/testbench": "^3.6",
"phpunit/phpunit": "7.1"
},
"autoload": {
"psr-4": {
"Kussie\\VersionCard\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Kussie\\VersionCard\\Tests\\": "tests/"
}
},
"extra": {
"laravel": {
"providers": [
"Kussie\\VersionCard\\CardServiceProvider"
]
}
},
"config": {
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true
}
1 change: 1 addition & 0 deletions dist/css/card.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions dist/js/card.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions dist/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"/js/card.js": "/js/card.js",
"/css/card.css": "/css/card.css"
}
33 changes: 33 additions & 0 deletions mix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const mix = require('laravel-mix')
const webpack = require('webpack')
const path = require('path')

class NovaExtension {
name() {
return 'nova-extension'
}

register(name) {
this.name = name
}

webpackConfig(webpackConfig) {
webpackConfig.externals = {
vue: 'Vue',
}

webpackConfig.resolve.alias = {
...(webpackConfig.resolve.alias || {}),
'laravel-nova': path.join(
__dirname,
'../../vendor/laravel/nova/resources/js/mixins/packages.js'
),
}

webpackConfig.output = {
uniqueName: this.name,
}
}
}

mix.extend('nova', new NovaExtension())
19 changes: 19 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "mix",
"watch": "mix watch",
"watch-poll": "mix watch -- --watch-options-poll=1000",
"hot": "mix watch --hot",
"prod": "npm run production",
"production": "mix --production"
},
"devDependencies": {
"@vue/compiler-sfc": "^3.2.22",
"laravel-mix": "^6.0.41",
"postcss": "^8.3.11",
"vue-loader": "^16.8.3"
},
"dependencies": {}
}
1 change: 1 addition & 0 deletions resources/css/card.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* Nova Card CSS */
5 changes: 5 additions & 0 deletions resources/js/card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Card from './components/Card'

Nova.booting((app, store) => {
app.component('version-card', Card)
})
63 changes: 63 additions & 0 deletions resources/js/components/Card.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<template>
<Card class="flex flex-col">
<div class="p-6">
<Heading :level="3">System Versions</Heading>
<table class="w-full text-left table-collapse">
<tbody class="align-baseline">
<tr>
<td class="p-2 font-bold">OS</td>
<td class="p-2">{{ os }}</td>
</tr>
<tr>
<td class="p-2 font-bold">PHP Version</td>
<td class="p-2">{{ php }}</td>
</tr>
<tr>
<td class="p-2 font-bold">Database</td>
<td class="p-2">{{ database }}</td>
</tr>
<tr>
<td class="p-2 font-bold">Laravel Version</td>
<td class="p-2">{{ laravel }}</td>
</tr>
<tr>
<td class="p-2 font-bold">Nova Version</td>
<td class="p-2">{{ nova }}</td>
</tr>
</tbody>
</table>
</div>
</Card>
</template>

<script>
export default {
props: [
'card',
// The following props are only available on resource detail cards...
// 'resource',
// 'resourceId',
// 'resourceName',
],
data () {
return {
os: null,
php: null,
database: null,
}
},
mounted() {
Nova.request().get('/nova-vendor/kussie/version-card/versions')
.then(({data}) => {
this.os = data.os
this.php = data.php
this.database = data.database
this.laravel = data.laravel
this.nova = data.nova
})
},
}
</script>
17 changes: 17 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Card API Routes
|--------------------------------------------------------------------------
|
| Here is where you may register API routes for your card. These routes
| are loaded by the ServiceProvider of your card. You're free to add
| as many additional routes to this file as your card may require.
|
*/

Route::get('versions', \Kussie\VersionCard\Http\Controllers\VersionController::class.'@versions');
Binary file added screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions src/CardServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace Kussie\VersionCard;

use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;
use Laravel\Nova\Events\ServingNova;
use Laravel\Nova\Nova;

class CardServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
$this->app->booted(function () {
$this->routes();
});

Nova::serving(function (ServingNova $event) {
Nova::script('version-card', __DIR__.'/../dist/js/card.js');
Nova::style('version-card', __DIR__.'/../dist/css/card.css');
});
}

/**
* Register the card's routes.
*
* @return void
*/
protected function routes()
{
if ($this->app->routesAreCached()) {
return;
}

Route::middleware(['nova'])
->prefix('nova-vendor/kussie/version-card')
->group(__DIR__.'/../routes/api.php');
}

/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
}
38 changes: 38 additions & 0 deletions src/Http/Controllers/VersionController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Kussie\VersionCard\Http\Controllers;

use DB;
use Laravel\Nova\Nova;

class VersionController
{
public function versions()
{
return [
'os' => php_uname('s') . ' (' . php_uname('r') . ' - ' . php_uname('v') . ')',
'php' => phpversion(),
'database' => $this->getDatabase(),
'laravel' => app()->version(),
'nova' => Nova::version(),
];
}

private function getDatabase()
{
$knownDatabases = [
'sqlite',
'mysql',
'pgsql',
'sqlsrv',
];

if (! in_array(config('database.default'), $knownDatabases)) {
return 'Unkown';
}

$results = DB::select(DB::raw("select version()"));

return $results[0]->{'version()'};
}
}
25 changes: 25 additions & 0 deletions src/VersionCard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Kussie\VersionCard;

use Laravel\Nova\Card;

class VersionCard extends Card
{
/**
* The width of the card (1/3, 1/2, or full).
*
* @var string
*/
public $width = '1/2';

/**
* Get the component name for the element.
*
* @return string
*/
public function component()
{
return 'version-card';
}
}
22 changes: 22 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Kussie\VersionCard\Tests;

use Illuminate\Support\Facades\Route;
use Orchestra\Testbench\TestCase as Orchestra;
use Kussie\VersionCard\CardServiceProvider;

abstract class TestCase extends Orchestra
{
public function setUp()
{
parent::setUp();
Route::middlewareGroup('nova', []);
}
protected function getPackageProviders($app)
{
return [
CardServiceProvider::class,
];
}
}
17 changes: 17 additions & 0 deletions tests/VersionControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Kussie\VersionCard\Tests;

class VersionControllerTest extends TestCase
{
/** @test */
public function it_returns_system_information()
{
$content = $this->get('nova-vendor/kussie/nova-version-card/versions')
->getContent();

$systemInfo = json_decode($content, true);

$this->assertSame(app()->version(), $systemInfo['laravel']);
}
}
10 changes: 10 additions & 0 deletions webpack.mix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
let mix = require('laravel-mix')

require('./mix')

mix
.setPublicPath('dist')
.js('resources/js/card.js', 'js')
.vue({ version: 3 })
.css('resources/css/card.css', 'css')
.nova('kussie/nova-version-card')

0 comments on commit 5a37cbe

Please sign in to comment.