Browse Source

- Finished 'New Vault' page with support for pre-population from other sources.

- Added a 'Show More' to the pastes for when they are too long.
- Added direct links for each item.
tags/2.0.6
Teknikode 3 years ago
parent
commit
19f42c5276

+ 25
- 4
Teknik/Areas/Upload/Scripts/Upload.js View File

@@ -4,7 +4,8 @@

$("[name='encrypt']").bootstrapSwitch();

linkCopyAll($('#copy-all-button'));
linkCopyAll($('#copy-all'));
linkCreateVault($('#create-vault'));
});

function linkUploadDelete(element, uploadID) {
@@ -59,7 +60,7 @@ function linkRemove(element, fileID) {
$('#upload-panel-' + fileID).remove();
if ($('#upload-links').children().length == 0) {
$("#upload-links").css('display', 'none', 'important');
$('#copy-all-button').hide();
$('#upload-action-buttons').hide();
}
return false;
});
@@ -78,7 +79,7 @@ function linkCopyAll(element) {
$("div[id^='upload-panel-']").each(function () {
var url = $(this).find('#upload-link').text();
if (url !== '') {
allUploads.push(url);
allUploads.unshift(url);
}
});
if (allUploads.length > 0) {
@@ -88,6 +89,25 @@ function linkCopyAll(element) {
});
}

function linkCreateVault(element) {
element.click(function () {
var allUploads = [];
$("div[id^='upload-panel-']").each(function () {
var url = $(this).find('#upload-url').val();
if (url !== '') {
allUploads.unshift(url);
}
});
if (allUploads.length > 0) {
var urlList = allUploads.join();
window.open(createVaultURL + '&urls=' + urlList, '_blank');
}
else {
window.open(createVaultURL, '_blank');
}
});
}

var fileCount = 0;

