-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e7721cb
commit d87c080
Showing
19 changed files
with
244 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
class Web::Admin::VideosController < Web::Admin::ApplicationController | ||
def index | ||
@videos = {} | ||
@videos[:active] = Content::Video.active.page(params[:page]).decorate | ||
@videos[:unviewed] = Content::Video.unviewed.page(params[:page]).decorate | ||
@videos[:removed] = Content::Video.removed.page(params[:page]).decorate | ||
@videos[:search] = Content::Video.search_everywhere(params[:search]).page(params[:page]).decorate if params[:search] | ||
end | ||
|
||
def new | ||
@video_form = Content::VideoForm.new_with_model | ||
end | ||
|
||
def edit | ||
@video_form = Content::VideoForm.find_with_model params[:id] | ||
end | ||
|
||
def create | ||
@video_form = Content::VideoForm.new_with_model | ||
@video_form.submit(params[:video]) | ||
if @video_form.save | ||
redirect_to admin_videos_path | ||
else | ||
render action: :new | ||
end | ||
end | ||
|
||
def update | ||
@video_form = Content::VideoForm.find_with_model params[:id] | ||
@video_form.submit(params[:video]) | ||
if @video_form.save | ||
redirect_to edit_admin_video_path @video_form.model | ||
else | ||
render action: :edit | ||
end | ||
end | ||
|
||
def destroy | ||
@video = Content::Video.find params[:id] | ||
@video.remove | ||
redirect_to admin_videos_path | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Content::VideoForm < ApplicationForm | ||
attributes :title, :link, :description, :author_id, :state | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Content | ||
def self.table_name_prefix | ||
'content_' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class Content::Video < ActiveRecord::Base | ||
belongs_to :author, class_name: 'User' | ||
|
||
validates :title, presence: true | ||
validates :link, presence: :url | ||
|
||
include Content::VideoScopes | ||
|
||
state_machine :state, initial: :active do | ||
state :active | ||
state :unviewed | ||
state :removed | ||
|
||
event :make_active do | ||
transition unviewed: :active | ||
end | ||
event :hide do | ||
transition active: :unviewed | ||
end | ||
event :remove do | ||
transition all => :removed | ||
end | ||
event :restore do | ||
transition removed: :unviewed | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Content::VideoScopes | ||
extend ActiveSupport::Concern | ||
include Concerns::StateMachine | ||
|
||
included do | ||
scope :active, -> { where(state: :active).order('created_at ASC') } | ||
scope :unviewed, -> { where(state: :unviewed).order('id DESC') } | ||
scope :presented, -> { where.not(state: :removed).order('id ASC') } | ||
scope :removed, -> { where state: :removed } | ||
scope :with_vertical, -> { where.not(vertical: nil) } | ||
scope :with_horizontal, -> { where.not(horizontal: nil) } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
- model_class = Content::Video | ||
- current_title = page_title(action, model_class.model_name.human) | ||
- title current_title, :admin | ||
.page-header | ||
%h1= page_title(action, Content::Video.model_name.human) | ||
.row | ||
.col-lg-12 | ||
= render 'layouts/web/admin/shared/messages', object: @video_form | ||
.row | ||
.col-lg-6 | ||
= simple_form_for [:admin, @video_form], input_html: { class: 'form-horizontal' } do |f| | ||
= f.input :title, as: :string | ||
= f.input :description, as: :string | ||
= f.input :author_id, as: :select, collection: users_hash(@users), input_html: { class: :select2 } | ||
= f.input :state_event, as: :state_event | ||
= f.input :link, as: :string | ||
= f.button :submit, t('helpers.links.save'), class: 'btn-success' | ||
= link_to t('helpers.links.back'), admin_members_path, class: 'btn btn-default' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
= paginate videos, theme: 'twitter-bootstrap-3' | ||
- model_class = Content::Video | ||
%table.table.table-condensed.table-hover | ||
%thead | ||
%tr | ||
%th= model_class.human_attribute_name(:id) | ||
%th= model_class.human_attribute_name(:photo) | ||
%th= model_class.human_attribute_name(:link) | ||
%th= model_class.human_attribute_name(:duration) | ||
%th= t 'helpers.links.actions' | ||
%tbody | ||
- videos.each do |video| | ||
%tr.link{ class: state_color(video), data: { href: edit_admin_video_path(video) } } | ||
%td= video.id | ||
%td= image_tag video.small_thumb | ||
%td= link_to video.link, video.link | ||
%td= "#{l(video.begin_date)} - #{l(video.end_date)}" | ||
%td.actions | ||
= link_to edit_admin_video_path(video), class: 'btn btn-warning btn-xs' do | ||
%span.glyphicon.glyphicon-pencil | ||
= link_to admin_video_path(video), method: :delete, class: 'btn btn-xs btn-danger' do | ||
%span.glyphicon.glyphicon-remove | ||
= paginate videos, theme: 'twitter-bootstrap-3' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
= render partial: 'form', locals: { action: :update } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
= render 'web/admin/default/index', items: @videos |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
= render partial: 'form', locals: { action: :create } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class CreateContentVideos < ActiveRecord::Migration | ||
def change | ||
create_table :content_videos do |t| | ||
t.text :title | ||
t.text :description | ||
t.integer :author_id | ||
t.text :link | ||
t.text :state | ||
|
||
t.timestamps null: false | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
require 'test_helper' | ||
|
||
class Web::Admin::VideosControllerTest < ActionController::TestCase | ||
setup do | ||
@video = create :content_video | ||
admin = create :admin | ||
sign_in admin | ||
@exceptions_attributes = ['id', 'created_at', 'updated_at'] | ||
end | ||
|
||
test 'should get new' do | ||
get :new | ||
assert_response :success, @response.body | ||
end | ||
|
||
test 'should get index' do | ||
get :index | ||
assert_response :success, @response.body | ||
end | ||
|
||
test 'should get index with search' do | ||
get :index, search: @video.link | ||
assert_response :success, @response.body | ||
end | ||
|
||
test 'should get index without instances' do | ||
Content::Video.all.map &:destroy | ||
get :index | ||
assert_response :success, @response.body | ||
end | ||
|
||
test 'should create video' do | ||
attributes = attributes_for :video | ||
post :create, video: attributes | ||
assert_response :redirect, @response.body | ||
assert_redirected_to admin_videos_path | ||
video = Content::Video.last | ||
video.attributes.keys.except(*@exceptions_attributes).each do |key| | ||
assert_equal attributes[key.to_sym], video.send(key), key | ||
end | ||
end | ||
|
||
test 'should get edit' do | ||
get :edit, id: @video | ||
assert_response :success, @response.body | ||
end | ||
|
||
test 'should patch update' do | ||
attributes = attributes_for :video | ||
patch :update, video: attributes, id: @video | ||
assert_response :redirect, @response.body | ||
assert_redirected_to edit_admin_video_path @video | ||
@video.reload | ||
@video.attributes.keys.except(*@exceptions_attributes).each do |key| | ||
assert_equal attributes[key.to_sym], @video.send(key), key | ||
end | ||
end | ||
|
||
test 'should delete destroy' do | ||
delete :destroy, id: @video | ||
@video.reload | ||
assert @video.removed? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FactoryGirl.define do | ||
factory :content_video, class: 'Content::Video' do | ||
title { generate :string } | ||
description { generate :string } | ||
link { generate :url } | ||
author_id { User.last ? User.last.id : create(:user).id } | ||
state { Content::Video.state_machines[:state].states.map(&:name).first.to_s } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'test_helper' | ||
|
||
class Content::VideoTest < ActiveSupport::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
end |