my_forum 0.0.1.beta27 → 0.0.1.beta28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 85befe5d26e8e5dd2cdd6c60b72b8603447b9c5d
4
- data.tar.gz: 0edfd26fa58e9b16ec5cbf13210352d732adb120
3
+ metadata.gz: 9e9c4dc6e1fd0e4d60d78d975bec3ed7a6a27946
4
+ data.tar.gz: c45c52e592f918069fa6879d4a391da75a75e0ae
5
5
  SHA512:
6
- metadata.gz: 55a8479d2f36b42a31b41f686c69a9dd17fdb5ce98e65480c156f88a6d7085770f612b8b8077dfe04c1dafb8b97c6d9af425b328ea6ce1bb1fd77d0cc75e0a28
7
- data.tar.gz: a9583685f8dc25443eddd20846f9e35aed13a0323ce27c0ccdba6d06c4410c5e82783631e490a98d1057bbf555304a6d4dbbe0fbb2d93a6d691db657b41ce441
6
+ metadata.gz: 829a37be49a60d7a44676e195ab285cb8004c926d208c003d1cb010cce148ecd6866173c16dc11855afd03ddb63e0c833cca5177fdfc0deed6a22e6ce42e5db8
7
+ data.tar.gz: d3cad5b3c19c147d2e48d61279a99fcf8120b2e625eb940d605daa21c2328e7f67e47d836263a45f5d51e170c27371a5398e8178cb02a946983da022c3311417
@@ -0,0 +1,3 @@
1
+ .submit_update_avatar {
2
+ margin-top: 10px;
3
+ }
@@ -77,8 +77,23 @@ module MyForum
77
77
  end
78
78
  end
79
79
 
80
+ def avatar_update
81
+ if params[:user][:avatar]
82
+ avatar = upload_avatar(params[:user][:avatar])
83
+ current_user.update(avatar_url: File.join(Avatar::URL, current_user.id.to_s, avatar.file_name)) if avatar
84
+ elsif params[:user][:avatar_url]
85
+ current_user.update_columns(avatar_params)
86
+ end
87
+
88
+ redirect_to edit_user_path(current_user)
89
+ end
90
+
80
91
  private
81
92
 
93
+ def avatar_params
94
+ params.require(:user).permit(:avatar_url)
95
+ end
96
+
82
97
  def user_params
83
98
  params.require(:user).permit(:login, :email, :password)
84
99
  end
@@ -96,5 +111,28 @@ module MyForum
96
111
  current_user.update_attributes(password: new_password)
97
112
  end
98
113
 
114
+ def upload_avatar(avatar_param)
115
+ return false unless Avatar::ALLOWED_FILE_EXTENSIONS.include? File.extname(avatar_param.original_filename)
116
+
117
+ current_avatar = current_user.avatar
118
+ upload_path = File.join(Avatar::UPLOAD_PATH, current_user.id.to_s)
119
+
120
+ # Create dir of not exists
121
+ FileUtils::mkdir_p upload_path
122
+
123
+ File.open(File.join(upload_path, avatar_param.original_filename), 'wb') do |file|
124
+ file.write(avatar_param.read)
125
+ end
126
+
127
+ new_avatar = Avatar.create(user_id: current_user.id, file_name: avatar_param.original_filename)
128
+
129
+ if current_avatar and new_avatar
130
+ FileUtils.rm File.join(upload_path, current_avatar.file_name) rescue nil
131
+ current_avatar.destroy
132
+ end
133
+
134
+ new_avatar
135
+ end
136
+
99
137
  end
100
138
  end
@@ -8,7 +8,7 @@ module MyForum
8
8
 
9
9
  # Display user avatar
10
10
  def user_avatar(user)
11
- return image_tag(user.avatar, class: 'user-avatar') unless user.avatar.blank?
11
+ return image_tag(user.avatar_url, class: 'user-avatar') unless user.avatar_url.blank?
12
12
 
13
13
  image_tag('blank_avatar.png', class: 'user-avatar')
14
14
  end
@@ -6,6 +6,6 @@ module MyForum
6
6
  UPLOAD_PATH = File.join(Rails.public_path, 'uploads', 'attachments')
7
7
  URL = File.join('/uploads', 'attachments')
8
8
 
9
- ALLOWED_FILE_EXTENSIONS = %w(.jpg .png .gif)
9
+ ALLOWED_FILE_EXTENSIONS = %w(.jpg .jpeg .png .gif)
10
10
  end
11
11
  end
@@ -1,5 +1,10 @@
1
1
  module MyForum
2
2
  class Avatar < Image
3
3
  belongs_to :user
4
+
5
+ UPLOAD_PATH = File.join(Rails.public_path, 'uploads', 'avatars')
6
+ URL = File.join('/uploads', 'avatars')
7
+
8
+ ALLOWED_FILE_EXTENSIONS = %w(.jpg .jpeg .png .gif)
4
9
  end
5
10
  end
@@ -11,6 +11,7 @@ module MyForum
11
11
 
12
12
  has_one :avatar
13
13
 
14
+ default_scope { where(is_deleted: false) }
14
15
  scope :online, -> { where("updated_at > ?", 10.minutes.ago) }
15
16
  scope :today_visited, -> { where("updated_at > ?", Time.now.beginning_of_day) }
16
17
 
@@ -0,0 +1,44 @@
1
+ #add_photo.modal.fade
2
+ .modal-dialog
3
+ .modal-content
4
+ .modal-header
5
+ %button.close{ type: 'button', aria_label: 'Close', data: { dismiss: 'modal' } }
6
+ %span{ aria_hidden: "true" }
7
+ &times;
8
+ %h4.modal-title
9
+ = t('.add_new_photo')
10
+ .modal-body
11
+ %p= t('my_forum.attachments.allowed_extensions', ext: upload_allowed_extensions.join(', '))
12
+ = form_for MyForum::Attachment.new, url: attachments_path, multipart: true, remote: true do |f|
13
+ = f.file_field 'file[]', multiple: true, id: 'attachment_files'
14
+
15
+ #loaded-content
16
+
17
+ .modal-footer
18
+ %button.btn.btn-default{ type: 'button', aria_label: 'Close', data: { dismiss: 'modal' } }
19
+ Close
20
+
21
+ :coffee
22
+ $('#attachment_files').change ->
23
+ form_data = new FormData()
24
+
25
+ files_count = $('#attachment_files').prop('files').length
26
+ form_data.append('files[]', $('#attachment_files').prop('files')[c]) for c in [0...files_count]
27
+
28
+ $.ajax({
29
+ url: "#{attachments_path}"
30
+ dataType: 'html'
31
+ cache: false
32
+ contentType: false
33
+ processData: false
34
+ data: form_data
35
+ type: 'post',
36
+ success: (data, textStatus, jqXHR) ->
37
+ response = $.parseJSON(data)
38
+ bbcode_attachments = ''
39
+ bbcode_attachments += ('[attachment=' + id + '] \n') for id in response.attachments
40
+ $('##{textarea}').append(bbcode_attachments)
41
+ $('#loaded-content').html('#{t('my_forum.successfull_aploaded')}')
42
+ $('#add_photo').modal('hide')
43
+ $('#attachment_files').val('')
44
+ })
@@ -11,25 +11,10 @@
11
11
  =link_to '#', class: 'btn btn-default btn-sm' do
12
12
  %i{ class: 'fa fa-underline' }
13
13
 
14
- -# %div.btn-group
15
- -# =link_to '#', class: 'btn btn-default btn-sm' do
16
- -# %i{ class: 'fa fa-align-left' }
17
- -# =link_to '#', class: 'btn btn-default btn-sm' do
18
- -# %i{ class: 'fa fa-align-center' }
19
- -# =link_to '#', class: 'btn btn-default btn-sm' do
20
- -# %i{ class: 'fa fa-align-right' }
21
- -# =link_to '#', class: 'btn btn-default btn-sm' do
22
- -# %i{ class: 'fa fa-align-justify' }
23
-
24
14
  %div.btn-group
25
15
  =link_to '#', class: 'btn btn-default btn-sm', data: { toggle: 'modal' } do
26
16
  %i{ class: 'fa fa-camera-retro' }
27
17
 
28
- -# =link_to '#', class: 'btn btn-default btn-sm' do
29
- -# %i{ class: 'fa fa-video-camera' }
30
- -# =link_to '#', class: 'btn btn-default btn-sm' do
31
- -# %i{ class: 'fa fa-link' }
32
-
33
18
  %div.btn-group.smiles
34
19
  - emoticons_list.each do |code, path|
35
20
  =link_to '#', class: 'btn btn-default btn-sm smile-past' do
@@ -43,51 +28,5 @@
43
28
 
44
29
  .pull-right
45
30
  = form.submit t('.quick_answer'), class: 'btn btn-primary'
46
- =# link_to t('.advanced_answer'), '#', class: 'btn btn-primary'
47
-
48
-
49
- #add_photo.modal.fade
50
- .modal-dialog
51
- .modal-content
52
- .modal-header
53
- %button.close{ type: 'button', aria_label: 'Close', data: { dismiss: 'modal' } }
54
- %span{ aria_hidden: "true" }
55
- &times;
56
- %h4.modal-title
57
- = t('.add_new_photo')
58
- .modal-body
59
- %p= t('my_forum.attachments.allowed_extensions', ext: upload_allowed_extensions.join(', '))
60
- = form_for MyForum::Attachment.new, url: attachments_path, multipart: true, remote: true do |f|
61
- = f.file_field 'file[]', multiple: true, id: 'attachment_files'
62
-
63
- #loaded-content
64
-
65
- :coffee
66
- $('#attachment_files').change ->
67
- form_data = new FormData()
68
-
69
- files_count = $('#attachment_files').prop('files').length
70
- form_data.append('files[]', $('#attachment_files').prop('files')[c]) for c in [0...files_count]
71
-
72
- $.ajax({
73
- url: "#{attachments_path}"
74
- dataType: 'html'
75
- cache: false
76
- contentType: false
77
- processData: false
78
- data: form_data
79
- type: 'post',
80
- success: (data, textStatus, jqXHR) ->
81
- response = $.parseJSON(data)
82
- bbcode_attachments = ''
83
- bbcode_attachments += ('[attachment=' + id + '] \n') for id in response.attachments
84
- $('#quick_answer_textarea').append(bbcode_attachments)
85
- $('#loaded-content').html('#{t('my_forum.successfull_aploaded')}')
86
- $('#add_photo').modal('hide')
87
- $('#attachment_files').val('')
88
- })
89
-
90
31
 
91
- .modal-footer
92
- %button.btn.btn-default{ type: 'button', aria_label: 'Close', data: { dismiss: 'modal' } }
93
- Close
32
+ = render partial: 'my_forum/shared/upload_photo', locals: { textarea: 'quick_answer_textarea' }
@@ -1,12 +1,38 @@
1
1
  %h2= t('.create_new_topic_in', topic_name: @forum.name)
2
2
 
3
+
4
+
3
5
  = form_for @topic, url: forum_topics_path, role: 'form' do |form|
4
6
  .form-group= form.text_field :name, class: 'name form-control', placeholder: t('.name')
5
7
  .form-group= form.text_field :description, class: 'description form-control', placeholder: t('.description')
6
8
 
7
9
  %br
8
10
 
9
- = fields_for :post do |post_form|
10
- .form-group= post_form.text_area :text, placeholder: t('.post_text'), class: 'form-control', rows: 10
11
+ .row
12
+ .col-md-12
13
+ .text-editor-buttons{ data: { apply_to: 'post_text' } }
14
+ %div.btn-group
15
+ =link_to '#', class: 'btn btn-default btn-sm' do
16
+ %i{ class: 'fa fa-bold' }
17
+ =link_to '#', class: 'btn btn-default btn-sm' do
18
+ %i{ class: 'fa fa-italic' }
19
+ =link_to '#', class: 'btn btn-default btn-sm' do
20
+ %i{ class: 'fa fa-strikethrough' }
21
+ =link_to '#', class: 'btn btn-default btn-sm' do
22
+ %i{ class: 'fa fa-underline' }
23
+
24
+ %div.btn-group
25
+ =link_to '#', class: 'btn btn-default btn-sm', data: { toggle: 'modal' } do
26
+ %i{ class: 'fa fa-camera-retro' }
27
+
28
+ %div.btn-group.smiles
29
+ - emoticons_list.each do |code, path|
30
+ =link_to '#', class: 'btn btn-default btn-sm smile-past' do
31
+ %img{ src: path, class: 'smile', data: { code: code } }
32
+
33
+ = fields_for :post do |post_form|
34
+ .form-group= post_form.text_area :text, placeholder: t('.post_text'), class: 'form-control', rows: 10
11
35
 
12
36
  = form.submit class: 'btn '
37
+
38
+ = render partial: 'my_forum/shared/upload_photo', locals: { textarea: 'post_text' }
@@ -10,11 +10,18 @@
10
10
  .form-group= form.password_field :password, value: '', class: 'description form-control', placeholder: t('.current_password')
11
11
  .form-group= form.text_field :new_password, value: '', class: 'description form-control', placeholder: t('.new_password')
12
12
 
13
- = form.submit class: 'btn btn-primary btn-sm'
13
+ = form.submit t('.update'), class: 'btn btn-primary btn-sm'
14
14
 
15
- .col-md-4
15
+ .col-md-5.col-md-offset-1
16
16
  .row.col-sm-4
17
17
  .thumbnail
18
18
  = user_avatar(current_user)
19
- .row.col-sm-4
20
- upload
19
+ .row.col-sm-7.col-sm-offset-1
20
+ .row
21
+ %strong=t('.avatar')
22
+ = form_for current_user, url: user_avatar_update_path(current_user), role: 'form', multipart: true do |form|
23
+ .row
24
+ %p= t('.avatar_upload_description')
25
+ .row= form.file_field :avatar
26
+ .row= form.text_field :avatar_url, placeholder: 'http://...'
27
+ .row= form.submit t('.update_avatar'), class: 'btn btn-primary btn-sm submit_update_avatar'
@@ -103,6 +103,10 @@ ru:
103
103
  email: 'Электронная почта'
104
104
  current_password: 'Текущий пароль'
105
105
  new_password: 'Новый пароль'
106
+ avatar: 'Аватар'
107
+ avatar_upload_description: 'Загрузите свой аватар или укажите ссылку'
108
+ update: 'Обновить'
109
+ update_avatar: 'Обновить аватар'
106
110
 
107
111
 
108
112
  private_messages:
data/config/routes.rb CHANGED
@@ -15,6 +15,7 @@ MyForum::Engine.routes.draw do
15
15
  resources :attachments
16
16
 
17
17
  resources :users do
18
+ patch :avatar_update
18
19
  collection do
19
20
  get :autocomplete
20
21
  end
@@ -0,0 +1,5 @@
1
+ class MyForumRenameUserAvatar < ActiveRecord::Migration
2
+ def change
3
+ rename_column :my_forum_users, :avatar, :avatar_url
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class MyForumChangeUserAvatar < ActiveRecord::Migration
2
+ def change
3
+ change_column :my_forum_users, :avatar_url, :text, length: 350
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module MyForum
2
- VERSION = "0.0.1.beta27"
2
+ VERSION = "0.0.1.beta28"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: my_forum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.beta27
4
+ version: 0.0.1.beta28
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vitaly Omelchenko
@@ -252,6 +252,7 @@ files:
252
252
  - app/views/my_forum/private_messages/inbox.haml
253
253
  - app/views/my_forum/private_messages/new.haml
254
254
  - app/views/my_forum/private_messages/show.haml
255
+ - app/views/my_forum/shared/_upload_photo.haml
255
256
  - app/views/my_forum/topics/_post.haml
256
257
  - app/views/my_forum/topics/_quick_answer.haml
257
258
  - app/views/my_forum/topics/_topic_header.haml
@@ -287,6 +288,8 @@ files:
287
288
  - db/migrate/20151012095554_create_my_forum_images.rb
288
289
  - db/migrate/20151218135729_add_is_deleted.rb
289
290
  - db/migrate/20151220121140_create_my_forum_emoticons.rb
291
+ - db/migrate/20151221203243_my_forum_rename_user_avatar.rb
292
+ - db/migrate/20151221205045_my_forum_change_user_avatar.rb
290
293
  - lib/my_forum.rb
291
294
  - lib/my_forum/engine.rb
292
295
  - lib/my_forum/version.rb