oversee 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 197a8356cd3b94594875d7ef8426abaf4718f3ac42dd35fed5ab8937615dde91
4
- data.tar.gz: 883cfa8fa1e3de33bc6300064b7e801ee666b8d5b4abbea794ed8fa740a26be2
3
+ metadata.gz: eda2b577791e666d84d3b2af260c06604489d84936c8ff907f51573f5441e7e7
4
+ data.tar.gz: 83ca5ac7da8e9b5f66bc19523e2b78875634e669b0acd7e34bad2b2dcb76887d
5
5
  SHA512:
6
- metadata.gz: 7e35bb4c48f9b971cf95e9659f662054fe0917973f87a89d9837027cf99c6e40a9f498fcc2505191e20072ce42e8ac524ce916767fccef03ef28e5fc39785c23
7
- data.tar.gz: 1e371d883dada238d0f9a333db69a67b8ad5fd0e360e5d348fc5b232d844648d8b163b566dd0b0900e0cd7f4206b07b5e254478ae557de93ce22d4c9cbd521e3
6
+ metadata.gz: 0a7fc59d7b8f317e15927ec883017b374f5216aeaa5208bdb29d67f3cbf03dd944e57b7a90e5eac161cde60257276def41ebfa5e34399f3f41db43e47c3e63d8
7
+ data.tar.gz: a441505a216cf3df44dc9a58be3e135a5741564b3b8a51e1e486de08a53dfdfe0f640dcc2126813c1dd3d32d21deb806480f52a03b8deab54a6713af3e33b6ad
@@ -13,8 +13,11 @@ module Oversee
13
13
  # A map for components to use when rendering a form input field
14
14
  INPUT_MAP ={
15
15
  string: Oversee::Fields::Input::StringComponent,
16
+ boolean: Oversee::Fields::Input::StringComponent,
16
17
  integer: Oversee::Fields::Input::IntegerComponent,
17
18
  datetime: Oversee::Fields::Input::DatetimeComponent,
19
+ text: Oversee::Fields::Input::StringComponent,
20
+ enum: Oversee::Fields::Input::StringComponent,
18
21
  }
19
22
 
