From 699caa0fb58fbe1890dc944e009378f12d3dd91a Mon Sep 17 00:00:00 2001 From: Kanishk Chhabra <67221487+mrkc2303@users.noreply.github.com> Date: Fri, 4 Oct 2024 20:10:07 -0500 Subject: [PATCH 1/5] dev: demo dashboard created sucessfully --- app/assets/stylesheets/dashboard.css | 80 +++++++++++++++++++ app/controllers/dashboard_controller.rb | 36 +++++++++ app/models/dashboard.rb | 12 +++ app/views/dashboard/show.html.erb | 33 ++++++++ app/views/games/_all_pages_nav.html.erb | 2 +- config/routes.rb | 2 + features/dashboard.feature | 17 ++++ features/step_definitions/dashboard_steps.rb | 30 +++++++ spec/controllers/dashboard_controller_spec.rb | 38 +++++++++ 9 files changed, 249 insertions(+), 1 deletion(-) create mode 100644 app/assets/stylesheets/dashboard.css create mode 100644 app/controllers/dashboard_controller.rb create mode 100644 app/models/dashboard.rb create mode 100644 app/views/dashboard/show.html.erb create mode 100644 features/dashboard.feature create mode 100644 features/step_definitions/dashboard_steps.rb create mode 100644 spec/controllers/dashboard_controller_spec.rb diff --git a/app/assets/stylesheets/dashboard.css b/app/assets/stylesheets/dashboard.css new file mode 100644 index 00000000..a44d88c7 --- /dev/null +++ b/app/assets/stylesheets/dashboard.css @@ -0,0 +1,80 @@ +/* Game History Container */ +.game-history { + display: flex; + justify-content: space-between; + padding: 20px; + background-color: #e0e0e0; /* Light gray background */ + border-radius: 10px; + margin-bottom: 20px; + } + + /* Each Stat Card */ + .game-history .stat-card { + flex: 1; + background-color: #333; + color: #fff; + padding: 20px; + margin: 0 10px; + text-align: center; + border-radius: 10px; + box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); + } + + .game-history .stat-card h3 { + font-size: 2.5rem; + margin-bottom: 10px; + } + + .game-history .stat-card p { + font-size: 1.2rem; + color: #ccc; + } + + .stat-label { + font-size: 0.9rem; + color: #aaa; + } + + /* Game Cards Container */ + .game-list { + display: grid; + grid-template-columns: repeat(2, 1fr); + grid-gap: 20px; + } + + .game-card { + background-color: #333; + color: #fff; + padding: 20px; + border-radius: 10px; + box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); + } + + .game-card h4 { + font-size: 1.5rem; + color: #fff; + margin-bottom: 10px; + } + + .game-card p { + font-size: 1rem; + margin: 5px 0; + color: #ccc; + } + + .game-card p.status { + color: green; + font-weight: bold; + } + + /* Responsive Design */ + @media (max-width: 768px) { + .game-history { + flex-direction: column; + gap: 10px; + } + + .game-list { + grid-template-columns: 1fr; + } + } \ No newline at end of file diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb new file mode 100644 index 00000000..d73a0919 --- /dev/null +++ b/app/controllers/dashboard_controller.rb @@ -0,0 +1,36 @@ +class DashboardController < ApplicationController + before_action :require_login, only: [:show] + + def show + # Dummy data to simulate user statistics + @dummy_dashboard = { + user_id: 1, + total_games_played: 950, + total_games_won: 450, + last_played: time_ago_in_words(Time.parse('2024-09-27')), + current_streak: 12, + longest_streak: 15 + } + + # Dummy data to simulate game history + @dummy_games = [ + { name: 'Spelling Bee', played_on: '2024-09-27', status: 'Won', points: 1354 }, + { name: 'Wordle', played_on: '2024-09-27', status: 'Won', points: 1354 }, + { name: 'Letter Boxed', played_on: '2024-09-27', status: 'Won', points: 1354 } + ] + end + + private + def time_ago_in_words(from_time) + distance_in_minutes = ((Time.now - from_time) / 60).to_i + + case distance_in_minutes + when 0..59 + "#{distance_in_minutes}m ago" # Minutes ago + when 60..1439 + "#{distance_in_minutes / 60}h ago" # Hours ago + else + "#{distance_in_minutes / 1440}d ago" # Days ago + end + end + end \ No newline at end of file diff --git a/app/models/dashboard.rb b/app/models/dashboard.rb new file mode 100644 index 00000000..12cc1678 --- /dev/null +++ b/app/models/dashboard.rb @@ -0,0 +1,12 @@ +class Dashboard < ApplicationRecord + # belongs_to :user + # has_many :games + + def update_statistics(game) + self.total_games_played += 1 + self.total_games_won += 1 if game.won? + self.last_played = game.played_on + # Logic for streaks goes here + self.save + end + end \ No newline at end of file diff --git a/app/views/dashboard/show.html.erb b/app/views/dashboard/show.html.erb new file mode 100644 index 00000000..67e7f300 --- /dev/null +++ b/app/views/dashboard/show.html.erb @@ -0,0 +1,33 @@ +<%= stylesheet_link_tag 'dashboard', media: 'all', 'data-turbolinks-track': 'reload' %> +<%= render "/games/all_pages_nav" %> +

Welcome to Your Dashboard!

+ +
+ +
+

<%= @dummy_dashboard[:total_games_played] %>

+

Total Games Played

+
+ +
+

<%= @dummy_dashboard[:last_played] %>

+

Last Played

+
+ +
+

<%= @dummy_dashboard[:total_games_won] %>

+

Total Games Won

+
+
+ +

Your Recent Games

+
+ <% @dummy_games.each do |game| %> +
+

<%= game[:name] %>

+

Played on: <%= game[:played_on] %>

+

Status: <%= game[:status] %>

+

Points Earned: <%= game[:points] %>

+
+ <% end %> +
\ No newline at end of file diff --git a/app/views/games/_all_pages_nav.html.erb b/app/views/games/_all_pages_nav.html.erb index 7714854c..a6e5921c 100644 --- a/app/views/games/_all_pages_nav.html.erb +++ b/app/views/games/_all_pages_nav.html.erb @@ -26,7 +26,7 @@