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

Implemented listing spaces

parent b52466ea
No related branches found
No related tags found
No related merge requests found
Pipeline #54711 passed
<?php
require_once(__DIR__."/ks-datasets-database.php");
$EMPTY_SPACE = '{"links":[],"nodes":[]}';
$SPACES_DIR = __DIR__."/spaces/";
......@@ -21,7 +22,7 @@ function kg_get_space() {
add_action("wp_ajax_list_spaces", "kg_list_spaces"); // Fires only for logged-in-users
function kg_list_spaces() {
$spaces = kg_get_list_of_spaces();
$spaces = ks_select_spaces();
$payload = array("spaces" => $spaces);
echo json_encode($payload);
......@@ -66,25 +67,6 @@ function kg_get_space_file_path($space_id) {
return $SPACES_DIR.$space_id.".json";
}
function kg_get_list_of_spaces() {
global $SPACES_DIR;
$all_files = scandir($SPACES_DIR);
if ($all_files == false) {
return [];
}
$spaces = [];
foreach ($all_files as $file) {
if (endsWith($file, ".json")) {
$spaces[] = substr($file, 0, -strlen(".json"));
}
}
return $spaces;
}
function kg_create_empty_space($file_path) {
// Don't do anything, if it exists
if (file_exists($file_path)) {
......
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once(__DIR__ . "/../knowledge-space-database.php");
function ks_insert_or_update_graph($graph)
{
}
function ks_select_spaces()
{
global $SPACES_TABLE;
$sql = "SELECT * FROM $SPACES_TABLE";
global $wpdb;
$results = $wpdb->get_results($sql); // or die(mysql_error());
return ks_spaces_to_array($results);
}
function ks_spaces_to_array($spaces)
{
$array = array();
foreach ($spaces as $space) {
$space_id = $space->space_id;
$array_space = array(
"space_id" => $space_id,
"name" => $space->name,
"description" => $space->description
);
$array[$space_id] = $array_space;
}
return $array;
}
......@@ -14,13 +14,14 @@ export function initInteractions() {
// Fill space dropdown
var selectContainer = jQuery("#space-id-select");
listAllSpaces().then((spaces) => {
spaces.forEach(space => {
Object.keys(spaces).forEach(space_id => {
var selectedTxt = "";
if (space === SPACE) {
var space = spaces[space_id];
if (space.name === SPACE) {
selectedTxt = "selected ";
}
var child = "<option " + selectedTxt + "value=\"" + space + "\">" + space + "</option>"
var child = "<option " + selectedTxt + "value=\"" + space_id + "\" title=\"" + space.description + "\">" + space.name + "</option>"
selectContainer.append(child);
});
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment