From 23b20e1c374336a7de3030cb2191dd8d7f765beb Mon Sep 17 00:00:00 2001 From: James Patrick Date: Fri, 22 May 2020 14:41:22 -0400 Subject: [PATCH] Scalfolding out the counter cluster groups. --- app/controllers/cluster_controller.rb | 19 +++++++++ app/controllers/counter_controller.rb | 10 +++++ app/helpers/cluster_helper.rb | 2 + app/helpers/counter_helper.rb | 2 + app/helpers/session_helper.rb | 2 + app/views/cluster/new.html.erb | 4 ++ app/views/counter/show.html.erb | 13 ++++++ config/routes.rb | 5 ++- .../cluster-list/_cluster-list.html.erb | 0 .../components/cluster-list/cluster-list.js | 1 + .../components/cluster-list/cluster-list.pcss | 1 + .../cluster-new/_cluster-new.html.erb | 6 +++ .../components/cluster-new/cluster-new.js | 1 + .../components/cluster-new/cluster-new.pcss | 41 +++++++++++++++++++ frontend/packs/application.js | 3 ++ test/controllers/cluster_controller_test.rb | 7 ++++ test/controllers/counter_controller_test.rb | 7 ++++ test/controllers/session_controller_test.rb | 7 ++++ 18 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 app/controllers/cluster_controller.rb create mode 100644 app/controllers/counter_controller.rb create mode 100644 app/helpers/cluster_helper.rb create mode 100644 app/helpers/counter_helper.rb create mode 100644 app/helpers/session_helper.rb create mode 100644 app/views/cluster/new.html.erb create mode 100644 app/views/counter/show.html.erb create mode 100644 frontend/components/cluster-list/_cluster-list.html.erb create mode 100644 frontend/components/cluster-list/cluster-list.js create mode 100644 frontend/components/cluster-list/cluster-list.pcss create mode 100644 frontend/components/cluster-new/_cluster-new.html.erb create mode 100644 frontend/components/cluster-new/cluster-new.js create mode 100644 frontend/components/cluster-new/cluster-new.pcss create mode 100644 test/controllers/cluster_controller_test.rb create mode 100644 test/controllers/counter_controller_test.rb create mode 100644 test/controllers/session_controller_test.rb diff --git a/app/controllers/cluster_controller.rb b/app/controllers/cluster_controller.rb new file mode 100644 index 0000000..d4583e9 --- /dev/null +++ b/app/controllers/cluster_controller.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +# This is the landing for a specific tally cluster +class ClusterController < ApplicationController + before_action :only_for_unknown + def new; end + + def create + # TODO: This will need to modify a shared object to insert a new tally cluster. + session[:cluster] = params[:cluster] + redirect_to root_path + end + + private + + def only_for_unknown + redirect_to root_path if session[:cluster] + end +end diff --git a/app/controllers/counter_controller.rb b/app/controllers/counter_controller.rb new file mode 100644 index 0000000..8627d18 --- /dev/null +++ b/app/controllers/counter_controller.rb @@ -0,0 +1,10 @@ +class CounterController < ApplicationController + before_action :associate! + + def show; end + + private + def associate! + redirect_to cluster_path unless session[:cluster] + end +end diff --git a/app/helpers/cluster_helper.rb b/app/helpers/cluster_helper.rb new file mode 100644 index 0000000..7b237b8 --- /dev/null +++ b/app/helpers/cluster_helper.rb @@ -0,0 +1,2 @@ +module ClusterHelper +end diff --git a/app/helpers/counter_helper.rb b/app/helpers/counter_helper.rb new file mode 100644 index 0000000..0bac859 --- /dev/null +++ b/app/helpers/counter_helper.rb @@ -0,0 +1,2 @@ +module CounterHelper +end diff --git a/app/helpers/session_helper.rb b/app/helpers/session_helper.rb new file mode 100644 index 0000000..f867f86 --- /dev/null +++ b/app/helpers/session_helper.rb @@ -0,0 +1,2 @@ +module SessionHelper +end diff --git a/app/views/cluster/new.html.erb b/app/views/cluster/new.html.erb new file mode 100644 index 0000000..2822593 --- /dev/null +++ b/app/views/cluster/new.html.erb @@ -0,0 +1,4 @@ +<%= c("page") do %> + <%= c("cluster-list") %> + <%= c("cluster-new") %> +<% end %> diff --git a/app/views/counter/show.html.erb b/app/views/counter/show.html.erb new file mode 100644 index 0000000..b19cab6 --- /dev/null +++ b/app/views/counter/show.html.erb @@ -0,0 +1,13 @@ +
+
+

