diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index cb5ec14..eb9edfa 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -3,4 +3,12 @@ class HomeController < ApplicationController def index redirect_to forms_url if logged_in? end + + def demo + if params[:backend] == 'airtable' + render 'demo-airtable' + else + render 'demo-google' + end + end end diff --git a/app/javascript/demo.js b/app/javascript/demo.js index 66e15d5..420708d 100644 --- a/app/javascript/demo.js +++ b/app/javascript/demo.js @@ -13,8 +13,13 @@ document.addEventListener("turbolinks:load", function () { var name = document.getElementById('demo-submission-name'); var demoFields = document.getElementById('demo-fields'); var demoSucess = document.getElementById('demo-success'); + var demoIframe = document.getElementById('demo-sheet'); demoFields.style.display = 'none'; demoSucess.style.display = 'block'; name.innerText = e.detail.submission.Name; + // The airtable sheet must be reloaded for the submission to get visible + if (demoIframe.dataset.refresh) { + demoIframe.src = demoIframe.src + '&c=' + new Date().getTime(); + } }); }); diff --git a/app/models/submission.rb b/app/models/submission.rb index 3a60e14..5a404d8 100644 --- a/app/models/submission.rb +++ b/app/models/submission.rb @@ -37,7 +37,7 @@ class Submission < ApplicationRecord attachment = ActiveStorage::Attachment.new(record: self, name: 'files', blob: create_one.blob) attachment.save # return the URL that we use to show in the Spreadsheet - Rails.application.routes.url_helpers.file_upload_url(form_id: form, submission_id: self, id: attachment.token, host: DEFAULT_HOST) + Rails.application.routes.url_helpers.file_upload_url(form_id: form, submission_id: self, id: attachment.token, host: DEFAULT_HOST, filename: attachment.blob.filename) else value.to_s end diff --git a/app/views/home/demo-airtable.html.erb b/app/views/home/demo-airtable.html.erb new file mode 100644 index 0000000..bb7e144 --- /dev/null +++ b/app/views/home/demo-airtable.html.erb @@ -0,0 +1,87 @@ +
+
+
+
+
+ +

Demo

+

+ This short form is connected to the embedded <%= link_to 'document', AIRTABLE_DEMO_EMBED_URL %> on the right.
+ Submit the form and see the update of the document in realtime. +

+ + + +
+
+ +
+ +
+
+ +
+ +
+
+ +
+
+
+ +
+ +
+ + +
+
+ +
+ +
+ +
+
+ +
+
+ +
+
+
+
+
+ +
+ +
+
+
+
+ diff --git a/app/views/home/demo.html.erb b/app/views/home/demo-google.html.erb similarity index 85% rename from app/views/home/demo.html.erb rename to app/views/home/demo-google.html.erb index c75d4bd..4f357c5 100644 --- a/app/views/home/demo.html.erb +++ b/app/views/home/demo-google.html.erb @@ -1,12 +1,12 @@
-
+
-
+ -

Demo

+

Demo

- This short form is connected to the embedded <%= link_to 'document', DEMO_FORM.spreadsheet_url %> on the right.
+ This short form is connected to the embedded <%= link_to 'document', GOOGLE_DEMO_FORM.spreadsheet_url %> on the right.
Submit the form and see the update of the document in realtime.

@@ -79,8 +79,8 @@
- -

Document not loading? <%= link_to 'Open it here', DEMO_FORM.spreadsheet_url %>.

+ +

Document not loading? <%= link_to 'Open it here', GOOGLE_DEMO_FORM.spreadsheet_url %>.

diff --git a/config/initializers/demo.rb b/config/initializers/demo.rb index 915b94c..4947248 100644 --- a/config/initializers/demo.rb +++ b/config/initializers/demo.rb @@ -1 +1,3 @@ -DEMO_FORM = Form.find_by(id: ENV['DEMO_FORM_ID']) +GOOGLE_DEMO_FORM = Form.find_by(id: ENV['GOOGLE_DEMO_FORM_ID']) +AIRTABLE_DEMO_FORM = Form.find_by(id: ENV['AIRTABLE_DEMO_FORM_ID']) +AIRTABLE_DEMO_EMBED_URL = ENV['AIRTABLE_DEMO_EMBED_URL'] diff --git a/config/routes.rb b/config/routes.rb index fcf270a..d977dd6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,7 +6,9 @@ Rails.application.routes.draw do resources :submissions end # short link for submission file uploads - get '/s/:form_id/:submission_id/:id' => 'file_uploads#show', as: :file_upload + # we add the filename as part of the URL which allows e.g. Airtable to identify and name the file properly + # the constraint makes sure that a . (dot) can be in the filename. e.g. cat.jpg + get '/s/:form_id/:submission_id/:id(/:filename)' => 'file_uploads#show', as: :file_upload, constraints: { filename: /[^\/]+/ } # form post url to save new submissions post '/s/:form_id' => 'submissions#create', as: :submission @@ -21,7 +23,7 @@ Rails.application.routes.draw do get '/logout' => 'sessions#destroy', as: :logout get '/auth' => 'sessions#auth', as: :auth - get '/demo' => 'home#demo', as: :demo + get '/demo(/:backend)' => 'home#demo', as: :demo get '/contact' => 'home#contact', as: :contact get '/help', to: redirect('https://www.notion.so/Tinyforms-Help-Center-04f13b5908bc46cfb4283079a3cb1149') diff --git a/env.example b/env.example index 70b5e82..ff2ac81 100644 --- a/env.example +++ b/env.example @@ -2,3 +2,6 @@ GOOGLE_CLIENT_ID=clientid GOOGLE_CLIENT_SECRET=secret GOOGLE_PROJECT_ID=projectid LOCKBOX_MASTER_KEY=f7b18b63d3f7ec48fa78bab327cdf81b0969020f70dc16947b14572cde3e2b7d +GOOGLE_DEMO_FORM_ID=1 +AIRTABLE_DEMO_FROM_ID=2 +AIRTABLE_DEMO_EMBED_URL=''