From 052fab1d9162d47cf0b039bd734c686c8b969f90 Mon Sep 17 00:00:00 2001 From: James Patrick Date: Sat, 23 May 2020 02:23:37 -0400 Subject: [PATCH] Added cluster selection and creation path. --- app/controllers/application_controller.rb | 7 ++++ app/controllers/cluster_controller.rb | 10 +++-- app/controllers/counter_controller.rb | 2 +- app/models/cluster.rb | 3 +- app/views/cluster/new.html.erb | 4 -- app/views/cluster/show.html.erb | 3 ++ .../cluster-list/_cluster-list.html.erb | 5 +++ .../components/cluster-list/cluster-list.js | 2 + .../components/cluster-list/cluster-list.pcss | 5 ++- .../components/cluster-new/cluster-new.pcss | 6 --- .../cluster-view/_cluster-view.html.erb | 4 ++ .../components/cluster-view/cluster-view.css | 8 ++++ .../components/cluster-view/cluster-view.js | 4 ++ frontend/components/cluster/_cluster.html.erb | 6 +++ frontend/components/cluster/cluster.js | 1 + frontend/components/cluster/cluster.pcss | 40 +++++++++++++++++++ frontend/init/index.pcss | 5 +++ frontend/packs/application.js | 3 +- 18 files changed, 99 insertions(+), 19 deletions(-) delete mode 100644 app/views/cluster/new.html.erb create mode 100644 app/views/cluster/show.html.erb create mode 100644 frontend/components/cluster-view/_cluster-view.html.erb create mode 100644 frontend/components/cluster-view/cluster-view.css create mode 100644 frontend/components/cluster-view/cluster-view.js create mode 100644 frontend/components/cluster/_cluster.html.erb create mode 100644 frontend/components/cluster/cluster.js create mode 100644 frontend/components/cluster/cluster.pcss diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e250433..be53fee 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,4 +2,11 @@ class ApplicationController < ActionController::Base prepend_view_path Rails.root.join('frontend') + + def valid_cluster? + return false unless session[:cluster_uuid] + return false unless Cluster.get(session[:cluster_uuid]) + + true + end end diff --git a/app/controllers/cluster_controller.rb b/app/controllers/cluster_controller.rb index d4583e9..c6c8c6b 100644 --- a/app/controllers/cluster_controller.rb +++ b/app/controllers/cluster_controller.rb @@ -3,17 +3,19 @@ # This is the landing for a specific tally cluster class ClusterController < ApplicationController before_action :only_for_unknown - def new; end + def show + @clusters = Cluster.list + end def create - # TODO: This will need to modify a shared object to insert a new tally cluster. - session[:cluster] = params[:cluster] + cluster = Cluster.new(params[:cluster]) + session[:cluster_uuid] = cluster.uuid; redirect_to root_path end private def only_for_unknown - redirect_to root_path if session[:cluster] + redirect_to root_path if valid_cluster? end end diff --git a/app/controllers/counter_controller.rb b/app/controllers/counter_controller.rb index 9b5c8a5..21431d6 100644 --- a/app/controllers/counter_controller.rb +++ b/app/controllers/counter_controller.rb @@ -8,6 +8,6 @@ class CounterController < ApplicationController private def associate! - redirect_to cluster_path unless session[:cluster] + redirect_to cluster_path unless valid_cluster? end end diff --git a/app/models/cluster.rb b/app/models/cluster.rb index e4923e7..7bdabe9 100644 --- a/app/models/cluster.rb +++ b/app/models/cluster.rb @@ -4,7 +4,7 @@ require 'securerandom' # A collective for a tally class Cluster - attr_reader :count, :name, :status, :uuid + attr_reader :count, :name, :status, :uuid, :created_on @@clusters = {} def initialize(name) @@ -13,6 +13,7 @@ class Cluster @count = 0 @status = :open @mutex = Mutex.new + @created_on = Time.new @@clusters[@uuid] = self end diff --git a/app/views/cluster/new.html.erb b/app/views/cluster/new.html.erb deleted file mode 100644 index 2822593..0000000 --- a/app/views/cluster/new.html.erb +++ /dev/null @@ -1,4 +0,0 @@ -<%= c("page") do %> - <%= c("cluster-list") %> - <%= c("cluster-new") %> -<% end %> diff --git a/app/views/cluster/show.html.erb b/app/views/cluster/show.html.erb new file mode 100644 index 0000000..3341a7b --- /dev/null +++ b/app/views/cluster/show.html.erb @@ -0,0 +1,3 @@ +<%= c("page") do %> + <%= c("cluster-view") %> +<% end %> diff --git a/frontend/components/cluster-list/_cluster-list.html.erb b/frontend/components/cluster-list/_cluster-list.html.erb index e69de29..f98db37 100644 --- a/frontend/components/cluster-list/_cluster-list.html.erb +++ b/frontend/components/cluster-list/_cluster-list.html.erb @@ -0,0 +1,5 @@ +
+ <% clusters.each do |cluster| %> + <%= c("cluster", cluster: cluster) %> + <% end %> +
diff --git a/frontend/components/cluster-list/cluster-list.js b/frontend/components/cluster-list/cluster-list.js index 9311c03..9b83c61 100644 --- a/frontend/components/cluster-list/cluster-list.js +++ b/frontend/components/cluster-list/cluster-list.js @@ -1 +1,3 @@ import "./cluster-list.pcss"; + +import "components/cluster/cluster"; diff --git a/frontend/components/cluster-list/cluster-list.pcss b/frontend/components/cluster-list/cluster-list.pcss index 545eb34..e9daea7 100644 --- a/frontend/components/cluster-list/cluster-list.pcss +++ b/frontend/components/cluster-list/cluster-list.pcss @@ -1 +1,4 @@ -/* placeholder */ +.cluster-list { + line-height: 1.5; + margin-bottom: 2rem; +} diff --git a/frontend/components/cluster-new/cluster-new.pcss b/frontend/components/cluster-new/cluster-new.pcss index f847653..e3df3ed 100644 --- a/frontend/components/cluster-new/cluster-new.pcss +++ b/frontend/components/cluster-new/cluster-new.pcss @@ -1,10 +1,4 @@ .create-cluster-form { - display: flex; - justify-content: center; - align-items: center; - width: 100%; - height: 100%; - & input { width: 100%; padding: 12px 0; diff --git a/frontend/components/cluster-view/_cluster-view.html.erb b/frontend/components/cluster-view/_cluster-view.html.erb new file mode 100644 index 0000000..47fad75 --- /dev/null +++ b/frontend/components/cluster-view/_cluster-view.html.erb @@ -0,0 +1,4 @@ +
+ <%= c("cluster-list", clusters: @clusters.values) %> + <%= c("cluster-new") %> +
diff --git a/frontend/components/cluster-view/cluster-view.css b/frontend/components/cluster-view/cluster-view.css new file mode 100644 index 0000000..900190d --- /dev/null +++ b/frontend/components/cluster-view/cluster-view.css @@ -0,0 +1,8 @@ +.cluster-view { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + width: 100%; + height: 100%; +} diff --git a/frontend/components/cluster-view/cluster-view.js b/frontend/components/cluster-view/cluster-view.js new file mode 100644 index 0000000..512314b --- /dev/null +++ b/frontend/components/cluster-view/cluster-view.js @@ -0,0 +1,4 @@ +import "./cluster-view.css"; + +import "components/cluster-new/cluster-new"; +import "components/cluster-list/cluster-list"; diff --git a/frontend/components/cluster/_cluster.html.erb b/frontend/components/cluster/_cluster.html.erb new file mode 100644 index 0000000..c123919 --- /dev/null +++ b/frontend/components/cluster/_cluster.html.erb @@ -0,0 +1,6 @@ + + + + <%= cluster.name %> + created on <%= cluster.created_on.strftime("%Y-%m-%d %H:%M:%S")%> + diff --git a/frontend/components/cluster/cluster.js b/frontend/components/cluster/cluster.js new file mode 100644 index 0000000..d2f1705 --- /dev/null +++ b/frontend/components/cluster/cluster.js @@ -0,0 +1 @@ +import "./cluster.pcss"; diff --git a/frontend/components/cluster/cluster.pcss b/frontend/components/cluster/cluster.pcss new file mode 100644 index 0000000..fb5b07c --- /dev/null +++ b/frontend/components/cluster/cluster.pcss @@ -0,0 +1,40 @@ +.cluster { + align-items: center; + display: flex; + justify-content: flex-start; + padding: 0.5em 0.75em; + + & .panel-icon { + display: inline-block; + font-size: 14px; + height: 1em; + line-height: 1em; + text-align: center; + vertical-align: top; + width: 1em; + color: #7a7a7a; + margin-right: 0.75em; + } + + & .panel-text { + font-weight: 800; + margin-right: 0.5rem; + } + + & .panel-subtext { + font-weight: 100; + opacity: 40%; + } + &:hover, + &:focus { + background-color: #f5f5f5; + + & .panel-icon { + color: #3273dc; + } + } + + &:not(:last-child) { + border-bottom: 1px solid #ededed; + } +} diff --git a/frontend/init/index.pcss b/frontend/init/index.pcss index 4a96efc..734bc6b 100644 --- a/frontend/init/index.pcss +++ b/frontend/init/index.pcss @@ -5,3 +5,8 @@ body { font-size: 16px; line-height: 24px; } + +a { + color: inherit; + text-decoration: none; +} diff --git a/frontend/packs/application.js b/frontend/packs/application.js index d120a0c..f39197d 100644 --- a/frontend/packs/application.js +++ b/frontend/packs/application.js @@ -1,5 +1,4 @@ import "init"; import "components/page/page"; -import "components/cluster-list/cluster-list"; -import "components/cluster-new/cluster-new"; +import "components/cluster-view/cluster-view";