plugin/theme installation pages and placeholder task for actual installation

This commit is contained in:
Gert
2015-04-04 14:49:40 +02:00
parent a69759f275
commit b52d5462a5
12 changed files with 174 additions and 77 deletions

View File

@@ -10,7 +10,7 @@ use Grav\Common\Uri;
use Grav\Common\Page\Pages;
use Grav\Common\Page\Page;
use Grav\Common\Data;
use Grav\Common\GPM\Local\Packages as LocalPackages;
use Grav\Common\GPM\GPM;
use RocketTheme\Toolbox\File\File;
use RocketTheme\Toolbox\File\LogFile;
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
@@ -66,9 +66,9 @@ class Admin
public $user;
/**
* @var Packages
* @var Grav\Common\GPM\GPM
*/
public $localPackages;
protected $gpm;
/**
@@ -287,6 +287,15 @@ class Admin
return $data[$type];
}
public function gpm()
{
if (!$this->gpm) {
$this->gpm = new GPM();
}
return $this->gpm;
}
/**
* Converts dot notation to array notation.
*
@@ -317,13 +326,12 @@ class Admin
*
* @return array
*/
public function plugins()
public function plugins($local = true)
{
if (!$this->localPackages) {
$this->localPackages = new LocalPackages();
}
return $this->localPackages['plugins'];
$gpm = $this->gpm();
return $local ? $gpm->getInstalledPlugins() : $gpm->getRepositoryPlugins()->filter(function ($package, $slug) use ($gpm) {
return !$gpm->isPluginInstalled($slug);
});
}
/**
@@ -331,15 +339,12 @@ class Admin
*
* @return array
*/
public function themes()
public function themes($local = true)
{
if (!$this->localPackages) {
$this->localPackages = new LocalPackages();
}
return $this->localPackages['themes'];
$gpm = $this->gpm();
return $local ? $gpm->getInstalledThemes() : $gpm->getRepositoryThemes()->filter(function ($package, $slug) use ($gpm) {
return !$gpm->isThemeInstalled($slug);
});
}
/**

View File

@@ -328,6 +328,20 @@ class AdminController
return true;
}
/**
* Handles installing plugins and themes
*
* @return bool True is the action was performed
*/
public function taskInstall()
{
$mode = $this->view === 'plugins' ? 'plugin' : 'theme';
$package = $this->route;
$this->admin->setMessage("Actual installation is not hooked up to GPM yet.");
return true;
}
/**
* Handles form and saves the input data if its valid.
*

View File

@@ -1,6 +1,6 @@
@charset "UTF-8";
@import url(//fonts.googleapis.com/css?family=Montserrat:400|Lato:300,400,700|Ubuntu+Mono:400,700);
#admin-login, #admin-logo h3, #admin-main .titlebar h1, #admin-main .titlebar .button-bar, #admin-main .flush-bottom.button-bar .button, #admin-main .danger.button-bar .button, #admin-dashboard #updates .numeric, #admin-dashboard #popularity .stat, #admin-mode-toggle .switch-grav {
#admin-login, #admin-logo h3, #admin-main .titlebar h1, #admin-main .titlebar .button-bar, #admin-main .flush-bottom.button-bar .button, #admin-main .danger.button-bar .button, #admin-main .success.button-bar .button, #admin-dashboard #updates .numeric, #admin-dashboard #popularity .stat, #admin-mode-toggle .switch-grav {
position: relative;
top: 50%;
-webkit-transform: translateY(-50%);
@@ -943,21 +943,21 @@ tr {
height: 70px;
padding: 0 1rem;
float: none; }
#admin-main .danger {
#admin-main .danger, #admin-main .success {
position: relative; }
#admin-main .danger.button-bar {
#admin-main .danger.button-bar, #admin-main .success.button-bar {
margin: 2rem 0 -2rem;
height: 70px;
padding: 1rem;
float: none;
background: #e9e9e9; }
#admin-main .danger.button-bar .button {
background: #DA4B46;
color: rgba(255, 255, 255, 0.85);
border-radius: 4px; }
#admin-main .danger.button-bar .button:hover {
background: #de605b;
color: #fff; }
#admin-main .danger.button-bar .button {
background: #DA4B46;
color: rgba(255, 255, 255, 0.85);
border-radius: 4px; }
#admin-main .danger.button-bar .button:hover {
background: #de605b;
color: #fff; }
#admin-dashboard:after {
content: "";
@@ -1971,10 +1971,10 @@ button.toast-close-button {
font-size: 0.9rem; }
.gpm .gpm-update .gpm-name {
color: #349886; }
.gpm .gpm-actions {
.gpm .gpm-actions .enabled, .gpm .gpm-actions .disabled {
font-size: 1.6rem; }
.gpm .gpm-actions .disabled {
color: #8d959a; }
.gpm .gpm-actions .disabled {
color: #8d959a; }
.gpm .gpm-item-info {
position: relative;
border-bottom: 3px solid #e1e1e1;
@@ -2031,17 +2031,30 @@ button.toast-close-button {
background: #e9e9e9;
margin: 1rem -1rem -1rem -1rem;
height: 4rem;
line-height: 4rem;
text-align: right;
padding-right: 1rem; }
padding: 1rem; }
.gpm .themes .gpm-actions.active-theme {
font-size: 1rem;
font-weight: bold;
text-align: center;
background: #314D5B;
color: #EEEEEE; }
.gpm .themes .gpm-actions a {
color: #737C81;
vertical-align: middle; }
.gpm .themes .gpm-actions.active-theme, .gpm .themes .gpm-actions.inactive-theme {
line-height: 2rem; }
.gpm .themes .gpm-actions.active-theme a, .gpm .themes .gpm-actions.inactive-theme a {
color: #737C81; }
.log__line .severity {
border-radius: 10px;
padding: 10px; }
.log__line .severity.debug, .log__line .severity.info {
background-color: #737C81;
color: #EEEEEE; }
.log__line .severity.notice, .log__line .severity.warning {
background-color: #0082BA;
color: #fff; }
.log__line .severity.error, .log__line .severity.critical, .log__line .severity.alert, .log__line .severity.emergency {
background-color: #DA4B46;
color: #fff; }
/*# sourceMappingURL=template.css.map */

