Browse Source

Added options to pastes and uploads to add to an existing vault if they are logged in.

pull/50/head
Teknikode 6 years ago
parent
commit
9bce07edfc
  1. 9
      Teknik/Areas/Paste/Controllers/PasteController.cs
  2. 15
      Teknik/Areas/Paste/Scripts/Paste.js
  3. 2
      Teknik/Areas/Paste/ViewModels/PasteViewModel.cs
  4. 11
      Teknik/Areas/Paste/Views/Paste/Full.cshtml
  5. 1
      Teknik/Areas/Upload/Controllers/UploadController.cs
  6. 34
      Teknik/Areas/Upload/Scripts/Upload.js
  7. 9
      Teknik/Areas/Upload/ViewModels/UploadViewModel.cs
  8. 11
      Teknik/Areas/Upload/Views/Upload/Index.cshtml
  9. 35
      Teknik/Areas/Vault/Controllers/VaultController.cs
  10. 4
      Teknik/Areas/Vault/Views/Vault/ViewVault.cshtml

9
Teknik/Areas/Paste/Controllers/PasteController.cs

@ -64,6 +64,15 @@ namespace Teknik.Areas.Paste.Controllers @@ -64,6 +64,15 @@ namespace Teknik.Areas.Paste.Controllers
byte[] data = Encoding.UTF8.GetBytes(paste.Content);
if (User.Identity.IsAuthenticated && type.ToLower() == "full")
{
Users.Models.User user = UserHelper.GetUser(db, User.Identity.Name);
if (user != null)
{
model.Vaults = user.Vaults.ToList();
}
}
// The paste has a password set
if (!string.IsNullOrEmpty(paste.HashedPassword))
{

15
Teknik/Areas/Paste/Scripts/Paste.js

@ -2,12 +2,25 @@ @@ -2,12 +2,25 @@
$('#content').focus();
linkCreateVault($('#create-vault'));
$('#add-to-vault-menu').find('.add-to-vault').each(function () {
linkAddToVault($(this));
});
});
function linkCreateVault(element) {
element.click(function () {
var pasteUrl = $(this).data('paste-url');
var pasteTitle = $(this).data('paste-title');
window.open(createVaultURL + '&urls=' + encodeURIComponent(pasteUrl + ':' + pasteTitle), '_blank');
window.open(createVaultURL + '&items=' + encodeURIComponent(pasteUrl + ':' + pasteTitle), '_blank');
});
}
function linkAddToVault(element) {
element.click(function () {
var addToVaultURL = $(this).data('add-to-vault-url');
var pasteUrl = $(this).data('paste-url');
var pasteTitle = $(this).data('paste-title');
window.open(addToVaultURL + '&items=' + encodeURIComponent(pasteUrl + ':' + pasteTitle), '_blank');
});
}

2
Teknik/Areas/Paste/ViewModels/PasteViewModel.cs

@ -19,5 +19,7 @@ namespace Teknik.Areas.Paste.ViewModels @@ -19,5 +19,7 @@ namespace Teknik.Areas.Paste.ViewModels
public string Password { get; set; }
public bool Hide { get; set; }
public DateTime DatePosted { get; set; }
public List<Vault.Models.Vault> Vaults { get; set; }
}
}

11
Teknik/Areas/Paste/Views/Paste/Full.cshtml

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
@model Teknik.Areas.Paste.ViewModels.PasteViewModel
@using Teknik.Utilities
@using Teknik.Areas.Vault.Models
@Styles.Render("~/Content/paste")
@ -22,6 +23,16 @@ @@ -22,6 +23,16 @@
<a role="button" class="btn btn-default" href="@Url.SubRouteUrl("paste", "Paste.Raw", new { url = Model.Url })">Raw</a>
<a role="button" class="btn btn-default" href="@Url.SubRouteUrl("paste", "Paste.Download", new { url = Model.Url })">Download</a>
<button type="button" class="btn btn-default" id="create-vault" data-paste-url="@Model.Url" data-paste-title="@((string.IsNullOrEmpty(Model.Title)) ? "Untitled" : Model.Title)">Create Vault</button>
@if (User.Identity.IsAuthenticated && Model.Vaults != null && Model.Vaults.Any())
{
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">Add to Vault <span class="caret"></span></button>
<ul class="dropdown-menu pull-right" id="add-to-vault-menu">
@foreach (Vault item in Model.Vaults)
{
<li><a href="#" class="add-to-vault" data-add-to-vault-url="@Url.SubRouteUrl("v", "Vault.EditVault", new { url = item.Url, type = "Paste" })" data-paste-url="@Model.Url" data-paste-title="@((string.IsNullOrEmpty(Model.Title)) ? "Untitled" : Model.Title)">@item.Title</a></li>
}
</ul>
}
</div>
</div>
</div>

