Browse Source

Created initial Vault viewing page to handle multiple formats.

master
Teknikode 5 years ago
parent
commit
6a620e18f1
  1. 4
      Teknik/Areas/Paste/Models/Paste.cs
  2. 16
      Teknik/Areas/Paste/Views/Paste/Full.cshtml
  3. 4
      Teknik/Areas/Upload/Models/Upload.cs
  4. 4
      Teknik/Areas/User/Models/User.cs
  5. 12
      Teknik/Areas/User/Utility/UserHelper.cs
  6. 5
      Teknik/Areas/Vault/Content/Vault.css
  7. 24
      Teknik/Areas/Vault/Controllers/VaultController.cs
  8. 1
      Teknik/Areas/Vault/Models/Vault.cs
  9. 2
      Teknik/Areas/Vault/Models/VaultItem.cs
  10. 17
      Teknik/Areas/Vault/VaultAreaRegistration.cs
  11. 23
      Teknik/Areas/Vault/ViewModels/CreateVaultViewModel.cs
  12. 14
      Teknik/Areas/Vault/ViewModels/VaultViewModel.cs
  13. 3
      Teknik/Areas/Vault/Views/Vault/Create.cshtml
  14. 121
      Teknik/Areas/Vault/Views/Vault/ViewVault.cshtml
  15. 27
      Teknik/Models/TeknikEntities.cs
  16. 3
      Teknik/Teknik.csproj

4
Teknik/Areas/Paste/Models/Paste.cs

@ -17,6 +17,10 @@ namespace Teknik.Areas.Paste.Models @@ -17,6 +17,10 @@ namespace Teknik.Areas.Paste.Models
public virtual User User { get; set; }
public int? VaultId { get; set; }
public virtual Vault.Models.Vault Vault { get; set; }
public DateTime DatePosted { get; set; }
[CaseSensitive]

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

@ -20,18 +20,16 @@ @@ -20,18 +20,16 @@
</div>
<hr />
<div class="row">
<div class="col-sm-1 col-sm-offset-1 text-center">
<a class="btn btn-default" href="@Url.SubRouteUrl("paste", "Paste.Simple", new { url = Model.Url })">Simple</a>
</div>
<div class="col-sm-1 text-center">
<a class="btn btn-default" href="@Url.SubRouteUrl("paste", "Paste.Raw", new { url = Model.Url })">Raw</a>
</div>
<div class="col-sm-1 text-center">
<a class="btn btn-default" href="@Url.SubRouteUrl("paste", "Paste.Download", new { url = Model.Url })">Download</a>
<div class="col-sm-12 pull-left">
<div class="btn-group" role="group">
<a role="button" class="btn btn-default" href="@Url.SubRouteUrl("paste", "Paste.Simple", new { url = Model.Url })">Simple</a>
<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>
</div>
</div>
</div>
<br />
<div class="row">
<div class="col-sm-10 col-sm-offset-1">@Html.Raw(Model.Content)</div>
<div class="col-sm-12">@Html.Raw(Model.Content)</div>
</div>
</div>

4
Teknik/Areas/Upload/Models/Upload.cs

@ -15,6 +15,10 @@ namespace Teknik.Areas.Upload.Models @@ -15,6 +15,10 @@ namespace Teknik.Areas.Upload.Models
public virtual User User { get; set; }
public int? VaultId { get; set; }
public virtual Vault.Models.Vault Vault { get; set; }
public DateTime DateUploaded { get; set; }
[CaseSensitive]

4
Teknik/Areas/User/Models/User.cs

@ -41,6 +41,10 @@ namespace Teknik.Areas.Users.Models @@ -41,6 +41,10 @@ namespace Teknik.Areas.Users.Models
public virtual ICollection<Paste.Models.Paste> Pastes { get; set; }
public virtual ICollection<Shortener.Models.ShortenedUrl> ShortenedUrls { get; set; }
public virtual ICollection<Vault.Models.Vault> Vaults { get; set; }
public User()
{
Username = string.Empty;

12
Teknik/Areas/User/Utility/UserHelper.cs

@ -472,6 +472,18 @@ namespace Teknik.Areas.Users.Utility @@ -472,6 +472,18 @@ namespace Teknik.Areas.Users.Utility
db.SaveChanges();
}
// Update vaults
List<Vault.Models.Vault> vaults = db.Vaults.Where(u => u.User.Username == user.Username).ToList();
if (vaults != null)
{
foreach (Vault.Models.Vault vault in vaults)
{
vault.UserId = null;
db.Entry(vault).State = EntityState.Modified;
}
db.SaveChanges();
}
// Delete Blogs
Blog.Models.Blog blog = db.Blogs.Where(u => u.User.Username == user.Username).FirstOrDefault();
if (blog != null)

