Browse Source

Added upload searching on Administration page.

tags/3.0.0
Teknikode 2 years ago
parent
commit
5d27bb9c21

+ 14
- 1
Teknik/Areas/Admin/AdminAreaRegistration.cs View File

@@ -31,10 +31,18 @@ namespace Teknik.Areas.Admin
"Admin.Search", // Route name
new List<string>() { "admin" }, // Subdomains
new List<string>() { config.Host },
"Search", // URL with parameters
"Search/Users", // URL with parameters
new { controller = "Admin", action = "Search" }, // Parameter defaults
new[] { typeof(Controllers.AdminController).Namespace }
);
context.MapSubdomainRoute(
"Admin.UploadSearch", // Route name
new List<string>() { "admin" }, // Subdomains
new List<string>() { config.Host },
"Search/Uploads", // URL with parameters
new { controller = "Admin", action = "UploadSearch" }, // Parameter defaults
new[] { typeof(Controllers.AdminController).Namespace }
);
context.MapSubdomainRoute(
"Admin.UserInfo", // Route name
new List<string>() { "admin" }, // Subdomains
@@ -55,6 +63,11 @@ namespace Teknik.Areas.Admin
// Register Script Bundles
BundleTable.Bundles.Add(new CdnScriptBundle("~/bundles/Search", config.CdnHost).Include(
"~/Areas/Admin/Scripts/Search.js"));

// Register Script Bundles
BundleTable.Bundles.Add(new CdnScriptBundle("~/bundles/UploadSearch", config.CdnHost).Include(
"~/Scripts/bootbox/bootbox.min.js",
"~/Areas/Admin/Scripts/UploadSearch.js"));
}
}
}

+ 27
- 0
Teknik/Areas/Admin/Controllers/AdminController.cs View File

@@ -39,6 +39,13 @@ namespace Teknik.Areas.Admin.Controllers
return View(model);
}

[HttpGet]
public ActionResult UploadSearch()
{
UploadSearchViewModel model = new UploadSearchViewModel();
return View(model);
}

[HttpPost]
public ActionResult GetSearchResults(string query)
{
@@ -63,5 +70,25 @@ namespace Teknik.Areas.Admin.Controllers

return PartialView("~/Areas/Admin/Views/Admin/SearchResults.cshtml", models);
}

[HttpPost]
public ActionResult GetUploadSearchResults(string url)
{
Upload.Models.Upload foundUpload = db.Uploads.Where(u => u.Url == url).FirstOrDefault();
if (foundUpload != null)
{
UploadResultViewModel model = new UploadResultViewModel();

model.Url = foundUpload.Url;
model.ContentType = foundUpload.ContentType;
model.ContentLength = foundUpload.ContentLength;
model.DateUploaded = foundUpload.DateUploaded;
model.Downloads = foundUpload.Downloads;
model.DeleteKey = foundUpload.DeleteKey;

return PartialView("~/Areas/Admin/Views/Admin/UploadResult.cshtml", model);
}
return Json(new { error = new { message = "Upload does not exist" } });
}
}
}

+ 67
- 0
Teknik/Areas/Admin/Scripts/UploadSearch.js View File

@@ -0,0 +1,67 @@
$(document).ready(function () {
$('#Query').on('input', function (e) {
query = $(this).val();

// Try to strip out the ID from the url
var pattern = '(?:(?:.+)\\/)?([^\\?]+)(?:\\?(?:.*))?';
var reg = new RegExp(pattern);
var match = reg.exec(query);
query = match[1];

$.ajax({
type: "POST",
url: searchResultsURL,
data: { url: query },
success: function (html) {
if (html) {
if (html.error) {
$("#top_msg").css('display', 'inline', 'important');
$("#top_msg").html('<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' + html.error.message + '</div>');
}
else {
$("#top_msg").css('display', 'none');
$("#top_msg").html('');
$("#results").html(html);
LinkUploadDelete($('.delete-upload-button'));
}
}
}
});
});
});

function LinkUploadDelete(selector) {
$(selector).click(function () {
var deleteUrl = $(this).attr('id');
var uploadID = $(this).data('upload-id');
bootbox.confirm("Are you sure you want to delete this upload?", function (result) {
if (result) {
if (deleteUrl !== '') {
window.open(deleteUrl, '_blank');
window.location.reload();
}
else {
$.ajax({
type: "POST",
url: generateDeleteKeyURL,
data: { file: uploadID },
headers: { 'X-Requested-With': 'XMLHttpRequest' },
xhrFields: {
withCredentials: true
},
success: function (html) {
if (html.result) {
window.open(html.result.url, '_blank');
window.location.reload();
}
else {
$("#top_msg").css('display', 'inline', 'important');
$("#top_msg").html('<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' + html.error.message + '</div>');
}
}
});
}
}
});
});
}

+ 18
- 0
Teknik/Areas/Admin/ViewModels/UploadResultViewModel.cs View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Teknik.ViewModels;

namespace Teknik.Areas.Admin.ViewModels
{
public class UploadResultViewModel : ViewModelBase
{
public string Url { get; set; }
public string ContentType { get; set; }
public long ContentLength { get; set; }
public DateTime DateUploaded { get; set; }
public int Downloads { get; set; }
public string DeleteKey { get; set; }
}
}

+ 12
- 0
Teknik/Areas/Admin/ViewModels/UploadSearchViewModel.cs View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Teknik.ViewModels;

namespace Teknik.Areas.Admin.ViewModels
{
public class UploadSearchViewModel : ViewModelBase
{
}
}

+ 5
- 0
Teknik/Areas/Admin/Views/Admin/Dashboard.cshtml View File

