Skip to content

Commit

Permalink
Added AssetPreviewManager
Browse files Browse the repository at this point in the history
  • Loading branch information
usercode committed Oct 22, 2022
1 parent 9d32733 commit e4fe8e8
Show file tree
Hide file tree
Showing 22 changed files with 319 additions and 166 deletions.
2 changes: 1 addition & 1 deletion src/DragonFly.Razor/DragonFlyApiExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// https://github.com/usercode/DragonFly
// MIT License

using DragonFly.Assets;
using DragonFly.Razor.Pages.Assets;
using DragonFly.Razor.Pages.ContentItems.Fields;
using DragonFly.Razor.Pages.ContentItems.Query;
using DragonFly.Razor.Pages.ContentSchemas.Fields;
Expand Down
2 changes: 2 additions & 0 deletions src/DragonFly.Razor/DragonFlyClientExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using DragonFly.Builders;
using DragonFly.Core.ContentStructures;
using DragonFly.Razor;
using DragonFly.Razor.Assets;
using DragonFly.Razor.Modules;
using DragonFly.Razor.Services;
using DragonFly.Storage;
Expand Down Expand Up @@ -46,6 +47,7 @@ private static IDragonFlyBuilder AddDragonFlyClient(this WebAssemblyHostBuilder
builder.Services.AddSingleton(ComponentManager.Default);
builder.Services.AddSingleton(ContentFieldManager.Default);
builder.Services.AddSingleton(AssetMetadataManager.Default);
builder.Services.AddSingleton(AssetPreviewManager.Default);

builder.Services.AddTransient(sp => new HttpClient { BaseAddress = apiBaseUri });
builder.Services.AddTransient<ClientContentService>();
Expand Down
30 changes: 30 additions & 0 deletions src/DragonFly.Razor/Extensions/NavigationManagerExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) usercode
// https://github.com/usercode/DragonFly
// MIT License

using Microsoft.AspNetCore.Components;

namespace DragonFly.Razor.Extensions;

public static class NavigationManagerExtensions
{
public static void NavigateToAssets(this NavigationManager manager)
{
manager.NavigateTo("asset");
}

public static void NavigateToAsset(this NavigationManager manager, Asset asset)
{
manager.NavigateTo($"asset/{asset.Id}");
}

public static void NavigateToCreateAsset(this NavigationManager manager, long? folderId = null)
{
manager.NavigateTo($"asset/create/{folderId}");
}

public static void NavigateToContent(this NavigationManager manager, ContentItem content)
{
manager.NavigateTo($"content/{content.Schema.Name}/create/{content.Id}");
}
}
5 changes: 5 additions & 0 deletions src/DragonFly.Razor/Modules/AssetModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// MIT License

using DragonFly.Assets;
using DragonFly.Razor.Pages.Assets.Metadata;
using DragonFly.Razor.Pages.Assets.Preview;
using DragonFly.Razor.Shared;

namespace DragonFly.Razor.Modules;
Expand All @@ -24,5 +26,8 @@ public override void Init(IDragonFlyApi api)

api.RegisterMetadata<ImageMetadata, ImageMetadataView>();
api.RegisterMetadata<PdfMetadata, PdfMetadataView>();

api.AssetPreview().Register<ImagePreviewView>(MimeTypes.WebP, MimeTypes.Jpeg, MimeTypes.Png, MimeTypes.Gif, MimeTypes.Bmp);
api.AssetPreview().Register<PdfPreviewView>(MimeTypes.Pdf);
}
}
239 changes: 114 additions & 125 deletions src/DragonFly.Razor/Pages/Assets/AssetDetail.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,145 +2,134 @@
@page "/asset/create"
@page "/asset/create/{FolderId:guid}"
@inherits AssetDetailBase
@inject ComponentManager FieldComponentManager
@inject ComponentManager ComponentManager
@inject AssetPreviewManager AssetPreviewManager

