mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-07 22:06:05 +01:00
codemirror: select python version
This commit is contained in:
@@ -78,6 +78,17 @@ class FileManager:
|
||||
def findThemeFile(theme):
|
||||
return '<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.1/theme/%s.min.css" />' % (theme)
|
||||
|
||||
@staticmethod
|
||||
def findAdditionalOptions(mode):
|
||||
if mode == 'text/x-python':
|
||||
return """<select ng-model="optionValue" ng-change="additionalOptions()">
|
||||
<option>Python 2</option>
|
||||
<option>Python 3</option>
|
||||
</select>
|
||||
"""
|
||||
else:
|
||||
return ""
|
||||
|
||||
def ajaxPre(self, status, errorMessage):
|
||||
final_dic = {'status': status, 'error_message': errorMessage, 'uploadStatus': status}
|
||||
final_json = json.dumps(final_dic)
|
||||
|
||||
@@ -63,12 +63,27 @@ fileManager.controller('editFileCtrl', function ($scope, $http, $window) {
|
||||
|
||||
if (response.data.status === 1) {
|
||||
|
||||
var cm = new CodeMirror.fromTextArea(document.getElementById("fileContent"), {
|
||||
lineNumbers: true,
|
||||
mode: $("#mode").text(),
|
||||
lineWrapping: false,
|
||||
theme: $("#theme").text()
|
||||
});
|
||||
let url = new URL(window.location.href);
|
||||
let params = new URLSearchParams(url.search);
|
||||
let python = params.get('python');
|
||||
|
||||
if(python == null) {
|
||||
var cm = new CodeMirror.fromTextArea(document.getElementById("fileContent"), {
|
||||
lineNumbers: true,
|
||||
mode: $("#mode").text(),
|
||||
lineWrapping: false,
|
||||
theme: $("#theme").text()
|
||||
});
|
||||
}else{
|
||||
var mode = {name: $("#mode").text(), version:python};
|
||||
|
||||
var cm = new CodeMirror.fromTextArea(document.getElementById("fileContent"), {
|
||||
lineNumbers: true,
|
||||
mode: mode,
|
||||
lineWrapping: false,
|
||||
theme: $("#theme").text()
|
||||
});
|
||||
}
|
||||
|
||||
cm.setValue(response.data.fileContents);
|
||||
cm.setSize(null, 800);
|
||||
@@ -93,7 +108,45 @@ fileManager.controller('editFileCtrl', function ($scope, $http, $window) {
|
||||
$scope.getFileContents();
|
||||
|
||||
$scope.changeTheme = function () {
|
||||
$window.location.href = window.location.href + '&theme=' + $scope.theme;
|
||||
|
||||
let url = new URL(window.location.href);
|
||||
let params = new URLSearchParams(url.search);
|
||||
let theme = params.get('theme');
|
||||
|
||||
if (theme == null) {
|
||||
$window.location.href = window.location.href + '&theme=' + $scope.theme;
|
||||
} else {
|
||||
params.set('theme', $scope.theme);
|
||||
$window.location.href = 'https://' + window.location.hostname + ':' + window.location.port + window.location.pathname + '?' + params.toString();
|
||||
}
|
||||
};
|
||||
|
||||
$scope.additionalOptions = function () {
|
||||
|
||||
if ($scope.optionValue === 'Python 2') {
|
||||
let url = new URL(window.location.href);
|
||||
let params = new URLSearchParams(url.search);
|
||||
let python = params.get('python');
|
||||
|
||||
if (python == null) {
|
||||
$window.location.href = window.location.href + '&python=2';
|
||||
} else {
|
||||
params.set('python', '2');
|
||||
$window.location.href = 'https://' + window.location.hostname + ':' + window.location.port + window.location.pathname + '?' + params.toString();
|
||||
}
|
||||
|
||||
} else if ($scope.optionValue === 'Python 3') {
|
||||
let url = new URL(window.location.href);
|
||||
let params = new URLSearchParams(url.search);
|
||||
let python = params.get('python');
|
||||
|
||||
if (python == null) {
|
||||
$window.location.href = window.location.href + '&python=3';
|
||||
} else {
|
||||
params.set('python', '3');
|
||||
$window.location.href = 'https://' + window.location.hostname + ':' + window.location.port + window.location.pathname + '?' + params.toString();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$scope.putFileContents = function () {
|
||||
|
||||
@@ -80,7 +80,7 @@
|
||||
|
||||
<!--- second bar ends ---->
|
||||
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||
<ul class="navbar-nav mr-auto">
|
||||
<ul class="navbar-nav mr-auto" style="float: right">
|
||||
<select ng-model="theme" ng-change="changeTheme()" id="select">
|
||||
<option>3024-day</option>
|
||||
<option>3024-night</option>
|
||||
@@ -92,7 +92,7 @@
|
||||
<option>base16-light</option>
|
||||
<option>bespin</option>
|
||||
<option>blackboard</option>
|
||||
<option selected="">cobalt</option>
|
||||
<option>cobalt</option>
|
||||
<option>colorforth</option>
|
||||
<option>darcula</option>
|
||||
<option>dracula</option>
|
||||
@@ -145,7 +145,7 @@
|
||||
<option>yonce</option>
|
||||
<option>zenburn</option>
|
||||
</select>
|
||||
|
||||
{{ additionalOptions | safe }}
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
@@ -158,7 +158,7 @@
|
||||
<div class="row">
|
||||
|
||||
<div class="col-sm-12">
|
||||
<div class="mb-3 mt-30 mx-10" style="min-height: 30rem; margin: 1%">
|
||||
<div class="mb-3 mt-30 mx-10" style="min-height: 30rem; margin: 0px; margin-top: 2px">
|
||||
<div class="">
|
||||
<textarea id="fileContent" class="form-control" rows="15"></textarea>
|
||||
</div>
|
||||
|
||||
@@ -192,12 +192,13 @@ def editFile(request):
|
||||
|
||||
mode = FM.findMode(fileName)
|
||||
modeFiles = FM.findModeFiles(mode)
|
||||
additionalOptions = FM.findAdditionalOptions(mode)
|
||||
themeFile = FM.findThemeFile(theme)
|
||||
|
||||
if ACLManager.checkOwnership(domainName, admin, currentACL) == 1:
|
||||
return render(request, 'filemanager/editFile.html', {'domainName': domainName, 'fileName': fileName,
|
||||
'mode': mode, 'modeFiles': modeFiles, 'theme': theme,
|
||||
'themeFile': themeFile})
|
||||
'themeFile': themeFile, 'additionalOptions': additionalOptions})
|
||||
else:
|
||||
return ACLManager.loadError()
|
||||
|
||||
|
||||
@@ -63,12 +63,27 @@ fileManager.controller('editFileCtrl', function ($scope, $http, $window) {
|
||||
|
||||
if (response.data.status === 1) {
|
||||
|
||||
var cm = new CodeMirror.fromTextArea(document.getElementById("fileContent"), {
|
||||
lineNumbers: true,
|
||||
mode: $("#mode").text(),
|
||||
lineWrapping: false,
|
||||
theme: $("#theme").text()
|
||||
});
|
||||
let url = new URL(window.location.href);
|
||||
let params = new URLSearchParams(url.search);
|
||||
let python = params.get('python');
|
||||
|
||||
if(python == null) {
|
||||
var cm = new CodeMirror.fromTextArea(document.getElementById("fileContent"), {
|
||||
lineNumbers: true,
|
||||
mode: $("#mode").text(),
|
||||
lineWrapping: false,
|
||||
theme: $("#theme").text()
|
||||
});
|
||||
}else{
|
||||
var mode = {name: $("#mode").text(), version:python};
|
||||
|
||||
var cm = new CodeMirror.fromTextArea(document.getElementById("fileContent"), {
|
||||
lineNumbers: true,
|
||||
mode: mode,
|
||||
lineWrapping: false,
|
||||
theme: $("#theme").text()
|
||||
});
|
||||
}
|
||||
|
||||
cm.setValue(response.data.fileContents);
|
||||
cm.setSize(null, 800);
|
||||
@@ -93,7 +108,45 @@ fileManager.controller('editFileCtrl', function ($scope, $http, $window) {
|
||||
$scope.getFileContents();
|
||||
|
||||
$scope.changeTheme = function () {
|
||||
$window.location.href = window.location.href + '&theme=' + $scope.theme;
|
||||
|
||||
let url = new URL(window.location.href);
|
||||
let params = new URLSearchParams(url.search);
|
||||
let theme = params.get('theme');
|
||||
|
||||
if (theme == null) {
|
||||
$window.location.href = window.location.href + '&theme=' + $scope.theme;
|
||||
} else {
|
||||
params.set('theme', $scope.theme);
|
||||
$window.location.href = 'https://' + window.location.hostname + ':' + window.location.port + window.location.pathname + '?' + params.toString();
|
||||
}
|
||||
};
|
||||
|
||||
$scope.additionalOptions = function () {
|
||||
|
||||
if ($scope.optionValue === 'Python 2') {
|
||||
let url = new URL(window.location.href);
|
||||
let params = new URLSearchParams(url.search);
|
||||
let python = params.get('python');
|
||||
|
||||
if (python == null) {
|
||||
$window.location.href = window.location.href + '&python=2';
|
||||
} else {
|
||||
params.set('python', '2');
|
||||
$window.location.href = 'https://' + window.location.hostname + ':' + window.location.port + window.location.pathname + '?' + params.toString();
|
||||
}
|
||||
|
||||
} else if ($scope.optionValue === 'Python 3') {
|
||||
let url = new URL(window.location.href);
|
||||
let params = new URLSearchParams(url.search);
|
||||
let python = params.get('python');
|
||||
|
||||
if (python == null) {
|
||||
$window.location.href = window.location.href + '&python=3';
|
||||
} else {
|
||||
params.set('python', '3');
|
||||
$window.location.href = 'https://' + window.location.hostname + ':' + window.location.port + window.location.pathname + '?' + params.toString();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$scope.putFileContents = function () {
|
||||
|
||||
Reference in New Issue
Block a user