ezframe 0.0.4 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/README.md +1 -1
  4. data/asset/css/materialize.min.css +13 -0
  5. data/asset/css/style.css +3 -0
  6. data/asset/html/index.html +1 -0
  7. data/{app_template/asset/image/favicon.ico → asset/image/c_e.ico} +0 -0
  8. data/asset/js/ezframe.js +387 -0
  9. data/exe/check_column_yml +64 -0
  10. data/exe/console +2 -2
  11. data/exe/{create_table.rb → create_table} +7 -4
  12. data/exe/dbmigrate +174 -0
  13. data/exe/html2ruby +61 -0
  14. data/ezframe.gemspec +10 -8
  15. data/lib/ezframe.rb +9 -3
  16. data/lib/ezframe/auth.rb +50 -31
  17. data/lib/ezframe/column_set.rb +314 -103
  18. data/lib/ezframe/column_type.rb +456 -99
  19. data/lib/ezframe/config.rb +27 -6
  20. data/lib/ezframe/controller.rb +41 -38
  21. data/lib/ezframe/database.rb +171 -52
  22. data/lib/ezframe/editor_common.rb +74 -0
  23. data/lib/ezframe/email.rb +34 -0
  24. data/lib/ezframe/ezlog.rb +40 -0
  25. data/lib/ezframe/ht.rb +42 -17
  26. data/lib/ezframe/html.rb +47 -31
  27. data/lib/ezframe/japanese_utils.rb +15 -0
  28. data/lib/ezframe/jquery-ui.rb +29 -0
  29. data/lib/ezframe/loader.rb +4 -4
  30. data/lib/ezframe/main_editor.rb +19 -0
  31. data/lib/ezframe/main_page_kit.rb +226 -0
  32. data/lib/ezframe/materialize.rb +10 -14
  33. data/lib/ezframe/message.rb +46 -0
  34. data/lib/ezframe/page_base.rb +59 -71
  35. data/lib/ezframe/route.rb +126 -0
  36. data/lib/ezframe/server.rb +16 -5
  37. data/lib/ezframe/single_page_editor.rb +22 -0
  38. data/lib/ezframe/single_page_kit.rb +199 -0
  39. data/lib/ezframe/sub_editor.rb +25 -0
  40. data/lib/ezframe/sub_page_kit.rb +213 -0
  41. data/lib/ezframe/template.rb +5 -4
  42. data/lib/ezframe/util.rb +45 -23
  43. data/lib/ezframe/version.rb +1 -1
  44. metadata +74 -34
  45. data/.rubocop.yml +0 -44
  46. data/app_template/asset/js/ezframe.js +0 -288
  47. data/app_template/config.ru +0 -10
  48. data/app_template/config/generic.yml +0 -3
  49. data/app_template/config/materialize.yml +0 -5
  50. data/app_template/pages/basic.rb +0 -5
  51. data/exe/setup.rb +0 -15
  52. data/lib/ezframe/editor.rb +0 -188
  53. data/lib/ezframe/model.rb +0 -52
  54. data/lib/ezframe/page_kit.rb +0 -63
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "logger"
4
- require "rack"
5
- require "ezframe"
6
-
7
- use Rack::Session::Pool
8
- use Rack::Static, urls: ["/image", "/js", "/css"], root: "asset"
9
- use Rack::ShowExceptions
10
- run Ezframe::Server
@@ -1,3 +0,0 @@
1
- default_page_class: BasicPages
2
- template_file: base.html
3
- favicon: /image/favicon.ico
@@ -1,5 +0,0 @@
1
- extra_js_list:
2
- - https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js
3
- extra_css_list:
4
- - https://fonts.googleapis.com/icon?family=Material+Icons
5
- - https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css
@@ -1,5 +0,0 @@
1
- class BasicPages < Ezframe::PageBase
2
- def public_default_page
3
- return "<H1>Ezframe is working.</H1>"
4
- end
5
- end
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #coding: utf-8
3
- =begin
4
-
5
- アプリケーションテンプレートの生成
6
-
7
- =end
8
- require "fileutils"
9
-
10
- target_dir = ARGV[0]
11
-
12
- unless File.exist?(target_dir)
13
- Dir.mkdir(target_dir)
14
- end
15
- FileUtils.cp_r("app_template", target_dir)
@@ -1,188 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Ezframe
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 @json
17
- @event = @json[:event] || {}
18
- @target_id = @event[@target]
19
- end
20
- @auth = false
21
- init_vars
22
- end
23
-
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
31
- end
32
- @target.downcase!
33
- @target = @target.to_sym
34
- return @target
35
- end
36
-
37
- def public_login_page
38
- flash_area = ""
39
- mylog "public_login_page: #{@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
- common_page(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}, #{@json}"
55
- warden.authenticate
56
- public_index_page
57
- end
58
-
59
- #--------------------------------------------------------------------------------------------------------
60
- # add new parts
61
- def public_new_page
62
- matrix = @column_set.map do |column|
63
- [column.label, column.form]
64
- end
65
- matrix.push([Ht.button(child: "送信", class: %w[btn], event: "on=click:branch=add_new:url=/#{@target}/new:with=form")])
66
- tb = Ht::Table.new(matrix)
67
- layout = main_layout(left: sidenav, center: Ht.form(child: tb.to_h))
68
- common_page(title: "新規登録", body: Html.convert(Materialize.convert(layout)))
69
- end
70
-
71
- def public_new_post
72
- @column_set.values = @event[:form]
73
- @column_set[:id].value = @target_id = @column_set.save
74
- { redirect: "/#{@target}/detail?id=#{@target_id}" }
75
- end
76
-
77
- #--------------------------------------------------------------------------------------------------------
78
- # index parts
79
- def public_index_page
80
- data_a = @dataset.all
81
- htb = make_index_table(data_a)
82
- layout = index_layout(left: sidenav, center: Ht.form(child: htb))
83
- common_page(title: "データ一覧", body: Html.convert(Materialize.convert(layout)))
84
- end
85
-
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)
100
- end
101
-
102
- alias_method :public_default_page, :public_index_page
103
-
104
- #--------------------------------------------------------------------------------------------------------
105
- # search parts
106
- def public_search_post
107
- mylog "public_search_post: #{@json.inspect}"
108
- word = @event[:form][:word]
109
- 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_page
117
- mylog "pubilc_detail_page: #{@request.params.inspect}"
118
- @target_id ||= @request.params["id"]
119
- data = @column_set.set_from_db(@target_id)
120
- return common_page(title: "no data", body: "no customer data: #{@target_id}") unless data
121
- common_page(title: "データ一覧", body: Html.convert(make_detail_page))
122
- end
123
-
124
- def make_detail_page
125
- layout = main_layout( left: sidenav, center: detail_table )
126
- @request.env['rack.session'][@target] = @target_id
127
- layout[:event] = "on=load:branch=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}: #{@json}"
133
- if @json[:global]
134
- @target_id ||= @json[:global][@target]
135
- end
136
- @column_set.set_from_db(@target_id)
137
- case @event[:branch]
138
- when "update_value"
139
- update_value
140
- end
141
- { inject: "#center-panel", is_html: true, body: Html.convert(Materialize.convert(detail_table)) }
142
- end
143
-
144
- private
145
-
146
- def update_value
147
- form = @event[:form]
148
- @column_set.update(@target_id, form)
149
- end
150
-
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)
160
- end
161
-
162
- def detail_value_part(column)
163
- return Ht.span(class: %w[switch-element], child: [ Ht.span(child: column.view) , edit_button(column)])
164
- end
165
-
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
173
- end
174
-
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"))
178
- end
179
-
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"))
182
- end
183
-
184
- def edit_cancel_button
185
- Ht.span(class: %w[btn red small waves-effect waves-light switch-button], child: Ht.icon("clear"))
186
- end
187
- end
188
- end
@@ -1,52 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Ezframe
4
- class Model
5
- class << self
6
-
7
- def init_column_sets
8
- @base_column_sets = ColumnSets.new
9
- @base_column_sets.load_files('./columns')
10
- end
11
-
12
- def init_db
13
- @base_db = Database.new
14
- end
15
-
16
- def init
17
- unless @base_column_sets
18
- init_column_sets
19
- init_db
20
- end
21
- end
22
-
23
- def get_clone
24
- new(@base_column_sets.deep_dup, @base_db)
25
- end
26
- end
27
-
28
- attr_accessor :column_sets, :db
29
-
30
- def initialize(column_sets, db)
31
- @column_sets, @db = column_sets, db
32
- @column_sets.model = self
33
- # @column_sets.each {|name, colset| colset.model = self }
34
- end
35
-
36
- def create_tables
37
- @column_sets.tables.each do |table_name, column_set|
38
- begin
39
- create_one_table(table_name, column_set)
40
- rescue => e
41
- mylog("*** #{e.inspect}\n#{$@.inspect}")
42
- end
43
- end
44
- end
45
-
46
- def create_one_table(table_name, column_set)
47
- col_h = column_set.get_hash(:db_type)
48
- mylog "create_one_table: col_h=#{col_h.inspect}"
49
- @db.create_table(table_name, col_h)
50
- end
51
- end
52
- end
@@ -1,63 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Ezframe
4
- module PageKit
5
- class IndexTable
6
- def initialize(attr = {})
7
- @attribute = attr
8
- end
9
-
10
- def make_table(row_a)
11
- column_set = @attribute[:column_set]
12
- table_a = row_a.map do |row_h|
13
- column_set.values = row_h
14
- id = column_set[:id].value
15
- value_a = (@attribute[:column_header]||[]).map do |key|
16
- col = column_set[key]
17
- unless col
18
- mylog "undefined key: #{key}"
19
- next
20
- end
21
- checkbox_key = @attribute[:add_checkbox]
22
- if checkbox_key && key == checkbox_key
23
- text = add_checkbox(col)
24
- else
25
- text = col.view
26
- end
27
- deco = @attribute[:decorate_column]
28
- if deco
29
- text = deco.call(key, id, text)
30
- # mylog "deco: #{text}"
31
- end
32
- Ht.td(child: text)
33
- end
34
- tr = Ht.tr(child: value_a)
35
- if @attribute[:onclick_rows]
36
- tr[:id] = elem_id = "tr_#{id}"
37
- end
38
- tr
39
- end
40
- Ht.table(child: [make_header, table_a])
41
- end
42
-
43
- def add_checkbox(col)
44
- Ht.checkbox(name: "checkbox_#{col.key}_#{col.value}", value: col.value, label: col.view)
45
- end
46
-
47
- def make_header
48
- column_set = @attribute[:column_set]
49
- th_a = (@attribute[:column_header]||[]).map do |key|
50
- col = column_set[key]
51
- if col
52
- Ht.th(child: col.label)
53
- else
54
- nil
55
- end
56
- end
57
- if @attribute[:add_checkbox]
58
- end
59
- Ht.tr(child: th_a)
60
- end
61
- end
62
- end
63
- end