Skip to content

Commit

Permalink
#31 - Profile can defined date time format.
Browse files Browse the repository at this point in the history
  • Loading branch information
maraf committed Feb 6, 2019
1 parent 5b0897a commit 53a836a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/FileUpload.Web.UI/Models/UploadSettings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Neptuo.Text.Tokens;
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand All @@ -21,6 +20,8 @@ public class UploadSettings
public string BackupTemplate { get; set; }
public List<string> Roles { get; set; }

public string DateTimeFormat { get; set; }

public bool IsSupportedExtension(string extension)
{
if (SupportedExtensions == null || SupportedExtensions.Count == 0)
Expand Down
12 changes: 11 additions & 1 deletion src/FileUpload.Web.UI/ViewModels/BrowseViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ namespace FileUpload.ViewModels
public class BrowseViewModel
{
private readonly string downloadUrl;
private readonly string dateTimeFormat;

public string ReloadUrl { get; }

public IReadOnlyList<FileModel> Files { get; }
public bool IsDownloadEnabled { get; }
public bool IsDeleteEnabled { get; }

public BrowseViewModel(IReadOnlyList<FileModel> files, string downloadUrl, string reloadUrl, bool isDownloadEnabled, bool isDeleteEnabled)
public BrowseViewModel(IReadOnlyList<FileModel> files, string downloadUrl, string reloadUrl, bool isDownloadEnabled, bool isDeleteEnabled, string dateTimeFormat)
{
Ensure.NotNull(files, "files");
Ensure.NotNull(downloadUrl, "downloadUrl");
Expand All @@ -28,6 +29,7 @@ public BrowseViewModel(IReadOnlyList<FileModel> files, string downloadUrl, strin
IsDeleteEnabled = isDeleteEnabled;
ReloadUrl = reloadUrl;
this.downloadUrl = downloadUrl;
this.dateTimeFormat = dateTimeFormat;
}

public string GetFileUrl(FileModel file)
Expand All @@ -37,5 +39,13 @@ public string GetFileUrl(FileModel file)
else
return downloadUrl + '/' + file.Name;
}

public string Format(DateTime dateTime)
{
if (String.IsNullOrEmpty(dateTimeFormat))
return dateTime.ToString();

return dateTime.ToString(dateTimeFormat);
}
}
}
9 changes: 8 additions & 1 deletion src/FileUpload.Web.UI/ViewModels/Factory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ public BrowseViewModel CreateBrowser()
if (files == null)
return null;

return new BrowseViewModel(files, urlBuilder.Index(), urlBuilder.Browse(noLayout: true), configuration.IsDownloadEnabled, configuration.IsDeleteEnabled);
return new BrowseViewModel(
files,
urlBuilder.Index(),
urlBuilder.Browse(noLayout: true),
configuration.IsDownloadEnabled,
configuration.IsDeleteEnabled,
configuration.DateTimeFormat
);
}

public UploadViewModel CreateUpload()
Expand Down
2 changes: 1 addition & 1 deletion src/FileUpload.Web.UI/Views/Shared/_Browser.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
@(Math.Max(1, Math.Round(((decimal)file.Size / 1000), MidpointRounding.AwayFromZero)).ToString("N0")) KB
</td>
<td class="file-modifiedat">
@file.ModifiedAt
@Model.Format(file.ModifiedAt)
</td>
@if (Model.IsDeleteEnabled)
{
Expand Down
3 changes: 2 additions & 1 deletion src/FileUpload.Web.UI/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"IsDownloadEnabled": true,
"IsBrowserEnabled": true,
"IsDeleteEnabled": true,
"IsListed": true
"IsListed": true,
"DateTimeFormat": "yyyy-MM-dd HH:mm"
},
"Profiles": {
"images": {
Expand Down

0 comments on commit 53a836a

Please sign in to comment.