add/edit .gitignore

This commit is contained in:
Usman Nasir
2020-03-12 13:30:18 +05:00
parent a219e7977c
commit afe87ac4fc
5 changed files with 406 additions and 51 deletions

View File

@@ -6371,12 +6371,16 @@ app.controller('manageGIT', function ($scope, $http, $timeout, $window) {
}
};
function getCreationStatus() {
$scope.fetchGitignore = function () {
$scope.cyberpanelLoading = false;
url = "/websites/fetchGitignore";
url = "/websites/installWordpressStatus";
var data = {
statusFile: statusFile
domain: $("#domain").text(),
folder: $scope.folder
};
var config = {
@@ -6385,62 +6389,92 @@ app.controller('manageGIT', function ($scope, $http, $timeout, $window) {
}
};
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
if (response.data.abort === 1) {
if (response.data.installStatus === 1) {
$scope.cyberpanelLoading = true;
$scope.installationDetailsForm = true;
$scope.installationProgress = false;
$scope.goBackDisable = false;
$("#installProgress").css("width", "100%");
$scope.installPercentage = "100";
$scope.currentStatus = response.data.currentStatus;
$timeout.cancel();
if (response.data.status === 1) {
new PNotify({
title: 'Success',
text: 'Successfully fetched.',
type: 'success'
});
$scope.gitIgnoreContent = response.data.gitIgnoreContent;
} else {
$scope.cyberpanelLoading = true;
$scope.installationDetailsForm = true;
$scope.installationProgress = false;
$scope.goBackDisable = false;
$scope.currentStatus = response.data.error_message;
$("#installProgress").css("width", "0%");
$scope.installPercentage = "0";
$scope.goBackDisable = false;
new PNotify({
title: 'Operation Failed!',
text: response.data.error_message,
type: 'error'
});
}
} else {
$("#installProgress").css("width", response.data.installationProgress + "%");
$scope.installPercentage = response.data.installationProgress;
$scope.currentStatus = response.data.currentStatus;
$timeout(getCreationStatus, 1000);
}
}
function cantLoadInitialDatas(response) {
$scope.cyberpanelLoading = true;
$scope.installationDetailsForm = true;
$scope.installationProgress = false;
$scope.goBackDisable = false;
new PNotify({
title: 'Operation Failed!',
text: 'Could not connect to server, please refresh this page.',
type: 'error'
});
}
};
$scope.saveGitIgnore = function () {
$scope.cyberpanelLoading = false;
url = "/websites/saveGitIgnore";
var data = {
domain: $("#domain").text(),
folder: $scope.folder,
gitIgnoreContent: $scope.gitIgnoreContent
};
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
$scope.cyberpanelLoading = true;
if (response.data.status === 1) {
new PNotify({
title: 'Success',
text: 'Successfully saved.',
type: 'success'
});
} else {
new PNotify({
title: 'Operation Failed!',
text: response.data.error_message,
type: 'error'
});
}
}
function cantLoadInitialDatas(response) {
$scope.cyberpanelLoading = true;
new PNotify({
title: 'Operation Failed!',
text: 'Could not connect to server, please refresh this page.',
type: 'error'
});
}
};
});
/* Java script code to git tracking ends here */

View File

