enju_search_log 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,17 +6,17 @@ class SearchHistoriesController < ApplicationController
6
6
  # GET /search_histories.json
7
7
  def index
8
8
  if params[:mode] == 'not_found'
9
- if current_user.has_role?('Administrator')
10
- @search_histories = SearchHistory.not_found.order('created_at DESC').page(params[:page])
11
- else
9
+ #if current_user.has_role?('Administrator')
10
+ # @search_histories = SearchHistory.not_found.order('created_at DESC').page(params[:page])
11
+ #else
12
12
  @search_histories = current_user.search_histories.not_found.order('created_at DESC').page(params[:page])
13
- end
13
+ #end
14
14
  else
15
- if current_user.has_role?('Administrator')
16
- @search_histories = SearchHistory.order('created_at DESC').page(params[:page])
17
- else
15
+ #if current_user.has_role?('Administrator')
16
+ # @search_histories = SearchHistory.order('created_at DESC').page(params[:page])
17
+ #else
18
18
  @search_histories = current_user.search_histories.order('created_at DESC').page(params[:page])
19
- end
19
+ #end
20
20
  end
21
21
 
22
22
  respond_to do |format|
@@ -44,4 +44,13 @@ class SearchHistoriesController < ApplicationController
44
44
  format.json { head :no_content }
45
45
  end
46
46
  end
47
+
48
+ def remove_all
49
+ SearchHistory.remove_all_history(current_user)
50
+
51
+ respond_to do |format|
52
+ format.html { redirect_to search_histories_url, :notice => t('controller.successfully_deleted', :model => t('activerecord.models.search_history')) }
53
+ format.json { head :no_content }
54
+ end
55
+ end
47
56
  end
@@ -16,6 +16,10 @@ class SearchHistory < ActiveRecord::Base
16
16
  def self.not_found_query(number, duration = 1.year.ago)
17
17
  self.not_found.where('created_at > ?', duration).all.collect(&:query).inject(Hash.new(0)){|r,e|r[e]+=1;r}.to_a.collect{|q| q if q[1] >= number.to_i}.compact
18
18
  end
19
+
20
+ def self.remove_all_history(user)
21
+ user.search_histories.update_all(:user_id => nil)
22
+ end
19
23
  end
20
24
 
21
25
  # == Schema Information
@@ -41,7 +41,7 @@
41
41
  </td>
42
42
  <td>
43
43
  <%- if can? :destroy, search_history -%>
44
- <%= link_to t('page.destroy'), search_history, :confirm => t('page.are_you_sure'), :method => :delete -%>
44
+ <%= link_to t('page.destroy'), search_history, :data => {:confirm => t('page.are_you_sure')}, :method => :delete -%>
45
45
  <%- end -%>
46
46
  </td>
47
47
  </tr>
@@ -53,4 +53,7 @@
53
53
  </div>
54
54
 
55
55
  <div id="submenu" class="ui-corner-all">
56
+ <ul>
57
+ <li><%= link_to t('search_history.remove_all_history'), remove_all_search_histories_path, :method => :put, :data => {:confirm => t('page.are_you_sure')} %></li>
58
+ </ul>
56
59
  </div>
@@ -29,3 +29,4 @@ en:
29
29
  all_history: "All search history"
30
30
  failed_search: "Failed searches"
31
31
  searched_at: "Searched at"
32
+ remove_all_history: "Remove all search history"
@@ -29,3 +29,4 @@ ja:
29
29
  all_history: "全ての検索履歴"
30
30
  failed_search: "失敗した検索"
31
31
  searched_at: "検索時刻"
32
+ remove_all_history: "すべての検索履歴を削除"
data/config/routes.rb CHANGED
@@ -1,3 +1,5 @@
1
1
  Rails.application.routes.draw do
2
- resources :search_histories, :only => [:index, :show, :destroy]
2
+ resources :search_histories, :only => [:index, :show, :destroy] do
3
+ put :remove_all, :on => :collection
4
+ end
3
5
  end
@@ -7,12 +7,17 @@ module EnjuSearchLog
7
7
  if configatron.write_search_log_to_file
8
8
  write_search_log(query, total, user)
9
9
  else
10
- history = SearchHistory.create(:query => query, :user => user, :start_record => offset + 1, :maximum_records => nil, :number_of_records => total)
10
+ history = SearchHistory.new(:query => query, :start_record => offset + 1, :maximum_records => nil, :number_of_records => total)
11
+ history.user = user
12
+ history.save
11
13
  end
12
14
  end
13
15
 
14
16
  def write_search_log(query, total, user)
15
- SEARCH_LOGGER.info "#{Time.zone.now}\t#{query}\t#{total}\t#{user.try(:username)}\t#{params[:format]}"
17
+ if user
18
+ username = user.username if user.save_search_history
19
+ end
20
+ SEARCH_LOGGER.info "#{Time.zone.now}\t#{query}\t#{total}\t#{username}\t#{params[:format]}"
16
21
  end
17
22
  end
18
23
 
@@ -1,3 +1,3 @@
1
1
  module EnjuSearchLog
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
Binary file
@@ -2,8 +2,16 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe SearchHistory do
5
- #pending "add some examples to (or delete) #{__FILE__}"
5
+ fixtures :all
6
6
 
7
+ it "should destroy all history" do
8
+ user = users(:admin)
9
+ old_count = SearchHistory.count
10
+ old_user_count = user.search_histories.count
11
+ SearchHistory.remove_all_history(user)
12
+ user.search_histories.count.should eq 0
13
+ SearchHistory.count.should eq old_count
14
+ end
7
15
  end
8
16
 
9
17
  # == Schema Information
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enju_search_log
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-22 00:00:00.000000000 Z
12
+ date: 2012-06-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -182,7 +182,6 @@ files:
182
182
  - spec/dummy/config/locales/en.yml
183
183
  - spec/dummy/config/routes.rb
184
184
  - spec/dummy/config.ru
185
- - spec/dummy/db/development.sqlite3
186
185
  - spec/dummy/db/migrate/20111201121844_create_roles.rb
187
186
  - spec/dummy/db/migrate/20111201155456_create_users.rb
188
187
  - spec/dummy/db/migrate/20111201155513_add_devise_to_users.rb
@@ -259,7 +258,6 @@ test_files:
259
258
  - spec/dummy/config/locales/en.yml
260
259
  - spec/dummy/config/routes.rb
261
260
  - spec/dummy/config.ru
262
- - spec/dummy/db/development.sqlite3
263
261
  - spec/dummy/db/migrate/20111201121844_create_roles.rb
264
262
  - spec/dummy/db/migrate/20111201155456_create_users.rb
265
263
  - spec/dummy/db/migrate/20111201155513_add_devise_to_users.rb
File without changes