Permalink
Browse files

- flash messages

- digital ocean remote models
- hmmmm
  • Loading branch information...
Raekye committed Apr 29, 2014
1 parent 2cb2d33 commit 5398bdbfa7c29fc8b4fbd993f26058bfa7bd8690
@@ -14,3 +14,5 @@
# Ignore all logfiles and tempfiles.
/log/*.log
/tmp

/config/app.yml
@@ -48,3 +48,4 @@ gem 'digital_ocean'
gem 'httparty'
gem 'sinatra', :require => nil
gem 'font-awesome-sass'
gem 'simple_form'
@@ -132,6 +132,9 @@ GEM
json
redis (>= 3.0.6)
redis-namespace (>= 1.3.1)
simple_form (3.0.2)
actionpack (~> 4.0)
activemodel (~> 4.0)
sinatra (1.4.5)
rack (~> 1.4)
rack-protection (~> 1.4)
@@ -179,5 +182,6 @@ DEPENDENCIES
sass-rails (~> 4.0.3)
sdoc (~> 0.4.0)
sidekiq
simple_form
sinatra
uglifier (>= 1.3.0)
@@ -1,11 +1,11 @@
body {
font-family: "driod-sans", sans-serif;
font-family: "Droid Sans", sans-serif;
}

h1, h2, h3, h4, h5, h6 {
font-family: "ocr-a-std", sans-serif;
font-family: "Droid Sans Mono"/*"ocr-a-std"*/, sans-serif;
}

.navbar-brand {
font-family: "ocr-a-std", sans-serif;
font-family: "Droid Sans Mono"/*"ocr-a-std"*/, sans-serif;
}
@@ -0,0 +1,25 @@
.flash-container {
width: 100%;
margin-top: -20px;
text-align: center;
font-size: 14px;
position: relative;

.flash-notice {
background: #49C;
text-shadow: 0 1px 1px #178;
padding: 10px;
}

.flash-alert {
background: #C67;
text-shadow: 0 1px 1px #945;
padding: 10px;
}

.flash-error {
background: #D2322D;
text-shadow: 0 1px 1px #178;
padding: 10px;
}
}
@@ -0,0 +1,8 @@
class DigitalOcean::Connection

attr_reader :request

def initialize(client_id, api_key)
@request = DigitalOcean::API.new(client_id: client_id, api_key: api_key, debug: false)
end
end
@@ -0,0 +1,52 @@
class DigitalOcean::Droplet

def initialize(local_droplet)
@local_droplet = local_droplet
end

def create
user = local_droplet.minecraft_server.user
connection = user.digital_ocean
if connection.nil?
return nil
end
if user.minecraft_snapshot_id.nil?
return nil
end
response = connection.droplets.create({
name: local_droplet.host_name,
size_id: local_droplet.minecraft_server.droplet_size_id,
image_id: user.minecraft_snapshot_id,
region_id: 4, # TODO
})
if response.status == 'OK'
return response
end
return nil
end

def shutdown
connection = local_droplet.minecraft_server.user.digital_ocean
if connection.nil?
return nil
end
response = connection.droplets.shutdown(local_droplet.remote_id)
if response.status == 'OK'
return response.event_id
end
return nil
end

def snapshot
connection = local_droplet.minecraft_server.user.digital_ocean
if connection.nil?
return nil
end
response = connection.droplets.snapshot(local_droplet.remote_id, name: local_droplet.host_name)
if response.status == 'OK'
return response.event_id
end
return nil
end

end
@@ -0,0 +1,15 @@
class DigitalOcean::DropletSize

def initialize

end

def all
end

def default
end

def available
end
end
@@ -0,0 +1,28 @@
class DigitalOcean::Event
include HTTParty

def initialize(event_id, user)
@event_id = event_id
@user = user
@response = self.class.get("https://api.digitalocean.com/events/#{@event_id}/?client_id=#{user.digital_ocean_client_id}&api_key=#{user.digital_ocean_api_key}")
@body = JSON.parse(@response.body)
end

def show
return @body
end

def has_error?
return !(@body['status'] == 'OK' && @body['error_message'].nil?)
end