File diff suppressed because one or more lines are too long

View File

@@ -282,7 +282,7 @@ $update-height: 3rem;
}
}
.danger {
.danger, .success {
position: relative;
&.button-bar {
@@ -292,11 +292,18 @@ $update-height: 3rem;
float: none;
.button {
@extend %vertical-align;
@include button-color($secondary-link);
}
background: darken($content-bg, 2%);
}
}
.danger {
&.button-bar {
.button {
@include button-color($secondary-link);
}
}
}
}

View File

@@ -18,7 +18,10 @@
}
.gpm-actions {
font-size: 1.6rem;
.enabled, .disabled {
font-size: 1.6rem;
}
.disabled {
color: lighten($content-fg,10%);
@@ -98,9 +101,8 @@
background: darken($content-bg, 2%);
margin: 1rem -1rem -1rem -1rem;
height: 4rem;
line-height: 4rem;
text-align: right;
padding-right: 1rem;
padding: 1rem;
&.active-theme {
font-size: 1rem;
@@ -109,13 +111,15 @@
background: $page-bg;
color: $content-bg;
}
&.active-theme, &.inactive-theme {
line-height: 2rem;
a {
color: $content-fg;
vertical-align: middle;
a {
color: $content-fg;
}
}
}
.active-theme {

View File

@@ -1,6 +1,8 @@
{% set gpm = admin.gpm() %}
{% set installed = gpm.isPluginInstalled(admin.route) %}
<div class="grav-update plugin" data-gpm-plugin="{{ admin.route }}">
{% if gpm.isPluginUpdatable(admin.route) %}
{% if installed and gpm.isPluginUpdatable(admin.route) %}
{% set remote = gpm.getRepositoryPlugin(admin.route) %}
<p>
<i class="fa fa-bullhorn"></i>
@@ -77,10 +79,16 @@
</table>
</div>
{% set data = admin.data('plugins/' ~ admin.route) %}
{% include 'partials/blueprints.html.twig' with { data: data, blueprints: data.blueprints } %}
{% if (installed) %}
{% set data = admin.data('plugins/' ~ admin.route) %}
{% include 'partials/blueprints.html.twig' with { data: data, blueprints: data.blueprints } %}
<div class="button-bar danger">
<span class="danger-zone"></span>
<a class="button" href="#"><i class="fa fa-fw fa-warning"></i>Remove Plugin</a>
</div>
<div class="button-bar danger">
<span class="danger-zone"></span>
<a class="button" href="#"><i class="fa fa-fw fa-warning"></i>Remove Plugin</a>
</div>
{% else %}
<div class="button-bar success">
<a class="button" href="{{ base_url_relative }}/plugins/{{ plugin.slug }}/task:install"><i class="fa fa-fw fa-plus"></i>Install Plugin</a>
</div>
{% endif %}

View File

@@ -1,11 +1,11 @@
<div class="grav-update plugins"></div>
<h1>
Installed Plugins
{{ installing ? 'Available' : 'Installed' }} Plugins
</h1>
<table>
{% for slug, package in admin.plugins %}
{% for slug, package in admin.plugins(not installing) %}
{% set plugin = package.toArray() %}
{% set data = admin.data('plugins/' ~ slug) %}
@@ -21,10 +21,12 @@
<span class="gpm-version">v{{ plugin.version }}</span>
</td>
<td class="gpm-actions">
{% if (plugin.form.fields.enabled) %}
{% if (not installing and plugin.form.fields.enabled) %}
<a class="{{ data.get('enabled') ? 'enabled' : 'disabled' }}" href="{{ base_url_relative }}/plugins/{{ slug }}/task:{{ data.get('enabled') ? 'disable' : 'enable' }}">
<i class="fa fa-fw fa-toggle-{{ data.get('enabled') ? 'on' : 'off' }}"></i>
</a>
{% elseif (installing) %}
<a class="button" href="{{ base_url_relative }}/plugins/{{ slug }}/task:install"><i class="fa fa-plus"></i> Install</a>
{% endif %}
</td>
</tr>

View File

@@ -1,6 +1,8 @@
{% set gpm = admin.gpm() %}
{% set installed = gpm.isPluginInstalled(admin.route) %}
<div class="grav-update theme" data-gpm-theme="{{ admin.route }}">
{% if gpm.isThemeUpdatable(admin.route) %}
{% if installed and gpm.isThemeUpdatable(admin.route) %}
{% set remote = gpm.getRepositoryTheme(admin.route) %}
<p>
<i class="fa fa-bullhorn"></i>
@@ -82,10 +84,20 @@
</table>
</div>
{% set data = admin.data('themes/' ~ admin.route) %}
{% include 'partials/blueprints.html.twig' with { data: data, blueprints: data.blueprints } %}
{% if (installed) %}
{% set data = admin.data('themes/' ~ admin.route) %}
{% include 'partials/blueprints.html.twig' with { data: data, blueprints: data.blueprints } %}
<div class="button-bar danger">
<span class="danger-zone"></span>
<a class="button" href="#"><i class="fa fa-fw fa-warning"></i>Remove Theme</a>
</div>
{% else %}
<div class="button-bar success">
<a class="button" href="{{ base_url_relative }}/themes/{{ theme.slug }}/task:install"><i class="fa fa-fw fa-plus"></i>Install Theme</a>
</div>
{% endif %}
<div class="button-bar danger">
<span class="danger-zone"></span>
<a class="button" href="#"><i class="fa fa-fw fa-warning"></i>Remove Theme</a>
</div>

View File

@@ -1,11 +1,11 @@
<div class="grav-update themes"></div>
<h1>
Installed Themes
{{ installing ? 'Available' : 'Installed' }} Themes
</h1>
<div class="themes card-row grid fixed-blocks pure-g">
{% for slug, package in admin.themes %}
{% for slug, package in admin.themes(not installing) %}
{% set theme = package.toArray() %}
<div class="theme card-item pure-u-1-3" data-gpm-theme="{{ slug|url_encode }}">
@@ -22,15 +22,21 @@
<div class="gpm-screenshot">
<a href="{{ base_url_relative }}/themes/{{ slug|url_encode }}"><img src="{{ theme.thumbnail }}" /></a>
</div>
{% if config.get('system.pages.theme') == slug %}
{% if (installing) %}
<div class="gpm-actions">
<a class="button" href="{{ base_url_relative }}/themes/{{ slug }}/task:install"><i class="fa fa-plus"></i> Install</a>
</div>
{% elseif config.get('system.pages.theme') == slug %}
<div class="gpm-actions active-theme">
<i class="fa fa-star"></i> Active Theme
</div>
{% else %}
<div class="gpm-actions">
<a href="{{ base_url_relative }}/themes/{{ slug }}/task:activate"><i class="fa fa-fw fa-toggle-off"></i></a>
<div class="gpm-actions inactive-theme">
<a class="disabled" href="{{ base_url_relative }}/themes/{{ slug }}/task:activate"><i class="fa fa-fw fa-toggle-off"></i></a>
</div>
{% endif %}
</div>
{% endfor %}
</div>

View File

@@ -1,20 +1,33 @@
{% extends 'partials/base.html.twig' %}
{% if admin.route %}
{% set package = admin.plugins[admin.route] %}
{% set plugin = package.toArray() %}
{% set installing = admin.route starts with 'install' %}
{% set installed = true %}
{# Try installed packages first, then remote #}
{% set package = admin.plugins(true)[admin.route] %}
{% if (not package) %}
{% set package = admin.plugins(false)[admin.route] %}
{% set installed = false %}
{% endif %}
{% set plugin = package.toArray() %}
{% endif %}
{% block titlebar %}
{% if not admin.route %}
{% if not admin.route or installing %}
{% if (not installing) %}
<div class="button-bar">
<button class="button" type="submit" name="task" value="add"><i class="fa fa-plus"></i> Add</button>
<a class="button" href="{{ base_url_relative }}/plugins/install"><i class="fa fa-plus"></i> Add</a>
</div>
{% endif %}
<h1><i class="fa fa-fw fa-plug"></i> Plugins</h1>
{% else %}
{% if (installed) %}
<div class="button-bar">
<button class="button" type="submit" name="task" value="save" form="blueprints"><i class="fa fa-check"></i> Save</button>
</div>
{% endif %}
<h1><i class="fa fa-fw fa-plug"></i> Plugin: {{ plugin.name|e }}</h1>
{% endif %}
{% endblock %}
@@ -25,7 +38,7 @@
{% include 'partials/messages.html.twig' %}
{% if not admin.route %}
{% if not admin.route or installing %}
{% include 'partials/plugins-list.html.twig' %}
{% else %}
{% include 'partials/plugins-details.html.twig' %}

View File

@@ -1,20 +1,33 @@
{% extends 'partials/base.html.twig' %}
{% if admin.route %}
{% set package = admin.themes[admin.route] %}
{% set installing = admin.route starts with 'install' %}
{% set installed = true %}
{# Try installed packages first, then remote #}
{% set package = admin.themes(true)[admin.route] %}
{% if (not package) %}
{% set package = admin.themes(false)[admin.route] %}
{% set installed = false %}
{% endif %}
{% set theme = package.toArray() %}
{% endif %}
{% block titlebar %}
{% if not admin.route %}
{% if not admin.route or installing %}
{% if (not installing) %}
<div class="button-bar">
<button class="button" type="submit" name="task" value="add"><i class="fa fa-plus"></i> Add</button>
<a class="button" href="{{ base_url_relative }}/themes/install"><i class="fa fa-plus"></i> Add</a>
</div>
{% endif %}
<h1><i class="fa fa-fw fa-plug"></i> Themes</h1>
{% else %}
{% if (installed) %}
<div class="button-bar">
<button class="button" type="submit" name="task" value="save" form="blueprints"><i class="fa fa-check"></i> Save</button>
</div>
{% endif %}
<h1><i class="fa fa-fw fa-plug"></i> Theme: {{ theme.name|e }}</h1>
{% endif %}
{% endblock %}
@@ -25,7 +38,7 @@
{% include 'partials/messages.html.twig' %}
{% if not admin.route %}
{% if not admin.route or installing %}
{% include 'partials/themes-list.html.twig' %}
{% else %}
{% include 'partials/themes-details.html.twig' %}