ezframe 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 +4 -4
- data/lib/ezframe/column_set.rb +5 -0
- data/lib/ezframe/editor.rb +132 -144
- data/lib/ezframe/model.rb +1 -0
- data/lib/ezframe/route.rb +8 -5
- data/lib/ezframe/server.rb +6 -2
- data/lib/ezframe/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ba49d27d45a195d4b177c3d95eccdca2f01a3e9f20cd072ccc56acee5265b59
|
4
|
+
data.tar.gz: a3d7589ff5d0d3c81e405a950c9c57f6ca0110cc9748f6dc5bc254e276d27bb7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ca38e91d91c1e1e30b9175efd9da518da54e6860d8f510173ddfbc2d23e553e52e3189137ef4c807c491740724349991921c58ad8d2749579716a873a8db744
|
7
|
+
data.tar.gz: 847a914cf8c68690be28b40a07903c3d0c47dd8e86dba9d6cbe6e05053cfa454fd0ead717b2267cacab570f96a3583093570cc21647b21c6c00a1bcd7b69f11c
|
data/lib/ezframe/column_set.rb
CHANGED
@@ -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
|
data/lib/ezframe/editor.rb
CHANGED
@@ -2,187 +2,175 @@
|
|
2
2
|
|
3
3
|
module Ezframe
|
4
4
|
class DataEditor < PageBase
|
5
|
-
|
6
|
-
def
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
-
@
|
33
|
-
|
34
|
-
|
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
|
-
#
|
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
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
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
|
-
|
73
|
-
|
74
|
-
|
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
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
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
|
-
|
87
|
-
|
88
|
-
@
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
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
|
-
#
|
95
|
+
# 検索
|
106
96
|
def public_search_post
|
107
97
|
mylog "public_search_post: #{@parsed_body.inspect}"
|
108
|
-
|
98
|
+
sch_keys = @search_keys || @column_set.keys
|
99
|
+
word = @params["word"]
|
109
100
|
pattern = "%#{word}%"
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
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
|
-
|
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
|
-
|
147
|
-
|
148
|
-
@
|
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
|
152
|
-
|
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
|
-
|
163
|
-
|
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
|
-
|
167
|
-
|
168
|
-
form =
|
169
|
-
|
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
|
-
|
176
|
-
|
177
|
-
|
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
|
-
|
181
|
-
|
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
|
-
|
185
|
-
|
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
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
|
71
|
+
return scan_route(class_snake, route_h.deep_dup).reverse
|
72
72
|
end
|
73
73
|
|
74
74
|
# targetに対応する名称のクラスまでの経路を返す
|
75
|
-
def
|
76
|
-
|
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
|
-
|
81
|
+
route_h.each do |k, v|
|
82
|
+
next if k == :class
|
81
83
|
if v.is_a?(Hash)
|
82
|
-
a =
|
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")
|
data/lib/ezframe/server.rb
CHANGED
@@ -2,14 +2,18 @@
|
|
2
2
|
|
3
3
|
module Ezframe
|
4
4
|
class Server
|
5
|
-
def
|
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
|
data/lib/ezframe/version.rb
CHANGED