diff --git a/Teknik/Areas/Vault/Controllers/VaultController.cs b/Teknik/Areas/Vault/Controllers/VaultController.cs index eeb9c8a..fd4e27d 100644 --- a/Teknik/Areas/Vault/Controllers/VaultController.cs +++ b/Teknik/Areas/Vault/Controllers/VaultController.cs @@ -47,6 +47,11 @@ namespace Teknik.Areas.Vault.Controllers { foreach (VaultItem item in foundVault.Items) { + VaultItemViewModel itemModel = new VaultItemViewModel(); + itemModel.Title = item.Title; + itemModel.Description = item.Description; + itemModel.DateAdded = item.DateAdded; + if (item.GetType().BaseType == typeof(UploadItem)) { UploadItem upload = (UploadItem)item; @@ -54,6 +59,13 @@ namespace Teknik.Areas.Vault.Controllers upload.Upload.Downloads += 1; db.Entry(upload.Upload).State = EntityState.Modified; db.SaveChanges(); + + UploadItemViewModel uploadModel = new UploadItemViewModel(); + uploadModel.Title = item.Title; + uploadModel.Description = item.Description; + uploadModel.DateAdded = item.DateAdded; + uploadModel.Upload = upload.Upload; + model.Items.Add(uploadModel); } else if (item.GetType().BaseType == typeof(PasteItem)) { @@ -70,12 +82,16 @@ namespace Teknik.Areas.Vault.Controllers db.SaveChanges(); break; } - } - model.Items.Add(item); + PasteItemViewModel pasteModel = new PasteItemViewModel(); + pasteModel.Title = item.Title; + pasteModel.Description = item.Description; + pasteModel.DateAdded = item.DateAdded; + pasteModel.Paste = paste.Paste; + model.Items.Add(pasteModel); + } } } - model.Items = foundVault.Items.ToList(); return View(model); } @@ -99,6 +115,7 @@ namespace Teknik.Areas.Vault.Controllers NewVaultViewModel model = new NewVaultViewModel(); string[] allURLs = urls.Split(','); + int index = 0; foreach (string url in allURLs) { string[] urlInfo = url.Split(':'); @@ -112,10 +129,13 @@ namespace Teknik.Areas.Vault.Controllers if (IsValidItem(type, uploadId)) { NewVaultItemViewModel item = new NewVaultItemViewModel(); + item.isTemplate = false; + item.index = index; item.title = title; item.url = uploadId; item.type = type; model.items.Add(item); + index++; } } diff --git a/Teknik/Areas/Vault/ViewModels/NewVaultItemViewModel.cs b/Teknik/Areas/Vault/ViewModels/NewVaultItemViewModel.cs index ed24700..9499eb9 100644 --- a/Teknik/Areas/Vault/ViewModels/NewVaultItemViewModel.cs +++ b/Teknik/Areas/Vault/ViewModels/NewVaultItemViewModel.cs @@ -8,6 +8,8 @@ namespace Teknik.Areas.Vault.ViewModels { public class NewVaultItemViewModel : ViewModelBase { + public bool isTemplate { get; set; } + public int index { get; set; } public string title { get; set; } public string description { get; set; } public string type { get; set; } @@ -15,6 +17,8 @@ namespace Teknik.Areas.Vault.ViewModels public NewVaultItemViewModel() { + isTemplate = true; + index = 0; title = string.Empty; description = string.Empty; type = "Upload"; diff --git a/Teknik/Areas/Vault/ViewModels/PasteItemViewModel.cs b/Teknik/Areas/Vault/ViewModels/PasteItemViewModel.cs new file mode 100644 index 0000000..b35bc20 --- /dev/null +++ b/Teknik/Areas/Vault/ViewModels/PasteItemViewModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using Teknik.ViewModels; + +namespace Teknik.Areas.Vault.ViewModels +{ + public class PasteItemViewModel : VaultItemViewModel + { + public Paste.Models.Paste Paste { get; set; } + } +} \ No newline at end of file diff --git a/Teknik/Areas/Vault/ViewModels/UploadItemViewModel.cs b/Teknik/Areas/Vault/ViewModels/UploadItemViewModel.cs new file mode 100644 index 0000000..867a9e1 --- /dev/null +++ b/Teknik/Areas/Vault/ViewModels/UploadItemViewModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using Teknik.ViewModels; + +namespace Teknik.Areas.Vault.ViewModels +{ + public class UploadItemViewModel : VaultItemViewModel + { + public Upload.Models.Upload Upload { get; set; } + } +} \ No newline at end of file diff --git a/Teknik/Areas/Vault/ViewModels/VaultItemViewModel.cs b/Teknik/Areas/Vault/ViewModels/VaultItemViewModel.cs new file mode 100644 index 0000000..264c9c7 --- /dev/null +++ b/Teknik/Areas/Vault/ViewModels/VaultItemViewModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using Teknik.ViewModels; + +namespace Teknik.Areas.Vault.ViewModels +{ + public class VaultItemViewModel : ViewModelBase + { + public int VaultItemId { get; set; } + public string Title { get; set; } + public string Description { get; set; } + public DateTime DateAdded { get; set; } + } +} \ No newline at end of file diff --git a/Teknik/Areas/Vault/ViewModels/VaultViewModel.cs b/Teknik/Areas/Vault/ViewModels/VaultViewModel.cs index 1440722..5267146 100644 --- a/Teknik/Areas/Vault/ViewModels/VaultViewModel.cs +++ b/Teknik/Areas/Vault/ViewModels/VaultViewModel.cs @@ -16,7 +16,7 @@ namespace Teknik.Areas.Vault.ViewModels public string Description { get; set; } public DateTime DateCreated { get; set; } public DateTime DateEdited { get; set; } - public List Items { get; set; } + public List Items { get; set; } public VaultViewModel() { @@ -24,7 +24,7 @@ namespace Teknik.Areas.Vault.ViewModels Description = string.Empty; DateCreated = DateTime.Now; DateEdited = DateTime.Now; - Items = new List(); + Items = new List(); } } } \ No newline at end of file diff --git a/Teknik/Areas/Vault/Views/Vault/NewVault.cshtml b/Teknik/Areas/Vault/Views/Vault/NewVault.cshtml index 4a9067a..b10ff18 100644 --- a/Teknik/Areas/Vault/Views/Vault/NewVault.cshtml +++ b/Teknik/Areas/Vault/Views/Vault/NewVault.cshtml @@ -10,7 +10,7 @@ var validateItemURL = '@Url.SubRouteUrl("vault", "Vault.Action", new { action = "ValidateItem" })'; var createVaultURL = '@Url.SubRouteUrl("vault", "Vault.Action", new { action = "CreateVault" })'; - var itemCount = 0; + var itemCount = @Model.items.Count(); @@ -156,121 +156,17 @@
@if (Model.items.Any()) { - int index = 0; foreach (NewVaultItemViewModel item in Model.items) { -
-
-
-
-
-
-

@item.title

-
-
-
- - -
-
-
-
-
-
-
Type
-
@item.type
-
Url
-
@item.url
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
- -
- { - index++; - } + @Html.Partial("~/Areas/Vault/Views/Vault/NewVaultItem.cshtml", item) } }
- -@Scripts.Render("~/bundles/vault") \ No newline at end of file +@Scripts.Render("~/bundles/vault") diff --git a/Teknik/Areas/Vault/Views/Vault/NewVaultItem.cshtml b/Teknik/Areas/Vault/Views/Vault/NewVaultItem.cshtml new file mode 100644 index 0000000..d34a7d2 --- /dev/null +++ b/Teknik/Areas/Vault/Views/Vault/NewVaultItem.cshtml @@ -0,0 +1,65 @@ +@model Teknik.Areas.Vault.ViewModels.NewVaultItemViewModel +@{ + bool isTemplate = (Model.isTemplate); +} + +
+
+
+
+
+
+

@(isTemplate ? string.Empty : Model.title)

+
+
+
+ + +
+
+
+
+
+
+
Type
+
@(isTemplate ? string.Empty : Model.type)
+
Url
+
@(isTemplate ? string.Empty : Model.url)
+
+
+ +
+
+
+
+
+ +
+
+
+
+
+ +
+
+
+ @if (!isTemplate) + { + + } +
\ No newline at end of file diff --git a/Teknik/Areas/Vault/Views/Vault/PasteItem.cshtml b/Teknik/Areas/Vault/Views/Vault/PasteItem.cshtml new file mode 100644 index 0000000..5d19508 --- /dev/null +++ b/Teknik/Areas/Vault/Views/Vault/PasteItem.cshtml @@ -0,0 +1,61 @@ +@model Teknik.Areas.Vault.ViewModels.PasteItemViewModel + +@using Teknik.Utilities +@using Teknik.Pygments + +@{ + // Transform content into HTML + if (!Highlighter.Lexers.ToList().Exists(l => l.Aliases.Contains(Model.Paste.Syntax))) + { + Model.Paste.Syntax = "text"; + } + Highlighter highlighter = new Highlighter(); + // Add a space in front of the content due to bug with pygment (No idea why yet) + Model.Paste.Content = highlighter.HighlightToHtml(" " + Model.Paste.Content, Model.Paste.Syntax, Model.Config.PasteConfig.SyntaxVisualStyle, generateInlineStyles: true, fragment: true); +} + +
+
+
+
+

@((string.IsNullOrEmpty(Model.Title)) ? "Paste" : Model.Title) Pasted on - Format: @Model.Paste.Syntax

+
+ +
+
+
+
+
+
+ Simple + Raw + Download +
+
+
+
+
+
+ @if (!string.IsNullOrEmpty(Model.Paste.HashedPassword)) + { +

Password Required

+ } + else + { + @Html.Raw(Model.Paste.Content) + } +
+
+ +
+
+
+ @if (!string.IsNullOrEmpty(Model.Description)) + { + + } +
\ No newline at end of file diff --git a/Teknik/Areas/Vault/Views/Vault/UploadItem.cshtml b/Teknik/Areas/Vault/Views/Vault/UploadItem.cshtml new file mode 100644 index 0000000..f72d544 --- /dev/null +++ b/Teknik/Areas/Vault/Views/Vault/UploadItem.cshtml @@ -0,0 +1,68 @@ +@model Teknik.Areas.Vault.ViewModels.UploadItemViewModel + +@using Teknik.Utilities + +@{ + bool needsKey = (string.IsNullOrEmpty(Model.Upload.Key) && !string.IsNullOrEmpty(Model.Upload.IV)); +} + +
+
+
+
+

@((string.IsNullOrEmpty(Model.Title)) ? "Upload" : Model.Title) Uploaded on

+
+ +
+
+
+ @if (Model.Upload.ContentType.StartsWith("image") && !needsKey) + { + + + + } + else if (Model.Upload.ContentType.StartsWith("audio") && !needsKey) + { +
+ +
+ } + else if (Model.Upload.ContentType.StartsWith("video") && !needsKey) + { +
+ +
+ } + else + { +
+
+ +

@StringHelper.GetBytesReadable(Model.Upload.ContentLength)

+
+
+ +

@Model.Upload.ContentType

+
+
+ +

+
+
+ } +
+ @if (!string.IsNullOrEmpty(Model.Description)) + { + + } +
+ diff --git a/Teknik/Areas/Vault/Views/Vault/ViewVault.cshtml b/Teknik/Areas/Vault/Views/Vault/ViewVault.cshtml index c8819df..fc65eef 100644 --- a/Teknik/Areas/Vault/Views/Vault/ViewVault.cshtml +++ b/Teknik/Areas/Vault/Views/Vault/ViewVault.cshtml @@ -1,6 +1,6 @@ @model Teknik.Areas.Vault.ViewModels.VaultViewModel -@using Teknik.Areas.Vault.Models; +@using Teknik.Areas.Vault.ViewModels @using Teknik.Utilities @using Teknik.Pygments @@ -23,133 +23,20 @@ }
- @foreach (VaultItem item in Model.Items) + @foreach (VaultItemViewModel item in Model.Items) { Type itemType = item.GetType(); - if (itemType.BaseType == typeof(PasteItem)) + if (itemType == typeof(PasteItemViewModel)) { - PasteItem paste = (PasteItem)item; + PasteItemViewModel pasteModel = (PasteItemViewModel)item; - // Transform content into HTML - if (!Highlighter.Lexers.ToList().Exists(l => l.Aliases.Contains(paste.Paste.Syntax))) - { - paste.Paste.Syntax = "text"; - } - Highlighter highlighter = new Highlighter(); - // Add a space in front of the content due to bug with pygment (No idea why yet) - paste.Paste.Content = highlighter.HighlightToHtml(" " + paste.Paste.Content, paste.Paste.Syntax, Model.Config.PasteConfig.SyntaxVisualStyle, generateInlineStyles: true, fragment: true); - -
-
-
-
-

@((string.IsNullOrEmpty(paste.Title)) ? "Paste" : paste.Title) Pasted on - Format: @paste.Paste.Syntax

-
- -
-
-
-
-
-
- Simple - Raw - Download -
-
-
-
-
-
- @if (!string.IsNullOrEmpty(paste.Paste.HashedPassword)) - { -

Password Required

- } - else - { - @Html.Raw(paste.Paste.Content) - } -
-
- -
-
-
- @if (!string.IsNullOrEmpty(paste.Description)) - { - - } -
+ @Html.Partial("~/Areas/Vault/Views/Vault/PasteItem.cshtml", pasteModel) } - else if (itemType.BaseType == typeof(UploadItem)) + else if (itemType == typeof(UploadItemViewModel)) { - UploadItem upload = (UploadItem)item; + UploadItemViewModel uploadModel = (UploadItemViewModel)item; - bool needsKey = (string.IsNullOrEmpty(upload.Upload.Key) && !string.IsNullOrEmpty(upload.Upload.IV)); - -
-
-
-
-

@((string.IsNullOrEmpty(upload.Title)) ? "Upload" : upload.Title) Uploaded on

-
- -
-
-
- @if (upload.Upload.ContentType.StartsWith("image") && !needsKey) - { - - - - } - else if (upload.Upload.ContentType.StartsWith("audio") && !needsKey) - { -
- -
- } - else if (upload.Upload.ContentType.StartsWith("video") && !needsKey) - { -
- -
- } - else - { -
-
- -

@StringHelper.GetBytesReadable(upload.Upload.ContentLength)

-
-
- -

@upload.Upload.ContentType

-
-
- -

-
-
- } -
- @if (!string.IsNullOrEmpty(upload.Description)) - { - - } -
+ @Html.Partial("~/Areas/Vault/Views/Vault/UploadItem.cshtml", uploadModel) } else { diff --git a/Teknik/Teknik.csproj b/Teknik/Teknik.csproj index 4d01266..6c6ff15 100644 --- a/Teknik/Teknik.csproj +++ b/Teknik/Teknik.csproj @@ -244,6 +244,9 @@ + + + @@ -578,6 +581,9 @@ + + +