Skip to content

Commit 8fe23c6

Browse files
authored
Merge pull request #110 from easycoder/dev
File manager
2 parents d7262db + 3c91b83 commit 8fe23c6

File tree

8 files changed

+372
-48
lines changed

8 files changed

+372
-48
lines changed

dist/easycoder-min.js

Lines changed: 24 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/easycoder.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5659,12 +5659,23 @@ const EasyCoder_Browser = {
56595659
}
56605660
}
56615661
};
5662+
ajax.onerror = function (data) {
5663+
if (command.onError) {
5664+
program.errorMessage = this.responseText;
5665+
program.run(command.onError);
5666+
} else {
5667+
const error = this.responseText;
5668+
program.runtimeError(command.lino, error);
5669+
}
5670+
};
56625671
program.ajaxCommand = command;
56635672
const rest = document.getElementById(`easycoder-rest`);
56645673
if (!rest) {
56655674
program.runtimeError(command.lino, `No REST server defined`);
56665675
}
5667-
const postpath = path.startsWith(`http`) ? path : `${window.location.origin}${rest}/${path}`;
5676+
const postpath = path.startsWith(`http`)
5677+
? path
5678+
: `${window.location.origin}/${rest.innerText}/${path}`;
56685679
ajax.open(`POST`, postpath);
56695680
ajax.send(formData);
56705681
}

iwsy/resources/ecs/fileman.txt

Lines changed: 267 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,267 @@
1+
! File Manager
2+
3+
script FileManager
4+
5+
import div Container
6+
7+
div Tracer
8+
div Panel
9+
div FileListing
10+
div FileRow
11+
div Scroller
12+
div Uploader
13+
div Buttons
14+
div Location
15+
span UploadStatus
16+
progress UploadProgress
17+
input UploadFile
18+
input URL
19+
button CloseButton
20+
button NewFolderButton
21+
button UploadButton
22+
button DeleteButton
23+
a FileName
24+
img Icon
25+
img Image
26+
variable Mobile
27+
variable FileCount
28+
variable File
29+
variable Name
30+
variable Type
31+
variable Source
32+
variable Content
33+
variable Home
34+
variable UserRecord
35+
variable CurrentPath
36+
variable FilePath
37+
variable Path
38+
variable N
39+
variable Even
40+
41+
if portrait
42+
begin
43+
if mobile set Mobile else clear Mobile
44+
end
45+
46+
create Panel in Container
47+
if Mobile set the style of Panel to `background:#ffe`
48+
else set the style of Panel to `width:100%;height:100%;background:#ffe`
49+
50+
create Tracer in Panel
51+
set attribute `id` of Tracer to `easycoder-tracer`
52+
53+
create Uploader in Panel
54+
set the style of Uploader to `width:100%;padding:0.5em 0;font-size:80%;text-align:center`
55+
create UploadFile in Uploader
56+
set the style of UploadFile to `font-family:serif;color:black`
57+
set attribute `type` of UploadFile to `file`
58+
set attribute `name` of UploadFile to `Source`
59+
create UploadStatus in Uploader
60+
set the style of UploadStatus to `font-family:serif;color:black`
61+
create UploadProgress in Uploader
62+
set style `margin-left` of UploadProgress to `0.5em`
63+
set attribute `value` of UploadProgress to 0
64+
set attribute `max` of UploadProgress to 100
65+
66+
create Buttons in Panel
67+
set the style of Buttons to `display:flex`
68+
create UploadButton in Buttons
69+
set the style of UploadButton to `flex:1;width:150px;height:40px;font-family:sans;color:black`
70+
set the text of UploadButton to `Upload`
71+
on click UploadButton go to Upload
72+
create NewFolderButton in Buttons
73+
set the style of NewFolderButton to `flex:1;width:150px;height:40px;font-family:sans;color:black`
74+
set the text of NewFolderButton to `New Folder`
75+
create DeleteButton in Buttons
76+
set the style of DeleteButton to `flex:1;width:150px;height:40px;font-family:sans;color:black`
77+
set the text of DeleteButton to `Delete`
78+
create CloseButton in Buttons
79+
set the style of CloseButton to `flex:1;width:150px;height:40px;font-family:sans;color:black`
80+
set the text of CloseButton to `Close`
81+
on click CloseButton go to Exit
82+
83+
create FileListing in Panel
84+
set the style of FileListing to `width:100%;height:80%;text-align:center`
85+
create Location in FileListing
86+
set the style of Location to `width:100%;text-align:left;color:black;padding:0 0.5em`
87+
create URL in FileListing
88+
set the style of URL to `display:none;width:100%;text-align:left;font-family:sans;color:black;padding:0 0.5em`
89+
90+
create Scroller in FileListing
91+
set the style of Scroller to `width:100%;height:100%;text-align:left;overflow-y:scroll;font-family:mono`
92+
create Image in FileListing
93+
set the style of Image to `margin:0 auto;max-width:100%;max-height:100%`
94+
95+
on click NewFolderButton
96+
begin
97+
put prompt `Name of folder:` with `new` into Path
98+
if Path is empty stop
99+
replace ` ` with `-` in Path
100+
put CurrentPath cat `/` cat Path into Path
101+
rest post to `mkdir/resources/` cat Path or
102+
begin
103+
alert `Failed to create a directory.`
104+
stop
105+
end
106+
goto Browser
107+
end
108+
109+
on message go to Show
110+
set ready
111+
stop
112+
113+
Show:
114+
set style `display` of Container to `block`
115+
116+
get UserRecord from storage as `.user`
117+
put property `home` of UserRecord into Home
118+
put `users/` cat Home cat `/images` into Home
119+
put Home into CurrentPath
120+
121+
! Build the list
122+
Browser:
123+
rest get Content from `list/` cat CurrentPath
124+
or begin
125+
alert `Failed to list files.`
126+
stop
127+
end
128+
put CurrentPath into Path
129+
set the content of Location to `Current path: ` cat Path
130+
put the json count of Content into FileCount
131+
set the elements of File to FileCount
132+
set the elements of FileName to FileCount
133+
134+
! Add a row for each file
135+
set the content of Scroller to ``
136+
set Even
137+
138+
if CurrentPath is not Home
139+
begin
140+
create FileRow in Scroller
141+
set the style of FileRow to `width:90%;padding:0.5em 1em;text-align:left`
142+
create Icon in FileRow
143+
set the style of Icon to `float:left;margin-right:0.5em;width:20px`
144+
set attribute `src` of Icon to `/resources/icon/arrow-back.png`
145+
create FileName in FileRow
146+
set the content of FileName to `(back to previous folder)`
147+
on click FileName
148+
begin
149+
put the position of the last `/` in CurrentPath into N
150+
put left N of CurrentPath into CurrentPath
151+
go to Browser
152+
end
153+
end
154+
155+
set the elements of FileName to FileCount
156+
put 0 into N
157+
while N is less than FileCount
158+
begin
159+
index File to N
160+
put element N of Content into File
161+
put property `name` of File into Name
162+
put property `type` of File into Type
163+
create FileRow in Scroller
164+
set the style of FileRow to `clear:both;padding:0.5em 1em;text-align:left`
165+
if Even set style `background` of FileRow to `#eee`
166+
create Icon in FileRow
167+
set the style of Icon to `float:left;margin-right:0.5em;width:20px`
168+
if Type is `dir` put `folder.png` into Source
169+
else if Type is `img` put `image.png` into Source
170+
else if Type is `txt` put `text.png` into Source
171+
else if Type is `doc` put `document.png` into Source
172+
else put `unknown.png` into Source
173+
set attribute `src` of Icon to `/resources/icon/` cat Source
174+
index FileName to N
175+
create FileName in FileRow
176+
set the content of FileName to Name
177+
on click FileName go to SelectFile
178+
toggle Even
179+
add 1 to N
180+
end
181+
182+
on click DeleteButton
183+
begin
184+
if FileCount is 0
185+
begin
186+
put Path into CurrentPath
187+
rest post to `delete/` cat CurrentPath or
188+
begin
189+
alert `Failed to delete a file.`
190+
stop
191+
end
192+
put the position of the last `~` in CurrentPath into N
193+
if N is less than 0 put the position of the last `/` in CurrentPath into N
194+
put left N of CurrentPath into CurrentPath
195+
alert `Returning to ` cat CurrentPath
196+
go to Browser
197+
end
198+
else
199+
begin
200+
alert `Folder is not empty`
201+
end
202+
end
203+
204+
stop
205+
206+
SelectFile:
207+
index File to the index of FileName
208+
put property `type` of File into Type
209+
if Type is `dir`
210+
begin
211+
put CurrentPath cat `~` cat the content of FileName into CurrentPath
212+
goto Browser
213+
end
214+
if Type is `img`
215+
begin
216+
set style `display` of Uploader to `none`
217+
set style `display` of UploadButton to `none`
218+
set style `display` of NewFolderButton to `none`
219+
set style `display` of Location to `none`
220+
set style `display` of URL to `block`
221+
222+
set style `display` of Scroller to `none`
223+
set style `display` of Image to `block`
224+
put CurrentPath cat `/` cat property `name` of File into FilePath
225+
set attribute `src` of Image to `/resources/` cat FilePath
226+
on click CloseButton go to CloseMedia
227+
set the text of URL to `/resources/` cat FilePath
228+
! highlight URL
229+
on click DeleteButton
230+
begin
231+
put `upload` cat FilePath into FilePath
232+
rest post to `delete/` cat FilePath or
233+
begin
234+
alert `Failed to delete the image.`
235+
stop
236+
end
237+
go to CloseMedia
238+
end
239+
end
240+
stop
241+
242+
CloseMedia:
243+
set style `display` of Image to `none`
244+
set style `display` of Scroller to `block`
245+
set style `display` of Uploader to `inline-block`
246+
set style `display` of UploadButton to `inline-block`
247+
set style `display` of NewFolderButton to `inline-block`
248+
set the content of Location to `Current path: ` cat CurrentPath
249+
set style `display` of Location to `block`
250+
set style `display` of URL to `none`
251+
on click CloseButton go to Exit
252+
go to Browser
253+
254+
Upload:
255+
if UploadFile is empty alert `Please choose a file to upload`
256+
else
257+
begin
258+
put CurrentPath into Path
259+
put `upload/` cat Path into Path
260+
upload UploadFile to Path with UploadProgress and UploadStatus
261+
goto Browser
262+
end
263+
stop
264+
265+
Exit:
266+
set style `display` of Container to `none`
267+
stop

0 commit comments

Comments
 (0)