foreman_datacenter 0.1.23 → 0.1.24

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: 10a10f0c7efa0d822edda97c4f26f2bffd289e13
4
- data.tar.gz: 21bd60d5f30ffea8a219f568fb1f1d4c7b58e125
3
+ metadata.gz: 830571f1589958041b0aaa9dec1bf8304b5c841c
4
+ data.tar.gz: 0bd0a890f73397ccbb390f15843fdf6b5bbd50ad
5
5
  SHA512:
6
- metadata.gz: 1a5b68f299357f2f72fad9731ae2a178a238b6d2440a8b85b4950e97a7add05ecf2023bd87b2444e3e94fd1ad5a43bf817c48eab0ec846679120b316e650db6f
7
- data.tar.gz: 00c7bdbaa133a41a519bd31adeb5188f752045a4ea867b6f5fc578e6991b521e6ad7987b2ab694fd443b9be2f2e0cd6eeb0a804ba3dd4f9ce3cb7436b8824086
6
+ metadata.gz: 6ebe444b3ad488c5f06ec03ee38fc51d90433f2522beeff517f8c3922bd4fdfd6c9616b894601130a9fce24f309913d4d9bf3323a377643932f711111ed5ac97
7
+ data.tar.gz: 52471ce0703b8f63641380dacb524d8a3e5e1f9c09f34d1272cbcae2eb43f52e1a01b5cb8fee4ef567b2581ff5be2fe82ef956e708d74a8ee876b224b9552f3a
@@ -1,31 +1,62 @@
1
1
  module ForemanDatacenter
2
2
  class CommentsController < ApplicationController
3
- before_filter :load_commentable
4
-
5
- def index
6
- @comments = @commentable.comments
7
- end
8
-
9
- def new
10
- end
3
+ before_filter :load_resource, :load_commentable
11
4
 
12
5
  def edit
6
+ @comment = Comment.find(params[:id])
13
7
  end
14
8
 
15
9
  def create
10
+ @comment = @commentable.comments.new(comment_params)
11
+ if @comment.save
12
+ process_success :success_redirect => "/datacenter/#{@resource}/#{@id}#comment-#{@comment.id}"
13
+ else
14
+ process_error :redirect => "/datacenter/#{@resource}/#{@id}", :error_msg => _("Failed: %s") % (e)
15
+ end
16
16
  end
17
17
 
18
18
  def update
19
+ @comment = Comment.find(params[:id])
20
+ @device = find_commentable(@comment)
21
+ @submodule = parse_submodule(@comment)
22
+ if @comment.update(comment_params)
23
+ process_success :success_redirect => "/datacenter/#{@submodule}/#{@comment.commentable_id}#comment-#{@comment.id}"
24
+ else
25
+ process_error :redirect => "/datacenter/#{@submodule}/#{@comment.commentable_id}#comment-#{@comment.id}", :error_msg => _("Failed: %s") % (e)
26
+ end
19
27
  end
20
28
 
21
29
  def destroy
30
+ @comment = ForemanDatacenter::Comment.find(params[:id])
31
+ if @comment.destroy
32
+ process_success :success_redirect => "/datacenter/#{@resource}/#{@id}#comment-#{@comment.id}"
33
+ else
34
+ process_error :redirect => "/datacenter/#{@resource}/#{@id}", :error_msg => _("Failed: %s") % (e)
35
+ end
22
36
  end
23
37
 
24
38
  private
39
+
40
+ def load_resource
41
+ @resource, @id = request.path.split('/')[2, 3]
42
+ end
43
+
25
44
  def load_commentable
26
- resource, id = request.path.split('/')[2, 3]
27
- @commentable = "foreman_datacenter::#{resource.capitalize}".singularize.classify.constantize.find(id)
45
+ @commentable = "foreman_datacenter::#{@resource.capitalize}".singularize.classify.constantize.find(@id.to_i)
46
+ end
47
+
48
+ def comment_params
49
+ params[:foreman_datacenter_comment].permit(:content, :commntable_type, :commentable_id)
50
+ end
51
+
52
+ def find_commentable(comment)
53
+ comment.commentable_type.classify.constantize.find(comment.commentable_id)
54
+ end
55
+
56
+ def parse_submodule(comment)
57
+ comment.commentable_type.gsub("ForemanDatacenter::", "").pluralize.downcase
28
58
  end
29
59
 
30
60
  end
31
61
  end
62
+
@@ -9,6 +9,8 @@ module ForemanDatacenter
9
9
  before_action :set_device, only: [:update, :destroy, :inventory,
10
10
  :destroy_interfaces, :qr_code]
11
11
 
12
+ before_action :load_resource
13
+
12
14
  def index
13
15
  begin
14
16
  search = resource_base.search_for(params[:search], :order => params[:order])
@@ -28,6 +30,9 @@ module ForemanDatacenter
28
30
  console_ports: [:console_server_port],
29
31
  power_ports: [:power_outlet]
30
32
  ).find(params[:id])
33
+ @user = User.current
34
+ @commentable = @device
35
+ @comment = Comment.new
31
36
  end
32
37
 
33
38
  def inventory
@@ -106,10 +111,14 @@ module ForemanDatacenter
106
111
  def device_params
107
112
  params[:device].permit(:device_type_id, :device_role_id, :platform_id,
108
113
  :name, :serial, :rack_id, :position, :side,
109
- :face, :status, :primary_ip4, :primary_ip6, :comments,
114
+ :face, :status, :primary_ip4, :primary_ip6,
110
115
  :host_id, :size)
111
116
  end
112
117
 
118
+ def load_resource
119
+ @resource, @id = request.path.split('/')[2, 3]
120
+ end
121
+
113
122
  def populate_from_host
114
123
  if params[:host_id]
115
124
  host = Host.find(params[:host_id])
@@ -29,7 +29,7 @@ module ForemanDatacenter
29
29
  has_one :site, :through => :rack
30
30
 
31
31
  has_many :comments, :class_name => 'ForemanDatacenter::Comment',
32
- dependent: :destroy
32
+ dependent: :destroy, as: :commentable
33
33
 
34
34
  enum face: [:front, :rear]
35
35
  enum side: [:left, :right, :full]
@@ -24,7 +24,7 @@ module ForemanDatacenter
24
24
  i = 1
25
25
  loop do
26
26
  current_device = devs.select{ |d| d[0].include?(i) }
27
- current_device == [] ? (result << [[i],[]]; i +=1 ) : (result << current_device[0]; i = current_device[0][0].last + 1)
27
+ current_device == [] ? (result << [[i],[]]; i +=1 ) : (result << merge_devices(current_device, i); i = i + current_device[0][1].last.size)
28
28
  break if i > height
29
29
  end
30
30
  device_sorting(result)
@@ -33,7 +33,13 @@ module ForemanDatacenter
33
33
  private
34
34
 
35
35
  def device_sorting(devices)
36
- devices.reverse.map { |d| [d[0].reverese, d[1]] }
36
+ devices.reverse.map { |d| [d[0].reverse, d[1]] }
37
37
  end
38
+
39
+ def merge_devices(devices, position)
40
+ devs = [[position],[]]
41
+ devices.each{|d| devs[1] << d[1][0]}
42
+ return devs
43
+ end
38
44
  end
39
45
  end
@@ -0,0 +1,24 @@
1
+ <% if action_name == "edit" %>
2
+ <%= form_for @comment, url: "/datacenter/comments/#{@comment.id}" do |f| %>
3
+ <div class="clearfix">
4
+ <div class="form-group">
5
+ <div class="col-md-5">
6
+ <%= f.text_area :content, rows: 8, class: "form-control" %>
7
+ </div>
8
+ </div>
9
+ </div>
10
+ <%= f.submit "Edit comment", class: "btn btn-primary remove_form_templates" %>
11
+ <% end %>
12
+ <% else %>
13
+ <%= form_for [@commentable, @comment], url: "/datacenter/devices/#{@commentable.id}/comments" do |f| %>
14
+ <div class="clearfix">
15
+ <div class="form-group">
16
+ <div class="col-md-5">
17
+ <%= f.text_area :content, rows: 8, class: "form-control" %>
18
+ </div>
19
+ </div>
20
+ </div>
21
+ <%= f.submit "Add comment", class: "btn btn-primary remove_form_templates" %>
22
+ <% end %>
23
+ <% end %>
24
+
@@ -1,3 +1,4 @@
1
- <h1>Comments#edit</h1>
2
- <p>Find me in app/views/comments/edit.html.erb</p>
1
+ <% title 'Editing a comment' %>
2
+
3
+ <%= render 'form' %>
3
4
 
@@ -72,14 +72,6 @@
72
72
  </div>
73
73
  </div>
74
74
 
75
- <!-- Comments -->
76
- <div class="panel panel-default">
77
- <div class="panel-heading"><strong>Comments</strong></div>
78
- <div class="panel-body">
79
- <%= textarea_f f, :comments, rows: 10 %>
80
- </div>
81
- </div>
82
-
83
75
  <%= f.hidden_field :host_id %>
84
76
 
85
77
  <%= submit_or_cancel f %>
@@ -389,5 +389,34 @@
389
389
  </div>
390
390
  </div>
391
391
  <% end %>
392
+
393
+ <!-- Comments -->
394
+ <div class="panel panel-default">
395
+ <div class="panel-heading"><strong>Comments</strong></div>
396
+ <table class="table table-hover panel-body table-striped">
397
+ <tbody>
398
+ <% @device.comments.each do |c| %>
399
+ <tr>
400
+ <td>
401
+ <!-- <div id="comment-<%#= c.id %>"></div> -->
402
+ <div class="text-left pull-left" id="comment-<%= c.id %>">
403
+ <strong><small>Updated by ... <%#= "#{@user.firstname} #{@user.lastname}" %> at <%= c.updated_at %></small></strong>
404
+ <br/>
405
+ <%= c.content %>
406
+ </div>
407
+ <div class="text-right pull-right">
408
+ <%= link_to "##{c.id}", "#comment-#{c.id}" %>
409
+ <%= link_to "Delete", "/datacenter/#{@resource}/#{@id}/comments/#{c.id}", method: :delete, data: {confirm: "Are you sure?"} %>
410
+ <%= link_to "Edit", "/datacenter/comments/#{c.id}/edit" %>
411
+ </div>
412
+ <br/>
413
+ </td>
414
+ </tr>
415
+ <% end %>
416
+ </tbody>
417
+ </table>
418
+ <%= render 'foreman_datacenter/comments/form' %>
419
+ </div>
420
+
392
421
  </div>
393
422
  </div>
data/config/routes.rb CHANGED
@@ -5,6 +5,7 @@ Foreman::Application.routes.draw do
5
5
  as: 'import_to_device'
6
6
 
7
7
  scope 'datacenter', module: :foreman_datacenter do
8
+ resources :comments, only: [:edit, :update]
8
9
  resources :sites
9
10
  resources :racks do
10
11
  get :rack_groups, on: :collection
@@ -83,7 +84,7 @@ Foreman::Application.routes.draw do
83
84
  resources :management_devices, only: [:new, :create, :edit, :update, :destroy],
84
85
  shallow: true
85
86
 
86
- resources :comments, except: [:show]
87
+ resources :comments, only: [:create, :destroy]
87
88
  end
88
89
  resources :device_interface_connections, only: [:index], path: 'connections' do
89
90
  get :interfaces, on: :collection
@@ -1,3 +1,3 @@
1
1
  module ForemanDatacenter
2
- VERSION = '0.1.23'.freeze
2
+ VERSION = '0.1.24'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_datacenter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.23
4
+ version: 0.1.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Ivanov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-24 00:00:00.000000000 Z
11
+ date: 2017-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deface
@@ -176,9 +176,8 @@ files:
176
176
  - app/models/foreman_datacenter/rack.rb
177
177
  - app/models/foreman_datacenter/rack_group.rb
178
178
  - app/models/foreman_datacenter/site.rb
179
+ - app/views/foreman_datacenter/comments/_form.html.erb
179
180
  - app/views/foreman_datacenter/comments/edit.html.erb
180
- - app/views/foreman_datacenter/comments/index.html.erb
181
- - app/views/foreman_datacenter/comments/new.html.erb
182
181
  - app/views/foreman_datacenter/console_port_templates/_form.html.erb
183
182
  - app/views/foreman_datacenter/console_port_templates/new.html.erb
184
183
  - app/views/foreman_datacenter/console_ports/_for_device.html.erb
@@ -1,9 +0,0 @@
1
- <h1>Comments for device <%= @commentable_type %> #<%= @commentable.id %></h1>
2
-
3
- <% @comments.each do |c| %>
4
- <%= c.content %>
5
- </br>
6
- </hr>
7
- <% end %>
8
-
9
-
@@ -1,2 +0,0 @@
1
- <h1>Comments#new</h1>
2
- <p>Find me in app/views/comments/new.html.erb</p>