Ohad Levy has uploaded a new change for review.

Change subject: added views as seperate files
......................................................................

added views as seperate files

Change-Id: Ie3a37e9304cfd8a2ec9a14b01a942f4cd73730dd
Signed-off-by: Ohad Levy <[email protected]>
---
A ruby/views/login.html.erb
A ruby/views/vms.html.erb
M ruby/webhandler.rb
3 files changed, 69 insertions(+), 63 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/samples-portals refs/changes/62/11562/1

diff --git a/ruby/views/login.html.erb b/ruby/views/login.html.erb
new file mode 100644
index 0000000..c42b2f3
--- /dev/null
+++ b/ruby/views/login.html.erb
@@ -0,0 +1,24 @@
+<html>
+<body>
+<center><br/><br/>
+
+  <form name="input" action="/" method="post">
+    <table>
+      <tr>
+        <td>User name:</td>
+        <td><input type="text" name="username" value=""/></td>
+      <tr>
+        <td>Password:</td>
+        <td><input type="password" name="password" value=""/></td>
+      <tr>
+        <td/>
+        <td align="right"><input type="submit" value="Login"/></td>
+      </tr>
+      <tr>
+        <td colspan="2" style="color:red"><%= @message %></td>
+      </tr>
+    </table>
+  </form>
+</center>
+</body>
+</html>
\ No newline at end of file
diff --git a/ruby/views/vms.html.erb b/ruby/views/vms.html.erb
new file mode 100644
index 0000000..1429cbd
--- /dev/null
+++ b/ruby/views/vms.html.erb
@@ -0,0 +1,35 @@
+<html>
+<body>
+<center><br/><br/>
+  <table cellpadding="5" style="border-width: 1px; border-spacing: 2px; 
border-style: outset; border-color: gray; border-collapse: separate; 
background-color: white;">
+    <tr>
+      <th>VM Name</th>
+      <th>Status</th>
+      <th>Display</th>
+      <th>Start</th>
+      <th>Stop</th>
+      <th>Console</th>
+    </tr>
+    <% @vms.each do|vm| %>
+      <tr>
+        <td> <%= vm.name %> </td>
+        <td> <%= vm.status %> </td>
+        <td> <%= vm.display[:type] %>  </td>
+        <td>
+          <button onclick=javascript:location.href=action?vmid=<%= vm.id 
%>&action=start type='button'>Start</button>
+        </td>
+        <td>
+          <button onclick=javascript:location.href=action?vmid=<%= vm.id 
%>&action=stop type='button'>Stop</button>
+        </td>
+        <td>
+          <button onclick=javascript:location.href=action?vmid=<%= vm.id 
%>&action=ticket type='button'>Console</button>
+        </td>
+      </tr>
+    <% end %>
+    <tr>
+      <td> <button 
onclick=javascript:location.href=/logout>Logout</button></td>
+    </tr>
+  </table>
+</center>
+</body>
+</html>
diff --git a/ruby/webhandler.rb b/ruby/webhandler.rb
index 99b51c1..19bfa65 100755
--- a/ruby/webhandler.rb
+++ b/ruby/webhandler.rb
@@ -7,16 +7,18 @@
 
 require 'yaml'
 
-$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '.' ))
+APP_ROOT = File.dirname(__FILE__)
+$LOAD_PATH.unshift(File.join(APP_ROOT, '.' ))
 require 'ovirtwrapper'
 
 ## --------------------------------------------
 enable :sessions
 
 configure do
-    conf = YAML.load_file('ovirt.conf.yml')
+    conf = YAML.load_file("#{APP_ROOT}/ovirt.conf.yml")
     set :bind, conf['server']['host']
     set :port, conf['server']['port']
+    set :views, APP_ROOT + "/views"
 end
 
 get '/vms' do
@@ -46,79 +48,24 @@
 end
 
 def login
-    message = ''
+    @message = ''
     wrapper = OVirtWrapper.new
     if params['username'] != nil and params['password'] != nil
         if wrapper.login(params['username'], params['password'])
             session[:wrapper] = wrapper
             redirect to('/vms')
         else
-            message = wrapper.getMessage
+            @message = wrapper.getMessage
         end
     end
-
-    '<html>
-    <body>
-    <center><br/><br/>
-    <form name="input" action="/" method="post">
-            <table>
-                <tr>
-                    <td>User name:</td>
-                    <td><input type="text" name="username" value=""/></td>
-                <tr>
-                    <td>Password:</td>
-                    <td><input type="password" name="password" value=""/></td>
-                <tr>
-                    <td/>
-                    <td align="right"><input type="submit" value="Login"/></td>
-                </tr>
-                <tr>
-                    <td colspan="2" style="color:red">%s</td>
-                </tr>
-        </form>
-    </body>
-    </html>' % message
+    erb :'login.html'
 end
 
 def doVms
     wrapper = session[:wrapper]
-    if wrapper == nil
-        redirect to '/'
-    end
-
-    html = '<html>
-    <body>
-        <center><br/><br/>
-        <table cellpadding="5" style="border-width: 1px; border-spacing: 2px; 
border-style: outset; border-color: gray; border-collapse: separate; 
background-color: white;">
-            <tr>
-                <th>VM Name</th>
-                <th>Status</th>
-                <th>Display</th>
-                <th>Start</th>
-                <th>Stop</th>
-                <th>Console</th>
-            </tr>'
-    for i in 0...wrapper.vms.length
-        vm = wrapper.vms[i]
-        startbtn = "<button 
onclick=javascript:location.href='action?vmid=%s&action=start' 
type='button'>Start</button>" % vm.id
-        stopbtn = "<button 
onclick=javascript:location.href='action?vmid=%s&action=stop' 
type='button'>Stop</button>" % vm.id
-        connectbtn = "<button 
onclick=javascript:location.href='action?vmid=%s&action=ticket' 
type='button'>Console</button>" % vm.id
-        html = html + '<tr>
-        <td>%s</td>
-        <td>%s</td>
-        <td>%s</td>
-        <td>%s</td>
-        <td>%s</td>
-        <td>%s</td>
-        </tr> ' % [vm.name, vm.status, vm.display[:type], startbtn, stopbtn, 
connectbtn]
-    end
-
-    html += '<tr>
-        <td><button 
onclick=javascript:location.href="/logout">Logout</button></td>
-    </tr>
-    </table></center></body></html>'
-
-    html
+    redirect to '/' unless wrapper
+    @vms = wrapper.vms
+    erb :'vms.html'
 end
 
 def doAction


--
To view, visit http://gerrit.ovirt.org/11562
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie3a37e9304cfd8a2ec9a14b01a942f4cd73730dd
Gerrit-PatchSet: 1
Gerrit-Project: samples-portals
Gerrit-Branch: master
Gerrit-Owner: Ohad Levy <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to