@@ -384,10 +384,56 @@
<input name="radio-toggle-1" type="radio">
Push To Remote
</a>
<a href="#" class="btn btn-info">
<a ng-click="fetchGitignore()" data-toggle="modal" data-target="#gitignore" href="#" class="btn btn-info">
<input name="radio-toggle-1" type="radio">
Edit .gitignore
</a>
<div id="gitignore" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;
</button>
<h4 class="modal-title">{% trans "Edit .gitignore" %}</h4>
</div>
<div class="modal-body">
<form name="containerSettingsForm" action="/" class="form-horizontal">
<div class="form-group">
<label class="col-sm-12 control-label" style="text-align: center;">{% trans "Contents of .gitignore, use the box below to Add/Edit content of .gitingore file." %}</label>
</div>
<hr>
<div class="form-group">
<div class="col-sm-12">
<textarea ng-model="gitIgnoreContent" rows="3" class="form-control"></textarea>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button"
class="btn btn-primary"
ng-click="saveGitIgnore()">Save<img ng-hide="$parent.cyberpanelLoading"
src="/static/images/loading.gif"
style="display: none;">
</button>
<button type="button"
class="btn btn-default" data-dismiss="modal">
Close
</button>
</div>
</div>
</div>
</div>
<a data-toggle="modal" data-target="#removeGit" href="#" class="btn btn-info">
<input name="radio-toggle-1" type="radio">
Remove Git
@@ -405,7 +451,7 @@
<div class="modal-body">
<form name="containerSettingsForm" action="/" class="form-horizontal">
<div ng-hide="installationDetailsForm" class="form-group">
<div class="form-group">
<label class="col-sm-13 control-label" style="text-align: center;">{% trans "Removing git tracking is not reversible, it will delete all of your commit history, however your files stays there." %}</label>
</div>
</form>
@@ -435,13 +481,14 @@
<th>Total Commits</th>
<th>Branch</th>
<th>Remote</th>
<th>Manage</th>
<th>Commits</th>
</tr>
</thead>
<tbody>
<tr>
<td><span class="bs-badge badge-success">{$ totalCommits $}</span></td>
<td>
<span class="bs-badge badge-success">{$ totalCommits $}</span>
</td>
<td>
<select ng-change="changeBranch()" ng-model="branchName" class="form-control">
<option ng-repeat="branch in branches track by $index">{$ branch $}</option>
@@ -568,7 +615,162 @@
</div>
</td>
<td></td>
<td>
<button data-toggle="modal" data-target="#settings" style="margin-left: 2%"
type="button" class="btn btn-primary">
{% trans "View Commits" %}
</button>
</td>
</tr>
</tbody>
</table>
<table ng-hide="gitCommitsTable" style="margin-top: 2%" class="table">
<thead>
<tr>
<th>Total Commits</th>
<th>Branch</th>
<th>Remote</th>
<th>Commits</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<span class="bs-badge badge-success">{$ totalCommits $}</span>
</td>
<td>
<select ng-change="changeBranch()" ng-model="branchName" class="form-control">
<option ng-repeat="branch in branches track by $index">{$ branch $}</option>
</select>
</td>
<td>
<button data-toggle="modal" data-target="#settings" style="margin-left: 2%"
type="button" class="btn btn-primary">
{% trans "View/Setup Remote" %}
</button>
<div id="settings" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;
</button>
<h4 class="modal-title">{% trans "Setup Remote" %}</h4>
</div>
<div class="modal-body">
<form name="containerSettingsForm" action="/" class="form-horizontal">
<div ng-hide="installationDetailsForm" class="form-group">
<label class="col-sm-3 control-label">{% trans "Git Host" %}</label>
<div class="col-sm-6">
<input placeholder="Ex. github.com or gitlab.com"
name="gitHost" type="text" class="form-control"
ng-model="$parent.gitHost" required>
</div>
</div>
<div ng-hide="installationDetailsForm" class="form-group">
<label class="col-sm-3 control-label">{% trans "Username" %}</label>
<div class="col-sm-6">
<input name="gitUsername" type="text" class="form-control"
ng-model="$parent.gitUsername" required>
</div>
</div>
<div ng-hide="installationDetailsForm" class="form-group">
<label class="col-sm-3 control-label">{% trans "Repo Name" %}</label>
<div class="col-sm-6">
<input name="gitReponame" type="text" class="form-control"
ng-model="$parent.gitReponame" required>
</div>
</div>
<hr>
<div class="form-group">
<div class="col-sm-12">
<table class="table">
<thead>
<tr>
<th>{% trans "Current Remote" %}</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div class="form-group">
<div class="col-sm-12">
<textarea rows="2"
class="form-control">{$ remoteResult $}</textarea>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<hr>
<div class="form-group">
<div class="col-sm-12">
<table class="table">
<thead>
<tr>
<th>{% trans "Deployment Key" %}</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div class="form-group">
<div class="col-sm-12">
<textarea rows="5"
class="form-control">{$ deploymentKey $}</textarea>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" ng-disabled="savingSettings"
class="btn btn-primary"
ng-click="setupRemote()">Save <img ng-hide="cyberpanelLoading"
src="/static/images/loading.gif"
style="display: none;">
</button>
<button type="button" ng-disabled="savingSettings"
class="btn btn-default" data-dismiss="modal">
Close
</button>
</div>
</div>
</div>
</div>
</td>
<td>
<button data-toggle="modal" data-target="#settings" style="margin-left: 2%"
type="button" class="btn btn-primary">
{% trans "View Commits" %}
</button>
</td>
</tr>
</tbody>
</table>

