admini 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f106a63ce982fb23ce0995f971014c505943003d
4
- data.tar.gz: 9be87bd739f34f6e6eda1e80914704ba3539a327
3
+ metadata.gz: 2951544c110448fa3e238ec1d2e06df1d3c22ca1
4
+ data.tar.gz: 726e830aa6a0e8b7bcf64f28fe9c78c33830f0be
5
5
  SHA512:
6
- metadata.gz: 781731b8eb9442abf59b0d1f807924f6b2ba02550b202c34b184f150bf5136139775ce20c867ab0e5b962074025b06e4ebe4097be65b0eedb0103a92d9877bbd
7
- data.tar.gz: 03ac9f74110c832abcf6aed47934a8e29a1c70aa7b67c272dd820d7e32f3497b69aabffa0879111c6a1f36f435fe94a33f81e14de216e813b787ef88dc9c1458
6
+ metadata.gz: fe48c9b92753655f75b136593ce5a38cec6b8a6026f130ebbef1f2fecb4be111511e31ecdcbb49cc606d4179dddb6038bc320a126df2a8e8a9ea1c1e166c5d9f
7
+ data.tar.gz: 915b6a16f2266be298a44e5d1fa3ad933bccbdb147a9f0f8e6a5e020c37ecac74fda88f36bb4fbde36d562b78cb3d4ae5a04cb7b2b28ceebb823b10db2ecb2e7
@@ -21,6 +21,17 @@ a {
21
21
  float: right;
22
22
  }
23
23
 
24
+ .clearfix:before {
25
+ display: table;
26
+ content: '';
27
+ }
28
+
29
+ .clearfix:after {
30
+ clear: both;
31
+ display: table;
32
+ content: '';
33
+ }
34
+
24
35
  .header {
25
36
  margin-bottom: 20px;
26
37
  padding-top: 20px;
@@ -73,9 +84,22 @@ textarea {
73
84
  padding: 8px;
74
85
  width: 50%;
75
86
  min-width: 480px;
76
- border: 1px solid #eee;
87
+ border: 1px solid #ddd;
88
+ border-radius: 2px;
89
+ vertical-align: middle;
90
+ }
91
+
92
+ input[type=search] {
93
+ padding: 2px;
94
+ border: 1px solid #ddd;
95
+ border-radius: 2px;
96
+ vertical-align: middle;
77
97
  }
78
98
 
79
99
  textarea {
80
100
  height: 160px;
81
101
  }
102
+
103
+ select {
104
+ vertical-align: middle;
105
+ }
@@ -4,10 +4,13 @@ module Admini
4
4
  module Resources
5
5
  extend ActiveSupport::Concern
6
6
 
7
+ include ActionView::Helpers::FormOptionsHelper
8
+
7
9
  included do
8
10
  before_action :load_resources, only: :index
9
11
  before_action :load_resource, only: [:edit, :update, :show, :destroy]
10
12
  before_action :build_resource, only: [:new, :create]
13
+ before_action :search_resources, only: :index
11
14
  before_action :authorize
12
15
 
13
16
  helper_method :resource_name,
@@ -15,6 +18,7 @@ module Admini
15
18
  :new_attributes,
16
19
  :edit_attributes,
17
20
  :show_attributes,
21
+ :search_attributes,
18
22
  :enum_attributes,
19
23
  :can_create?,
20
24
  :can_read?,
@@ -22,12 +26,16 @@ module Admini
22
26
  :can_delete?,
23
27
  :enable_action?,
24
28
  :render_attribute,
25
- :resource_object
29
+ :resource_object,
30
+ :search_options
26
31
 
27
32
  layout 'admini/layouts/application'
28
33
  end
29
34
 
30
35
  def index
36
+ @resources = @resources.order(id: :desc)
37
+ .page(params[:page])
38
+ .per(paginates_per)
31
39
  end
32
40
 
33
41
  def new
@@ -71,9 +79,7 @@ module Admini
71
79
  end
72
80
 
73
81
  def resources
74
- @resources ||= resource_class.order(id: :desc)
75
- .page(params[:page])
76
- .per(paginates_per)
82
+ @resources ||= resource_class.all
77
83
  end
78
84
  alias_method :load_resources, :resources
79
85
 
@@ -101,6 +107,13 @@ module Admini
101
107
  params.require(resource_name).permit(attributes)
102
108
  end
103
109
 
110
+ def search_resources
111
+ unless search_attributes.include?(params[:attribute].try(:to_sym))
112
+ return
113
+ end
114
+ @resources = @resources.where("#{params[:attribute]} LIKE ?", "%#{params[:value]}%")
115
+ end
116
+
104
117
  def index_attributes
105
118
  %i(id created_at updated_at)
106
119
  end
@@ -117,6 +130,10 @@ module Admini
117
130
  new_attributes
118
131
  end
119
132
 
133
+ def search_attributes
134
+ %i()
135
+ end
136
+
120
137
  def enum_attributes
121
138
  %i()
122
139
  end
@@ -188,6 +205,14 @@ module Admini
188
205
  end
189
206
  end
190
207
 
208
+ def search_options
209
+ options = []
210
+ search_attributes.each do |attribute|
211
+ options << [t("activerecord.attributes.#{resource_name}.#{attribute}"), attribute]
212
+ end
213
+ options_for_select(options)
214
+ end
215
+
191
216
  def paginates_per
192
217
  defined?(super) ? super : 25
193
218
  end
@@ -1,5 +1,5 @@
1
1
  <div class="nav">
2
- <div class="container">
2
+ <div class="container clearfix">
3
3
  <%= render 'admini/shared/links/index' %>
4
4
  <%= render 'admini/shared/links/new' %>
5
5
  <% if action_name.in?(%w(show edit update)) %>
@@ -7,5 +7,8 @@
7
7
  <%= render partial: 'admini/shared/links/edit', locals: { resource: @resource } %>
8
8
  <%= render partial: 'admini/shared/links/delete', locals: { resource: @resource } %>
9
9
  <% end %>
10
+ <div class="right">
11
+ <%= render 'admini/layouts/search' %>
12
+ </div>
10
13
  </div>
11
14
  </div>
@@ -0,0 +1,7 @@
1
+ <% unless search_attributes.blank? %>
2
+ <%= form_tag({ action: :index }, method: :get) do %>
3
+ <%= search_field_tag :value %>
4
+ <%= select_tag :attribute, search_options %>
5
+ <%= submit_tag t('admini.search') %>
6
+ <% end %>
7
+ <% end %>
@@ -11,3 +11,4 @@ en:
11
11
  show: Show
12
12
  delete: Delete
13
13
  confirm: Are you sure?
14
+ search: Search
@@ -11,3 +11,4 @@ ja:
11
11
  show: 表示
12
12
  delete: 削除
13
13
  confirm: 本当によろしいですか?
14
+ search: 検索する
@@ -1,3 +1,3 @@
1
1
  module Admini
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: admini
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - kami
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-29 00:00:00.000000000 Z
11
+ date: 2016-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -97,6 +97,7 @@ files:
97
97
  - app/controllers/concerns/admini/resources.rb
98
98
  - app/views/admini/layouts/_header.html.erb
99
99
  - app/views/admini/layouts/_nav.html.erb
100
+ - app/views/admini/layouts/_search.html.erb
100
101
  - app/views/admini/layouts/application.html.erb
101
102
  - app/views/admini/resources/_form.html.erb
102
103
  - app/views/admini/resources/edit.html.erb