Add 'Save as new' button
This commit is contained in:
parent
ec02787747
commit
680e9f3aa5
@ -94,7 +94,8 @@
|
|||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div id="buttons">
|
<div id="buttons">
|
||||||
<button onclick="save_code()"><span class="text">Save (ctrl-s)</span></button>
|
<button onclick="save_code('%SAVECODEURI%')"><span class="text">Save (ctrl-s)</span></button>
|
||||||
|
<button onclick="save_code('%SAVEASURI%')"><span class="text">Save as new</span></button>
|
||||||
Sim:
|
Sim:
|
||||||
<button onclick="send_to_icarus()"><span class="text">Icarus</span></button>
|
<button onclick="send_to_icarus()"><span class="text">Icarus</span></button>
|
||||||
<!-- button><span class="text">Verilator</span></button -->
|
<!-- button><span class="text">Verilator</span></button -->
|
||||||
@ -136,8 +137,8 @@
|
|||||||
.then((text) => { log_area.innerHTML = text; });
|
.then((text) => { log_area.innerHTML = text; });
|
||||||
};
|
};
|
||||||
|
|
||||||
function save_code() {
|
function save_code(uri) {
|
||||||
fetch('%SAVECODEURI%',
|
fetch(uri,
|
||||||
{
|
{
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
@ -41,6 +41,7 @@
|
|||||||
|
|
||||||
(define URI-IVERILOG "iverilog")
|
(define URI-IVERILOG "iverilog")
|
||||||
(define URI-SAVE-CODE "save")
|
(define URI-SAVE-CODE "save")
|
||||||
|
(define URI-SAVEAS-CODE "saveas")
|
||||||
|
|
||||||
(define LOG-DBG 3)
|
(define LOG-DBG 3)
|
||||||
(define LOG-VERBOSE 2)
|
(define LOG-VERBOSE 2)
|
||||||
@ -393,10 +394,13 @@
|
|||||||
(root (encode-and-join-uri-path root-path))
|
(root (encode-and-join-uri-path root-path))
|
||||||
(iverilog-path (append root-path `(,URI-IVERILOG)))
|
(iverilog-path (append root-path `(,URI-IVERILOG)))
|
||||||
(savecode-path (append root-path `(,URI-SAVE-CODE)))
|
(savecode-path (append root-path `(,URI-SAVE-CODE)))
|
||||||
|
(saveas-path (append root-path `(,URI-SAVEAS-CODE)))
|
||||||
(iverilog-post-uri (encode-and-join-uri-path iverilog-path))
|
(iverilog-post-uri (encode-and-join-uri-path iverilog-path))
|
||||||
(savecode-post-uri (encode-and-join-uri-path savecode-path))
|
(savecode-post-uri (encode-and-join-uri-path savecode-path))
|
||||||
|
(saveas-post-uri (encode-and-join-uri-path saveas-path))
|
||||||
(index-html (read-template-text index-file `(("IVERILOGPOSTURI" ,iverilog-post-uri)
|
(index-html (read-template-text index-file `(("IVERILOGPOSTURI" ,iverilog-post-uri)
|
||||||
("SAVECODEURI" ,savecode-post-uri)))))
|
("SAVECODEURI" ,savecode-post-uri)
|
||||||
|
("SAVEASURI" ,saveas-post-uri)))))
|
||||||
|
|
||||||
(lambda (request request-body)
|
(lambda (request request-body)
|
||||||
(let (;; Requested resource path
|
(let (;; Requested resource path
|
||||||
@ -484,21 +488,26 @@
|
|||||||
#:type 'text/plain))
|
#:type 'text/plain))
|
||||||
|
|
||||||
;; Save snippet
|
;; Save snippet
|
||||||
((equal? path savecode-path)
|
((or (equal? path savecode-path)
|
||||||
(logger LOG-DBG "Request code saving")
|
(equal? path saveas-path))
|
||||||
|
(let ((saveas (equal? path saveas-path)))
|
||||||
|
(logger LOG-DBG "Request code saving~a"
|
||||||
|
(if saveas " as new snippet" ""))
|
||||||
(let ((stor-dir
|
(let ((stor-dir
|
||||||
(or ref-stor-dir
|
(if (or saveas
|
||||||
|
(not ref-stor-dir))
|
||||||
(basename
|
(basename
|
||||||
(mkdtemp
|
(mkdtemp
|
||||||
(path+
|
(path+
|
||||||
stor-base
|
stor-base
|
||||||
(format "~a-XXXXXX"
|
(format "~a-XXXXXX"
|
||||||
(current-time))))))))
|
(current-time)))))
|
||||||
|
ref-stor-dir)))
|
||||||
(save-to-storage (path+ stor-base stor-dir) code)
|
(save-to-storage (path+ stor-base stor-dir) code)
|
||||||
(make-response
|
(make-response
|
||||||
(encode-and-join-uri-path
|
(encode-and-join-uri-path
|
||||||
(append root-path `(,stor-dir)))
|
(append root-path `(,stor-dir)))
|
||||||
#:type 'text/plain)))
|
#:type 'text/plain))))
|
||||||
|
|
||||||
;; Wrong POST request
|
;; Wrong POST request
|
||||||
(else
|
(else
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user