1
Teknik/Areas/Upload/Controllers/UploadController.cs

@ -41,6 +41,7 @@ namespace Teknik.Areas.Upload.Controllers @@ -41,6 +41,7 @@ namespace Teknik.Areas.Upload.Controllers
if (user != null)
{
model.Encrypt = user.UploadSettings.Encrypt;
model.Vaults = user.Vaults.ToList();
}
else
{

34
Teknik/Areas/Upload/Scripts/Upload.js

@ -6,6 +6,10 @@ @@ -6,6 +6,10 @@
linkCopyAll($('#copy-all'));
linkCreateVault($('#create-vault'));
$('#add-to-vault-menu').find('.add-to-vault').each(function () {
linkAddToVault($(this));
});
});
function linkUploadDelete(element, deleteUrl) {
@ -90,7 +94,7 @@ function linkCreateVault(element) { @@ -90,7 +94,7 @@ function linkCreateVault(element) {
});
if (allUploads.length > 0) {
var urlList = allUploads.join();
window.open(createVaultURL + '&urls=' + encodeURIComponent(urlList), '_blank');
window.open(createVaultURL + '&items=' + encodeURIComponent(urlList), '_blank');
}
else {
window.open(createVaultURL, '_blank');
@ -98,6 +102,30 @@ function linkCreateVault(element) { @@ -98,6 +102,30 @@ function linkCreateVault(element) {
});
}
function linkAddToVault(element) {
element.click(function () {
var addToVaultURL = $(this).data('add-to-vault-url');
var allUploads = [];
$("div[id^='upload-panel-']").each(function () {
var url = $(this).find('#upload-url').val();
if (url !== '') {
var origFile = $(this).find('#upload-title').text();
if (origFile !== null && origFile !== '') {
url += ':' + origFile;
}
allUploads.unshift(url);
}
});
if (allUploads.length > 0) {
var urlList = allUploads.join();
window.open(addToVaultURL + '&items=' + encodeURIComponent(urlList), '_blank');
}
else {
window.open(addToVaultURL, '_blank');
}
});
}
var fileCount = 0;
var dropZone = new Dropzone(document.body, {
@ -113,7 +141,6 @@ var dropZone = new Dropzone(document.body, { @@ -113,7 +141,6 @@ var dropZone = new Dropzone(document.body, {
fileCount++;
$("#upload-links").css('display', 'inline', 'important');
$('#upload-action-buttons').show();
var itemDiv = $('#upload-template').clone();
itemDiv.attr('id', 'upload-panel-' + fileID);
@ -318,6 +345,9 @@ function uploadComplete(fileID, key, encrypt, evt) { @@ -318,6 +345,9 @@ function uploadComplete(fileID, key, encrypt, evt) {
// Show the details
itemDiv.find('#upload-link-panel').show();
// Allow actions for all uploads
$('#upload-action-buttons').show();
}
}
else

9
Teknik/Areas/Upload/ViewModels/UploadViewModel.cs

@ -11,5 +11,14 @@ namespace Teknik.Areas.Upload.ViewModels @@ -11,5 +11,14 @@ namespace Teknik.Areas.Upload.ViewModels
public string CurrentSub { get; set; }
public bool Encrypt { get; set; }
public List<Vault.Models.Vault> Vaults { get; set; }
public UploadViewModel()
{
CurrentSub = string.Empty;
Encrypt = false;
Vaults = new List<Vault.Models.Vault>();
}
}
}

11
Teknik/Areas/Upload/Views/Upload/Index.cshtml

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
@model Teknik.Areas.Upload.ViewModels.UploadViewModel
@using Teknik.Utilities
@using Teknik.Areas.Vault.Models
<script>
var encScriptSrc = '@Scripts.Url("~/bundles/cryptoWorker")';
@ -53,6 +54,16 @@ @@ -53,6 +54,16 @@
<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-folder"></i>&nbsp;Create Vault</button>
@if (User.Identity.IsAuthenticated && Model.Vaults != null && Model.Vaults.Any())
{
<button type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown"><i class="fa fa-plus"></i>&nbsp;Add to Vault <span class="caret"></span></button>
<ul class="dropdown-menu" id="add-to-vault-menu">
@foreach (Vault item in Model.Vaults)
{
<li><a href="#" class="add-to-vault" data-add-to-vault-url="@Url.SubRouteUrl("v", "Vault.EditVault", new { url = item.Url, type = "Upload" })">@item.Title</a></li>
}
</ul>
}
</div>
</div>
</div>

35
Teknik/Areas/Vault/Controllers/VaultController.cs

@ -111,12 +111,12 @@ namespace Teknik.Areas.Vault.Controllers @@ -111,12 +111,12 @@ namespace Teknik.Areas.Vault.Controllers
[HttpGet]
[AllowAnonymous]
public ActionResult NewVaultFromService(string type, string urls)
public ActionResult NewVaultFromService(string type, string items)
{
ViewBag.Title = "Create Vault";
ModifyVaultViewModel model = new ModifyVaultViewModel();
string[] allURLs = urls.Split(',');
string[] allURLs = items.Split(',');
int index = 0;
foreach (string url in allURLs)
{
@ -145,7 +145,7 @@ namespace Teknik.Areas.Vault.Controllers @@ -145,7 +145,7 @@ namespace Teknik.Areas.Vault.Controllers
}
[HttpGet]
public ActionResult EditVault(string url)
public ActionResult EditVault(string url, string type, string items)
{
ViewBag.Title = "Edit Vault";
Vault.Models.Vault foundVault = db.Vaults.Where(v => v.Url == url).FirstOrDefault();
@ -162,6 +162,7 @@ namespace Teknik.Areas.Vault.Controllers @@ -162,6 +162,7 @@ namespace Teknik.Areas.Vault.Controllers
model.description = foundVault.Description;
int index = 0;
// Add all their existing items for the vault
foreach (VaultItem item in foundVault.VaultItems)
{
ModifyVaultItemViewModel itemModel = new ModifyVaultItemViewModel();
@ -190,6 +191,34 @@ namespace Teknik.Areas.Vault.Controllers @@ -190,6 +191,34 @@ namespace Teknik.Areas.Vault.Controllers
}
}
// If they passed any new items in via the parameters, let's add them
if (!string.IsNullOrEmpty(type) && !string.IsNullOrEmpty(items))
{
string[] allItems = items.Split(',');
foreach (string newItem in allItems)
{
string[] urlInfo = newItem.Split(':');
string itemId = urlInfo[0];
string title = string.Empty;
if (urlInfo.GetUpperBound(0) >= 1)
{
// They also passed in the original filename, so let's use it as our title
title = urlInfo[1];
}
if (IsValidItem(type, itemId))
{
ModifyVaultItemViewModel item = new ModifyVaultItemViewModel();
item.isTemplate = false;
item.index = index;
item.title = title;
item.url = itemId;
item.type = type;
model.items.Add(item);
index++;
}
}
}
return View("~/Areas/Vault/Views/Vault/ModifyVault.cshtml", model);
}
return Redirect(Url.SubRouteUrl("error", "Error.Http403"));

4
Teknik/Areas/Vault/Views/Vault/ViewVault.cshtml

@ -20,8 +20,8 @@ @@ -20,8 +20,8 @@
{
<div class="row">
<div class="col-sm-12">
<div role="group" class="btn-group pull-right">
<a role="button" class="btn btn-primary edit-vault-button" href="@Url.SubRouteUrl("v", "Vault.EditVault", new { url = Model.Url })">Edit</a>
<div class="pull-right">
<a role="button" class="btn btn-primary edit-vault-button" href="@Url.SubRouteUrl("v", "Vault.EditVault", new { url = Model.Url })">Edit</a>&nbsp;
<button role="button" class="btn btn-danger delete-vault-button" data-vault-url="@Model.Url">Delete</button>
</div>
</div>

Loading…
Cancel
Save