fix up editable stuff
authorTom Clegg <tom@clinicalfuture.com>
Fri, 7 Jun 2013 05:11:29 +0000 (01:11 -0400)
committerTom Clegg <tom@clinicalfuture.com>
Fri, 7 Jun 2013 05:11:29 +0000 (01:11 -0400)
apps/workbench/app/assets/stylesheets/application.css
apps/workbench/app/controllers/application_controller.rb
apps/workbench/app/controllers/authorized_keys_controller.rb
apps/workbench/app/helpers/application_helper.rb
apps/workbench/app/models/arvados_base.rb
apps/workbench/app/views/authorized_keys/index.html.erb

index ef6e8053e89bcb4b904d241e783fb4433ebf0548..829b1759f1eb3e59d4a0a0630f4c61fd466473cd 100644 (file)
@@ -36,3 +36,9 @@ tr.cell-noborder>td {
 table .data-size, .table .data-size {
     text-align: right;
 }
+body .editable-empty {
+    color: #999;
+}
+body .editable-empty:hover {
+    color: #0088cc;
+}
index f66f968d65e83ce2e590c125546c7d9ca5ad1fa0..92ef77b7c0ec3364d549464096563ade9746c7d4 100644 (file)
@@ -78,11 +78,19 @@ class ApplicationController < ActionController::Base
   end
 
   def create
-    @object = model_class.new params[model_class.to_s.singularize.to_sym]
+    @object ||= model_class.new params[model_class.to_s.singularize.to_sym]
     @object.save!
     redirect_to @object
   end
 
+  def destroy
+    if @object.destroy
+      redirect_to(params[:return_to] || :back)
+    else
+      self.render_error status: 422
+    end
+  end
+
   def current_user
     if Thread.current[:arvados_api_token]
       @current_user ||= User.current
index dc8a0998313c5a6bfae71d8b38136527f26ca168..5ca5222d6e93ee107078693045fee575a12bab3b 100644 (file)
@@ -2,5 +2,11 @@ class AuthorizedKeysController < ApplicationController
   def new
     super
     @object.authorized_user = current_user.uuid if current_user
+    @object.key_type = 'SSH'
+  end
+
+  def create
+    @object = AuthorizedKey.new authorized_user: current_user.uuid, key_type: 'SSH'
+    super
   end
 end
index fa25a29417eef49c186eccb16ae703321f064e64..c6d4d64a8ba4b8ac87ed773e06482cda1d83ac8a 100644 (file)
@@ -33,16 +33,19 @@ module ApplicationHelper
     end
   end
 
-  def render_editable_attribute(object, attr)
-    attrvalue = object.send attr
+  def render_editable_attribute(object, attr, attrvalue=nil, htmloptions={})
+    attrvalue = object.send(attr) if attrvalue.nil?
     return attrvalue if !object.attribute_editable? attr
-    link_to object.send(attr).to_s, '#', {
-      "data-type" => "text",
+    link_to attrvalue.to_s, '#', {
+      "data-emptytext" => "none",
+      "data-placement" => "bottom",
+      "data-type" => (object.class.attribute_info[attr.to_sym][:type] == "text" ? "textarea" : "text"),
       "data-resource" => object.class.to_s.underscore,
       "data-name" => attr,
+      "data-value" => object.send(attr),
       "data-url" => url_for(action: "update", id: object.uuid, controller: object.class.to_s.pluralize.underscore),
       "data-original-title" => "Update #{attr.gsub '_', ' '}",
       :class => "editable"
-    }
+    }.merge(htmloptions)
   end
 end
index 268b7b9a8c570ba6c47350d3c645c20c0988b03f..6da4eeda597c1d5cf9f6061ac4f90de13ae32da4 100644 (file)
@@ -43,6 +43,7 @@ class ArvadosBase < ActiveRecord::Base
   def self.columns
     return @columns unless @columns.nil?
     @columns = []
+    @attribute_info ||= {}
     return @columns if $arvados_api_client.arvados_schema[self.to_s.to_sym].nil?
     $arvados_api_client.arvados_schema[self.to_s.to_sym].each do |coldef|
       k = coldef[:name].to_sym
@@ -53,6 +54,7 @@ class ArvadosBase < ActiveRecord::Base
         serialize k, coldef[:type].constantize
       end
       attr_accessible k
+      @attribute_info[k] = coldef
     end
     attr_reader :etag
     attr_reader :kind
@@ -61,6 +63,10 @@ class ArvadosBase < ActiveRecord::Base
   def self.column(name, sql_type = nil, default = nil, null = true)
     ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
   end
+  def self.attribute_info
+    self.columns
+    @attribute_info
+  end
   def self.find(uuid)
     if uuid.class != String or uuid.length < 27 then
       raise 'argument to find() must be a uuid string. Acceptable formats: warehouse locator or string with format xxxxx-xxxxx-xxxxxxxxxxxxxxx'
index 99ab69bc3ad3963822d42eb50bfca760e535ee4e..823a17eb96cb129697c9dd3cbe8a2ce18b99cd2d 100644 (file)
@@ -1,4 +1,4 @@
-<table class="table table-hover">
+<table class="table">
   <thead>
     <tr class="contain-align-left">
       <th>
@@ -18,7 +18,7 @@
   </thead>
   <tbody>
 
-    <% @objects.sort_by { |ak| ak[:created_at] }.reverse.each do |ak| %>
+    <% @objects.sort_by { |ak| ak[:created_at] }.each do |ak| %>
 
     <tr>
       <td>
       </td><td>
         <%= render_editable_attribute ak, 'name' %>
       </td><td>
-        <%= render_editable_attribute ak, 'key_type' %>
+        <%= render_editable_attribute ak, 'key_type', ak.key_type, "data-type" => "select", "data-source" => '[{value:"SSH",text:"SSH"}]' %>
       </td><td>
-        <%= render_editable_attribute ak, 'public_key' %>
+        <%= render_editable_attribute ak, 'public_key', ak.public_key.andand.sub(/^(.{12}).{16,}(.{16,})$/, '\1...\2') %>
       </td><td>
         <%= render_editable_attribute ak, 'expires_at' %>
+      </td><td>
+        <%= link_to raw('<i class="icon-trash"></i>'), { action: 'destroy', id: ak.uuid }, { confirm: 'Delete this key?', method: 'delete' } %>
       </td>
     </tr>
 
     <% end %>
     <% if @objects.count == 0 %>
     <tr>
-      <td colspan="6">
+      <td colspan="7">
         (no authorized keys)
       </td>
     </tr>
@@ -47,3 +49,5 @@
 
   </tbody>
 </table>
+
+<%= button_to "Add a new key", { action: 'create', return_to: './' }, { class: 'btn btn-primary' } %>