From f08dd50aa724f28f0a909fa63523cfcd4a863323 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Clibaumann=E2=80=9D?= Date: Tue, 20 Dec 2022 16:43:12 +0100 Subject: [PATCH 1/3] add button design and translation --- app/controllers/dashboard_controller.rb | 1 + app/views/dashboard/index.html.erb | 36 ++++++++++++++++++----- config/locales/de.yml | 2 +- config/locales/en.yml | 2 +- spec/features/dashboard/dashboard_spec.rb | 4 +-- 5 files changed, 33 insertions(+), 12 deletions(-) diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 4ce323ca..35b8fa2b 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -1,5 +1,6 @@ class DashboardController < ApplicationController def index @user = current_user + @unread_notifications_num = 0 end end diff --git a/app/views/dashboard/index.html.erb b/app/views/dashboard/index.html.erb index da902f0c..3c1f25fb 100644 --- a/app/views/dashboard/index.html.erb +++ b/app/views/dashboard/index.html.erb @@ -25,20 +25,37 @@ margin-bottom: 7px; } - .box { - width: 350px; - border: 1px solid black; - padding: 5px; - margin: 5px; - margin-bottom: 15px; + .button { + border: none; + color: white; + padding: 10px 20px; + text-align: center; + text-decoration: none; + display: inline-block; + margin: 4px 2px; + cursor: pointer; + font-family: Roboto, sans-serif; + font-weight: bold; + font-size: 20px; + spacing: auto spacing; + margin-bottom: 12px; + <% if @unread_notifications_num > 0 %> + background-color: #2596be; + <% else %> + background-color: #7cc0d8; + <% end %> + } + + .button:hover { + color: white; } + <% if user_signed_in? %>

<%= t('views.dashboard.greeting', name: @user.first_name)%>

- -

<%= t 'views.dashboard.unread_messages' %>

+ <%= t('views.dashboard.unread_messages', num: @unread_notifications_num) %>

<%= t 'views.dashboard.lent_items.title' %>

@@ -60,3 +77,6 @@ <%= t 'views.landing_page.signup' %> <% end %> <% end %> + + + diff --git a/config/locales/de.yml b/config/locales/de.yml index e14ffeb7..e2abe1bf 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -18,7 +18,7 @@ de: title: "Übersicht" greeting: "Hallo, %{name}!" not_signed_in: "Du bist nicht angemeldet." - unread_messages: "Du hast ... ungelesene Nachrichten" + unread_messages: "Du hast %{num} ungelesene Nachrichten" lent_items: title: "AUSGELIEHENE ARTIKEL" offered_items: diff --git a/config/locales/en.yml b/config/locales/en.yml index 160e39c3..4a634dde 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -49,7 +49,7 @@ en: title: "Dashboard" greeting: "Hello, %{name}!" not_signed_in: "You are not signed in." - unread_messages: "You have ... unread messages" + unread_messages: "You have %{num} unread messages" lent_items: title: "LENT ITEMS" offered_items: diff --git a/spec/features/dashboard/dashboard_spec.rb b/spec/features/dashboard/dashboard_spec.rb index f4cddf3a..741e4533 100644 --- a/spec/features/dashboard/dashboard_spec.rb +++ b/spec/features/dashboard/dashboard_spec.rb @@ -16,10 +16,10 @@ expect(page).to have_content(@user.first_name) end - it "shows unread messages" do + it "shows unread messages and links to notifications" do sign_in user visit dashboard_path - expect(page).to have_content I18n.t('views.dashboard.unread_messages') + expect(page).to have_selector("a[href='/notifications']") end it "shows lent items" do From 1e5901f5887c815b93c09f50fdbec498f3fc92e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Clibaumann=E2=80=9D?= Date: Mon, 2 Jan 2023 21:00:21 +0100 Subject: [PATCH 2/3] add test and rubocop, acess notifications from view directly --- app/views/dashboard/index.html.erb | 2 +- spec/features/dashboard/dashboard_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/dashboard/index.html.erb b/app/views/dashboard/index.html.erb index 3c1f25fb..4f31725d 100644 --- a/app/views/dashboard/index.html.erb +++ b/app/views/dashboard/index.html.erb @@ -55,7 +55,7 @@ <% if user_signed_in? %>

<%= t('views.dashboard.greeting', name: @user.first_name)%>

- <%= t('views.dashboard.unread_messages', num: @unread_notifications_num) %> + <%= t('views.dashboard.unread_messages', num: @user.notifications.size) %>

<%= t 'views.dashboard.lent_items.title' %>

diff --git a/spec/features/dashboard/dashboard_spec.rb b/spec/features/dashboard/dashboard_spec.rb index 741e4533..7613d904 100644 --- a/spec/features/dashboard/dashboard_spec.rb +++ b/spec/features/dashboard/dashboard_spec.rb @@ -19,7 +19,7 @@ it "shows unread messages and links to notifications" do sign_in user visit dashboard_path - expect(page).to have_selector("a[href='/notifications']") + expect(page).to have_link(href: '/notifications') end it "shows lent items" do From 831f08ba9a13ac0f9bf43112f37b3a38819b23eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Clibaumann=E2=80=9D?= Date: Wed, 4 Jan 2023 19:04:43 +0100 Subject: [PATCH 3/3] add test and button design --- app/controllers/dashboard_controller.rb | 1 - app/views/dashboard/index.html.erb | 11 ++++++----- db/schema.rb | 8 ++++---- spec/features/dashboard/dashboard_spec.rb | 10 +++++++++- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index f03c379a..3dd30ae6 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -2,6 +2,5 @@ class DashboardController < ApplicationController before_action :authenticate_user! def index @user = current_user - @unread_notifications_num = 0 end end diff --git a/app/views/dashboard/index.html.erb b/app/views/dashboard/index.html.erb index dbce9e05..1e451caf 100644 --- a/app/views/dashboard/index.html.erb +++ b/app/views/dashboard/index.html.erb @@ -26,6 +26,7 @@ } .button { + width: 100%; border: none; color: white; padding: 10px 20px; @@ -36,10 +37,10 @@ cursor: pointer; font-family: Roboto, sans-serif; font-weight: bold; - font-size: 20px; + font-size: 16px; spacing: auto spacing; - margin-bottom: 12px; - <% if @unread_notifications_num > 0 %> + margin-bottom: 18px; + <% if user_signed_in? && @user.notifications.where(unread: true).size > 0 %> background-color: #2596be; <% else %> background-color: #7cc0d8; @@ -51,12 +52,11 @@ } -

<%= t('views.dashboard.greeting', name: @user.first_name)%>

<% if user_signed_in? %>

<%= t('views.dashboard.greeting', name: @user.first_name)%>

- <%= t('views.dashboard.unread_messages', num: @user.notifications.size) %> + <%= t('views.dashboard.unread_messages', num: @user.notifications.where(unread: true).size) %>

<%= t 'views.dashboard.lent_items.title' %>

@@ -69,3 +69,4 @@

<%= t 'views.dashboard.wishlist.title' %>

<%= render "wishlist"%> +<% end %> \ No newline at end of file diff --git a/db/schema.rb b/db/schema.rb index c1e59721..004c2a8d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -14,8 +14,8 @@ create_table "active_storage_attachments", force: :cascade do |t| t.string "name", null: false t.string "record_type", null: false - t.bigint "record_id", null: false - t.bigint "blob_id", null: false + t.integer "record_id", null: false + t.integer "blob_id", null: false t.datetime "created_at", null: false t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id" t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true @@ -34,7 +34,7 @@ end create_table "active_storage_variant_records", force: :cascade do |t| - t.bigint "blob_id", null: false + t.integer "blob_id", null: false t.string "variation_digest", null: false t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true end @@ -105,7 +105,7 @@ t.datetime "updated_at", null: false t.string "actable_type" t.integer "actable_id" - t.boolean "active", null: false + t.boolean "active", default: false, null: false t.boolean "unread" t.index ["actable_type", "actable_id"], name: "index_notifications_on_actable" t.index ["user_id"], name: "index_notifications_on_user_id" diff --git a/spec/features/dashboard/dashboard_spec.rb b/spec/features/dashboard/dashboard_spec.rb index 4c6a3748..07b69e9e 100644 --- a/spec/features/dashboard/dashboard_spec.rb +++ b/spec/features/dashboard/dashboard_spec.rb @@ -2,7 +2,10 @@ RSpec.describe "Dashboard", type: :feature do - let(:user) { build(:user) } + let(:password) { 'password' } + let(:user) { create(:user, password: password) } + let(:borrower) { create(:max, password: password) } + let(:item) { create(:item, owner: user.id) } it "redirects to login without user signed in" do visit dashboard_path @@ -20,6 +23,11 @@ sign_in user visit dashboard_path expect(page).to have_link(href: '/notifications') + expect(page).to have_content I18n.t('views.dashboard.unread_messages', num: 0) + @notifications = create_list(:lend_request_notification, 2, user: user, item: item, borrower: borrower) + @notifications.each(&:save) + page.refresh + expect(page).to have_content I18n.t('views.dashboard.unread_messages', num: 2) end it "shows lent items" do