Skip to content

File manager #110

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

Merged
merged 2 commits into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
File manager
  • Loading branch information
graham-trott committed Jun 8, 2020
commit a2b355ba56e16c381aa91d3489e299907d58339f
48 changes: 24 additions & 24 deletions dist/easycoder-min.js

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion dist/easycoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -5659,12 +5659,23 @@ const EasyCoder_Browser = {
}
}
};
ajax.onerror = function (data) {
if (command.onError) {
program.errorMessage = this.responseText;
program.run(command.onError);
} else {
const error = this.responseText;
program.runtimeError(command.lino, error);
}
};
program.ajaxCommand = command;
const rest = document.getElementById(`easycoder-rest`);
if (!rest) {
program.runtimeError(command.lino, `No REST server defined`);
}
const postpath = path.startsWith(`http`) ? path : `${window.location.origin}${rest}/${path}`;
const postpath = path.startsWith(`http`)
? path
: `${window.location.origin}/${rest.innerText}/${path}`;
ajax.open(`POST`, postpath);
ajax.send(formData);
}
Expand Down
267 changes: 267 additions & 0 deletions iwsy/resources/ecs/fileman.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
! File Manager

script FileManager

import div Container

div Tracer
div Panel
div FileListing
div FileRow
div Scroller
div Uploader
div Buttons
div Location
span UploadStatus
progress UploadProgress
input UploadFile
input URL
button CloseButton
button NewFolderButton
button UploadButton
button DeleteButton
a FileName
img Icon
img Image
variable Mobile
variable FileCount
variable File
variable Name
variable Type
variable Source
variable Content
variable Home
variable UserRecord
variable CurrentPath
variable FilePath
variable Path
variable N
variable Even

if portrait
begin
if mobile set Mobile else clear Mobile
end

create Panel in Container
if Mobile set the style of Panel to `background:#ffe`
else set the style of Panel to `width:100%;height:100%;background:#ffe`

create Tracer in Panel
set attribute `id` of Tracer to `easycoder-tracer`

create Uploader in Panel
set the style of Uploader to `width:100%;padding:0.5em 0;font-size:80%;text-align:center`
create UploadFile in Uploader
set the style of UploadFile to `font-family:serif;color:black`
set attribute `type` of UploadFile to `file`
set attribute `name` of UploadFile to `Source`
create UploadStatus in Uploader
set the style of UploadStatus to `font-family:serif;color:black`
create UploadProgress in Uploader
set style `margin-left` of UploadProgress to `0.5em`
set attribute `value` of UploadProgress to 0
set attribute `max` of UploadProgress to 100

create Buttons in Panel
set the style of Buttons to `display:flex`
create UploadButton in Buttons
set the style of UploadButton to `flex:1;width:150px;height:40px;font-family:sans;color:black`
set the text of UploadButton to `Upload`
on click UploadButton go to Upload
create NewFolderButton in Buttons
set the style of NewFolderButton to `flex:1;width:150px;height:40px;font-family:sans;color:black`
set the text of NewFolderButton to `New Folder`
create DeleteButton in Buttons
set the style of DeleteButton to `flex:1;width:150px;height:40px;font-family:sans;color:black`
set the text of DeleteButton to `Delete`
create CloseButton in Buttons
set the style of CloseButton to `flex:1;width:150px;height:40px;font-family:sans;color:black`
set the text of CloseButton to `Close`
on click CloseButton go to Exit

create FileListing in Panel
set the style of FileListing to `width:100%;height:80%;text-align:center`
create Location in FileListing
set the style of Location to `width:100%;text-align:left;color:black;padding:0 0.5em`
create URL in FileListing
set the style of URL to `display:none;width:100%;text-align:left;font-family:sans;color:black;padding:0 0.5em`

create Scroller in FileListing
set the style of Scroller to `width:100%;height:100%;text-align:left;overflow-y:scroll;font-family:mono`
create Image in FileListing
set the style of Image to `margin:0 auto;max-width:100%;max-height:100%`

on click NewFolderButton
begin
put prompt `Name of folder:` with `new` into Path
if Path is empty stop
replace ` ` with `-` in Path
put CurrentPath cat `/` cat Path into Path
rest post to `mkdir/resources/` cat Path or
begin
alert `Failed to create a directory.`
stop
end
goto Browser
end

