ezframe 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b1de1a04055c38786bf34b3500dbea3a3ae46a93a6e4a86fab281cf919b1dac8
4
- data.tar.gz: c9d87fbba6277f9571f027c5e05876a0ab4f6774fdb03a3ddc940671cbcf616d
3
+ metadata.gz: 3ba49d27d45a195d4b177c3d95eccdca2f01a3e9f20cd072ccc56acee5265b59
4
+ data.tar.gz: a3d7589ff5d0d3c81e405a950c9c57f6ca0110cc9748f6dc5bc254e276d27bb7
5
5
  SHA512:
6
- metadata.gz: 7171e4d623c6adb049ca4bc365b33c5828b4f12558a3beec074ad90b2bb9da0aa5176d84c8153b4309cfb68d4b14d4dd5a3f428e68bb24d1c294bdcaf48a0521
7
- data.tar.gz: 529b47101f1aa14eda4605a6bc67329a12deb180e8a84900391d860e7bc5aa23ce27192354aca73199f13acf588513f6fcf0ae0cc0b83879e3a58cedbd0a7ecf
6
+ metadata.gz: 7ca38e91d91c1e1e30b9175efd9da518da54e6860d8f510173ddfbc2d23e553e52e3189137ef4c807c491740724349991921c58ad8d2749579716a873a8db744
7
+ data.tar.gz: 847a914cf8c68690be28b40a07903c3d0c47dd8e86dba9d6cbe6e05053cfa454fd0ead717b2267cacab570f96a3583093570cc21647b21c6c00a1bcd7b69f11c
@@ -60,6 +60,10 @@ module Ezframe
60
60
  end
61
61
  end
62
62
 
63
+ def keys
64
+ @columns.keys
65
+ end
66
+
63
67
  # 配列を初期化する
64
68
  def set(attr_a)
65
69
  @columns[:id] = IdType.new(key: "id", label: "ID", no_edit: true)
@@ -128,6 +132,7 @@ module Ezframe
128
132
  mylog "column_set.updated_values = #{updated_values.inspect}"
129
133
  if updated_values.length > 0
130
134
  updated_values[:updated_at] = Time.now
135
+ puts dataset.where(id: id).update_sql(updated_values)
131
136
  dataset.where(id: id).update(updated_values)
132
137
  end
133
138
  end
@@ -2,187 +2,175 @@
2
2
 
3
3
  module Ezframe
4
4
  class DataEditor < PageBase
5
-
6
- def initialize(request=nil, model=nil)
7
- super(request, model)
8
- decide_target
9
- if model
10
- @column_set = @model.column_sets[@target]
11
- unless @column_set
12
- raise "[ERROR] no such column set: #{@target}"
13
- end
14
- @dataset = @column_set.dataset
15
- end
16
- if @parsed_body
17
- @event = @parsed_body[:event] || {}
18
- @target_id = @event[@target]
5
+ # 一覧ページ生成
6
+ def public_default_get
7
+ id = get_id
8
+ if id
9
+ return show_detail_page
10
+ else
11
+ data_a = @dataset.all
12
+ htb = make_index_table(data_a)
13
+ layout = index_layout(center: Ht.form(child: htb))
14
+ return show_base_template(title: Message[:index_page_title], body: Html.convert(layout))
19
15
  end
20
- @auth = false
21
- init_vars
22
16
  end
23
17
 
24
- def init_vars
25
- end
26
-
27
- def decide_target
28
- @target = self.class.to_s
29
- if @target.index("::")
30
- @target = $1 if /::(\w+)$/ =~ @target
18
+ # 一覧テーブルの生成
19
+ def make_index_table(data_a)
20
+ # @column_set.each { |col| col.attribute.delete(:hidden) }
21
+ idx_keys = @index_keys || @column_set.keys
22
+ puts "idx_keys=#{idx_keys.inspect}"
23
+ a_element = Proc.new { |key, id, text|
24
+ if key.to_s.index("_name")
25
+ Ht.a(href: "#{make_base_url(id)}", child: text)
26
+ else
27
+ text
28
+ end
29
+ }
30
+ tr_a = data_a.map do |data|
31
+ @column_set.clear
32
+ @column_set.values = data
33
+ line = idx_keys.map do |key|
34
+ view = @column_set[key].view
35
+ Ht.td(Ht.a(href: "#{make_base_url(data[:id])}", child: view))
36
+ end
37
+ Ht.tr(line)
31
38
  end