+ Hello World +

+

+ + + + My first website with Bulma! +

+
+
diff --git a/config/routes.rb b/config/routes.rb index 0469c11..b9992fe 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,8 @@ # frozen_string_literal: true Rails.application.routes.draw do - root 'pages#home' + root 'counter#show' + + get '/cluster', to: 'cluster#new' + post '/cluster', to: 'cluster#create' end diff --git a/frontend/components/cluster-list/_cluster-list.html.erb b/frontend/components/cluster-list/_cluster-list.html.erb new file mode 100644 index 0000000..e69de29 diff --git a/frontend/components/cluster-list/cluster-list.js b/frontend/components/cluster-list/cluster-list.js new file mode 100644 index 0000000..9311c03 --- /dev/null +++ b/frontend/components/cluster-list/cluster-list.js @@ -0,0 +1 @@ +import "./cluster-list.pcss"; diff --git a/frontend/components/cluster-list/cluster-list.pcss b/frontend/components/cluster-list/cluster-list.pcss new file mode 100644 index 0000000..545eb34 --- /dev/null +++ b/frontend/components/cluster-list/cluster-list.pcss @@ -0,0 +1 @@ +/* placeholder */ diff --git a/frontend/components/cluster-new/_cluster-new.html.erb b/frontend/components/cluster-new/_cluster-new.html.erb new file mode 100644 index 0000000..517fdf5 --- /dev/null +++ b/frontend/components/cluster-new/_cluster-new.html.erb @@ -0,0 +1,6 @@ +
+ <%= form_tag cluster_path, method: :post do %> + <%= text_field_tag :cluster, "", class: "create-cluster-form--input", placeholder: "Cluster Name", autofocus: true, required: true %> + <%= submit_tag "Create", class: "create-cluster-form--submit" %> + <% end %> +
diff --git a/frontend/components/cluster-new/cluster-new.js b/frontend/components/cluster-new/cluster-new.js new file mode 100644 index 0000000..e965294 --- /dev/null +++ b/frontend/components/cluster-new/cluster-new.js @@ -0,0 +1 @@ +import "./cluster-new.pcss"; diff --git a/frontend/components/cluster-new/cluster-new.pcss b/frontend/components/cluster-new/cluster-new.pcss new file mode 100644 index 0000000..f847653 --- /dev/null +++ b/frontend/components/cluster-new/cluster-new.pcss @@ -0,0 +1,41 @@ +.create-cluster-form { + display: flex; + justify-content: center; + align-items: center; + width: 100%; + height: 100%; + + & input { + width: 100%; + padding: 12px 0; + border: 1px solid rgba(0, 0, 0, 0.1); + font-size: 18px; + text-align: center; + outline: none; + transition: border-color 150ms; + box-sizing: border-box; + + &:hover, + &:focus { + border: 1px solid #3f94f9; + } + } + + & input[type="submit"] { + width: 100%; + margin-top: 6px; + padding: 12px 0; + background: #3f94f9; + border: 1px solid #3f94f9; + color: white; + font-size: 18px; + outline: none; + transition: opacity 150ms; + cursor: pointer; + + &:hover, + &:focus { + opacity: 0.7; + } + } +} diff --git a/frontend/packs/application.js b/frontend/packs/application.js index 558bdd1..d120a0c 100644 --- a/frontend/packs/application.js +++ b/frontend/packs/application.js @@ -1,2 +1,5 @@ import "init"; + import "components/page/page"; +import "components/cluster-list/cluster-list"; +import "components/cluster-new/cluster-new"; diff --git a/test/controllers/cluster_controller_test.rb b/test/controllers/cluster_controller_test.rb new file mode 100644 index 0000000..daaa651 --- /dev/null +++ b/test/controllers/cluster_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ClusterControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end diff --git a/test/controllers/counter_controller_test.rb b/test/controllers/counter_controller_test.rb new file mode 100644 index 0000000..7e78252 --- /dev/null +++ b/test/controllers/counter_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class CounterControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end diff --git a/test/controllers/session_controller_test.rb b/test/controllers/session_controller_test.rb new file mode 100644 index 0000000..266fc95 --- /dev/null +++ b/test/controllers/session_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class SessionControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end