codemirror: select python version

This commit is contained in:
Usman Nasir
2020-10-20 11:51:58 +05:00
parent baf17748e4
commit d95fe846d7
5 changed files with 137 additions and 19 deletions

View File

@@ -78,6 +78,17 @@ class FileManager:
def findThemeFile(theme): def findThemeFile(theme):
return '<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.1/theme/%s.min.css" />' % (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): def ajaxPre(self, status, errorMessage):
final_dic = {'status': status, 'error_message': errorMessage, 'uploadStatus': status} final_dic = {'status': status, 'error_message': errorMessage, 'uploadStatus': status}
final_json = json.dumps(final_dic) final_json = json.dumps(final_dic)

View File

@@ -63,12 +63,27 @@ fileManager.controller('editFileCtrl', function ($scope, $http, $window) {
if (response.data.status === 1) { if (response.data.status === 1) {
var cm = new CodeMirror.fromTextArea(document.getElementById("fileContent"), { let url = new URL(window.location.href);
lineNumbers: true, let params = new URLSearchParams(url.search);
mode: $("#mode").text(), let python = params.get('python');
lineWrapping: false,
theme: $("#theme").text() 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.setValue(response.data.fileContents);
cm.setSize(null, 800); cm.setSize(null, 800);
@@ -93,7 +108,45 @@ fileManager.controller('editFileCtrl', function ($scope, $http, $window) {
$scope.getFileContents(); $scope.getFileContents();
$scope.changeTheme = function () { $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 () { $scope.putFileContents = function () {

View File

@@ -80,7 +80,7 @@
<!--- second bar ends ----> <!--- second bar ends ---->
<div class="collapse navbar-collapse" id="navbarSupportedContent"> <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"> <select ng-model="theme" ng-change="changeTheme()" id="select">
<option>3024-day</option> <option>3024-day</option>
<option>3024-night</option> <option>3024-night</option>
@@ -92,7 +92,7 @@
<option>base16-light</option> <option>base16-light</option>
<option>bespin</option> <option>bespin</option>
<option>blackboard</option> <option>blackboard</option>
<option selected="">cobalt</option> <option>cobalt</option>
<option>colorforth</option> <option>colorforth</option>
<option>darcula</option> <option>darcula</option>
<option>dracula</option> <option>dracula</option>
@@ -145,7 +145,7 @@
<option>yonce</option> <option>yonce</option>
<option>zenburn</option> <option>zenburn</option>
</select> </select>
{{ additionalOptions | safe }}
</ul> </ul>
</div> </div>
</nav> </nav>
@@ -158,7 +158,7 @@
<div class="row"> <div class="row">
<div class="col-sm-12"> <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=""> <div class="">
<textarea id="fileContent" class="form-control" rows="15"></textarea> <textarea id="fileContent" class="form-control" rows="15"></textarea>
</div> </div>

View File

@@ -192,12 +192,13 @@ def editFile(request):
mode = FM.findMode(fileName) mode = FM.findMode(fileName)
modeFiles = FM.findModeFiles(mode) modeFiles = FM.findModeFiles(mode)
additionalOptions = FM.findAdditionalOptions(mode)
themeFile = FM.findThemeFile(theme) themeFile = FM.findThemeFile(theme)
if ACLManager.checkOwnership(domainName, admin, currentACL) == 1: if ACLManager.checkOwnership(domainName, admin, currentACL) == 1:
return render(request, 'filemanager/editFile.html', {'domainName': domainName, 'fileName': fileName, return render(request, 'filemanager/editFile.html', {'domainName': domainName, 'fileName': fileName,
'mode': mode, 'modeFiles': modeFiles, 'theme': theme, 'mode': mode, 'modeFiles': modeFiles, 'theme': theme,
'themeFile': themeFile}) 'themeFile': themeFile, 'additionalOptions': additionalOptions})
else: else:
return ACLManager.loadError() return ACLManager.loadError()

View File

@@ -63,12 +63,27 @@ fileManager.controller('editFileCtrl', function ($scope, $http, $window) {
if (response.data.status === 1) { if (response.data.status === 1) {
var cm = new CodeMirror.fromTextArea(document.getElementById("fileContent"), { let url = new URL(window.location.href);
lineNumbers: true, let params = new URLSearchParams(url.search);
mode: $("#mode").text(), let python = params.get('python');
lineWrapping: false,
theme: $("#theme").text() 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.setValue(response.data.fileContents);
cm.setSize(null, 800); cm.setSize(null, 800);
@@ -93,7 +108,45 @@ fileManager.controller('editFileCtrl', function ($scope, $http, $window) {
$scope.getFileContents(); $scope.getFileContents();
$scope.changeTheme = function () { $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 () { $scope.putFileContents = function () {