diff --git a/web/Gemfile b/web/Gemfile index 23b5783..4218ee1 100644 --- a/web/Gemfile +++ b/web/Gemfile @@ -25,6 +25,7 @@ gem 'sdoc', '~> 0.4.0', group: :doc gem 'active_scaffold' gem 'bootstrap', '~> 4.0.0.alpha3' gem 'ace-rails-ap' +gem 'puma' # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' diff --git a/web/Gemfile.lock b/web/Gemfile.lock index 9c00e91..ffa7970 100644 --- a/web/Gemfile.lock +++ b/web/Gemfile.lock @@ -86,6 +86,7 @@ GEM parser (2.3.0.6) ast (~> 2.2) powerpack (0.1.1) + puma (2.16.0) rack (1.6.4) rack-test (0.6.3) rack (>= 1.0) @@ -171,6 +172,7 @@ DEPENDENCIES coffee-rails (~> 4.1.0) jbuilder (~> 2.0) jquery-rails + puma rails (= 4.2.5.1) rubocop sass-rails (~> 5.0) diff --git a/web/app/assets/images/chub.png b/web/app/assets/images/chub.png new file mode 100644 index 0000000..de339c3 Binary files /dev/null and b/web/app/assets/images/chub.png differ diff --git a/web/app/assets/images/ubuntu.png b/web/app/assets/images/ubuntu.png new file mode 100644 index 0000000..f0a4088 Binary files /dev/null and b/web/app/assets/images/ubuntu.png differ diff --git a/web/app/assets/javascripts/application.js b/web/app/assets/javascripts/application.js index e07c5a8..a245878 100644 --- a/web/app/assets/javascripts/application.js +++ b/web/app/assets/javascripts/application.js @@ -14,3 +14,5 @@ //= require jquery_ujs //= require turbolinks //= require_tree . +//= require active_scaffold +//= require bootstrap-sprockets diff --git a/web/app/assets/stylesheets/application.css b/web/app/assets/stylesheets/application.css.scss similarity index 83% rename from web/app/assets/stylesheets/application.css rename to web/app/assets/stylesheets/application.css.scss index f9cd5b3..78857fd 100644 --- a/web/app/assets/stylesheets/application.css +++ b/web/app/assets/stylesheets/application.css.scss @@ -1,3 +1,4 @@ + /* * This is a manifest file that'll be compiled into application.css, which will include all the files * listed below. @@ -10,6 +11,15 @@ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new * file per style scope. * - *= require_tree . - *= require_self + *= require active_scaffold */ + @import "bootstrap"; + +#logo { + margin: 20px; + color: green; +} + +.server-thumbnail { + margin: 15px; +} diff --git a/web/app/controllers/operating_systems_controller.rb b/web/app/controllers/operating_systems_controller.rb new file mode 100644 index 0000000..1c39f29 --- /dev/null +++ b/web/app/controllers/operating_systems_controller.rb @@ -0,0 +1,4 @@ +class OperatingSystemsController < ApplicationController + active_scaffold :operating_system do |conf| + end +end diff --git a/web/app/controllers/servers_controller.rb b/web/app/controllers/servers_controller.rb new file mode 100644 index 0000000..3d96d9a --- /dev/null +++ b/web/app/controllers/servers_controller.rb @@ -0,0 +1,6 @@ +class ServersController < ApplicationController + active_scaffold :server do |conf| + conf.columns = [:name, :operating_system] + conf.columns[:operating_system].form_ui = :select + end +end diff --git a/web/app/helpers/operating_systems_helper.rb b/web/app/helpers/operating_systems_helper.rb new file mode 100644 index 0000000..b4c2770 --- /dev/null +++ b/web/app/helpers/operating_systems_helper.rb @@ -0,0 +1,2 @@ +module OperatingSystemsHelper +end diff --git a/web/app/helpers/servers_helper.rb b/web/app/helpers/servers_helper.rb new file mode 100644 index 0000000..a36fb17 --- /dev/null +++ b/web/app/helpers/servers_helper.rb @@ -0,0 +1,2 @@ +module ServersHelper +end diff --git a/web/app/models/operating_system.rb b/web/app/models/operating_system.rb new file mode 100644 index 0000000..f034e25 --- /dev/null +++ b/web/app/models/operating_system.rb @@ -0,0 +1,3 @@ +class OperatingSystem < ActiveRecord::Base + has_many :servers +end diff --git a/web/app/models/server.rb b/web/app/models/server.rb new file mode 100644 index 0000000..6733cad --- /dev/null +++ b/web/app/models/server.rb @@ -0,0 +1,8 @@ +class Server < ActiveRecord::Base + belongs_to :operating_system + before_create :generate_hash + + def generate_hash + self.namehash = SecureRandom.hex + end +end diff --git a/web/app/views/layouts/application.html.erb b/web/app/views/layouts/application.html.erb index d67f770..aca93f4 100644 --- a/web/app/views/layouts/application.html.erb +++ b/web/app/views/layouts/application.html.erb @@ -7,8 +7,11 @@ <%= csrf_meta_tags %> - +

+CHUB +

+
<%= yield %> - +
diff --git a/web/app/views/servers/list.html.erb b/web/app/views/servers/list.html.erb new file mode 100644 index 0000000..2de515a --- /dev/null +++ b/web/app/views/servers/list.html.erb @@ -0,0 +1,23 @@ +
+
+

Servers

+
+
+ <%= link_to(new_server_path) do %> + + <% end %> + +
+ +
+ <% @page.items.each do |server| %> +
+
+ <%= image_tag('ubuntu.png', size: '128', class:"img-responsive" ) %> +
+

<%= server.name %>

