Skip to content

Commit

Permalink
add panel view for laravel-tracy
Browse files Browse the repository at this point in the history
  • Loading branch information
Recca Tsai committed Feb 14, 2016
1 parent 65bf134 commit 4fb739d
Show file tree
Hide file tree
Showing 14 changed files with 108 additions and 32 deletions.
8 changes: 8 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ elixir(function(mix) {
.copy([
], config.get('public.css.outputFolder'))
.copy([
// "resources/assets/vendor/jquery/dist/jquery.min.js",
// "resources/assets/vendor/jquery-mousewheel/jquery.mousewheel.min.js",
], config.get('public.js.outputFolder'))
.scripts([
"jquery/dist/jquery.js",
Expand All @@ -29,6 +31,12 @@ elixir(function(mix) {
"jquery.terminal/js/xml_formatting.js",
"jsvi/vi.js",
], config.get('public.js.outputFolder') + '/plugins.js', 'resources/assets/vendor')
.scripts([
"jquery.terminal/js/jquery.terminal-src.js",
"jquery.terminal/js/unix_formatting.js",
"jquery.terminal/js/xml_formatting.js",
"jsvi/vi.js",
], config.get('public.js.outputFolder') + '/terminal.js', 'resources/assets/vendor')
.sass([
'app.scss'
], config.get('public.css.outputFolder') + '/app.css', {
Expand Down
2 changes: 1 addition & 1 deletion public/css/app.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion public/js/app.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions public/js/jquery.min.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions public/js/jquery.mousewheel.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions public/js/terminal.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions resources/assets/coffee/app.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,6 @@ do ($ = jQuery, window, document) ->

win = $(window)
win.on "resize", =>
@element.width(win.width())
@element.height(win.height())
@element.width(@element.parent().width())
@element.height(@element.parent().height())
win.trigger "resize"
19 changes: 5 additions & 14 deletions resources/assets/sass/app.scss
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
@import 'jquery.terminal/css/jquery.terminal';
@import 'jsvi/vi';

html,
body
{
overflow: hidden;

width: 100%;
height: 100%;
margin: 0;
padding: 0;

background: #000;
}

#shell
{
min-width: 480px;
Expand All @@ -30,7 +17,11 @@ body

.editor
{
z-index: 5;
z-index: 40000;
pre {
background-color: inherit;
border: inherit;
}
}

.editorcursor
Expand Down
9 changes: 9 additions & 0 deletions resources/views/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
<meta name="csrf-token" content="{{ csrf_token() }}">
<title>Terminal</title>
<link href="{{ asset('vendor/terminal/css/app.css') }}" rel="stylesheet"/>
<style>
html, body{
width: 100%;
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
}
</style>
</head>
<body>
<textarea id="editor"></textarea>
Expand Down
30 changes: 30 additions & 0 deletions resources/views/panel.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<style>
{!! $style !!}
</style>

<textarea id="editor"></textarea>
<div id="shell"></div>

<script type="text/javascript">
if (!window.jQuery) {
{!! $jquery !!}
}
if (!window.jQuery.fn.mousewheel) {
{!! $mousewheel !!}
}
{!! $terminal !!}
{!! $script !!}
</script>

<script>
(function() {
{!! $script !!}
new Term("#shell", $.extend({!! $options !!}, {
editor: "#editor"
}));
})();
</script>
3 changes: 2 additions & 1 deletion src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Exception;
use Illuminate\Console\Application as ConsoleApplication;
use Illuminate\Console\Command;
use Illuminate\Console\Events\ArtisanStarting;
use Illuminate\Http\Request;
use Symfony\Component\Console\Command\Command as SymfonyCommand;
use Symfony\Component\Console\Formatter\OutputFormatter;
Expand Down Expand Up @@ -118,7 +119,7 @@ private function isFromArtisanStartingEvent()
{
// Illuminate\Console\Events\ArtisanStarting
if (is_null($this->laravel['events']) === false) {
return $this->laravel['events']->firing() !== false;
return $this->laravel['events']->firing() === ArtisanStarting::class;
}

return false;
Expand Down
33 changes: 25 additions & 8 deletions src/Http/Controllers/TerminalController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,31 @@
namespace Recca0120\Terminal\Http\Controllers;

use Illuminate\Contracts\Foundation\Application as ApplicationContract;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Recca0120\Terminal\Console\Kernel as ConsoleKernel;

class TerminalController extends Controller
{
protected $consoleKernel;

public function __construct(ConsoleKernel $consoleKernel)
{
$this->consoleKernel = $consoleKernel;
}

/**
* index.
*
* @param \Illuminate\Contracts\Foundation\Application $app
* @param \Recca0120\Terminal\Console\Kernel $consoleKernel
* @param \Illuminate\Filesystem\Filesystem $filesystem
*
* @return mixed
*/
public function index(ApplicationContract $app, ConsoleKernel $consoleKernel)
public function index(ApplicationContract $app, Filesystem $filesystem, $panel = false)
{
$consoleKernel->call('--ansi');
$this->consoleKernel->call('--ansi');
$options = json_encode([
'username' => 'LARAVEL',
'hostname' => php_uname('n'),
Expand All @@ -28,7 +36,7 @@ public function index(ApplicationContract $app, ConsoleKernel $consoleKernel)
'environment' => $app->environment(),
'version' => $app->version(),
'endPoint' => action('\\'.static::class.'@endPoint'),
'helpInfo' => $consoleKernel->output(),
'helpInfo' => $this->consoleKernel->output(),
'interpreters' => [
'mysql' => 'mysql',
'artisan tinker' => 'tinker',
Expand All @@ -46,27 +54,36 @@ public function index(ApplicationContract $app, ConsoleKernel $consoleKernel)
],
]);

if ($panel === true) {
$style = $filesystem->get(public_path('vendor/terminal/css/app.css'));
$jquery = $filesystem->get(public_path('vendor/terminal/js/jquery.min.js'));
$mousewheel = $filesystem->get(public_path('vendor/terminal/js/jquery.mousewheel.min.js'));
$terminal = $filesystem->get(public_path('vendor/terminal/js/terminal.js'));
$script = $filesystem->get(public_path('vendor/terminal/js/app.js'));

return view('terminal::panel', compact('options', 'style', 'jquery', 'mousewheel', 'terminal', 'script'));
}

return view('terminal::index', compact('options'));
}

/**
* rpc response.
*
* @param \Recca0120\Terminal\Console\Kernel $consoleKernel
* @param \Illuminate\Http\Request $request
*
* @return mixed
*/
public function endPoint(ConsoleKernel $consoleKernel, Request $request)
public function endPoint(Request $request)
{
$cmd = $request->get('cmd');
$command = array_get($cmd, 'command');
$status = $consoleKernel->call($command);
$status = $this->consoleKernel->call($command);

return response()->json([
'jsonrpc' => $request->get('jsonrpc'),
'id' => $request->get('id'),
'result' => $consoleKernel->output(),
'result' => $this->consoleKernel->output(),
'error' => $status,
]);
}
Expand Down
4 changes: 2 additions & 2 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ public function registerRoutes(Router $router)
{
if ($this->app->routesAreCached() === false) {
$prefix = 'terminal';
$middleware = (version_compare($this->app->version(), 5.2, '>=') === true) ? ['web'] : [];
// $middleware = (version_compare($this->app->version(), 5.2, '>=') === true) ? ['web'] : [];
$router->group([
'as' => 'terminal::',
'middleware' => $middleware,
// 'middleware' => $middleware,
'namespace' => $this->namespace,
'prefix' => $prefix,
], function () {
Expand Down
10 changes: 7 additions & 3 deletions tests/TerminalTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Illuminate\Filesystem\Filesystem;
use Illuminate\Http\Request;
use Mockery as m;
use Recca0120\Terminal\Console\Commands\Artisan;
use Recca0120\Terminal\Console\Commands\ArtisanTinker;
Expand Down Expand Up @@ -37,17 +39,19 @@ public function test_controller($arguments)
$kernel = $arguments[0];
$app = $arguments[1];

$controller = m::mock('Recca0120\Terminal\Http\Controllers\TerminalController')
$controller = m::mock(new Recca0120\Terminal\Http\Controllers\TerminalController($kernel))
->makePartial();

$request = m::mock('Illuminate\Http\Request')
->makePartial()
->shouldReceive('get')->andReturn(['command' => 'list'])
->mock();

$controller->index($app, $kernel);
$filesystem = new Filesystem();

$controller->endPoint($kernel, $request);
$controller->index($app, $filesystem);

$controller->endPoint($request);

return [$kernel, $app];
}
Expand Down

0 comments on commit 4fb739d

Please sign in to comment.