From c37885692d5f44af4c2eb452897e664993c4fd0f Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Wed, 5 Oct 2016 16:14:44 +0200 Subject: [PATCH 1/4] Add DB index onto checked field of user_notifications --- ...0160928114915_create_user_notifications.rb | 2 +- db/schema.rb | 69 ++++--------------- 2 files changed, 14 insertions(+), 57 deletions(-) diff --git a/db/migrate/20160928114915_create_user_notifications.rb b/db/migrate/20160928114915_create_user_notifications.rb index 7a00c6dcd..4d52905e9 100644 --- a/db/migrate/20160928114915_create_user_notifications.rb +++ b/db/migrate/20160928114915_create_user_notifications.rb @@ -3,7 +3,7 @@ class CreateUserNotifications < ActiveRecord::Migration create_table :user_notifications do |t| t.belongs_to :user, index: true, foreign_key: true t.belongs_to :notification, index: true, foreign_key: true - t.boolean :checked, default: false + t.boolean :checked, default: false, index: true t.timestamps null: false end diff --git a/db/schema.rb b/db/schema.rb index cf70f46da..4a0b0e388 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -63,41 +63,6 @@ ActiveRecord::Schema.define(version: 20161004074754) do add_index "assets", ["file_file_name"], name: "index_assets_on_file_file_name", using: :gist add_index "assets", ["last_modified_by_id"], name: "index_assets_on_last_modified_by_id", using: :btree - create_table "billing_accounts", force: :cascade do |t| - t.string "braintree_customer_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - end - - add_index "billing_accounts", ["braintree_customer_id"], name: "index_billing_accounts_on_braintree_customer_id", using: :btree - - create_table "billing_plans", force: :cascade do |t| - t.string "braintree_plan_id", null: false - t.string "name", null: false - t.string "description" - t.integer "price_cents", default: 0, null: false - t.string "price_currency", default: "USD", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.boolean "main", default: false, null: false - t.integer "max_storage", limit: 8, default: 0 - t.integer "position", default: 0, null: false - t.boolean "free", default: false, null: false - end - - add_index "billing_plans", ["braintree_plan_id"], name: "index_billing_plans_on_braintree_plan_id", using: :btree - - create_table "billing_subscriptions", force: :cascade do |t| - t.string "braintree_subscription_id" - t.integer "billing_account_id", null: false - t.integer "billing_plan_id", null: false - t.boolean "active", default: false, null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - end - - add_index "billing_subscriptions", ["braintree_subscription_id"], name: "index_billing_subscriptions_on_braintree_subscription_id", using: :btree - create_table "checklist_items", force: :cascade do |t| t.string "text", null: false t.boolean "checked", default: false, null: false @@ -280,11 +245,8 @@ ActiveRecord::Schema.define(version: 20161004074754) do t.integer "last_modified_by_id" t.string "description" t.integer "space_taken", limit: 8, default: 1048576, null: false - t.integer "billing_account_id" - t.integer "agile_crm_deal_id", limit: 8 end - add_index "organizations", ["billing_account_id"], name: "index_organizations_on_billing_account_id", using: :btree add_index "organizations", ["created_by_id"], name: "index_organizations_on_created_by_id", using: :btree add_index "organizations", ["last_modified_by_id"], name: "index_organizations_on_last_modified_by_id", using: :btree add_index "organizations", ["name"], name: "index_organizations_on_name", using: :btree @@ -635,6 +597,7 @@ ActiveRecord::Schema.define(version: 20161004074754) do t.datetime "updated_at", null: false end + add_index "user_notifications", ["checked"], name: "index_user_notifications_on_checked", using: :btree add_index "user_notifications", ["notification_id"], name: "index_user_notifications_on_notification_id", using: :btree add_index "user_notifications", ["user_id"], name: "index_user_notifications_on_user_id", using: :btree @@ -665,20 +628,20 @@ ActiveRecord::Schema.define(version: 20161004074754) do add_index "user_projects", ["user_id"], name: "index_user_projects_on_user_id", using: :btree create_table "users", force: :cascade do |t| - t.string "full_name", null: false - t.string "initials", null: false - t.string "email", default: "", null: false - t.string "encrypted_password", default: "", null: false + t.string "full_name", null: false + t.string "initials", null: false + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false + t.integer "sign_in_count", default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" t.string "current_sign_in_ip" t.string "last_sign_in_ip" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.string "avatar_file_name" t.string "avatar_content_type" t.integer "avatar_file_size" @@ -687,7 +650,7 @@ ActiveRecord::Schema.define(version: 20161004074754) do t.datetime "confirmed_at" t.datetime "confirmation_sent_at" t.string "unconfirmed_email" - t.string "time_zone", default: "UTC" + t.string "time_zone", default: "UTC" t.string "invitation_token" t.datetime "invitation_created_at" t.datetime "invitation_sent_at" @@ -695,13 +658,10 @@ ActiveRecord::Schema.define(version: 20161004074754) do t.integer "invitation_limit" t.integer "invited_by_id" t.string "invited_by_type" - t.integer "invitations_count", default: 0 - t.integer "tutorial_status", default: 0, null: false - t.integer "initial_billing_plan_id" - t.datetime "last_seen_at" - t.integer "agile_crm_contact_id", limit: 8 - t.boolean "assignments_notification", default: true - t.boolean "recent_notification", default: true + t.integer "invitations_count", default: 0 + t.integer "tutorial_status", default: 0, null: false + t.boolean "assignments_notification", default: true + t.boolean "recent_notification", default: true end add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree @@ -717,8 +677,6 @@ ActiveRecord::Schema.define(version: 20161004074754) do add_foreign_key "asset_text_data", "assets" add_foreign_key "assets", "users", column: "created_by_id" add_foreign_key "assets", "users", column: "last_modified_by_id" - add_foreign_key "billing_subscriptions", "billing_accounts" - add_foreign_key "billing_subscriptions", "billing_plans" add_foreign_key "checklist_items", "checklists" add_foreign_key "checklist_items", "users", column: "created_by_id" add_foreign_key "checklist_items", "users", column: "last_modified_by_id" @@ -749,7 +707,6 @@ ActiveRecord::Schema.define(version: 20161004074754) do add_foreign_key "my_modules", "users", column: "last_modified_by_id" add_foreign_key "my_modules", "users", column: "restored_by_id" add_foreign_key "notifications", "users", column: "generator_user_id" - add_foreign_key "organizations", "billing_accounts" add_foreign_key "organizations", "users", column: "created_by_id" add_foreign_key "organizations", "users", column: "last_modified_by_id" add_foreign_key "project_comments", "comments" From 56d2240de5ef68224ef6e8748d8a7a46210e4139 Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Wed, 5 Oct 2016 16:19:59 +0200 Subject: [PATCH 2/4] Optimize data query in user_notification.rb --- app/models/user_notification.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/models/user_notification.rb b/app/models/user_notification.rb index 17f9eb275..a99b05895 100644 --- a/app/models/user_notification.rb +++ b/app/models/user_notification.rb @@ -23,9 +23,6 @@ class UserNotification < ActiveRecord::Base end def self.seen_by_user(user) - where(user: user).map do |n| - n.checked = true - n.save - end + where(user: user).where(checked: false).update_all(checked: true) end end From 877574e853b3b4eeb16b784e7b1792be9e5d04bd Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Wed, 5 Oct 2016 16:26:26 +0200 Subject: [PATCH 3/4] Add link to settings from both notification lists --- app/assets/stylesheets/themes/scinote.scss | 4 ++++ app/views/shared/_navigation.html.erb | 2 +- app/views/user_notifications/index.html.erb | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/assets/stylesheets/themes/scinote.scss b/app/assets/stylesheets/themes/scinote.scss index 5c37dc541..d71437ff3 100644 --- a/app/assets/stylesheets/themes/scinote.scss +++ b/app/assets/stylesheets/themes/scinote.scss @@ -159,6 +159,10 @@ table { color: $color-wild-sand; font-weight: bold; padding: 8px; + + a { + color: $color-white; + } } .notifications-dropdown-footer { diff --git a/app/views/shared/_navigation.html.erb b/app/views/shared/_navigation.html.erb index beb4aa14d..187b470b3 100644 --- a/app/views/shared/_navigation.html.erb +++ b/app/views/shared/_navigation.html.erb @@ -69,7 +69,7 @@ data-href="<%= unseen_notification_url(current_user) %>"> diff --git a/app/views/user_notifications/index.html.erb b/app/views/user_notifications/index.html.erb index 3a20af3b0..9376295df 100644 --- a/app/views/user_notifications/index.html.erb +++ b/app/views/user_notifications/index.html.erb @@ -1,7 +1,7 @@ <% provide(:head_title, raw(t("notifications.title"))) %>
- <%= t('notifications.title') %><%= t('nav.user.settings') %> + <%= t('notifications.title') %><%= link_to t('nav.user.settings'), preferences_path %>
    From 5c80c8a8176aa47bee490de9dd909f7ef6256cb2 Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Wed, 5 Oct 2016 16:48:40 +0200 Subject: [PATCH 4/4] Add "no notifications" to dropdown & notifications index page --- app/assets/javascripts/navigation.js | 8 ++++++++ app/assets/stylesheets/notifications.scss | 4 ++++ app/assets/stylesheets/themes/scinote.scss | 6 ++++++ app/views/shared/_navigation.html.erb | 1 + app/views/user_notifications/index.html.erb | 8 +++++++- config/locales/en.yml | 3 +++ 6 files changed, 29 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/navigation.js b/app/assets/javascripts/navigation.js index 6b8a77129..8c7e77092 100644 --- a/app/assets/javascripts/navigation.js +++ b/app/assets/javascripts/navigation.js @@ -15,8 +15,11 @@ function loadDropdownNotifications() { var button = $('#notifications-dropdown'); + var noRecentText = + $('.dropdown-notifications .notifications-no-recent'); button .on('click', function() { + noRecentText.hide(); $.ajax({ url: button.attr('data-href'), type: 'GET', @@ -29,6 +32,11 @@ $('.notifications-dropdown-header') .after(data.html); animateSpinner($('.notifications-dropdown-header'), false); + + var ul = $('.dropdown-menu.dropdown-notifications'); + if (ul.children('.notification').length === 0) { + noRecentText.show(); + } } }); $('#count-notifications').hide(); diff --git a/app/assets/stylesheets/notifications.scss b/app/assets/stylesheets/notifications.scss index dc7594de2..39f126e63 100644 --- a/app/assets/stylesheets/notifications.scss +++ b/app/assets/stylesheets/notifications.scss @@ -33,6 +33,10 @@ &:hover { background-color: $color-mystic; } + + &.no-notifications { + padding-left: 15px; + } } .unseen { diff --git a/app/assets/stylesheets/themes/scinote.scss b/app/assets/stylesheets/themes/scinote.scss index d71437ff3..ce4029f87 100644 --- a/app/assets/stylesheets/themes/scinote.scss +++ b/app/assets/stylesheets/themes/scinote.scss @@ -107,6 +107,12 @@ table { width: 450px; word-wrap: break-word; + .notifications-no-recent { + padding-bottom: 10px; + padding-left: 10px; + padding-top: 10px; + } + .notification { border-bottom: 1px solid $color-alto; padding-bottom: 10px; diff --git a/app/views/shared/_navigation.html.erb b/app/views/shared/_navigation.html.erb index 187b470b3..519d91220 100644 --- a/app/views/shared/_navigation.html.erb +++ b/app/views/shared/_navigation.html.erb @@ -70,6 +70,7 @@ diff --git a/app/views/user_notifications/index.html.erb b/app/views/user_notifications/index.html.erb index 9376295df..0776a8810 100644 --- a/app/views/user_notifications/index.html.erb +++ b/app/views/user_notifications/index.html.erb @@ -5,7 +5,13 @@
    - <%= render 'list', notifications: @notifications %> + <% if @notifications.count > 0 %> + <%= render 'list', notifications: @notifications %> + <% else %> +
  • + <%= t('notifications.no_notifications') %> +
  • + <% end %>