20
23
  MAP = {
@@ -26,7 +29,7 @@ module Oversee
26
29
  @kind = kind
27
30
  @datatype = VALUE_MAP.key?(datatype) ? datatype : :text
28
31
  @key = key
29
- @value = value
32
+ @value = value || nil
30
33
  end
31
34
 
32
35
  def view_template
@@ -25,7 +25,7 @@ class Oversee::Fields::DisplayRowComponent < Phlex::HTML
25
25
  a(
26
26
  href:
27
27
  (
28
- helpers.input_field_resource_path(
28
+ input_field_path(
29
29
  @resource.id,
30
30
  resource: @resource.class,
31
31
  key: @key
@@ -0,0 +1,26 @@
1
+ module Oversee
2
+ module Fields
3
+ module Input
4
+ class BooleanComponent < Phlex::HTML
5
+ def initialize(key:, value:)
6
+ @key = key
7
+ @value = value
8
+ end
9
+
10
+ def view_template
11
+ input type: "text", id: field_id, name: field_name, value: @value, class: "border rounded-md px-4 py-2 text-sm"
12
+ end
13
+
14
+ private
15
+
16
+ def field_id
17
+ "resource_#{@key.to_s}"
18
+ end
19
+
20
+ def field_name
21
+ "resource[#{@key.to_s}]"
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -8,7 +8,7 @@ module Oversee
8
8
  end
9
9
 
10
10
  def view_template
11
- input type: "text", id: field_id, name: field_name, value: @value, class: "border rounded-md px-4 py-2 text-sm"
11
+ input type: "text", id: field_id, name: field_name, value: @value, class: "border rounded-md px-4 py-2 text-sm w-full"
12
12
  end
13
13
 
14
14
  private
@@ -2,7 +2,7 @@ module Oversee
2
2
  class ResourcesController < BaseController
3
3
  include ActionView::RecordIdentifier
4
4
 
5
- before_action :set_resource_class, except: [:update]
5
+ before_action :set_resource_class, except: [:create, :update]
6
6
  before_action :set_resource, only: %i[show edit destroy]
7
7
 
8
8
  def index
@@ -12,6 +12,23 @@ module Oversee
12
12
  @pagy, @resources = pagy(@resources)
13
13
  end
14
14
 
15
+ def new
16
+ @resource = @resource_class.new
17
+ end
18
+
19
+ def create
20
+ @resource_class = params[:resource_class].constantize
21
+ @resource = @resource_class.new(resource_params)
22
+
23
+ respond_to do |format|
24
+ if @resource.update(resource_params)
25
+ format.html { redirect_to resource_path(@resource.id, resource: @resource_class) }
26
+ format.turbo_stream
27
+ else
28
+ end
29
+ end
30
+ end
31
+
15
32
  def show
16
33
  resource_associations
17
34
  end
@@ -48,11 +65,13 @@ module Oversee
48
65
  @value = @resource.send(@key)
49
66
  @datatype = @resource.class.columns_hash[@key.to_s].type
50
67
 
51
- puts "---"
52
- puts "key: #{@key}"
53
- puts "value: #{@value}"
54
- puts "datatype: #{@datatype}"
55
- puts "---"
68
+ respond_to do |format|
69
+ format.turbo_stream do
70
+ render turbo_stream: [
71
+ turbo_stream.replace(dom_id(@resource, @key), partial: "oversee/resources/input_field", locals: { datatype: @datatype, key: @key, value: @value })
72
+ ]
73
+ end
74
+ end
56
75
  end
57
76
 
58
77
  private
@@ -0,0 +1,10 @@
1
+ class Resource
2
+ def initialize(resource)
3
+ @resource = resource
4
+ end
5
+
6
+ def columns_for_create
7
+ excluded_columns = [@resource.class.primary_key, "created_at", "updated_at"]
8
+ @resource.columns_hash.except(*excluded_columns)
9
+ end
10
+ end
@@ -4,7 +4,7 @@
4
4
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
5
5
  <meta name="ROBOTS" content="NOODP">
6
6
 
7
- <title>Oversee | <%= Rails.application.class %></title>
7
+ <title>Oversee | <%= Oversee.application_name %></title>
8
8
  <%= csrf_meta_tags %>
9
9
  <%= csp_meta_tag %>
10
10
 
@@ -4,7 +4,6 @@
4
4
  <p class="text-xs uppercase font-medium text-gray-400">Resource</p>
5
5
  <h1 class="text-xl"><%= params[:resource] %></h1>
6
6
  </div>
7
-
8
7
  <%= link_to 'Edit', edit_resource_path(@resource, resource: params[:resource]), class: "inline-flex items-center justify-center py-2 px-6 rounded bg-blue-500 text-white text-sm font-medium" %>
9
8
  </div>
10
9
  </div>
@@ -4,7 +4,7 @@
4
4
  <p class="text-xs font-medium text-gray-500">Index</p>
5
5
  <h1 class="text-2xl"><%= params[:resource] %></h1>
6
6
  </div>
7
- <%= link_to 'Add new', "", class: "inline-flex items-center justify-center py-2 px-6 rounded bg-blue-500 text-white text-sm font-medium" %>
7
+ <%= link_to 'Add new', new_resource_path(params[:resource]), class: "inline-flex items-center justify-center py-2 px-6 rounded bg-blue-500 text-white text-sm font-medium" %>
8
8
  </div>
9
9
  </div>
10
10
  <div class="">
@@ -0,0 +1,28 @@
1
+ <div class="p-8">
2
+ <div class="flex items-center justify-between">
3
+ <div>
4
+ <p class="text-xs uppercase font-medium text-gray-400">New</p>
5
+ <h1 class="text-xl"><%= params[:resource] %></h1>
6
+ </div>
7
+ </div>
8
+ </div>
9
+
10
+ <div class="pb-8 px-8">
11
+ <%= form_with model: @resource, scope: :resource, url: create_resource_path(resource_class: @resource.class), scope: :resource do |f| %>
12
+ <div class="border-y -mx-8 py-8">
13
+ <% @resource_class.columns_hash.each do |key, metadata| %>
14
+ <% next if [@resource_class.primary_key, "created_at", "updated_at"].include?(key) %>
15
+ <div class="px-8 py-2">
16
+ <%= render Oversee::FieldLabelComponent.new(key: key, datatype: metadata.sql_type_metadata.type) %>
17
+ <div class="mt-2 w-2/3">
18
+ <%= render Oversee::FieldComponent.new(kind: :input, datatype: metadata.sql_type_metadata.type, key: key)%>
19
+ </div>
20
+ </div>
21
+ <%#= render Oversee::Fields::DisplayRowComponent.new(key: key, resource: @resource, datatype: metadata.sql_type_metadata.type, value: @resource.send(key)) %>
22
+ <% end %>
23
+ </div>
24
+ <div class="flex justify-end mt-8">
25
+ <%= f.submit "Save", class: "bg-blue-500 px-4 py-2 rounded-md text-white text-sm hover:bg-blue-600 hover:cursor-pointer" %>
26
+ </div>
27
+ <% end %>
28
+ </div>
@@ -11,6 +11,17 @@
11
11
  </div>
12
12
  </div>
13
13
 
14
+ <div class="pb-8">
15
+ <div class="px-8">
16
+ <h3 class="text-xl mb-8">Attributes</h3>
17
+ <div class="border-y divide-y -mx-8">
18
+ <% @resource_class.columns_hash.each do |key, metadata| %>
19
+ <%= render Oversee::Fields::DisplayRowComponent.new(key: key, resource: @resource, datatype: metadata.sql_type_metadata.type, value: @resource.send(key)) %>
20
+ <% end %>
21
+ </div>
22
+ </div>
23
+ </div>
24
+
14
25
  <div class="pb-8">
15
26
  <div class="px-8">
16
27
  <h3 class="text-xl mb-8">Associations</h3>
@@ -38,14 +49,3 @@
38
49
  </div>
39
50
  </div>
40
51
  </div>
41
-
42
- <div class="pb-8">
43
- <div class="px-8">
44
- <h3 class="text-xl mb-8">Attributes</h3>
45
- <div class="border-y divide-y -mx-8">
46
- <% @resource_class.columns_hash.each do |key, metadata| %>
47
- <%= render Oversee::Fields::DisplayRowComponent.new(key: key, resource: @resource, datatype: metadata.sql_type_metadata.type, value: @resource.send(key)) %>
48
- <% end %>
49
- </div>
50
- </div>
51
- </div>
data/config/routes.rb CHANGED
@@ -1,10 +1,16 @@
1
1
  Oversee::Engine.routes.draw do
2
2
 
3
3
  # Resources
4
- resources :resources do
5
- resources :fields, only: [:show, :edit, :update]
6
- get :input_field, on: :member
4
+ scope :resources, controller: "resources" do
5
+ get ":resource/", action: :index, as: :resources
6
+ get ":resource/new", action: :new, as: :new_resource
7
+ post ":resource_class/", action: :create, as: :create_resource
8
+ get ":resource/:id", action: :show, as: :resource
9
+ get ":resource/:id/edit", action: :edit, as: :edit_resource
10
+ patch ":resource/:id", action: :update, as: :update_resource
11
+ delete ":resource/:id", action: :destroy, as: :destroy_resource
12
+ get ":resource/:id/input_field", action: :input_field, as: :input_field
7
13
  end
8
-
14
+
9
15
  root to: "dashboard#show"
10
16
  end
@@ -1,3 +1,3 @@
1
1
  module Oversee
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/oversee.rb CHANGED
@@ -14,6 +14,11 @@ loader.setup
14
14
 
15
15
  module Oversee
16
16
  class << self
17
+
18
+ def application_name
19
+ Rails.application.class.to_s.gsub("::Application", "")
20
+ end
21
+
17
22
  def allowed_resource_list
18
23
  ApplicationRecord.descendants
19
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oversee
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
  - Elvinas Predkelis
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2024-09-03 00:00:00.000000000 Z
12
+ date: 2024-10-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -99,6 +99,7 @@ files:
99
99
  - app/components/oversee/field_component.rb
100
100
  - app/components/oversee/field_label_component.rb
101
101
  - app/components/oversee/fields/display_row_component.rb
102
+ - app/components/oversee/fields/input/boolean_component.rb
102
103
  - app/components/oversee/fields/input/datetime_component.rb
103
104
  - app/components/oversee/fields/input/integer_component.rb
104
105
  - app/components/oversee/fields/input/string_component.rb
@@ -118,6 +119,7 @@ files:
118
119
  - app/mailers/oversee/application_mailer.rb
119
120
  - app/models/oversee/application_record.rb
120
121
  - app/oversee/cards.rb
122
+ - app/oversee/resource.rb
121
123
  - app/views/layouts/oversee/application.html.erb
122
124
  - app/views/oversee/application/_javascript.html.erb
123
125
  - app/views/oversee/dashboard/show.html.erb
@@ -126,7 +128,7 @@ files:
126
128
  - app/views/oversee/resources/edit.html.erb
127
129
  - app/views/oversee/resources/index.html.erb
128
130
  - app/views/oversee/resources/input_field.html.erb
129
- - app/views/oversee/resources/input_field.turbo_stream.erb
131
+ - app/views/oversee/resources/new.html.erb
130
132
  - app/views/oversee/resources/show.html.erb
131
133
  - app/views/oversee/resources/update.turbo_stream.erb
132
134
  - app/views/shared/_sidebar.html.erb
@@ -157,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
159
  - !ruby/object:Gem::Version
158
160
  version: '0'
159
161
  requirements: []
160
- rubygems_version: 3.5.3
162
+ rubygems_version: 3.5.9
161
163
  signing_key:
162
164
  specification_version: 4
163
165
  summary: Lightweight admin dashboard for Rails
@@ -1,3 +0,0 @@
1
- <%= turbo_stream.replace dom_id(@resource, @key) do %>
2
- <%= render partial: "oversee/resources/input_field", locals: { datatype: @datatype, key: @key, value: @value } %>
3
- <% end %>