@if (Entity != null)
{
<div class="content-header">
<h1>Asset</h1>
<div class="content-header">
<h1>Asset</h1>

<Toolbar Items="ToolbarItems"></Toolbar>
</div>
<div class="scroll-content">
<EditForm Model="Entity">
<BSRow>
<div class="col-md-6">

<!-- id -->
<div class="form-group">
<BSRow>
<label class="col-sm-2 col-form-label">ID</label>
<div class="col-sm-10">
<input type="text" class="form-control" @bind-value="@Entity.Id" readonly />
</div>
</BSRow>
</div>

<!-- name -->
<div class="form-group">
<BSRow>
<label class="col-sm-2 col-form-label">Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" @bind-value="@Entity.Name" />
</div>
</BSRow>
</div>

<!-- slug -->
<div class="form-group">
<BSRow>
<label class="col-sm-2 col-form-label">Slug</label>
<div class="col-sm-10">
<input type="text" class="form-control" value="@Entity.Slug" @onchange="x => Entity.Slug = Slugify.ToSlug(x.Value.ToString())" />
</div>
</BSRow>
</div>

<!-- alt -->
<div class="form-group">
<BSRow>
<label class="col-sm-2 col-form-label">Alt</label>
<div class="col-sm-10">
<input type="text" class="form-control" @bind-value="@Entity.Alt" />
</div>
</BSRow>
</div>
<Toolbar Items="ToolbarItems"></Toolbar>
</div>
<div class="scroll-content">
<EditForm Model="Entity">
<BSRow>
<div class="col-md-6">

<!-- mimetype -->
<div class="form-group">
<BSRow>
<label class="col-sm-2 col-form-label">Mimetype</label>
<div class="col-sm-10">
<input type="text" class="form-control" @bind-value="@Entity.MimeType" readonly />
</div>
</BSRow>
</div>

<!-- size -->
<div class="form-group">
<BSRow>
<label class="col-sm-2 col-form-label">Size</label>
<div class="col-sm-10">
<input type="text" class="form-control" value="@Entity.GetFileSize()" readonly />
</div>
</BSRow>
</div>
<!-- id -->
<div class="form-group">
<BSRow>
<label class="col-sm-2 col-form-label">ID</label>
<div class="col-sm-10">
<input type="text" class="form-control" @bind-value="@Entity.Id" readonly />
</div>
</BSRow>
</div>

<!-- folder -->
<div class="form-group">
<BSRow>
<label class="col-sm-2 col-form-label">Folder</label>
<div class="col-sm-10">
@if (Entity.Folder != null)
{
<input type="text" class="form-control" value="@Entity.Folder.Name" readonly />
}
</div>
</BSRow>
</div>
<!-- name -->
<div class="form-group">
<BSRow>
<label class="col-sm-2 col-form-label">Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" @bind-value="@Entity.Name" />
</div>
</BSRow>
</div>

<!-- description -->
<div class="form-group">
<BSRow>
<label class="col-sm-2 col-form-label">Description</label>
<div class="col-sm-10">
<textarea class="form-control" style="height:20rem" @bind="Entity.Description"></textarea>
</div>
</BSRow>
</div>
<!-- slug -->
<div class="form-group">
<BSRow>
<label class="col-sm-2 col-form-label">Slug</label>
<div class="col-sm-10">
<input type="text" class="form-control" value="@Entity.Slug" @onchange="x => Entity.Slug = Slugify.ToSlug(x.Value.ToString())" />
</div>
</BSRow>
</div>

@foreach (var m in Entity.Metaddata)
{
<h3>@m.Key</h3>
@FieldComponentManager.CreateComponent(m.Value)
}
<!-- alt -->
<div class="form-group">
<BSRow>
<label class="col-sm-2 col-form-label">Alt</label>
<div class="col-sm-10">
<input type="text" class="form-control" @bind-value="@Entity.Alt" />
</div>
</BSRow>
</div>
<div class="col-md-6">
@if (IsNewEntity == false)
{
<div>
<InputFile OnChange="OnInputFileChange" />

<!-- mimetype -->
<div class="form-group">
<BSRow>
<label class="col-sm-2 col-form-label">Mimetype</label>
<div class="col-sm-10">
<input type="text" class="form-control" @bind-value="@Entity.MimeType" readonly />
</div>

@if (string.IsNullOrEmpty(Entity.PreviewUrl) == false)
{
<!-- image preview -->
<img src="@Entity.PreviewUrl" />
}
@*else if (Entity.IsPdf())
{
<div id="pdf" style="width: 100%; height: 100%;">
<iframe src="@Entity.GetDataUrl()" style="width: 100%; height: 100%;" frameborder="0" scrolling="no">
<p>It appears your web browser doesn't support iframes.</p>
</iframe>
</div>
}*@
}
</BSRow>
</div>
</BSRow>
</EditForm>
</div>
<div class="content-footer">
<div class="row">
<div class="col-sm-4">
<p>Created: @Entity.CreatedAt</p>

<!-- size -->
<div class="form-group">
<BSRow>
<label class="col-sm-2 col-form-label">Size</label>
<div class="col-sm-10">
<input type="text" class="form-control" value="@Entity.GetFileSize()" readonly />
</div>
</BSRow>
</div>
<div class="col-sm-4">
<p>Modified: @Entity.ModifiedAt</p>

<!-- folder -->
<div class="form-group">
<BSRow>
<label class="col-sm-2 col-form-label">Folder</label>
<div class="col-sm-10">
@if (Entity.Folder != null)
{
<input type="text" class="form-control" value="@Entity.Folder.Name" readonly />
}
</div>
</BSRow>
</div>
<div class="col-sm-4">
<p>Published: @Entity.PublishedAt</p>

<!-- description -->
<div class="form-group">
<BSRow>
<label class="col-sm-2 col-form-label">Description</label>
<div class="col-sm-10">
<textarea class="form-control" style="height:20rem" @bind="Entity.Description"></textarea>
</div>
</BSRow>
</div>

@foreach (var m in Entity.Metaddata)
{
<h3>@m.Key</h3>
@ComponentManager.CreateComponent(m.Value)
}
</div>
<div class="col-md-6">
@if (IsNewEntity == false)
{
<div>
<InputFile OnChange="OnInputFileChange" />
</div>

@AssetPreviewManager.CreateComponent(Entity)
}
</div>
</BSRow>
</EditForm>
</div>
<div class="content-footer">
<div class="row">
<div class="col-sm-4">
<p>Created: @Entity.CreatedAt</p>
</div>
<div class="col-sm-4">
<p>Modified: @Entity.ModifiedAt</p>
</div>
<div class="col-sm-4">
<p>Published: @Entity.PublishedAt</p>
</div>
</div>
</div>
}
5 changes: 3 additions & 2 deletions src/DragonFly.Razor/Pages/Assets/AssetDetail.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using DragonFly.Razor.Extensions;

namespace DragonFly.Razor.Pages.Assets;

Expand Down Expand Up @@ -78,7 +79,7 @@ protected override async Task CreateActionAsync()
{
await ContentService.CreateAsync(Entity);

NavigationManager.NavigateTo($"asset/{Entity.Id}");
NavigationManager.NavigateToAsset(Entity);
}

protected override async Task UpdateActionAsync()
Expand All @@ -90,7 +91,7 @@ protected override async Task DeleteActionAsync()
{
await AssetStore.DeleteAsync(Entity.Id);

NavigationManager.NavigateTo($"asset");
NavigationManager.NavigateToAssets();
}

protected async Task OnInputFileChange(InputFileChangeEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

using Microsoft.AspNetCore.Components;

namespace DragonFly.Assets;
namespace DragonFly.Razor.Pages.Assets;

public abstract class AssetMetadataComponent<T> : ComponentBase, IAssetMetadataComponent
where T : AssetMetadata
Expand Down
Loading

0 comments on commit e4fe8e8

Please sign in to comment.