diff --git a/app/assets/javascripts/lxd_hosts.coffee b/app/assets/javascripts/lxd_hosts.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/lxd_hosts.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/lxd_hosts.scss b/app/assets/stylesheets/lxd_hosts.scss new file mode 100644 index 0000000..4752d3d --- /dev/null +++ b/app/assets/stylesheets/lxd_hosts.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the lxd_hosts controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/lxd_hosts_controller.rb b/app/controllers/lxd_hosts_controller.rb new file mode 100644 index 0000000..eed8dfa --- /dev/null +++ b/app/controllers/lxd_hosts_controller.rb @@ -0,0 +1,74 @@ +class LxdHostsController < ApplicationController + before_action :set_lxd_host, only: [:show, :edit, :update, :destroy] + + # GET /lxd_hosts + # GET /lxd_hosts.json + def index + @lxd_hosts = LxdHost.all + end + + # GET /lxd_hosts/1 + # GET /lxd_hosts/1.json + def show + end + + # GET /lxd_hosts/new + def new + @lxd_host = LxdHost.new + end + + # GET /lxd_hosts/1/edit + def edit + end + + # POST /lxd_hosts + # POST /lxd_hosts.json + def create + @lxd_host = LxdHost.new(lxd_host_params) + + respond_to do |format| + if @lxd_host.save + format.html { redirect_to @lxd_host, notice: 'Lxd host was successfully created.' } + format.json { render :show, status: :created, location: @lxd_host } + else + format.html { render :new } + format.json { render json: @lxd_host.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /lxd_hosts/1 + # PATCH/PUT /lxd_hosts/1.json + def update + respond_to do |format| + if @lxd_host.update(lxd_host_params) + format.html { redirect_to @lxd_host, notice: 'Lxd host was successfully updated.' } + format.json { render :show, status: :ok, location: @lxd_host } + else + format.html { render :edit } + format.json { render json: @lxd_host.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /lxd_hosts/1 + # DELETE /lxd_hosts/1.json + def destroy + @lxd_host.destroy + respond_to do |format| + format.html { redirect_to lxd_hosts_url, notice: 'Lxd host was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_lxd_host + @lxd_host = LxdHost.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def lxd_host_params + params.require(:lxd_host).permit(:name, :uri, :password, :password_confirmation) + end +end diff --git a/app/helpers/lxd_hosts_helper.rb b/app/helpers/lxd_hosts_helper.rb new file mode 100644 index 0000000..b77befd --- /dev/null +++ b/app/helpers/lxd_hosts_helper.rb @@ -0,0 +1,2 @@ +module LxdHostsHelper +end diff --git a/app/views/lxd_hosts/_form.html.erb b/app/views/lxd_hosts/_form.html.erb new file mode 100644 index 0000000..b19cc8f --- /dev/null +++ b/app/views/lxd_hosts/_form.html.erb @@ -0,0 +1,33 @@ +<%= form_for(@lxd_host) do |f| %> + <% if @lxd_host.errors.any? %> +
<%= notice %>
+ +| Name | +Uri | ++ | ||
|---|---|---|---|---|
| <%= lxd_host.name %> | +<%= lxd_host.uri %> | +<%= link_to 'Show', lxd_host %> | +<%= link_to 'Edit', edit_lxd_host_path(lxd_host) %> | +<%= link_to 'Destroy', lxd_host, method: :delete, data: { confirm: 'Are you sure?' } %> | +
<%= notice %>
+ ++ Name: + <%= @lxd_host.name %> +
+ ++ Uri: + <%= @lxd_host.uri %> +
+ +<%= link_to 'Edit', edit_lxd_host_path(@lxd_host) %> | +<%= link_to 'Back', lxd_hosts_path %> diff --git a/app/views/lxd_hosts/show.json.jbuilder b/app/views/lxd_hosts/show.json.jbuilder new file mode 100644 index 0000000..7f7df55 --- /dev/null +++ b/app/views/lxd_hosts/show.json.jbuilder @@ -0,0 +1 @@ +json.extract! @lxd_host, :id, :name, :uri, :created_at, :updated_at diff --git a/config/routes.rb b/config/routes.rb index 5ba9fb0..4312c64 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ Rails.application.routes.draw do + resources :lxd_hosts resources :certificates get 'dashboard/index' diff --git a/test/controllers/lxd_hosts_controller_test.rb b/test/controllers/lxd_hosts_controller_test.rb new file mode 100644 index 0000000..2055c29 --- /dev/null +++ b/test/controllers/lxd_hosts_controller_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' + +class LxdHostsControllerTest < ActionController::TestCase + setup do + @lxd_host = lxd_hosts(:one) + end + + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:lxd_hosts) + end + + test "should get new" do + get :new + assert_response :success + end + + test "should create lxd_host" do + assert_difference('LxdHost.count') do + post :create, lxd_host: { name: @lxd_host.name, password: 'secret', password_confirmation: 'secret', uri: @lxd_host.uri } + end + + assert_redirected_to lxd_host_path(assigns(:lxd_host)) + end + + test "should show lxd_host" do + get :show, id: @lxd_host + assert_response :success + end + + test "should get edit" do + get :edit, id: @lxd_host + assert_response :success + end + + test "should update lxd_host" do + patch :update, id: @lxd_host, lxd_host: { name: @lxd_host.name, password: 'secret', password_confirmation: 'secret', uri: @lxd_host.uri } + assert_redirected_to lxd_host_path(assigns(:lxd_host)) + end + + test "should destroy lxd_host" do + assert_difference('LxdHost.count', -1) do + delete :destroy, id: @lxd_host + end + + assert_redirected_to lxd_hosts_path + end +end