aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/assets/stylesheets/api_keys.css.scss34
-rw-r--r--app/controllers/api_keys_controller.rb17
-rw-r--r--app/models/api/v1/api_key.rb4
-rw-r--r--app/views/api_keys/_api_key.html.erb12
-rw-r--r--app/views/api_keys/_form.html.erb14
-rw-r--r--app/views/api_keys/edit.html.erb4
-rw-r--r--app/views/api_keys/new.html.erb4
-rw-r--r--app/views/referentials/show.html.erb7
8 files changed, 96 insertions, 0 deletions
diff --git a/app/assets/stylesheets/api_keys.css.scss b/app/assets/stylesheets/api_keys.css.scss
new file mode 100644
index 000000000..cca96321e
--- /dev/null
+++ b/app/assets/stylesheets/api_keys.css.scss
@@ -0,0 +1,34 @@
+// Place all the styles related to the routes controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
+@import "common";
+
+#workspace.referentials.show
+{
+ .api_key:after {
+ @include after_div_for_object;
+ }
+
+ .api_keys {
+ margin-top: 20px;
+ }
+
+ .api_keys:after {
+ @include content_to_clear;
+ }
+
+ .api_key {
+ @include div_for_object;
+
+ /* to create multi-column index */
+ width: 350px;
+ padding-right: 10px;
+
+ .name {
+ line-height: 16px;
+ float: left;
+ }
+
+ }
+}
+
diff --git a/app/controllers/api_keys_controller.rb b/app/controllers/api_keys_controller.rb
new file mode 100644
index 000000000..fea8f66b3
--- /dev/null
+++ b/app/controllers/api_keys_controller.rb
@@ -0,0 +1,17 @@
+class ApiKeysController < ChouetteController
+ defaults :resource_class => Api::V1::ApiKey
+
+ belongs_to :referential
+
+ def create
+ create! { referential_path(@referential) }
+ end
+ def update
+ update! { referential_path(@referential) }
+ end
+ def destroy
+ destroy! { referential_path(@referential) }
+ end
+
+end
+
diff --git a/app/models/api/v1/api_key.rb b/app/models/api/v1/api_key.rb
index 40719127a..2c1b9ba5f 100644
--- a/app/models/api/v1/api_key.rb
+++ b/app/models/api/v1/api_key.rb
@@ -4,6 +4,10 @@ module Api
before_create :generate_access_token
belongs_to :referential, :class_name => '::Referential'
+ def self.model_name
+ ActiveModel::Name.new self, Api::V1, self.name.demodulize
+ end
+
def eql?(other)
other.token == self.token
end
diff --git a/app/views/api_keys/_api_key.html.erb b/app/views/api_keys/_api_key.html.erb
new file mode 100644
index 000000000..6492af3b0
--- /dev/null
+++ b/app/views/api_keys/_api_key.html.erb
@@ -0,0 +1,12 @@
+<%= div_for(api_key) do %>
+ <%= api_key.token %>
+ <div class="info">
+ <%= api_key.class.human_attribute_name('name') %> <%= api_key.name %> -
+ <%= api_key.class.human_attribute_name('updated_at') %> <%= l(api_key.updated_at) %>
+ <div class="actions">
+ <%= link_to t("actions.edit"), edit_referential_api_key_path(@referential, api_key), :class => "edit" %> |
+ <%= link_to t("actions.destroy"), referential_api_key_path(@referential, api_key), :method => :delete, :data => {:confirm => t('api_keys.actions.destroy_confirm')}, :class => "remove" %>
+ </div>
+ </div>
+<% end %>
+
diff --git a/app/views/api_keys/_form.html.erb b/app/views/api_keys/_form.html.erb
new file mode 100644
index 000000000..de3f9ad7e
--- /dev/null
+++ b/app/views/api_keys/_form.html.erb
@@ -0,0 +1,14 @@
+<%= semantic_form_for [@referential, @api_key] do |form| %>
+ <%= form.inputs do %>
+ <%= form.input :name %>
+ <% unless @api_key.new_record? %>
+ <%= form.input :token, :input_html => { :disabled => true } %>
+ <% end %>
+ <% end %>
+
+ <%= form.actions do %>
+ <%= form.action :submit, :as => :button %>
+ <%= form.action :cancel, :as => :link %>
+ <% end %>
+<% end %>
+
diff --git a/app/views/api_keys/edit.html.erb b/app/views/api_keys/edit.html.erb
new file mode 100644
index 000000000..7d367421e
--- /dev/null
+++ b/app/views/api_keys/edit.html.erb
@@ -0,0 +1,4 @@
+<%= title_tag t('api_keys.edit.title') %>
+
+<%= render "form" %>
+
diff --git a/app/views/api_keys/new.html.erb b/app/views/api_keys/new.html.erb
new file mode 100644
index 000000000..40dd1a4fe
--- /dev/null
+++ b/app/views/api_keys/new.html.erb
@@ -0,0 +1,4 @@
+<%= title_tag t('api_keys.new.title') %>
+
+<%= render "form" %>
+
diff --git a/app/views/referentials/show.html.erb b/app/views/referentials/show.html.erb
index 64df439a0..d8e5dd8df 100644
--- a/app/views/referentials/show.html.erb
+++ b/app/views/referentials/show.html.erb
@@ -39,12 +39,19 @@
</td>
</tr>
</table>
+
+<h3 class="api_keys"><%= t('.api_keys') %></h3>
+
+<div class="api_keys">
+ <%= render :partial => "api_keys/api_key", :collection => @referential.api_keys %>
+</div>
</div>
<% content_for :sidebar do %>
<ul class="actions">
<li><%= link_to t('referentials.actions.edit'), edit_referential_path(@referential), :class => "edit" %></li>
<li><%= link_to t('referentials.actions.destroy'), referential_path(@referential), :method => :delete, :data => {:confirm => t('referentials.actions.destroy_confirm')}, :class => "remove" %></li>
+ <li><%= link_to t('api_keys.actions.new'), new_referential_api_key_path(@referential), :class => "add" %></li>
<br>
</ul>