2022-07-17 18:16:00 +00:00
|
|
|
<!--
|
2023-01-03 09:18:30 +00:00
|
|
|
Copyright (C) 2019-2023 Nicola Murino
|
2022-07-17 18:16:00 +00:00
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published
|
|
|
|
by the Free Software Foundation, version 3.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
2023-01-03 09:18:30 +00:00
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2022-07-17 18:16:00 +00:00
|
|
|
-->
|
2021-10-09 12:17:28 +00:00
|
|
|
{{template "base" .}}
|
|
|
|
|
|
|
|
{{define "title"}}{{.Title}}{{end}}
|
|
|
|
|
|
|
|
{{define "extra_css"}}
|
|
|
|
<link href="{{.StaticURL}}/vendor/codemirror/codemirror.css" rel="stylesheet">
|
|
|
|
<link href="{{.StaticURL}}/vendor/codemirror/addon/dialog/dialog.css" rel="stylesheet">
|
|
|
|
<link href="{{.StaticURL}}/vendor/codemirror/addon/search/matchesonscrollbar.css" rel="stylesheet">
|
|
|
|
<style>
|
|
|
|
.CodeMirror {
|
|
|
|
border: 1px solid #eee;
|
|
|
|
height: 30em;
|
|
|
|
font-size: 13px;
|
|
|
|
}
|
|
|
|
.shortcut {font-family: monospace; color: #666;}
|
|
|
|
</style>
|
|
|
|
{{end}}
|
|
|
|
{{define "additionalnavitems"}}
|
|
|
|
<li class="nav-item dropdown no-arrow mx-1">
|
2023-02-09 08:33:33 +00:00
|
|
|
<a class="nav-link dropdown-toggle" href="#" id="infoDropdown" role="button"
|
2021-10-09 12:17:28 +00:00
|
|
|
data-toggle="modal" data-target="#infoModal">
|
|
|
|
<i class="fas fa-info fa-fw"></i>
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
|
|
|
|
<div class="topbar-divider d-none d-sm-block"></div>
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
{{define "page_body"}}
|
2023-10-29 07:17:24 +00:00
|
|
|
<div id="errorMsg" class="alert alert-warning fade show" style="display: none;" role="alert">
|
2023-02-10 17:07:23 +00:00
|
|
|
<span id="errorTxt"></span>
|
2023-10-29 07:17:24 +00:00
|
|
|
<button type="button" class="close" aria-label="Close" onclick="dismissErrorMsg();">
|
2023-02-10 17:07:23 +00:00
|
|
|
<span aria-hidden="true">×</span>
|
|
|
|
</button>
|
2021-10-09 12:17:28 +00:00
|
|
|
</div>
|
2023-10-29 07:17:24 +00:00
|
|
|
<script type="text/javascript">
|
|
|
|
function dismissErrorMsg(){
|
|
|
|
$('#errorMsg').hide();
|
|
|
|
}
|
|
|
|
</script>
|
2021-10-09 12:17:28 +00:00
|
|
|
<div class="card shadow mb-4">
|
|
|
|
<div class="card-header">
|
|
|
|
<h6 class="d-flex justify-content-between align-items-center">
|
2023-09-17 15:38:20 +00:00
|
|
|
<span class="font-weight-bold text-primary">{{- if .ReadOnly}}View{{- else}}Edit{{- end}} file "{{.Path}}"</span>
|
2021-10-09 12:17:28 +00:00
|
|
|
<span class="btn-toolbar">
|
|
|
|
<a id="idBack" class="btn btn-secondary mx-1 my-1" href='{{.FilesURL}}?path={{.CurrentDir}}' role="button">Back</a>
|
2021-11-25 18:24:32 +00:00
|
|
|
{{if not .ReadOnly}}
|
2021-10-09 12:17:28 +00:00
|
|
|
<a id="idSave" class="btn btn-primary mx-1 my-1" href="#" onclick="saveFile()" role="button">Save</a>
|
2021-11-25 18:24:32 +00:00
|
|
|
{{end}}
|
2021-10-09 12:17:28 +00:00
|
|
|
</span>
|
|
|
|
</h6>
|
|
|
|
</div>
|
|
|
|
<div class="card-body">
|
|
|
|
<div class="col-sm-12">
|
|
|
|
<textarea id="editor" name="editor"></textarea>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
{{define "dialog"}}
|
|
|
|
<div class="modal fade" id="infoModal" tabindex="-1" role="dialog" aria-labelledby="infoModalLabel"
|
|
|
|
aria-hidden="true">
|
|
|
|
<div class="modal-dialog" role="document">
|
|
|
|
<div class="modal-content">
|
|
|
|
<div class="modal-header">
|
|
|
|
<h5 class="modal-title" id="infoModalLabel">
|
|
|
|
Editor keybindings
|
|
|
|
</h5>
|
|
|
|
<button class="close" type="button" data-dismiss="modal" aria-label="Close">
|
|
|
|
<span aria-hidden="true">×</span>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<div class="modal-body">
|
|
|
|
<p>
|
|
|
|
<span class="shortcut">Ctrl-F / Cmd-F</span> => Start searching
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
<span class="shortcut">Ctrl-G / Cmd-G</span> => Find next
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
<span class="shortcut">Shift-Ctrl-G / Shift-Cmd-G</span> => Find previous
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
<span class="shortcut">Shift-Ctrl-F / Cmd-Option-F</span> => Replace
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
<span class="shortcut">Shift-Ctrl-R / Shift-Cmd-Option-F</span> => Replace all
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
<span class="shortcut">Alt-G</span> => Jump to line
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
<span class="shortcut">Alt-F</span> => Persistent search: enter to find next, Shift-Enter to find previous
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<div class="modal-footer">
|
|
|
|
<button class="btn btn-primary" type="button" data-dismiss="modal">OK</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
{{define "extra_js"}}
|
|
|
|
<script src="{{.StaticURL}}/vendor/codemirror/codemirror.js"></script>
|
|
|
|
<script src="{{.StaticURL}}/vendor/codemirror/meta.js"></script>
|
|
|
|
<script src="{{.StaticURL}}/vendor/codemirror/addon/selection/active-line.js"></script>
|
|
|
|
<script src="{{.StaticURL}}/vendor/codemirror/addon/dialog/dialog.js"></script>
|
|
|
|
<script src="{{.StaticURL}}/vendor/codemirror/addon/search/searchcursor.js"></script>
|
|
|
|
<script src="{{.StaticURL}}/vendor/codemirror/addon/search/search.js"></script>
|
2022-10-16 16:29:42 +00:00
|
|
|
<script src="{{.StaticURL}}/vendor/codemirror/addon/scroll/annotatescrollbar.js"></script>
|
2021-10-09 12:17:28 +00:00
|
|
|
<script src="{{.StaticURL}}/vendor/codemirror/addon/search/matchesonscrollbar.js"></script>
|
|
|
|
<script src="{{.StaticURL}}/vendor/codemirror/addon/search/jump-to-line.js"></script>
|
|
|
|
<script type="text/javascript">
|
|
|
|
$(document).ready(function () {
|
|
|
|
var cm = CodeMirror.fromTextArea(document.getElementById("editor"), {
|
|
|
|
lineNumbers: true,
|
|
|
|
styleActiveLine: true,
|
|
|
|
extraKeys: {"Alt-F": "findPersistent"},
|
2021-11-25 18:24:32 +00:00
|
|
|
{{if .ReadOnly}}
|
|
|
|
readOnly: true,
|
|
|
|
{{end}}
|
2021-10-09 12:17:28 +00:00
|
|
|
autofocus: true
|
|
|
|
});
|
|
|
|
var filename = "{{.Path}}";
|
|
|
|
var extension = filename.slice((filename.lastIndexOf(".") - 1 >>> 0) + 2).toLowerCase();
|
|
|
|
mode = CodeMirror.findModeByExtension(extension);
|
|
|
|
if (mode != null) {
|
|
|
|
cm.setOption("mode", mode.mode);
|
|
|
|
}
|
|
|
|
cm.setValue("{{.Data}}");
|
2021-12-04 14:14:44 +00:00
|
|
|
setInterval(keepAlive, 300000);
|
2021-10-09 12:17:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
function keepAlive() {
|
|
|
|
$.ajax({
|
|
|
|
url: '{{.ProfileURL}}',
|
|
|
|
timeout: 15000
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-11-25 18:24:32 +00:00
|
|
|
{{if not .ReadOnly}}
|
2021-10-09 12:17:28 +00:00
|
|
|
function saveFile() {
|
|
|
|
$('#idSave').addClass("disabled");
|
2023-02-10 17:07:23 +00:00
|
|
|
$('#errorMsg').hide();
|
2021-10-09 12:17:28 +00:00
|
|
|
|
2021-12-08 18:25:22 +00:00
|
|
|
async function uploadFile() {
|
|
|
|
var errorMessage = "Error saving file";
|
|
|
|
let response;
|
|
|
|
try {
|
|
|
|
var uploadPath = '{{.FileURL}}?path='+encodeURIComponent('{{.CurrentDir}}/{{.Name}}');
|
|
|
|
var cm = document.querySelector('.CodeMirror').CodeMirror;
|
|
|
|
var blob = new Blob([cm.getValue()]);
|
|
|
|
response = await fetch(uploadPath, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'X-CSRF-TOKEN': '{{.CSRFToken}}'
|
|
|
|
},
|
|
|
|
credentials: 'same-origin',
|
|
|
|
redirect: 'error',
|
|
|
|
body: blob
|
|
|
|
});
|
|
|
|
if (response.status == 201){
|
|
|
|
window.location.href = '{{.FilesURL}}?path='+encodeURIComponent('{{.CurrentDir}}');
|
|
|
|
} else {
|
|
|
|
let jsonResponse;
|
|
|
|
try {
|
|
|
|
jsonResponse = await response.json();
|
|
|
|
} catch(e){
|
|
|
|
throw Error(errorMessage);
|
|
|
|
}
|
|
|
|
if (jsonResponse.message) {
|
|
|
|
errorMessage = jsonResponse.message;
|
|
|
|
}
|
|
|
|
if (jsonResponse.error) {
|
|
|
|
errorMessage += ": " + jsonResponse.error;
|
2021-10-09 12:17:28 +00:00
|
|
|
}
|
2021-12-08 18:25:22 +00:00
|
|
|
throw Error(errorMessage);
|
2021-10-09 12:17:28 +00:00
|
|
|
}
|
2021-12-08 18:25:22 +00:00
|
|
|
} catch (e){
|
|
|
|
throw Error(errorMessage+": " +e.message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uploadFile().catch(function(error){
|
|
|
|
$('#idSave').removeClass("disabled");
|
|
|
|
$('#errorTxt').text(error.message);
|
|
|
|
$('#errorMsg').show();
|
|
|
|
});
|
2021-10-09 12:17:28 +00:00
|
|
|
}
|
2021-11-25 18:24:32 +00:00
|
|
|
{{end}}
|
2021-10-09 12:17:28 +00:00
|
|
|
</script>
|
|
|
|
{{end}}
|