Skip to content

Commit

Permalink
Merge pull request #1645 from shhirose/view_redmie_for_plugin
Browse files Browse the repository at this point in the history
プラグイン一覧画面でREADMEを表示する
  • Loading branch information
Yangsin committed Dec 1, 2016
2 parents d815f19 + e7ee0b1 commit fbc1d9e
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/Eccube/Controller/Admin/Store/PluginController.php
Expand Up @@ -32,6 +32,7 @@
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Exception\RouteNotFoundException;
use Symfony\Component\Validator\Constraints as Assert;
Expand Down Expand Up @@ -301,6 +302,40 @@ public function uninstall(Application $app, $id)
return $app->redirect($app->url('admin_store_plugin'));
}

/**
* 対象プラグインの README を返却します。
*
* @param Application $app
* @param unknown $code
*/
public function readme(Application $app, Request $request, $id)
{
if ($request->isXmlHttpRequest()) {
$Plugin = $app['eccube.repository.plugin']->find($id);
if (!$Plugin) {
$response = new Response(json_encode('NG'), 400);
$response->headers->set('Content-Type', 'application/json');
return $response;
}

$code = $Plugin->getCode();
$readme = $app['config'][$code]['const']['readme'];
$data = array(
'code' => $code,
'name' => $Plugin->getName(),
'readme' => $readme,
);

$response = new Response(json_encode($data));
$response->headers->set('Content-Type', 'application/json');
return $response;
}

$response = new Response(json_encode('NG'), 400);
$response->headers->set('Content-Type', 'application/json');
return $response;
}

public function handler(Application $app)
{
$handlers = $app['eccube.repository.plugin_event_handler']->getHandlers();
Expand Down
1 change: 1 addition & 0 deletions src/Eccube/ControllerProvider/AdminControllerProvider.php
Expand Up @@ -223,6 +223,7 @@ public function connect(Application $app)
$c->put('/store/plugin/{id}/disable', '\Eccube\Controller\Admin\Store\PluginController::disable')->assert('id', '\d+')->bind('admin_store_plugin_disable');
$c->post('/store/plugin/{id}/update', '\Eccube\Controller\Admin\Store\PluginController::update')->assert('id', '\d+')->bind('admin_store_plugin_update');
$c->delete('/store/plugin/{id}/uninstall', '\Eccube\Controller\Admin\Store\PluginController::uninstall')->assert('id', '\d+')->bind('admin_store_plugin_uninstall');
$c->match('/store/plugin/{id}/readme', '\Eccube\Controller\Admin\Store\PluginController::readme')->assert('id', '\d+')->bind('admin_store_plugin_readme');
$c->match('/store/plugin/handler_up/{handlerId}', '\Eccube\Controller\Admin\Store\PluginController::handler_up')->bind('admin_store_plugin_handler_up');
$c->match('/store/plugin/handler_down/{handlerId}', '\Eccube\Controller\Admin\Store\PluginController::handler_down')->bind('admin_store_plugin_handler_down');
$c->match('/store/plugin/authentication_setting', '\Eccube\Controller\Admin\Store\PluginController::authenticationSetting')->bind('admin_store_authentication_setting');
Expand Down
38 changes: 38 additions & 0 deletions src/Eccube/Resource/template/admin/Store/plugin.twig
Expand Up @@ -33,6 +33,27 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
document.forms[form_name].action = action;
document.forms[form_name].submit();
}
$(function(){
$('[data-readme]').on('click', function() {
var url = '{{ url('admin_store_plugin_readme', {'id': '999999'}) }}';
$.ajax({
type: 'GET',
url: url.replace('999999', $(this).data('readme')),
dataType: "json",
success: function(data) {
$(".prevention-masked").remove();
$('#readmeModalLabel').text(data.name);
$('#readmeContent').html(data.readme);
$('#readmeModal').modal('show');
},
error: function() {
$(".prevention-masked").remove();
alert('Failed to read README.');
}
});
return false;
});
});
</script>
{% endblock javascript %}

Expand Down Expand Up @@ -71,3 +92,20 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
</div><!-- /.col -->
</div>
{% endblock %}
{% block modal %}
<div class="modal" id="readmeModal" tabindex="-1" role="dialog" aria-labelledby="readmeModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><svg class="cb cb-close" aria-hidden="true"><use xlink:href="#cb-close"></svg></button>
<h4 class="modal-title" id="readmeModalLabel">{# プラグイン名 #}</h4>
</div>
<div class="modal-body">
<div class="form-group" id="readmeContent">
{# README #}
</div>
</div>
</div>
</div>
</div>
{% endblock %}
6 changes: 6 additions & 0 deletions src/Eccube/Resource/template/admin/Store/plugin_table.twig
Expand Up @@ -30,6 +30,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
<th>コード</th>
<th>アップデート</th>
<th>設定</th>
<th>README</th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -86,6 +87,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
<a href='{{configPages[Plugin.code]}}'>設定</a>
{% endif %}
</td>
<td class="tr text-center">
{% if attribute(app.config[Plugin.code].const, 'readme') is defined %}
<a class="prevention-mask view_readme" href="" data-readme="{{ Plugin.id }}">README</a>
{% endif %}
</td>
</tr>
</form>
{% endfor %}
Expand Down
Expand Up @@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
<th>コード</th>
<th>アップデート</th>
<th>設定</th>
<th>README</th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -59,6 +60,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
&nbsp;-&nbsp;
{% endif %}
</td>
<td class="tr text-center">
{% if attribute(app.config[Plugin.code].const, 'readme') is defined %}
<a class="prevention-mask view_readme" href="" data-readme="{{ Plugin.id }}">README</a>
{% endif %}
</td>
</tr>
</form>
{% endfor %}
Expand Down

0 comments on commit fbc1d9e

Please sign in to comment.