Skip to content

Commit

Permalink
update history
Browse files Browse the repository at this point in the history
  • Loading branch information
ck3g committed Jul 25, 2012
1 parent dc095e5 commit b53d2a4
Show file tree
Hide file tree
Showing 18 changed files with 179 additions and 29 deletions.
2 changes: 2 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ $(function() {
});

$('.datepicker').datepicker($.datepicker.regional['ru']);

$('.has-tooltip').tooltip();
});
3 changes: 3 additions & 0 deletions app/assets/javascripts/update_histories.js.coffee
Original file line number Diff line number Diff line change
@@ -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/
2 changes: 2 additions & 0 deletions app/assets/stylesheets/custom.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,5 @@ h2.inactive {
display: inline;
}
}

.no-margin { margin: 0px; }
3 changes: 3 additions & 0 deletions app/assets/stylesheets/update_histories.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the update_histories controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
8 changes: 8 additions & 0 deletions app/controllers/update_histories_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class UpdateHistoriesController < ApplicationController
load_and_authorize_resource

def index
@link = Link.find(params[:link_id])
@history = @link.update_histories.order("created_at DESC")
end
end
2 changes: 2 additions & 0 deletions app/helpers/update_histories_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module UpdateHistoriesHelper
end
2 changes: 1 addition & 1 deletion app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def initialize(user)
can [:read], [PaymentMethod, Seller]
can [:manage], Payment
cannot [:moderate, :destroy], Payment
can [:index], [Status, Placement, Seller, SellerOrigin, Category, OurSite]
can [:index], [Status, Placement, Seller, SellerOrigin, Category, OurSite, UpdateHistory]
end
#
# The first argument to `can` is the action you are giving the user permission to do.
Expand Down
25 changes: 20 additions & 5 deletions app/models/link.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class Link < ActiveRecord::Base
# TODO: Обновление параметров с сохранением истории
# TODO: Выбор начальной и конечной даты клендариками или радиобатонами на 3/6/12 месяцев
# TODO: Имейлы продавца. При добавлении оплаты, выбирать имейл этого продавца. Дать возможность добавить имейл сразу. Если такой имел уже существует в базе, нужно вывести список продавцов у кого такой имейл есть. Возможность забанить имейл, забаненый имел не показывать в списке при оплате.
# TODO: Возможность продлить оплату до определенного срока, за основу взять текущие параметры (цену и т.п.)
Expand All @@ -9,21 +8,24 @@ class Link < ActiveRecord::Base
include ActionView::Helpers::DateHelper

belongs_to :user
has_many :payments
has_many :payments, dependent: :destroy
belongs_to :status
belongs_to :placement
belongs_to :our_site
has_one :last_payment, :class_name => "Payment", :conditions => { :moderated => true }, :order => 'payments.id DESC'
has_one :seller, :through => :last_payment
has_many :update_histories, dependent: :destroy

attr_protected :user_id

validates :url, :name, :keyword, :placement_id, :presence => true
validates :page_rank, :numericality => true, :inclusion => { :in => 1..10 }

delegate :name, :to => :placement, :prefix => true
delegate :name, :to => :our_site, :prefix => true
delegate :email, :to => :user, :prefix => true
before_update :update_history

delegate :name, to: :placement, prefix: true, allow_nil: true
delegate :name, to: :our_site, prefix: true, allow_nil: true
delegate :email, to: :user, prefix: true, allow_nil: true

scope :url, proc { |url| where('url LIKE ?', "%#{url}%")}
scope :page_rank, proc { |page_rank| where(:page_rank => page_rank) }
Expand Down Expand Up @@ -89,4 +91,17 @@ def has_unmoderated_payments?
def nil_sign
"-"
end

def update_history
history = self.update_histories.new
history.inactive = inactive
history.keyword = keyword
history.name = name
history.our_site_id = our_site_id
history.page_rank = page_rank
history.placement_id = placement_id
history.status_id = status_id
history.url = url
history.save
end
end
1 change: 1 addition & 0 deletions app/models/our_site.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class OurSite < ActiveRecord::Base
belongs_to :category
has_many :links
has_many :update_histories

attr_accessible :category_id, :name, :access_list_user_ids

Expand Down
1 change: 1 addition & 0 deletions app/models/placement.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class Placement < ActiveRecord::Base
has_many :links, :dependent => :destroy
has_many :update_histories

