How to enter in sintra / haml?

I encoded a small web application that runs ant (batch file). Processing time for a batch file can take up to several minutes.

index.haml list all available ant files and run.haml launches them. The flow of how it works now is that when I click the link from index.haml, the ant script is launched, and after it finishes, the entire run.haml page is sent to the browser. So after clicking the link to index.haml, I still see index.haml and nothing from run.haml

After I click the link from index.haml , I want

  • show that the script will be run and then
  • run ant script and then
  • display its results.

I recommended using my other question

I did not understand how a separate workflow can help me. Will the delayed work results captured by the ruby ​​call to the browser after the task is completed?

I also did not understand how I can use Ajax in the sinatra.

Can someone please tell me what solution could be for this? Please note that I know a little ruby, learned a little about sinatra and hamla yesterday. There is nothing about Ajax :-) I will learn by examples ... and am happy to learn something.

index.haml gives me html like

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
      <head>
        <title>Available test suits</title>
      </head>
      <body>
        <h1>Available test suits</h1>
        <br/><br/>
        <a href='run?run=login_build'>login_build</a>
        <br />
        <a href='run?run=login_cycle_build'>login_cycle_build</a>
        <br />
        <a href='run?run=login_cycle_academicyear_build'>login_cycle_academicyear_build</a>
      </body>
    </html>

run.haml looks like

    !!!  
    %html  
      %head  
        %title Running  
      %body
        = "Starting test suite: #{params['run']}"
        - output = %x[cd C:\\Program Files\\TestPro\\TestPro Automation Framework410 && ant -lib lib -f "C:\\Program Files\\TestPro\\TestPro Automation Framework410\\Output Files\\builds\\#{params['run']}.xml"]
        -#The result is
        %br
        = output.split("\n")[-2,2].join("<BR>")
        = "<br/>"*2
        %a(href="/")back to suits list
+3
source share
2 answers

Ajax , javascript- Dojo, Prototype, Mootools, jQuery... ajax.

javascript xhr ( Ajax), , Sinatra , - , .

var xhrLoadClientMenu = function(param){
var result_node = dojo.byId('div_menu')
var xhrArgs = {
  // the Sinatra get "/run" ... end handler
  url: '/run',
  load: function(data){
    // When response is rendered come here 
    result_node.innerHTML = data;
  },
  error: function(error){
    msg = "<p>Ooops some error ...<br><br>" + error + "</p>";
   }
 }
  // Here you can put what you want to display durring loading
  result_node.innerHtml = "Loading..." 
  var defered = dojo.xhrGet(xhrArgs)
}

xhrGet dojo. . .

  • xhrLoadClientMenu (param) ;
  • HTML- id #div_menu result_node;
  • xhrArgs Ajax :
    • url: Sinatra, ;
    • load: result_node .
    • , - , result_node;
  • result_node -, ;
  • xhr.

.

+1

Delayed_job " ". , Sinatra DJ .

, , , . , , ; , , DJ . ; , - , .

, , delayed_job - " " , "", .

Ajax . Javascript , ​​ . , , - , Sinatra delayed_job, , , , Ruby.

+1

Source: https://habr.com/ru/post/1769690/


All Articles