From d29fb8f39adb772360244a697d201ad8216b60eb Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Tue, 10 Mar 2015 13:55:57 +0500 Subject: [PATCH] feed improvements: in progress --- app/controllers/application_controller.rb | 2 +- app/controllers/home_controller.rb | 2 ++ app/models/concerns/feed/build_list.rb | 2 +- app/models/concerns/feed/comment.rb | 6 ++-- app/models/concerns/feed/git.rb | 4 +-- app/models/concerns/feed/issue.rb | 4 +-- app/views/home/_filters.html.slim | 15 ++++++++++ ...{_sidebar.html.haml => _sidebar.html.slim} | 30 +++++++++---------- config/locales/models/activity_feed.en.yml | 10 +++++-- config/locales/models/activity_feed.ru.yml | 4 +++ 10 files changed, 51 insertions(+), 28 deletions(-) create mode 100644 app/views/home/_filters.html.slim rename app/views/home/{_sidebar.html.haml => _sidebar.html.slim} (68%) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ef09b5d33..cfe784c4e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -18,7 +18,7 @@ class ApplicationController < ActionController::Base helper_method :get_owner - unless Rails.env.development? + unless false#Rails.env.development? rescue_from Exception, with: :render_500 rescue_from ActiveRecord::RecordNotFound, # ActionController::RoutingError, # see: config/routes.rb: diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 39495990d..1560be43b 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -9,6 +9,8 @@ class HomeController < ApplicationController @filter = t('feed_menu').has_key?(params[:filter].try(:to_sym)) ? params[:filter].to_sym : :all @activity_feeds = current_user.activity_feeds @activity_feeds = @activity_feeds.where(kind: "ActivityFeed::#{@filter.upcase}".constantize) unless @filter == :all + @activity_feeds = @activity_feeds.where(user_id: current_user) if @own_filter == :created + @activity_feeds = @activity_feeds.where.not(user_id: current_user) if @own_filter == :not_created @activity_feeds = @activity_feeds.paginate page: current_page respond_to do |format| diff --git a/app/models/concerns/feed/build_list.rb b/app/models/concerns/feed/build_list.rb index 49f1ad99e..face782a8 100644 --- a/app/models/concerns/feed/build_list.rb +++ b/app/models/concerns/feed/build_list.rb @@ -20,7 +20,7 @@ module Feed::BuildList ) updater = publisher || user - (project.admins | [publisher].compact).each do |recipient| + (project.all_members | [publisher].compact).each do |recipient| ActivityFeed.create( user: recipient, kind: 'build_list_notification', diff --git a/app/models/concerns/feed/comment.rb b/app/models/concerns/feed/comment.rb index 9fe848bbd..b9f5a1248 100644 --- a/app/models/concerns/feed/comment.rb +++ b/app/models/concerns/feed/comment.rb @@ -14,7 +14,7 @@ module Feed::Comment if issue_comment? commentable.subscribes.each do |subscribe| - if user_id != subscribe.user_id && can_notify_on_new_comment?(subscribe) + if user_id == subscribe.user_id || can_notify_on_new_comment?(subscribe) UserMailer.new_comment_notification(self, subscribe.user_id).deliver ActivityFeed.create( { @@ -38,8 +38,8 @@ module Feed::Comment end elsif commit_comment? Subscribe.comment_subscribes(self).where(status: true).each do |subscribe| - next if !subscribe.user_id || own_comment?(subscribe.user) - if subscribe.user.notifier.can_notify && + next if !subscribe.user_id + if subscribe.user.notifier.can_notify && !own_comment?(subscribe.user) ( (subscribe.project.owner?(subscribe.user) && subscribe.user.notifier.new_comment_commit_repo_owner) || (subscribe.user.commentor?(self.commentable) && subscribe.user.notifier.new_comment_commit_commentor) || (subscribe.user.committer?(self.commentable) && subscribe.user.notifier.new_comment_commit_owner) ) diff --git a/app/models/concerns/feed/git.rb b/app/models/concerns/feed/git.rb index b79c3618f..e3976f34a 100644 --- a/app/models/concerns/feed/git.rb +++ b/app/models/concerns/feed/git.rb @@ -47,12 +47,12 @@ module Feed::Git options.merge!({user_id: record.user.id, user_name: record.user.name, user_email: record.user.email}) if record.user record.project.admins.each do |recipient| - next if record.user && record.user.id == recipient.id ActivityFeed.create!( user: recipient, kind: kind, data: options ) + next if record.user && record.user.id == recipient.id if recipient.notifier.can_notify && recipient.notifier.update_code UserMailer.send(kind, recipient, options).deliver end @@ -63,8 +63,6 @@ module Feed::Git project = Project.find record[:project_id] project.admins.each do |recipient| - next if actor && actor.id == recipient.id - ActivityFeed.create!( user: recipient, kind: 'wiki_new_commit_notification', diff --git a/app/models/concerns/feed/issue.rb b/app/models/concerns/feed/issue.rb index f57f0fce0..230cf1558 100644 --- a/app/models/concerns/feed/issue.rb +++ b/app/models/concerns/feed/issue.rb @@ -15,8 +15,8 @@ module Feed::Issue def new_issue_notifications collect_recipients.each do |recipient| - next if user_id == recipient.id - if recipient.notifier.can_notify && recipient.notifier.new_issue && assignee_id != recipient.id + if user_id != recipient.id && recipient.notifier.can_notify && + recipient.notifier.new_issue && assignee_id != recipient.id UserMailer.new_issue_notification(id, recipient.id).deliver end ActivityFeed.create( diff --git a/app/views/home/_filters.html.slim b/app/views/home/_filters.html.slim new file mode 100644 index 000000000..a33859664 --- /dev/null +++ b/app/views/home/_filters.html.slim @@ -0,0 +1,15 @@ +hr.offset10 + h3=t('layout.relations.filters') + +input.form-control[ name = 'search' + size = 30 + type = 'text' + ng-model = 'search' + placeholder = t('layout.find_project') + ng-change = 'filterProjects()' ] + +ul.nav.nav-pills.nav-stacked + - options_for_filters(@projects, @groups, @owners).each do |options| + li{ 'ng-class' => "{active: #{options[:class_name]}_filter_#{options[:id]}_class}" } + a{ href: '#', 'ng-click' => "change_#{options[:class_name]}_filter(#{options[:id]})" } + = options[:uname] diff --git a/app/views/home/_sidebar.html.haml b/app/views/home/_sidebar.html.slim similarity index 68% rename from app/views/home/_sidebar.html.haml rename to app/views/home/_sidebar.html.slim index ecccaa8aa..2bd327745 100644 --- a/app/views/home/_sidebar.html.haml +++ b/app/views/home/_sidebar.html.slim @@ -1,29 +1,29 @@ -%p +p = link_to t('layout.activity_feed.new_project'), new_project_path, class: 'btn btn-primary btn-small', role: 'button' -%hr -%h5= t('layout.activity_feed.my_last_projects') +hr +h5= t('layout.activity_feed.my_last_projects') -%ul.nav.nav-pills.nav-stacked +ul.nav.nav-pills.nav-stacked - current_user.projects.order(updated_at: :desc).limit(5).each do |project| - %li + li = link_to project_path(project) do = fa_visibility_icon project = project.name_with_owner - %li + li = link_to t('layout.activity_feed.all_my_projects'), projects_path -%hr +hr - midnight = Time.now.utc.to_date -%h5= t 'layout.activity_feed.my_builds_by_day' -%ul.nav.nav-pills.nav-stacked +h5= t 'layout.activity_feed.my_builds_by_day' +ul.nav.nav-pills.nav-stacked - ['BuildList::BUILD_PUBLISHED', 'BuildList::SUCCESS', 'BuildList::BUILD_STARTED', 'BuildList::BUILD_PENDING', 'BuildList::BUILD_ERROR'].each do |state| - %li - %a{ href: build_lists_path(filter: {status: state.constantize, 'updated_at_start(1i)' => midnight.year, - 'updated_at_start(2i)' => midnight.month, 'updated_at_start(3i)' => midnight.day}) } - %span.badge.pull-right + li + a[ href = build_lists_path(filter: {status: state.constantize, 'updated_at_start(1i)' => midnight.year, + 'updated_at_start(2i)' => midnight.month, 'updated_at_start(3i)' => midnight.day}) ] + span.badge.pull-right = BuildList.for_status(state.constantize).for_user(current_user).for_notified_date_period(midnight, nil).count = t "layout.build_lists.statuses.#{state.demodulize.downcase}" - %li - %a{ href: build_lists_path }=t 'layout.activity_feed.all_my_builds' \ No newline at end of file + li + a[ href = build_lists_path ]=t 'layout.activity_feed.all_my_builds' diff --git a/config/locales/models/activity_feed.en.yml b/config/locales/models/activity_feed.en.yml index cdea9e975..68314ca55 100644 --- a/config/locales/models/activity_feed.en.yml +++ b/config/locales/models/activity_feed.en.yml @@ -1,6 +1,6 @@ en: layout: - activity_feed: + activity_feed: header: Activity Feed my_last_projects: My last projects all_my_projects: All my projects @@ -9,6 +9,10 @@ en: new_project: Create project load_messages: show previous messages atom_title: Activity Feed + filters: + all: All + my: Mine + others: Others notifications: subjects: @@ -24,12 +28,12 @@ en: bodies: view_it_on: View it on - new_comment_notification: + new_comment_notification: title: '%{user_link} added a new comment' content: in issue %{issue_link} commit_content: in commit %{commit_link} new_issue_notification: '%{user_link} added a new issue' - new_user_notification: + new_user_notification: title: Hello, %{user_name}. content: You have registered in project «ROSA ABF» and now you can sign in. email: ==Your email %{user_email} diff --git a/config/locales/models/activity_feed.ru.yml b/config/locales/models/activity_feed.ru.yml index 3f5988f86..fee899c8d 100644 --- a/config/locales/models/activity_feed.ru.yml +++ b/config/locales/models/activity_feed.ru.yml @@ -9,6 +9,10 @@ ru: new_project: Создать проект load_messages: показать предыдущие сообщения atom_title: Лента активности + filters: + all: Вся + my: Моя + others: Чужая notifications: subjects: