added admin controller and index view

This commit is contained in:
Skud
2013-05-29 14:37:42 +10:00
parent 7a1eaeffee
commit cbca8c19a5
15 changed files with 155 additions and 20 deletions

View File

@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/

View File

@@ -0,0 +1,45 @@
class Admin::OrdersController < ApplicationController
def index
authorize! :manage, :all
respond_to do |format|
format.html # index.html.haml
end
end
def search
@orders = nil
if params[:search_text]
case params[:search_by]
when "member"
begin
@member = Member.find(params[:search_text])
@orders = @member.orders
rescue ActiveRecord::RecordNotFound
flash[:alert] = "Couldn't find member with name #{params[:search_text]}"
end
when "order_id"
begin
@orders = [ Order.find(params[:search_text]) ]
rescue ActiveRecord::RecordNotFound
flash[:alert] = "Couldn't find order with id #{params[:search_text]}"
end
when "paypal_token"
@orders = [ Order.find_by_paypal_express_token(params[:search_text]) ]
if @orders.nil?
flash[:alert] = "Couldn't find order with paypal token #{params[:search_text]}"
end
when "paypal_payer_id"
@orders = [ Order.find_by_paypal_express_payer_id(params[:search_text]) ]
if @orders.nil?
flash[:alert] = "Couldn't find order with paypal payer id #{params[:search_text]}"
end
end
end
respond_to do |format|
format.html # index.html.haml
end
end
end

View File

@@ -0,0 +1,2 @@
module Admin::OrdersHelper
end

View File

@@ -1 +1,13 @@
-content_for :title, 'Admin'
%h2 Manage
%ul
%li= link_to "Account types", account_types_path
%li= link_to "Products", products_path
%li= link_to "Roles", roles_path
%li= link_to "Forums", forums_path
%h2 Orders
=render "admin/orders/searchform"

View File

@@ -0,0 +1,5 @@
= form_tag(url_for(:controller => 'admin/orders', :action => 'search'), :method => :get, :class => 'form-inline') do
= label_tag :distance, "Search orders:", :class => 'control-label'
= text_field_tag :search_text
= select_tag :search_by, options_for_select({'Member' => 'member', 'Order ID' => 'order_id', 'Paypal Token' => 'paypal_token', 'Paypal Payer ID' => 'paypal_payer_id' })
= submit_tag "Search", :class => 'btn btn-primary'

View File

@@ -0,0 +1,3 @@
-content_for :title, 'Admin Orders'
=render "admin/orders/searchform"

View File

@@ -0,0 +1,36 @@
-content_for :title, 'Search Orders'
=render "admin/orders/searchform"
- if @orders
%h2
Found
= pluralize(@orders.count, "result")
%table.table.table-striped
%tr
%th Member
%th Order number
%th Date completed
%th Items
%th
- @orders.each do |order|
%tr
%td= link_to order.member.login_name, order.member
%td= order.id
%td
- if order.completed_at
= order.completed_at.to_s
- else
In progress
%td
- if order.order_items.count > 0
- order.order_items.each do |o|
= o.quantity
x
= o.product.name
@
= price_with_currency(o.price)
%br/
%td= link_to 'Details', order, :class => 'btn btn-mini'

View File

@@ -35,16 +35,6 @@
%br/
- if current_member == current_member && !current_member.is_paid?
= link_to "Upgrade and Support Growstuff", shop_path, :class => 'btn btn-primary'
- if current_member.has_role?(:admin)
%p
%b You are an ADMIN USER.
- if current_member.forums.count > 0
%p
%b Forums you administer:
%ul
- current_member.forums.each do |f|
%li= link_to f.name, f
.row
.span6

View File

@@ -13,6 +13,8 @@
%li= link_to "Posts", posts_path
%li= link_to "Forums", forums_path
%li= link_to "Shop", shop_path
-if member_signed_in? and current_member.has_role?(:admin)
%li= link_to "Admin", admin_path
%li.divider-vertical
- if member_signed_in?
%li.dropdown<

View File

@@ -17,6 +17,14 @@
%strong Date completed:
= @order.completed_at.to_s
- if current_member.has_role? :admin
%p
%strong Paypal Express token:
= @order.paypal_express_token
%p
%strong Paypal Express payer ID:
= @order.paypal_express_payer_id
%h2 Order items
%table.table.table-striped

View File

@@ -99,6 +99,8 @@ Growstuff::Application.routes.draw do
match '/shop' => 'shop#index'
match '/shop/:action' => 'shop#:action'
match '/admin/orders' => 'admin/orders#index'
match '/admin/orders/:action' => 'admin/orders#:action'
match '/admin' => 'admin#index'
match '/admin/:action' => 'admin#:action'

View File

@@ -0,0 +1,5 @@
require 'spec_helper'
describe Admin::OrdersController do
end

View File

@@ -0,0 +1,15 @@
require 'spec_helper'
# Specs in this file have access to a helper object that includes
# the Admin::OrdersHelper. For example:
#
# describe Admin::OrdersHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# helper.concat_strings("this","that").should == "this that"
# end
# end
# end
describe Admin::OrdersHelper do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@@ -0,0 +1,17 @@
require 'spec_helper'
describe 'admin/index.html.haml', :type => "view" do
before(:each) do
@member = FactoryGirl.create(:admin_member)
sign_in @member
controller.stub(:current_user) { @member }
render
end
it "includes links to manage various things" do
assert_select "a", :href => account_types_path
assert_select "a", :href => products_path
assert_select "a", :href => roles_path
assert_select "a", :href => forums_path
end
end

View File

@@ -46,8 +46,6 @@ describe 'home/index.html.haml', :type => "view" do
@forum = FactoryGirl.create(:forum, :owner => @member)
@post = FactoryGirl.create(:post, :author => @member)
assign(:posts, [@post])
@role = FactoryGirl.create(:admin)
@member.roles << @role
render
end
@@ -82,13 +80,5 @@ describe 'home/index.html.haml', :type => "view" do
rendered.should contain "Upgrade"
end
it 'shows admin status' do
rendered.should contain "You are an ADMIN USER"
end
it 'shows forum list' do
assert_select "a[href=#{url_for(@forum)}]", @forum.name
end
end
end