update
This commit is contained in:
parent
37538b5112
commit
e9d72c6fc5
@ -57,3 +57,5 @@
|
|||||||
// Right Click Event
|
// Right Click Event
|
||||||
|
|
||||||
//= require contextmenu
|
//= require contextmenu
|
||||||
|
|
||||||
|
//= require js/validator/validator.js
|
@ -1,6 +1,7 @@
|
|||||||
class NodeController < ApplicationController
|
class NodeController < ApplicationController
|
||||||
def index
|
def index
|
||||||
@hosts = Array.new
|
@hosts = Array.new
|
||||||
|
@nodes = Node.all.order("id asc")
|
||||||
|
|
||||||
if get_hosts.blank?
|
if get_hosts.blank?
|
||||||
flash[:danger] = "Check Server"
|
flash[:danger] = "Check Server"
|
||||||
@ -12,4 +13,21 @@ class NodeController < ApplicationController
|
|||||||
def get_hosts
|
def get_hosts
|
||||||
return ['2', 'aaa', 'bbb', 'ccc']
|
return ['2', 'aaa', 'bbb', 'ccc']
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def node_add
|
||||||
|
new_node = Node.new
|
||||||
|
new_node.host_name = params[:host_name]
|
||||||
|
new_node.host_ip = params[:host_ip]
|
||||||
|
new_node.host_port = params[:host_port]
|
||||||
|
new_node.user_name = params[:user_name]
|
||||||
|
new_node.user_password = params[:user_password]
|
||||||
|
new_node.save
|
||||||
|
redirect_to '/node/index'
|
||||||
|
end
|
||||||
|
|
||||||
|
def node_delete
|
||||||
|
one_node = Node.find(params[:node_id])
|
||||||
|
one_node.destroy
|
||||||
|
redirect_to '/node/index'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
2
app/models/node.rb
Normal file
2
app/models/node.rb
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
class Node < ActiveRecord::Base
|
||||||
|
end
|
@ -8,12 +8,88 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="clearfix"></div>
|
<div class="clearfix"></div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12 col-sm-12 col-xs-12">
|
||||||
|
<div class="x_panel">
|
||||||
|
<div class="x_title">
|
||||||
|
<h2>Add Node</h2>
|
||||||
|
<ul class="nav navbar-right panel_toolbox">
|
||||||
|
<li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
|
||||||
|
</li>
|
||||||
|
<li class="dropdown">
|
||||||
|
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-wrench"></i></a>
|
||||||
|
<ul class="dropdown-menu" role="menu">
|
||||||
|
<li><a href="#">Settings 1</a>
|
||||||
|
</li>
|
||||||
|
<li><a href="#">Settings 2</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<li><a class="close-link"><i class="fa fa-close"></i></a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<div class="clearfix"></div>
|
||||||
|
</div>
|
||||||
|
<div class="x_content">
|
||||||
|
|
||||||
|
<form class="form-horizontal form-label-left" action="/node/add" method="post" novalidate>
|
||||||
|
<span class="section">Node Info</span>
|
||||||
|
|
||||||
|
<div class="item form-group">
|
||||||
|
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Host Name <span class="required">*</span>
|
||||||
|
</label>
|
||||||
|
<div class="col-md-6 col-sm-6 col-xs-12">
|
||||||
|
<input id="name" class="form-control col-md-7 col-xs-12" data-validate-length-range="10" data-validate-words="1" name="host_name" placeholder="Host Name" required="required" type="text">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="item form-group">
|
||||||
|
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="ip">Host IP <span class="required">*</span>
|
||||||
|
</label>
|
||||||
|
<div class="col-md-6 col-sm-6 col-xs-12">
|
||||||
|
<input id="ip" class="form-control col-md-7 col-xs-12" data-validate-length-range="10" data-validate-words="1" name="host_ip" placeholder="127.0.0.1" required="required" type="text">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="item form-group">
|
||||||
|
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="number">Host Port <span class="required">*</span>
|
||||||
|
</label>
|
||||||
|
<div class="col-md-6 col-sm-6 col-xs-12">
|
||||||
|
<input type="number" id="number" name="host_port" required="required" data-validate-length-range="4" data-validate-minmax="0,9999" placeholder="0~9999" class="form-control col-md-7 col-xs-12">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="item form-group">
|
||||||
|
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">User Name <span class="required">*</span>
|
||||||
|
</label>
|
||||||
|
<div class="col-md-6 col-sm-6 col-xs-12">
|
||||||
|
<input id="occupation" type="text" name="user_name" required="required" data-validate-length-range="5,20" class="form-control col-md-7 col-xs-12">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="item form-group">
|
||||||
|
<label for="password" class="control-label col-md-3">User Password <span class="required">*</span></label>
|
||||||
|
<div class="col-md-6 col-sm-6 col-xs-12">
|
||||||
|
<input id="password" type="password" name="user_password" data-validate-length="1,10" class="form-control col-md-7 col-xs-12" required="required">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="ln_solid"></div>
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="col-md-6 col-md-offset-3">
|
||||||
|
<button type="submit" class="btn btn-primary">Cancel</button>
|
||||||
|
<button id="send" type="submit" class="btn btn-success">Add</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6 col-sm-6 col-xs-12">
|
<div class="col-md-12 col-sm-12 col-xs-12">
|
||||||
<div class="x_panel">
|
<div class="x_panel">
|
||||||
<div class="x_title">
|
<div class="x_title">
|
||||||
<h2>Hover rows <small>Try hovering over the rows</small></h2>
|
<h2>Node List <small>Try hovering over the rows</small></h2>
|
||||||
<ul class="nav navbar-right panel_toolbox">
|
<ul class="nav navbar-right panel_toolbox">
|
||||||
<li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
|
<li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
|
||||||
</li>
|
</li>
|
||||||
@ -37,19 +113,25 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th>#</th>
|
<th>#</th>
|
||||||
<th>Host Name</th>
|
<th>Host Name</th>
|
||||||
<th>IP Address</th>
|
<th>Host IP</th>
|
||||||
<th>Status</th>
|
<th>Host Port</th>
|
||||||
<th>UUID</th>
|
<th>User Name</th>
|
||||||
|
<th>User Password</th>
|
||||||
|
<th>Date</th>
|
||||||
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<%@hosts.each do |t|%>
|
<%@nodes.each do |t|%>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">1</th>
|
<th scope="row"><%=t.id%></th>
|
||||||
<td>Mark</td>
|
<td><%=t.host_name%></td>
|
||||||
<td>Otto</td>
|
<td><%=t.host_ip%></td>
|
||||||
<td>@mdo</td>
|
<td><%=t.host_port%></td>
|
||||||
<td>tmp</td>
|
<td><%=t.user_name%></td>
|
||||||
|
<td><%=t.user_password%></td>
|
||||||
|
<td><%=t.created_at%></td>
|
||||||
|
<td><a href="/node/delete/<%=t.id%>"><i class="fa fa-trash"></i></a></td>
|
||||||
</tr>
|
</tr>
|
||||||
<%end%>
|
<%end%>
|
||||||
</tbody>
|
</tbody>
|
||||||
@ -60,3 +142,45 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- /page content -->
|
<!-- /page content -->
|
||||||
|
<script>
|
||||||
|
// initialize the validator function
|
||||||
|
validator.message['date'] = 'not a real date';
|
||||||
|
|
||||||
|
// validate a field on "blur" event, a 'select' on 'change' event & a '.reuired' classed multifield on 'keyup':
|
||||||
|
$('form')
|
||||||
|
.on('blur', 'input[required], input.optional, select.required', validator.checkField)
|
||||||
|
.on('change', 'select.required', validator.checkField)
|
||||||
|
.on('keypress', 'input[required][pattern]', validator.keypress);
|
||||||
|
|
||||||
|
$('.multi.required')
|
||||||
|
.on('keyup blur', 'input', function() {
|
||||||
|
validator.checkField.apply($(this).siblings().last()[0]);
|
||||||
|
});
|
||||||
|
|
||||||
|
// bind the validation to the form submit event
|
||||||
|
//$('#send').click('submit');//.prop('disabled', true);
|
||||||
|
|
||||||
|
$('form').submit(function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
var submit = true;
|
||||||
|
// evaluate the form using generic validaing
|
||||||
|
if (!validator.checkAll($(this))) {
|
||||||
|
submit = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (submit)
|
||||||
|
this.submit();
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
/* FOR DEMO ONLY */
|
||||||
|
$('#vfields').change(function() {
|
||||||
|
$('form').toggleClass('mode2');
|
||||||
|
}).prop('checked', false);
|
||||||
|
|
||||||
|
$('#alerts').change(function() {
|
||||||
|
validator.defaults.alerts = (this.checked) ? false : true;
|
||||||
|
if (this.checked)
|
||||||
|
$('form .alert').remove();
|
||||||
|
}).prop('checked', false);
|
||||||
|
</script>
|
@ -28,6 +28,8 @@ Rails.application.routes.draw do
|
|||||||
|
|
||||||
#Node
|
#Node
|
||||||
get 'node/index' => 'node#index'
|
get 'node/index' => 'node#index'
|
||||||
|
post 'node/add' => "node#node_add"
|
||||||
|
get 'node/delete/:node_id' => "node#node_delete"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
14
db/migrate/20160920111650_create_nodes.rb
Normal file
14
db/migrate/20160920111650_create_nodes.rb
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
class CreateNodes < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :nodes do |t|
|
||||||
|
|
||||||
|
t.string :host_name
|
||||||
|
t.string :host_ip
|
||||||
|
t.integer :host_port
|
||||||
|
t.string :user_name
|
||||||
|
t.string :user_password
|
||||||
|
|
||||||
|
t.timestamps null: false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
12
db/schema.rb
12
db/schema.rb
@ -11,7 +11,17 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20160819061449) do
|
ActiveRecord::Schema.define(version: 20160920111650) do
|
||||||
|
|
||||||
|
create_table "nodes", force: :cascade do |t|
|
||||||
|
t.string "host_name"
|
||||||
|
t.string "host_ip"
|
||||||
|
t.integer "host_port"
|
||||||
|
t.string "user_name"
|
||||||
|
t.string "user_password"
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
end
|
||||||
|
|
||||||
create_table "users", force: :cascade do |t|
|
create_table "users", force: :cascade do |t|
|
||||||
t.string "email", default: "", null: false
|
t.string "email", default: "", null: false
|
||||||
|
11
test/fixtures/nodes.yml
vendored
Normal file
11
test/fixtures/nodes.yml
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
|
# This model initially had no columns defined. If you add columns to the
|
||||||
|
# model remove the '{}' from the fixture names and add the columns immediately
|
||||||
|
# below each fixture, per the syntax in the comments below
|
||||||
|
#
|
||||||
|
one: {}
|
||||||
|
# column: value
|
||||||
|
#
|
||||||
|
two: {}
|
||||||
|
# column: value
|
7
test/models/node_test.rb
Normal file
7
test/models/node_test.rb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class NodeTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user