@@ -8,4 +8,9 @@
<a href="@Url.SubRouteUrl("admin", "Admin.Search")">Search</a>
</div>
</div>
<div class="row">
<div class="col-sm-10 col-sm-offset-1">
<a href="@Url.SubRouteUrl("admin", "Admin.UploadSearch")">Upload Search</a>
</div>
</div>
</div>

+ 33
- 0
Teknik/Areas/Admin/Views/Admin/UploadResult.cshtml View File

@@ -0,0 +1,33 @@
@model Teknik.Areas.Admin.ViewModels.UploadResultViewModel

@using Teknik.Utilities

<div class="panel panel-default">
<div class="panel-heading text-center">
<a id="upload-url" href="@Url.SubRouteUrl("u", "Upload.Download", new { file = Model.Url })">@Url.SubRouteUrl("u", "Upload.Download", new { file = Model.Url })</a>
</div>
<div class="panel-body">
<div class="col-sm-2 text-center">
<label for="size">Size</label>
<p id="size">@StringHelper.GetBytesReadable(Model.ContentLength)</p>
</div>
<div class="col-sm-3 text-center">
<label for="type">Type</label>
<p id="type">@Model.ContentType</p>
</div>
<div class="col-sm-3 text-center">
<label for="dateUploaded">Date Uploaded</label>
<p id="dateUploaded"><time datetime="@Model.DateUploaded.ToString("s")">@Model.DateUploaded.ToString("MMMM dd, yyyy")</time></p>
</div>
<div class="col-sm-2 text-center">
<label for="downloads">Downloads</label>
<p id="downloads">@Model.Downloads</p>
</div>
<div class="col-sm-2 text-center" style="overflow-x: hidden">
@{
string deleteUrl = (string.IsNullOrEmpty(Model.DeleteKey)) ? string.Empty : Url.SubRouteUrl("u", "Upload.Delete", new { file = Model.Url, key = Model.DeleteKey });
}
<p id="delete-upload"><button role="button" class="btn btn-danger delete-upload-button" id="@deleteUrl" data-upload-id="@Model.Url">Delete</button></p>
</div>
</div>
</div>

+ 28
- 0
Teknik/Areas/Admin/Views/Admin/UploadSearch.cshtml View File

@@ -0,0 +1,28 @@
@model Teknik.Areas.Admin.ViewModels.UploadSearchViewModel

@using Teknik.Utilities

<script>
// We need to define the action URLs for the script
var searchResultsURL = '@Url.SubRouteUrl("admin", "Admin.Action", new { action = "GetUploadSearchResults" })';
var generateDeleteKeyURL = '@Url.SubRouteUrl("u", "Upload.GenerateDeleteKey")';
</script>

@Scripts.Render("~/bundles/UploadSearch")

<div class="container">
<div class="row">
<div class="col-sm-6 col-sm-offset-3">
<form>
<div class="form-group center-block">
<input type="text" class="form-control" id="Query" name="Query" placeholder="Upload Url" />
</div>
</form>
</div>
</div>
<div class="row">
<div class="col-sm-10 col-sm-offset-1">
<div class="results" id="results"></div>
</div>
</div>
</div>

+ 1
- 1
Teknik/Areas/Upload/Models/Upload.cs View File

@@ -25,7 +25,7 @@ namespace Teknik.Areas.Upload.Models
[CaseSensitive]
public string FileName { get; set; }

public int ContentLength { get; set; }
public long ContentLength { get; set; }

public string ContentType { get; set; }


+ 1
- 1
Teknik/Areas/Upload/ViewModels/DownloadViewModel.cs View File

@@ -10,7 +10,7 @@ namespace Teknik.Areas.Upload.ViewModels
{
public string FileName { get; set; }
public string ContentType { get; set; }
public int ContentLength { get; set; }
public long ContentLength { get; set; }
public string IV { get; set; }
public int keySize { get; set; }
public int blockSize { get; set; }

BIN
Teknik/Scripts/_references.js View File


+ 5
- 0
Teknik/Teknik.csproj View File

@@ -216,6 +216,8 @@
<Compile Include="Areas\Admin\Controllers\AdminController.cs" />
<Compile Include="Areas\Admin\ViewModels\DashboardViewModel.cs" />
<Compile Include="Areas\Admin\ViewModels\SearchResultViewModel.cs" />
<Compile Include="Areas\Admin\ViewModels\UploadResultViewModel.cs" />
<Compile Include="Areas\Admin\ViewModels\UploadSearchViewModel.cs" />
<Compile Include="Areas\Admin\ViewModels\SearchViewModel.cs" />
<Compile Include="Areas\Admin\ViewModels\UserInfoViewModel.cs" />
<Compile Include="Areas\API\APIAreaRegistration.cs" />
@@ -373,6 +375,7 @@
<Content Include="App_Data\robots.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Areas\Admin\Scripts\UploadSearch.js" />
<Content Include="Areas\Admin\Scripts\Search.js" />
<Content Include="Areas\Blog\Content\Blog.css" />
<Content Include="Areas\Blog\Scripts\Blog.js" />
@@ -640,6 +643,8 @@
<Content Include="Areas\FAQ\Views\_ViewStart.cshtml" />
<Content Include="Areas\FAQ\Views\FAQ\Index.cshtml" />
<Content Include="Areas\User\Views\User\GetPremium.cshtml" />
<Content Include="Areas\Admin\Views\Admin\UploadSearch.cshtml" />
<Content Include="Areas\Admin\Views\Admin\UploadResult.cshtml" />
<None Include="Properties\PublishProfiles\Teknik Dev.pubxml" />
<None Include="Properties\PublishProfiles\Teknik Production.pubxml" />
<None Include="Scripts\jquery-2.1.4.intellisense.js" />

Loading…
Cancel
Save