소스 검색

Add delete torrent feature

Antoine Leroyer 11 년 전
부모
커밋
7e8f9b1e8f
9개의 변경된 파일319개의 추가작업 그리고 9개의 파일을 삭제
  1. 11 0
      lib/rSeed/rtorrent.rb
  2. 17 0
      lib/rSeed/server.rb
  3. 137 0
      public/css/alertify.core.css
  4. 128 0
      public/css/alertify.foundation.css
  5. 1 0
      public/js/alertify.min.js
  6. 20 2
      public/js/custom.js
  7. 0 4
      public/js/notify-combined.min.js
  8. 3 3
      views/index.haml
  9. 2 0
      views/layout.haml

+ 11 - 0
lib/rSeed/rtorrent.rb

@@ -94,5 +94,16 @@ module RSeed
 
     end
 
+    def delete(hash)
+      begin
+        @client.call("d.stop", hash)
+        @client.call("d.erase", hash)
+      rescue XMLRPC::FaultException => e
+        puts "Error:"
+        puts e.faultCode
+        puts e.faultString
+      end
+    end
+
   end
 end

+ 17 - 0
lib/rSeed/server.rb

@@ -176,5 +176,22 @@ module RSeed
       end
     end
 
+    post '/api/:request' do
+      case params[:request]
+      when 'delete'
+        if not params[:hash].nil?
+          if @rtorrent.delete(@rtorrent.getHash(params[:hash]))
+            return "OK"
+          else
+            return "Error"
+          end
+        else
+          502
+        end
+      else
+        502
+      end
+    end
+
   end
 end

+ 137 - 0
public/css/alertify.core.css

@@ -0,0 +1,137 @@
+.alertify,
+.alertify-show,
+.alertify-log {
+	-webkit-transition: all 500ms cubic-bezier(0.175, 0.885, 0.320, 1.275);
+	   -moz-transition: all 500ms cubic-bezier(0.175, 0.885, 0.320, 1.275);
+	    -ms-transition: all 500ms cubic-bezier(0.175, 0.885, 0.320, 1.275);
+	     -o-transition: all 500ms cubic-bezier(0.175, 0.885, 0.320, 1.275);
+	        transition: all 500ms cubic-bezier(0.175, 0.885, 0.320, 1.275); /* easeOutBack */
+}
+.alertify-hide {
+	-webkit-transition: all 250ms cubic-bezier(0.600, -0.280, 0.735, 0.045);
+	   -moz-transition: all 250ms cubic-bezier(0.600, -0.280, 0.735, 0.045);
+	    -ms-transition: all 250ms cubic-bezier(0.600, -0.280, 0.735, 0.045);
+	     -o-transition: all 250ms cubic-bezier(0.600, -0.280, 0.735, 0.045);
+	        transition: all 250ms cubic-bezier(0.600, -0.280, 0.735, 0.045); /* easeInBack */
+}
+.alertify-log-hide {
+	-webkit-transition: all 500ms cubic-bezier(0.600, -0.280, 0.735, 0.045);
+	   -moz-transition: all 500ms cubic-bezier(0.600, -0.280, 0.735, 0.045);
+	    -ms-transition: all 500ms cubic-bezier(0.600, -0.280, 0.735, 0.045);
+	     -o-transition: all 500ms cubic-bezier(0.600, -0.280, 0.735, 0.045);
+	        transition: all 500ms cubic-bezier(0.600, -0.280, 0.735, 0.045); /* easeInBack */
+}
+.alertify-cover {
+	position: fixed; z-index: 99999;
+	top: 0; right: 0; bottom: 0; left: 0;
+	background-color:white;
+	filter:alpha(opacity=0);
+	opacity:0;
+}
+	.alertify-cover-hidden {
+		display: none;
+	}
+.alertify {
+	position: fixed; z-index: 99999;
+	top: 50px; left: 50%;
+	width: 550px;
+	margin-left: -275px;
+	opacity: 1;
+}
+	.alertify-hidden {
+		-webkit-transform: translate(0,-150px);
+		   -moz-transform: translate(0,-150px);
+		    -ms-transform: translate(0,-150px);
+		     -o-transform: translate(0,-150px);
+		        transform: translate(0,-150px);
+		opacity: 0;
+		display: none;
+	}
+	/* overwrite display: none; for everything except IE6-8 */
+	:root *> .alertify-hidden {
+		display: block;
+		visibility: hidden;
+	}
+.alertify-logs {
+	position: fixed;
+	z-index: 5000;
+	bottom: 10px;
+	right: 10px;
+	width: 300px;
+}
+.alertify-logs-hidden {
+	display: none;
+}
+	.alertify-log {
+		display: block;
+		margin-top: 10px;
+		position: relative;
+		right: -300px;
+		opacity: 0;
+	}
+	.alertify-log-show {
+		right: 0;
+		opacity: 1;
+	}
+	.alertify-log-hide {
+		-webkit-transform: translate(300px, 0);
+		   -moz-transform: translate(300px, 0);
+		    -ms-transform: translate(300px, 0);
+		     -o-transform: translate(300px, 0);
+		        transform: translate(300px, 0);
+		opacity: 0;
+	}
+	.alertify-dialog {
+		padding: 25px;
+	}
+		.alertify-resetFocus {
+			border: 0;
+			clip: rect(0 0 0 0);
+			height: 1px;
+			margin: -1px;
+			overflow: hidden;
+			padding: 0;
+			position: absolute;
+			width: 1px;
+		}
+		.alertify-inner {
+			text-align: center;
+		}
+		.alertify-text {
+			margin-bottom: 15px;
+			width: 100%;
+			-webkit-box-sizing: border-box;
+			   -moz-box-sizing: border-box;
+			        box-sizing: border-box;
+			font-size: 100%;
+		}
+		.alertify-buttons {
+		}
+			.alertify-button,
+			.alertify-button:hover,
+			.alertify-button:active,
+			.alertify-button:visited {
+				background: none;
+				text-decoration: none;
+				border: none;
+				/* line-height and font-size for input button */
+				line-height: 1.5;
+				font-size: 100%;
+				display: inline-block;
+				cursor: pointer;
+				margin-left: 5px;
+			}
+
+@media only screen and (max-width: 680px) {
+	.alertify,
+	.alertify-logs {
+		width: 90%;
+		-webkit-box-sizing: border-box;
+		   -moz-box-sizing: border-box;
+		        box-sizing: border-box;
+	}
+	.alertify {
+		left: 5%;
+		margin: 0;
+	}
+}

