mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-07 13:56:01 +01:00
createNewBranch and commitChanges
This commit is contained in:
@@ -5793,6 +5793,7 @@ app.controller('manageGIT', function ($scope, $http, $timeout, $window) {
|
|||||||
$scope.loadingSticks = true;
|
$scope.loadingSticks = true;
|
||||||
$scope.gitTracking = true;
|
$scope.gitTracking = true;
|
||||||
$scope.gitEnable = true;
|
$scope.gitEnable = true;
|
||||||
|
$scope.statusBox = true;
|
||||||
|
|
||||||
var statusFile;
|
var statusFile;
|
||||||
|
|
||||||
@@ -6029,6 +6030,122 @@ app.controller('manageGIT', function ($scope, $http, $timeout, $window) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$scope.createNewBranch = function () {
|
||||||
|
$scope.cyberpanelLoading = false;
|
||||||
|
$scope.commandStatus = "";
|
||||||
|
$scope.statusBox = false;
|
||||||
|
|
||||||
|
url = "/websites/createNewBranch";
|
||||||
|
|
||||||
|
|
||||||
|
var data = {
|
||||||
|
domain: $("#domain").text(),
|
||||||
|
folder: $scope.folder,
|
||||||
|
newBranchName: $scope.newBranchName
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
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: 'Changes applied.',
|
||||||
|
type: 'success'
|
||||||
|
});
|
||||||
|
$scope.commandStatus = response.data.commandStatus;
|
||||||
|
$scope.fetchFolderDetails();
|
||||||
|
} else {
|
||||||
|
new PNotify({
|
||||||
|
title: 'Operation Failed!',
|
||||||
|
text: response.data.error_message,
|
||||||
|
type: 'error'
|
||||||
|
});
|
||||||
|
$scope.commandStatus = response.data.commandStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function cantLoadInitialDatas(response) {
|
||||||
|
$scope.cyberpanelLoading = false;
|
||||||
|
new PNotify({
|
||||||
|
title: 'Operation Failed!',
|
||||||
|
text: 'Could not connect to server, please refresh this page.',
|
||||||
|
type: 'error'
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
$scope.commitChanges = function () {
|
||||||
|
$scope.cyberpanelLoading = false;
|
||||||
|
$scope.commandStatus = "";
|
||||||
|
$scope.statusBox = false;
|
||||||
|
|
||||||
|
url = "/websites/commitChanges";
|
||||||
|
|
||||||
|
|
||||||
|
var data = {
|
||||||
|
domain: $("#domain").text(),
|
||||||
|
folder: $scope.folder,
|
||||||
|
commitMessage: $scope.commitMessage
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
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: 'Changes applied.',
|
||||||
|
type: 'success'
|
||||||
|
});
|
||||||
|
$scope.commandStatus = response.data.commandStatus;
|
||||||
|
$scope.fetchFolderDetails();
|
||||||
|
} else {
|
||||||
|
new PNotify({
|
||||||
|
title: 'Operation Failed!',
|
||||||
|
text: response.data.error_message,
|
||||||
|
type: 'error'
|
||||||
|
});
|
||||||
|
$scope.commandStatus = response.data.commandStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function cantLoadInitialDatas(response) {
|
||||||
|
$scope.cyberpanelLoading = false;
|
||||||
|
new PNotify({
|
||||||
|
title: 'Operation Failed!',
|
||||||
|
text: 'Could not connect to server, please refresh this page.',
|
||||||
|
type: 'error'
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
function getCreationStatus() {
|
function getCreationStatus() {
|
||||||
|
|
||||||
url = "/websites/installWordpressStatus";
|
url = "/websites/installWordpressStatus";
|
||||||
|
|||||||
@@ -40,6 +40,131 @@
|
|||||||
Init Repo
|
Init Repo
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
<div style="margin-bottom: 0px" ng-hide="gitEnable" class="btn-group" data-toggle="buttons">
|
||||||
|
<a data-toggle="modal" data-target="#createNewBranch" href="#" class="btn btn-info">
|
||||||
|
<input name="radio-toggle-1" type="radio">
|
||||||
|
Create New Branch
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<div id="createNewBranch" 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">×
|
||||||
|
</button>
|
||||||
|
<h4 class="modal-title">{% trans "Create New Branch" %}</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 "Branch Name" %}</label>
|
||||||
|
<div class="col-sm-6">
|
||||||
|
<input placeholder="Ex. newbranch (without spaces)"
|
||||||
|
name="newBranchName" type="text" class="form-control"
|
||||||
|
ng-model="$parent.newBranchName" required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
<div ng-hide="statusBox" class="form-group">
|
||||||
|
|
||||||
|
<div class="col-sm-12">
|
||||||
|
<textarea rows="3"
|
||||||
|
class="form-control">{$ commandStatus $}</textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button"
|
||||||
|
class="btn btn-primary"
|
||||||
|
ng-click="createNewBranch()">Commit<img id="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="#commitChanges" href="#" class="btn btn-info">
|
||||||
|
<input name="radio-toggle-1" type="radio">
|
||||||
|
Commit Changes
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<div id="commitChanges" 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">×
|
||||||
|
</button>
|
||||||
|
<h4 class="modal-title">{% trans "Commit Changes" %}</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 "Commit Message" %}</label>
|
||||||
|
<div class="col-sm-6">
|
||||||
|
<input placeholder="Ex. Initial commit"
|
||||||
|
name="newBranchName" type="text" class="form-control"
|
||||||
|
ng-model="$parent.commitMessage" required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
<div ng-hide="statusBox" class="form-group">
|
||||||
|
|
||||||
|
<div class="col-sm-12">
|
||||||
|
<textarea rows="3"
|
||||||
|
class="form-control">{$ commandStatus $}</textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button"
|
||||||
|
class="btn btn-primary"
|
||||||
|
ng-click="commitChanges()">Create New Branch<img id="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 href="#" class="btn btn-info">
|
||||||
|
<input name="radio-toggle-1" type="radio">
|
||||||
|
Pull From Remote
|
||||||
|
</a>
|
||||||
|
<a href="#" class="btn btn-info">
|
||||||
|
<input name="radio-toggle-1" type="radio">
|
||||||
|
Push To Remote
|
||||||
|
</a>
|
||||||
|
<a href="#" class="btn btn-info">
|
||||||
|
<input name="radio-toggle-1" type="radio">
|
||||||
|
Edit .gitignore
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
<table ng-hide="gitEnable" style="margin-top: 2%" class="table">
|
<table ng-hide="gitEnable" style="margin-top: 2%" class="table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -52,7 +177,7 @@
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td>{$ totalCommits $}</td>
|
<td><span class="bs-badge badge-success">{$ totalCommits $}</span></td>
|
||||||
<td>
|
<td>
|
||||||
<select ng-change="changeBranch()" ng-model="branchName" class="form-control">
|
<select ng-change="changeBranch()" ng-model="branchName" class="form-control">
|
||||||
<option ng-repeat="branch in branches track by $index">{$ branch $}</option>
|
<option ng-repeat="branch in branches track by $index">{$ branch $}</option>
|
||||||
@@ -183,6 +308,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<div id="showStatus" class="modal fade" role="dialog">
|
<div id="showStatus" class="modal fade" role="dialog">
|
||||||
<div class="modal-dialog">
|
<div class="modal-dialog">
|
||||||
|
|
||||||
|
|||||||
@@ -124,6 +124,8 @@ urlpatterns = [
|
|||||||
url(r'^initRepo$', views.initRepo, name='initRepo'),
|
url(r'^initRepo$', views.initRepo, name='initRepo'),
|
||||||
url(r'^setupRemote$', views.setupRemote, name='setupRemote'),
|
url(r'^setupRemote$', views.setupRemote, name='setupRemote'),
|
||||||
url(r'^changeGitBranch$', views.changeGitBranch, name='changeGitBranch'),
|
url(r'^changeGitBranch$', views.changeGitBranch, name='changeGitBranch'),
|
||||||
|
url(r'^createNewBranch$', views.createNewBranch, name='createNewBranch'),
|
||||||
|
url(r'^commitChanges$', views.commitChanges, name='commitChanges'),
|
||||||
## Catch all for domains
|
## Catch all for domains
|
||||||
url(r'^(?P<domain>(.*))/(?P<childDomain>(.*))$', views.launchChild, name='launchChild'),
|
url(r'^(?P<domain>(.*))/(?P<childDomain>(.*))$', views.launchChild, name='launchChild'),
|
||||||
url(r'^(?P<domain>(.*))$', views.domain, name='domain'),
|
url(r'^(?P<domain>(.*))$', views.domain, name='domain'),
|
||||||
|
|||||||
@@ -757,3 +757,19 @@ def changeGitBranch(request):
|
|||||||
return wm.changeGitBranch(userID, json.loads(request.body))
|
return wm.changeGitBranch(userID, json.loads(request.body))
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return redirect(loadLoginPage)
|
return redirect(loadLoginPage)
|
||||||
|
|
||||||
|
def createNewBranch(request):
|
||||||
|
try:
|
||||||
|
userID = request.session['userID']
|
||||||
|
wm = WebsiteManager()
|
||||||
|
return wm.createNewBranch(userID, json.loads(request.body))
|
||||||
|
except KeyError:
|
||||||
|
return redirect(loadLoginPage)
|
||||||
|
|
||||||
|
def commitChanges(request):
|
||||||
|
try:
|
||||||
|
userID = request.session['userID']
|
||||||
|
wm = WebsiteManager()
|
||||||
|
return wm.commitChanges(userID, json.loads(request.body))
|
||||||
|
except KeyError:
|
||||||
|
return redirect(loadLoginPage)
|
||||||
@@ -3140,3 +3140,84 @@ StrictHostKeyChecking no
|
|||||||
data_ret = {'status': 0, 'error_message': str(msg)}
|
data_ret = {'status': 0, 'error_message': str(msg)}
|
||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
def createNewBranch(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.newBranchName = data['newBranchName']
|
||||||
|
|
||||||
|
if ACLManager.checkOwnership(self.domain, admin, currentACL) == 1:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
return ACLManager.loadErrorJson('status', 0)
|
||||||
|
|
||||||
|
if self.folderCheck():
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
return ACLManager.loadErrorJson()
|
||||||
|
|
||||||
|
## Check if remote exists
|
||||||
|
|
||||||
|
command = 'git -C %s checkout -b %s' % (self.folder, self.newBranchName)
|
||||||
|
commandStatus = ProcessUtilities.outputExecutioner(command)
|
||||||
|
|
||||||
|
if commandStatus.find(self.newBranchName) > -1:
|
||||||
|
data_ret = {'status': 1, 'commandStatus': commandStatus}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
else:
|
||||||
|
data_ret = {'status': 0, 'error_message': 'Failed to create branch', 'commandStatus': commandStatus}
|
||||||
|
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 commitChanges(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.commitMessage = data['commitMessage']
|
||||||
|
|
||||||
|
if ACLManager.checkOwnership(self.domain, admin, currentACL) == 1:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
return ACLManager.loadErrorJson('status', 0)
|
||||||
|
|
||||||
|
if self.folderCheck():
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
return ACLManager.loadErrorJson()
|
||||||
|
|
||||||
|
## Check if remote exists
|
||||||
|
|
||||||
|
command = 'git -C %s add -A' % (self.folder)
|
||||||
|
ProcessUtilities.outputExecutioner(command)
|
||||||
|
|
||||||
|
command = 'git -C %s commit -m %s' % (self.folder, self.commitMessage)
|
||||||
|
commandStatus = ProcessUtilities.outputExecutioner(command)
|
||||||
|
|
||||||
|
if commandStatus.find('nothing to commit') == -1:
|
||||||
|
data_ret = {'status': 1, 'commandStatus': commandStatus}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
else:
|
||||||
|
data_ret = {'status': 0, 'error_message': 'Nothing to commit.', 'commandStatus': commandStatus}
|
||||||
|
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user