diff --git a/.gitignore b/.gitignore index 072bcce..d906f33 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,4 @@ /yarn-error.log yarn-debug.log* .yarn-integrity +.vscode diff --git a/Gemfile b/Gemfile index 61e4225..9e9983d 100644 --- a/Gemfile +++ b/Gemfile @@ -18,7 +18,7 @@ gem 'turbolinks', '~> 5' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 2.7' # Use Redis adapter to run Action Cable in production -# gem 'redis', '~> 4.0' +gem 'redis', '~> 4.0' # Use Active Model has_secure_password # gem 'bcrypt', '~> 3.1.7' @@ -41,7 +41,7 @@ group :development do gem 'rack-mini-profiler', '~> 2.0' gem 'listen', '~> 3.3' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring - gem 'spring' + gem 'spring', '~> 3.0.0' end group :test do @@ -61,3 +61,5 @@ gem 'rails_admin', '~> 2.0' gem 'client_side_validations' gem 'jquery-rails', '~> 4.3' + +gem "hotwire-rails", "~> 0.1.3" diff --git a/Gemfile.lock b/Gemfile.lock index df78dd3..e28bc28 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -101,6 +101,10 @@ GEM haml (5.2.2) temple (>= 0.8.0) tilt + hotwire-rails (0.1.3) + rails (>= 6.0.0) + stimulus-rails + turbo-rails i18n (1.8.10) concurrent-ruby (~> 1.0) jbuilder (2.11.2) @@ -202,6 +206,7 @@ GEM rb-inotify (0.10.1) ffi (~> 1.0) rbtree (0.4.4) + redis (4.4.0) regexp_parser (2.1.1) regexp_property_values (1.0.0) remotipart (1.4.4) @@ -227,7 +232,7 @@ GEM sorted_set (1.0.3) rbtree set (~> 1.0) - spring (2.1.1) + spring (3.0.0) sprockets (4.0.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) @@ -236,9 +241,13 @@ GEM activesupport (>= 4.0) sprockets (>= 3.0.0) sqlite3 (1.4.2) + stimulus-rails (0.5.4) + rails (>= 6.0.0) temple (0.8.2) thor (1.1.0) tilt (2.0.10) + turbo-rails (0.7.14) + rails (>= 6.0.0) turbolinks (5.2.1) turbolinks-source (~> 5.2) turbolinks-source (5.2.0) @@ -276,6 +285,7 @@ DEPENDENCIES capybara (>= 3.26) client_side_validations devise (~> 4.8) + hotwire-rails (~> 0.1.3) jbuilder (~> 2.7) jquery-rails (~> 4.3) listen (~> 3.3) @@ -283,9 +293,10 @@ DEPENDENCIES rack-mini-profiler (~> 2.0) rails (~> 6.1.4, >= 6.1.4.1) rails_admin (~> 2.0) + redis (~> 4.0) sass-rails (>= 6) selenium-webdriver - spring + spring (~> 3.0.0) sqlite3 (~> 1.4) turbolinks (~> 5) tzinfo-data diff --git a/app/controllers/hello_controller.rb b/app/controllers/hello_controller.rb new file mode 100644 index 0000000..98837b9 --- /dev/null +++ b/app/controllers/hello_controller.rb @@ -0,0 +1,20 @@ +class HelloController < ApplicationController + before_action only: [:show, :edit, :update, :destroy] + + def index + @employers = Employer.all + @employer = Employer.new + end + + # def create + # @product.increment! :retweets_count + # redirect_to @tweet + # end + + private + + # def set_tweet + # # @tweet = Tweet.find(params[:tweet_id]) + # end +end + diff --git a/app/javascript/controllers/application.js b/app/javascript/controllers/application.js new file mode 100644 index 0000000..932e75c --- /dev/null +++ b/app/javascript/controllers/application.js @@ -0,0 +1,10 @@ +import { Application } from "@hotwired/stimulus" + +const application = Application.start() + +// Configure Stimulus development experience +application.warnings = true +application.debug = false +window.Stimulus = application + +export { application } diff --git a/app/javascript/controllers/hello_controller.js b/app/javascript/controllers/hello_controller.js new file mode 100644 index 0000000..5975c07 --- /dev/null +++ b/app/javascript/controllers/hello_controller.js @@ -0,0 +1,7 @@ +import { Controller } from "@hotwired/stimulus" + +export default class extends Controller { + connect() { + this.element.textContent = "Hello World!" + } +} diff --git a/app/javascript/controllers/index.js b/app/javascript/controllers/index.js new file mode 100644 index 0000000..c645750 --- /dev/null +++ b/app/javascript/controllers/index.js @@ -0,0 +1,7 @@ +// This file is auto-generated by ./bin/rails stimulus:manifest:update +// Run that command whenever you add a new controller + +import { application } from "./application" + +import HelloController from "./hello_controller" +application.register("hello", HelloController) diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js index e1f98b6..80d094c 100644 --- a/app/javascript/packs/application.js +++ b/app/javascript/packs/application.js @@ -5,9 +5,13 @@ // import Rails from "@rails/ujs" import Turbolinks from "turbolinks" +import { Turbo } from "@hotwired/turbo-rails" import * as ActiveStorage from "@rails/activestorage" +import "controllers" import "channels" Rails.start() Turbolinks.start() +window.Turbo = Turbo +Turbo.start() ActiveStorage.start() diff --git a/app/models/employer.rb b/app/models/employer.rb index 2105f2d..018c3bc 100644 --- a/app/models/employer.rb +++ b/app/models/employer.rb @@ -1,4 +1,8 @@ class Employer < ApplicationRecord + after_create_commit { broadcast_prepend_to "employers" } + after_update_commit { broadcast_replace_to "employers" } + after_destroy_commit { broadcast_remove_to "employers" } + include Recentable has_many :subscriptions diff --git a/app/views/employers/_employer.html.erb b/app/views/employers/_employer.html.erb new file mode 100644 index 0000000..4095e04 --- /dev/null +++ b/app/views/employers/_employer.html.erb @@ -0,0 +1,7 @@ +<%= turbo_frame_tag dom_id(employer) do %> +
+
Something
+
<%= employer.name %>
+ +
+<% end %> diff --git a/app/views/employers/_employer.json.jbuilder b/app/views/employers/_employer.json.jbuilder new file mode 100644 index 0000000..c81540a --- /dev/null +++ b/app/views/employers/_employer.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! employer, :id, :name + diff --git a/app/views/hello/_employer.html.erb b/app/views/hello/_employer.html.erb new file mode 100644 index 0000000..1fce3b8 --- /dev/null +++ b/app/views/hello/_employer.html.erb @@ -0,0 +1,5 @@ +<%= turbo_frame_tag dom_id(employer) do %> +
+
<%= @employer.name %>
+
+<% end %> diff --git a/app/views/hello/_employer.json.jbuilder b/app/views/hello/_employer.json.jbuilder new file mode 100644 index 0000000..c81540a --- /dev/null +++ b/app/views/hello/_employer.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! employer, :id, :name + diff --git a/app/views/hello/_form.html.erb b/app/views/hello/_form.html.erb new file mode 100644 index 0000000..f0ce847 --- /dev/null +++ b/app/views/hello/_form.html.erb @@ -0,0 +1,23 @@ +<%= form_with(model: employer, id: dom_id(employer)) do |form| %> + <% if employer.errors.any? %> +
+

