uchi 0.1.7 → 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/belongs_to/edit.html.erb +1 -1
- data/app/components/uchi/field/belongs_to.rb +36 -2
- 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/edit.html.erb +1 -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/flowbite/button.rb +1 -1
- data/app/components/uchi/flowbite/input/field.rb +6 -0
- data/app/components/uchi/flowbite/input/label.rb +2 -0
- data/app/components/uchi/flowbite/input_field.rb +11 -1
- data/app/components/uchi/flowbite/styles.rb +34 -0
- data/app/components/uchi/ui/actions/dropdown/dropdown.html.erb +1 -1
- data/app/components/uchi/ui/index/records_table/records_table.html.erb +1 -1
- data/app/controllers/uchi/repository_controller.rb +24 -8
- 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 +2 -2
- data/app/views/uchi/repository/show.html.erb +4 -4
- data/lib/uchi/field/configuration.rb +43 -6
- data/lib/uchi/field.rb +11 -0
- data/lib/uchi/plugins.rb +21 -0
- data/lib/uchi/repository/routes.rb +9 -5
- data/lib/uchi/repository.rb +45 -6
- data/lib/uchi/routes.rb +27 -5
- data/lib/uchi/sort_order.rb +9 -4
- data/lib/uchi/version.rb +1 -1
- data/lib/uchi.rb +5 -0
- metadata +8 -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
|
@@ -9,7 +9,7 @@ module Uchi
|
|
|
9
9
|
before_action :set_repository
|
|
10
10
|
|
|
11
11
|
def create
|
|
12
|
-
@record =
|
|
12
|
+
@record = build_record_for_new
|
|
13
13
|
if @record.save
|
|
14
14
|
flash[:success] = @repository.translate.successful_create
|
|
15
15
|
redirect_to(@repository.routes.path_for(:show, id: @record.id), status: :see_other)
|
|
@@ -54,7 +54,7 @@ module Uchi
|
|
|
54
54
|
end
|
|
55
55
|
|
|
56
56
|
def new
|
|
57
|
-
@record =
|
|
57
|
+
@record = build_record_for_new
|
|
58
58
|
end
|
|
59
59
|
|
|
60
60
|
def show
|
|
@@ -63,7 +63,7 @@ module Uchi
|
|
|
63
63
|
|
|
64
64
|
def update
|
|
65
65
|
@record = find_record
|
|
66
|
-
if @record.update(
|
|
66
|
+
if @record.update(record_params_for_update)
|
|
67
67
|
flash[:success] = @repository.translate.successful_update
|
|
68
68
|
redirect_to(@repository.routes.path_for(:show, id: @record.id, uniq: rand), status: :see_other)
|
|
69
69
|
else
|
|
@@ -73,8 +73,8 @@ module Uchi
|
|
|
73
73
|
|
|
74
74
|
private
|
|
75
75
|
|
|
76
|
-
def
|
|
77
|
-
@repository.build(
|
|
76
|
+
def build_record_for_new
|
|
77
|
+
@repository.build(record_params_for_new)
|
|
78
78
|
end
|
|
79
79
|
|
|
80
80
|
# Returns the path to use for the cancel link
|
|
@@ -128,10 +128,26 @@ module Uchi
|
|
|
128
128
|
25
|
|
129
129
|
end
|
|
130
130
|
|
|
131
|
-
def
|
|
132
|
-
|
|
131
|
+
def permitted_params_for_edit
|
|
132
|
+
@repository.fields_for_edit(record: @record).map(&:permitted_param)
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def permitted_params_for_new
|
|
136
|
+
@repository.fields_for_new(record: @record || @repository.build).map(&:permitted_param)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def record_params_for_edit
|
|
140
|
+
(params[@repository.model_param_key] || ActionController::Parameters.new)
|
|
141
|
+
.permit(*permitted_params_for_edit)
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def record_params_for_update
|
|
145
|
+
record_params_for_edit
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def record_params_for_new
|
|
133
149
|
(params[@repository.model_param_key] || ActionController::Parameters.new)
|
|
134
|
-
.permit(*
|
|
150
|
+
.permit(*permitted_params_for_new)
|
|
135
151
|
end
|
|
136
152
|
|
|
137
153
|
# Returns the repository class associated with this controller.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
<%= javascript_include_tag "uchi/application", "data-turbo-track": "reload" %>
|
|
1
|
+
<%= javascript_include_tag "uchi/application", "data-turbo-track": "reload", nonce: true %>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<!DOCTYPE html>
|
|
2
2
|
|
|
3
|
-
<html
|
|
3
|
+
<html lang="en">
|
|
4
4
|
<head>
|
|
5
5
|
<title>
|
|
6
6
|
<%= content_for?(:page_title) ? yield(:page_title) : "Uchi" %>
|
|
@@ -15,12 +15,10 @@
|
|
|
15
15
|
<%= render "layouts/uchi/stylesheets" %>
|
|
16
16
|
</head>
|
|
17
17
|
|
|
18
|
-
<body class="antialiased bg-neutral-secondary-medium h-
|
|
19
|
-
|
|
20
|
-
<%= render(partial: "uchi/navigation/main") %>
|
|
18
|
+
<body class="antialiased bg-neutral-secondary-medium p-2 h-screen overflow-hidden md:flex md:p-0">
|
|
19
|
+
<%= render(partial: "uchi/navigation/main") %>
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
</div>
|
|
21
|
+
<main class="py-6 overflow-x-hidden grow md:px-6"><%= yield %></main>
|
|
24
22
|
|
|
25
23
|
<%= render "layouts/uchi/flash_messages" %>
|
|
26
24
|
</body>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<ul class="p-4
|
|
1
|
+
<ul class="p-4 space-y-4 text-sm font-medium text-body">
|
|
2
2
|
<% @records.each do |record| %>
|
|
3
3
|
<%
|
|
4
4
|
checkbox_id = dom_id(record, [source_repository.model, @field_name, 'checkbox'].join("-"))
|
|
@@ -12,12 +12,14 @@
|
|
|
12
12
|
<input
|
|
13
13
|
type="checkbox"
|
|
14
14
|
id="<%= checkbox_id %>"
|
|
15
|
-
class="w-4 h-4 border border-default-strong rounded-xs bg-neutral-secondary-strong focus:ring-2 focus:ring-brand-soft
|
|
15
|
+
class="w-4 h-4 border cursor-pointer border-default-strong rounded-xs bg-neutral-secondary-strong focus:ring-2 focus:ring-brand-soft"
|
|
16
16
|
data-action="change->has-many#handleCheckboxChange"
|
|
17
17
|
data-has-many-target="checkbox"
|
|
18
|
-
|
|
18
|
+
<% if @current_values.include?(record) %>
|
|
19
|
+
checked
|
|
20
|
+
<% end %>
|
|
19
21
|
>
|
|
20
|
-
<label for="<%= checkbox_id %>" class="
|
|
22
|
+
<label for="<%= checkbox_id %>" class="text-sm font-medium cursor-pointer ms-2 text-heading">
|
|
21
23
|
<%= record_title(record) %>
|
|
22
24
|
</label>
|
|
23
25
|
</div>
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
<%= render(Uchi::Flowbite::Card.new) do %>
|
|
18
18
|
<%= form_with model: @record, url: @repository.routes.path_for(:update, id: @record.id) do |form| %>
|
|
19
19
|
<div class="space-y-6">
|
|
20
|
-
<% @repository.fields_for_edit.each do |field| %>
|
|
20
|
+
<% @repository.fields_for_edit(record: @record).each do |field| %>
|
|
21
21
|
<div>
|
|
22
22
|
<%= render(
|
|
23
23
|
field.edit_component(
|
|
@@ -15,10 +15,10 @@
|
|
|
15
15
|
<%= render(Uchi::Flowbite::Card.new) do %>
|
|
16
16
|
<%= form_with model: @record, url: @repository.routes.path_for(:create) do |form| %>
|
|
17
17
|
<div class="space-y-6">
|
|
18
|
-
<% @repository.
|
|
18
|
+
<% @repository.fields_for_new(record: @record).each do |field| %>
|
|
19
19
|
<div>
|
|
20
20
|
<%= render(
|
|
21
|
-
field.
|
|
21
|
+
field.new_component(
|
|
22
22
|
form: form,
|
|
23
23
|
repository: @repository,
|
|
24
24
|
label: @repository.translate.field_label(field),
|
|
@@ -39,14 +39,14 @@
|
|
|
39
39
|
]) %>
|
|
40
40
|
<% end %>
|
|
41
41
|
|
|
42
|
+
<% visible_fields = @repository.fields_for_show(record: @record) %>
|
|
43
|
+
|
|
42
44
|
<%= render(Uchi::Ui::Show::AttributeFields.new(
|
|
43
|
-
attribute_fields:
|
|
45
|
+
attribute_fields: visible_fields.select { |field| field.group_as(:show) == :attributes },
|
|
44
46
|
record: @record,
|
|
45
47
|
repository: @repository
|
|
46
48
|
)) %>
|
|
47
49
|
|
|
48
|
-
<%
|
|
49
|
-
|
|
50
|
-
<% association_fields.each do |field| %>
|
|
50
|
+
<% visible_fields.select { |field| field.group_as(:show) == :associations }.each do |field| %>
|
|
51
51
|
<%= render(field.show_component(record: @record, repository: @repository)) %>
|
|
52
52
|
<% end %>
|
|
@@ -6,13 +6,15 @@ module Uchi
|
|
|
6
6
|
class Unset; end
|
|
7
7
|
|
|
8
8
|
DEFAULT_READER = ->(record, field_name) { record&.public_send(field_name) }
|
|
9
|
+
DEFAULT_VISIBLE = ->(_record) { true }
|
|
9
10
|
|
|
10
11
|
def initialize(*args)
|
|
11
12
|
super
|
|
12
13
|
@on = default_on
|
|
13
14
|
@reader = DEFAULT_READER
|
|
14
15
|
@searchable = default_searchable?
|
|
15
|
-
@
|
|
16
|
+
@visible = DEFAULT_VISIBLE
|
|
17
|
+
@sortable = default_sortable
|
|
16
18
|
end
|
|
17
19
|
|
|
18
20
|
# Sets or gets which actions this field should appear on.
|
|
@@ -89,6 +91,32 @@ module Uchi
|
|
|
89
91
|
!!@searchable
|
|
90
92
|
end
|
|
91
93
|
|
|
94
|
+
# Sets or gets a conditional proc that determines whether this field should
|
|
95
|
+
# be visible for a given record.
|
|
96
|
+
#
|
|
97
|
+
# When called with a proc argument, sets the visibility condition and returns
|
|
98
|
+
# self for chaining. When called without arguments, returns the current proc.
|
|
99
|
+
#
|
|
100
|
+
# @param visible_proc [Proc] A callable that receives the record and returns
|
|
101
|
+
# a boolean indicating whether the field should be visible.
|
|
102
|
+
# Raises ArgumentError for non-callables.
|
|
103
|
+
# @return [self, Proc] Returns self for method chaining when setting,
|
|
104
|
+
# or the current proc when getting
|
|
105
|
+
#
|
|
106
|
+
# @example Setting
|
|
107
|
+
# Field::String.new(:id).visible(lambda { |record| record.id.even? })
|
|
108
|
+
#
|
|
109
|
+
# @example Getting
|
|
110
|
+
# field.visible # => #<Proc...>
|
|
111
|
+
def visible(visible_proc = Configuration::Unset)
|
|
112
|
+
return @visible if visible_proc == Configuration::Unset
|
|
113
|
+
|
|
114
|
+
raise ArgumentError, "visible must be callable" unless visible_proc.respond_to?(:call)
|
|
115
|
+
|
|
116
|
+
@visible = visible_proc
|
|
117
|
+
self
|
|
118
|
+
end
|
|
119
|
+
|
|
92
120
|
# Sets or gets whether and how this field is sortable.
|
|
93
121
|
#
|
|
94
122
|
# When called with an argument, sets sortable and returns self for chaining.
|
|
@@ -111,7 +139,7 @@ module Uchi
|
|
|
111
139
|
# @example Getting
|
|
112
140
|
# field.sortable # => true
|
|
113
141
|
def sortable(value = Configuration::Unset)
|
|
114
|
-
return @sortable if value == Configuration::Unset
|
|
142
|
+
return @sortable.nil? ? default_sortable : @sortable if value == Configuration::Unset
|
|
115
143
|
|
|
116
144
|
@sortable = value
|
|
117
145
|
self
|
|
@@ -119,22 +147,31 @@ module Uchi
|
|
|
119
147
|
|
|
120
148
|
# Returns true if the field is sortable
|
|
121
149
|
def sortable?
|
|
122
|
-
|
|
150
|
+
!!sortable
|
|
151
|
+
end
|
|
123
152
|
|
|
124
|
-
|
|
153
|
+
# Returns whether this field should be visible for the given record.
|
|
154
|
+
#
|
|
155
|
+
# Calls the visible proc with the record. Defaults to DEFAULT_VISIBLE,
|
|
156
|
+
# which always returns true.
|
|
157
|
+
#
|
|
158
|
+
# @param record [Object] The record to check visibility for
|
|
159
|
+
# @return [Boolean] Whether the field should be visible
|
|
160
|
+
def visible_for?(record)
|
|
161
|
+
!!@visible.call(record)
|
|
125
162
|
end
|
|
126
163
|
|
|
127
164
|
protected
|
|
128
165
|
|
|
129
166
|
def default_on
|
|
130
|
-
[:edit, :index, :show]
|
|
167
|
+
[:edit, :index, :new, :show]
|
|
131
168
|
end
|
|
132
169
|
|
|
133
170
|
def default_searchable?
|
|
134
171
|
false
|
|
135
172
|
end
|
|
136
173
|
|
|
137
|
-
def default_sortable
|
|
174
|
+
def default_sortable
|
|
138
175
|
true
|
|
139
176
|
end
|
|
140
177
|
end
|
data/lib/uchi/field.rb
CHANGED
|
@@ -51,6 +51,17 @@ module Uchi
|
|
|
51
51
|
@name = name.to_sym
|
|
52
52
|
end
|
|
53
53
|
|
|
54
|
+
def new_component(form:, repository:, label: nil, hint: nil)
|
|
55
|
+
# For now all components use the same component for Edit and New. Override
|
|
56
|
+
# this method in a subclass to provide a different component.
|
|
57
|
+
edit_component(
|
|
58
|
+
form: form,
|
|
59
|
+
hint: hint,
|
|
60
|
+
label: label,
|
|
61
|
+
repository: repository
|
|
62
|
+
)
|
|
63
|
+
end
|
|
64
|
+
|
|
54
65
|
# Returns the key that this field is expected to use in params
|
|
55
66
|
def param_key
|
|
56
67
|
name.to_sym
|
data/lib/uchi/plugins.rb
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Uchi
|
|
2
|
+
class Plugins
|
|
3
|
+
attr_reader :registered
|
|
4
|
+
|
|
5
|
+
def hook(hook_name, **kwargs)
|
|
6
|
+
registered.each do |plugin_class|
|
|
7
|
+
next unless plugin_class.hooks_into?(hook_name)
|
|
8
|
+
|
|
9
|
+
plugin_class.hook(hook_name, **kwargs)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def initialize
|
|
14
|
+
@registered = []
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def register(plugin_class)
|
|
18
|
+
@registered << plugin_class
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -22,7 +22,7 @@ module Uchi
|
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
def root_path
|
|
25
|
-
"/#{
|
|
25
|
+
"/#{uchi_path}/"
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
private
|
|
@@ -34,7 +34,7 @@ module Uchi
|
|
|
34
34
|
|
|
35
35
|
def plural_path_for(_action, **options)
|
|
36
36
|
parts = [
|
|
37
|
-
|
|
37
|
+
uchi_as,
|
|
38
38
|
plural,
|
|
39
39
|
"path"
|
|
40
40
|
].compact
|
|
@@ -47,15 +47,19 @@ module Uchi
|
|
|
47
47
|
action = nil if action == :destroy
|
|
48
48
|
parts = [
|
|
49
49
|
action,
|
|
50
|
-
|
|
50
|
+
uchi_as,
|
|
51
51
|
singular,
|
|
52
52
|
"path"
|
|
53
53
|
].compact
|
|
54
54
|
call_url_helper_in_main_app(parts, **options)
|
|
55
55
|
end
|
|
56
56
|
|
|
57
|
-
def
|
|
58
|
-
|
|
57
|
+
def uchi_as
|
|
58
|
+
Uchi.routes.mount_as
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def uchi_path
|
|
62
|
+
Uchi.routes.mount_at
|
|
59
63
|
end
|
|
60
64
|
end
|
|
61
65
|
end
|
data/lib/uchi/repository.rb
CHANGED
|
@@ -51,18 +51,43 @@ module Uchi
|
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
# Returns an array of fields to show on the edit page.
|
|
54
|
-
|
|
55
|
-
|
|
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.
|
|
57
|
+
# @return [Array<Uchi::Field>]
|
|
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) }
|
|
56
62
|
end
|
|
57
63
|
|
|
58
64
|
# Returns an array of fields to show on the index page.
|
|
65
|
+
#
|
|
66
|
+
# @return [Array<Uchi::Field>]
|
|
59
67
|
def fields_for_index
|
|
60
|
-
|
|
68
|
+
fields_for(:index)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Returns an array of fields to show on the new page.
|
|
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.
|
|
75
|
+
# @return [Array<Uchi::Field>]
|
|
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) }
|
|
61
80
|
end
|
|
62
81
|
|
|
63
82
|
# Returns an array of fields to show on the show page.
|
|
64
|
-
|
|
65
|
-
|
|
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.
|
|
86
|
+
# @return [Array<Uchi::Field>]
|
|
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) }
|
|
66
91
|
end
|
|
67
92
|
|
|
68
93
|
def find_all(search: nil, scope: model.all, sort_order: default_sort_order)
|
|
@@ -175,7 +200,7 @@ module Uchi
|
|
|
175
200
|
end
|
|
176
201
|
|
|
177
202
|
def apply_sort_order(query, sort_order)
|
|
178
|
-
field_to_sort_by = fields.find { |field| field.name == sort_order.
|
|
203
|
+
field_to_sort_by = fields.find { |field| field.name == sort_order.column }
|
|
179
204
|
return query unless field_to_sort_by
|
|
180
205
|
|
|
181
206
|
if field_to_sort_by.sortable.respond_to?(:call)
|
|
@@ -185,6 +210,20 @@ module Uchi
|
|
|
185
210
|
end
|
|
186
211
|
end
|
|
187
212
|
|
|
213
|
+
# Returns an array of fields to show for the given action.
|
|
214
|
+
#
|
|
215
|
+
# @param action [Symbol] The action to get fields for. One of :index, :show,
|
|
216
|
+
# :new, :edit.
|
|
217
|
+
#
|
|
218
|
+
# @return [Array<Uchi::Field>]
|
|
219
|
+
def fields_for(action)
|
|
220
|
+
fields_with_repository.select { |field| field.on.include?(action) }
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
def fields_with_repository
|
|
224
|
+
fields.each { |field| field.repository = self }
|
|
225
|
+
end
|
|
226
|
+
|
|
188
227
|
def searchable_fields
|
|
189
228
|
@searchable_fields ||= fields.select { |field| field.searchable? }
|
|
190
229
|
end
|
data/lib/uchi/routes.rb
CHANGED
|
@@ -7,19 +7,26 @@ module Uchi
|
|
|
7
7
|
# Rails.application.routes.draw do
|
|
8
8
|
# Uchi.routes.mount(self)
|
|
9
9
|
# end
|
|
10
|
+
#
|
|
11
|
+
# @param host_routes [ActionDispatch::Routing::Mapper] The host
|
|
12
|
+
# application's routes mapper.
|
|
13
|
+
#
|
|
14
|
+
# @param at [Symbol] The path segment where Uchi should be mounted.
|
|
10
15
|
def mount(host_routes, at: default_at)
|
|
16
|
+
@mount_at = (at || default_at).to_sym
|
|
11
17
|
host_routes.mount(
|
|
12
18
|
Uchi::Engine,
|
|
13
|
-
|
|
19
|
+
as: mount_as,
|
|
20
|
+
at: mount_at
|
|
14
21
|
)
|
|
15
22
|
|
|
16
|
-
draw_repository_routes(host_routes, at:
|
|
23
|
+
draw_repository_routes(host_routes, at: mount_at)
|
|
17
24
|
end
|
|
18
25
|
|
|
19
26
|
def draw_root_route(routes, repository:, at: default_at)
|
|
20
27
|
return unless repository
|
|
21
28
|
|
|
22
|
-
routes.namespace(at) do
|
|
29
|
+
routes.namespace(at, as: mount_as) do
|
|
23
30
|
routes.root to: "#{repository.controller_name}#index"
|
|
24
31
|
end
|
|
25
32
|
end
|
|
@@ -28,7 +35,7 @@ module Uchi
|
|
|
28
35
|
repositories = Uchi::Repository.all
|
|
29
36
|
repositories.each do |repository_class|
|
|
30
37
|
resources_name = repository_class.controller_name
|
|
31
|
-
routes.namespace(at) do
|
|
38
|
+
routes.namespace(at, as: mount_as) do
|
|
32
39
|
routes.resources(resources_name)
|
|
33
40
|
end
|
|
34
41
|
end
|
|
@@ -36,10 +43,25 @@ module Uchi
|
|
|
36
43
|
draw_root_route(routes, at: at, repository: repositories.first)
|
|
37
44
|
end
|
|
38
45
|
|
|
46
|
+
# Returns the name to use when generating routing helper method names
|
|
47
|
+
def mount_as
|
|
48
|
+
:uchi
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Returns the path prefix for the routes, i.e. the first URL segment where
|
|
52
|
+
# Uchi can be requested.
|
|
53
|
+
def mount_at
|
|
54
|
+
@mount_at ||= default_at
|
|
55
|
+
end
|
|
56
|
+
|
|
39
57
|
private
|
|
40
58
|
|
|
41
59
|
def default_at
|
|
42
|
-
|
|
60
|
+
:uchi
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def mount_path
|
|
64
|
+
mount_at
|
|
43
65
|
end
|
|
44
66
|
end
|
|
45
67
|
end
|
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
data/lib/uchi.rb
CHANGED
|
@@ -11,12 +11,17 @@ require "uchi/action"
|
|
|
11
11
|
require "uchi/action_response"
|
|
12
12
|
require "uchi/field"
|
|
13
13
|
require "uchi/i18n"
|
|
14
|
+
require "uchi/plugins"
|
|
14
15
|
require "uchi/repository"
|
|
15
16
|
require "uchi/routes"
|
|
16
17
|
require "uchi/sort_order"
|
|
17
18
|
require "uchi/repository/translate"
|
|
18
19
|
|
|
19
20
|
module Uchi
|
|
21
|
+
def self.plugins
|
|
22
|
+
@plugins ||= Plugins.new
|
|
23
|
+
end
|
|
24
|
+
|
|
20
25
|
def self.routes
|
|
21
26
|
@routes ||= Routes.new
|
|
22
27
|
end
|
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
|
|
@@ -169,6 +170,7 @@ files:
|
|
|
169
170
|
- app/components/uchi/flowbite/input_field/url.rb
|
|
170
171
|
- app/components/uchi/flowbite/link.rb
|
|
171
172
|
- app/components/uchi/flowbite/style.rb
|
|
173
|
+
- app/components/uchi/flowbite/styles.rb
|
|
172
174
|
- app/components/uchi/flowbite/toast.rb
|
|
173
175
|
- app/components/uchi/flowbite/toast/icon.html.erb
|
|
174
176
|
- app/components/uchi/flowbite/toast/icon.rb
|
|
@@ -262,6 +264,7 @@ files:
|
|
|
262
264
|
- lib/uchi/pagy/toolbox/helpers/page_url.rb
|
|
263
265
|
- lib/uchi/pagy/toolbox/paginators/method.rb
|
|
264
266
|
- lib/uchi/pagy/toolbox/paginators/offset.rb
|
|
267
|
+
- lib/uchi/plugins.rb
|
|
265
268
|
- lib/uchi/repository.rb
|
|
266
269
|
- lib/uchi/repository/routes.rb
|
|
267
270
|
- lib/uchi/repository/translate.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) %>
|