From b8d58ec22e2d12cd607b90bc530519c2ecdc1202 Mon Sep 17 00:00:00 2001 From: sukhbir-singh Date: Wed, 1 Aug 2018 15:15:47 +0530 Subject: [PATCH] small improvements --- app/assets/javascripts/rsnapshot_backups.js | 48 +++++++++---------- .../rsnapshot_backups_controller.rb | 10 ++-- .../rsnapshot_backups/settings.html.slim | 2 +- lib/rsnapshot_backups/rsnapshot_helper.rb | 2 + 4 files changed, 32 insertions(+), 30 deletions(-) diff --git a/app/assets/javascripts/rsnapshot_backups.js b/app/assets/javascripts/rsnapshot_backups.js index f4687d3..497d16d 100755 --- a/app/assets/javascripts/rsnapshot_backups.js +++ b/app/assets/javascripts/rsnapshot_backups.js @@ -89,17 +89,21 @@ $(document).on('click', '.add-source-path', function(event) { $(document).on('ajax:success', '#backup_destination_form_id', function(event, results) { // show message temporary var messages_span = this.querySelector("#dest_update_messages"); + messages_span.innerHTML = results["message"]; + if(results["success"]){ - messages_span.innerHTML = "Succesfully Updated !!"; + messages_span.style.color="green"; var fixed_span = this.parentElement.previousSibling; var edit_text = this.querySelector("#destination_path"); - fixed_span.innerHTML=results["set_path"]; - edit_text.value=results["set_path"]; + fixed_span.innerHTML = results["set_path"]; + edit_text.value = results["set_path"]; }else{ - messages_span.innerHTML = results["message"]; + messages_span.style.color="#a44"; } - messages_span.style.display="inline-block"; + messages_span.style.display = "inline-block"; + messages_span.style.width = "100%"; + var that=this; setTimeout(function() { messages_span.style.display="none"; @@ -123,11 +127,13 @@ function getBackupElement(path){ $(document).on('ajax:success', '#backup_source_form_id', function(event, results) { var messages_span = this.querySelector("#source_update_messages"); + messages_span.innerHTML = results["message"]; + if(results["success"]){ - messages_span.innerHTML = "Succesfully Updated !!"; + messages_span.style.color="green"; }else{ + messages_span.style.color="#a44"; messages_span.style.width="100%"; - messages_span.innerHTML = results["message"]; } messages_span.style.display="inline-block"; @@ -167,23 +173,11 @@ $(document).on('ajax:success', '#backup_source_form_id', function(event, results spinner.style.display="none"; }); -$(document).on('ajax:success', '#set_interval_form_id', function(event, results) { - var messages_span = this.querySelector("#interval_update_messages"); - messages_span.innerHTML = "Automatic Backups Started !!"; - messages_span.style.display="inline-block"; - - setTimeout(function(){ - window.location.reload(); - }, 4000); - - var spinner = this.querySelector(".start_cron_spinner"); - spinner.style.display="none"; -}); - $(document).on('ajax:success', '#stop_backup_form_id', function(event, results) { - var messages_span = this.querySelector("#stop_cron_messages"); - messages_span.innerHTML = "Automatic Backups Stopped !!"; - messages_span.style.display="inline-block"; + var messages_span = this.querySelector("#stop_cron_messages"); + messages_span.innerHTML = results["message"]; + messages_span.style.display="inline-block"; + messages_span.style.color="green"; setTimeout(function(){ window.location.reload(); @@ -209,7 +203,7 @@ $(document).ready(function() { }); $(document).on('click', '#start_backups_button', function(event) { - if (confirm('This will start the automatic backups of the folders entered, with the periodicity selected above. Are you sure you want to continue?')) { + if (confirm('This will start the automatic backups of the folders entered, with the periodicity selected. Are you sure you want to continue?')) { var current = event.target; current.previousSibling.style.display = ""; var submit_btn=document.getElementById("start_backups"); @@ -235,6 +229,12 @@ $(document).on('ajax:success', '#start_backups_form_id', function(event, results messages_span.innerHTML = results["message"] messages_span.style.display="inline-block"; + if(results["success"]){ + messages_span.style.color="green"; + }else{ + messages_span.style.color="#a44"; + } + setTimeout(function(){ if(results["success"]){ window.location.reload(); diff --git a/app/controllers/rsnapshot_backups_controller.rb b/app/controllers/rsnapshot_backups_controller.rb index 815ed46..1ecf6a6 100755 --- a/app/controllers/rsnapshot_backups_controller.rb +++ b/app/controllers/rsnapshot_backups_controller.rb @@ -25,7 +25,7 @@ def update_backup_directory dest_path = RsnapshotHelper.formatted_path(params[:destination_path]) if RsnapshotHelper.check_if_path_exists(dest_path) RsnapshotHelper.update_conf("snapshot_root", dest_path) - render :json => {success: true, set_path: dest_path} + render :json => {success: true, set_path: dest_path, message: "Updated"} else render :json => {success: false, message: "Error: Path '#{dest_path}' do not exist."} end @@ -45,7 +45,7 @@ def update_backup_sources RsnapshotHelper.add_conf("backup", [source, "./"]) end - render :json => {success: true, message: "Backup Paths Set Successfully.", sources: sources} + render :json => {success: true, message: "Updated", sources: sources} else render :json => {success: false, message: "Error: One or more paths do not exist."} end @@ -57,13 +57,13 @@ def start_backups render :json => {success: false, message: "Error: Select atleast one 'Repeat Duration' to start backups"} else CronTabHelper.add_crons(intervals) - render :json => {success: true, message: "Backups Started Successfully !!"} + render :json => {success: true, message: "Backups Scheduled"} end end def stop_backups CronTabHelper.remove_all_crons - render :json => {success: true, message: "Backups Stopped Successfully !!"} + render :json => {success: true, message: "Backups Stopped"} end def update_interval @@ -74,7 +74,7 @@ def update_interval else CronTabHelper.remove_cron(interval) end - render :json => {success: true, message: "Successfully Updated !!", + render :json => {success: true, message: "Updated", interval: interval, type: type} end diff --git a/app/views/rsnapshot_backups/settings.html.slim b/app/views/rsnapshot_backups/settings.html.slim index 092b11f..7d781b5 100755 --- a/app/views/rsnapshot_backups/settings.html.slim +++ b/app/views/rsnapshot_backups/settings.html.slim @@ -38,7 +38,7 @@ css: :id => 'backup_destination_form_id' do |f| = text_field_tag 'destination_path', "#{@dest_path[0][0]}", :placeholder => 'Select Destination Path', :class=>'form-control input-sm increase-length-40', :style=>'display: inline-block; margin-right: 8px; ' = spinner "dest_update_spinner" - input#backup_destination_submit type="submit" style="cursor:pointer" + input#backup_destination_submit type="submit" value="Save" style="cursor:pointer" = link_to t('cancel'), '#', :class => 'close-backup-destination-form cancel-link cancel-btn-style btn-sm' br span#dest_update_messages.messages style="display: none" diff --git a/lib/rsnapshot_backups/rsnapshot_helper.rb b/lib/rsnapshot_backups/rsnapshot_helper.rb index 6644b28..7b91ed0 100644 --- a/lib/rsnapshot_backups/rsnapshot_helper.rb +++ b/lib/rsnapshot_backups/rsnapshot_helper.rb @@ -180,6 +180,7 @@ def formatted_path(paths) if paths.class == Array new_paths = [] paths.each do |path| + next if path.size == 0 path = "/"+path if path[0]!="/" path = path+"/" if path[-1]!="/" new_paths << path @@ -195,6 +196,7 @@ def formatted_path(paths) def check_if_path_exists(paths) if paths.class == Array paths.each do |path| + return false if path.size == 0 return false unless File.exists?(path) end return true