Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


Infodetails
hiddentrue

This article in Russian: Инструкция по интеграции HBW во внешнюю систему

...

The following methods need to be implemented for sending requests ted for sending  GET, POST, PUT and PUT DELETE requests to the HydraOMS backend:

Code Block
languageruby
def request_bpmwidget_backend(path, method = :get, parameters = {})
  request_params = {
      method:   method,
      url:      build_bpm_widget_path(path),
      user:     bpm_config.hbw_login,
      password: bpm_config.passwordhbw_token
  }
  
  if method == :get
    request_params.merge!({headers: {params: parameters.merge(bpm_parameters)}})
  else
    request_params.merge!({payload: parameters.merge(bpm_parameters)})
  end
  
 response(params) end
 
private
 
def response(params)
  response = RestClient::Request.execute(request_params)
end
  
{private
  
 code: response.code,
    headers: response.headers,
    body: response.body
  }
end
 
def request_params(path)def bpm_parameters
  {
    urluser_identifier:      build_bpm_widget_path(path)config[:hbw_login],
    userentity_type:     configurationparams[:loginentity_type],
    passwordentity_code: configuration    params[:passwordentity_code],
    headersentity_class: {       'Content-Type': 'application/json'
    }
  }
end
 
params[:entity_class]
  }
end
  
def build_bpm_widget_path(path = '')
  URI.join(configuration[:url]bpm_config.url, '/widget/', path)
end
 
def configuration
  {
    url:      "http://homs:3000", # hbw_url
    login:    "user@example.com", # hbw_login
    password: "renewmeplease"     # hbw_token
  }
end
 
def with_user_identifier(parameters)
  parameters.merge(
    user_identifier: session[:email] # email of current user
  )
end    
   
def allow_params(*allowed_params)
  with_user_identifier(params.slice(*allowed_params))
end

...

.to_s
end
  
def bpm_config
  YourApplication::Config.widgets.bpm
end

GET and DELETE parameters should be passed as query part of url, e.g.: 

...

Code Block
languagexml
titleHTML page example
<html>
<head>
  <title>HydraOMS Widget</title>
  <script type="text/javascript" src="${hbw_public_path}/assets/hbw.js"></script>
  <link rel="stylesheet" type="text/css" href="${hbw_public_path}/assets/hbw.css">
</head>
<body>
  <div class="hbw-styles">
   <div id='hbw-container'>
   </div>
  </div>
  <script type="text/javascript">
    var config = {
      widgetURL: 'https://homs.some.domain', // hbw_public_path, important for WebSocket connection
      entity_class: 'crm_account',
      entity_type: 'customer',
      container_id: 'hbw-container', // Same as <div> id
      userIdentifier: 'user@example.com', // user identifier for Web-Socket connection
      locale: {
        code: 'en', // locale code
        dateTimeFormat: 'MM/DD/YYYY HH:mm aaa' // date-fns fomatformat, see https://date-fns.org/v1.30.1/docs/format for more details
      }
    };
    var entityId = ...; // Set here id or other uniq value of entity, like customerId
 
    window.hbw_widget = new (modulejs.require('HBW'))({
      userIdentifier: config.userIdentifier,
      widgetContainer: `#${config.container_id}`,
      widgetURL: config.widgetURL,
      widgetPath: '/widget',
      entity_class: config.entity_class,
      entity_type: config.entity_type,
      entity_code: `${entityId}`,
      locale: config.locale,
      payload: {
        variables: {
          someInitialVariable: { // You can pass other useful information to process initial_variables
            value: 'initialValue',
            type: 'string'
          }
        }
      }
    });
 
    window.hbw_widget.render();
 
    // If you use some kind ot SPA (Single Page Application), call this before exiting current page:
    // window.hbw_widget.unmountWidget();
  </script>
</body>
</html>

...