32
- @target.downcase!
33
- @target = @target.to_sym
34
- return @target
39
+ th_a = idx_keys.map {|key| Ht.th(@column_set[key.to_sym].label) }
40
+ thead = Ht.thead(Ht.tr(th_a))
41
+ tbody = Ht.tbody(tr_a)
42
+ table_id = "enable_datatable_#{@class_snake}"
43
+ return Ht.table(id: table_id, class: %w[enable_datatable], child: [ thead, tbody ], event: "on=load:command=enable_datatable:target=##{table_id}:size=10")
35
44
  end
36
45
 
37
- # def public_login_get
38
- # flash_area = ""
39
- # mylog "public_login_get: #{@request}"
40
- # if @request
41
- # mylog "flash=#{@request.env['x-rack.flash']}"
42
- # flash_area = Ht.div(class: %w[teal], child: @request['env']['x-rack.flash'].error)
43
- # end
44
- # form = Ht.multi_div([ %w[container], %w[row]],
45
- # Ht.form(class: "col s6 offset-s3", action: "/#{@target}/login", method: "post", child: [
46
- # Materialize.input(type: "text", name: "account", label: "User ID"),
47
- # Materialize.input(type: "password", name: "password", label: "Password"),
48
- # Ht.button(type: "submit", class: %w[btn], child: "login")
49
- # ]))
50
- # show_base_template(title: "Login", body: Html.convert(Materialize.convert([flash_area, form])))
51
- # end
52
-
53
- # def public_login_post
54
- # mylog "public_login_post: #{@params.inspect}, #{@parsed_body}"
55
- # warden.authenticate
56
- # public_index_get
57
- # end
58
-
59
- #--------------------------------------------------------------------------------------------------------
60
- # add new parts
46
+ # 新規登録フォーム表示
61
47
  def public_create_get
62
- matrix = @column_set.map do |column|
63
- [column.label, column.form]
64
- end
65
- matrix.push([Ht.button(child: Message[:create_finish_button_label], class: %w[btn], event: "on=click:url=/#{@target}/create:with=form")])
66
- tb = Ht::Table.new(matrix)
67
- layout = main_layout(left: sidenav, center: Ht.form(child: tb.to_h))
68
- show_base_template(title: Message[:create_page_title], body: Html.convert(Materialize.convert(layout)))
48
+ @column_set.clear
49
+ table = make_edit_form(:create)
50
+ layout = main_layout(center: Ht.form(child: table), type: 2)
51
+ show_base_template(title: Message[:parent_create_page_title], body: Html.convert(layout))
69
52
  end
70
53
 
54
+ # 新規登録受信
71
55
  def public_create_post
72
- @column_set.values = @event[:form]
73
- @column_set[:id].value = @target_id = @column_set.create
74
- { redirect: "/#{@target}/detail?id=#{@target_id}" }
56
+ unless @event[:form]
57
+ { inject: "#center-panel", body: Ht.form(child: make_edit_form(:create)) }
58
+ else
59
+ # 値の保存
60
+ @column_set.clear
61
+ @column_set.values = @event[:form]
62
+ @column_set[:id].value = id = @column_set.create
63
+ return { redirect: make_base_url(id) }
64
+ end
75
65
  end
76
66
 
77
- #--------------------------------------------------------------------------------------------------------
78
- # index parts
79
- def public_index_get
80
- data_a = @dataset.all
81
- htb = make_index_table(data_a)
82
- layout = index_layout(left: sidenav, center: Ht.form(child: htb))
83
- show_base_template(title: Message[:index_page_title], body: Html.convert(Materialize.convert(layout)))
67
+ # データ編集受信
68
+ def public_edit_post
69
+ id = get_id
70
+ unless @event[:form]
71
+ data = @column_set.set_from_db(id)
72
+ return show_message_page("no data", "data is not defined: #{id}") unless data
73
+ { inject: "#center-panel", body: Html.convert(Ht.form(make_edit_form)) }
74
+ else
75
+ # 値を保存
76
+ @column_set.update(id, @event[:form])
77
+ { redirect: make_base_url(id) }
78
+ end
84
79
  end
85
80
 
86
- def make_index_table(data_a)
87
- column_header = [:id, :name, :email, :zipcode, :prefecture]
88
- @column_set.each { |col| col.attribute.delete(:hidden) }
89
- a_element = Proc.new { |key, id, text|
90
- # mylog "proc executed"
91
- if key == :name
92
- Ht.a(href: "/#{@target}/detail?id=#{id}", child: text)
93
- else
94
- text
95
- end
96
- }
97
- table = PageKit::IndexTable.new(column_header: column_header, column_set: @column_set, add_checkbox: :id,
98
- decorate_column: a_element)
99
- table.make_table(data_a)
81
+ # 編集フォームの生成
82
+ def make_edit_form(command = :edit)
83
+ @id = get_id
84
+ table = []
85
+ matrix = @column_set.map do |column|
86
+ form = column.form
87
+ table.push Ht.p([ Ht.small_text(column.label), form ]) if form
88
+ end
89
+ send_button = Ht.button(child: Message[:edit_finish_button_label], class: %w[btn], event: "on=click:url=#{make_base_url(@id)}/#{command}:with=form")
90
+ table.push(send_button)
91
+ return Ht.table(Ht.tr(table))
100
92
  end
