Skip to content

Commit

Permalink
API call done via Routing and AJAX
Browse files Browse the repository at this point in the history
  • Loading branch information
jsvdvis committed Mar 29, 2018
1 parent a02066a commit 2113833
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 14 deletions.
60 changes: 60 additions & 0 deletions app/EvidencioAPI.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace App;

class EvidencioAPI
{
/*
* @return API response converted into a PHP variable.
* @throws JsonDecodeException if JSON response could not be decoded.
* Other possible exceptions are listed in Guzzle's documentation
*/
private static function fetch($path, $params = [])
{
$client = new \GuzzleHttp\Client(['base_uri' => 'https://www.evidencio.com/api/']);
$res = $client->post($path,
[
'headers' => [
'Accept' => 'application/json',
'Authorization' => config('app.evidencio_key')
],
'form_params' => $params
]);
$json = json_decode($res->getBody());
if(is_null($json))
{
throw new Exceptions\JsonDecodeException("Could not decode API response to JSON: '".$res->getBody()."'.");
}
return $json;
}

public static function overview()
{
return self::fetch("overview");
}

public static function search($query)
{
return self::fetch("search",["query" => $query]);
}

public static function models()
{
return self::fetch("models");
}

public static function getModel($id)
{
return self::fetch("model",["id" => $id]);
}

/*
* @param $values array of key-value pairs for each variable where id is the key
*/
public static function run($id,$values)
{
$values["id"] = $id;
return self::fetch("run",$values);
}

}
7 changes: 7 additions & 0 deletions app/Exceptions/JsonDecodeException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace App\Exceptions;

use Exception;

class JsonDecodeException extends Exception { }
12 changes: 12 additions & 0 deletions app/Http/Controllers/DesignerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\EvidencioAPI;

class DesignerController extends Controller
{
Expand All @@ -25,4 +26,15 @@ public function index()
{
return view('designer');
}

/**
* Fetch
*
*/
public function fetchVariables()
{
$modelID = $_GET['modelID'];
$data = EvidencioAPI::getModel($modelID);
return json_encode($data);
}
}
Binary file added composer.phar
Binary file not shown.
8 changes: 8 additions & 0 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@

'cipher' => 'AES-256-CBC',

/*
|--------------------------------------------------------------------------
| Evidencio API key
|--------------------------------------------------------------------------
*/

'evidencio_key' => env('EVIDENCIO_KEY'),

/*
|--------------------------------------------------------------------------
| Autoloaded Service Providers
Expand Down
29 changes: 15 additions & 14 deletions public/js/sidebar.js

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions public/js/workflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -2640,6 +2640,17 @@ var cyCanvas = __webpack_require__(49);
cyCanvas(cytoscape);
//const tippy = require('tippy.js')

window.model = [];

$.ajax({
url: '/designer/fetch',
data: {
'modelID': 756
},
success: function success(result) {
model = JSON.parse(result);
}
});

//Init Cytoscape
var cy = cytoscape({
Expand Down
1 change: 1 addition & 0 deletions resources/assets/js/sidebar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var $ = require('jquery');
window.$ = $;
require("malihu-custom-scrollbar-plugin");
require("jquery-mousewheel");
require('octicons');
Expand Down
11 changes: 11 additions & 0 deletions resources/assets/js/workflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ const cyCanvas = require('cytoscape-canvas');
cyCanvas(cytoscape);
//const tippy = require('tippy.js')

window.model = [];

$.ajax({
url: '/designer/fetch',
data: {
'modelID': 756
},
success: function (result) {
model = JSON.parse(result);
}
})

//Init Cytoscape
const cy = cytoscape({
Expand Down
2 changes: 2 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
Auth::routes();

Route::get('/designer', 'DesignerController@index')->name('designer');
Route::get('/designer/fetch', 'DesignerController@fetchVariables');

Route::get('/graph', function () {
return view('graph');
});

0 comments on commit 2113833

Please sign in to comment.