<%= pluralize(employer.errors.count, "error") %> prohibited this employer from being saved:

+ + +
+ <% end %> + +
+ <%= form.label :name %> + <%= form.text_area :name %> +
+ +
+ <%= form.submit %> +
+<% end %> + diff --git a/app/views/hello/index.html.erb b/app/views/hello/index.html.erb new file mode 100644 index 0000000..bb024ec --- /dev/null +++ b/app/views/hello/index.html.erb @@ -0,0 +1,243 @@ + + + + + + + + + + + + + <%= turbo_include_tags %> + <%= stimulus_include_tags %> + <%= stylesheet_link_tag "vendor.css", :media => :all %> + <%= stylesheet_link_tag "profiler.css", :media => :all %> + <%= csrf_meta_tag %> + <%= csrf_meta_tags %> + <%= stylesheet_link_tag "rails_admin/rails_admin.css", :media => :all %> + <%= javascript_include_tag "rails_admin/rails_admin.js" %> + + <%= stylesheet_link_tag 'application', media: 'all' %> + + + <%# <%= stimulus_include_tags %> %> + + + + Concertiv | Profiler + + + +
+ +
+ +
+ + +
+
+
+
+
+
+
+
+
+ +
+
+ + +
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+ +
+ +
+
+
+
+
+ <%= turbo_stream_from "@employers" %> + <%= turbo_frame_tag "employers" do %> + <%= render @employers %> + <% end %> + <%= turbo_frame_tag "employer_form" do %> + <%= render "hello/form", employer: @employer %> + <% end %> +
+ +
+
+ <%# <%= render :template => 'layouts/rails_admin/pjax' %> + + +
+
+
+
+
+
+ +
+
+ + + + diff --git a/app/views/hello/index.json.jbuilder b/app/views/hello/index.json.jbuilder new file mode 100644 index 0000000..1c81f2f --- /dev/null +++ b/app/views/hello/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @employers, partial: "tweets/tweet", as: :employer diff --git a/app/views/rails_admin/employers/_form.html.erb b/app/views/rails_admin/employers/_form.html.erb index 27fe379..018aa5b 100644 --- a/app/views/rails_admin/employers/_form.html.erb +++ b/app/views/rails_admin/employers/_form.html.erb @@ -2,7 +2,7 @@ <%= bootstrap_form_with model: model, local: true do |form| %> -V <%= form.text_field :name %> + <%= form.text_field :name %> <%= form.time_zone_select(:shoot_location_time_zone, nil, label: "Time zone of shoot location") %>
<%= link_to t("shared.cancel"), [project, :broadcasts], class: "col-3 text-reset" %>
diff --git a/config/cable.yml b/config/cable.yml index 6572e7a..b8bafc4 100644 --- a/config/cable.yml +++ b/config/cable.yml @@ -1,5 +1,6 @@ development: - adapter: async + adapter: redis + url: redis://localhost:6379/1 test: adapter: test diff --git a/config/routes.rb b/config/routes.rb index f9b7518..385f963 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,9 @@ Rails.application.routes.draw do mount RailsAdmin::Engine => '/admin', as: 'rails_admin' + resources :employers do + resource :like + resource :retweet + end + root to: 'hello#index' # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html end diff --git a/package.json b/package.json index b0c6063..e094440 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,8 @@ "private": true, "dependencies": { "@client-side-validations/client-side-validations": "^0.1.5", + "@hotwired/stimulus": "^3.0.0-beta.2", + "@hotwired/turbo-rails": "^7.0.0-rc.4", "@rails/actioncable": "^6.0.0", "@rails/activestorage": "^6.0.0", "@rails/ujs": "^6.0.0", diff --git a/yarn.lock b/yarn.lock index 891ece8..3c65366 100644 --- a/yarn.lock +++ b/yarn.lock @@ -895,6 +895,24 @@ resolved "https://registry.yarnpkg.com/@gar/promisify/-/promisify-1.1.2.tgz#30aa825f11d438671d585bd44e7fd564535fc210" integrity sha512-82cpyJyKRoQoRi+14ibCeGPu0CwypgtBAdBhq1WfvagpCZNKqwXbKwXllYSMG91DhmG4jt9gN8eP6lGOtozuaw== +"@hotwired/stimulus@^3.0.0-beta.2": + version "3.0.0-beta.2" + resolved "https://registry.yarnpkg.com/@hotwired/stimulus/-/stimulus-3.0.0-beta.2.tgz#64ca67af9cc473ca97bb99d98fee5bc08e4c3914" + integrity sha512-rp2XojlugD0mvqi3qbqM660PbjqS7hnq/8FYa7SK/DL2rvWDu0/Ka3KW8cyXtcB1RiVG4nX5Oh4oq3nmuDjENQ== + +"@hotwired/turbo-rails@^7.0.0-rc.4": + version "7.0.0-rc.4" + resolved "https://registry.yarnpkg.com/@hotwired/turbo-rails/-/turbo-rails-7.0.0-rc.4.tgz#647e7f976b1bb645a2902c131c235d7440c28e29" + integrity sha512-ibCoMPnJRz/1CTsMywYLotq0zz2G4VZUeMiYSupzjmGFesGSJiCRiC42+iXPK/P1qwqp0WdWxSBRhfXI/wbH0A== + dependencies: + "@hotwired/turbo" "^7.0.0-rc.4" + "@rails/actioncable" "^6.0.0" + +"@hotwired/turbo@^7.0.0-rc.4": + version "7.0.0-rc.4" + resolved "https://registry.yarnpkg.com/@hotwired/turbo/-/turbo-7.0.0-rc.4.tgz#d3ab9555544534f5ec649613553e72ff6c7d7122" + integrity sha512-4qx+6O6mUN+cSN+ZLGCOGc+2MxNrs7cFbmnWD6LIfiHAQyuNiIuB87Y5IAtOo8xj16fOBd2CdU1WRJya4Wkw0A== + "@npmcli/fs@^1.0.0": version "1.0.0" resolved "https://registry.yarnpkg.com/@npmcli/fs/-/fs-1.0.0.tgz#589612cfad3a6ea0feafcb901d29c63fd52db09f"