101
93
 
102
- alias_method :public_default_get, :public_index_get
103
-
104
94
  #--------------------------------------------------------------------------------------------------------
105
- # search parts
95
+ # 検索
106
96
  def public_search_post
107
97
  mylog "public_search_post: #{@parsed_body.inspect}"
108
- word = @event[:form][:word]
98
+ sch_keys = @search_keys || @column_set.keys
99
+ word = @params["word"]
109
100
  pattern = "%#{word}%"
110
- data_a = @dataset.where(Sequel.|(Sequel.like(:name_kana, pattern), Sequel.like(:name, pattern))).all
111
- make_index_table(data_a)
112
- end
113
-
114
- #--------------------------------------------------------------------------------------------------------
115
- # detail parts
116
- def public_detail_get
117
- mylog "pubilc_detail_get: #{@request.params.inspect}"
118
- @target_id ||= @request.params["id"]
119
- data = @column_set.set_from_db(@target_id)
120
- return show_base_template(title: "no data", body: "no customer data: #{@target_id}") unless data
121
- show_base_template(title: Message[:index_page_title], body: Html.convert(make_detail_get))
122
- end
123
-
124
- def make_detail_get
125
- layout = main_layout( left: sidenav, center: detail_table )
126
- @request.env['rack.session'][@target] = @target_id
127
- layout[:event] = "on=load:command=set_global@target=#{@target_id}"
128
- Materialize.convert(layout)
129
- end
130
-
131
- def public_detail_post
132
- mylog "public_detail_post: #{@request.params.inspect}: #{@parsed_body}"
133
- if @parsed_body[:global]
134
- @target_id ||= @parsed_body[:global][@target]
135
- end
136
- @column_set.set_from_db(@target_id)
137
- case @event[:branch]
138
- when "update_value"
139
- update_value
101
+ pattern_a = sch_keys.map {|key| Sequel.like(key, pattern) }
102
+ data_a = @dataset.where(Sequel.|(*pattern_a)).all
103
+ puts data_a.inspect
104
+ layout = index_layout(center: make_index_table(data_a))
105
+ show_base_template(title: Message[:search_result_page_title], body: Html.convert(layout))
106
+ end
107
+
108
+ # 詳細表示
109
+ def show_detail_page
110
+ mylog "show_detail_page: #{@request.params.inspect}"
111
+ id = get_id(@class_snake)
112
+ unless @column_set.set_from_db(id)
113
+ return show_message_page("no data", "data is not defined: #{id}")
140
114
  end
141
- { inject: "#center-panel", is_html: true, body: Html.convert(Materialize.convert(detail_table)) }
115
+ layout = main_layout(center: make_detail_table)
116
+ return show_base_template(title: Message[:detail_page_title], body: Html.convert(layout))
142
117
  end
143
118
 
144
119
  private
145
120
 
146
- def update_value
147
- form = @event[:form]
148
- @column_set.update(@target_id, form)
121
+ # 詳細ページの表の生成
122
+ def make_detail_table
123
+ @id = get_id
124
+ table = []
125
+ array = @column_set.map do |column|
126
+ edit_btn = nil
127
+ if @column_edit_mode
128
+ edit_btn = edit_button(column)
129
+ edit_btn[:event] = "on=click:branch=edit_column:key=#{column.key}" if edit_btn
130
+ end
131
+ table.push(Ht.p(class: %w[hover-button-box], child: [ Ht.small_text(column.label), column.view, edit_btn ].compact))
132
+ end
133
+ unless @column_edit_mode
134
+ edit_btn = Ht.button(class: %w[btn], child: [ Ht.icon("edit"), Message[:edit_button_label] ], event: "on=click:url=#{make_base_url(@id)}/edit")
135
+ table.push(edit_btn)
136
+ end
137
+ return Ht.table(Ht.tr(table))
149
138
  end
150
139
 
151
- def detail_table
152
- row_a = @column_set.map do |column|
153
- # column.attribute.delete(:hidden) # Todo: remove this
154
- Ht.tr(class: %w[hover-button-box], child: [
155
- Ht.td(child: column.label),
156
- Ht.td(child: Ht.div(class: %w[switch-box], child: [ detail_value_part(column), detail_form_part(column)].compact))
157
- ])
158
- end
159
- return Ht.table(child: row_a)
140
+ def edit_cancel_button
141
+ Ht.span(class: %w[btn red small waves-effect waves-light switch-button], child: Ht.icon("cancel"))
160
142
  end
