Skip to content

Commit 4cb6ede

Browse files
author
WaqasAr
committed
Content Search
1 parent 4443378 commit 4cb6ede

File tree

3 files changed

+78
-15
lines changed

3 files changed

+78
-15
lines changed

resources/js/components/IndexScreen.vue

+22-3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
3434
updateEntriesTimeout: null,
3535
updateEntriesTimer: 2500,
36+
content: '',
3637
};
3738
},
3839
@@ -46,6 +47,7 @@
4647
this.familyHash = this.$route.query.family_hash || '';
4748
4849
this.tag = this.$route.query.tag || '';
50+
this.content = this.$route.query.content || '';
4951
5052
this.loadEntries((entries) => {
5153
this.entries = entries;
@@ -89,6 +91,9 @@
8991
if (!this.$route.query.tag) {
9092
this.tag = '';
9193
}
94+
if (!this.$route.query.content) {
95+
this.content = '';
96+
}
9297
9398
this.ready = false;
9499
@@ -109,7 +114,8 @@
109114
'?tag=' + this.tag +
110115
'&before=' + this.lastEntryIndex +
111116
'&take=' + this.entriesPerRequest +
112-
'&family_hash=' + this.familyHash
117+
'&family_hash=' + this.familyHash +
118+
'&content=' + this.content
113119
).then(response => {
114120
this.lastEntryIndex = response.data.entries.length ? _.last(response.data.entries).sequence : this.lastEntryIndex;
115121
@@ -134,7 +140,9 @@
134140
axios.post(Telescope.basePath + '/telescope-api/' + this.resource +
135141
'?tag=' + this.tag +
136142
'&take=1' +
137-
'&family_hash=' + this.familyHash
143+
'&family_hash=' + this.familyHash +
144+
'&content=' + this.content
145+
138146
).then(response => {
139147
if (! this._isDestroyed) {
140148
this.recordingStatus = response.data.status;
@@ -180,7 +188,7 @@
180188
181189
clearTimeout(this.newEntriesTimeout);
182190
183-
this.$router.push({query: _.assign({}, this.$route.query, {tag: this.tag})});
191+
this.$router.push({query: _.assign({}, this.$route.query, {tag: this.tag,content:this.content})});
184192
});
185193
},
186194
@@ -271,6 +279,17 @@
271279
<div class="card-header d-flex align-items-center justify-content-between">
272280
<h2 class="h6 m-0">{{this.title}}</h2>
273281

282+
<div class="form-control-with-icon w-25" >
283+
<div class="icon-wrapper">
284+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" class="icon">
285+
<path fill-rule="evenodd" d="M9 3.5a5.5 5.5 0 100 11 5.5 5.5 0 000-11zM2 9a7 7 0 1112.452 4.391l3.328 3.329a.75.75 0 11-1.06 1.06l-3.329-3.328A7 7 0 012 9z" clip-rule="evenodd" />
286+
</svg>
287+
</div>
288+
<input type="text" class="form-control w-100"
289+
id="contentInput"
290+
placeholder="Search Content" v-model="content" @input.stop="search">
291+
</div>
292+
274293
<div class="form-control-with-icon w-25" v-if="!hideSearch && (tag || entries.length > 0)">
275294
<div class="icon-wrapper">
276295
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" class="icon">

src/Storage/EntryModel.php

+28-6
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,12 @@ class EntryModel extends Model
6565
public function scopeWithTelescopeOptions($query, $type, EntryQueryOptions $options)
6666
{
6767
$this->whereType($query, $type)
68-
->whereBatchId($query, $options)
69-
->whereTag($query, $options)
70-
->whereFamilyHash($query, $options)
71-
->whereBeforeSequence($query, $options)
72-
->filter($query, $options);
68+
->whereBatchId($query, $options)
69+
->whereTag($query, $options)
70+
->whereContent($query, $options)
71+
->whereFamilyHash($query, $options)
72+
->whereBeforeSequence($query, $options)
73+
->filter($query, $options);
7374

7475
return $query;
7576
}
@@ -116,7 +117,7 @@ protected function whereBatchId($query, EntryQueryOptions $options)
116117
protected function whereTag($query, EntryQueryOptions $options)
117118
{
118119
$query->when($options->tag, function ($query, $tag) {
119-
$tags = collect(explode(',', $tag))->map(fn ($tag) => trim($tag));
120+
$tags = collect(explode(',', $tag))->map(fn($tag) => trim($tag));
120121

121122
if ($tags->isEmpty()) {
122123
return $query;
@@ -133,6 +134,27 @@ protected function whereTag($query, EntryQueryOptions $options)
133134
return $this;
134135
}
135136

137+
/**
138+
* Scope the query for the given type.
139+
*
140+
* @param \Illuminate\Database\Eloquent\Builder $query
141+
* @param \Laravel\Telescope\Storage\EntryQueryOptions $options
142+
* @return $this
143+
*/
144+
protected function whereContent($query, EntryQueryOptions $options)
145+
{
146+
$query->when($options->content, function ($query, $content) {
147+
148+
if (empty ($content)) {
149+
return $query;
150+
}
151+
152+
return $query->where('content', 'LIKE', '%' . $content . '%');
153+
});
154+
155+
return $this;
156+
}
157+
136158
/**
137159
* Scope the query for the given type.
138160
*

src/Storage/EntryQueryOptions.php

+28-6
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ class EntryQueryOptions
4848
*/
4949
public $limit = 50;
5050

51+
/**
52+
* The number of entries to retrieve.
53+
*
54+
* @var string
55+
*/
56+
public $content;
57+
5158
/**
5259
* Create new entry query options from the incoming request.
5360
*
@@ -57,12 +64,14 @@ class EntryQueryOptions
5764
public static function fromRequest(Request $request)
5865
{
5966
return (new static)
60-
->batchId($request->batch_id)
61-
->uuids($request->uuids)
62-
->beforeSequence($request->before)
63-
->tag($request->tag)
64-
->familyHash($request->family_hash)
65-
->limit($request->take ?? 50);
67+
->batchId($request->batch_id)
68+
->uuids($request->uuids)
69+
->beforeSequence($request->before)
70+
->tag($request->tag)
71+
->familyHash($request->family_hash)
72+
->limit($request->take ?? 50)
73+
->content($request->content);
74+
6675
}
6776

6877
/**
@@ -153,4 +162,17 @@ public function limit(int $limit)
153162

154163
return $this;
155164
}
165+
166+
/**
167+
* Set the number of entries that should be retrieved.
168+
*
169+
* @param string $content
170+
* @return $this
171+
*/
172+
public function content(?string $content)
173+
{
174+
$this->content = $content;
175+
176+
return $this;
177+
}
156178
}

0 commit comments

Comments
 (0)