Skip to content

Commit

Permalink
Add admin controls for licenses
Browse files Browse the repository at this point in the history
  • Loading branch information
marktabler committed Jun 10, 2013
1 parent b7c09a0 commit 3cc99ce
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
17 changes: 16 additions & 1 deletion app/controllers/admin/licenses_controller.rb
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions app/views/admin/licenses/edit.html.erb
Original file line number Diff line number Diff line change
@@ -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 %>
19 changes: 19 additions & 0 deletions app/views/admin/licenses/index.html.erb
Original file line number Diff line number Diff line change
@@ -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>
6 changes: 3 additions & 3 deletions app/views/layouts/_nav.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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.