var dropZone = new Dropzone(document.body, {
@@ -103,7 +123,7 @@ var dropZone = new Dropzone(document.body, {
fileCount++;

$("#upload-links").css('display', 'inline', 'important');
$('#copy-all-button').show();
$('#upload-action-buttons').show();

var itemDiv = $('#upload-template').clone();
itemDiv.attr('id', 'upload-panel-' + fileID);
@@ -292,6 +312,7 @@ function uploadComplete(fileID, key, encrypt, evt) {
itemDiv.find('.panel').addClass('panel-success');

// Add the upload details
itemDiv.find('#upload-url').val(name);
itemDiv.find('#upload-link').attr('href', fullName);
itemDiv.find('#upload-link').text(fullName);
itemDiv.find('#upload-contentType').html(contentType);

+ 8
- 3
Teknik/Areas/Upload/Views/Upload/Index.cshtml View File

@@ -13,7 +13,8 @@
var chunkSize = @Model.Config.UploadConfig.ChunkSize;
var keySize = @Model.Config.UploadConfig.KeySize;
var blockSize = @Model.Config.UploadConfig.BlockSize;
var shortenURL = '@Url.SubRouteUrl("shorten", "Shortener.Action", new { action= "ShortenUrl" })';
var shortenURL = '@Url.SubRouteUrl("shorten", "Shortener.Action", new { action = "ShortenUrl" })';
var createVaultURL = '@Url.SubRouteUrl("vault", "Vault.NewVaultFromService", new { type = "Upload" })';
</script>

@Styles.Render("~/Content/upload")
@@ -50,9 +51,12 @@
</div>
</div>
</div>
<div class="row" id="copy-all-button" style="display: none">
<div class="row" id="upload-action-buttons" style="display: none">
<div class="col-sm-12">
<button type="button" class="btn btn-default btn-sm pull-right" id="copy-all"><i class="fa fa-clipboard"></i>&nbsp;Copy All Uploads</button>
<div class="btn-group pull-right" role="group">
<button type="button" class="btn btn-default btn-sm" id="copy-all"><i class="fa fa-clipboard"></i>&nbsp;Copy All Uploads</button>
<button type="button" class="btn btn-default btn-sm" id="create-vault"><i class="fa fa-clipboard"></i>&nbsp;Add to Vault</button>
</div>
</div>
</div>
<div class="container" id="upload-links">
@@ -88,6 +92,7 @@
</div>
<div class="panel-body" id="upload-details">
<div class="row" id="upload-link-panel">
<input type="hidden" id="upload-url" />
<div class="col-sm-8">
<dl class="dl-horizontal">
<dt>Url</dt>

+ 20
- 2
Teknik/Areas/Vault/Content/Vault.css View File

@@ -1,5 +1,23 @@
.paste-content {
/*.paste-content {
height: 100%;
max-height: 500px;
overflow-y: auto;
overflow-y: hidden;
}*/


.hideContent {
overflow-y: hidden;
height: 100%;
max-height: 400px;
margin-bottom: 10px;
}

.showContent{
height: 100%;
max-height: none;
}

.show-more {
padding: 10px 0;
text-align: center;
}

+ 7
- 3
Teknik/Areas/Vault/Controllers/VaultController.cs View File

@@ -86,17 +86,21 @@ namespace Teknik.Areas.Vault.Controllers
return View(model);
}

public ActionResult NewVaultFromUploads(List<string> urls)
[HttpGet]
[AllowAnonymous]
public ActionResult NewVaultFromService(string type, string urls)
{
ViewBag.Title = "Create Vault";
NewVaultViewModel model = new NewVaultViewModel();

foreach (string url in urls)
string[] allURLs = urls.Split(',');
foreach (string url in allURLs)
{
if (IsValidItem("Upload", url))
if (IsValidItem(type, url))
{
NewVaultItemViewModel item = new NewVaultItemViewModel();
item.url = url;
item.type = type;
model.items.Add(item);
}
}

+ 47
- 5
Teknik/Areas/Vault/Scripts/Vault.js View File

@@ -61,9 +61,9 @@

itemDiv.find('#edit-item').attr('id', itemCount);

itemDiv.find('#remove-item').click(function () {
itemDiv.remove();
});
linkRemove(itemDiv);
linkMoveUp(itemDiv);
linkMoveDown(itemDiv);

$('#vault-items').append(itemDiv);

@@ -120,12 +120,20 @@
items.push(item);
});

// First Validation
// Validation
if (title == null || title == '') {
$("#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>You must supply a Title</div>');
return false;
}

if (items.length == 0) {
$("#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>You must have at least one item in the vault</div>');
return false;
}

// Create the vault
$.ajax({
type: "POST",
url: createVaultURL,
@@ -142,4 +150,38 @@
});
return false;
});
});

$("#show-more-button").on("click", function () {
var link = $(this);
var contentDiv = link.parent().prev("div.paste-content");
var linkText = link.text().toUpperCase();

if (linkText === "SHOW MORE") {
linkText = "Show Less";
contentDiv.removeClass('hideContent');
contentDiv.addClass('showContent');
} else {
linkText = "Show More";
contentDiv.removeClass('showContent');
contentDiv.addClass('hideContent');
};

link.text(linkText);
});
});

function linkRemove(element) {
element.find('#remove-item').click(function () {
element.remove();
});
}
function linkMoveUp(element) {
element.find('#move-up').click(function () {
moveUp(element);
});
}
function linkMoveDown(element) {
element.find('#move-down').click(function () {
moveDown(element);
});
}

+ 11
- 2
Teknik/Areas/Vault/VaultAreaRegistration.cs View File

@@ -23,16 +23,25 @@ namespace Teknik.Areas.Vault
"Vault.NewVault",
new List<string>() { "vault", "v" }, // Subdomains
new List<string>() { config.Host }, // domains
"",
"Create",
new { controller = "Vault", action = "NewVault" },
new[] { typeof(Controllers.VaultController).Namespace }
);

