mirror of
https://gitlab.com/freepascal.org/fpc/pas2js.git
synced 2025-09-02 17:10:15 +02:00
* Some cleanup
This commit is contained in:
parent
4dda20fc64
commit
8802cf610b
@ -19,12 +19,16 @@
|
|||||||
<p>
|
<p>
|
||||||
You can use the utility to construct a file tree of the ZenFS filesystem. At the same time, you can
|
You can use the utility to construct a file tree of the ZenFS filesystem. At the same time, you can
|
||||||
use the helper routines to create a download link and to download the (virtual) files from browser to disk.
|
use the helper routines to create a download link and to download the (virtual) files from browser to disk.
|
||||||
|
You can use the "Reset" button to clear the filesystem and re-populate it.
|
||||||
</p>
|
</p>
|
||||||
</div> <!-- .box -->
|
</div> <!-- .box -->
|
||||||
<div class="box columns" style="min-height: 400px;">
|
<div class="box columns" style="min-height: 400px;">
|
||||||
<div class="column">
|
<div class="column">
|
||||||
<div id="treeFiles" style="min-height: 300px;">
|
<div id="treeFiles" style="min-height: 300px;">
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<button class="button is-small" id="btnReset">Reset</button>
|
||||||
|
</div>
|
||||||
<div class="field is-horizontal">
|
<div class="field is-horizontal">
|
||||||
<div class="field-label is-normal">
|
<div class="field-label is-normal">
|
||||||
<label class="label">File</label>
|
<label class="label">File</label>
|
||||||
|
@ -17,10 +17,11 @@ Type
|
|||||||
DivDownloads : TJSHTMLElement;
|
DivDownloads : TJSHTMLElement;
|
||||||
FTreeBuilder : THTMLZenFSTree;
|
FTreeBuilder : THTMLZenFSTree;
|
||||||
procedure CreateFiles;
|
procedure CreateFiles;
|
||||||
|
procedure DoReset(Event: TJSEvent); async;
|
||||||
procedure DoSelectFile(Sender: TObject; aFileName: String; aType: TFileType);
|
procedure DoSelectFile(Sender: TObject; aFileName: String; aType: TFileType);
|
||||||
|
procedure MaybeCreateFiles;
|
||||||
procedure SetupFS; async;
|
procedure SetupFS; async;
|
||||||
procedure DoDownload(Event : TJSEvent);
|
procedure DoDownload(Event : TJSEvent);
|
||||||
procedure SelectFile(Sender: TObject; aFileName: String; aType : TFileType);
|
|
||||||
Public
|
Public
|
||||||
constructor Create(aOwner : TComponent); override;
|
constructor Create(aOwner : TComponent); override;
|
||||||
procedure DoRun; override;
|
procedure DoRun; override;
|
||||||
@ -34,12 +35,14 @@ begin
|
|||||||
// Allow to load file specified in hash: index.html#mywasmfile.wasm
|
// Allow to load file specified in hash: index.html#mywasmfile.wasm
|
||||||
BtnDownload:=TJSHTMLButtonElement(GetHTMLElement('btnDownload'));
|
BtnDownload:=TJSHTMLButtonElement(GetHTMLElement('btnDownload'));
|
||||||
BtnDownload.AddEVentListener('click',@DoDownload);
|
BtnDownload.AddEVentListener('click',@DoDownload);
|
||||||
|
BtnDownload:=TJSHTMLButtonElement(GetHTMLElement('btnReset'));
|
||||||
|
BtnDownload.AddEVentListener('click',@DoReset);
|
||||||
EdtFileName:=TJSHTMLInputElement(GetHTMLElement('edtFilename'));
|
EdtFileName:=TJSHTMLInputElement(GetHTMLElement('edtFilename'));
|
||||||
DivDownloads:=GetHTMLElement('divDownloads');
|
DivDownloads:=GetHTMLElement('divDownloads');
|
||||||
FTreeBuilder:=THTMLZenFSTree.Create(Self);
|
FTreeBuilder:=THTMLZenFSTree.Create(Self);
|
||||||
FTreeBuilder.MaxHeight:='300px';
|
FTreeBuilder.MaxHeight:='300px';
|
||||||
FTreeBuilder.ParentElementID:='treeFiles';
|
FTreeBuilder.ParentElementID:='treeFiles';
|
||||||
FTreeBuilder.OnFileSelected:=@SelectFile;
|
FTreeBuilder.OnFileSelected:=@DoSelectFile;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TMyApplication.DoRun;
|
procedure TMyApplication.DoRun;
|
||||||
@ -123,24 +126,13 @@ begin
|
|||||||
EdtFileName.Value:=aFileName;
|
EdtFileName.Value:=aFileName;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TMyApplication.SetupFS;
|
procedure TMyApplication.MaybeCreateFiles;
|
||||||
|
|
||||||
var
|
var
|
||||||
Stat : TZenFSStats;
|
Stat : TZenFSStats;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Terminate;
|
|
||||||
// Set up filesystem
|
|
||||||
aWait(TJSObject,ZenFS.configure(
|
|
||||||
New([
|
|
||||||
'mounts', New([
|
|
||||||
'/',DomBackends.WebStorage
|
|
||||||
])
|
|
||||||
])));
|
|
||||||
// Allow to load file specified in hash: index.html#mywasmfile.wasm
|
|
||||||
try
|
try
|
||||||
Stat:=ZenFS.statSync('/tmp/file1.txt');
|
Stat:=ZenFS.statSync('/tmp/file1.txt');
|
||||||
|
|
||||||
except
|
except
|
||||||
Writeln('Directory structure does not exist, creating one');
|
Writeln('Directory structure does not exist, creating one');
|
||||||
end;
|
end;
|
||||||
@ -148,8 +140,28 @@ begin
|
|||||||
CreateFiles
|
CreateFiles
|
||||||
else
|
else
|
||||||
Writeln('Directory structure already exists.');
|
Writeln('Directory structure already exists.');
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TMyApplication.SetupFS;
|
||||||
|
|
||||||
|
begin
|
||||||
|
Terminate;
|
||||||
|
aWait(TJSObject,ZenFS.configure(
|
||||||
|
New([
|
||||||
|
'mounts', New([
|
||||||
|
'/',DomBackends.WebStorage
|
||||||
|
])
|
||||||
|
])));
|
||||||
|
MaybeCreateFiles;
|
||||||
FTreeBuilder.ShowDir('/');
|
FTreeBuilder.ShowDir('/');
|
||||||
FTreeBuilder.OnFileSelected:=@DoSelectFile;
|
end;
|
||||||
|
|
||||||
|
procedure TMyApplication.DoReset(Event : TJSEvent);
|
||||||
|
|
||||||
|
begin
|
||||||
|
window.localStorage.removeItem('0');
|
||||||
|
FTreeBuilder.Clear;
|
||||||
|
SetupFS;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TMyApplication.DoDownload(Event : TJSEvent);
|
procedure TMyApplication.DoDownload(Event : TJSEvent);
|
||||||
@ -160,11 +172,6 @@ begin
|
|||||||
a.click;
|
a.click;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TMyApplication.SelectFile(Sender: TObject; aFileName: String; aType : TFileType);
|
|
||||||
begin
|
|
||||||
if aType=ftFile then
|
|
||||||
EdtFileName.Value:=aFileName;
|
|
||||||
end;
|
|
||||||
|
|
||||||
var
|
var
|
||||||
Application : TMyApplication;
|
Application : TMyApplication;
|
||||||
|
@ -583,12 +583,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
Function CreateFileTree(const aStartDir : string; aParent : TJSHTMLElement) : TJSHTMLELement;
|
|
||||||
|
|
||||||
begin
|
|
||||||
|
|
||||||
end;
|
|
||||||
|
|
||||||
const base64abc : Array of char = (
|
const base64abc : Array of char = (
|
||||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
|
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
|
||||||
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
||||||
@ -757,6 +751,7 @@ begin
|
|||||||
Result:=TJSHTMLAnchorElement(Document.createElement('a'));
|
Result:=TJSHTMLAnchorElement(Document.createElement('a'));
|
||||||
Result.href:=CreateDataURL(aFileName,aMimetype);
|
Result.href:=CreateDataURL(aFileName,aMimetype);
|
||||||
Result.Download:=ExtractFileName(aFileName);
|
Result.Download:=ExtractFileName(aFileName);
|
||||||
|
aParent.AppendChild(Result);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
|
Loading…
Reference in New Issue
Block a user