-
Notifications
You must be signed in to change notification settings - Fork 600
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat-views' of https://github.com/barryvdh/telescope in…
…to barryvdh-feat-views
- Loading branch information
Showing
11 changed files
with
268 additions
and
0 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
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,40 @@ | ||
<script type="text/ecmascript-6"> | ||
import StylesMixin from './../../mixins/entriesStyles'; | ||
export default { | ||
mixins: [ | ||
StylesMixin, | ||
], | ||
} | ||
</script> | ||
|
||
<template> | ||
<index-screen title="Views" resource="views"> | ||
<tr slot="table-header"> | ||
<th scope="col">Name</th> | ||
<th scope="col">Path</th> | ||
<th scope="col">Happened</th> | ||
<th scope="col"></th> | ||
</tr> | ||
|
||
|
||
<template slot="row" slot-scope="slotProps"> | ||
|
||
<td class="table-fit"> | ||
{{slotProps.entry.content.name}} | ||
</td> | ||
|
||
<td>{{truncate(slotProps.entry.content.path, 80)}}</td> | ||
|
||
<td class="table-fit" :data-timeago="slotProps.entry.created_at">{{timeAgo(slotProps.entry.created_at)}}</td> | ||
|
||
<td class="table-fit"> | ||
<router-link :to="{name:'view-preview', params:{id: slotProps.entry.id}}" class="control-action"> | ||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 22 16"> | ||
<path d="M16.56 13.66a8 8 0 0 1-11.32 0L.3 8.7a1 1 0 0 1 0-1.42l4.95-4.95a8 8 0 0 1 11.32 0l4.95 4.95a1 1 0 0 1 0 1.42l-4.95 4.95-.01.01zm-9.9-1.42a6 6 0 0 0 8.48 0L19.38 8l-4.24-4.24a6 6 0 0 0-8.48 0L2.4 8l4.25 4.24h.01zM10.9 12a4 4 0 1 1 0-8 4 4 0 0 1 0 8zm0-2a2 2 0 1 0 0-4 2 2 0 0 0 0 4z"></path> | ||
</svg> | ||
</router-link> | ||
</td> | ||
</template> | ||
</index-screen> | ||
</template> |
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,48 @@ | ||
<script type="text/ecmascript-6"> | ||
import _ from 'lodash'; | ||
import StylesMixin from './../../mixins/entriesStyles'; | ||
export default { | ||
mixins: [ | ||
StylesMixin, | ||
], | ||
data(){ | ||
return { | ||
entry: null, | ||
batch: [], | ||
}; | ||
}, | ||
} | ||
</script> | ||
|
||
<template> | ||
<preview-screen title="View Action" resource="views" :id="$route.params.id"> | ||
<template slot="table-parameters" slot-scope="slotProps"> | ||
<tr> | ||
<td class="table-fit font-weight-bold">View</td> | ||
<td> | ||
{{slotProps.entry.content.name}} | ||
</td> | ||
</tr> | ||
|
||
<tr> | ||
<td class="table-fit font-weight-bold">Path</td> | ||
<td> | ||
{{slotProps.entry.content.path}} | ||
</td> | ||
</tr> | ||
</template> | ||
|
||
<div slot="after-attributes-card" slot-scope="slotProps"> | ||
<div class="card mt-5" v-if="slotProps.entry.content.data"> | ||
<div class="card-header"><h5>Data</h5></div> | ||
|
||
<div class="code-bg p-4 mb-0 text-white"> | ||
<vue-json-pretty :data="slotProps.entry.content.data"></vue-json-pretty> | ||
</div> | ||
</div> | ||
</div> | ||
</preview-screen> | ||
</template> |
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,29 @@ | ||
<?php | ||
|
||
namespace Laravel\Telescope\Http\Controllers; | ||
|
||
use Laravel\Telescope\EntryType; | ||
use Laravel\Telescope\Watchers\ViewWatcher; | ||
|
||
class ViewsController extends EntryController | ||
{ | ||
/** | ||
* The entry type for the controller. | ||
* | ||
* @return string | ||
*/ | ||
protected function entryType() | ||
{ | ||
return EntryType::VIEW; | ||
} | ||
|
||
/** | ||
* The watcher class for the controller. | ||
* | ||
* @return string | ||
*/ | ||
protected function watcher() | ||
{ | ||
return ViewWatcher::class; | ||
} | ||
} |
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,76 @@ | ||
<?php | ||
|
||
namespace Laravel\Telescope\Watchers; | ||
|
||
use Illuminate\View\View; | ||
use Illuminate\Support\Str; | ||
use Laravel\Telescope\Telescope; | ||
use Laravel\Telescope\IncomingEntry; | ||
|
||
class ViewWatcher extends Watcher | ||
{ | ||
/** | ||
* Register the watcher. | ||
* | ||
* @param \Illuminate\Contracts\Foundation\Application $app | ||
* @return void | ||
*/ | ||
public function register($app) | ||
{ | ||
$app['events']->listen($this->options['events'] ?? 'composing:*', [$this, 'recordAction']); | ||
} | ||
|
||
/** | ||
* Record an action. | ||
* | ||
* @param string $event | ||
* @param array $data | ||
* @return void | ||
*/ | ||
public function recordAction($event, $data) | ||
{ | ||
if (! Telescope::isRecording()) { | ||
return; | ||
} | ||
|
||
/** @var View $view */ | ||
$view = $data[0]; | ||
|
||
Telescope::recordView(IncomingEntry::make(array_filter([ | ||
'name' => $view->getName(), | ||
'path' => $this->extractPath($view), | ||
'data' => $this->extractKeysFromData($view), | ||
]))); | ||
} | ||
|
||
/** | ||
* Extract the path from the given view. | ||
* | ||
* @param \Illuminate\View\View $view | ||
* @return string | ||
*/ | ||
protected function extractPath($view) | ||
{ | ||
$path = $view->getPath(); | ||
|
||
if (Str::startsWith($path, base_path())) { | ||
$path = substr($path, strlen(base_path())); | ||
} | ||
|
||
return $path; | ||
} | ||
|
||
|
||
/** | ||
* Extract the keys from the given view in array form. | ||
* | ||
* @param \Illuminate\View\View $view | ||
* @return array | ||
*/ | ||
protected function extractKeysFromData($view) | ||
{ | ||
return collect($view->getData())->filter(function ($value, $key) { | ||
return ! in_array($key, ['app', '__env', 'obLevel', 'errors']); | ||
})->keys(); | ||
} | ||
} |