context.MapSubdomainRoute(
"Vault.NewVaultFromService",
new List<string>() { "vault", "v" }, // Subdomains
new List<string>() { config.Host }, // domains
"Create/{type}",
new { controller = "Vault", action = "NewVaultFromService" },
new[] { typeof(Controllers.VaultController).Namespace }
);

context.MapSubdomainRoute(
"Vault.ViewVault",
new List<string>() { "vault", "v" }, // Subdomains
new List<string>() { config.Host }, // domains
"{id}",
"v/{id}",
new { controller = "Vault", action = "ViewVault" },
new[] { typeof(Controllers.VaultController).Namespace }
);

+ 108
- 58
Teknik/Areas/Vault/Views/Vault/NewVault.cshtml View File

@@ -10,8 +10,7 @@
var validateItemURL = '@Url.SubRouteUrl("vault", "Vault.Action", new { action = "ValidateItem" })';
var createVaultURL = '@Url.SubRouteUrl("vault", "Vault.Action", new { action = "CreateVault" })';


var itemCount = @Model.items.Count();
var itemCount = 0;

</script>

@@ -120,75 +119,117 @@
</div>
<form class="form" action="@Url.SubRouteUrl("vault", "Vault.Action", new { action = "CreateVault" })" method="post" id="newVaultForm">
<div class="row">
<div class="form-group col-sm-10 col-sm-offset-1">
<label for="title"><h4>Title</h4></label>
<input class="form-control" name="title" id="title" placeholder="Collection of items" title="enter a title for your vault." type="text" />
<div class="col-sm-10">
<div class="row">
<div class="form-group col-sm-10 col-sm-offset-1">
<label for="title"><h4>Title</h4></label>
<input class="form-control" name="title" id="title" placeholder="Collection of items" title="enter a title for your vault." type="text" />
</div>
</div>
<div class="row">
<div class="form-group col-sm-10 col-sm-offset-1">
<label for="article"><h4>Description</h4></label>
<textarea class="form-control" name="description" id="description" placeholder="This is a cool collection of uploads and pastes" title="enter the description for this vault" rows="5"></textarea>
</div>
</div>
</div>
</div>
<div class="row">
<div class="form-group col-sm-10 col-sm-offset-1">
<label for="article"><h4>Description</h4></label>
<textarea class="form-control" name="description" id="description" placeholder="This is a cool collection of uploads and pastes" title="enter the description for this vault" rows="5"></textarea>
<div class="col-sm-2">
<br />
<br />
<div class="row">
<div class="form-group col-sm-12">
<button type="submit" class="btn btn-primary pull-left" id="submit">Save Vault</button>
</div>
</div>
</div>
</div>
<div class="row">
<div class="form-group col-sm-8 col-sm-offset-2">
<button type="button" class="btn btn-primary pull-right" id="add-item" data-toggle="modal" data-target="#newItem">Add Item</button>
</div>
<div class="form-group col-sm-2">
<button type="submit" class="btn btn-primary pull-right" id="submit">Save Vault</button>
<br />
<div class="col-sm-10">
<div class="row">
<div class="form-group col-sm-10 col-sm-offset-1">
<button type="button" class="btn btn-default pull-right" id="add-item" data-toggle="modal" data-target="#newItem">Add Item</button>
</div>
</div>
</div>
<br />
<div class="container" id="vault-items">
@if (Model.items.Any())
{
int index = 0;
foreach (NewVaultItemViewModel item in Model.items)
<div class="row">
<div class="col-sm-10" id="vault-items">
@if (Model.items.Any())
{
<div class="row vault-item" id="vault-item-@index">
<div class="col-sm-8 col-sm-offset-2">
<div class="panel panel-default">
<div class="panel-heading">
<div class="row">
<div class="col-sm-8 text-left">
<h4><b id="item-title">@item.title</b></h4>
</div>
<div class="col-sm-4">
<div class="btn-group pull-right" role="group">
<button type="button" class="btn btn-default" id="edit-item" data-toggle="modal" data-target="#editItem">Edit</button>
<button type="button" class="btn btn-danger" id="remove-item">Remove</button>
int index = 0;
foreach (NewVaultItemViewModel item in Model.items)
{
<div class="row vault-item" id="vault-item-@index">
<div class="col-sm-9 col-sm-offset-1">
<div class="panel panel-default">
<div class="panel-heading">
<div class="row">
<div class="col-sm-8 text-left">
<h4><b id="item-title">@item.title</b></h4>
</div>
<div class="col-sm-4">
<div class="btn-group pull-right" role="group">
<button type="button" class="btn btn-default" id="@index" data-toggle="modal" data-target="#editItem">Edit</button>
<button type="button" class="btn btn-danger" id="remove-item">Remove</button>
</div>
</div>
</div>
</div>
<div class="panel-body">
<dl class="dl-horizontal pull-left">
<dt>Type</dt>
<dd id="item-type">@item.type</dd>
<dt>Url</dt>
<dd id="item-url">@item.url</dd>
</dl>
</div>
<div class="panel-footer">
<p id="item-description">@item.description</p>
</div>
</div>
<div class="panel-body">
<div class="row">
<div class="col-sm-10 col-sm-offset-1 text-left">
<dl class="dl-horizontal">
<dt>Type</dt>
<dd id="item-type">@item.type</dd>
<dt>Url</dt>
<dd id="item-url">@item.url</dd>
</dl>
</div>
</div>
<div class="col-sm-1">
<div class="row">
<div class="col-sm-12">
<button type="button" class="btn btn-default" id="move-up"><i class="fa fa-chevron-up"></i></button>
</div>
</div>
<div class="panel-footer" @((string.IsNullOrEmpty(item.description)) ? "style=\"display: none\"" : string.Empty)>
<p id="item-description">@item.description</p>
<br />
<div class="row">
<div class="col-sm-12">
<button type="button" class="btn btn-default" id="move-down"><i class="fa fa-chevron-down"></i></button>
</div>
</div>
</div>
<script type="text/javascript">
itemCount++;
$(document).ready(function () {
var itemDiv = $('#vault-item-@index');

linkRemove(itemDiv);
linkMoveUp(itemDiv);
linkMoveDown(itemDiv);

@if (string.IsNullOrEmpty(item.description))
{
@:itemDiv.find('.panel-footer').hide();
}
});
</script>
</div>
</div>
{
index++;
}
}
}
}
</div>
</div>
</form>
</div>

