Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FilePicker component #3745

Merged
merged 81 commits into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
e87e8e4
FilePicker : Start
David-Moreira Apr 24, 2022
3eb841b
FilePicker : Show Files, size, progress bar and clear/upload buttons
David-Moreira Apr 25, 2022
b34c80f
Move Progress inside of ListGroupItem
David-Moreira Apr 25, 2022
6baf4df
FilePicker : Set ShouldAutoGenerateId to true for FileEdit JsInterop
David-Moreira Apr 25, 2022
961c02b
Merge branch 'master' into dev-1.1.0-FilePicker
David-Moreira Apr 25, 2022
0daa149
filedit.js : remove file ongoing
David-Moreira Apr 25, 2022
757deec
fileEdit.js | Fix mapElementFilesToFileEntries
David-Moreira Apr 25, 2022
4d1f5cb
Implement RemoveFile // Simple helper for JS Calls
David-Moreira Apr 25, 2022
ad00b80
FileEntry Status
David-Moreira Apr 26, 2022
d023ac6
Commit Dashboard FilePicker example temporarly
David-Moreira Apr 26, 2022
e1962aa
FilePicker : Implement UploadAll capability
David-Moreira Apr 27, 2022
a86a67c
FilePicker : AutoReset default false
David-Moreira Apr 27, 2022
d1cffd9
FilePicker : Drop Files Support
David-Moreira Apr 29, 2022
77f8e2b
Track whether the file is too large and inform the user
David-Moreira Apr 29, 2022
b77a455
Add FileContent and ButtonContent customizability
David-Moreira Apr 29, 2022
ef05505
Finish FileContent implementation
David-Moreira Apr 30, 2022
c505588
Finish ButtonContent
David-Moreira Apr 30, 2022
ed52855
FilePicker localizer
David-Moreira Apr 30, 2022
0813fe9
FilePickerShowMode && FilePickerShowMode.Dropdown implementation
David-Moreira Apr 30, 2022
ed120f6
FilePickerLocalizer
David-Moreira Apr 30, 2022
c0dbf67
FilePicker Drop Or Paste accept only actual files
David-Moreira Apr 30, 2022
59e2fdc
Merge branch 'master' into dev-1.1.0-FilePicker
David-Moreira May 1, 2022
9e45753
Prefer byte[] return on readFileData
David-Moreira May 3, 2022
57fbd56
Dropdown Show CloseButton @onclick:stopPropagation
David-Moreira May 3, 2022
c49f034
FileEdit : Modify OpenReadStream to stream from JS
David-Moreira May 3, 2022
5f95da6
merge
David-Moreira May 9, 2022
b2168ff
Fix RemoteFileEntryStream Progress Report
David-Moreira May 9, 2022
214a9d4
Fix WASM UI freeze with WriteToStreamAsync
David-Moreira May 9, 2022
a53bf50
Demo test update
David-Moreira May 9, 2022
8746f23
FileEdit / FilePicker patch notes
David-Moreira May 9, 2022
44100a3
FileEdit patch notes : rephrase 'problem'
David-Moreira May 9, 2022
d9ac7d6
FileEdit Docs : Add OpenReadStream advise note && Reset Button
David-Moreira May 9, 2022
61d8905
FilePicker : Examples
David-Moreira May 9, 2022
28c1c95
Demo : Revert Dashboard to original and setup FilePicker Page
David-Moreira May 21, 2022
6034aae
Fix multiple filepicker dropzone
David-Moreira May 21, 2022
06f29a4
Demo : Custom example improvements
David-Moreira May 21, 2022
31d386f
Docs : FilePicker Custom example
David-Moreira May 21, 2022
4c4bdd5
Merge
David-Moreira May 31, 2022
d130cdc
merge master
stsrki Jun 7, 2022
85fedb3
merge master
stsrki Jun 7, 2022
e3f19a6
merge
stsrki Jun 7, 2022
a46bedb
Merge branch 'master' into dev-1.1.0-FilePicker
David-Moreira Jul 2, 2022
45090d7
Merge branch 'master' into dev-1.1.0-FilePicker
stsrki Jul 11, 2022
406bfc1
FilePicker Confirm Remove && Dropdown style adjustments
David-Moreira Jul 11, 2022
3371b2e
FilePicker Confirm Remove && Dropdown style adjustments
David-Moreira Jul 11, 2022
6c54a9a
Implement FileEntry Cancel support / FilePicker CancelUpload
David-Moreira Jul 11, 2022
6110f37
FilePicker : Confirm operations for Clear / RemoveFile and CancelUplo…
David-Moreira Jul 17, 2022
f3d3bf6
FilePicker : Rename RenderFragment suffix : Content to Template
David-Moreira Jul 17, 2022
ae7876f
FilePicker : Update Demo & Docs with RenderFragment Template Suffix
David-Moreira Jul 17, 2022
7f6eba0
FilePicker : Fix RemoveFile and Clear actions
David-Moreira Jul 17, 2022
e1b7cb5
FilePicker : Add upload single file btn : Some adjustments to cancell…
David-Moreira Jul 23, 2022
def0108
FileEdit / Picker : Upload Improvements for big files.... // Testing …
David-Moreira Jul 24, 2022
4e1a1ef
merge master
stsrki Aug 10, 2022
a24ee0d
fix merge
stsrki Aug 10, 2022
80261c1
Adjust item alignments
stsrki Aug 10, 2022
381875b
Adjust element sizes
stsrki Aug 10, 2022
ae8acb1
Place FilePicker in Field
stsrki Aug 10, 2022
3252cd4
Adjust margins
stsrki Aug 10, 2022
11046c9
Rename ButtonsTemplate
stsrki Aug 10, 2022
f63d202
Docs: Place FilePicker inside of Field
stsrki Aug 10, 2022
a5d3113
Add placeholder to core FileEdit
stsrki Aug 10, 2022
62eb7f7
Remove custom FileEdit for BS5
stsrki Aug 10, 2022
3d70ea6
Fix SEO
stsrki Aug 10, 2022
a82bdaf
Rename FilePickerButtonsContext
stsrki Aug 10, 2022
c279ca6
merge
David-Moreira Sep 19, 2022
7943fbb
Revert FilePicker page to standard examples
David-Moreira Sep 19, 2022
68f9c9b
Change buffered example to use Microsoft's recommend approach, CopyTo…
David-Moreira Sep 19, 2022
169606b
Remove unedeed comments
David-Moreira Sep 19, 2022
8ba9b0c
Introduce new DisableProgressReport Parameter
David-Moreira Sep 19, 2022
2853e7b
Merge branch 'master' into dev-1.1.0-FilePicker
David-Moreira Sep 19, 2022
668a70a
Docs : FileEdit note about DisableProgressReport
David-Moreira Sep 19, 2022
c0e2d2b
Docs : FilePicker note about DisableProgressReport
David-Moreira Sep 19, 2022
f4c59a2
Blazor.Server Fixes && missing Dispose
David-Moreira Sep 19, 2022
58ba58a
Renames and comments
stsrki Sep 20, 2022
34ee525
Rename cancel APIs
stsrki Sep 20, 2022
968d028
Clean Blazorise.csproj
stsrki Sep 20, 2022
53ed354
Clean
stsrki Sep 20, 2022
398fc9b
Delete WebApplication1
David-Moreira Sep 20, 2022
79e349f
Merge branch 'master' into dev-1.1.0-FilePicker
David-Moreira Sep 20, 2022
319c6ba
Awaitable Cancel method
stsrki Sep 21, 2022
c30f984
Rename member vars
stsrki Sep 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions Blazorise.sln
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazorise.QRCode", "Source\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazorise.Docs.Generator", "Documentation\Blazorise.Docs.Generator\Blazorise.Docs.Generator.csproj", "{F4C121CA-C204-43C4-AF1D-DEE56392526F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazorise.LoadingIndicator", "Source\Extensions\Blazorise.LoadingIndicator\Blazorise.LoadingIndicator.csproj", "{F7975395-2F45-4F4E-850E-ADD4BFFA2D86}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Blazorise.FluentValidation", "Source\Extensions\Blazorise.FluentValidation\Blazorise.FluentValidation.csproj", "{55C2652B-18A3-4B28-935A-67D78BFE6E8C}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazorise.LoadingIndicator", "Source\Extensions\Blazorise.LoadingIndicator\Blazorise.LoadingIndicator.csproj", "{570C2383-EE8C-4F02-91E8-E59B879EDCD2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -278,14 +276,10 @@ Global
{F4C121CA-C204-43C4-AF1D-DEE56392526F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F4C121CA-C204-43C4-AF1D-DEE56392526F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F4C121CA-C204-43C4-AF1D-DEE56392526F}.Release|Any CPU.Build.0 = Release|Any CPU
{F7975395-2F45-4F4E-850E-ADD4BFFA2D86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F7975395-2F45-4F4E-850E-ADD4BFFA2D86}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F7975395-2F45-4F4E-850E-ADD4BFFA2D86}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F7975395-2F45-4F4E-850E-ADD4BFFA2D86}.Release|Any CPU.Build.0 = Release|Any CPU
{55C2652B-18A3-4B28-935A-67D78BFE6E8C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{55C2652B-18A3-4B28-935A-67D78BFE6E8C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{55C2652B-18A3-4B28-935A-67D78BFE6E8C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{55C2652B-18A3-4B28-935A-67D78BFE6E8C}.Release|Any CPU.Build.0 = Release|Any CPU
{570C2383-EE8C-4F02-91E8-E59B879EDCD2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{570C2383-EE8C-4F02-91E8-E59B879EDCD2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{570C2383-EE8C-4F02-91E8-E59B879EDCD2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{570C2383-EE8C-4F02-91E8-E59B879EDCD2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -334,8 +328,7 @@ Global
{7D4C9E83-5211-41C4-BB10-AB4599CA6C3D} = {9731051E-0AA7-411E-A76A-987854F034DA}
{81EDE0C8-05A4-4B5C-88AC-BD100FEC0471} = {9731051E-0AA7-411E-A76A-987854F034DA}
{F4C121CA-C204-43C4-AF1D-DEE56392526F} = {700B33A3-A855-46C3-BD5A-C6954FC7274B}
{F7975395-2F45-4F4E-850E-ADD4BFFA2D86} = {9731051E-0AA7-411E-A76A-987854F034DA}
{55C2652B-18A3-4B28-935A-67D78BFE6E8C} = {9731051E-0AA7-411E-A76A-987854F034DA}
{570C2383-EE8C-4F02-91E8-E59B879EDCD2} = {9731051E-0AA7-411E-A76A-987854F034DA}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {205B3EA4-470F-45DA-911E-346AF7D0A9A5}
Expand Down
1 change: 1 addition & 0 deletions Demos/Blazorise.Demo/Components/SideMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<BarDropdownItem To="tests/dragdrop">Drag & Drop</BarDropdownItem>
<BarDropdownItem To="tests/elements">General UI</BarDropdownItem>
<BarDropdownItem To="tests/figures">Figures</BarDropdownItem>
<BarDropdownItem To="tests/file-picker">File Picker</BarDropdownItem>
<BarDropdownItem To="tests/icons">Icons </BarDropdownItem>
<BarDropdownItem To="tests/listgroup">List group</BarDropdownItem>
<BarDropdownItem To="tests/modals">Modals</BarDropdownItem>
Expand Down
224 changes: 224 additions & 0 deletions Demos/Blazorise.Demo/Pages/Tests/FilePickerPage.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
@page "/tests/file-picker";
@using System.Diagnostics
@using System.IO
@using Blazorise.Extensions

<Row>
<Column ColumnSize="ColumnSize.Is12">
<Card Margin="Margin.Is4.OnY">
<CardHeader>
<CardTitle>Options</CardTitle>
</CardHeader>
<CardBody>
<Field>
<FieldBody>
<Check @bind-Checked="@disableProgressReport">Disable Report Progress</Check>
<Paragraph>By disabling progress report, file transfer can be significantly improved.</Paragraph>
</FieldBody>
</Field>
</CardBody>
</Card>
</Column>
</Row>

<Row>
<Column ColumnSize="ColumnSize.Is12.OnMobile.IsHalf.OnTablet">
<Card Margin="Margin.Is2.OnY">
<CardHeader>
<CardTitle>Standard Upload</CardTitle>
</CardHeader>
<CardBody>
<FilePicker @ref=filePicker
Multiple
MaxChunkSize=FileEditMaxChunkSize
Written=OnFilePartReceived
Ended=OnFileUploadEnded
Progressed=OnFileUploadProgressChanged
Upload="OnFileUpload"
ShowMode="FilePickerShowMode.List"
DisableProgressReport="@disableProgressReport">
</FilePicker>
</CardBody>
</Card>
</Column>
<Column ColumnSize="ColumnSize.Is12.OnMobile.IsHalf.OnTablet">
<Card Margin="Margin.Is2.OnY">
<CardHeader>
<CardTitle>Buffered Upload</CardTitle>
</CardHeader>
<CardBody>
<FilePicker @ref=filePickerBuffered
Multiple
MaxChunkSize=FileEditMaxChunkSize
Written=OnFilePartReceived
Ended=OnFileUploadEnded
Progressed=OnFileUploadProgressChanged
Upload="OnFileUploadBuffered"
ShowMode="FilePickerShowMode.List"
DisableProgressReport="@disableProgressReport">
</FilePicker>
</CardBody>
</Card>
</Column>
</Row>

<Row>
<Column ColumnSize="ColumnSize.Is12.OnMobile.IsHalf.OnTablet">
<Card Margin="Margin.Is4.OnY">
<CardHeader>
<CardTitle>Dropdown Show Mode</CardTitle>
</CardHeader>
<CardBody>
<FilePicker @ref=filePickerDropdown
Multiple
MaxChunkSize=FileEditMaxChunkSize
Written=OnFilePartReceived
Ended=OnFileUploadEnded
Progressed=OnFileUploadProgressChanged
Upload="OnFileUpload"
ShowMode="FilePickerShowMode.Dropdown"
DisableProgressReport="@disableProgressReport">
</FilePicker>
</CardBody>
</Card>
</Column>
<Column ColumnSize="ColumnSize.Is12.OnMobile.IsHalf.OnTablet">
<Card Margin="Margin.Is4.OnY">
<CardHeader>
<CardTitle>Custom</CardTitle>
</CardHeader>
<CardBody>
<FilePicker @ref=filePickerCustom
Multiple
MaxChunkSize=FileEditMaxChunkSize
Written=OnFilePartReceived
Ended=OnFileUploadEnded
Progressed=OnFileUploadProgressChanged
Upload="OnFileUploadBuffered"
ShowMode="FilePickerShowMode.List"
DisableProgressReport="@disableProgressReport">
<FileTemplate>
<Div Flex="Flex.JustifyContent.Between">
<Div>
<Heading Size="HeadingSize.Is5">@context.File.Name</Heading>
<Paragraph>@FilePicker.GetFileSizeReadable(context.File)</Paragraph>
</Div>
<Div>
@if ( context.File.Status == FileEntryStatus.Ready )
{
<Icon TextColor="TextColor.Primary" Name="IconName.FileUpload" />
}
else if ( context.File.Status == FileEntryStatus.Uploading )
{
<Icon TextColor="TextColor.Warning" Name="IconName.Bolt" />
}
else if ( context.File.Status == FileEntryStatus.Uploaded )
{
<Icon TextColor="TextColor.Success" Name="IconName.CheckCircle" />
}
else if ( context.File.Status == FileEntryStatus.Error )
{
<Icon TextColor="TextColor.Danger" Name="IconName.TimesCircle" />
}
</Div>
</Div>
<Divider Margin="Margin.Is0" />
</FileTemplate>
<ButtonsTemplate>
@if ( !disableProgressReport )
{
<Progress Value="@filePickerCustom.GetProgressPercentage()" />
}
<Buttons>
<Button Clicked="@context.Clear" Color="Color.Warning"><Icon Name="IconName.Clear" /></Button>
<Button Clicked="@context.Upload" Color="Color.Primary"><Icon Name="IconName.FileUpload" /></Button>
</Buttons>
</ButtonsTemplate>
</FilePicker>
</CardBody>
</Card>
</Column>
</Row>

@code {
private bool disableProgressReport = false;
private Stopwatch sw = new();
private readonly int FileEditMaxChunkSize = 24 * 1024;
private FilePicker filePicker { get; set; }
private FilePicker filePickerBuffered { get; set; }
private FilePicker filePickerDropdown { get; set; }
private FilePicker filePickerCustom { get; set; }

private async Task FileChanged( Microsoft.AspNetCore.Components.Forms.InputFileChangeEventArgs e )
{
sw.Restart();
using ( MemoryStream result = new MemoryStream() )
{
await InvokeAsync( async () => await e.File.OpenReadStream( long.MaxValue ).CopyToAsync( result ) );
}
sw.Stop();
Console.WriteLine( "file upload using buffer took " + sw.ElapsedMilliseconds + " ms" );
}

private void OnFileUploadEnded( FileEndedEventArgs e )
{
Console.WriteLine( $"File {e.File.Name} upload {( e.Success ? "succeeded" : "failed" )}." );
}

private async Task OnFileUpload( FileUploadEventArgs e )
{
var bytes = await FileUpload( e.File );
}

private async Task OnFileUploadBuffered( FileUploadEventArgs e )
{
var bytes = await FileUploadBuffered( e.File );
}

private async Task<byte[]> FileUpload( IFileEntry file )
{
sw.Restart();
byte[] result = await Read( file );
sw.Stop();
Console.WriteLine( "file upload without explicit buffering took " + sw.ElapsedMilliseconds + " ms" );
return result;
}

private async Task<byte[]> FileUploadBuffered( IFileEntry file )
{
sw.Restart();
byte[] result = await ReadBuffered( file );
sw.Stop();
Console.WriteLine( "file upload using buffer took " + sw.ElapsedMilliseconds + " ms" );
return result;
}

private async Task<byte[]> Read( IFileEntry file )
{
using ( var stream = new MemoryStream() )
{
await file.WriteToStreamAsync( stream );
stream.Seek( 0, SeekOrigin.Begin );
return stream.ToArray();
}
}

private async Task<byte[]> ReadBuffered( IFileEntry file )
{
using ( MemoryStream result = new MemoryStream() )
{
await file.OpenReadStream( long.MaxValue ).CopyToAsync( result );
return result.ToArray();
}
}

private void OnFilePartReceived( FileWrittenEventArgs e )
{
Console.WriteLine( $"File part received. Position: {e.Position} Received data size: {e.Data.Length}" );
}

private void OnFileUploadProgressChanged( FileProgressedEventArgs e )
{
Console.WriteLine( $"File upload progress: {e.Percentage:0.0} %" );
}
}
1 change: 1 addition & 0 deletions Documentation/Blazorise.Docs/Layouts/DocsLayout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<BarDropdownItem To="docs/components/field">Field</BarDropdownItem>
<BarDropdownItem To="docs/components/figure">Figure</BarDropdownItem>
<BarDropdownItem To="docs/components/file">File Edit</BarDropdownItem>
<BarDropdownItem To="docs/components/file-picker">File Picker</BarDropdownItem>
<BarDropdownItem To="docs/components/focus-trap">FocusTrap</BarDropdownItem>
<BarDropdownItem To="docs/components/grid">Grid</BarDropdownItem>
<BarDropdownItem To="docs/components/highlighter">Highlighter</BarDropdownItem>
Expand Down
Loading