161
143
 
162
- def detail_value_part(column)
163
- return Ht.span(class: %w[switch-element], child: [ Ht.span(child: column.view) , edit_button(column)])
144
+ # URLからのIDの取得
145
+ def get_id(class_name = nil)
146
+ class_name ||= @class_snake
147
+ params = @request.env['url_params']
148
+ return nil unless params
149
+ # mylog "get_id: #{params.inspect}, #{class_name}"
150
+ return params[class_name.to_sym]
164
151
  end
165
152
 
166
- def detail_form_part(column)
167
- return nil if column.attribute[:no_edit]
168
- form = column.form
169
- if (form)
170
- form = Ht.form(class: %w[switch-element hide], child: [ Ht.span(child: column.form) , edit_ok_button(column), edit_cancel_button ])
171
- end
172
- return form
153
+ # 値の更新
154
+ def update_value
155
+ form = @event[:form]
156
+ @column_set.update(get_id, form)
173
157
  end
174
158
 
175
- def edit_button(column)
176
- return nil if column.attribute[:no_edit]
177
- return Ht.button(class: %w[btn-floating switch-button hover-button hide right], child: Ht.icon("edit"))
159
+ # ラベル付きで1カラムのviewを表示
160
+ def show_label_view(key)
161
+ col = @column_set[key]
162
+ Ht.span([Ht.small_text(col.label), col.view(force: true)])
178
163
  end
179
164
 
180
- def edit_ok_button(column)
181
- return Ht.span(class: %w[btn small teal waves-effect waves-light], event: "on=click:branch=update_value:url=/#{@target}/detail:key=#{column.key}:with=form", child: Ht.icon("check"))
165
+ # ラベル付きで1カラムのformを表示
166
+ def show_label_edit(key)
167
+ col = @column_set[key]
168
+ Ht.span([Ht.small_text(col.label), col.form(force: true)])
182
169
  end
183
170
 
184
- def edit_cancel_button
185
- Ht.span(class: %w[btn red small waves-effect waves-light switch-button], child: Ht.icon("clear"))
171
+ # エラーページの表示
172
+ def show_message_page(title, body)
173
+ return show_base_template(title: title, body: Html.convert(body))
186
174
  end
187
175
  end
188
176
  end
data/lib/ezframe/model.rb CHANGED
@@ -21,6 +21,7 @@ module Ezframe
21
21
  end
22
22
 
23
23
  def get_clone
24
+
24
25
  new(@base_column_sets.deep_dup, @base_db)
25
26
  end
26
27
  end
data/lib/ezframe/route.rb CHANGED
@@ -68,18 +68,20 @@ module Ezframe
68
68
  def get_path(class_snake, route_h = nil)
69
69
  route_h = Config[:route] unless route_h
70
70
  @get_path_found_it = nil
71
- return scan_hash(class_snake, route_h.deep_dup).reverse
71
+ return scan_route(class_snake, route_h.deep_dup).reverse
72
72
  end
73
73
 
74
74
  # targetに対応する名称のクラスまでの経路を返す
75
- def scan_hash(target, hash)
76
- if hash.keys.include?(target)
75
+ def scan_route(target, route_h)
76
+ # puts "scan_route: target=#{target}, route_h=#{route_h}"
77
+ if route_h.keys.include?(target.to_sym)
77
78
  @get_path_found_it = true
78
79
  return [ target ]
79
80
  else
80
- hash.each do |k, v|
81
+ route_h.each do |k, v|
82
+ next if k == :class
81
83
  if v.is_a?(Hash)
82
- a = scan_hash(target, v)
84
+ a = scan_route(target, v)
83
85
  if @get_path_found_it
84
86
  a.push(k)
85
87
  return a
@@ -87,6 +89,7 @@ module Ezframe
87
89
  end
88
90
  end
89
91
  end
92
+ return nil
90
93
  end
91
94
 
92
95
  def make_method_name(base_name, method = "get")
@@ -2,14 +2,18 @@
2
2
 
3
3
  module Ezframe
4
4
  class Server
5
- def self.call(env)
5
+ def initialize
6
+ Controller.init
7
+ end
8
+
9
+ def call(env)
6
10
  req = Rack::Request.new(env)
7
11
  res = Rack::Response.new
8
12
  Controller.exec(req, res)
9
13
  if res.body.empty?
10
14
  raise "no body in response"
11
15
  end
12
- res.finish
16
+ return res.finish
13
17
  end
14
18
  end
15
19
  end
@@ -1,3 +1,3 @@
1
1
  module Ezframe
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ezframe
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
  - KAMACHI Masayuki