<div id="templates" style="display: none">
<div class="row" id="item-template">
<div class="col-sm-8 col-sm-offset-2">
<div class="col-sm-9 col-sm-offset-1">
<div class="panel panel-default">
<div class="panel-heading">
<div class="row">
@@ -204,22 +245,31 @@
</div>
</div>
<div class="panel-body">
<div class="row">
<div class="col-sm-10 col-sm-offset-1 text-left">
<dl class="dl-horizontal">
<dt>Type</dt>
<dd id="item-type"></dd>
<dt>Url</dt>
<dd id="item-url"></dd>
</dl>
</div>
</div>
<dl class="dl-horizontal">
<dt>Type</dt>
<dd id="item-type"></dd>
<dt>Url</dt>
<dd id="item-url"></dd>
</dl>
</div>
<div class="panel-footer">
<p id="item-description"></p>
</div>
</div>
</div>
<div class="col-sm-1">
<div class="row">
<div class="col-sm-12">
<button type="button" class="btn btn-default" id="move-up"><i class="fa fa-chevron-up"></i></button>
</div>
</div>
<br />
<div class="row">
<div class="col-sm-12">
<button type="button" class="btn btn-default" id="move-down"><i class="fa fa-chevron-down"></i></button>
</div>
</div>
</div>
</div>
</div>


