mirror of
https://github.com/lempamo/Project-Unite.git
synced 2025-02-02 13:07:34 +00:00
add search system (downloads and topics)
This commit is contained in:
parent
5860170c1f
commit
5eea4787f1
5 changed files with 120 additions and 1 deletions
|
@ -4,6 +4,7 @@ using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
|
using Project_Unite.Models;
|
||||||
|
|
||||||
namespace Project_Unite.Controllers
|
namespace Project_Unite.Controllers
|
||||||
{
|
{
|
||||||
|
@ -33,5 +34,24 @@ namespace Project_Unite.Controllers
|
||||||
{
|
{
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public ActionResult Search(string query)
|
||||||
|
{
|
||||||
|
var result = new SearchResult();
|
||||||
|
query = query.ToLower();
|
||||||
|
using(var db = new ApplicationDbContext())
|
||||||
|
{
|
||||||
|
result.Downloads = db.Downloads.Where(x => x.Name.ToLower().Contains(query) || x.Changelog.ToLower().Contains(query));
|
||||||
|
result.ForumPosts = db.ForumPosts.Where(x => x.Body.ToLower().Contains(query));
|
||||||
|
result.ForumTopics = db.ForumTopics.Where(x => x.Subject.ToLower().Contains(query));
|
||||||
|
result.Skins = db.Skins.Where(x => x.Name.ToLower().Contains(query) || x.ShortDescription.ToLower().Contains(query) || x.FullDescription.ToLower().Contains(query));
|
||||||
|
result.Users = db.Users.Where(x => x.DisplayName.ToLower().Contains(query)||x.Bio.ToLower().Contains(query)||x.Interests.ToLower().Contains(query)||x.Hobbies.ToLower().Contains(query));
|
||||||
|
result.WikiPages = db.WikiPages.Where(x => x.Name.ToLower().Contains(query) || x.Contents.ToLower().Contains(query));
|
||||||
|
}
|
||||||
|
|
||||||
|
//Holy crap that search was... long.
|
||||||
|
return View(result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
22
Project-Unite/Models/SearchModels.cs
Normal file
22
Project-Unite/Models/SearchModels.cs
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Web;
|
||||||
|
|
||||||
|
namespace Project_Unite.Models
|
||||||
|
{
|
||||||
|
public class SimpleSearch
|
||||||
|
{
|
||||||
|
public string Query { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class SearchResult
|
||||||
|
{
|
||||||
|
public IEnumerable<ForumPost> ForumPosts { get; set; }
|
||||||
|
public IEnumerable<ForumTopic> ForumTopics { get; set; }
|
||||||
|
public IEnumerable<ApplicationUser> Users { get; set; }
|
||||||
|
public IEnumerable<Skin> Skins { get; set; }
|
||||||
|
public IEnumerable<Download> Downloads { get; set; }
|
||||||
|
public IEnumerable<WikiPage> WikiPages { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -427,6 +427,7 @@
|
||||||
<Compile Include="Models\ManageViewModels.cs" />
|
<Compile Include="Models\ManageViewModels.cs" />
|
||||||
<Compile Include="Models\Notification.cs" />
|
<Compile Include="Models\Notification.cs" />
|
||||||
<Compile Include="Models\Role.cs" />
|
<Compile Include="Models\Role.cs" />
|
||||||
|
<Compile Include="Models\SearchModels.cs" />
|
||||||
<Compile Include="Models\Skin.cs" />
|
<Compile Include="Models\Skin.cs" />
|
||||||
<Compile Include="Models\WikiModels.cs" />
|
<Compile Include="Models\WikiModels.cs" />
|
||||||
<Compile Include="NotificationDaemon.cs" />
|
<Compile Include="NotificationDaemon.cs" />
|
||||||
|
@ -547,6 +548,7 @@
|
||||||
<Content Include="Views\Developer\AddWikiCategory.cshtml" />
|
<Content Include="Views\Developer\AddWikiCategory.cshtml" />
|
||||||
<Content Include="Views\Wiki\AddPage.cshtml" />
|
<Content Include="Views\Wiki\AddPage.cshtml" />
|
||||||
<Content Include="Views\Wiki\EditPage.cshtml" />
|
<Content Include="Views\Wiki\EditPage.cshtml" />
|
||||||
|
<Content Include="Views\Home\Search.cshtml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="App_Data\" />
|
<Folder Include="App_Data\" />
|
||||||
|
|
75
Project-Unite/Views/Home/Search.cshtml
Normal file
75
Project-Unite/Views/Home/Search.cshtml
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
@model Project_Unite.Models.SearchResult
|
||||||
|
@{
|
||||||
|
ViewBag.Title = "Search";
|
||||||
|
}
|
||||||
|
|
||||||
|
<h2>Search results</h2>
|
||||||
|
|
||||||
|
<p>Here's what we found for that query.</p>
|
||||||
|
|
||||||
|
|
||||||
|
<ul id="tabs" data-tabs="tabs" class="nav nav-tabs" role="tablist">
|
||||||
|
<li class="active"><a data-toggle="tab" href="#t_topics"><span class="glyphicon glyphicon-list"></span> Forum Topics (@Model.ForumTopics.Count())</a></li>
|
||||||
|
<li><a data-toggle="tab" href="#t_downloads"><span class="glyphicon glyphicon-arrow-down"></span> Downloads (@Model.Downloads.Count())</a></li>
|
||||||
|
<li><a data-toggle="tab" href="#t_skins"><span class="glyphicon glyphicon-eye-open"></span> Skins (@Model.Skins.Count())</a></li>
|
||||||
|
<li><a data-toggle="tab" href="#t_users"><span class="glyphicon glyphicon-user"></span> Users (@Model.Users.Count())</a></li>
|
||||||
|
<li><a data-toggle="tab" href="#t_wiki"><span class="glyphicon glyphicon-book"></span> Wiki Pages (@Model.WikiPages.Count())</a></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<div class="tab-content">
|
||||||
|
<div class="tab-pane fade in active" id="t_topics">
|
||||||
|
<h4>Forum Topics</h4>
|
||||||
|
<table class="table">
|
||||||
|
<tr>
|
||||||
|
<th style="width:45%">Topic</th>
|
||||||
|
<th style="width:20%">Popularity</th>
|
||||||
|
<th>Most Recent Post</th>
|
||||||
|
</tr>
|
||||||
|
@foreach (var topic in Model.ForumTopics.OrderByDescending(x=>x.StartedAt))
|
||||||
|
{
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
@Html.TopicLinkFor(topic.Id) <br/>
|
||||||
|
<p>by @Html.UserLink(topic.AuthorId) at @topic.StartedAt</p>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<span class="glyphicon glyphicon-thumbs-up"></span> @topic.Likes.Length <span class="glyphicon glyphicon-thumbs-down"></span> @topic.Dislikes.Length
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@{
|
||||||
|
var mostrecent = topic.Posts.OrderByDescending(x => x.PostedAt).First();
|
||||||
|
}
|
||||||
|
<p>By @Html.UserLink(mostrecent.AuthorId) at @mostrecent.PostedAt</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="tab-pane fade in active" id="t_downloads">
|
||||||
|
<h4>Downloads</h4>
|
||||||
|
<table class="table">
|
||||||
|
<tr>
|
||||||
|
<th style="width:65%">Download</th>
|
||||||
|
<th>Actions</th>
|
||||||
|
</tr>
|
||||||
|
@foreach (var download in Model.Downloads.OrderByDescending(x => x.PostDate))
|
||||||
|
{
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<p>@download.Name <br/> ...released by @Html.UserLink(download.ReleasedBy), released at @download.PostDate</p>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@if (!string.IsNullOrEmpty(download.DevUpdateId))
|
||||||
|
{
|
||||||
|
<a href="http://youtube.com/watch?v=@download.DevUpdateId" class="btn btn-default"><span class="glyphicon glyphicon-play"></span> Watch dev update</a>
|
||||||
|
<a href="@Url.Action("ViewRelease", "Download", new {id=download.Id})" class="btn btn-default"><span class="glyphicon glyphicon-eye-open"></span> View details</a>
|
||||||
|
<a href="@download.DownloadUrl" class="btn btn-default"><span class="glyphicon glyphicon-arrow-down"></span> Download</a>
|
||||||
|
}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
|
@ -83,7 +83,7 @@
|
||||||
|
|
||||||
if (Request.IsAuthenticated)
|
if (Request.IsAuthenticated)
|
||||||
{
|
{
|
||||||
<ul>
|
<ul class="nav nav-pills">
|
||||||
<li><a href="@Url.Action("EditPage", new { id = Model.Page.Id })"><span class="glyphicon glyphicon-pencil"></span> Edit this page</a></li>
|
<li><a href="@Url.Action("EditPage", new { id = Model.Page.Id })"><span class="glyphicon glyphicon-pencil"></span> Edit this page</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue