my_forum 0.0.1.beta28 → 0.0.1.beta29

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e9c4dc6e1fd0e4d60d78d975bec3ed7a6a27946
4
- data.tar.gz: c45c52e592f918069fa6879d4a391da75a75e0ae
3
+ metadata.gz: 81f9f7e3ca4c8bdfc291d5e53c27f602f5023b6d
4
+ data.tar.gz: c35fb58614dd1bf75170b626df663a359f6e5b36
5
5
  SHA512:
6
- metadata.gz: 829a37be49a60d7a44676e195ab285cb8004c926d208c003d1cb010cce148ecd6866173c16dc11855afd03ddb63e0c833cca5177fdfc0deed6a22e6ce42e5db8
7
- data.tar.gz: d3cad5b3c19c147d2e48d61279a99fcf8120b2e625eb940d605daa21c2328e7f67e47d836263a45f5d51e170c27371a5398e8178cb02a946983da022c3311417
6
+ metadata.gz: e820b8589722f67d278cf6a5821fb5f184a9ac5ab384f66bff63672214a34f5ce5ecad25e7cbc5ee922723a79d5476783cd0f00dd22e60a654a24ad6e18702f0
7
+ data.tar.gz: 4c38f98ecf6fdc739b0ec517dab58cc7562f7f38ae1abce7ebe3f2eb9adb71850b2274ac11a54ae7edd8102585806c8b582221610e5b600c8933b90f768bd083
@@ -1,3 +1,13 @@
1
+ .profile-popover {
2
+ width: 360px;
3
+ font-size: 11px;
4
+ color: #000;
5
+
6
+ .pm {
7
+ margin-top: 10px;
8
+ }
9
+ }
10
+
1
11
  .topic_posts_info {
2
12
  background-color: #d3daed;
3
13
  color: #fff;
@@ -14,11 +24,19 @@
14
24
  border: 1px solid #DFDFDF;
15
25
  background-color: #fff;
16
26
 
27
+ .user_profile_popover {
28
+ cursor: pointer;
29
+ }
30
+
17
31
  .post_from_user_login {
18
32
  font-weight: bold;
19
33
  color: #c1ccf5;
20
34
  }
21
35
 
36
+ .post_from_user_login .login:hover {
37
+ color: #fff;
38
+ }
39
+
22
40
  .post-header {
23
41
  height: 36px;
24
42
  line-height: 36px;
@@ -3,7 +3,7 @@ module MyForum
3
3
 
4
4
  before_filter :user_activity
5
5
 
6
- helper_method :attachment_img_path, :emoticons_list
6
+ helper_method :attachment_img_path, :emoticons_list, :is_admin?
7
7
 
8
8
  def authenticate_user!
9
9
  redirect_to admin_signin_path unless current_user
@@ -19,6 +19,11 @@ module MyForum
19
19
  end
20
20
  helper_method :current_user_id
21
21
 
22
+ def is_admin?
23
+ return false unless current_user
24
+ current_user.is_admin?
25
+ end
26
+
22
27
  def current_user_groups
23
28
  return [].push UserGroup::GUEST_GROUP.name unless current_user
24
29
  current_user.user_groups.map &:name
@@ -2,7 +2,8 @@ require_dependency "my_forum/application_controller"
2
2
 
3
3
  module MyForum
4
4
  class TopicsController < ApplicationController
5
- before_filter :find_forum, only: [:new, :create, :show]
5
+ before_filter :find_forum, only: [:new, :create, :show]
6
+ before_filter :check_is_admin, only: [:pin, :close, :delete]
6
7
 
7
8
  def new
8
9
  @topic = @forum.topics.build
@@ -33,8 +34,34 @@ module MyForum
33
34
  redirect_to forum_path(@forum)
34
35
  end
35
36
 
37
+ def pin
38
+ return unless topic = Topic.find_by_id(params[:topic_id])
39
+ topic.toggle!(:pinned)
40
+
41
+ redirect_to forum_topic_path(topic.forum, topic)
42
+ end
43
+
44
+ def close
45
+ return unless topic = Topic.find_by_id(params[:topic_id])
46
+ topic.toggle!(:closed)
47
+
48
+ redirect_to forum_topic_path(topic.forum, topic)
49
+ end
50
+
51
+ def delete
52
+ return unless topic = Topic.find_by_id(params[:topic_id])
53
+ topic.update!(deleted: true)
54
+
55
+ redirect_to forum_path(topic.forum)
56
+ end
57
+
36
58
  private
37
59
 
60
+ def check_is_admin
61
+ return unless current_user
62
+ return unless current_user.is_admin?
63
+ end
64
+
38
65
  def find_forum
39
66
  @forum = Forum.find(params[:forum_id])
40
67
  end
@@ -8,7 +8,9 @@ module MyForum
8
8
  end
9
9
 
10
10
  def can_quick_answer?(forum)
11
- return false unless current_user
11
+ return false unless current_user
12
+ return true if is_admin?
13
+ return false if forum.closed?
12
14
  true
13
15
  end
14
16
 
@@ -17,6 +17,10 @@ module MyForum
17
17
  user.posts_count
18
18
  end
19
19
 
20
+ def is_online_user?(user_login)
21
+ User.online.pluck(:login).include?(user_login)
22
+ end
23
+
20
24
  def online_user_marker(user_login)
21
25
  return unless User.online.pluck(:login).include?(user_login)
22
26
  content_tag :div, '&nbsp;'.html_safe, class: 'label label-success'
@@ -34,7 +34,7 @@ module MyForum
34
34
  FROM my_forum_topics
35
35
  JOIN my_forum_posts ON my_forum_posts.id = my_forum_topics.latest_post_id
36
36
  JOIN my_forum_users ON my_forum_posts.user_id = my_forum_users.id
37
- WHERE my_forum_topics.forum_id = #{self.id}
37
+ WHERE my_forum_topics.forum_id = #{self.id} AND my_forum_topics.deleted IS FALSE
38
38
  ORDER BY my_forum_posts.id DESC
39
39
  ", page: page, per_page: per_page)
40
40
  end
@@ -48,7 +48,7 @@ module MyForum
48
48
  FROM my_forum_topics
49
49
  JOIN my_forum_posts ON my_forum_posts.id = my_forum_topics.latest_post_id
50
50
  JOIN my_forum_users ON my_forum_posts.user_id = my_forum_users.id
51
- WHERE my_forum_topics.id NOT IN (#{log_topic_ids.join(',')})
51
+ WHERE my_forum_topics.id NOT IN (#{log_topic_ids.join(',')}) AND my_forum_topics.deleted IS FALSE
52
52
  ORDER BY my_forum_posts.id DESC
53
53
  ", page: page, per_page: per_page)
54
54
  end
@@ -4,6 +4,8 @@ module MyForum
4
4
  belongs_to :forum, counter_cache: true
5
5
  belongs_to :user
6
6
 
7
+ default_scope { where(deleted: false) }
8
+
7
9
  def info
8
10
  author = (post = posts.first).user.login
9
11
  created = post.created_at
@@ -13,9 +13,9 @@
13
13
  .form-group= form.text_field :recipient, value: @reply_pm.sender_login, class: 'subject form-control'
14
14
  .form-group= form.text_field :subject, value: @reply_pm.subject ,class: 'subject form-control', placeholder: t('.subject')
15
15
  - else
16
- .form-group= form.text_field :recipient, class: 'subject form-control autocomplete', placeholder: t('.recipient'), data: { autocomplete_path: autocomplete_users_path }
16
+ .form-group= form.text_field :recipient, value: params[:to], class: 'subject form-control autocomplete', placeholder: t('.recipient'), data: { autocomplete_path: autocomplete_users_path }
17
17
  .form-group= form.text_field :subject, class: 'subject form-control', placeholder: t('.subject')
18
18
 
19
19
  .form-group= form.text_area :body, class: 'body form-control', placeholder: t('.body')
20
20
 
21
- = form.submit class: 'btn btn-primary btn-sm'
21
+ = form.submit t('.send'), class: 'btn btn-primary btn-sm'
@@ -1,10 +1,12 @@
1
1
  - post_counter += 1
2
2
 
3
3
  .row.post-header{ id: "post_number_#{post_counter}"}
4
- .col-md-10.post_from_user_login
5
- - user_login = post.user.try(:login)
6
- = online_user_marker(user_login)
7
- = user_login
4
+ .col-md-10
5
+ %span.post_from_user_login
6
+ - user_login = post.user.try(:login)
7
+ %span.user_profile_popover{ title: user_login, data: { toggle: 'popover', content: (render partial: 'profile_popover', locals: { user: post.user })}}
8
+ = online_user_marker(user_login)
9
+ %span.login= user_login
8
10
  .col-md-2.post_number.text-right
9
11
  - # TODO optimize condition!
10
12
  - if current_user and current_user.is_admin? and post.topic.posts.first != post
@@ -0,0 +1,22 @@
1
+ .profile-popover
2
+ .row
3
+ .col-sm-5
4
+ = t('my_forum.profile_popover.posts_count')
5
+ .col-sm-4
6
+ = user.posts_count
7
+
8
+ .row
9
+ .col-sm-5
10
+ = t('my_forum.profile_popover.registered_at')
11
+ .col-sm-4
12
+ = time(user.created_at)
13
+
14
+ .row
15
+ .col-sm-5
16
+ = t('my_forum.profile_popover.status')
17
+ .col-sm-4
18
+ = is_online_user?(user.login) ? t('my_forum.profile_popover.online') : t('my_forum.profile_popover.offline')
19
+
20
+ .row.pm
21
+ .col-sm-12
22
+ = link_to t('my_forum.profile_popover.write_pm'), new_private_message_path(to: user.login), class: 'btn btn-xs btn-warning'
@@ -16,14 +16,49 @@
16
16
  .row
17
17
  = will_paginate @topic_posts
18
18
 
19
+ - if is_admin?
20
+ .row
21
+ - options = { method: :patch, data: { confirm: t('.are_you_sure?') } }
22
+
23
+ - @topic.pinned? ? options.merge!(class: 'btn btn-sm btn-info') : options.merge!(class: 'btn btn-sm btn-warning')
24
+ = link_to (@topic.pinned? ? t('.unpin_topic') : t('.pin_topic')), forum_topic_pin_path(@topic.forum, @topic), options
25
+
26
+ - @topic.closed? ? options.merge!(class: 'btn btn-sm btn-info') : options.merge!(class: 'btn btn-sm btn-danger')
27
+ = link_to (@topic.closed? ? t('.unlock_topic') : t('.lock_topic')), forum_topic_close_path(@topic.forum, @topic), options
28
+
29
+ - options.merge!(class: 'btn btn-sm btn-danger')
30
+ = link_to t('.delete_topic'), forum_topic_delete_path(@topic.forum, @topic), options
31
+
19
32
  - if can_quick_answer?(@topic)
20
33
  #quick_answer
34
+ - if @topic.closed?
35
+ .alert.alert-danger=t('.warning_closed_topic')
21
36
  = render 'quick_answer', forum: @forum, topic: @topic
22
37
 
23
38
  :coffee
24
39
  $(document).on 'ready page:load', ->
40
+
41
+ $('.user_profile_popover').popover(
42
+ trigger: 'click'
43
+ html: true
44
+ delay:
45
+ 'show': 100
46
+ 'hide': 200
47
+ ).on('mouseenter', ->
48
+ _this = this
49
+ $(this).popover("show")
50
+ $(this).siblings(".popover").on('mouseleave', ->
51
+ $(_this).popover('hide')
52
+ )
53
+ )
54
+ .on('mouseleave', ->
55
+ _this = this
56
+ setTimeout (-> $(_this).popover("hide") if !$(".popover:hover").length ), 300
57
+ )
58
+
59
+
25
60
  container = $('body')
26
61
  scroll_to = $('post_number_' + "#{params[:show_post]}")
27
62
  scroll_to = 'post_number_' + "#{params[:show_post]}"
28
63
 
29
- $('body').scrollTo(scroll_to);
64
+ $('body').scrollTo(scroll_to)
@@ -3,6 +3,15 @@ ru:
3
3
  my_forum:
4
4
  mailer:
5
5
  new_pm_notification_subject: 'Уведомление о новом личном сообщении'
6
+
7
+ profile_popover:
8
+ posts_count: 'Сообщений на форуме: '
9
+ registered_at: 'Дата регистрации: '
10
+ status: 'Текущий статус:'
11
+ online: 'на форуме'
12
+ offline: 'не на форуме'
13
+ write_pm: 'Написать ЛС'
14
+
6
15
  today: "Сегодня в %{hhmm}"
7
16
  yesterday: "Вчера в %{hhmm}"
8
17
  create_new_pm: 'Написать личное сообщение'
@@ -71,6 +80,13 @@ ru:
71
80
  create_new_topic_in: "Создать новую тему в '%{topic_name}'"
72
81
  show:
73
82
  messages_in_topic: "Сообщений в теме: %{count}"
83
+ pin_topic: 'Закрепить тему'
84
+ unpin_topic: 'Открепить тему'
85
+ lock_topic: 'Закрыть тему'
86
+ unlock_topic: 'Открыть тему'
87
+ delete_topic: 'Удалить тему'
88
+ are_you_sure?: 'Вы уверены?'
89
+ warning_closed_topic: 'Внимание! Эта тема закрыта, никто кроме вас, не сможет ответить!'
74
90
  user_info:
75
91
  user_posts_count: "%{count} сообщений"
76
92
  quick_answer:
@@ -118,6 +134,8 @@ ru:
118
134
  recipient: 'Кому'
119
135
  subject: 'Тема'
120
136
  body: 'Сообщение'
137
+ new_private_message: 'Написать личное сообщение'
138
+ send: 'Отправить'
121
139
  create:
122
140
  cant_find_recipient: 'Ошибка, пользователя адресата не существует'
123
141
 
data/config/routes.rb CHANGED
@@ -16,6 +16,7 @@ MyForum::Engine.routes.draw do
16
16
 
17
17
  resources :users do
18
18
  patch :avatar_update
19
+
19
20
  collection do
20
21
  get :autocomplete
21
22
  end
@@ -25,6 +26,9 @@ MyForum::Engine.routes.draw do
25
26
 
26
27
  resources :forums, only: [:index, :show] do
27
28
  resources :topics do
29
+ patch :pin
30
+ patch :close
31
+ patch :delete
28
32
  resources :posts
29
33
  end
30
34
  end
@@ -1,3 +1,3 @@
1
1
  module MyForum
2
- VERSION = "0.0.1.beta28"
2
+ VERSION = "0.0.1.beta29"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: my_forum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.beta28
4
+ version: 0.0.1.beta29
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vitaly Omelchenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-21 00:00:00.000000000 Z
11
+ date: 2015-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -254,6 +254,7 @@ files:
254
254
  - app/views/my_forum/private_messages/show.haml
255
255
  - app/views/my_forum/shared/_upload_photo.haml
256
256
  - app/views/my_forum/topics/_post.haml
257
+ - app/views/my_forum/topics/_profile_popover.haml
257
258
  - app/views/my_forum/topics/_quick_answer.haml
258
259
  - app/views/my_forum/topics/_topic_header.haml
259
260
  - app/views/my_forum/topics/_user_info.haml