+ 24
- 9
Teknik/Areas/Vault/Views/Vault/ViewVault.cshtml View File

@@ -40,31 +40,41 @@
paste.Paste.Content = highlighter.HighlightToHtml(" " + paste.Paste.Content, paste.Paste.Syntax, Model.Config.PasteConfig.SyntaxVisualStyle, generateInlineStyles: true, fragment: true);

<div class="panel panel-default">
<div class="panel-heading text-left">
<h4><b><a href="@Url.SubRouteUrl("p", "Paste.View", new { file = paste.Paste.Url })" target="_blank">@((string.IsNullOrEmpty(paste.Title)) ? "Paste" : paste.Title)</a></b> <small>Pasted on <time datetime="@paste.Paste.DatePosted.ToString("s")">@paste.Paste.DatePosted.ToString("dddd, MMMM d, yyyy") at @paste.Paste.DatePosted.ToString("h:mm:ss tt")</time> - Format: <b id="syntaxLanguage">@paste.Paste.Syntax</b></small></h4>
<div class="panel-heading">
<div class="row">
<div class="col-sm-10 text-left">
<h4><b>@((string.IsNullOrEmpty(paste.Title)) ? "Paste" : paste.Title)</b> <small>Pasted on <time datetime="@paste.Paste.DatePosted.ToString("s")">@paste.Paste.DatePosted.ToString("dddd, MMMM d, yyyy") at @paste.Paste.DatePosted.ToString("h:mm:ss tt")</time> - Format: <b id="syntaxLanguage">@paste.Paste.Syntax</b></small></h4>
</div>
<div class="col-sm-2 text-right">
<h4><small><a href="@Url.SubRouteUrl("p", "Paste.View", new { url = paste.Paste.Url })" target="_blank">Direct Link</a></small></h4>
</div>
</div>
</div>
<div class="panel-body">
<div class="row">
<div class="col-sm-12 pull-left">
<div class="btn-group" role="group">
<a role="button" class="btn btn-default" href="@Url.SubRouteUrl("p", "Paste.Simple", new { url = paste.Paste.Url })">Simple</a>
<a role="button" class="btn btn-default" href="@Url.SubRouteUrl("p", "Paste.Raw", new { url = paste.Paste.Url })">Raw</a>
<a role="button" class="btn btn-default" href="@Url.SubRouteUrl("p", "Paste.Simple", new { url = paste.Paste.Url })" target="_blank">Simple</a>
<a role="button" class="btn btn-default" href="@Url.SubRouteUrl("p", "Paste.Raw", new { url = paste.Paste.Url })" target="_blank">Raw</a>
<a role="button" class="btn btn-default" href="@Url.SubRouteUrl("p", "Paste.Download", new { url = paste.Paste.Url })">Download</a>
</div>
</div>
</div>
<br />
<div class="row paste-item">
<div class="col-sm-12 paste-content">
<div class="col-sm-12 paste-content hideContent">
@if (!string.IsNullOrEmpty(paste.Paste.HashedPassword))
{
<p class="text-center">Password Required</p>
}
else
{
Html.Raw(paste.Paste.Content);
@Html.Raw(paste.Paste.Content)
}
</div>
<div class="show-more">
<button class="btn btn-default btn-sm" id="show-more-button">Show More</button>
</div>
</div>
</div>
@if (!string.IsNullOrEmpty(paste.Description))
@@ -84,8 +94,11 @@
<div class="panel panel-default">
<div class="panel-heading">
<div class="row">
<div class="col-sm-12 text-left">
<h4><b><a href="@Url.SubRouteUrl("u", "Upload.Download", new { file = upload.Upload.Url })" target="_blank">@((string.IsNullOrEmpty(upload.Title)) ? "Upload" : upload.Title)</a></b> <small>Uploaded on <time datetime="@upload.Upload.DateUploaded.ToString("s")">@upload.Upload.DateUploaded.ToString("dddd, MMMM d, yyyy") at @upload.Upload.DateUploaded.ToString("h:mm:ss tt")</time></small></h4>
<div class="col-sm-10 text-left">
<h4><b>@((string.IsNullOrEmpty(upload.Title)) ? "Upload" : upload.Title)</b> <small>Uploaded on <time datetime="@upload.Upload.DateUploaded.ToString("s")">@upload.Upload.DateUploaded.ToString("dddd, MMMM d, yyyy") at @upload.Upload.DateUploaded.ToString("h:mm:ss tt")</time></small></h4>
</div>
<div class="col-sm-2 text-right">
<h4><small><a href="@Url.SubRouteUrl("u", "Upload.Download", new { file = upload.Upload.Url })" target="_blank">Direct Link</a></small></h4>
</div>
</div>
</div>
@@ -143,4 +156,6 @@
// Nothing to see here folks. :)
}
}
</div>
</div>

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

