Skip to content

Commit

Permalink
Basic view system/front end working
Browse files Browse the repository at this point in the history
Dashboard links to a control panel
  • Loading branch information
stevemidgley committed Dec 30, 2013
1 parent 3c8188c commit abcc39f
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 13 deletions.
1 change: 1 addition & 0 deletions thermoapp-test/boot-server.json
Expand Up @@ -2,6 +2,7 @@
"config": {
"port": 8080,
"api_key": "WAtJD7txQj8WxfKBHMQPaKuR7Mf4Yu4Mn",
"app_api_key": "TrxAsgoivs8g6HNuCiuHCrga4yo9aoqrDq43qoWu",
"base_folder": "./data"
}
}
3 changes: 3 additions & 0 deletions thermoapp-test/startserver.rb
@@ -0,0 +1,3 @@
#!/usr/bin/env ruby
#We start the thermoserver using the config file from this folder
Kernel.exec("ruby ../thermoserver/thermoserver.rb ./boot-server.json")
29 changes: 25 additions & 4 deletions thermoserver/thermoserver.rb
Expand Up @@ -27,7 +27,8 @@
require 'fileutils'
require 'tempfile'
require 'chronic'
if ENV['RACK_ENV'] == 'testing'

if ENV['RACK_ENV'] == 'testing' or settings.development?
require 'debugger'
end

Expand Down Expand Up @@ -149,11 +150,13 @@ def self.get_file_if_newer_date(options)
def self.get_list_of_files(options)
pattern = options[:pattern]
base_folder = options[:base_folder]
rooted_filename = File::join(base_folder, "*#{pattern}*")
retval = {:authorized => false, :status => 500, :status_message => "Unknown error in list request processing."}
if filename_is_safe?(pattern)
# get files matching pattern in data folder
list = Dir["*#{pattern}*"]
list = Dir[rooted_filename]
if list.length > 0
list.collect! {|l| File::basename(l)}
results_json = {:file_list => list}.to_json
retval = {:authorized => true, :status => 200,
:results_json => results_json}
Expand Down Expand Up @@ -320,10 +323,24 @@ def debug(val)

## Application server (generates user interface from erb templates)

get "/app/:page/#{config.app_api_key}" do
erb params[:page].to_sym
get "/app/dashboard/#{config.app_api_key}" do
file_hash = Thermoserver::get_list_of_files({:pattern=>"config", :base_folder => config.base_folder})
if file_hash[:authorized] && file_hash[:status] == 200
list_of_heaters = JSON.parse(file_hash[:results_json])["file_list"]
retval = erb :dashboard, :locals => {:list_of_heaters => list_of_heaters, :app_api_key => config.app_api_key}
else
response.status = file_hash[:status]
retval = file_hash[:status_message]
end
retval
end

get "/app/control/#{config.app_api_key}/:heater_name" do
retval = erb :control, :locals => {:app_api_key => config.app_api_key}
retval
end


# return open thermo icon
# Credit to Rob Sanders for icon: http://www.iconarchive.com/artist/rob-sanders.html
get "/favicon.ico" do
Expand Down Expand Up @@ -426,6 +443,9 @@ def debug(val)
file_hash[:status_message] || ""
end

# Sets the named heater to mode specified
# Mode options are: off or daily_schedule
# To set "immediate" or "temp_override" modes, use "override_mode" API
put "/app-api/#{config.app_api_key}/:thermoname/default/:mode" do
mode = params[:mode]
# retrieve heater file
Expand All @@ -451,6 +471,7 @@ def debug(val)
file_hash[:status_message] || ""
end

# Creates a new heater configuration file with default configuration for thermoname. If thermoname exists, returns error.
post "/app-api/#{config.app_api_key}/:thermoname/initialize" do
filename = params[:thermoname]
if !File::exists?(Thermoserver::DEFAULT_CONFIG_FILE)
Expand Down
8 changes: 5 additions & 3 deletions thermoserver/views/control.erb
Expand Up @@ -3,7 +3,8 @@
Takes parameter "heater_name"
<p />
Status:
Information about heater
<% # Get heater infomation file %>
Display information about heater
Current temperature
Is heater on?
Mode of operation
Expand All @@ -12,5 +13,6 @@ Information about heater
Control:
Set temperature
Input box with current temperature in it
Button to set input temperature
Turn off/on heater
* Buttons to inc/dec input temperature
* Buttons to turn off/on heater
* Button to save settings
16 changes: 10 additions & 6 deletions thermoserver/views/dashboard.erb
@@ -1,8 +1,12 @@
<%="hello world<br />Here"%>

<p />
List of available thermostats to control
...Clickable List... => link to control.erb
Create new thermostat to control
<% list_of_heaters.each do |heater_name|%>

<p>List of available thermostats to control</p>
<% heater_url = url("/app/control/#{app_api_key}/#{heater_name}")%>
<a href="<%=heater_url%>"><%=heater_name%></a><br />

<% end # list_of_heaters.each do...%>

<p>Create new thermostat to control</p>
...Input box for name of thermostat...
...Button to create new...
...Button to create new...

0 comments on commit abcc39f

Please sign in to comment.