Browse Source

get accounts loaded

Chris Mague 7 years ago
parent
commit
398a91cb41

+ 7 - 8
config.ru

@@ -2,15 +2,14 @@
 require (File.join(File.dirname(__FILE__), 'web', 'controllers'))
 
 # serve up static assets using rack
-map "/js" do
-  run Rack::Directory.new("#{File.join(File.dirname(__FILE__), 'web', 'static', 'js')}")
-end
-
-# serve up static assets using rack
-map "/bootstrap" do
-  run Rack::Directory.new("#{File.join(File.dirname(__FILE__), 'web', 'static', 'js')}")
-end
+#map "/js" do
+#  run Rack::Directory.new("#{File.join(File.dirname(__FILE__), 'web', 'static', 'js')}")
+#end
 
 map "/" do
     run Toppage
 end
+
+map "/load" do
+    run Dataloader
+end

+ 8 - 0
lib/neoinfra.rb

@@ -1,5 +1,13 @@
 # frozen_string_literal: true
 
+lib_dir = File.join(File.dirname(File.expand_path(__FILE__)))
+$LOAD_PATH.unshift(lib_dir) unless
+  $LOAD_PATH.include?(lib_dir) || $LOAD_PATH.include?(lib_dir)
+
+models_dir = File.join(File.dirname(File.expand_path(__FILE__)), '..', 'models')
+$LOAD_PATH.unshift(models_dir) unless
+  $LOAD_PATH.include?(models_dir) || $LOAD_PATH.include?(models_dir)
+
 # The supplies all of the various neoinfra info
 module NeoInfra
   require 'neoinfra/config'

+ 6 - 0
lib/neoinfra/accounts.rb

@@ -10,6 +10,12 @@ require 'neoinfra/config'
 module NeoInfra
   # Provide informations about the accounts available
   class Accounts
+
+    def list_names
+      @cfg = NeoInfra::Config.new
+      @cfg.accounts.map{ |x| x[:name] }
+    end
+
     def load
       @cfg = NeoInfra::Config.new
 

+ 28 - 0
web/controllers/dataloader.rb

@@ -0,0 +1,28 @@
+lib_dir = File.join(File.dirname(File.expand_path(__FILE__)), '..', '..', 'lib')
+$LOAD_PATH.unshift(lib_dir) unless
+  $LOAD_PATH.include?(lib_dir) || $LOAD_PATH.include?(lib_dir)
+
+require 'neoinfra'
+require 'sinatra'
+require 'sinatra/base'
+require 'sinatra/respond_to'
+
+class Dataloader < Sinatra::Base
+  register Sinatra::RespondTo
+  set :views, File.join(File.dirname(__FILE__), '..', '/views')
+
+  get '/all' do
+    respond_to do |wants|
+      wants.html {  erb :load_all,
+      :layout => :base_layout }
+    end
+  end
+
+  get '/accounts' do
+    j = NeoInfra::Accounts.new
+    #j.load
+    status 200
+    "Loaded Accounts: #{j.list_names.sort.join(' ')}"
+  end
+
+end

+ 3 - 1
web/views/base_layout.html.erb

@@ -6,7 +6,9 @@
     <meta name="description" content="">
     <meta name="author" content="">
     <link rel="icon" href="../../favicon.ico">
-    <script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
+    <script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
+
+
     <script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
 
     <title>Neo4 Infra</title>

+ 14 - 0
web/views/load_all.html.erb

@@ -0,0 +1,14 @@
+<h2 class="title"><br><br><center>Loading Data</center></h2>
+
+<% ['accounts'].each do |ep| %>
+
+<script>
+$.get( "/load/<%= ep %>", function( data ) {
+  $( ".result" ).html( data );
+  $("#div<%= ep %>").html("<h4>" + data + "</h4>");
+});
+</script>
+
+<div id="div<%= ep %>"><h4>Begin Loading <%= ep %></h4></div>
+
+<% end %>