-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f414213
commit 54fb9af
Showing
11 changed files
with
365 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"extends": "stylelint-config-recommended", | ||
"rules": { | ||
"at-rule-no-unknown": [ true, { | ||
"ignoreAtRules": [ | ||
"screen", | ||
"extends", | ||
"responsive", | ||
"tailwind" | ||
] | ||
}], | ||
"block-no-empty": null, | ||
"no-descending-specificity": null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"/utilities/dist/js/app.js": "/utilities/dist/js/app.js" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
/** | ||
* Reporter plugin for Craft CMS 3.x | ||
* | ||
* Reporter plugin for Craft CMS. | ||
* | ||
* @link https://www.webmenedzser.hu | ||
* @copyright Copyright (c) 2020 Ottó Radics | ||
*/ | ||
|
||
namespace webmenedzser\reporter\assetbundles\utilities; | ||
|
||
use craft\web\AssetBundle; | ||
use craft\web\assets\cp\CpAsset; | ||
|
||
/** | ||
* Asset bundle for Restore Utility | ||
*/ | ||
class RestoreUtilityAsset extends AssetBundle | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public $sourcePath = __DIR__ . '/dist'; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public $depends = [ | ||
CpAsset::class, | ||
]; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public $js = [ | ||
'js/app.js', | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import Vue from 'vue'; | ||
|
||
Vue.component('restoreform', require('../vue/RestoreForm').default); | ||
|
||
const app = document.getElementById('craft-reporter-vue'); | ||
if (app) { | ||
new Vue({ | ||
el: app | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Configure the GraphQL api endpoint | ||
export const axiosConfiguration = (url) => ({ | ||
baseURL: url, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
<template> | ||
<div class="restore-form"> | ||
<div class="progress pane" v-if="this.status === 'loading'"> | ||
<div class="spinner"></div> | ||
|
||
<div class="progress-text"> | ||
Restoring... | ||
</div> | ||
</div> | ||
|
||
<div class="result pane" v-if="this.status === 'finished' || this.status === 'error'"> | ||
<div class="" v-if="this.status === 'finished'"> | ||
<p> | ||
<span class="checkmark-icon"></span> | ||
|
||
<span class="progress-text"> | ||
Done! | ||
</span> | ||
</p> | ||
</div> | ||
|
||
<code v-else> | ||
{{ this.result }} | ||
</code> | ||
</div> | ||
|
||
<button | ||
@click="startDbRestore" | ||
class="btn submit" | ||
:class="this.status === 'loading' ? 'disabled' : ''" | ||
:disabled="this.status === 'loading'" | ||
v-if="this.propKey" | ||
> | ||
Restore Database | ||
</button> | ||
|
||
<div class="btn submit disabled" disabled="disabled" v-else> | ||
Craft Report API Key is missing! | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import axios from 'axios'; | ||
import { axiosConfiguration } from '../js/utils.js'; | ||
export default { | ||
name: 'RestoreForm', | ||
props: { | ||
propActionUrl: { | ||
default: '', | ||
type: String | ||
}, | ||
propCsrfToken: { | ||
default: '', | ||
type: String | ||
}, | ||
propKey: { | ||
default: '', | ||
type: String | ||
} | ||
}, | ||
computed: { | ||
result() { | ||
return this.response.message ?? this.response.statusText ?? ''; | ||
}, | ||
status() { | ||
if (this.loading === true) { | ||
return 'loading'; | ||
} | ||
if (this.result === 'OK') { | ||
return 'finished'; | ||
} | ||
if (this.result) { | ||
return 'error'; | ||
} | ||
return 'ready'; | ||
} | ||
}, | ||
data() { | ||
return { | ||
loading: false, | ||
response: {} | ||
} | ||
}, | ||
methods: { | ||
startDbRestore() { | ||
if (!confirm('Are you sure want to restore your last backup from Craft Report? This will destroy your current database.')) { | ||
return; | ||
} | ||
const api = axios.create(axiosConfiguration(this.propActionUrl)); | ||
this.loading = true; | ||
api.post('', { | ||
csrfToken: this.propCsrfToken | ||
}).then(response => { | ||
this.response = response; | ||
this.loading = false; | ||
}).catch(error => { | ||
this.response = error; | ||
this.loading = false; | ||
}); | ||
} | ||
}, | ||
}; | ||
</script> | ||
<style> | ||
.progress, | ||
.result { | ||
margin-top: 2rem; | ||
margin-bottom: 2rem; | ||
} | ||
.progress { | ||
display: flex; | ||
align-items: center; | ||
justify-content: start; | ||
} | ||
.progress-text { | ||
margin-left: 1rem; | ||
font-weight: bold; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{% import "_includes/forms" as forms %} | ||
|
||
{% set canRestore = currentUser.can('craft-reporter:restore-utility') ?? false %} | ||
{% do view.registerAssetBundle("webmenedzser\\reporter\\assetbundles\\utilities\\RestoreUtilityAsset") %} | ||
|
||
{% block content %} | ||
{% if canRestore %} | ||
<p class="light"> | ||
{{ 'You can restore the last Database Backup from Craft Report.' | t('craft-reporter') }} | ||
</p> | ||
|
||
<div id="craft-reporter-vue"> | ||
<RestoreForm | ||
prop-action-url="{{ actionUrl('craft-reporter/backup/restore') }}" | ||
prop-csrf-token="{{ craft.app.request.csrfToken }}" | ||
prop-key="{{ settings.apiKey }}" | ||
></RestoreForm> | ||
</div> | ||
{% else %} | ||
<p class="light"> | ||
{{ 'You don\'t have permissions to restore Database Backup from Craft Report.' | t('craft-reporter') }} | ||
</p> | ||
{% endif %} | ||
{% endblock %} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
/** | ||
* Reporter plugin for Craft CMS 3.x | ||
* | ||
* Reporter plugin for Craft CMS. | ||
* | ||
* @link https://www.webmenedzser.hu | ||
* @copyright Copyright (c) 2020 Ottó Radics | ||
*/ | ||
|
||
namespace webmenedzser\reporter\utilities; | ||
|
||
use webmenedzser\reporter\assetbundles\utilities\RestoreUtilityAsset; | ||
use webmenedzser\reporter\Reporter; | ||
|
||
use Craft; | ||
use craft\base\Utility; | ||
|
||
/** | ||
* Class RestoreUtility | ||
* | ||
* @package webmenedzser\reporter\utilities | ||
* @since: 1.10.0 | ||
*/ | ||
class RestoreUtility extends Utility | ||
{ | ||
public static function displayName() : string | ||
{ | ||
return Craft::t('craft-reporter', 'Restore Database Backup'); | ||
} | ||
|
||
public static function id() : string | ||
{ | ||
return 'craft-reporter-restore-utility'; | ||
} | ||
|
||
public static function iconPath() | ||
{ | ||
return Craft::getAlias('@vendor/webmenedzser/craft-reporter/src/icon-mask.svg'); | ||
} | ||
|
||
public static function contentHtml() : string | ||
{ | ||
$view = Craft::$app->getView(); | ||
|
||
return Craft::$app->getView()->renderTemplate('craft-reporter/_restore-utility', [ | ||
'settings' => Reporter::$plugin->getSettings(), | ||
]); | ||
} | ||
} |
Oops, something went wrong.