Skip to content
Browse files

Add admin controls for licenses

  • Loading branch information...
1 parent b7c09a0 commit 3cc99ceea85344e02fae3c14af80ffbe067dd9fa @marktabler committed Jun 9, 2013
View
17 app/controllers/admin/licenses_controller.rb
@@ -1,5 +1,20 @@
class Admin::LicensesController < ApplicationController
before_filter :admin_required
-
+
+ def edit
+ @license = License.find(params[:id])
+ end
+
+ def update
+ @license = License.find(params[:id])
+ @license.update_attributes(license_params)
+ return redirect_to admin_licenses_path
+ end
+
+ private
+
+ def license_params
+ params.require(:license).permit(:name, :capacity)
+ end
end
View
7 app/views/admin/licenses/edit.html.erb
@@ -0,0 +1,7 @@
+<%= form_for @license, url: admin_license_path(@license), method: :put do |f| %>
+ <%= f.label :name %>
+ <%= f.text_field :name %>
+ <%= f.label :capacity %>
+ <%= f.text_field :capacity %>
+ <%= f.submit %>
+<% end %>
View
19 app/views/admin/licenses/index.html.erb
@@ -0,0 +1,19 @@
+<h2>Administer Licenses</h2>
+<table>
+ <tr>
+ <th>Name</th>
+ <th>Total</th>
+ <th>Used</th>
+ <th>Remaining</th>
+ <th>Delete</th>
+ </tr>
+ <% License.all.each do |license| %>
+ <tr>
+ <td><%= link_to license.name, edit_admin_license_path(license) %></td>
+ <td><%= license.capacity %></td>
+ <td><%= license.used_count %></td>
+ <td><%= license.remaining %></td>
+ <td><%= link_to "Delete", admin_license_path(license), method: :delete, data: { confirm: "Delete #{license.name} and all installation records? This action cannot be undone."} %></td>
+ </tr>
+ <% end %>
+</table>
View
6 app/views/layouts/_nav.html.erb
@@ -3,7 +3,7 @@
<li><%= link_to "View Licenses", licenses_path %></li>
<li><%= link_to "View Assets", machines_path %></li>
<% if current_user.admin? %>
- <li><%= link_to "Administer Licenses", licenses_path %></li>
- <li><%= link_to "Administer Assets", machines_path %></li>
- <li><%= link_to "Administer Users", licenses_path %></li>
+ <li><%= link_to "Administer Licenses", admin_licenses_path %></li>
+ <li><%= link_to "Administer Assets", admin_machines_path %></li>
+ <li><%= link_to "Administer Users", admin_users_path %></li>
<% end %>

0 comments on commit 3cc99ce

Please sign in to comment.
Something went wrong with that request. Please try again.