Admin subscribe manage

This commit is contained in:
yafeilee 2016-04-27 15:42:44 +08:00
parent 218548c3b4
commit f543fad37d
9 changed files with 115 additions and 1 deletions

View File

@ -0,0 +1,3 @@
.admin-subscribes-field {
}

View File

@ -22,7 +22,7 @@ class Admin::PostsController < ApplicationController
end end
def index def index
@posts = Post.order(created_at: :desc).page(params[:page]) @posts = Post.order(created_at: :desc).page(params[:page]).per(25)
end end
def create def create

View File

@ -0,0 +1,26 @@
class Admin::SubscribesController < ApplicationController
layout 'layouts/admin'
before_action :authericate_user!
def index
@subscribes = Subscribe.all.order(created_at: :desc).page(params[:page]).per(25)
end
def enable
@subscribe = Subscribe.find(params[:id])
@subscribe.enable = true
@subscribe.save!
redirect_to admin_subscribes_path, notice: "#{@subscribe.email} is enabled!"
end
def disable
@subscribe = Subscribe.find(params[:id])
@subscribe.enable = false
@subscribe.save!
redirect_to admin_subscribes_path, notice: "#{@subscribe.email} is disabled!"
end
end

View File

@ -0,0 +1,25 @@
.row.admin-subscribes-field
.small-12.columns
h3.blog-title #{t('admin.subscribes') }
table width="100%"
thead
tr
th #{t('admin.subscribes_head.email')}
th #{t('admin.subscribes_head.enable')}
th #{t('admin.subscribes_head.created_at')}
th #{t('admin.subscribes_head.operation')}
tbody
- @subscribes.each do |subscribe|
tr
td
= mail_to subscribe.email
td
= subscribe.enable
td
= format_time(subscribe.created_at)
td
- if subscribe.enable
= link_to t('admin.subscribes_head.op.disable'), disable_admin_subscribe_path(subscribe), method: 'POST', data: { confirm: 'Confirm?' }
- else
= link_to t('admin.subscribes_head.op.enable'), enable_admin_subscribe_path(subscribe), method: 'POST', data: { confirm: 'Confirm?' }
== paginate @subscribes

View File

@ -20,6 +20,8 @@ html
= link_to t('admin.new_post'), new_admin_post_path = link_to t('admin.new_post'), new_admin_post_path
li li
= link_to t('admin.posts'), admin_posts_path = link_to t('admin.posts'), admin_posts_path
li
= link_to t('admin.subscribes'), admin_subscribes_path
.top-bar-right .top-bar-right
ul.menu ul.menu
li li

View File

@ -77,6 +77,16 @@ en:
reply: 'Reply' reply: 'Reply'
destroy: 'Destroy' destroy: 'Destroy'
subscribes: 'Manage Subscribes'
subscribes_head:
email: 'Email'
enable: 'Enable Flag'
created_at: 'Created at'
operation: 'Operation'
op:
enable: 'Enable'
disable: 'Disable'
back: 'Back to Home' back: 'Back to Home'
logout: 'Logout' logout: 'Logout'
dashboard: dashboard:

View File

@ -77,6 +77,16 @@ zh-CN:
reply: '回复' reply: '回复'
destroy: '删除' destroy: '删除'
subscribes: '订阅管理'
subscribes_head:
email: '邮箱'
enable: '是否启用'
created_at: '创建时间'
operation: '操作'
op:
enable: '启用'
disable: '禁用'
back: '返回首页' back: '返回首页'
logout: '退出' logout: '退出'
dashboard: dashboard:

View File

@ -29,6 +29,12 @@ WBlog::Application.routes.draw do
resources :comments resources :comments
end end
resources :sessions, :only=>[:new, :create, :destroy] resources :sessions, :only=>[:new, :create, :destroy]
resources :subscribes, only: [:index] do
member do
post :enable
post :disable
end
end
root 'dashboard#index' root 'dashboard#index'
end end

View File

@ -0,0 +1,32 @@
require 'spec_helper'
RSpec.describe Admin::SubscribesController, :type => :controller do
before do
session[:login] = true
end
describe "GET index" do
it "returns http success" do
get :index
expect(response).to have_http_status(:success)
end
end
describe "POST enable" do
it "returns http success" do
subscribe = create(:subscribe)
post :enable, id: subscribe.id
expect(subscribe.reload.enable).to eq(true)
end
end
describe "POST disable" do
it "returns http success" do
subscribe = create(:subscribe, enable: true)
post :disable, id: subscribe.id
expect(subscribe.reload.enable).to eq(false)
end
end
end