Skip to content
This repository was archived by the owner on Dec 21, 2023. It is now read-only.

Commit f9ad65a

Browse files
Merge pull request #10 from OpenTabletDriver/search-arguments
Add search arguments
2 parents c5e95f2 + 018804d commit f9ad65a

6 files changed

Lines changed: 83 additions & 14 deletions

File tree

OpenTabletDriver.Web/Controllers/PluginsController.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
using System.Collections.Generic;
12
using System.Threading.Tasks;
23
using Microsoft.AspNetCore.Mvc;
4+
using OpenTabletDriver.Web.Core.Plugins;
35
using OpenTabletDriver.Web.Core.Services;
6+
using OpenTabletDriver.Web.Models;
47

58
namespace OpenTabletDriver.Web.Controllers
69
{
@@ -14,10 +17,14 @@ public PluginsController(IPluginMetadataService pluginMetadataService)
1417
private IPluginMetadataService pluginMetadataService;
1518

1619
[ResponseCache(Duration = 300)]
17-
public async Task<IActionResult> Index()
20+
public async Task<IActionResult> Index(string search = null)
1821
{
19-
var metadata = await pluginMetadataService.GetPlugins();
20-
return View(metadata);
22+
var model = new EnumerableSearchViewModel<PluginMetadata>()
23+
{
24+
Items = await pluginMetadataService.GetPlugins(),
25+
Search = search
26+
};
27+
return View(model);
2128
}
2229
}
2330
}

OpenTabletDriver.Web/Controllers/TabletsController.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
using System.Net.Http;
33
using System.Runtime.Versioning;
44
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Html;
56
using Microsoft.AspNetCore.Mvc;
67
using OpenTabletDriver.Web.Core.Services;
8+
using OpenTabletDriver.Web.Models;
79

810
namespace OpenTabletDriver.Web.Controllers
911
{
@@ -13,7 +15,7 @@ public class TabletsController : Controller
1315
"https://github.com/OpenTabletDriver/OpenTabletDriver/raw/master/TABLETS.md";
1416

1517
[ResponseCache(Duration = 300)]
16-
public async Task<IActionResult> Index()
18+
public async Task<IActionResult> Index(string search = null)
1719
{
1820
using (var client = new HttpClient())
1921
using (var httpStream = await client.GetStreamAsync(TABLETS_MARKDOWN_URL))
@@ -25,7 +27,13 @@ public async Task<IActionResult> Index()
2527
"<table>",
2628
"<table id=\"tablets\" class=\"table table-hover\">"
2729
);
28-
return View(model: patchedHtml);
30+
31+
var model = new ContentSearchViewModel
32+
{
33+
Content = new HtmlString(patchedHtml),
34+
Search = search
35+
};
36+
return View(model);
2937
}
3038
}
3139
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using Microsoft.AspNetCore.Html;
2+
3+
namespace OpenTabletDriver.Web.Models
4+
{
5+
public class ContentSearchViewModel
6+
{
7+
public IHtmlContent Content { set; get; }
8+
public string Search { set; get; }
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Collections.Generic;
2+
3+
namespace OpenTabletDriver.Web.Models
4+
{
5+
public class EnumerableSearchViewModel<T>
6+
{
7+
public IEnumerable<T> Items { set; get; }
8+
public string Search { set; get; }
9+
}
10+
}

OpenTabletDriver.Web/Views/Plugins/Index.cshtml

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
@using OpenTabletDriver.Web.Core.Plugins
22
@using System.Data.Common
33

4-
@model IEnumerable<PluginMetadata>
4+
@model EnumerableSearchViewModel<PluginMetadata>
55

66
@{
77
ViewBag.Title = "Plugins";
8-
var pluginVersions = Model.Select(m => m.SupportedDriverVersion)
8+
var pluginVersions = Model.Items.Select(m => m.SupportedDriverVersion)
99
.Distinct()
1010
.OrderByDescending(v => v.ToString());
1111
}
@@ -14,13 +14,14 @@
1414
<div class="d-flex mb-3">
1515
<div class="flex-fill">
1616
<div class="form-floating me-3">
17-
<input type="text" class="form-control" id="searchInput" placeholder="Search" onkeyup="filter()"/>
17+
<input type="text" class="form-control" id="searchInput" placeholder="Search" onkeyup="filterInput()"
18+
value="@Model.Search"/>
1819
<label for="searchInput">Search</label>
1920
</div>
2021
</div>
2122
<div class="flex-fill">
2223
<div class="form-floating">
23-
<select class="form-select" id="pluginVersionSelector" onchange="filter()">
24+
<select class="form-select" id="pluginVersionSelector" onchange="filterInput()">
2425
<option value="">All Versions</option>
2526
@foreach (var version in pluginVersions)
2627
{
@@ -33,7 +34,7 @@
3334
</div>
3435

3536
<div id="metadataList">
36-
@foreach (var metadata in Model)
37+
@foreach (var metadata in Model.Items)
3738
{
3839
<div class="card mb-2 plugin-metadata-card"
3940
data-name="@metadata.Name" data-version="@metadata.SupportedDriverVersion">
@@ -74,7 +75,22 @@
7475
@section Scripts
7576
{
7677
<script type="text/javascript">
77-
filter();
78+
document.onreadystatechange = function () {
79+
if (document.readyState == "complete") {
80+
filter();
81+
}
82+
};
83+
84+
function filterInput() {
85+
let searchInput = document.getElementById('searchInput');
86+
let text = searchInput.value;
87+
let action = 'Plugins';
88+
if (text.length > 0) {
89+
action += '?search=' + encodeURIComponent(text);
90+
}
91+
window.history.replaceState('', '', action);
92+
filter();
93+
}
7894
7995
function filter() {
8096
let selector = document.getElementById('pluginVersionSelector');

OpenTabletDriver.Web/Views/Tablets/Index.cshtml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,37 @@
22
ViewData["Title"] = "Tablets";
33
}
44

5-
@model string
5+
@model ContentSearchViewModel
66

77
<div class="container">
88
<div class="form-floating mb-3">
9-
<input type="text" class="form-control" id="searchInput" placeholder="Search" onkeyup="search()"/>
9+
<input id="searchInput" type="text" class="form-control" onkeyup="searchInput()" placeholder="Search"
10+
value="@Model.Search"/>
1011
<label for="searchInput">Search</label>
1112
</div>
12-
@Html.Raw(Model)
13+
@Model.Content
1314
</div>
1415

1516
@section Scripts
1617
{
1718
<script type="text/javascript">
19+
document.onreadystatechange = function () {
20+
if (document.readyState == "complete") {
21+
search();
22+
}
23+
};
24+
25+
function searchInput() {
26+
let input = document.getElementById('searchInput');
27+
let text = input.value;
28+
let action = 'Tablets'
29+
if (text.length > 0) {
30+
action += '?search=' + encodeURIComponent(text);
31+
}
32+
window.history.replaceState('', '', action);
33+
search();
34+
}
35+
1836
function search() {
1937
let input = document.getElementById('searchInput');
2038
let filter = input.value.toUpperCase();

0 commit comments

Comments
 (0)