on message go to Show
set ready
stop

Show:
set style `display` of Container to `block`

get UserRecord from storage as `.user`
put property `home` of UserRecord into Home
put `users/` cat Home cat `/images` into Home
put Home into CurrentPath

! Build the list
Browser:
rest get Content from `list/` cat CurrentPath
or begin
alert `Failed to list files.`
stop
end
put CurrentPath into Path
set the content of Location to `Current path: ` cat Path
put the json count of Content into FileCount
set the elements of File to FileCount
set the elements of FileName to FileCount

! Add a row for each file
set the content of Scroller to ``
set Even

if CurrentPath is not Home
begin
create FileRow in Scroller
set the style of FileRow to `width:90%;padding:0.5em 1em;text-align:left`
create Icon in FileRow
set the style of Icon to `float:left;margin-right:0.5em;width:20px`
set attribute `src` of Icon to `/resources/icon/arrow-back.png`
create FileName in FileRow
set the content of FileName to `(back to previous folder)`
on click FileName
begin
put the position of the last `/` in CurrentPath into N
put left N of CurrentPath into CurrentPath
go to Browser
end
end

set the elements of FileName to FileCount
put 0 into N
while N is less than FileCount
begin
index File to N
put element N of Content into File
put property `name` of File into Name
put property `type` of File into Type
create FileRow in Scroller
set the style of FileRow to `clear:both;padding:0.5em 1em;text-align:left`
if Even set style `background` of FileRow to `#eee`
create Icon in FileRow
set the style of Icon to `float:left;margin-right:0.5em;width:20px`
if Type is `dir` put `folder.png` into Source
else if Type is `img` put `image.png` into Source
else if Type is `txt` put `text.png` into Source
else if Type is `doc` put `document.png` into Source
else put `unknown.png` into Source
set attribute `src` of Icon to `/resources/icon/` cat Source
index FileName to N
create FileName in FileRow
set the content of FileName to Name
on click FileName go to SelectFile
toggle Even
add 1 to N
end

on click DeleteButton
begin
if FileCount is 0
begin
put Path into CurrentPath
rest post to `delete/` cat CurrentPath or
begin
alert `Failed to delete a file.`
stop
end
put the position of the last `~` in CurrentPath into N
if N is less than 0 put the position of the last `/` in CurrentPath into N
put left N of CurrentPath into CurrentPath
alert `Returning to ` cat CurrentPath
go to Browser
end
else
begin
alert `Folder is not empty`
end
end

stop

SelectFile:
index File to the index of FileName
put property `type` of File into Type
if Type is `dir`
begin
put CurrentPath cat `~` cat the content of FileName into CurrentPath
goto Browser
end
if Type is `img`
begin
set style `display` of Uploader to `none`
set style `display` of UploadButton to `none`
set style `display` of NewFolderButton to `none`
set style `display` of Location to `none`
set style `display` of URL to `block`

set style `display` of Scroller to `none`
set style `display` of Image to `block`
put CurrentPath cat `/` cat property `name` of File into FilePath
set attribute `src` of Image to `/resources/` cat FilePath
on click CloseButton go to CloseMedia
set the text of URL to `/resources/` cat FilePath
! highlight URL
on click DeleteButton
begin
put `upload` cat FilePath into FilePath
rest post to `delete/` cat FilePath or
begin
alert `Failed to delete the image.`
stop
end
go to CloseMedia
end
end
stop

CloseMedia:
set style `display` of Image to `none`
set style `display` of Scroller to `block`
set style `display` of Uploader to `inline-block`
set style `display` of UploadButton to `inline-block`
set style `display` of NewFolderButton to `inline-block`
set the content of Location to `Current path: ` cat CurrentPath
set style `display` of Location to `block`
set style `display` of URL to `none`
on click CloseButton go to Exit
go to Browser

Upload:
if UploadFile is empty alert `Please choose a file to upload`
else
begin
put CurrentPath into Path
put `upload/` cat Path into Path
upload UploadFile to Path with UploadProgress and UploadStatus
goto Browser
end
stop

Exit:
set style `display` of Container to `none`
stop
Loading