table .data-size, .table .data-size {
text-align: right;
}
+body .editable-empty {
+ color: #999;
+}
+body .editable-empty:hover {
+ color: #0088cc;
+}
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
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
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
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
serialize k, coldef[:type].constantize
end
attr_accessible k
+ @attribute_info[k] = coldef
end
attr_reader :etag
attr_reader :kind
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'
-<table class="table table-hover">
+<table class="table">
<thead>
<tr class="contain-align-left">
<th>
</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>
</tbody>
</table>
+
+<%= button_to "Add a new key", { action: 'create', return_to: './' }, { class: 'btn btn-primary' } %>