+
+
+
+ <% end %> +
diff --git a/web/config/initializers/assets.rb b/web/config/initializers/assets.rb index 01ef3e6..e8b03f6 100644 --- a/web/config/initializers/assets.rb +++ b/web/config/initializers/assets.rb @@ -9,3 +9,4 @@ Rails.application.config.assets.version = '1.0' # Precompile additional assets. # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. # Rails.application.config.assets.precompile += %w( search.js ) +Rails.application.config.assets.precompile += %w( active_scaffold/indicator.gif ) diff --git a/web/config/routes.rb b/web/config/routes.rb index 3f66539..83441d0 100644 --- a/web/config/routes.rb +++ b/web/config/routes.rb @@ -1,9 +1,11 @@ Rails.application.routes.draw do + resources :operating_systems do as_routes end + resources :servers do as_routes end # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". # You can have the root of your site routed with "root" - # root 'welcome#index' + root 'servers#index' # Example of regular route: # get 'products/:id' => 'catalog#view' diff --git a/web/db/migrate/20160220084417_create_servers.rb b/web/db/migrate/20160220084417_create_servers.rb new file mode 100644 index 0000000..358a7f4 --- /dev/null +++ b/web/db/migrate/20160220084417_create_servers.rb @@ -0,0 +1,12 @@ +class CreateServers < ActiveRecord::Migration + def change + create_table :servers do |t| + t.string :name, null: false + t.string :namehash, null: false + t.integer :operating_system_id, null: false + t.boolean :initialized, null: false, default: false + t.string :hostname + t.timestamps null: false + end + end +end diff --git a/web/db/migrate/20160220091225_create_operating_systems.rb b/web/db/migrate/20160220091225_create_operating_systems.rb new file mode 100644 index 0000000..4dfc35e --- /dev/null +++ b/web/db/migrate/20160220091225_create_operating_systems.rb @@ -0,0 +1,8 @@ +class CreateOperatingSystems < ActiveRecord::Migration + def change + create_table :operating_systems do |t| + t.string :name, null: false + t.timestamps null: false + end + end +end diff --git a/web/db/schema.rb b/web/db/schema.rb new file mode 100644 index 0000000..f1ca930 --- /dev/null +++ b/web/db/schema.rb @@ -0,0 +1,30 @@ +# encoding: UTF-8 +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 20_160_220_091_225) do + create_table 'operating_systems', force: :cascade do |t| + t.string 'name', null: false + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + end + + create_table 'servers', force: :cascade do |t| + t.string 'name', null: false + t.string 'namehash', null: false + t.integer 'operating_system_id', null: false + t.boolean 'initialized', default: false, null: false + t.string 'hostname' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + end +end diff --git a/web/test/controllers/operating_systems_controller_test.rb b/web/test/controllers/operating_systems_controller_test.rb new file mode 100644 index 0000000..1037a18 --- /dev/null +++ b/web/test/controllers/operating_systems_controller_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' + +class OperatingSystemsControllerTest < ActionController::TestCase + setup do + @operating_system = operating_systems(:one) + end + + test 'should get index' do + get :index + assert_response :success + assert_not_nil assigns(:operating_systems) + end + + test 'should get new' do + get :new + assert_response :success + end + + test 'should create operating_system' do + assert_difference('OperatingSystem.count') do + post :create, operating_system: {} + end + + assert_redirected_to operating_system_path(assigns(:operating_system)) + end + + test 'should show operating_system' do + get :show, id: @operating_system + assert_response :success + end + + test 'should get edit' do + get :edit, id: @operating_system + assert_response :success + end + + test 'should update operating_system' do + patch :update, id: @operating_system, operating_system: {} + assert_redirected_to operating_system_path(assigns(:operating_system)) + end + + test 'should destroy operating_system' do + assert_difference('OperatingSystem.count', -1) do + delete :destroy, id: @operating_system + end + + assert_redirected_to operating_systems_path + end +end diff --git a/web/test/controllers/servers_controller_test.rb b/web/test/controllers/servers_controller_test.rb new file mode 100644 index 0000000..733a349 --- /dev/null +++ b/web/test/controllers/servers_controller_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' + +class ServersControllerTest < ActionController::TestCase + setup do + @server = servers(:one) + end + + test 'should get index' do + get :index + assert_response :success + assert_not_nil assigns(:servers) + end + + test 'should get new' do + get :new + assert_response :success + end + + test 'should create server' do + assert_difference('Server.count') do + post :create, server: {} + end + + assert_redirected_to server_path(assigns(:server)) + end + + test 'should show server' do + get :show, id: @server + assert_response :success + end + + test 'should get edit' do + get :edit, id: @server + assert_response :success + end + + test 'should update server' do + patch :update, id: @server, server: {} + assert_redirected_to server_path(assigns(:server)) + end + + test 'should destroy server' do + assert_difference('Server.count', -1) do + delete :destroy, id: @server + end + + assert_redirected_to servers_path + end +end diff --git a/web/test/fixtures/operating_systems.yml b/web/test/fixtures/operating_systems.yml new file mode 100644 index 0000000..937a0c0 --- /dev/null +++ b/web/test/fixtures/operating_systems.yml @@ -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 diff --git a/web/test/fixtures/servers.yml b/web/test/fixtures/servers.yml new file mode 100644 index 0000000..937a0c0 --- /dev/null +++ b/web/test/fixtures/servers.yml @@ -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 diff --git a/web/test/models/operating_system_test.rb b/web/test/models/operating_system_test.rb new file mode 100644 index 0000000..46f9239 --- /dev/null +++ b/web/test/models/operating_system_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class OperatingSystemTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/web/test/models/server_test.rb b/web/test/models/server_test.rb new file mode 100644 index 0000000..125ffc9 --- /dev/null +++ b/web/test/models/server_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ServerTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end