Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions build/app/assets/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
min-height: 100%
}
</style>
<script src="netcreate-config.js">
// auto generated netcreate config script
</script>
<script>
// NC_UNISYS are network parameters
if (window.NC_UNISYS) {
let err = `**FATAL ERROR** NC_UNISYS already initialized.\n\n`;
err += `Take a screen shot with your phone and report the error!`
Expand All @@ -45,6 +49,7 @@
uport : '<%=uport%>'
}
};
//
window.NC_DBG = null; // {} or null
if (window.NC_DBG) {
Object.assign(window.NC_DBG, {
Expand Down
3 changes: 3 additions & 0 deletions build/app/assets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
min-height: 100%
}
</style>
<script src="netcreate-config.js">
// auto generated netcreate config script
</script>
<script>
// index.html is loaded only by standalone mode without a server
// server-based operation uses index.ejs
Expand Down
6 changes: 6 additions & 0 deletions build/app/assets/netcreate-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// this file generated by NC command
const NC_CONFIG = {
dataset: "netcreate"
};
if (typeof process === "object") module.exports = NC_CONFIG;
if (typeof window === "object") window.NC_CONFIG = NC_CONFIG;
152 changes: 152 additions & 0 deletions build/app/assets/templates/_default.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
{

"_comments": [ "/// NetCreate Template File ///",
"/// IMPORTANT: As of 1/31/2019, the following functionality is available: ///",
"/// * `label` parameter for each field may be customized ///",
"/// * `hidden` parameter may be used to hide fields ///",
"/// * changing the order of the `options` WILL change their order on selections ///",
"/// * changing the order of the prompts themselves will NOT change their order ///",
"/// * `duplicateWarning` is used in NodeSelector ///",
"/// * `sourceNodeIsLockedMessage` is used in NodeSelector ///",
"/// * `edgeIsLockedMessage` is used in EdgeEditor ///",
"/// The rest of the definitions are there as placeholders for future functionality ///"
],

"name": "Tacitus",

"description": "Tacitus with all genders included in a single Person node type",


"nodePrompts": {
"label": {
"label": "Label",
"help": "A short title for the node",
"duplicateWarning": "You’re entering a duplicate node. Do you want to View the Existing node, or Continue creating?",
"sourceNodeIsLockedMessage": "This node is currently being edited by someone else, please try again later.",
"_cmt4": "/// `Label` is always required and cannot be hidden"
},
"type": {
"label": "Type",
"help": "Multiple people are a 'Group'",
"hidden": false,
"options": [
{
"_comment": "Default color when nothing is selected",
"id": "",
"label": "",
"color": "#EEEEEE"
},
{
"id": "person",
"label": "Person",
"color": "#aabaf2"
},
{
"id": "group",
"label": "Group",
"color": "#3399FF"
},
{
"id": "place",
"label": "Place",
"color": "#00FF00"
},
{
"id": "thing",
"label": "Thing",
"color": "#FF0000"
},
{
"id": "event",
"label": "Event",
"color": "#009999"
}
]
},
"degrees": {
"label": "Degrees",
"help": "Number of edges.",
"hidden": false
},
"notes": {
"label": "Significance",
"help": "Add some details.",
"hidden": false
},
"info": {
"label": "Geocode or Date",
"help": "Use latitude/longitude or a date mm/dd/yyy",
"hidden": true
},
"delete": {
"hidden": false
}
},



"edgePrompts": {
"edgeIsLockedMessage": "This edge is currently being edited by someone else, please try again later.",
"source": {
"label": "Source",
"help": "",
"hidden": false
},
"type": {
"label": "Type",
"help": "",
"hidden": false,
"options": [
{
"id": "notSelected",
"label": ""
},
{
"id": "peaceful",
"label": "has peaceful, familial or conversational interaction with"
},
{
"id": "martial",
"label": "has martial or adversarial interaction with"
},
{
"id": "writes",
"label": "sends written communication to"
},
{
"id": "member",
"label": "is a group member of"
},
{
"id": "participate",
"label": "participates in"
},
{
"id": "visit",
"label": "makes visit to"
}
]
},
"target": {
"label": "Target",
"help": "",
"hidden": false
},
"notes": {
"label": "Signficance",
"help": "",
"hidden": false
},
"info": {
"label": "Approximate Date of Interaction",
"help": "",
"hidden": true
},
"citation": {
"label": "Citation",
"help": "Enter Chapter number.",
"hidden": false
}
}

}
2 changes: 1 addition & 1 deletion build/app/system/datastore.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ DSTOR.PromiseJSONFile = function(jsonFile) {
D3DATA = Object.assign(D3DATA, JSON.parse(data));
resolve(D3DATA);
});
xobj.open("GET", `data/${jsonFile}`, true);
xobj.open("GET", `${jsonFile}`, true);
xobj.send();
});
return promise;
Expand Down
76 changes: 64 additions & 12 deletions build/app/unisys/server-database.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ const SESSION = require("../unisys/common-session");
const LOGGER = require("../unisys/server-logger");
const PROMPTS = require("../system/util/prompts");
const PR = PROMPTS.Pad("ServerDB");
const DB_FILE = "./runtime/netcreate.loki";
const RUNTIMEPATH = './runtime/';
const TEMPLATEPATH = './app/assets/templates/';
const DB_CLONEMASTER = "blank.loki";
const NC_CONFIG = require("../assets/netcreate-config");

/// MODULE-WIDE VARS //////////////////////////////////////////////////////////
/// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Expand All @@ -32,28 +34,34 @@ let NODES; // loki "nodes" collection
let EDGES; // loki "edges" collection
let m_locked_nodes;
let m_locked_edges;
let TEMPLATE;

/// API METHODS ///////////////////////////////////////////////////////////////
/// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
let DB = {};
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/*/ API: Initialize the database
/*/
DB.InitializeDatabase = function(options = {}) {
FS.ensureDirSync(PATH.dirname(DB_FILE));
if (!FS.existsSync(DB_FILE)) {
console.log(PR, `NO EXISTING DATABASE ${DB_FILE}, so creating BLANK DATABASE...`);
DB.InitializeDatabase = function (options = {}) {

let dataset = NC_CONFIG.dataset;
let db_file = m_GetValidDBFilePath(dataset);
FS.ensureDirSync(PATH.dirname(db_file));
if (!FS.existsSync(db_file)) {
console.log(PR, `NO EXISTING DATABASE ${db_file}, so creating BLANK DATABASE...`);
}
console.log(PR, `LOADING DATABASE ${db_file}`);
let ropt = {
autoload: true,
autoloadCallback: f_DatabaseInitialize,
autosave: true,
autosaveCallback: f_AutosaveStatus,
autosaveInterval: 4000 // save every four seconds
autosaveInterval: 4000, // save every four seconds
};
ropt = Object.assign(ropt, options);
m_db = new Loki(DB_FILE, ropt);
m_db = new Loki(db_file, ropt);
m_options = ropt;
m_options.db_file = db_file; // store for use by DB.WriteJSON

// callback on load
function f_DatabaseInitialize() {
Expand Down Expand Up @@ -118,7 +126,20 @@ DB.InitializeDatabase = function(options = {}) {
console.log(PR,`DATABASE LOADED! m_max_nodeID '${m_max_nodeID}', m_max_edgeID '${m_max_edgeID}'`);
m_db.saveDatabase();

if (typeof m_options.onLoadComplete==='function') {
// LOAD TEMPLATE - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
let templatePath = RUNTIMEPATH + NC_CONFIG.dataset + ".template";
FS.ensureDirSync(PATH.dirname(templatePath));
// Does the template exist?
if (!FS.existsSync(templatePath)) {
console.log(PR, `NO EXISTING TEMPLATE ${templatePath}, so cloning default template...`);
FS.copySync(TEMPLATEPATH+'_default.template', templatePath);
}
console.log(PR, `LOADING TEMPLATE ${templatePath}`);
// Now load it
TEMPLATE = FS.readJsonSync(templatePath);

// Call complete callback
if (typeof m_options.onLoadComplete === 'function') {
m_options.onLoadComplete();
}
} // end f_DatabaseInitialize
Expand All @@ -140,7 +161,7 @@ DB.PKT_GetDatabase = function(pkt) {
let edges = EDGES.chain().data({ removeMeta: true });
if (DBG) console.log(PR,`PKT_GetDatabase ${pkt.Info()} (loaded ${nodes.length} nodes, ${edges.length} edges)`);
LOGGER.Write(pkt.Info(), `getdatabase`);
return { nodes, edges };
return { d3data: { nodes, edges }, template: TEMPLATE };
};
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/*/ API: reset database from scratch
Expand Down Expand Up @@ -430,8 +451,13 @@ DB.FilterEdgeLog = function(edge) {
/*/ called by brunch to generate an up-to-date JSON file to path.
creates the path if it doesn't exist
/*/
DB.WriteJSON = function( filePath ) {
let db = new Loki(DB_FILE,{
DB.WriteDbJSON = function (filePath) {
let dataset = NC_CONFIG.dataset;

// Ideally we should use m_otions value, but in standlone mode,
// m_options might not be defined.
let db_file = m_options ? m_options.db_file : m_GetValidDBFilePath(dataset);
let db = new Loki(db_file,{
autoload: true,
autoloadCallback: () => {
if (typeof filePath==='string') {
Expand All @@ -446,14 +472,29 @@ DB.WriteJSON = function( filePath ) {
FS.ensureDirSync(PATH.dirname( filePath ));
if (DBG) console.log(PR,`writing file ${filePath}`);
FS.writeFileSync( filePath, json );
console.log(PR,`*** WROTE JSON DATABASE`);
console.log(PR, `*** WROTE JSON DATABASE ${filePath}`);
} else {
console.log(PR,`ERR path ${filePath} must be a pathname`);
}
}
}
);
};
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/*/ called by brunch to generate an up-to-date Template file to path.
creates the path if it doesn't exist
/*/
DB.WriteTemplateJSON = function (filePath) {
let templatePath = RUNTIMEPATH + NC_CONFIG.dataset + ".template";
FS.ensureDirSync(PATH.dirname(templatePath));
// Does the template exist?
if (!FS.existsSync(templatePath)) {
console.error(PR, `ERR could not find template ${templatePath}`);
} else {
FS.copySync(templatePath, filePath);
console.log(PR, `*** COPIED TEMPLATE ${templatePath} to ${filePath}`);
}
};

/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/// utility function for cleaning nodes with numeric id property
Expand Down Expand Up @@ -486,6 +527,17 @@ function m_CleanID(prompt, id) {
}
return id;
}
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/// utility function for getting a valid file path
function m_GetValidDBFilePath(dataset) {
// validate dataset name
let regex = /^([A-z0-9-_+./])*$/; // Allow _ - + . /, so nested pathways are allowed
if (!regex.test(dataset)) {
console.error(PR, `Trying to initialize database with bad dataset name: ${dataset}`);
}

return RUNTIMEPATH + dataset + ".loki";
}

/// EXPORT MODULE DEFINITION //////////////////////////////////////////////////
/// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Expand Down
6 changes: 3 additions & 3 deletions build/app/view/netcreate/components/EdgeEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ class EdgeEditor extends UNISYS.Component {
<FormText><b>EDGE {formData.id}</b></FormText>
<FormGroup row>
<Col sm={3}>
<Label for="source" className="small text-muted">Source</Label>
<Label for="source" className="small text-muted">{edgePrompts.source.label}</Label>
</Col>
<Col sm={9}>
<AutoComplete
Expand All @@ -794,7 +794,7 @@ class EdgeEditor extends UNISYS.Component {
</FormGroup>
<FormGroup row hidden={edgePrompts.type.hidden}>
<Col sm={3}>
<Label for="relationship" className="small text-muted">Type</Label>
<Label for="relationship" className="small text-muted">{edgePrompts.type.label}</Label>
</Col>
<Col sm={9}>
<Input type="select" name="relationship" id="relationship"
Expand All @@ -810,7 +810,7 @@ class EdgeEditor extends UNISYS.Component {
</FormGroup>
<FormGroup row>
<Col sm={3}>
<Label for="nodeLabel" className="small text-muted">Target</Label>
<Label for="nodeLabel" className="small text-muted">{edgePrompts.target.label}</Label>
</Col>
<Col sm={9}>
<AutoComplete
Expand Down
Loading