5
Teknik/Areas/Vault/Content/Vault.css

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

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

@ -3,16 +3,22 @@ using System.Collections.Generic; @@ -3,16 +3,22 @@ using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Teknik.Areas.Vault.Models;
using Teknik.Areas.Vault.ViewModels;
using Teknik.Attributes;
using Teknik.Controllers;
using Teknik.Models;
using Teknik.Utilities;
namespace Teknik.Areas.Vault.Controllers
{
[TeknikAuthorize]
public class VaultController : DefaultController
{
private TeknikEntities db = new TeknikEntities();
[AllowAnonymous]
public ActionResult Index()
public ActionResult Create()
{
return View();
}
@ -20,7 +26,21 @@ namespace Teknik.Areas.Vault.Controllers @@ -20,7 +26,21 @@ namespace Teknik.Areas.Vault.Controllers
[AllowAnonymous]
public ActionResult ViewVault(string id)
{
return View();
Models.Vault foundVault = db.Vaults.Where(v => v.Url == id).FirstOrDefault();
if (foundVault != null)
{
VaultViewModel model = new VaultViewModel();
model.Url = foundVault.Url;
model.Title = foundVault.Title;
model.Description = foundVault.Description;
model.DateCreated = foundVault.DateCreated;
model.DateEdited = foundVault.DateEdited;
model.Items = foundVault.Items.ToList();
return View(model);
}
return Redirect(Url.SubRouteUrl("error", "Error.Http404"));
}
}
}

1
Teknik/Areas/Vault/Models/Vault.cs