View File

@@ -130,6 +130,8 @@ urlpatterns = [
url(r'^gitPush$', views.gitPush, name='gitPush'),
url(r'^attachRepoGIT$', views.attachRepoGIT, name='attachRepoGIT'),
url(r'^removeTracking$', views.removeTracking, name='removeTracking'),
url(r'^fetchGitignore$', views.fetchGitignore, name='fetchGitignore'),
url(r'^saveGitIgnore$', views.saveGitIgnore, name='saveGitIgnore'),
## Catch all for domains

View File

@@ -805,3 +805,19 @@ def removeTracking(request):
return wm.removeTracking(userID, json.loads(request.body))
except KeyError:
return redirect(loadLoginPage)
def fetchGitignore(request):
try:
userID = request.session['userID']
wm = WebsiteManager()
return wm.fetchGitignore(userID, json.loads(request.body))
except KeyError:
return redirect(loadLoginPage)
def saveGitIgnore(request):
try:
userID = request.session['userID']
wm = WebsiteManager()
return wm.saveGitIgnore(userID, json.loads(request.body))
except KeyError:
return redirect(loadLoginPage)

View File

@@ -3150,6 +3150,12 @@ StrictHostKeyChecking no
else:
return ACLManager.loadErrorJson()
if self.branchName.find('*') > -1:
data_ret = {'status': 0, 'commandStatus': 'Already on this branch.', 'error_message': 'Already on this branch.'}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
## Check if remote exists
command = 'git -C %s checkout %s' % (self.folder, self.branchName.strip(' '))
@@ -3401,12 +3407,22 @@ StrictHostKeyChecking no
command = 'git config --global --unset core.sshCommand'
ProcessUtilities.executioner(command)
from filemanager.filemanager import FileManager
fm = FileManager(None, None)
fm.fixPermissions(self.domain)
data_ret = {'status': 1, 'commandStatus': commandStatus}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
else:
from filemanager.filemanager import FileManager
fm = FileManager(None, None)
fm.fixPermissions(self.domain)
command = 'git config --global --unset core.sshCommand'
ProcessUtilities.executioner(command)
@@ -3450,3 +3466,88 @@ StrictHostKeyChecking no
data_ret = {'status': 0, 'error_message': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
def fetchGitignore(self, userID=None, data=None):
try:
currentACL = ACLManager.loadedACL(userID)
admin = Administrator.objects.get(pk=userID)
self.domain = data['domain']
self.folder = data['folder']
if ACLManager.checkOwnership(self.domain, admin, currentACL) == 1:
pass
else:
return ACLManager.loadErrorJson('status', 0)
if self.folderCheck():
pass
else:
return ACLManager.loadErrorJson()
command = 'cat %s/.gitignore' % (self.folder)
gitIgnoreContent = ProcessUtilities.outputExecutioner(command)
if gitIgnoreContent.find('No such file or directory') > -1:
gitIgnoreContent = 'File is currently empty.'
data_ret = {'status': 1, 'gitIgnoreContent': gitIgnoreContent}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except BaseException as msg:
data_ret = {'status': 0, 'error_message': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
def saveGitIgnore(self, userID=None, data=None):
try:
currentACL = ACLManager.loadedACL(userID)
admin = Administrator.objects.get(pk=userID)
self.domain = data['domain']
self.folder = data['folder']
self.gitIgnoreContent = data['gitIgnoreContent']
tempPath = "/home/cyberpanel/" + str(randint(1000, 9999))
if ACLManager.checkOwnership(self.domain, admin, currentACL) == 1:
pass
else:
return ACLManager.loadErrorJson('status', 0)
if self.folderCheck():
pass
else:
return ACLManager.loadErrorJson()
## Write to temp file
writeToFile = open(tempPath, 'w')
writeToFile.write(self.gitIgnoreContent)
writeToFile.close()
## Move to original file
command = 'mv %s %s/.gitignore' % (tempPath, self.folder)
ProcessUtilities.executioner(command)
## Fix permissions
from filemanager.filemanager import FileManager
fm = FileManager(None, None)
fm.fixPermissions(self.domain)
data_ret = {'status': 1}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except BaseException as msg:
data_ret = {'status': 0, 'error_message': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)