foreman_datacenter 0.1.23 → 0.1.24
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/foreman_datacenter/comments_controller.rb +41 -10
- data/app/controllers/foreman_datacenter/devices_controller.rb +10 -1
- data/app/models/foreman_datacenter/device.rb +1 -1
- data/app/models/foreman_datacenter/rack.rb +8 -2
- data/app/views/foreman_datacenter/comments/_form.html.erb +24 -0
- data/app/views/foreman_datacenter/comments/edit.html.erb +3 -2
- data/app/views/foreman_datacenter/devices/_form.html.erb +0 -8
- data/app/views/foreman_datacenter/devices/show.html.erb +29 -0
- data/config/routes.rb +2 -1
- data/lib/foreman_datacenter/version.rb +1 -1
- metadata +3 -4
- data/app/views/foreman_datacenter/comments/index.html.erb +0 -9
- data/app/views/foreman_datacenter/comments/new.html.erb +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 830571f1589958041b0aaa9dec1bf8304b5c841c
|
4
|
+
data.tar.gz: 0bd0a890f73397ccbb390f15843fdf6b5bbd50ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
27
|
-
|
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,
|
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
|
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].
|
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
|
+
|
@@ -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,
|
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
|
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.
|
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-
|
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
|