Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbjr committed Jun 10, 2024
0 parents commit a659a5e
Show file tree
Hide file tree
Showing 29 changed files with 1,115 additions and 0 deletions.
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
30 changes: 30 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "coreproc/nova-artisan-cards",
"description": "A Laravel Nova card.",
"keywords": [
"laravel",
"nova"
],
"license": "MIT",
"require": {
"php": "^7.3|^8.0",
"spatie/laravel-backup": "^8.8"
},
"autoload": {
"psr-4": {
"Coreproc\\NovaArtisanCards\\": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"Coreproc\\NovaArtisanCards\\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 @@

2 changes: 2 additions & 0 deletions dist/js/card.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/js/card.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
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 nova.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())
23 changes: 23 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"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",
"nova:install": "npm --prefix='../../vendor/laravel/nova' ci"
},
"dependencies": {
"laravel-nova-ui": "0.4.10"
},
"devDependencies": {
"@vue/compiler-sfc": "^3.2.22",
"laravel-mix": "^6.0.41",
"luxon": "^1.28.1",
"postcss": "^8.3.11",
"vue-loader": "^16.8.3"
}
}
1 change: 1 addition & 0 deletions postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {}
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 */
11 changes: 11 additions & 0 deletions resources/js/card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import MigrateFreshCard from "./components/MigrateFresh/MigrateFreshCard.vue";
import MaintenanceModeCard from "./components/MaintenanceMode/MaintenanceModeCard.vue";
import MaintenanceModeWarningCard from "./components/MaintenanceMode/MaintenanceModeWarningCard.vue";
import DatabaseBackupCard from "./components/DatabaseBackup/DatabaseBackupCard.vue";

Nova.booting((app, store) => {
app.component('nova-artisan-migrate-fresh-card', MigrateFreshCard)
app.component('nova-artisan-maintenance-mode-card', MaintenanceModeCard)
app.component('nova-artisan-maintenance-mode-warning-card', MaintenanceModeWarningCard)
app.component('nova-artisan-database-backup-card', DatabaseBackupCard)
})
101 changes: 101 additions & 0 deletions resources/js/components/DatabaseBackup/DatabaseBackupCard.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<template>
<Card class="flex flex-col justify-center min-h-8">
<div class="px-4 py-4 flex justify-between items-center">
<div class="flex-grow pr-2">
<h3 class="text-lg font-bold">Database Backup</h3>
<p>
This will create a database backup in the following disks:
<span class="font-bold">{{ card.backup_disks }}</span>
</p>
<br/>
<p class="text-xs" v-if="card.last_database_backup_at">Last database backup was generated at <span
class="font-bold">{{ lastDatabaseBackupAt }}</span></p>
</div>
<div class="shrink-0 ml-4">
<Button
@click="showModal = true"
ref="confirmButton"
state="default"
>
Backup Database
</Button>
</div>
</div>
<ConfirmActionModal
:show="showModal"
title="Create Database Backup"
:message="'Are you sure you want to create a backup of the database? These will saved in the following disks: '+card.backup_disks"
@confirm="handleConfirm"
confirmButtonState="default"
confirmButtonText="Backup Database"
@close="handleClose"
/>
</Card>
</template>

<script>
import ConfirmActionModal from "../Modals/ConfirmActionModal.vue";
import {Button} from "laravel-nova-ui";
import {DateTime} from "luxon";
export default {
components: {Button, ConfirmActionModal},
props: [
'card',
// The following props are only available on resource detail cards...
// 'resource',
// 'resourceId',
// 'resourceName',
],
data() {
return {
loading: false,
showModal: false,
};
},
methods: {
async handleConfirm() {
this.loading = true;
try {
await Nova.request()
.post('/nova-vendor/nova-artisan-cards/artisan/database-backup', {
// Add any data you need to send with the request here
});
} catch (error) {
console.error('Error creating a database backup:', error);
alert('Error creating a database backup. Please try again later.')
// Handle error here
} finally {
this.showModal = false;
this.loading = false;
}
},
handleClose() {
this.showModal = false;
this.loading = false;
},
convertDateTime(dateTime) {
return DateTime.fromISO(dateTime)
.setZone(this.timezone)
.toLocaleString({
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
timeZoneName: 'short',
})
},
},
computed: {
lastDatabaseBackupAt() {
// if this.card.maintenance_mode_since doesn't have a value, return
if (!this.card.last_database_backup_at) {
return null;
}
return this.convertDateTime(this.card.last_database_backup_at)
},
},
};
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<template>
<div class="inline-block">
<Badge
class="whitespace-nowrap inline-flex items-center min-h-6 px-2 rounded-full uppercase text-xs font-bold whitespace-nowrap inline-flex items-center"
:class="{
'bg-red-100 text-red-600 dark:bg-red-400 dark:text-red-900': isDownForMaintenance,
'bg-green-100 text-green-600 dark:bg-green-400 dark:text-green-900': !isDownForMaintenance,
}"
>
<span class="mr-1 -ml-1">
<Icon
v-if="isDownForMaintenance"
:solid="true"
type="exclamation-circle"
/>
<Icon
v-if="!isDownForMaintenance"
:solid="true"
type="check-circle"
/>
</span>
{{ (isDownForMaintenance) ? 'Down' : 'Up' }}
</Badge>
</div>
</template>

<script>
export default {
props: {
isDownForMaintenance: Boolean,
}
}
</script>
Loading

0 comments on commit a659a5e

Please sign in to comment.