+ 19
- 11
Teknik/Global.asax.cs View File

@@ -46,22 +46,30 @@ namespace Teknik

protected void Application_EndRequest(object sender, EventArgs e)
{
HttpContext context = HttpContext.Current;
try
{
HttpContext context = HttpContext.Current;

// Set the generation time in the header
Stopwatch stopwatch = (Stopwatch)context.Items["Stopwatch"];
stopwatch.Stop();
// Set the generation time in the header
Stopwatch stopwatch = (Stopwatch)context.Items["Stopwatch"];
stopwatch.Stop();

TimeSpan ts = stopwatch.Elapsed;
string elapsedTime = String.Format("{0} seconds", ts.TotalSeconds);
TimeSpan ts = stopwatch.Elapsed;
string elapsedTime = String.Format("{0} seconds", ts.TotalSeconds);

context.Response.AppendHeader("GenerationTime", elapsedTime);
context.Response.AppendHeader("GenerationTime", elapsedTime);

// Allow this domain, or everything if local
string origin = (Request.IsLocal) ? "*" : context.Request.Headers.Get("Origin");
if (!string.IsNullOrEmpty(origin))
// Allow this domain, or everything if local
string origin = (Request.IsLocal) ? "*" : context.Request.Headers.Get("Origin");
if (!string.IsNullOrEmpty(origin))
{
context.Response.AppendHeader("Access-Control-Allow-Origin", origin);
}
}
catch (Exception ex)
{
context.Response.AppendHeader("Access-Control-Allow-Origin", origin);
// Just log it
Logging.Logger.WriteEntry(ex);
}
}


+ 24
- 0
Teknik/Scripts/Common.js View File

@@ -216,6 +216,30 @@ function getReadableBandwidthString(bandwidth) {

return Math.max(bandwidth, 0.1).toFixed(1) + byteUnits[i];
}

function moveUp(item) {
var prev = item.prev();
if (prev.length == 0)
return;
prev.css('z-index', 999).css('position', 'relative').animate({ top: item.height() }, 250);
item.css('z-index', 1000).css('position', 'relative').animate({ top: '-' + prev.height() }, 300, function () {
prev.css('z-index', '').css('top', '').css('position', '');
item.css('z-index', '').css('top', '').css('position', '');
item.insertBefore(prev);
});
}

function moveDown(item) {
var next = item.next();
if (next.length == 0)
return;
next.css('z-index', 999).css('position', 'relative').animate({ top: '-' + item.height() }, 250);
item.css('z-index', 1000).css('position', 'relative').animate({ top: next.height() }, 300, function () {
next.css('z-index', '').css('top', '').css('position', '');
item.css('z-index', '').css('top', '').css('position', '');
item.insertAfter(next);
});
}
/***************************** TIMER Page Load *******************************/
var loopTime;
var startTime = new Date();

Loading…
Cancel
Save