better dropdowns

This commit is contained in:
Andy Miller
2018-09-11 16:12:46 -06:00
parent b336ceb33d
commit d493194c4d
15 changed files with 120 additions and 48 deletions

View File

@@ -840,9 +840,9 @@ class AdminPlugin extends Plugin
public function onAdminTools(Event $event) public function onAdminTools(Event $event)
{ {
$event['tools'] = array_merge($event['tools'], [ $event['tools'] = array_merge($event['tools'], [
$this->grav['language']->translate('PLUGIN_ADMIN.DIRECT_INSTALL'), $this->grav['language']->translate('PLUGIN_ADMIN.BACKUPS'),
$this->grav['language']->translate('PLUGIN_ADMIN.SCHEDULER'), $this->grav['language']->translate('PLUGIN_ADMIN.SCHEDULER'),
$this->grav['language']->translate('PLUGIN_ADMIN.BACKUPS') $this->grav['language']->translate('PLUGIN_ADMIN.DIRECT_INSTALL'),
]); ]);
return $event; return $event;

View File

@@ -1386,6 +1386,69 @@ class AdminController extends AdminBaseController
return true; return true;
} }
/**
* Handle delete backup action
*
* @return bool
*/
protected function taskDeleteBackup()
{
$param_sep = $this->grav['config']->get('system.param_sep', ':');
if (!$this->authorizeTask('backup', ['admin.maintenance', 'admin.super'])) {
return false;
}
$backup = $this->grav['uri']->param('backup', null);
if (!is_null($backup)) {
$file = base64_decode(urldecode($backup));
$backups_root_dir = $this->grav['locator']->findResource('backup://', true);
$backup_path = $backups_root_dir . '/' . $file;
if (file_exists($backup_path)) {
unlink($backup_path);
$this->admin->json_response = [
'status' => 'success',
'message' => $this->admin->translate('PLUGIN_ADMIN.BACKUP_DELETED'),
'toastr' => [
'closeButton' => true
]
];
} else {
$this->admin->json_response = [
'status' => 'error',
'message' => $this->admin->translate('PLUGIN_ADMIN.BACKUP_NOT_FOUND'),
];
}
return true;
}
$download = urlencode(base64_encode($backup));
$url = rtrim($this->grav['uri']->rootUrl(true), '/') . '/' . trim($this->admin->base,
'/') . '/task' . $param_sep . 'backup/download' . $param_sep . $download . '/admin-nonce' . $param_sep . Utils::getNonce('admin-form');
$log->content([
'time' => time(),
'location' => $backup
]);
$log->save();
$this->admin->json_response = [
'status' => 'success',
'message' => $this->admin->translate('PLUGIN_ADMIN.YOUR_BACKUP_IS_READY_FOR_DOWNLOAD') . '. <a href="' . $url . '" class="button">' . $this->admin->translate('PLUGIN_ADMIN.DOWNLOAD_BACKUP') . '</a>',
'toastr' => [
'timeOut' => 0,
'extendedTimeOut' => 0,
'closeButton' => true
]
];
return true;
}
protected function taskGetChildTypes() protected function taskGetChildTypes()
{ {
if (!$this->authorizeTask('get childtypes', ['admin.pages', 'admin.super'])) { if (!$this->authorizeTask('get childtypes', ['admin.pages', 'admin.super'])) {

View File

@@ -99,6 +99,8 @@ PLUGIN_ADMIN:
BACKUPS_NEWEST: "Newest Backup" BACKUPS_NEWEST: "Newest Backup"
BACKUPS_OLDEST: "Oldest Backup" BACKUPS_OLDEST: "Oldest Backup"
BACKUPS_PURGE: "Purge" BACKUPS_PURGE: "Purge"
BACKUP_DELETED: "Backup Successfully Deleted"
BACKUP_NOT_FOUND: "Backup Not Found"
STATISTICS: "Statistics" STATISTICS: "Statistics"
TODAY: "Today" TODAY: "Today"
WEEK: "Week" WEEK: "Week"

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -255,7 +255,9 @@ tr {
&:focus, &:hover { &:focus, &:hover {
color: $button-text; color: $button-text;
background-color: $button-bg; &:hover {
background: tint($button-bg,15%);
}
} }
} }
@@ -1158,6 +1160,19 @@ form {
.button { .button {
@include button-color($secondary-accent-bg, $secondary-accent-fg); @include button-color($secondary-accent-bg, $secondary-accent-fg);
} }
.button-group {
.dropdown-menu {
background: $secondary-accent-bg;
li {
a {
&:hover {
background: tint($secondary-accent-bg,15%);
}
}
}
}
}
} }
.card-item { .card-item {

View File

@@ -765,8 +765,11 @@ body.sidebar-quickopen #admin-main {
display: flex; display: flex;
.button { .button {
@extend %vertical-align;
margin: 0; margin: 0;
&.dropdown-toggle {
margin-left: -4px;
}
} }
} }
} }

