Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URL Rewriting Module #16687

Merged
merged 97 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
edcb175
Sync with upstream OrchardCMS/dev
arkadiuszwojcik Jul 10, 2020
ad39ce7
Merge pull request #3 from OrchardCMS/dev
arkadiuszwojcik Dec 17, 2020
67ff75e
Merge pull request #4 from OrchardCMS/dev
arkadiuszwojcik Dec 21, 2020
0c6761b
Merge pull request #5 from OrchardCMS/dev
arkadiuszwojcik Dec 27, 2020
f8ec4e2
Merge branch 'OrchardCMS:main' into dev
arkadiuszwojcik Sep 7, 2024
4661da6
Rewrite module
Sep 7, 2024
49f3939
Fix warning as errors
Sep 7, 2024
d7e6f61
Update OrchardCore.Rewrite.csproj
MikeAlhayek Sep 9, 2024
171c170
Code cleanup after code review
Sep 10, 2024
0f2914a
Rename module
Sep 11, 2024
3cbccfb
Rename classes to match module name
Sep 13, 2024
2eeefea
- Constant for module order
Sep 15, 2024
40bf27b
- Introduce ConfigureOptions
Sep 15, 2024
5a0a436
Merge branch 'OrchardCMS:main' into dev
arkadiuszwojcik Sep 16, 2024
3d86a84
Merge branch 'dev' into new_rewrite_module
Sep 16, 2024
6d1f4b4
UrlRewriting UI - part 1
Sep 18, 2024
ff64d23
Merge branch 'OrchardCMS:main' into dev
arkadiuszwojcik Sep 18, 2024
1735f9a
Merge branch 'dev' into new_rewrite_module
Sep 18, 2024
8080821
UrlRewriting UI - part 2
Sep 22, 2024
23546cb
UrlRewriting UI - part 3
Sep 25, 2024
060a19c
UrlRewriting UI - part 4
Sep 30, 2024
61e2ce7
Merge branch 'OrchardCMS:main' into dev
arkadiuszwojcik Sep 30, 2024
397ffa0
Merge branch 'dev' into new_rewrite_module
Sep 30, 2024
2963137
Add recipe step
Oct 2, 2024
7ffe421
Mark classes as sealed
Oct 2, 2024
806be17
Bug fixes
Oct 2, 2024
8b23ca1
UI fix
Oct 2, 2024
45d1547
Cleanup, add Id to Rules and other things
MikeAlhayek Oct 3, 2024
8fb929f
Merge branch 'main' into new_rewrite_module
MikeAlhayek Oct 3, 2024
78d7943
add site release warning
MikeAlhayek Oct 3, 2024
f5cd1f5
style
MikeAlhayek Oct 3, 2024
1f83775
Use Queries like UI and change everything
MikeAlhayek Oct 3, 2024
342d69b
remove old properties from RewriteStep
MikeAlhayek Oct 3, 2024
a1de614
missed method
MikeAlhayek Oct 3, 2024
b567e92
Fix the UI, add order and simplify drivers and views
MikeAlhayek Oct 4, 2024
c6e52e3
Merge branch 'main' into new_rewrite_module
MikeAlhayek Oct 4, 2024
f1f0923
fix build and add docs
MikeAlhayek Oct 5, 2024
81bd0ee
Merge branch 'new_rewrite_module' of https://github.com/arkadiuszwojc…
MikeAlhayek Oct 5, 2024
3e58f22
fix docs
MikeAlhayek Oct 5, 2024
d4a4b2b
add all the handlers
MikeAlhayek Oct 5, 2024
5c25ba2
fix build
MikeAlhayek Oct 5, 2024
59a9353
Merge branch 'main' into new_rewrite_module
MikeAlhayek Oct 5, 2024
d7627ed
Fix flags creation
Oct 6, 2024
2925e7c
Fix for RewriteRuleSource
Oct 6, 2024
11e657a
Move SkipFurtherRules to RewriteUrl metadata
Oct 6, 2024
a33b104
Fix RedirectRule flags creation
Oct 6, 2024
b4647d9
Merge branch 'main' into new_rewrite_module
MikeAlhayek Oct 7, 2024
b534431
fix build
MikeAlhayek Oct 7, 2024
53b08e2
cleanup
MikeAlhayek Oct 7, 2024
d688d18
Fix names Queries -> Rules
Oct 8, 2024
0bd925b
Autogen initial rule order
Oct 8, 2024
f6d3b70
Fix names
Oct 8, 2024
ba20fb5
Merge branch 'main' into new_rewrite_module
MikeAlhayek Oct 8, 2024
dda221c
remove buttons shape
MikeAlhayek Oct 8, 2024
e280d84
fix conflict
MikeAlhayek Oct 8, 2024
2faad49
handle bulk remove abd cleanup
MikeAlhayek Oct 8, 2024
80cfe0a
Change 'Skip Further Rules' to 'Stop processing of subsequent rules'
Oct 9, 2024
4c81d44
Rename Url to SubstitutionUrl
Oct 11, 2024
6a5f621
Fix exception in Max fun if there is no rules
Oct 11, 2024
03770b1
Merge branch 'main' into new_rewrite_module
MikeAlhayek Oct 13, 2024
396c05d
minor change
MikeAlhayek Oct 13, 2024
7378ffe
improve logic
MikeAlhayek Oct 13, 2024
a2efe8b
cleanup
MikeAlhayek Oct 13, 2024
f6a494b
Update RewriteRuleOptions.cs
MikeAlhayek Oct 13, 2024
5ffd90b
Update RewriteRule.Buttons.SummaryAdmin.cshtml
MikeAlhayek Oct 13, 2024
9518870
Forgotten SubstitutionUrl rename in UrlRedirectSourceMetadata
Oct 13, 2024
21ba143
- Align rule construction code
Oct 13, 2024
efa342c
Fix flags append
Oct 14, 2024
15c307d
Remove using
Oct 14, 2024
cb238d0
Fix recipe step, add validate handlers, and simplify
MikeAlhayek Oct 14, 2024
d0aa57c
add recipe docs and allow updating rule from recipe
MikeAlhayek Oct 14, 2024
c251813
address feedback
MikeAlhayek Oct 14, 2024
4c83d8e
remove extra quotes
MikeAlhayek Oct 14, 2024
56dc8dc
Merge branch 'main' into new_rewrite_module
MikeAlhayek Oct 14, 2024
6cacc1a
improve labels
MikeAlhayek Oct 15, 2024
1018f4a
improve docs
MikeAlhayek Oct 15, 2024
431185e
improve docs and cleanup
MikeAlhayek Oct 15, 2024
92cc77a
Merge branch 'main' into new_rewrite_module
MikeAlhayek Oct 15, 2024
41816e6
Add extra hint
Oct 15, 2024
001d983
address feedback
MikeAlhayek Oct 15, 2024
354cd5f
Merge branch 'main' into new_rewrite_module
MikeAlhayek Oct 15, 2024
1010bca
cleanup
MikeAlhayek Oct 15, 2024
dc7abcb
address feedback
MikeAlhayek Oct 15, 2024
b592a11
better order counting
MikeAlhayek Oct 15, 2024
15f7a59
Merge branch 'main' into new_rewrite_module
MikeAlhayek Oct 15, 2024
148fccb
Merge branch 'main' into new_rewrite_module
MikeAlhayek Oct 16, 2024
7972b09
add sorting UI instead of an input
MikeAlhayek Oct 16, 2024
0ed0b77
save
MikeAlhayek Oct 17, 2024
b4c8a59
fix sort logic
MikeAlhayek Oct 17, 2024
eca859e
move JS into scrtipt file, use drop down menu for the query string po…
MikeAlhayek Oct 17, 2024
85a22d2
cleanup
MikeAlhayek Oct 18, 2024
0b77fa1
Merge branch 'main' into new_rewrite_module
MikeAlhayek Oct 18, 2024
6823a92
Add a display name for the source
MikeAlhayek Oct 19, 2024
76b5ed0
Merge branch 'main' into new_rewrite_module
MikeAlhayek Oct 19, 2024
0ddb4b5
cleanup
MikeAlhayek Oct 19, 2024
9c88223
improve docs
MikeAlhayek Oct 19, 2024
f2740c2
cleaner table
MikeAlhayek Oct 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions OrchardCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.Queries.Core",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.Sms.Azure", "src\OrchardCore.Modules\OrchardCore.Sms.Azure\OrchardCore.Sms.Azure.csproj", "{013C8BBF-6879-4B47-80C9-A466923E45E5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.UrlRewriting", "src\OrchardCore.Modules\OrchardCore.UrlRewriting\OrchardCore.UrlRewriting.csproj", "{D0F8B342-BDA8-44CB-AA43-7A65C79636A2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OrchardCore.UrlRewriting.Abstractions", "src\OrchardCore\OrchardCore.UrlRewriting.Abstractions\OrchardCore.UrlRewriting.Abstractions.csproj", "{675C8A76-C64F-47EC-B4F5-06D4F2D9662A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OrchardCore.UrlRewriting.Core", "src\OrchardCore\OrchardCore.UrlRewriting.Core\OrchardCore.UrlRewriting.Core.csproj", "{7B18DD99-A7BB-4297-8679-D87289758756}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1395,6 +1401,18 @@ Global
{013C8BBF-6879-4B47-80C9-A466923E45E5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{013C8BBF-6879-4B47-80C9-A466923E45E5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{013C8BBF-6879-4B47-80C9-A466923E45E5}.Release|Any CPU.Build.0 = Release|Any CPU
{D0F8B342-BDA8-44CB-AA43-7A65C79636A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D0F8B342-BDA8-44CB-AA43-7A65C79636A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D0F8B342-BDA8-44CB-AA43-7A65C79636A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D0F8B342-BDA8-44CB-AA43-7A65C79636A2}.Release|Any CPU.Build.0 = Release|Any CPU
{675C8A76-C64F-47EC-B4F5-06D4F2D9662A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{675C8A76-C64F-47EC-B4F5-06D4F2D9662A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{675C8A76-C64F-47EC-B4F5-06D4F2D9662A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{675C8A76-C64F-47EC-B4F5-06D4F2D9662A}.Release|Any CPU.Build.0 = Release|Any CPU
{7B18DD99-A7BB-4297-8679-D87289758756}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7B18DD99-A7BB-4297-8679-D87289758756}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7B18DD99-A7BB-4297-8679-D87289758756}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7B18DD99-A7BB-4297-8679-D87289758756}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1636,6 +1654,9 @@ Global
{4BAA08A2-878C-4B96-86BF-5B3DB2B6C2C7} = {F23AC6C2-DE44-4699-999D-3C478EF3D691}
{61B358F2-702C-40AA-9DF7-7121248FE6DE} = {F23AC6C2-DE44-4699-999D-3C478EF3D691}
{013C8BBF-6879-4B47-80C9-A466923E45E5} = {A066395F-6F73-45DC-B5A6-B4E306110DCE}
{D0F8B342-BDA8-44CB-AA43-7A65C79636A2} = {A066395F-6F73-45DC-B5A6-B4E306110DCE}
{675C8A76-C64F-47EC-B4F5-06D4F2D9662A} = {F23AC6C2-DE44-4699-999D-3C478EF3D691}
{7B18DD99-A7BB-4297-8679-D87289758756} = {F23AC6C2-DE44-4699-999D-3C478EF3D691}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {46A1D25A-78D1-4476-9CBF-25B75E296341}
Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ nav:
- Workflows: reference/modules/Workflows/README.md
- DataProtection (Azure Storage): reference/modules/DataProtection.Azure/README.md
- Background Tasks: reference/modules/BackgroundTasks/README.md
- URL Rewriting: reference/modules/UrlRewriting/README.md
- Reverse Proxy: reference/modules/ReverseProxy/README.md
- Resources:
- Learning: resources/README.md
Expand Down
30 changes: 30 additions & 0 deletions src/OrchardCore.Modules/OrchardCore.UrlRewriting/AdminMenu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Microsoft.Extensions.Localization;
using OrchardCore.Navigation;

namespace OrchardCore.UrlRewriting;

public sealed class AdminMenu : AdminNavigationProvider
{
internal readonly IStringLocalizer S;

public AdminMenu(IStringLocalizer<AdminMenu> stringLocalizer)
{
S = stringLocalizer;
}

protected override ValueTask BuildAsync(NavigationBuilder builder)
{
builder
.Add(S["Configuration"], configuration => configuration
.Add(S["URL Rewriting"], S["URL Rewriting"].PrefixPosition(), rewriting => rewriting
.AddClass("url-rewriting")
.Id("urlRewriting")
.Permission(UrlRewritingPermissions.ManageUrlRewritingRules)
.Action("Index", "Admin", "OrchardCore.UrlRewriting")
.LocalNav()
)
);

return ValueTask.CompletedTask;
}
}
14 changes: 14 additions & 0 deletions src/OrchardCore.Modules/OrchardCore.UrlRewriting/Assets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"inputs": [
"Assets/js/sortable-rules.js"
],
"output": "wwwroot/Scripts/sortable-rules.js"
},
{
"inputs": [
"Assets/js/admin-ui.js"
],
"output": "wwwroot/Scripts/admin-ui.js"
}
]
169 changes: 169 additions & 0 deletions src/OrchardCore.Modules/OrchardCore.UrlRewriting/Assets/js/admin-ui.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
urlRewritingAdmin = function () {

const initialize = (url, errorLabel, selectedLabel) => {

// Create the sortable UI.
sortingListManager.create('#rewrite-rules-sortable-list', url, errorLabel);

let searchBox = document.getElementById('search-box');
let searchAlert = document.getElementById('list-alert');

const filterElements = document.querySelectorAll('[data-filter-value]');

// If the user press Enter, don't submit.
searchBox.addEventListener('keydown', function (e) {
if (e.key === 'Enter') {
e.preventDefault();
}
});

searchBox.addEventListener('keyup', e => {

var search = e.target.value.toLowerCase();
// On ESC, clear the search box and display all rules.
if (e.key == 'Escape' || search == '') {
searchAlert.classList.add('d-none');
searchBox.value = '';
for (let i = 0; i < filterElements.length; i++) {
filterElements[i].classList.remove("d-none");
filterElements[i].classList.remove("first-child-visible");
filterElements[i].classList.remove("last-child-visible");
}

if (filterElements.length > 0) {
filterElements[0].classList.add('first-child-visible');
filterElements[filterElements.length - 1].classList.add('last-child-visible');
}
} else {
let visibleElements = [];
for (let i = 0; i < filterElements.length; i++) {
let filter = filterElements[i];

var text = filter.getAttribute('data-filter-value');

if (!text) {
filter.classList.add("d-none");
continue;
}

var found = text.indexOf(search) > -1;

if (found) {
filter.classList.remove("d-none");
filter.classList.remove("first-child-visible");
filter.classList.remove("last-child-visible");
visibleElements.push(filter);
} else {
filter.classList.add("d-none");
}
}

if (visibleElements.length > 0) {
visibleElements[0].classList.add('first-child-visible');
visibleElements[visibleElements.length - 1].classList.add('last-child-visible');
searchAlert.classList.add('d-none');
} else {
searchAlert.classList.remove('d-none');
}
}
});

var actions = document.getElementById('actions');
var items = document.getElementById('items');
var filters = document.querySelectorAll('.filter');
var selectAllCtrl = document.getElementById('select-all');
var selectedItems = document.getElementById('selected-items');
var itemsCheckboxes = document.querySelectorAll("input[type='checkbox'][name='ruleIds']");

function displayActionsOrFilters() {
// Select all checked checkboxes with name 'ruleIds'
var checkedCheckboxes = document.querySelectorAll("input[type='checkbox'][name='ruleIds']:checked");

if (checkedCheckboxes.length > 1) {
actions.classList.remove('d-none');
for (let i = 0; i < filters.length; i++) {
filters[i].classList.add('d-none');
}
selectedItems.classList.remove('d-none');
items.classList.add('d-none');
} else {
actions.classList.add('d-none');

for (let i = 0; i < filters.length; i++) {
filters[i].classList.remove('d-none');
}
selectedItems.classList.add('d-none');
items.classList.remove('d-none');
}
}

var dropdownItems = document.querySelectorAll(".dropdown-menu .dropdown-item");

// Add click event listeners to each dropdown item
dropdownItems.forEach(function (item) {
// Check if the item has a data-action attribute
if (item.dataset.action) {
item.addEventListener("click", function () {
// Get all checked checkboxes
var checkedCheckboxes = document.querySelectorAll("input[type='checkbox'][name='ruleIds']:checked");

// Check if more than one checkbox is checked
if (checkedCheckboxes.length > 1) {
// Get data attributes from the clicked item
var actionData = Object.assign({}, item.dataset);

confirmDialog({
...actionData,
callback: function (r) {
if (r) {
// Set the value of the BulkAction option
document.querySelector("[name='Options.BulkAction']").value = actionData.action;
// Trigger the submit action
document.querySelector("[name='submit.BulkAction']").click();
}
}
});
}
});
}
});

selectAllCtrl.addEventListener("click", function () {
itemsCheckboxes.forEach(function (checkbox) {
if (checkbox !== selectAllCtrl) {
checkbox.checked = selectAllCtrl.checked; // Set the checked state of all checkboxes
}
});

// Update the selected items text
updateSelectedItemsText();
displayActionsOrFilters();
});

// Event listener for individual checkboxes
itemsCheckboxes.forEach(function (checkbox) {
checkbox.addEventListener("click", function () {
var itemsCount = itemsCheckboxes.length;
var selectedItemsCount = document.querySelectorAll("input[type='checkbox'][name='ruleIds']:checked").length;

// Update selectAllCtrl state
selectAllCtrl.checked = selectedItemsCount === itemsCount;
selectAllCtrl.indeterminate = selectedItemsCount > 0 && selectedItemsCount < itemsCount;

// Update the selected items text
updateSelectedItemsText();
displayActionsOrFilters();
});
});

// Function to update selected items text
function updateSelectedItemsText() {
var selectedCount = document.querySelectorAll("input[type='checkbox'][name='ruleIds']:checked").length;
selectedItems.textContent = selectedCount + ' ' + selectedLabel;
}
}

return {
initialize: initialize
}
}();
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
sortingListManager = function () {

const saveOrders = (evt, url, errorMessage) => {

var data = {
oldIndex: evt.oldIndex,
newIndex: evt.newIndex
};
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
}).catch(error => {
console.log(error);
alert(errorMessage || 'Unable to sort the list');
});
}

const create = (selector, sortUrl, errorMessage) => {

var sortable = document.querySelector(selector);

if (!sortable) {
console.log('Unable to find the sortable element. The given selector is: ' + selector);

return;
}

if (sortUrl) {
orderUrl = sortUrl;
} else {
orderUrl = sortable.getAttribute('data-sort-uri');
}

if (!orderUrl) {
console.log('Unable to determine the sort post URI. Either pass it to the create function or set it as data-sort-uri to the sorting element.');

return;
}

var sortable = Sortable.create(sortable, {
handle: ".ui-sortable-handle",
animation: 150,
filter: ".ignore-elements",
draggable: ".item",
onUpdate: function (evt) {
saveOrders(evt, orderUrl, errorMessage);
}
});
};

return {
create: create
}
}();
Loading
Loading