created template selecting
This commit is contained in:
@@ -13,6 +13,5 @@
|
||||
//= require jquery
|
||||
//= require jquery_ujs
|
||||
//= require turbolinks
|
||||
//= require_tree .
|
||||
//= require active_scaffold
|
||||
//= require bootstrap-sprockets
|
||||
|
||||
7
web/app/assets/javascripts/template_select_form.js
Normal file
7
web/app/assets/javascripts/template_select_form.js
Normal file
@@ -0,0 +1,7 @@
|
||||
$(document).ready(function() {
|
||||
$(".template-selection").click( function(event) {
|
||||
var templateId = event.target.id.match(/\d/g).join("");
|
||||
$("#template_id").val(templateId);
|
||||
$("#create_from_template_form").submit();
|
||||
});
|
||||
});
|
||||
@@ -18,12 +18,48 @@
|
||||
color: green;
|
||||
}
|
||||
.server-thumbnail {
|
||||
margin: 15px;
|
||||
padding: 15px;
|
||||
cursor: pointer;
|
||||
|
||||
}
|
||||
|
||||
.server-icon:hover {
|
||||
border-style: solid;
|
||||
border-width: 1px;
|
||||
border-color: gray;
|
||||
}
|
||||
|
||||
.server-icon {
|
||||
border-style: none;
|
||||
border-width: 0px;
|
||||
}
|
||||
|
||||
.server-name {
|
||||
margin-top: 5px;
|
||||
text-transform: uppercase;
|
||||
font-size: 16px !important;
|
||||
text-align: center;
|
||||
|
||||
}
|
||||
|
||||
.template-description {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.template-selection {
|
||||
cursor: pointer;
|
||||
border-style: none;
|
||||
border-width: 0px;
|
||||
}
|
||||
|
||||
.template-selection:hover {
|
||||
cursor: pointer;
|
||||
border-style: solid;
|
||||
border-width: 1px;
|
||||
border-color: gray;
|
||||
}
|
||||
|
||||
body {
|
||||
margin-right: 5px;
|
||||
margin-left: 5px;
|
||||
}
|
||||
|
||||
16
web/app/controllers/configuration_files_controller.rb
Normal file
16
web/app/controllers/configuration_files_controller.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
class ConfigurationFilesController < ApplicationController
|
||||
before_filter :selected_server, only: [:new, :edit]
|
||||
|
||||
active_scaffold :"configuration_file" do |conf|
|
||||
conf.columns[:file_type].form_ui = :select
|
||||
end
|
||||
|
||||
def selected_server
|
||||
@server = Server.find(params[:server_id])
|
||||
@templates = ConfigurationTemplate.order(:name).all
|
||||
end
|
||||
|
||||
def create_from_template
|
||||
template = ConfigurationTemplate.find(params[:template_id])
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,4 @@
|
||||
class ConfigurationTemplatesController < ApplicationController
|
||||
active_scaffold :"configuration_template" do |conf|
|
||||
end
|
||||
end
|
||||
4
web/app/controllers/file_types_controller.rb
Normal file
4
web/app/controllers/file_types_controller.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
class FileTypesController < ApplicationController
|
||||
active_scaffold :"file_type" do |conf|
|
||||
end
|
||||
end
|
||||
4
web/app/controllers/file_versions_controller.rb
Normal file
4
web/app/controllers/file_versions_controller.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
class FileVersionsController < ApplicationController
|
||||
active_scaffold :"file_version" do |conf|
|
||||
end
|
||||
end
|
||||
2
web/app/helpers/configuration_files_helper.rb
Normal file
2
web/app/helpers/configuration_files_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module ConfigurationFilesHelper
|
||||
end
|
||||
2
web/app/helpers/configuration_templates_helper.rb
Normal file
2
web/app/helpers/configuration_templates_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module ConfigurationTemplatesHelper
|
||||
end
|
||||
2
web/app/helpers/file_types_helper.rb
Normal file
2
web/app/helpers/file_types_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module FileTypesHelper
|
||||
end
|
||||
2
web/app/helpers/file_versions_helper.rb
Normal file
2
web/app/helpers/file_versions_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module FileVersionsHelper
|
||||
end
|
||||
5
web/app/models/concerns/iconizable.rb
Normal file
5
web/app/models/concerns/iconizable.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
module Iconizable
|
||||
def safe_icon
|
||||
icon or 'chub.png'
|
||||
end
|
||||
end
|
||||
5
web/app/models/configuration_file.rb
Normal file
5
web/app/models/configuration_file.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class ConfigurationFile < ActiveRecord::Base
|
||||
belongs_to :server
|
||||
belongs_to :file_type
|
||||
has_many :file_versions
|
||||
end
|
||||
6
web/app/models/configuration_template.rb
Normal file
6
web/app/models/configuration_template.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
class ConfigurationTemplate < ActiveRecord::Base
|
||||
belongs_to :operating_system
|
||||
belongs_to :file_type
|
||||
|
||||
include Iconizable
|
||||
end
|
||||
3
web/app/models/file_type.rb
Normal file
3
web/app/models/file_type.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
class FileType < ActiveRecord::Base
|
||||
has_many :configuration_files
|
||||
end
|
||||
3
web/app/models/file_version.rb
Normal file
3
web/app/models/file_version.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
class FileVersion < ActiveRecord::Base
|
||||
belongs_to :configuration_file
|
||||
end
|
||||
@@ -1,3 +1,5 @@
|
||||
class OperatingSystem < ActiveRecord::Base
|
||||
has_many :servers
|
||||
has_many :configuration_templates
|
||||
include Iconizable
|
||||
end
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
class Server < ActiveRecord::Base
|
||||
belongs_to :operating_system
|
||||
before_create :generate_hash
|
||||
has_many :configuration_files
|
||||
|
||||
def generate_hash
|
||||
self.namehash = SecureRandom.hex
|
||||
end
|
||||
|
||||
def to_s
|
||||
"#{name} - #{namehash}"
|
||||
end
|
||||
end
|
||||
|
||||
33
web/app/views/configuration_files/create.html.erb
Normal file
33
web/app/views/configuration_files/create.html.erb
Normal file
@@ -0,0 +1,33 @@
|
||||
<% content_for :javascript_includes do %>
|
||||
<%= javascript_include_tag "template_select_form.js" %>
|
||||
<% end %>
|
||||
|
||||
<div class="row">
|
||||
<h2>Create New File</h2>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<p>for <%= @server %></p>
|
||||
</div>
|
||||
|
||||
|
||||
<% @templates.each do |template| %>
|
||||
<div class="row template-selection" id="template_<%= template.id %>">
|
||||
<div class="col-md-2 text-md-center">
|
||||
<div class="thumbnail">
|
||||
<%= image_tag(template.safe_icon, size: '128', class:"img-responsive" ) %>
|
||||
<div class="caption text-md-center">
|
||||
<h3 class="server-name"><%= template.name %></h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-10 template-description">
|
||||
<%= template.description %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= form_tag(create_from_template_configuration_files_url, method: :post, id: "create_from_template_form") do %>
|
||||
<%= hidden_field_tag('template_id','', id: 'template_id') %>
|
||||
<% end %>
|
||||
12
web/app/views/configuration_files/edit.html.erb
Normal file
12
web/app/views/configuration_files/edit.html.erb
Normal file
@@ -0,0 +1,12 @@
|
||||
<div class="row">
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-10">
|
||||
<div id="editor">
|
||||
<%= @record.content %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -4,6 +4,7 @@
|
||||
<title>Confighub</title>
|
||||
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
|
||||
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
|
||||
<%= yield :javascript_includes %>
|
||||
<%= csrf_meta_tags %>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -1,23 +1,26 @@
|
||||
<div class="row">
|
||||
<div class="col-md-11">
|
||||
<div class="col-md-10">
|
||||
<h2>Servers</h2>
|
||||
</div>
|
||||
<div class="col-md-1 text-right">
|
||||
<%= link_to(new_server_path) do %>
|
||||
<button class="btn btn-default pull-right">Add Server</button>
|
||||
<%= button_to(new_server_path, method: :get, class: "btn btn-default pull-right") do %>
|
||||
Add Server
|
||||
<% end %>
|
||||
</dev>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<% @page.items.each do |server| %>
|
||||
<div class="col-md-2 col-xs-6 text-md-center server-thumbnail">
|
||||
<div class="col-md-3 col-xs-6 text-md-center server-thumbnail">
|
||||
<%= link_to(server_path(server)) do %>
|
||||
<div class="thumbnail">
|
||||
<%= image_tag('ubuntu.png', size: '128', class:"img-responsive" ) %>
|
||||
<div class="caption text-md-center" >
|
||||
<div class="caption text-md-center">
|
||||
<h3 class="server-name"><%= server.name %></h3>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<br /><br />
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
30
web/app/views/servers/show.html.erb
Normal file
30
web/app/views/servers/show.html.erb
Normal file
@@ -0,0 +1,30 @@
|
||||
<div class="row">
|
||||
<div class="col-md-11">
|
||||
<h2><%= @record.name %></h2>
|
||||
<div class="small"><%= @record.namehash %>
|
||||
-
|
||||
<%= @record.operating_system.name %></div>
|
||||
<br/>
|
||||
<br/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<% if @record.configuration_files.blank? %>
|
||||
<div class="col-md-12 text-md-center">
|
||||
<p>There are no configuration files from this server in CHUB. You can create file now and pull it to the server later:<br/><br/></p>
|
||||
|
||||
<p><%= button_to(new_configuration_file_path, method: :get, params: { server_id: @record.id}, class: "btn btn-success") do %>
|
||||
Create New Configuration File
|
||||
<% end %><br/><br/>
|
||||
</p>
|
||||
|
||||
<p>Or you can initialize server with chub and upload the existing files from server by pasting this into your server's terminal:</p>
|
||||
|
||||
<% command = "sudo wget -O /usr/local/bin/chub http://chub.saburly.com/chub && sudo chub init #{@record.namehash}" %>
|
||||
|
||||
<p><%= text_field_tag 'command', command, readonly: true, class: 'form-control-sm', size: command.length %></p>
|
||||
</div>
|
||||
|
||||
<% end %>
|
||||
|
||||
</div>
|
||||
Reference in New Issue
Block a user