uchi 0.1.8 → 0.2.0
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 +4 -4
- data/app/assets/javascripts/uchi/application.js +384 -317
- data/app/assets/stylesheets/uchi/application.css +8 -0
- data/app/assets/tailwind/uchi.css +5 -0
- data/app/components/uchi/field/base/show.html.erb +1 -0
- data/app/components/uchi/field/base.rb +24 -27
- data/app/components/uchi/field/boolean/index.html.erb +9 -7
- data/app/components/uchi/field/boolean/show.html.erb +9 -7
- data/app/components/uchi/field/file/show.html.erb +1 -1
- data/app/components/uchi/field/file.rb +1 -1
- data/app/components/uchi/field/has_and_belongs_to_many.rb +19 -1
- data/app/components/uchi/field/has_many.rb +20 -0
- data/app/components/uchi/field/id/show.html.erb +1 -1
- data/app/components/uchi/field/image/index.html.erb +1 -1
- data/app/components/uchi/field/image/show.html.erb +2 -2
- data/app/components/uchi/field/image.rb +1 -1
- data/app/components/uchi/field/select/edit.html.erb +1 -0
- data/app/components/uchi/field/select/index.html.erb +1 -0
- data/app/components/uchi/field/select/show.html.erb +1 -0
- data/app/components/uchi/field/select.rb +144 -0
- data/app/components/uchi/field/text.rb +1 -1
- data/app/components/uchi/ui/index/records_table/records_table.html.erb +1 -1
- data/app/controllers/uchi/repository_controller.rb +2 -2
- data/app/views/layouts/uchi/_javascript.html.erb +1 -1
- data/app/views/layouts/uchi/application.html.erb +4 -6
- data/app/views/uchi/has_many/associated_records/index.html.erb +6 -4
- data/app/views/uchi/repository/edit.html.erb +1 -1
- data/app/views/uchi/repository/new.html.erb +1 -1
- data/app/views/uchi/repository/show.html.erb +4 -4
- data/lib/uchi/field/configuration.rb +42 -5
- data/lib/uchi/repository.rb +19 -7
- data/lib/uchi/sort_order.rb +9 -4
- data/lib/uchi/version.rb +1 -1
- metadata +6 -5
- data/app/components/uchi/field/date/show.html.erb +0 -1
- data/app/components/uchi/field/number/show.html.erb +0 -1
- data/app/components/uchi/field/string/show.html.erb +0 -1
- data/app/components/uchi/field/text/show.html.erb +0 -1
data/lib/uchi/repository.rb
CHANGED
|
@@ -52,9 +52,13 @@ module Uchi
|
|
|
52
52
|
|
|
53
53
|
# Returns an array of fields to show on the edit page.
|
|
54
54
|
#
|
|
55
|
+
# @param record [Object, nil] The record being edited. When provided, fields with a
|
|
56
|
+
# visibility condition are filtered by it. When omitted, all edit fields are returned.
|
|
55
57
|
# @return [Array<Uchi::Field>]
|
|
56
|
-
def fields_for_edit
|
|
57
|
-
fields_for(:edit)
|
|
58
|
+
def fields_for_edit(record: nil)
|
|
59
|
+
return fields_for(:edit) if record.nil?
|
|
60
|
+
|
|
61
|
+
fields_for(:edit).select { |field| field.visible_for?(record) }
|
|
58
62
|
end
|
|
59
63
|
|
|
60
64
|
# Returns an array of fields to show on the index page.
|
|
@@ -66,16 +70,24 @@ module Uchi
|
|
|
66
70
|
|
|
67
71
|
# Returns an array of fields to show on the new page.
|
|
68
72
|
#
|
|
73
|
+
# @param record [Object, nil] The record being created. When provided, fields with a
|
|
74
|
+
# visibility condition are filtered by it. When omitted, all new fields are returned.
|
|
69
75
|
# @return [Array<Uchi::Field>]
|
|
70
|
-
def fields_for_new
|
|
71
|
-
fields_for(:new)
|
|
76
|
+
def fields_for_new(record: nil)
|
|
77
|
+
return fields_for(:new) if record.nil?
|
|
78
|
+
|
|
79
|
+
fields_for(:new).select { |field| field.visible_for?(record) }
|
|
72
80
|
end
|
|
73
81
|
|
|
74
82
|
# Returns an array of fields to show on the show page.
|
|
75
83
|
#
|
|
84
|
+
# @param record [Object, nil] The record being shown. When provided, fields with a
|
|
85
|
+
# visibility condition are filtered by it. When omitted, all show fields are returned.
|
|
76
86
|
# @return [Array<Uchi::Field>]
|
|
77
|
-
def fields_for_show
|
|
78
|
-
fields_for(:show)
|
|
87
|
+
def fields_for_show(record: nil)
|
|
88
|
+
return fields_for(:show) if record.nil?
|
|
89
|
+
|
|
90
|
+
fields_for(:show).select { |field| field.visible_for?(record) }
|
|
79
91
|
end
|
|
80
92
|
|
|
81
93
|
def find_all(search: nil, scope: model.all, sort_order: default_sort_order)
|
|
@@ -188,7 +200,7 @@ module Uchi
|
|
|
188
200
|
end
|
|
189
201
|
|
|
190
202
|
def apply_sort_order(query, sort_order)
|
|
191
|
-
field_to_sort_by = fields.find { |field| field.name == sort_order.
|
|
203
|
+
field_to_sort_by = fields.find { |field| field.name == sort_order.column }
|
|
192
204
|
return query unless field_to_sort_by
|
|
193
205
|
|
|
194
206
|
if field_to_sort_by.sortable.respond_to?(:call)
|
data/lib/uchi/sort_order.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
module Uchi
|
|
2
|
+
# Encapsulates the sort order selected by a user.
|
|
2
3
|
class SortOrder
|
|
3
|
-
attr_reader :
|
|
4
|
+
attr_reader :column, :direction
|
|
4
5
|
|
|
5
6
|
class << self
|
|
6
7
|
def from_params(params)
|
|
@@ -20,15 +21,19 @@ module Uchi
|
|
|
20
21
|
end
|
|
21
22
|
|
|
22
23
|
def apply(query)
|
|
23
|
-
|
|
24
|
+
if column.respond_to?(:asc)
|
|
25
|
+
query.order(ascending? ? column.asc : column.desc)
|
|
26
|
+
else
|
|
27
|
+
query.order(column => direction)
|
|
28
|
+
end
|
|
24
29
|
end
|
|
25
30
|
|
|
26
31
|
def descending?
|
|
27
32
|
direction == :desc
|
|
28
33
|
end
|
|
29
34
|
|
|
30
|
-
def initialize(
|
|
31
|
-
@
|
|
35
|
+
def initialize(column, direction)
|
|
36
|
+
@column = column.respond_to?(:asc) ? column : column.to_sym
|
|
32
37
|
@direction = direction.to_sym
|
|
33
38
|
end
|
|
34
39
|
end
|
data/lib/uchi/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: uchi
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jakob Skjerning
|
|
@@ -71,6 +71,7 @@ files:
|
|
|
71
71
|
- app/assets/stylesheets/uchi/uchi.css
|
|
72
72
|
- app/assets/tailwind/uchi.css
|
|
73
73
|
- app/components/uchi/field/base.rb
|
|
74
|
+
- app/components/uchi/field/base/show.html.erb
|
|
74
75
|
- app/components/uchi/field/belongs_to.rb
|
|
75
76
|
- app/components/uchi/field/belongs_to/edit.html.erb
|
|
76
77
|
- app/components/uchi/field/belongs_to/index.html.erb
|
|
@@ -86,7 +87,6 @@ files:
|
|
|
86
87
|
- app/components/uchi/field/date.rb
|
|
87
88
|
- app/components/uchi/field/date/edit.html.erb
|
|
88
89
|
- app/components/uchi/field/date/index.html.erb
|
|
89
|
-
- app/components/uchi/field/date/show.html.erb
|
|
90
90
|
- app/components/uchi/field/date_time.rb
|
|
91
91
|
- app/components/uchi/field/date_time/edit.html.erb
|
|
92
92
|
- app/components/uchi/field/date_time/index.html.erb
|
|
@@ -113,15 +113,16 @@ files:
|
|
|
113
113
|
- app/components/uchi/field/number.rb
|
|
114
114
|
- app/components/uchi/field/number/edit.html.erb
|
|
115
115
|
- app/components/uchi/field/number/index.html.erb
|
|
116
|
-
- app/components/uchi/field/
|
|
116
|
+
- app/components/uchi/field/select.rb
|
|
117
|
+
- app/components/uchi/field/select/edit.html.erb
|
|
118
|
+
- app/components/uchi/field/select/index.html.erb
|
|
119
|
+
- app/components/uchi/field/select/show.html.erb
|
|
117
120
|
- app/components/uchi/field/string.rb
|
|
118
121
|
- app/components/uchi/field/string/edit.html.erb
|
|
119
122
|
- app/components/uchi/field/string/index.html.erb
|
|
120
|
-
- app/components/uchi/field/string/show.html.erb
|
|
121
123
|
- app/components/uchi/field/text.rb
|
|
122
124
|
- app/components/uchi/field/text/edit.html.erb
|
|
123
125
|
- app/components/uchi/field/text/index.html.erb
|
|
124
|
-
- app/components/uchi/field/text/show.html.erb
|
|
125
126
|
- app/components/uchi/flowbite/breadcrumb.rb
|
|
126
127
|
- app/components/uchi/flowbite/breadcrumb_home.rb
|
|
127
128
|
- app/components/uchi/flowbite/breadcrumb_item.rb
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<%= field.value(record) %>
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<%= field.value(record) %>
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<%= field.value(record) %>
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<%= field.value(record) %>
|