Skip to content

Commit

Permalink
[bug fix] dynamic property render in snippets (#1424)
Browse files Browse the repository at this point in the history
* [bug fix] dynamic property render in snippets 

Addresses: #1355
Demo: 


https://user-images.githubusercontent.com/55496123/220007755-4d4fa5f6-0534-4c7a-a499-06978793219c.mov

* feat: pointing to cms tag 3.5 (#1426)

---------

Co-authored-by: Er. Ajay Shrestha <55496123+ajaystha42@users.noreply.github.com>
  • Loading branch information
donrestarone and sthajay authored Feb 24, 2023
1 parent 5f74f68 commit 5da187f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ gem 'ros-apartment', require: 'apartment'
gem 'ros-apartment-sidekiq', require: 'apartment-sidekiq'
gem 'apartment-activejob'
gem 'devise'
gem "comfortable_mexican_sofa",git: 'https://github.com/restarone/comfortable-mexican-sofa', tag: '3.4'
gem "comfortable_mexican_sofa",git: 'https://github.com/restarone/comfortable-mexican-sofa', tag: '3.5'
gem "comfy_blog", git: 'https://github.com/restarone/comfy-blog', branch: 'master'
gem 'simple_discussion', git: 'https://github.com/restarone/simple_discussion', branch: 'master'
gem 'gravatar_image_tag'
Expand Down
29 changes: 10 additions & 19 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GIT
remote: https://github.com/restarone/comfortable-mexican-sofa
revision: 456fb8507e9668128529c0302fa2e77e029c1f88
tag: 3.4
revision: ccf9415ae220453a199759b8ecbb8e9436c75c85
tag: 3.5
specs:
comfortable_mexican_sofa (2.0.19)
active_link_to (>= 1.0.0)
Expand Down Expand Up @@ -210,7 +210,6 @@ GEM
encryptor (3.0.0)
errbase (0.2.1)
erubi (1.10.0)
erubis (2.7.0)
exception_notification (4.5.0)
actionmailer (>= 5.2, < 8)
activesupport (>= 5.2, < 8)
Expand All @@ -231,21 +230,16 @@ GEM
gravatar_image_tag (1.2.0)
groupdate (5.2.2)
activesupport (>= 5)
haml (5.2.2)
temple (>= 0.8.0)
haml (6.1.1)
temple (>= 0.8.2)
thor
tilt
haml-rails (2.0.1)
haml-rails (2.1.0)
actionpack (>= 5.1)
activesupport (>= 5.1)
haml (>= 4.0.6, < 6.0)
html2haml (>= 1.0.1)
haml (>= 4.0.6)
railties (>= 5.1)
hashdiff (1.0.1)
html2haml (2.2.0)
erubis (~> 2.7.0)
haml (>= 4.0, < 6)
nokogiri (>= 1.6.0)
ruby_parser (~> 3.5)
html_page (0.1.0)
http-accept (1.7.0)
http-cookie (1.0.3)
Expand All @@ -261,7 +255,7 @@ GEM
jbuilder (2.11.2)
activesupport (>= 5.0.0)
jmespath (1.6.1)
jquery-rails (4.4.0)
jquery-rails (4.5.1)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
Expand Down Expand Up @@ -355,7 +349,7 @@ GEM
nokogiri (>= 1.6)
rails-html-sanitizer (1.4.2)
loofah (~> 2.3)
rails-i18n (7.0.3)
rails-i18n (7.0.6)
i18n (>= 0.7, < 2)
railties (>= 6.0.0, < 8)
railties (6.1.5)
Expand Down Expand Up @@ -399,8 +393,6 @@ GEM
ruby-vips (2.1.4)
ffi (~> 1.12)
ruby2_keywords (0.0.5)
ruby_parser (3.19.1)
sexp_processor (~> 4.16)
rubyzip (2.3.0)
safely_block (0.3.0)
errbase (>= 0.1.1)
Expand All @@ -418,7 +410,6 @@ GEM
childprocess (>= 0.5, < 4.0)
rubyzip (>= 1.2.2)
semantic_range (3.0.0)
sexp_processor (4.16.1)
sidekiq (6.4.1)
connection_pool (>= 2.2.2)
rack (~> 2.0)
Expand Down Expand Up @@ -452,7 +443,7 @@ GEM
rails (>= 5.1)
responders
stripe (>= 3.15.0)
temple (0.8.2)
temple (0.10.0)
thor (1.2.1)
tilt (2.0.10)
turbo-rails (1.1.1)
Expand Down
7 changes: 7 additions & 0 deletions app/controllers/comfy/admin/api_namespaces_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ def show

field, direction = params[:q].key?(:s) ? params[:q][:s].split(" ") : [nil, nil]
fields_in_properties = @api_namespace.properties.keys
@custom_properties = {}
@api_namespace.properties.values.each_with_index do |obj,index|
if(obj.present? && obj != "nil" && obj != "\"\"")
@custom_properties[fields_in_properties[index]] = obj;
end
end
@custom_properties = JSON.parse(@custom_properties.to_json, object_class: OpenStruct).to_s.gsub(/=/,': ').gsub(/#<OpenStruct/,'{').gsub(/>/,'}').gsub("\\", "'").gsub(/"'"/,'"').gsub(/'""/,'"')
@image_options = @api_namespace.non_primitive_properties.select { |non_primitive_property| non_primitive_property.field_type == 'file' }.pluck(:label)
# check if we are sorting by a field inside properties jsonb column
if field && fields_in_properties.include?(field)
Expand Down
4 changes: 2 additions & 2 deletions app/views/comfy/admin/api_namespaces/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@
%pre= @api_namespace.snippet
%p
%b API HTML Renderer index snippet:
%pre= "{{ cms:helper api_namespace_resource_index '#{@api_namespace.slug}', scope: { properties: { property: value } } }}"
%pre= "{{ cms:helper render_api_namespace_resource_index '#{@api_namespace.slug}', scope: { properties: #{@custom_properties} } }}"
%p
%b API HTML Renderer show snippet:
%pre= "{{ cms:helper api_namespace_resource '#{@api_namespace.slug}', scope: { properties: { property: value } } }}"
%pre= "{{ cms:helper render_api_namespace_resource '#{@api_namespace.slug}', scope: { properties: #{@custom_properties} } }}"
%p
.d-flex.justify-content-between
%b Preview (outer border is present in preview only):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -775,18 +775,17 @@ class Comfy::Admin::ApiNamespacesControllerTest < ActionDispatch::IntegrationTes
test "#index: Rendering tab should include documentation on form snippet and API HTML renderer snippets" do
sign_in(@user)
@api_namespace.has_form = "1"
properties = { test_id: 123, obj:{ a:"b", c:"d"}, title: "Hello World", published: true, arr:[ 1, 2, 3], alpha_arr: ["a", "b"] }

@api_namespace.update(properties: properties)
get api_namespace_url(@api_namespace)
assert_response :success

assert_select "b", {count: 1, text: "Form rendering snippet:"}
assert_select "pre", {count: 1, text: @api_namespace.snippet}

assert_select "b", {count: 1, text: "API HTML Renderer index snippet:"}
assert_select "pre", {count: 1, text: "{{ cms:helper api_namespace_resource_index '#{@api_namespace.slug}', scope: { properties: { property: value } } }}"}

assert_select "pre", {count: 1, text: "{{ cms:helper render_api_namespace_resource_index '#{@api_namespace.slug}', scope: { properties: { arr: [1, 2, 3], obj: { a: \"b\", c: \"d\"}, title: \"Hello World\", test_id: 123, alpha_arr: [\"a\", \"b\"], published: true} } }}"}
assert_select "b", {count: 1, text: "API HTML Renderer show snippet:"}
assert_select "pre", {count: 1, text: "{{ cms:helper api_namespace_resource '#{@api_namespace.slug}', scope: { properties: { property: value } } }}"}
assert_select "pre", {count: 1, text: "{{ cms:helper render_api_namespace_resource '#{@api_namespace.slug}', scope: { properties: { arr: [1, 2, 3], obj: { a: \"b\", c: \"d\"}, title: \"Hello World\", test_id: 123, alpha_arr: [\"a\", \"b\"], published: true} } }}"}
end

######## API Accessibility Tests - START #########
Expand Down

0 comments on commit 5da187f

Please sign in to comment.