Permalink
Browse files

start showing different content types properly, ie use img tag for im…

…ages
  • Loading branch information...
1 parent 7975e5e commit d578e41b7eb6bc152a409375077f3133601a5e7c @johnthethird committed Mar 2, 2010
Showing with 51 additions and 7 deletions.
  1. +27 −3 briak.rb
  2. +6 −0 public/briak.css
  3. +18 −4 views/index.erb
View
@@ -1,6 +1,6 @@
require 'rubygems'
-require 'sinatra'
require 'ripple'
+require 'sinatra'
require 'erb'
require 'uri'
@@ -63,12 +63,13 @@
end
end
@robject.content_type = params[:content_type]
- @robject.data = params[:data]
+ @robject.data = @robject.content_type == "application/json" ? ActiveSupport::JSON.decode(params[:data]) : params[:data]
@robject.store
redirect "/get/#{@bucket}/#{@key}?flash=#{URI.escape(@flash) if @flash}"
elsif params[:operation] == "Delete"
@robject.delete
- redirect "/get/#{@bucket}/#{@key}"
+ @flash = "Deleted key: #{@key}"
+ redirect "/get/#{@bucket}?flash=#{URI.escape(@flash) if @flash}"
elsif params[:operation] == "Eval"
@robject.data = params[:data]
@robject.store
@@ -86,6 +87,15 @@
redirect "/get/#{bucket}"
end
+post '/delete_bucket/:bucket' do |bucket|
+ client[bucket].keys.each {|key|
+ puts "deleting #{key}..."
+ find(bucket,key).delete
+ }
+ redirect "/"
+end
+
+
get '/remove_link/:bucket/:key/:link_bucket/:link_key/:link_rel' do |bucket, key, link_bucket, link_key, link_rel|
o = find(bucket,key)
o.links = o.links.select{ |link|
@@ -124,6 +134,20 @@ def find(bucket, key)
end
end
+# Renders out the appropriate HTML for each content type
+helpers do
+ def render_data(bucket, key, robject)
+ case
+ when robject.content_type =~ %r{application/json}
+ %Q{<textarea id="key-data" name="data" spellcheck="false">#{robject.data.to_json}</textarea>}
+ when robject.content_type =~ %r{image}
+ %Q{<div id="image-data"><image src="http://#{session[:host]}:#{session[:port]}/riak/#{bucket}/#{key}" /></div>}
+ else
+ %Q{<textarea id="key-data" name="data" spellcheck="false">#{robject.data.to_s}</textarea>}
+ end
+ end
+end
+
module Riak
class Link
attr_accessor :bucket
View
@@ -231,3 +231,9 @@ textarea#results {
display: block;
}
+#image-data {
+ margin: 30px;
+ width: 560px;
+ #height: 100px;
+ text-align: center;
+}
View
@@ -23,6 +23,7 @@
<textarea name="bucket_names"><%= find("briak", "bucket_names").data rescue nil %></textarea>
<input type="submit" value="Save Bucket List"/>
</form>
+ <a class="delete-bucket" href="/foo">Delete Bucket</a>
</div>
<div class="select-bar">
<select id="bucket_names">
@@ -69,11 +70,13 @@
<span class="edit-link">
<a href="<%= "/remove_link/#{@bucket}/#{@key}/#{l.bucket}/#{l.key}/#{l.rel}" %>">(remove)</a></span><br />
<% end %>
- <textarea id="key-data" name="data" spellcheck="false"><%= @robject.data %></textarea>
+ <%= render_data(@bucket, @key, @robject) %>
<div class="buttons">
- <input type="submit" name="operation" value="Eval" />
- <span class="edit-link">(What's this?)</span>
- <input type="submit" name="operation" value="Update" />
+ <% unless @robject.content_type =~ /image/ %>
+ <input type="submit" name="operation" value="Eval" />
+ <span class="edit-link">(What's this?)</span>
+ <input type="submit" name="operation" value="Update" />
+ <% end %>
<input type="submit" name="operation" value="Delete" />
</div>
<div id="eval-help" style="display:none">
@@ -139,4 +142,15 @@
});
});
});
+
+ jQuery(function($) { // document ready
+ $('a.delete-bucket').live('click', function(event) {
+ if ( confirm("Are you sure you want to delete all the keys in bucket: <" + $('#bucket_names').val() + "> ?") )
+ $('<form method="post" action="/delete_bucket/' + $('#bucket_names').val() + '" ></form>')
+ .appendTo('body')
+ .submit();
+ return false;
+ });
+ });
+
</script>

0 comments on commit d578e41

Please sign in to comment.