Skip to content
Snippets Groups Projects
Commit 72aaa1c8 authored by Maximilian Giller's avatar Maximilian Giller :squid:
Browse files

Parsing graph in front end now

parent 06757cac
No related branches found
No related tags found
No related merge requests found
Pipeline #54333 passed
...@@ -7,9 +7,58 @@ import jQuery from "jquery"; ...@@ -7,9 +7,58 @@ import jQuery from "jquery";
* *
* @param {String} spaceId Identification of graph to load. * @param {String} spaceId Identification of graph to load.
* *
* @returns Promise returning graph object. * @returns Promise returning simple graph object.
*/ */
export function loadGraphJson(spaceId) { export function loadGraphJson(spaceId) {
return loadSpaceJson(spaceId).then((json) => {
var space = Object.values(json.spaces)[0];
// Simplify nodes
var nodes = [];
Object.values(space.nodes).forEach((n) => {
var references = Object.values(n.references).map((r) => r.url);
nodes.push({
id: n.node_id,
name: n.title,
description: n.description,
type: n.type.name,
color: n.type.color,
video: n.video_url,
icon: n.icon_url,
header: n.header_url,
references: references
});
});
// Simplify links
var links = [];
Object.values(space.links).forEach((l) => {
links.push({
source: l.source_node_id,
target: l.target_node_id,
});
});
// Convert to simple object
return {
id: space.space_id,
name: space.name,
description: space.description,
nodes: nodes,
links: links,
};
});
}
/**
* Returns the json object from the stored graph as promise.
*
* @param {String} spaceId Identification of graph to load.
*
* @returns Promise returning detailed space object.
*/
export function loadSpaceJson(spaceId) {
let payload = { let payload = {
action: "get_space", action: "get_space",
space_id: spaceId, space_id: spaceId,
......
<div id="ks-editor"> <div id="ks-editor">
<!--The id "ks-editor" indicates, that the javascript associated with this should automatically be executed--> <!--The id "ks-editor" indicates, that the javascript associated with this should automatically be executed-->
<h1>Interface</h1> <h1>Interface<span id="header-space-title"></span></h1>
<div id="box-select-layer"> <div id="box-select-layer">
<div id="2d-graph"></div> <div id="2d-graph"></div>
</div> </div>
......
...@@ -4,6 +4,7 @@ import { loadGraphJson } from "../../datasets/datasets"; ...@@ -4,6 +4,7 @@ import { loadGraphJson } from "../../datasets/datasets";
import ForceGraph from "force-graph"; import ForceGraph from "force-graph";
import * as Interactions from "./interactions"; import * as Interactions from "./interactions";
import { setSpace, SPACE } from "../../config"; import { setSpace, SPACE } from "../../config";
import jquery from "jquery";
export var state = undefined; export var state = undefined;
export var graph = undefined; export var graph = undefined;
...@@ -30,6 +31,8 @@ export function loadSpace(spaceId) { ...@@ -30,6 +31,8 @@ export function loadSpace(spaceId) {
setSpace(spaceId); setSpace(spaceId);
return loadGraphJson(SPACE).then((graphConfig) => { return loadGraphJson(SPACE).then((graphConfig) => {
jquery("#ks-editor #header-space-title").text(" - " + graphConfig.name + " [" + graphConfig.id + "]");
state = new State(); state = new State();
graph = new Graph.Graph(graphConfig); graph = new Graph.Graph(graphConfig);
load(); load();
......
...@@ -24,7 +24,7 @@ function ks_add_graph($atts = []): string ...@@ -24,7 +24,7 @@ function ks_add_graph($atts = []): string
function parse_atts($atts) function parse_atts($atts)
{ {
return shortcode_atts(array( return shortcode_atts(array(
'space' => 'space', 'space' => '1',
'mode' => 'default' 'mode' => 'default'
), $atts); ), $atts);
} }
...@@ -44,14 +44,13 @@ function ks_localize($handle, $atts) ...@@ -44,14 +44,13 @@ function ks_localize($handle, $atts)
echo '</pre>'; echo '</pre>';
} }
$space_id = kg_get_space_id_from_atts($atts); // TODO: Replace with $params
$plugin_dir = plugin_dir_url(__FILE__); $plugin_dir = plugin_dir_url(__FILE__);
wp_localize_script( wp_localize_script(
$handle, $handle,
'ks_global', 'ks_global',
array( array(
'ajax_url' => admin_url('admin-ajax.php'), 'ajax_url' => admin_url('admin-ajax.php'),
'space_id' => $space_id, 'space_id' => $params['space'],
'plugin_path' => $plugin_dir, 'plugin_path' => $plugin_dir,
'mode' => $params['mode'] 'mode' => $params['mode']
) )
...@@ -79,29 +78,6 @@ function ks_load_styles() { ...@@ -79,29 +78,6 @@ function ks_load_styles() {
wp_enqueue_style('ks-style', plugins_url($styles_path, __FILE__)); wp_enqueue_style('ks-style', plugins_url($styles_path, __FILE__));
} }
function kg_escape_space_id($id)
{
return str_replace(
"\\",
"-",
str_replace(
"/",
"-",
str_replace(" ", "-", $id)
)
);
}
function kg_get_space_id_from_atts($atts)
{
if ($atts != "" && array_key_exists("space", $atts)) {
return kg_escape_space_id($atts["space"]);
} else {
return "space";
}
}
add_action('admin_menu', 'kg_editor_admin_add_page'); add_action('admin_menu', 'kg_editor_admin_add_page');
function kg_editor_admin_add_page() function kg_editor_admin_add_page()
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment