From 8858c3c2569ca117f87347b57855fad9d4a987a6 Mon Sep 17 00:00:00 2001 From: Serik Ibragimov Date: Wed, 6 Mar 2024 14:24:52 +0500 Subject: [PATCH] feat(ruby): implement delete all files method --- .../ruby/app/assets/javascripts/jscript.js | 17 ++++++++++ .../app/assets/stylesheets/stylesheet.scss | 23 ++++++++++++++ .../ruby/app/controllers/home_controller.rb | 31 ++++++++++++------- .../ruby/app/views/home/index.html.erb | 9 +++++- .../ruby/config/application.rb | 2 +- 5 files changed, 68 insertions(+), 14 deletions(-) diff --git a/web/documentserver-example/ruby/app/assets/javascripts/jscript.js b/web/documentserver-example/ruby/app/assets/javascripts/jscript.js index 5a5e82e0..8a2c3de7 100644 --- a/web/documentserver-example/ruby/app/assets/javascripts/jscript.js +++ b/web/documentserver-example/ruby/app/assets/javascripts/jscript.js @@ -292,6 +292,7 @@ if (typeof jQuery != "undefined") { jq.ajax({ async: true, contentType: "text/xml", + type: "delete", url: requestAddress, complete: function (data) { document.location.reload(); @@ -299,6 +300,22 @@ if (typeof jQuery != "undefined") { }); }); + jq(document).on("click", ".clear-all", function () { + if (confirm("Delete all the files?")) { + jq.ajax({ + async: true, + contentType: "text/xml", + type: "delete", + url: "remove", + complete: function (data) { + if (JSON.parse(data.responseText).success) { + window.location.reload(true); + } + } + }); + } + }); + function showUserTooltip (isMobile) { if ( jq("div#portal-info").is(":hidden") ) { jq("div#portal-info").show(); diff --git a/web/documentserver-example/ruby/app/assets/stylesheets/stylesheet.scss b/web/documentserver-example/ruby/app/assets/stylesheets/stylesheet.scss index 83e55b17..fb7ca851 100644 --- a/web/documentserver-example/ruby/app/assets/stylesheets/stylesheet.scss +++ b/web/documentserver-example/ruby/app/assets/stylesheets/stylesheet.scss @@ -594,6 +594,29 @@ footer table tr td:first-child { width: 4%; } +.storedHeader { + display: flex; + width: 100%; + justify-content: space-between; + align-items: center; +} + +.storedHeaderClearAll { + padding-right: 52px; +} + +.clear-all { + display: inline-block; + width: 100px; + padding: 2px; + outline: 1px solid #E5E5E5; + text-align: center; + cursor:pointer; + text-transform: uppercase; + background-color: #F5F5F5; + color: #666666; +} + .select-user { color: #444444; font-family: Open Sans; diff --git a/web/documentserver-example/ruby/app/controllers/home_controller.rb b/web/documentserver-example/ruby/app/controllers/home_controller.rb index a9d11b2b..94731d7b 100755 --- a/web/documentserver-example/ruby/app/controllers/home_controller.rb +++ b/web/documentserver-example/ruby/app/controllers/home_controller.rb @@ -251,24 +251,31 @@ class HomeController < ApplicationController # removing a file def remove - file_name = File.basename(params[:filename]) # get the file name - unless file_name # if it doesn't exist - render(plain: '{"success":false}') # report that the operation is unsuccessful - return - end - DocumentHelper.init(request.remote_ip, request.base_url) - storage_path = DocumentHelper.storage_path(file_name, nil) - hist_dir = DocumentHelper.history_dir(storage_path) - # if the file exists - FileUtils.rm_f(storage_path) # delete it from the storage path + if params[:filename] && !params[:filename].blank? + file_name = File.basename(params[:filename]) # get the file name + unless file_name # if it doesn't exist + render(plain: '{"success":false}') # report that the operation is unsuccessful + return + end - # if the history directory of this file exists - FileUtils.rm_rf(hist_dir) # delete it + storage_path = DocumentHelper.storage_path(file_name, nil) + hist_dir = DocumentHelper.history_dir(storage_path) + # if the file exists + FileUtils.rm_f(storage_path) # delete it from the storage path + + # if the history directory of this file exists + FileUtils.rm_rf(hist_dir) # delete it + else + storage_path = DocumentHelper.storage_path('', nil) + FileUtils.rm_rf(storage_path) # remove the user's directory and all the containing files + end render(plain: '{"success":true}') # report that the operation is successful nil + rescue StandardError => e + render(plain: '{"error": "Server error"}') end # getting files information diff --git a/web/documentserver-example/ruby/app/views/home/index.html.erb b/web/documentserver-example/ruby/app/views/home/index.html.erb index 3f7b3e90..c40267a0 100755 --- a/web/documentserver-example/ruby/app/views/home/index.html.erb +++ b/web/documentserver-example/ruby/app/views/home/index.html.erb @@ -123,7 +123,14 @@ <% if docs.length > 0 %>
- Your documents +
+
+ Your documents +
+
+
Clear all
+
+
diff --git a/web/documentserver-example/ruby/config/application.rb b/web/documentserver-example/ruby/config/application.rb index 0034f7dc..82525745 100644 --- a/web/documentserver-example/ruby/config/application.rb +++ b/web/documentserver-example/ruby/config/application.rb @@ -39,7 +39,7 @@ class Application < Rails::Application match '/files', to: 'home#files', via: 'get' match '/index', to: 'home#index', via: 'get' match '/reference', to: 'home#reference', via: 'post' - match '/remove', to: 'home#remove', via: 'get' + match '/remove', to: 'home#remove', via: 'delete' match '/rename', to: 'home#rename', via: 'post' match '/restore', to: 'home#restore', via: 'put' match '/sample', to: 'home#sample', via: 'get'