validates :name, :presence => true
end
1 change: 1 addition & 0 deletions app/models/status.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class Status < ActiveRecord::Base
has_many :links, :dependent => :destroy
has_many :update_histories

validates :name, :presence => true
end
14 changes: 14 additions & 0 deletions app/models/update_history.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class UpdateHistory < ActiveRecord::Base
attr_accessible :inactive, :keyword, :link_id, :name, :our_site_id, :page_rank, :placement_id, :status_id, :url

belongs_to :link
belongs_to :placement
belongs_to :status
belongs_to :our_site

validates :link_id, presence: true

delegate :name, to: :status, prefix: true, allow_nil: true
delegate :name, to: :placement, prefix: true, allow_nil: true
delegate :name, to: :our_site, prefix: true, allow_nil: true
end
29 changes: 18 additions & 11 deletions app/views/links/index.haml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
%p
= link_to t("views.application.new"), new_link_path, :class => "btn"
= link_to t("views.application.new"), new_link_path, class: "btn"

- if can? :check, Link
= link_to t("views.links.check"), check_links_path, :class => "btn"
= link_to t("views.links.check"), check_links_path, class: "btn"

- if params[:inactive].blank?
= link_to t("views.links.show_inactive"), links_path(:inactive => true), :class => "btn btn-info"
= link_to t("views.links.show_inactive"), links_path(inactive: true), class: "btn btn-info"
- else
= link_to t("views.links.hide_inactive"), links_path, :class => "btn btn-info"
= link_to "#filter-modal", :class => "btn", :"data-toggle" => "modal" do
= link_to t("views.links.hide_inactive"), links_path, class: "btn btn-info"
= link_to "#filter-modal", class: "btn", :"data-toggle" => "modal" do
%i.icon-search
= t("views.links.filter")

Expand All @@ -32,7 +32,7 @@
%th.actions= t("views.application.actions")
%tbody
- @links.each do |link|
%tr{:class => ("inactive" if link.inactive?)}
%tr{class: ("inactive" if link.inactive?)}
%td= link.url
%td= link.page_rank
%td= link.placement_name
Expand All @@ -44,13 +44,20 @@
%td= link.status_name
%td
- if current_user.admin? && link.has_unmoderated_payments?
%span.badge.badge-warning{:title => t(:unmoderated_payments_count)}
%span.badge.badge-warning{title: t(:unmoderated_payments_count)}
= link.unmoderated_payments_count
%td.actions
= link_to t("views.links.payments"), link_payments_path(link.id), :class => "btn"
= link_to t("views.application.show"), link_path(link.id), :class => "btn"
= link_to t("views.application.edit"), edit_link_path(link.id), :class => "btn"
= link_to t("views.application.destroy"), link, :confirm => t("views.application.are_you_sure"), :method => :delete, :class => "btn btn-danger"
.btn-toolbar.no-margin
.btn-group
= link_to t("views.links.payments"), link_payments_path(link.id), class: "btn has-tooltip", title: t("views.links.payments")
- if can? :index, UpdateHistory
= link_to t(:history), link_update_histories_path(link), class: "btn has-tooltip", title: t(:history)
= link_to link_path(link.id), class: "btn has-tooltip", title: t("views.application.show") do
%i.icon-eye-open
= link_to edit_link_path(link.id), class: "btn has-tooltip", title: t("views.application.edit") do
%i.icon-edit
= link_to link, data: { confirm: t("views.application.are_you_sure") }, method: :delete, class: "btn btn-danger has-tooltip", title: t("views.application.destroy") do
%i.icon-trash.icon-white
- else
%p
- if params[:filter].present?
Expand Down
42 changes: 42 additions & 0 deletions app/views/update_histories/index.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
%h1= title t(:history_for, :link => @link.url)

- if @history.present?
%table.table.table-striped
%thead
%tr
%th
%span.has-tooltip{title: @link.url}
= UpdateHistory.human_attribute_name(:url)
%th
%span.has-tooltip{title: @link.page_rank}
= UpdateHistory.human_attribute_name(:page_rank)
%th
%span.has-tooltip{title: @link.name}
= UpdateHistory.human_attribute_name(:name)
%th
%span.has-tooltip{title: @link.placement_name}
= UpdateHistory.human_attribute_name(:placement)
%th
%span.has-tooltip{title: @link.keyword}
= UpdateHistory.human_attribute_name(:keyword)
%th
%span.has-tooltip{title: @link.status_name}
= UpdateHistory.human_attribute_name(:status)
%th
%span.has-tooltip{title: @link.our_site_name}
= UpdateHistory.human_attribute_name(:our_site)
%th
%span.has-tooltip{title: (@link.inactive? ? t(:inactive_yes) : t(:inactive_no))}
= UpdateHistory.human_attribute_name(:inactive)
%tbody
- @history.each do |history|
%tr
%td= history.url
%td= history.page_rank
%td= history.name
%td= history.placement_name
%td= history.keyword
%td= history.status_name
%td= history.our_site_name
%td= history.inactive? ? t(:inactive_yes) : t(:inactive_no)