+ 128 - 0
public/css/alertify.foundation.css

@@ -0,0 +1,128 @@
+/**
+ * Twitter Bootstrap Look and Feel
+ * Based on http://twitter.github.com/bootstrap/
+ */
+.alertify,
+.alertify-log {
+	font-family: sans-serif;
+}
+.alertify {
+	background: #FFF;
+	border: 1px solid #666; /* browsers that don't support rgba */
+	box-shadow: 0 0 10px rgba(#000,.4);
+	-webkit-background-clip: padding;     /* Safari 4? Chrome 6? */
+	   -moz-background-clip: padding;     /* Firefox 3.6 */
+	        background-clip: padding-box; /* Firefox 4, Safari 5, Opera 10, IE 9 */
+}
+.alertify-dialog {
+	padding: 0;
+}
+	.alertify-inner {
+		text-align: left;
+	}
+		.alertify-message {
+			padding: 15px;
+			margin: 0;
+		}
+		.alertify-text-wrapper {
+			padding: 0 15px;
+		}
+			.alertify-text {
+				color: #222;
+				border-radius: 4px;
+				padding: 8px;
+				background-color: #FFF;
+				border: 1px solid #CCC;
+				box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
+			}
+			.alertify-text:focus {
+				border-color: rgba(82,168,236,.8);
+				outline: 0;
+				box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(82,168,236,.6);
+			}
+
+		.alertify-buttons {
+			padding: 14px 15px 15px;
+			background: #F5F5F5;
+			border-top: 1px solid #DDD;
+			border-radius: 0 0 6px 6px;
+			box-shadow: inset 0 1px 0 #FFF;
+			text-align: right;
+		}
+			.alertify-button,
+			.alertify-button:hover,
+			.alertify-button:focus,
+			.alertify-button:active {
+				margin-left: 10px;
+				border-radius: 4px;
+				font-weight: normal;
+				padding: 4px 12px;
+				text-decoration: none;
+				box-shadow: inset 0 1px 0 rgba(255, 255, 255, .2), 0 1px 2px rgba(0, 0, 0, .05);
+				background-image: -webkit-linear-gradient(top, rgba(255,255,255,.3), rgba(255,255,255,0));
+				background-image:    -moz-linear-gradient(top, rgba(255,255,255,.3), rgba(255,255,255,0));
+				background-image:     -ms-linear-gradient(top, rgba(255,255,255,.3), rgba(255,255,255,0));
+				background-image:      -o-linear-gradient(top, rgba(255,255,255,.3), rgba(255,255,255,0));
+				background-image:         linear-gradient(top, rgba(255,255,255,.3), rgba(255,255,255,0));
+			}
+			.alertify-button:focus {
+				outline: none;
+				box-shadow: 0 0 5px #2B72D5;
+			}
+			.alertify-button:active {
+				position: relative;
+				box-shadow: inset 0 2px 4px rgba(0,0,0,.15), 0 1px 2px rgba(0,0,0,.05);
+			}
+				.alertify-button-cancel,
+				.alertify-button-cancel:hover,
+				.alertify-button-cancel:focus,
+				.alertify-button-cancel:active {
+					text-shadow: 0 -1px 0 rgba(255,255,255,.75);
+					background-color: #E6E6E6;
+					border: 1px solid #BBB;
+					color: #333;
+					background-image: -webkit-linear-gradient(top, #FFF, #E6E6E6);
+					background-image:    -moz-linear-gradient(top, #FFF, #E6E6E6);
+					background-image:     -ms-linear-gradient(top, #FFF, #E6E6E6);
+					background-image:      -o-linear-gradient(top, #FFF, #E6E6E6);
+					background-image:         linear-gradient(top, #FFF, #E6E6E6);
+				}
+				.alertify-button-cancel:hover,
+				.alertify-button-cancel:focus,
+				.alertify-button-cancel:active {
+					background: #E6E6E6;
+				}
+				.alertify-button-ok,
+				.alertify-button-ok:hover,
+				.alertify-button-ok:focus,
+				.alertify-button-ok:active {
+					text-shadow: 0 -1px 0 rgba(0,0,0,.25);
+					background-color: #04C;
+					border: 1px solid #04C;
+					border-color: #04C #04C #002A80;
+					border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
+					color: #FFF;
+				}
+				.alertify-button-ok:hover,
+				.alertify-button-ok:focus,
+				.alertify-button-ok:active {
+					background: #04C;
+				}
+
+.alertify-log {
+	background: #A0D3E8;
+	padding: 8px 14px;
+	border-radius: 4px;
+	color: #4F4F4F;
+	border: 1px solid #74BFDD;
+}
+	.alertify-log-error {
+		color: #FFF;
+		background: #F04124;
+		border: 1px solid #CF280E;
+	}
+	.alertify-log-success {
+		color: #FFF;
+		background: #43AC6A;
+		border: 1px solid #3A945B;
+	}

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 1 - 0
public/js/alertify.min.js


+ 20 - 2
public/js/custom.js

@@ -7,7 +7,7 @@ window.setInterval(function(){
 $(document).ready(function() {
   $.ajaxSetup({ cache: false });
 
-  $("a[data-torrent-id]").click(function() {
+  $(".share-torrent").click(function() {
       var hash = $(this).attr("data-torrent-id");
       $.ajax({
         type: "POST",
@@ -21,7 +21,25 @@ $(document).ready(function() {
         $('#shareModal').foundation('reveal', 'open');
       });
   });
-  
+
+  $(".del-torrent").click(function() {
+      var hash = $(this).attr("data-torrent-id");
+      var obj = $(this);
+      $.ajax({
+        type: "POST",
+        url: "api/delete",
+        data: { hash: hash }
+      })
+      .done(function( msg ) {
+        if( msg == "OK" ) {
+          alertify.success("Torrent deleted !"); 
+          obj.parent().parent().remove();
+        } else {
+          alertify.error("There is an error, I can't delete this torrent :(");
+        }
+      });
+  });  
+
   refreshList();
   refreshUpDownTotal();
   diskInfo();

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 4
public/js/notify-combined.min.js


+ 3 - 3
views/index.haml

@@ -49,10 +49,10 @@
             %td.text-center.upspeed
             %td.text-center.downspeed
             %td.text-center
-              %a{href: "#", data: {:torrent_id => "#{t["hash"][0,10]}"} }
+              %a.share-torrent{data: {:torrent_id => "#{t["hash"][0,10]}"} }
                 %i.fi-cloud
               |
-              %a
+              %a.del-torrent{data: {:torrent_id => "#{t["hash"][0,10]}"} }
                 %i.fi-trash
 
 #addModal.reveal-modal.medium{"data-reveal" => ""}
@@ -99,7 +99,7 @@
 
 %script{:src => '/js/vendor/jquery.js'}
 %script{:src => '/js/foundation.min.js'}
-%script{:src => '/js/notify-combined.min.js'}
+%script{:src => '/js/alertify.min.js'}
 %script{:src => '/js/custom.js'}
 %script
   $(document).foundation();

+ 2 - 0
views/layout.haml

@@ -4,6 +4,8 @@
     %meta{'http-equiv' => 'content-type', :content => 'text/html; charset=utf-8'}
     %link{:rel => :stylesheet, :href => "/css/foundation.css", :type => "text/css"}
     %link{:rel => :stylesheet, :href => "/fonts/foundation-icons/foundation-icons.css", :type => "text/css"}
+    %link{:rel => :stylesheet, :href => "/css/alertify.core.css", :type => "text/css"}
+    %link{:rel => :stylesheet, :href => "/css/alertify.foundation.css", :type => "text/css"}
     %script{:type => 'text/javascript', :src => '/js/modernizr.js'}
     %body
       %section{:role => 'main'}

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.