View File

@@ -1,6 +1,6 @@
%button { %button {
display: inline-block; display: inline-block;
padding: 0.3rem 1.5rem; padding: 0.5rem 1rem;
font-weight: 400; font-weight: 400;
cursor: pointer; cursor: pointer;
vertical-align: middle; vertical-align: middle;

View File

@@ -17,7 +17,6 @@
<td class="right pad">{{ backup.size|nicefilesize }}</td> <td class="right pad">{{ backup.size|nicefilesize }}</td>
<td class="right pad"> <td class="right pad">
<a class="button button-small hint--bottom" href="{{ grav.backups.getBackupDownloadUrl(backup.path, admin.base) }}" data-hint="Download"><i class="fa fa-download"></i></a> <a class="button button-small hint--bottom" href="{{ grav.backups.getBackupDownloadUrl(backup.path, admin.base) }}" data-hint="Download"><i class="fa fa-download"></i></a>
<a class="button button-small hint--bottom" data-hint="Re-run"><i class="fa fa-refresh"></i></a>
<a class="button button-small danger hint--bottom" data-hint="Delete"><i class="fa fa-close"></i></a> <a class="button button-small danger hint--bottom" data-hint="Delete"><i class="fa fa-close"></i></a>
</td> </td>
</tr> </tr>

View File

@@ -0,0 +1,21 @@
<div class="button-group">
{% set profiles = grav.backups.getBackupProfiles() %}
{% set backup_url = uri.addNonce(base_url_relative ~ "/backup.json/id:%BACKUP_ID/task" ~ config.system.param_sep ~ 'backup', 'admin-form', 'admin-nonce') %}
{% if profiles|length > 1 %}
<button class="button" href="#modal" data-remodal-target="modal" data-ajax="{{ backup_url|replace({'%BACKUP_ID':'0'}) }}">
<i class="fa fa-life-ring"></i> {{ "PLUGIN_ADMIN.BACKUP_NOW"|tu }}
</button>
<button type="button" class="button dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-caret-down"></i>
</button>
<ul class="dropdown-menu">
{% for id, profile in profiles %}
<li>
<a data-ajax="{{ backup_url|replace({'%BACKUP_ID':id}) }}" class="button">{{ profile.name }}</a>
</li>
{% endfor %}
</ul>
{% else %}
<button data-ajax="{{ backup_url|replace({'%BACKUP_ID':id}) }}" class="button"><i class="fa fa-life-ring"></i> {{ "PLUGIN_ADMIN.BACKUP_NOW"|tu }}</button>
{% endif %}
</div>

View File

@@ -23,21 +23,7 @@
<div class="flush-bottom button-bar"> <div class="flush-bottom button-bar">
<a class="button hidden" href="#" data-update-packages data-remodal-target="update-packages" data-plugin-action="start-packages-update"><i class="fa fa-cloud-download"></i> {{ "PLUGIN_ADMIN.UPDATE"|tu }}</a> <a class="button hidden" href="#" data-update-packages data-remodal-target="update-packages" data-plugin-action="start-packages-update"><i class="fa fa-cloud-download"></i> {{ "PLUGIN_ADMIN.UPDATE"|tu }}</a>
{% include 'partials/backups-button.html.twig' %}
<div class="button-group">
<button type="button" class="button disabled" href="#modal" data-remodal-target="modal">
<i class="fa fa-life-saver"></i> {{ "PLUGIN_ADMIN.BACKUP"|tu }}
</button><button type="button" class="button dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-caret-down"></i>
</button>
<ul class="dropdown-menu">
{% for id, profile in grav.backups.getBackupProfiles() %}
<li>
<a data-ajax="{{ uri.addNonce(base_url_relative ~ '/backup.json/id:' ~ id ~ '/task' ~ config.system.param_sep ~ 'backup', 'admin-form', 'admin-nonce') }}" class="button">{{ profile.name }}</a>
</li>
{% endfor %}
</ul>
</div>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -1,21 +1,6 @@
<div class="button-bar"> <div class="button-bar">
<a class="button" href="{{ base_url }}"><i class="fa fa-reply"></i> {{ "PLUGIN_ADMIN.BACK"|tu }}</a> <a class="button" href="{{ base_url }}"><i class="fa fa-reply"></i> {{ "PLUGIN_ADMIN.BACK"|tu }}</a>
<a class="button" href="{{ base_url }}"><i class="fa fa-trash"></i> {{ "PLUGIN_ADMIN.BACKUPS_PURGE"|tu }}</a> {% include 'partials/backups-button.html.twig' %}
<div class="button-group">
<button type="button" class="button disabled" href="#modal" data-remodal-target="modal">
<i class="fa fa-life-ring"></i> {{ "PLUGIN_ADMIN.BACKUP_NOW"|tu }}
</button>
<button type="button" class="button dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-caret-down"></i>
</button>
<ul class="dropdown-menu">
{% for id, profile in grav.backups.getBackupProfiles() %}
<li>
<a data-ajax="{{ uri.addNonce(base_url_relative ~ '/backup.json/id:' ~ id ~ '/task' ~ config.system.param_sep ~ 'backup', 'admin-form', 'admin-nonce') }}" class="button">{{ profile.name }}</a>
</li>
{% endfor %}
</ul>
</div>
<button class="button" type="submit" name="task" value="save" form="blueprints"><i class="fa fa-check"></i> {{ "PLUGIN_ADMIN.SAVE"|tu }}</button> <button class="button" type="submit" name="task" value="save" form="blueprints"><i class="fa fa-check"></i> {{ "PLUGIN_ADMIN.SAVE"|tu }}</button>
</div> </div>
<h1><i class="fa fa-fw fa-life-saver"></i> {{ "PLUGIN_ADMIN.BACKUPS"|tu }}</h1> <h1><i class="fa fa-fw fa-life-saver"></i> {{ "PLUGIN_ADMIN.BACKUPS"|tu }}</h1>

View File

@@ -1,8 +1,9 @@
{% extends 'partials/base.html.twig' %} {% extends 'partials/base.html.twig' %}
{% set tools_slug = uri.basename|e %} {% set tools_slug = uri.basename|e %}
{% if tools_slug == 'tools' %}{% set tools_slug = 'direct-install' %}{% endif %} {% if tools_slug == 'tools' %}{% set tools_slug = 'backups' %}{% endif %}
{% set title = "PLUGIN_ADMIN.TOOLS"|tu ~ ": " ~ ("PLUGIN_ADMIN." ~ tools_slug|underscorize|upper)|tu %} {% set title = "PLUGIN_ADMIN.TOOLS"|tu ~ ": " ~ ("PLUGIN_ADMIN." ~ tools_slug|underscorize|upper)|tu %}
{% set tools = admin.tools() %}
{% set titlebar -%} {% set titlebar -%}
{% include 'partials/tools-' ~ tools_slug ~ '-titlebar.html.twig' ignore missing %} {% include 'partials/tools-' ~ tools_slug ~ '-titlebar.html.twig' ignore missing %}
@@ -20,19 +21,16 @@
{% endblock %} {% endblock %}
{% block content_top %} {% block content_top %}
{% if tools|length > 1 %}
{% if admin.tools|length > 1 %}
<div class="form-tabs"> <div class="form-tabs">
<div class="tabs-nav"> <div class="tabs-nav">
{% for tool in admin.tools %} {% for tool in tools %}
<a href="{{ base_url_relative }}/tools/{{tool|hyphenize}}" {% if tools_slug == tool|hyphenize %}class="active"{% endif %}> <a href="{{ base_url_relative }}/tools/{{tool|hyphenize}}" {% if tools_slug == tool|hyphenize %}class="active"{% endif %}>
{{ tool|tu|capitalize }} {{ tool|tu|capitalize }}
</a> </a>
{% endfor %} {% endfor %}
</div> </div>
</div> </div>
{% endif %} {% endif %}
{% endblock %} {% endblock %}