2 changes: 2 additions & 0 deletions config/locales/ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,6 @@ ru:
change_password_hint: Оставить поле пустым во избежание смены пароля
visible_for_users: Виден для пользователей
arrow:
history: История
history_for: История для %{link}

27 changes: 16 additions & 11 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
LinkManager::Application.routes.draw do
resources :payment_methods, :statuses, :placements, :seller_origins, :categories, :our_sites, :users, :only => [:new, :edit, :create, :update, :destroy, :index]
resources :logs, :only => [:index]
resources :payment_methods, :statuses, :placements,
:seller_origins, :categories, :our_sites, :users,
only: [:new, :edit, :create, :update, :destroy, :index]

resources :logs, only: [:index]

resources :links do
resources :payments do
post :moderate, :on => :member
post :moderate, on: :member
end
get 'check', :on => :collection
post 'check', :on => :collection
get 'check', on: :collection
post 'check', on: :collection

resources :update_histories, only: :index
end

resources :sellers do
resources :comments, :only => [:create]
resources :comments, only: [:create]
end

devise_for :users do
get "/users/sign_out" => "devise/sessions#destroy", :as => :destroy_user_session
get "/users/sign_out" => "devise/sessions#destroy", as: :destroy_user_session
end

# The priority is based upon order of creation:
Expand All @@ -26,8 +31,8 @@
# Keep in mind you can assign values other than :controller and :action

# Sample of named route:
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
# This route can be invoked with purchase_url(:id => product.id)
# match 'products/:id/purchase' => 'catalog#purchase', as: :purchase
# This route can be invoked with purchase_url(id: product.id)

# Sample resource route (maps HTTP verbs to controller actions automatically):
# resources :products
Expand All @@ -54,7 +59,7 @@
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', :on => :collection
# get 'recent', on: :collection
# end
# end

Expand All @@ -67,7 +72,7 @@

# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
root :to => 'links#index'
root to: 'links#index'

# See how all your routes lay out with "rake routes"

Expand Down
22 changes: 22 additions & 0 deletions db/migrate/20120725060628_create_update_histories.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class CreateUpdateHistories < ActiveRecord::Migration
def change
create_table :update_histories do |t|
t.integer :link_id
t.string :url
t.string :name
t.integer :page_rank
t.string :keyword
t.integer :status_id
t.integer :placement_id
t.integer :our_site_id
t.boolean :inactive

t.timestamps
end
add_index :update_histories, :link_id
add_index :update_histories, :status_id
add_index :update_histories, :placement_id
add_index :update_histories, :our_site_id
add_index :update_histories, :inactive
end
end
22 changes: 21 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20120701113419) do
ActiveRecord::Schema.define(:version => 20120725060628) do

create_table "access_list_users_our_sites", :id => false, :force => true do |t|
t.integer "user_id"
Expand Down Expand Up @@ -171,6 +171,26 @@
t.datetime "updated_at"
end

create_table "update_histories", :force => true do |t|
t.integer "link_id"
t.string "url"
t.string "name"
t.integer "page_rank"
t.string "keyword"
t.integer "status_id"
t.integer "placement_id"
t.integer "our_site_id"
t.boolean "inactive"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end

add_index "update_histories", ["inactive"], :name => "index_update_histories_on_inactive"
add_index "update_histories", ["link_id"], :name => "index_update_histories_on_link_id"
add_index "update_histories", ["our_site_id"], :name => "index_update_histories_on_our_site_id"
add_index "update_histories", ["placement_id"], :name => "index_update_histories_on_placement_id"
add_index "update_histories", ["status_id"], :name => "index_update_histories_on_status_id"

create_table "users", :force => true do |t|
t.string "email", :default => "", :null => false
t.string "encrypted_password", :limit => 128, :default => "", :null => false
Expand Down

0 comments on commit b53d2a4

Please sign in to comment.