mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-26 17:51:13 +08:00
fixed migrations
This commit is contained in:
parent
cab1e9b521
commit
e1a1b93d44
11 changed files with 181 additions and 27 deletions
|
@ -1,12 +1,51 @@
|
|||
/* Loading overlay for search */
|
||||
$("#search-bar").submit(function (){
|
||||
if( $("#update-canvas") ){
|
||||
$(document.body).spin(true);
|
||||
setTimeout(function(){
|
||||
$(".spinner").remove();
|
||||
}, 1000);
|
||||
} else {
|
||||
animateSpinner();
|
||||
}
|
||||
});
|
||||
(function(){
|
||||
'use strict';
|
||||
|
||||
/* Loading overlay for search */
|
||||
$("#search-bar").submit(function (){
|
||||
if( $("#update-canvas") ){
|
||||
$(document.body).spin(true);
|
||||
setTimeout(function(){
|
||||
$(".spinner").remove();
|
||||
}, 1000);
|
||||
} else {
|
||||
animateSpinner();
|
||||
}
|
||||
});
|
||||
|
||||
function loadDropdownNotifications() {
|
||||
var button = $('#notifications-dropdown');
|
||||
button
|
||||
.on('click', function() {
|
||||
$.ajax({
|
||||
url: button.attr('data-href'),
|
||||
type: 'GET',
|
||||
dataType: 'json',
|
||||
success: function(data) {
|
||||
$('.notifications-dropdown-header')
|
||||
.nextAll('li.notification')
|
||||
.remove();
|
||||
$('.notifications-dropdown-header')
|
||||
.after(data.html);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function loadUnseenNotificationsNumber() {
|
||||
var notificationCount = $('#count-notifications');
|
||||
$.ajax({
|
||||
url: notificationCount.attr('data-href'),
|
||||
type: 'GET',
|
||||
dataType: 'json',
|
||||
success: function(data) {
|
||||
notificationCount.html('');
|
||||
notificationCount.html(data.notificationNmber);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// init
|
||||
loadDropdownNotifications();
|
||||
loadUnseenNotificationsNumber();
|
||||
})();
|
||||
|
|
|
@ -72,6 +72,53 @@ table {
|
|||
max-width: 400px;
|
||||
}
|
||||
|
||||
#notifications-dropdown {
|
||||
.fa-bell {
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
#count-notifications {
|
||||
background-color: $color-theme-primary;
|
||||
color: $color-wild-sand;
|
||||
font-size: 12px;
|
||||
font-weight: bold;
|
||||
z-index: 999999;
|
||||
position: fixed;
|
||||
margin-top: -10px;
|
||||
margin-left: 10px;
|
||||
padding-left: 4px;
|
||||
padding-right: 4px;
|
||||
border-radius: 5px;
|
||||
}
|
||||
}
|
||||
|
||||
@media(max-width:768px) {
|
||||
#count-notifications {
|
||||
position: absolute !important;
|
||||
margin-left: -4px !important;
|
||||
margin-top: 10px !important;
|
||||
}
|
||||
}
|
||||
.dropdown-notifications {
|
||||
min-width: 450px;
|
||||
padding-bottom: 0;
|
||||
padding-top: 0;
|
||||
|
||||
.notifications-dropdown-header {
|
||||
background-color: $color-theme-primary;
|
||||
color: $color-wild-sand;
|
||||
font-weight: bold;
|
||||
padding: 8px;
|
||||
}
|
||||
|
||||
.notifications-dropdown-footer {
|
||||
background-color: $color-mystic;
|
||||
padding: 8px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#search-menu {
|
||||
padding-right: 0;
|
||||
|
||||
|
|
|
@ -1,6 +1,27 @@
|
|||
class UserNotifications < ApplicationController
|
||||
class UserNotificationsController < ApplicationController
|
||||
def recent_notifications
|
||||
@recent_notifications = UserNorifications.recent_notifications
|
||||
@unseen_notification = UserNotifications.unseen_notification
|
||||
@recent_notifications = UserNotification.recent_notifications(current_user)
|
||||
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
render json: {
|
||||
html: render_to_string(
|
||||
partial: 'recent_notifications.html.erb'
|
||||
)
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def unseen_notification
|
||||
@number = UserNotification.unseen_notification(current_user)
|
||||
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
render json: {
|
||||
notificationNmber: @number
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
class Notification < ActiveRecord::Base
|
||||
has_many :user_notifications, inverse_of: :notification
|
||||
has_many :users, through: :user_notifications
|
||||
belongs_to :generator_user, class_name: 'User'
|
||||
|
||||
enum type_of: [:assignment, :recent_changes, :system_message]
|
||||
end
|
||||
|
|
|
@ -2,9 +2,14 @@ class UserNotification < ActiveRecord::Base
|
|||
belongs_to :user
|
||||
belongs_to :notification
|
||||
|
||||
def recent_notifications
|
||||
def self.recent_notifications(user)
|
||||
Notification.joins(:user_notifications)
|
||||
.where('user_notifications.user_id = ?', user.id)
|
||||
.order(created_at: :DESC)
|
||||
.limit(10)
|
||||
end
|
||||
|
||||
def unseen_notification
|
||||
def self.unseen_notification(user)
|
||||
where('user_id = ? AND checked = false', user.id).count
|
||||
end
|
||||
end
|
||||
|
|
|
@ -57,12 +57,21 @@
|
|||
<!-- profile info -->
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
|
||||
<%= fa_icon 'bell' %>
|
||||
<span id="count-notifications">5</span>
|
||||
<a href="#"
|
||||
id="notifications-dropdown"
|
||||
class="dropdown-toggle"
|
||||
data-toggle="dropdown"
|
||||
role="button"
|
||||
aria-haspopup="true"
|
||||
aria-expanded="false"
|
||||
data-href="<%= recent_notifications_url(current_user) %>">
|
||||
<%= fa_icon 'bell'%>
|
||||
<span id="count-notifications"
|
||||
data-href="<%= unseen_notification_url(current_user) %>"></span>
|
||||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
<ul class="dropdown-menu dropdown-notifications">
|
||||
<li class="notifications-dropdown-header"><span><%= t('notifications.title') %></span><span class="pull-right"><%= t('nav.user.settings') %></span></li>
|
||||
<li class="notifications-dropdown-footer">link to method goes here</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="dropdown">
|
||||
|
|
15
app/views/user_notifications/_recent_notifications.html.erb
Normal file
15
app/views/user_notifications/_recent_notifications.html.erb
Normal file
|
@ -0,0 +1,15 @@
|
|||
<% @recent_notifications.each do |notification| %>
|
||||
<li class="notification">
|
||||
<div class="row">
|
||||
<div class="col-md-3">
|
||||
<% byebug %>
|
||||
<% if notification.type_of == :assignment %>
|
||||
<%= image_tag avatar_path(notification.generator_user, :icon_small), class: "avatar" %>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="col-md-9">
|
||||
<strong><%= notification.title %></strong> <br> <%= notification.message %></
|
||||
</div>
|
||||
</div>
|
||||
<li>
|
||||
<% end %>
|
|
@ -32,6 +32,17 @@ Rails.application.routes.draw do
|
|||
get "users/settings/user_organizations/:user_organization_id/destroy_html", to: "users/settings#destroy_user_organization_html", as: "destroy_user_organization_html"
|
||||
delete "users/settings/user_organizations/:user_organization_id", to: "users/settings#destroy_user_organization", as: "destroy_user_organization"
|
||||
|
||||
# Notifications
|
||||
get 'users/:id/recent_notifications',
|
||||
to: 'user_notifications#recent_notifications',
|
||||
as: 'recent_notifications',
|
||||
defaults: { format: 'json' }
|
||||
|
||||
get 'users/:id/unseen_notification',
|
||||
to: 'user_notifications#unseen_notification',
|
||||
as: 'unseen_notification',
|
||||
defaults: { format: 'json' }
|
||||
|
||||
resources :organizations, only: [] do
|
||||
resources :samples, only: [:new, :create]
|
||||
resources :sample_types, only: [:new, :create]
|
||||
|
|
|
@ -4,9 +4,11 @@ class CreateNotifications < ActiveRecord::Migration
|
|||
t.string :title
|
||||
t.string :message
|
||||
t.integer :type_of, null: false
|
||||
t.integer :generator_user_id
|
||||
|
||||
t.timestamps null: false
|
||||
end
|
||||
add_index :notifications, :created_at
|
||||
add_foreign_key :notifications, :users, column: :generator_user_id
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
||||
t.boolean :checked, default: false
|
||||
|
||||
t.timestamps null: false
|
||||
end
|
||||
|
|
14
db/schema.rb
14
db/schema.rb
|
@ -229,9 +229,10 @@ ActiveRecord::Schema.define(version: 20160928114915) do
|
|||
create_table "notifications", force: :cascade do |t|
|
||||
t.string "title"
|
||||
t.string "message"
|
||||
t.integer "type_of", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "type_of", null: false
|
||||
t.integer "generator_user_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
add_index "notifications", ["created_at"], name: "index_notifications_on_created_at", using: :btree
|
||||
|
@ -591,9 +592,9 @@ ActiveRecord::Schema.define(version: 20160928114915) do
|
|||
create_table "user_notifications", force: :cascade do |t|
|
||||
t.integer "user_id"
|
||||
t.integer "notification_id"
|
||||
t.boolean "checked"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.boolean "checked", default: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
add_index "user_notifications", ["notification_id"], name: "index_user_notifications_on_notification_id", using: :btree
|
||||
|
@ -702,6 +703,7 @@ ActiveRecord::Schema.define(version: 20160928114915) do
|
|||
add_foreign_key "my_modules", "users", column: "created_by_id"
|
||||
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", "users", column: "created_by_id"
|
||||
add_foreign_key "organizations", "users", column: "last_modified_by_id"
|
||||
add_foreign_key "project_comments", "comments"
|
||||
|
|
Loading…
Reference in a new issue