feature: edit/manage inc backups

This commit is contained in:
Usman Nasir
2020-01-22 20:36:17 +05:00
parent 4f47b842ad
commit 77bf26a7d6
5 changed files with 540 additions and 28 deletions

View File

@@ -767,6 +767,181 @@ app.controller('scheduleBackupInc', function ($scope, $http) {
$scope.cyberpanelLoading = true;
if (response.data.status === 1) {
$scope.websites = JSON.parse(response.data.data);
if(response.data.websiteData === 1){
$scope.websiteData = true;
}
if(response.data.websiteDatabases === 1){
$scope.websiteDatabases = true;
}
if(response.data.websiteEmails === 1){
$scope.websiteEmails = true;
}
} 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'
});
}
};
$scope.saveChanges = function () {
$scope.cyberpanelLoading = false;
url = "/IncrementalBackups/saveChanges";
var data = {
id: $scope.jobID,
websiteData: $scope.websiteData,
websiteDatabases: $scope.websiteDatabases,
websiteEmails: $scope.websiteEmails
};
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) {
$scope.editInitial($scope.jobID);
new PNotify({
title: 'Success!',
text: 'Operation successful.',
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'
});
}
};
$scope.removeSite = function (website) {
$scope.cyberpanelLoading = false;
url = "/IncrementalBackups/removeSite";
var data = {
id: $scope.jobID,
website: website
};
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) {
$scope.editInitial($scope.jobID);
new PNotify({
title: 'Success!',
text: 'Operation successful.',
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'
});
}
};
$scope.cyberpanelLoading = true;
$scope.addWebsite = function () {
$scope.cyberpanelLoading = false;
url = "/IncrementalBackups/addWebsite";
var data = {
id: $scope.jobID,
website: $scope.websiteToBeAdded
};
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) {
$scope.editInitial($scope.jobID);
new PNotify({
title: 'Success!',
text: 'Operation successful.',
type: 'success'
});
} else {
new PNotify({
title: 'Operation Failed!',

View File

@@ -200,7 +200,7 @@
<button type="button" class="close" data-dismiss="modal">
&times;
</button>
<h4 class="modal-title">Edit User
<h4 class="modal-title">Edit Job
<img ng-hide="cyberpanelLoading"
src="{% static 'images/loading.gif' %}">
</h4>
@@ -225,7 +225,7 @@
<label class="col-sm-3 control-label">{% trans "Data" %}</label>
<div class="checkbox">
<label>
<input ng-model="websiteData"
<input ng-model="$parent.websiteData"
type="checkbox" value="">
Data
</label>
@@ -237,7 +237,7 @@
<label class="col-sm-3 control-label">{% trans "Databases" %}</label>
<div class="checkbox">
<label>
<input ng-model="websiteDatabases"
<input ng-model="$parent.websiteDatabases"
type="checkbox" value="">
Databases
</label>
@@ -249,36 +249,104 @@
<label class="col-sm-3 control-label">{% trans "Emails" %}</label>
<div class="checkbox">
<label>
<input ng-model="websiteEmails"
<input ng-model="$parent.websiteEmails"
type="checkbox" value="">
Emails
</label>
</div>
</div>
<hr>
<table class="table">
<thead>
<tr>
<th>{% trans "ID" %}</th>
<th>{% trans "Website" %}</th>
<th>{% trans "Actions" %}</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="record in websites track by $index">
<td ng-bind="record.id"></td>
<td ng-bind="record.website"></td>
<td>
<a ng-click="delSchedule(record.id)"
class="btn btn-border btn-alt border-red btn-link font-red"
href="#"
title=""><span>{% trans 'Delete' %}</span></a>
</td>
<div ng-hide="installationDetailsForm"
class="form-group">
<label class="col-sm-3 control-label">{% trans "" %}</label>
<button type="button" ng-click="saveChanges()"
class="btn btn-primary btn-lg">{% trans "Save Changes" %}</button>
</div>
</tr>
</tbody>
</table>
<hr>
<ul class="nav nav-tabs">
<li class="col-md-3 nav-item tab-mod active">
<a href="#tab-example-1" data-toggle="tab"
class="h4 nav-link">
<span>{% trans "Sites" %}</span>
</a>
</li>
<li class="col-md-4 tab-mod nav-item">
<a href="#tab-example-3" data-toggle="tab"
class="h4 nav-link">
<span>{% trans "Add Sites" %}</span>
</a>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane fade active in"
id="tab-example-1">
<div class="example-box-wrapper">
<table class="table">
<thead>
<tr>
<th>{% trans "ID" %}</th>
<th>{% trans "Website" %}</th>
<th>{% trans "Actions" %}</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="record in websites track by $index">
<td ng-bind="record.id"></td>
<td ng-bind="record.website"></td>
<td>
<a ng-click="removeSite(record.website)"
class="btn btn-border btn-alt border-red btn-link font-red"
href="#"
title=""><span>{% trans 'Delete' %}</span></a>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="tab-pane fade" id="tab-example-3">
<form action="/"
class="form-horizontal bordered-row">
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "Select Site" %}</label>
<div class="col-sm-6">
<select ng-model="$parent.websiteToBeAdded"
class="form-control">
{% for items in websiteList %}
<option>{{ items }}</option>
{% endfor %}
</select>
</div>
<img ng-hide="cyberpanelLoading"
src="{% static 'images/loading.gif' %}">
</div>
<div ng-hide="savebtn"
class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-4">
<button type="button"
ng-click="addWebsite()"
class="btn btn-primary btn-lg btn-block">{% trans "Add" %}</button>
</div>
</div>
</form>
</div>
</div>
</form>

View File

@@ -19,4 +19,7 @@ urlpatterns = [
url(r'^scheduleDelete$', views.scheduleDelete, name='scheduleDeleteInc'),
url(r'^getCurrentBackupSchedules$', views.getCurrentBackupSchedules, name='getCurrentBackupSchedulesInc'),
url(r'^fetchSites$', views.fetchSites, name='fetchSites'),
url(r'^saveChanges$', views.saveChanges, name='saveChanges'),
url(r'^removeSite$', views.removeSite, name='removeSite'),
url(r'^addWebsite$', views.addWebsite, name='addWebsite'),
]

View File

@@ -606,6 +606,8 @@ def scheduleBackups(request):
for items in os.listdir(path):
destinations.append('s3:s3.amazonaws.com/%s' % (items))
websitesName = ACLManager.findAllSites(currentACL, userID)
return defRenderer(request, 'IncBackups/backupSchedule.html', {'websiteList': websitesName, 'destinations': destinations})
except BaseException as msg:
logging.writeToFile(str(msg))
@@ -723,7 +725,9 @@ def fetchSites(request):
json_data = json_data + ',' + json.dumps(dic)
json_data = json_data + ']'
final_json = json.dumps({'status': 1, 'error_message': "None", "data": json_data})
final_json = json.dumps({'status': 1, 'error_message': "None", "data": json_data,
'websiteData': job.websiteData, 'websiteDatabases': job.websiteDatabases,
'websiteEmails': job.websiteDataEmails})
return HttpResponse(final_json)
except BaseException as msg:
@@ -780,3 +784,90 @@ def restoreRemoteBackups(request):
except BaseException as msg:
logging.writeToFile(str(msg))
return redirect(loadLoginPage)
def saveChanges(request):
try:
userID = request.session['userID']
currentACL = ACLManager.loadedACL(userID)
if ACLManager.currentContextPermission(currentACL, 'scheDuleBackups') == 0:
return ACLManager.loadErrorJson('scheduleStatus', 0)
data = json.loads(request.body)
id = data['id']
websiteData = data['websiteData']
websiteDatabases = data['websiteDatabases']
websiteEmails = data['websiteEmails']
job = BackupJob.objects.get(pk=id)
job.websiteData = int(websiteData)
job.websiteDatabases = int(websiteDatabases)
job.websiteEmails = int(websiteEmails)
job.save()
final_json = json.dumps({'status': 1, 'error_message': "None"})
return HttpResponse(final_json)
except BaseException as msg:
final_json = json.dumps({'status': 0, 'error_message': str(msg)})
return HttpResponse(final_json)
def removeSite(request):
try:
userID = request.session['userID']
currentACL = ACLManager.loadedACL(userID)
if ACLManager.currentContextPermission(currentACL, 'scheDuleBackups') == 0:
return ACLManager.loadErrorJson('scheduleStatus', 0)
data = json.loads(request.body)
id = data['id']
website = data['website']
job = BackupJob.objects.get(pk=id)
site = JobSites.objects.get(job=job, website=website)
site.delete()
final_json = json.dumps({'status': 1, 'error_message': "None"})
return HttpResponse(final_json)
except BaseException as msg:
final_json = json.dumps({'status': 0, 'error_message': str(msg)})
return HttpResponse(final_json)
def addWebsite(request):
try:
userID = request.session['userID']
currentACL = ACLManager.loadedACL(userID)
if ACLManager.currentContextPermission(currentACL, 'scheDuleBackups') == 0:
return ACLManager.loadErrorJson('scheduleStatus', 0)
data = json.loads(request.body)
id = data['id']
website = data['website']
job = BackupJob.objects.get(pk=id)
try:
JobSites.objects.get(job=job, website=website)
except:
site = JobSites(job=job, website=website)
site.save()
final_json = json.dumps({'status': 1, 'error_message': "None"})
return HttpResponse(final_json)
except BaseException as msg:
final_json = json.dumps({'status': 0, 'error_message': str(msg)})
return HttpResponse(final_json)

View File

@@ -767,6 +767,181 @@ app.controller('scheduleBackupInc', function ($scope, $http) {
$scope.cyberpanelLoading = true;
if (response.data.status === 1) {
$scope.websites = JSON.parse(response.data.data);
if(response.data.websiteData === 1){
$scope.websiteData = true;
}
if(response.data.websiteDatabases === 1){
$scope.websiteDatabases = true;
}
if(response.data.websiteEmails === 1){
$scope.websiteEmails = true;
}
} 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'
});
}
};
$scope.saveChanges = function () {
$scope.cyberpanelLoading = false;
url = "/IncrementalBackups/saveChanges";
var data = {
id: $scope.jobID,
websiteData: $scope.websiteData,
websiteDatabases: $scope.websiteDatabases,
websiteEmails: $scope.websiteEmails
};
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) {
$scope.editInitial($scope.jobID);
new PNotify({
title: 'Success!',
text: 'Operation successful.',
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'
});
}
};
$scope.removeSite = function (website) {
$scope.cyberpanelLoading = false;
url = "/IncrementalBackups/removeSite";
var data = {
id: $scope.jobID,
website: website
};
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) {
$scope.editInitial($scope.jobID);
new PNotify({
title: 'Success!',
text: 'Operation successful.',
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'
});
}
};
$scope.cyberpanelLoading = true;
$scope.addWebsite = function () {
$scope.cyberpanelLoading = false;
url = "/IncrementalBackups/addWebsite";
var data = {
id: $scope.jobID,
website: $scope.websiteToBeAdded
};
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) {
$scope.editInitial($scope.jobID);
new PNotify({
title: 'Success!',
text: 'Operation successful.',
type: 'success'
});
} else {
new PNotify({
title: 'Operation Failed!',