Skip to content

Commit 9acde12

Browse files
Merge pull request #16 from alt-design/query-string-filtering
Query string filtering
2 parents 65a2900 + b7e6e0a commit 9acde12

File tree

11 files changed

+411
-66
lines changed

11 files changed

+411
-66
lines changed

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- Supports headers on redirects
1010
- Regex Redirects
1111
- Imports and Exports
12+
- URI Query String Stripping
1213

1314
## How to Install
1415

@@ -56,6 +57,48 @@ php artisan vendor:publish --tag=alt-redirect-config
5657

5758
In the `headers` property, you can provide an array of headers to be passed to the `redirect` method.
5859

60+
### Query String Stripping
61+
62+
This is a new feature we've added to remove query strings from URIs before they're processed by the redirect middleware.
63+
64+
Because redirects are URI-based, an unexpected query string on a link would've cause your redirects to not function.
65+
66+
With this feature, you can strip out troublesome query strings so your redirects work as intended.
67+
68+
The Query Strings functionality can be found in the nav as a child underneath the Alt Redirect Addon
69+
```
70+
- Alt Redirect
71+
- Query Strings <---
72+
```
73+
74+
On this page you can manage the query strings you wish to strip, simply :
75+
- add the key of the query string `( eg 'foo' for ?foo=bar )`
76+
- Select your site
77+
- Hit save
78+
79+
You'll see your query string in the list.
80+
81+
#### Defaults
82+
83+
We've provided a few default query strings that will be stripped.
84+
They're added as regular items when you install the addon.
85+
86+
If you don't want / need these, simply delete them!
87+
88+
#### Artisan Command
89+
90+
We have provided an Artisan command to force the creation of defaults.
91+
92+
This will "force" create them, so they'll be installed even if the defaults have already been installed.
93+
94+
This is great for if you've deleted the defaults but want them back or if composer didn't install them during the addon install for some reason.
95+
96+
Simple run the command below and confirm when it asks you too :
97+
98+
```bash
99+
php artisan alt-redirect:default-query-strings
100+
```
101+
59102
## Questions etc
60103

61104
Drop us a big shout-out if you have any questions, comments, or concerns. We're always looking to improve our addons, so if you have any feature requests, we'd love to hear them.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
title: Query Strings
2+
tabs:
3+
main:
4+
display: Main
5+
sections:
6+
-
7+
fields:
8+
-
9+
handle: query_string
10+
field:
11+
type: text
12+
validate:
13+
- required
14+
display: Query String Key
15+
instructions_position: above
16+
listable: hidden
17+
visibility: visible
18+
replicator_preview: true
19+
input_type: text
20+
antlers: false
21+
hide_display: false
22+
width: 50
23+
-
24+
handle: sites
25+
field:
26+
mode: select
27+
type: sites
28+
display: Sites
29+
validate:
30+
- required
31+
icon: sites
32+
localizable: false
33+
listable: hidden
34+
instructions_position: above
35+
visibility: visible
36+
replicator_preview: true
37+
hide_display: false
38+
width: 50
39+
-
40+
handle: id
41+
field:
42+
type: text
43+
display: id
44+
icon: text
45+
listable: hidden
46+
instructions_position: above
47+
visibility: hidden
48+
replicator_preview: true
49+
hide_display: false

resources/js/components/AltRedirect.vue