@ -10,6 +10,7 @@ namespace Teknik.Areas.Vault.Models @@ -10,6 +10,7 @@ namespace Teknik.Areas.Vault.Models
public int VaultId { get; set; }
public int? UserId { get; set; }
public virtual Users.Models.User User { get; set; }
public string Url { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public DateTime DateCreated { get; set; }

2
Teknik/Areas/Vault/Models/VaultItem.cs

@ -10,7 +10,7 @@ namespace Teknik.Areas.Vault.Models @@ -10,7 +10,7 @@ namespace Teknik.Areas.Vault.Models
public int VaultItemId { get; set; }
public int VaultId { get; set; }
public virtual Vault Vault { get; set; }
public string Name { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public DateTime DateAdded { get; set; }
}

17
Teknik/Areas/Vault/VaultAreaRegistration.cs

@ -20,14 +20,27 @@ namespace Teknik.Areas.Vault @@ -20,14 +20,27 @@ namespace Teknik.Areas.Vault
{
Config config = Config.Load();
context.MapSubdomainRoute(
"Vault.Index",
"Vault.Create",
new List<string>() { "vault", "v" }, // Subdomains
new List<string>() { config.Host }, // domains
"",
new { controller = "Vault", action = "Index" },
new { controller = "Vault", action = "Create" },
new[] { typeof(Controllers.VaultController).Namespace }
);
context.MapSubdomainRoute(
"Vault.ViewVault",
new List<string>() { "vault", "v" }, // Subdomains
new List<string>() { config.Host }, // domains
"{id}",
new { controller = "Vault", action = "ViewVault" },
new[] { typeof(Controllers.VaultController).Namespace }
);
// Register style bundles
BundleTable.Bundles.Add(new CdnStyleBundle("~/Content/vault", config.CdnHost).Include(
"~/Areas/Vault/Content/Vault.css"));
// Register Script Bundle
BundleTable.Bundles.Add(new CdnScriptBundle("~/bundles/vault", config.CdnHost).Include(
"~/Areas/Vault/Scripts/Vault.js"));

23
Teknik/Areas/Vault/ViewModels/CreateVaultViewModel.cs

@ -0,0 +1,23 @@ @@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Teknik.Areas.Vault.Models;
using Teknik.ViewModels;
namespace Teknik.Areas.Vault.ViewModels
{
public class CreateVaultViewModel : ViewModelBase
{
public string Title { get; set; }
public string Description { get; set; }
public List<VaultItem> Items { get; set; }
public CreateVaultViewModel()
{
Title = string.Empty;
Description = string.Empty;
Items = new List<VaultItem>();
}
}
}

14
Teknik/Areas/Vault/ViewModels/VaultViewModel.cs

@ -9,14 +9,22 @@ namespace Teknik.Areas.Vault.ViewModels @@ -9,14 +9,22 @@ namespace Teknik.Areas.Vault.ViewModels
{
public class VaultViewModel : ViewModelBase
{
public int VaultId { get; set; }
public string Url { get; set; }
public int? UserId { get; set; }
public Users.Models.User User { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public DateTime DateCreated { get; set; }
public DateTime DateEdited { get; set; }
public List<UploadItem> Uploads { get; set; }
public List<PasteItem> Pastes { get; set; }
public List<VaultItem> Items { get; set; }
public VaultViewModel()
{
Title = string.Empty;
Description = string.Empty;
DateCreated = DateTime.Now;
DateEdited = DateTime.Now;
Items = new List<VaultItem>();
}
}
}

3
Teknik/Areas/Vault/Views/Vault/Create.cshtml

@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
@model Teknik.Areas.Vault.ViewModels.CreateVaultViewModel

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

@ -1,7 +1,126 @@ @@ -1,7 +1,126 @@
@model Teknik.Areas.Vault.ViewModels.VaultViewModel
@using Teknik.Areas.Vault.Models;
@using Teknik.Utilities
@using Teknik.Pygments
@Styles.Render("~/Content/vault")
<div class="container">
<p>Coming Soon!</p>
<div class="row text-center">
<div class="col-sm-12 text-center">
<h2><b>@((string.IsNullOrEmpty(Model.Title)) ? "Untitled" : Model.Title)</b> <small>Created on <time datetime="@Model.DateCreated.ToString("s")">@Model.DateCreated.ToString("dddd, MMMM d, yyyy") at @Model.DateCreated.ToString("h:mm:ss tt")</time></small></h2>
</div>
</div>
<br />
@foreach (VaultItem item in Model.Items)
{
Type itemType = item.GetType();
if (itemType == typeof(PasteItem))
{
PasteItem paste = (PasteItem)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);
<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>
<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.Download", new { url = paste.Paste.Url })">Download</a>
</div>
</div>
</div>
<br />
<div class="row paste-item">
<div class="col-sm-12 paste-content">@Html.Raw(paste.Paste.Content)</div>
</div>
</div>
@if (!string.IsNullOrEmpty(paste.Description))
{
<div class="panel-footer">
<p>@paste.Description</p>
</div>
}
</div>
}
else if (itemType == typeof(UploadItem))
{
UploadItem upload = (UploadItem)item;
<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>
</div>
</div>
<div class="panel-body">
@if (upload.Upload.ContentType.StartsWith("image"))
{
<a href="@Url.SubRouteUrl("u", "Upload.Download", new { file = upload.Upload.Url })" target="_blank">
<img src="@Url.SubRouteUrl("u", "Upload.Download", new { file = upload.Upload.Url })" class="img-thumbnail center-block" />
</a>
}
else if (upload.Upload.ContentType.StartsWith("audio"))
{
<div class="text-center">
<audio preload="none" controls>
<source src="@Url.SubRouteUrl("u", "Upload.Download", new { file = upload.Upload.Url })" type="@upload.Upload.ContentType" />
</audio>
</div>
}
else if (upload.Upload.ContentType.StartsWith("video"))
{
<div class="text-center">
<video preload="none" controls>
<source src="@Url.SubRouteUrl("u", "Upload.Download", new { file = upload.Upload.Url })" type="@upload.Upload.ContentType" />
</video>
</div>
}
else
{
<div class="row">
<div class="col-sm-4 text-center">
<label for="size">Size</label>
<p id="size">@StringHelper.GetBytesReadable(upload.Upload.ContentLength)</p>
</div>
<div class="col-sm-4 text-center">
<label for="type">Type</label>
<p id="type">@upload.Upload.ContentType</p>
</div>
<div class="col-sm-4 text-center">
<label for="dateUploaded">Date Uploaded</label>
<p id="dateUploaded"><time datetime="@upload.Upload.DateUploaded.ToString("s")">@upload.Upload.DateUploaded.ToString("MMMM dd, yyyy")</time></p>
</div>
</div>
}
</div>
@if (!string.IsNullOrEmpty(upload.Description))
{
<div class="panel-footer">
<p>@upload.Description</p>
</div>
}
</div>
}
else
{
// Nothing to see here folks. :)
}
}
</div>

27
Teknik/Models/TeknikEntities.cs

@ -13,6 +13,7 @@ using Teknik.Areas.Shortener.Models; @@ -13,6 +13,7 @@ using Teknik.Areas.Shortener.Models;
using Teknik.Attributes;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Linq;
using Teknik.Areas.Vault.Models;
namespace Teknik.Models
{
@ -52,6 +53,8 @@ namespace Teknik.Models @@ -52,6 +53,8 @@ namespace Teknik.Models
public DbSet<Takedown> Takedowns { get; set; }
// Url Shortener
public DbSet<ShortenedUrl> ShortenedUrls { get; set; }
// Vaults
public DbSet<Vault> Vaults { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
@ -101,6 +104,16 @@ namespace Teknik.Models @@ -101,6 +104,16 @@ namespace Teknik.Models
.WithOptional(u => u.User)
.WillCascadeOnDelete(false);
modelBuilder.Entity<User>()
.HasMany<ShortenedUrl>(u => u.ShortenedUrls)
.WithOptional(u => u.User)
.WillCascadeOnDelete(false);
modelBuilder.Entity<User>()
.HasMany<Vault>(u => u.Vaults)
.WithOptional(u => u.User)
.WillCascadeOnDelete(false);
// Upload Mappings
modelBuilder.Entity<Upload>()
.HasOptional(u => u.User);
@ -109,6 +122,14 @@ namespace Teknik.Models @@ -109,6 +122,14 @@ namespace Teknik.Models
modelBuilder.Entity<Paste>()
.HasOptional(u => u.User);
// Shortened URL Mappings
modelBuilder.Entity<ShortenedUrl>()
.HasOptional(u => u.User);
// Vault Mappings
modelBuilder.Entity<Vault>()
.HasOptional(u => u.User);
// Users
modelBuilder.Entity<User>().ToTable("Users");
modelBuilder.Entity<Group>().ToTable("Groups");
@ -133,6 +154,10 @@ namespace Teknik.Models @@ -133,6 +154,10 @@ namespace Teknik.Models
modelBuilder.Entity<Upload>().ToTable("Uploads");
// Pastes
modelBuilder.Entity<Paste>().ToTable("Pastes");
// Shortened Urls
modelBuilder.Entity<ShortenedUrl>().ToTable("ShortenedUrls");
// Vaults
modelBuilder.Entity<Vault>().ToTable("Vaults");
// Podcasts
modelBuilder.Entity<Podcast>().ToTable("Podcasts");
modelBuilder.Entity<PodcastFile>().ToTable("PodcastFiles");
@ -140,8 +165,6 @@ namespace Teknik.Models @@ -140,8 +165,6 @@ namespace Teknik.Models
// Transparency
modelBuilder.Entity<Transaction>().ToTable("Transactions");
modelBuilder.Entity<Takedown>().ToTable("Takedowns");
// Shortened Urls
modelBuilder.Entity<ShortenedUrl>().ToTable("ShortenedUrls");
// Custom Attributes
modelBuilder.Conventions.Add(new AttributeToColumnAnnotationConvention<CaseSensitiveAttribute, bool>(

3
Teknik/Teknik.csproj

@ -242,6 +242,7 @@ @@ -242,6 +242,7 @@
<Compile Include="Areas\User\Models\TrustedDevice.cs" />
<Compile Include="Areas\User\ViewModels\AuthTokenViewModel.cs" />
<Compile Include="Areas\User\ViewModels\TwoFactorViewModel.cs" />
<Compile Include="Areas\Vault\ViewModels\CreateVaultViewModel.cs" />
<Compile Include="Attributes\TeknikAuthorizeAttribute.cs" />
<Compile Include="Filters\CORSActionFilter.cs" />
<Compile Include="Models\TransferTypes.cs" />
@ -339,6 +340,7 @@ @@ -339,6 +340,7 @@
<Content Include="Areas\User\Scripts\User.js" />
<Content Include="Areas\Shortener\Scripts\Shortener.js" />
<Content Include="Areas\Upload\Scripts\Download.js" />
<Content Include="Areas\Vault\Content\Vault.css" />
<Content Include="Content\audioplayer.css" />
<Content Include="Content\Bootstra.386\bootstrap-theme.css" />
<Content Include="Content\Bootstra.386\bootstrap.css" />
@ -572,6 +574,7 @@ @@ -572,6 +574,7 @@
<Content Include="Areas\User\Views\User\AuthToken.cshtml" />
<Content Include="Areas\Error\Views\Error\Http401.cshtml" />
<Content Include="Areas\Transparency\Views\_ViewStart.cshtml" />
<Content Include="Areas\Vault\Views\Vault\Create.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