def is_done?
if has_error?
raise "Digital ocean event #{@event_id} for user #{@user.id} had error #{@body}"
end
if @body['event'].nil?
return false
end
return @body['event']['action_status'] == 'done'
end
end
@@ -0,0 +1,2 @@
class DigitalOcean::Sync
end
@@ -1,3 +1,19 @@
# == Schema Information
#
# Table name: droplets
#
# id :integer not null, primary key
# minecraft_server_id :integer
# remote_id :integer
# remote_size_id :integer
# remote_region_id :integer
# ip_address :inet
# remote_status :string(255)
# last_synced :datetime
# created_at :datetime
# updated_at :datetime
#

class Droplet < ActiveRecord::Base
belongs_to :minecraft_server
end
@@ -1,3 +1,17 @@
# == Schema Information
#
# Table name: minecraft_servers
#
# id :uuid not null, primary key
# user_id :integer
# name :string(255)
# saved_snapshot_id :integer
# pending_operation :string(255)
# created_at :datetime
# updated_at :datetime
#

class MinecraftServer < ActiveRecord::Base
belongs_to :user
has_one :droplet
end
@@ -1,6 +1,60 @@
# == Schema Information
#
# Table name: users
#
# id :integer not null, primary key
# email :string(255) default(""), not null
# encrypted_password :string(255) default(""), not null
# reset_password_token :string(255)
# reset_password_sent_at :datetime
# remember_created_at :datetime
# sign_in_count :integer default(0), not null
# current_sign_in_at :datetime
# last_sign_in_at :datetime
# current_sign_in_ip :string(255)
# last_sign_in_ip :string(255)
# created_at :datetime
# updated_at :datetime
# digital_ocean_client_id :string(255)
# digital_ocean_api_key :string(255)
# digital_ocean_minecraft_snapshot_id :integer
#

class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable

has_many :minecraft_servers, dependent: :destroy

def minecraft_snapshot_id
if digital_ocean_minecraft_snapshot_id.nil?
return nil
end
if digital_ocean.nil?
return nil
end
if digital_ocean.images.list.index { |x| x.image_id == digital_ocean_minecraft_snapshot_id }.nil?
return nil
end
return digital_ocean_minecraft_snapshot_id
end

def digital_ocean
if digital_ocean_client_id.nil? || digital_ocean_api_key.nil?
return nil
end
if @digital_ocean_connection.nil?
@digital_ocean_connection = DigitalOcean::Connection.new(digital_ocean_client_id, digital_ocean_api_key).request
end
return @digital_ocean_connection
end

def digital_ocean_droplets
if digital_ocean.nil?
return nil
end
return [] # TODO
end
end
@@ -4,14 +4,16 @@
<title>Gamocosm</title>
<%= stylesheet_link_tag 'application', media: 'all' %>
<%= javascript_include_tag 'application' %>
<%= stylesheet_link_tag 'application', 'http://fonts.googleapis.com/css?family=Droid+Sans' %>
<%= stylesheet_link_tag 'application', 'http://fonts.googleapis.com/css?family=Droid+Sans+Mono' %>
<%= csrf_meta_tags %>
</head>
<body>

<%= render partial: 'layouts/components/navbar' %>
<%= render partial: 'layouts/components/flash' %>
<div class="container"><%= yield %></div>
<%= render partial: 'layouts/components/footer' %>
<%= render partial: 'layouts/components/flash' %>

</body>
</html>
@@ -1,5 +1,5 @@
<% flash.each do |name, msg| %>
<div class="flash-container">
<div class="flash-<%= name %>"><%= msg %></div>
<div class="flash-container row">
<div class="flash-<%= name %> col-lg-12"><%= msg %></div>
</div>
<% end %>
@@ -16,7 +16,7 @@
</ul>
<ul class="nav navbar-nav navbar-right">
<% if user_signed_in? %>
<li><%= link_to 'Servers', servers_path %></li>
<li><%= link_to 'Servers', minecraft_servers_path %></li>
<li><a href="#"><%= current_user.email %></a></li>
<li><%= link_to 'Logout', destroy_user_session_path, method: :delete %></li>
<% else %>
No changes.
Oops, something went wrong.

0 comments on commit 5398bdb

Please sign in to comment.