From 67243a44b2e49ef1ceead73d1b3bde67db2ba11f Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Tue, 21 Jan 2020 22:10:58 +0500 Subject: [PATCH] feature: edit incremental backup plans --- IncBackups/static/IncBackups/IncBackups.js | 47 ++++++++ .../templates/IncBackups/backupSchedule.html | 114 +++++++++++++++++- IncBackups/urls.py | 1 + IncBackups/views.py | 36 ++++++ static/userManagment/userManagment.js | 55 +++++++++ 5 files changed, 251 insertions(+), 2 deletions(-) diff --git a/IncBackups/static/IncBackups/IncBackups.js b/IncBackups/static/IncBackups/IncBackups.js index 438065c89..b1ba61062 100644 --- a/IncBackups/static/IncBackups/IncBackups.js +++ b/IncBackups/static/IncBackups/IncBackups.js @@ -741,6 +741,53 @@ app.controller('scheduleBackupInc', function ($scope, $http) { }; + $scope.editInitial = function (id) { + + $scope.jobID = id; + + $scope.cyberpanelLoading = false; + + + url = "/IncrementalBackups/fetchSites"; + + + var data = {id: id}; + + 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.websites = JSON.parse(response.data.data); + } 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' + }); + } + + }; + }); diff --git a/IncBackups/templates/IncBackups/backupSchedule.html b/IncBackups/templates/IncBackups/backupSchedule.html index 625b8603e..8de13fb28 100755 --- a/IncBackups/templates/IncBackups/backupSchedule.html +++ b/IncBackups/templates/IncBackups/backupSchedule.html @@ -169,6 +169,7 @@ {% trans "ID" %} {% trans "Destination" %} {% trans "Frequency" %} + {% trans "Sites" %} {% trans "Delete" %} @@ -177,8 +178,117 @@ - + + + {% trans 'Delete' %} + {% trans 'Edit' %} + + + + + diff --git a/IncBackups/urls.py b/IncBackups/urls.py index aa0864b46..b7d227773 100644 --- a/IncBackups/urls.py +++ b/IncBackups/urls.py @@ -18,4 +18,5 @@ urlpatterns = [ url(r'^submitBackupSchedule$', views.submitBackupSchedule, name='submitBackupScheduleInc'), url(r'^scheduleDelete$', views.scheduleDelete, name='scheduleDeleteInc'), url(r'^getCurrentBackupSchedules$', views.getCurrentBackupSchedules, name='getCurrentBackupSchedulesInc'), + url(r'^fetchSites$', views.fetchSites, name='fetchSites'), ] \ No newline at end of file diff --git a/IncBackups/views.py b/IncBackups/views.py index fc2aea9f8..2850ad29e 100644 --- a/IncBackups/views.py +++ b/IncBackups/views.py @@ -678,6 +678,42 @@ def getCurrentBackupSchedules(request): dic = {'id': items.id, 'destination': items.destination, 'frequency': items.frequency, + 'numberOfSites': items.jobsites_set.all().count() + } + + if checker == 0: + json_data = json_data + json.dumps(dic) + checker = 1 + else: + json_data = json_data + ',' + json.dumps(dic) + + json_data = json_data + ']' + final_json = json.dumps({'status': 1, 'error_message': "None", "data": json_data}) + return HttpResponse(final_json) + + except BaseException as msg: + final_dic = {'status': 0, 'error_message': str(msg)} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + +def fetchSites(request): + try: + userID = request.session['userID'] + currentACL = ACLManager.loadedACL(userID) + + if ACLManager.currentContextPermission(currentACL, 'scheDuleBackups') == 0: + return ACLManager.loadErrorJson('fetchStatus', 0) + + data = json.loads(request.body) + + job = BackupJob.objects.get(pk=data['id']) + + json_data = "[" + checker = 0 + + for items in job.jobsites_set.all(): + dic = {'id': items.id, + 'website': items.website, } if checker == 0: diff --git a/static/userManagment/userManagment.js b/static/userManagment/userManagment.js index ea42f83ca..39cbf5d6d 100644 --- a/static/userManagment/userManagment.js +++ b/static/userManagment/userManagment.js @@ -1685,6 +1685,61 @@ app.controller('listTableUsers', function ($scope, $http) { }; + + $scope.controlUserState = function (userName, state) { + $scope.cyberpanelLoading = false; + + var url = "/users/controlUserState"; + + var data = { + accountUsername: userName, + state : state + }; + + 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.populateCurrentRecords(); + new PNotify({ + title: 'Success!', + text: 'Action successfully started.', + type: 'success' + }); + + } else { + + new PNotify({ + title: 'Error!', + text: response.data.error_message, + type: 'error' + }); + + + } + + } + + function cantLoadInitialDatas(response) { + + $scope.cyberpanelLoading = false; + new PNotify({ + title: 'Error!', + text: 'Could not connect to server, please refresh this page.', + type: 'error' + }); + + + } + } });