Lines changed: 69 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
export default ({
33
props: {
44
title: String,
5+
instructions: String,
56
action: String,
67
blueprint: Array,
78
meta: Array,
89
redirectTo: String,
910
values: Array,
1011
data: Array,
1112
items: Array,
13+
type: String,
1214
},
1315
computed: {
1416
lastPage() {
@@ -81,6 +83,17 @@ export default ({
8183
})
8284
}
8385
},
86+
deleteQueryString(query_string) {
87+
if (confirm('Are you sure you want to delete this query string?')) {
88+
Statamic.$axios.post(cp_url('/alt-design/alt-redirect/query-strings/delete'), {
89+
query_string: query_string,
90+
}).then(res => {
91+
this.updateItems(res)
92+
}).catch(err => {
93+
console.log(err)
94+
})
95+
}
96+
},
8497
importFromCSV() {
8598
if (!this.selectedFile) {
8699
alert("You haven't attached a CSV file!");
@@ -115,53 +128,84 @@ export default ({
115128
<template>
116129
<div id="alt-redirect">
117130

118-
<publish-form :title="title" :action="action" :blueprint="blueprint" :meta="meta" :values="values" @saved="updateItems($event)"></publish-form>
131+
<h1 class="flex-1">{{ title }}</h1>
132+
<h2 class="flex-1">{{ instructions }}</h2>
133+
134+
<publish-form :title="''" :action="action" :blueprint="blueprint" :meta="meta" :values="values" @saved="updateItems($event)"></publish-form>
119135

120136
<div class="card overflow-hidden p-0">
121137
<div class="mt-4 pb-2 px-4">
122138
<input type="text" class="input-text" v-model="search" placeholder="Search">
123139
</div>
124140
<div class="px-2">
125-
<table data-size="sm" tabindex="0" class="data-table" style="table-layout: fixed">
126-
<thead>
141+
<table v-if="type == 'redirects'" data-size="sm" tabindex="0" class="data-table" style="table-layout: fixed">
142+
<thead>
143+
<tr>
144+
<th class="group from-column sortable-column" style="width:33%">
145+
<span>From</span>
146+
</th>
147+
<th class="group from-column sortable-column pr-8 w-24" style="width:33%">
148+
<span>To</span>
149+
</th>
150+
<th class="group to-column pr-8" style="width:8%">
151+
<span>Type</span>
152+
</th>
153+
<th class="group to-column pr-8" style="width:15%">
154+
<span>Sites</span>
155+
</th>
156+
<th class="actions-column" style="width:13.4%"></th>
157+
</tr>
158+
</thead>
159+
<tbody>
160+
<tr v-for="item in itemsSliced" :key="item.id" style="width : 100%; overflow: clip">
161+
<td>
162+
{{ item.from }}
163+
</td>
164+
<td>
165+
{{ item.to }}
166+
</td>
167+
<td>
168+
{{ item.redirect_type }}
169+
</td>
170+
<td>
171+
{{ (item.sites && item.sites.length ) ? item.sites.join(', ') : "Unknown" }}
172+
</td>
173+
<td>
174+
<button @click="deleteRedirect(item.from, item.id)" class="btn"
175+
style="color: #bc2626;">Remove
176+
</button>
177+
</td>
178+
</tr>
179+
</tbody>
180+
</table>
181+
<table v-if="type == 'query-strings'" data-size="sm" tabindex="0" class="data-table" style="table-layout: fixed">
182+
<thead>
127183
<tr>
128-
<th class="group from-column sortable-column" style="width:33%">
129-
<span>From</span>
184+
<th class="group from-column sortable-column" style="width:66%">
185+
<span>Query String Key</span>
130186
</th>
131-
<th class="group from-column sortable-column pr-8 w-24" style="width:33%">
132-
<span>To</span>
133-
</th>
134-
<th class="group to-column pr-8" style="width:8%">
135-
<span>Type</span>
136-
</th>
137-
<th class="group to-column pr-8" style="width:15%">
187+
<th class="group to-column pr-8" style="width:20.6%">
138188
<span>Sites</span>
139189
</th>
140190
<th class="actions-column" style="width:13.4%"></th>
141191
</tr>
142-
</thead>
143-
<tbody>
192+
</thead>
193+
<tbody>
144194
<tr v-for="item in itemsSliced" :key="item.id" style="width : 100%; overflow: clip">
145195
<td>
146-
{{ item.from }}
147-
</td>
148-
<td>
149-
{{ item.to }}
150-
</td>
151-
<td>
152-
{{ item.redirect_type }}
196+
{{ item.query_string }}
153197
</td>
154198
<td>
155199
{{ (item.sites && item.sites.length ) ? item.sites.join(', ') : "Unknown" }}
156200
</td>
157201
<td>
158-
<button @click="deleteRedirect(item.from, item.id)" class="btn"
202+
<button @click="deleteQueryString(item.query_string)" class="btn"
159203
style="color: #bc2626;">Remove
160204
</button>
161205
</td>
162206
</tr>
163-
</tbody>
164-
</table>
207+
</tbody>
208+
</table>
165209
</div>
166210
<div class="pagination text-sm py-4 px-4 flex items-center justify-between">
167211
<div class="w-1/3 flex items-center">
@@ -213,8 +257,7 @@ export default ({
213257
</div>
214258
</div>
215259
</div>
216-
217-
<div class="flex justify-between">
260+
<div class="flex justify-between" :class="{ hidden: type == 'query-strings' }">
218261
<div class="w-full xl:w-1/2 card overflow-hidden p-0 mb-4 mt-4 mr-4 px-4 py-4">
219262
<span class="font-semibold mb-2">CSV Export</span><br>
220263
<p class="text-sm mb-4">Exports CSV of all redirects, use this format on import.</p>

resources/views/index.blade.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
@section('content')
44
<div id="alt-redirect-app" >
55
<alt-redirect
6-
title="Alt Redirect"
7-
action="{{ cp_route('alt-redirect.create') }}"
6+
title="{{ $title }}"
7+
instructions="{{ $instructions }}"
8+
action="{{ cp_route($action) }}"
89
:blueprint='@json($blueprint)'
910
:meta='@json($meta)'
1011
:values='@json($values)'
1112
:items="{{ json_encode($data) }}"
13+
type="{{ $type }}"
1214
></alt-redirect>
1315

1416
<!-- -->

routes/cp.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@
55
// Settings
66
Route::get('/alt-design/alt-redirect/', 'AltRedirectController@index')->name('alt-redirect.index');
77
Route::post('/alt-design/alt-redirect/', 'AltRedirectController@create')->name('alt-redirect.create');
8-
98
Route::post('/alt-design/alt-redirect/delete', 'AltRedirectController@delete')->name('alt-redirect.delete');
9+
10+
// Settings CSV Import / Export
1011
Route::get('/alt-design/alt-redirect/export', 'AltRedirectController@export')->name('alt-redirect.export');
1112
Route::post('/alt-design/alt-redirect/import', 'AltRedirectController@import')->name('alt-redirect.import');
1213

14+
// Query Strings
15+
Route::get('/alt-design/alt-redirect/query-strings/', 'AltRedirectController@index')->name('alt-redirect.query-strings.index');
16+
Route::post('/alt-design/alt-redirect/query-strings/', 'AltRedirectController@create')->name('alt-redirect.query-strings.create');
17+
Route::post('/alt-design/alt-redirect/query-strings/delete', 'AltRedirectController@delete')->name('alt-redirect.query-strings.delete');
1318
});
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace AltDesign\AltRedirect\Console\Commands;
4+
5+
use AltDesign\AltRedirect\Helpers\DefaultQueryStrings;
6+
use Illuminate\Console\Command;
7+
8+
class DefaultQueryStringsCommand extends Command
9+
{
10+
/**
11+
* The name and signature of the console command.
12+
*
13+
* @var string
14+
*/
15+
protected $signature = 'alt-redirect:default-query-strings';
16+
17+
/**
18+
* The console command description.
19+
*
20+
* @var string
21+
*/
22+
protected $description = 'Creates the default query string flags to be stripped from URIs in the Alt Redirect Addon';
23+
24+
/**
25+
* Execute the console command.
26+
*/
27+
public function handle()
28+
{
29+
if(!$this->confirm('Do you wish to (re)create the list of default query strings?')) {
30+
$this->error('User aborted Command');
31+
}
32+
33+
(new DefaultQueryStrings)->makeDefaultQueryStrings();
34+
$this->info('Default query strings list created');
35+
}
36+
}

0 commit comments

Comments
 (0)