mirror of
https://github.com/TangentFoxy/memex.git
synced 2024-11-22 04:54:23 +00:00
Update add. Messy but working correctly.
This commit is contained in:
parent
df6b87825b
commit
dfc294ad86
@ -19,12 +19,10 @@
|
|||||||
<script src="logic/lib/runic.js"></script>
|
<script src="logic/lib/runic.js"></script>
|
||||||
<script src="logic/lib/indental.js"></script>
|
<script src="logic/lib/indental.js"></script>
|
||||||
|
|
||||||
<script src="content/data.ndtl"></script>
|
|
||||||
<script src="logic/wrap.js"></script>
|
<script src="logic/wrap.js"></script>
|
||||||
<script src="logic/view.js"></script>
|
<script src="logic/view.js"></script>
|
||||||
<script src="logic/main.js"></script>
|
<script src="logic/main.js"></script>
|
||||||
<script src="logic/add.js"></script>
|
<script src="logic/add.js"></script>
|
||||||
<script src="logic/write.js"></script>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="page-overlay noselect" id="overlay"></div>
|
<div class="page-overlay noselect" id="overlay"></div>
|
||||||
@ -35,7 +33,6 @@
|
|||||||
<script>
|
<script>
|
||||||
var main = new Main();
|
var main = new Main();
|
||||||
main.install();
|
main.install();
|
||||||
main.start();
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
@ -1,6 +1,4 @@
|
|||||||
const { ipcRenderer } = nodeRequire('electron');
|
const { ipcRenderer } = nodeRequire('electron');
|
||||||
// const mainProcess = remote.nodeRequire('./main.js');
|
|
||||||
//const mainProcess = nodeRequire('./main.js');
|
|
||||||
|
|
||||||
function Add()
|
function Add()
|
||||||
{
|
{
|
||||||
@ -95,7 +93,10 @@ function Add()
|
|||||||
() =>
|
() =>
|
||||||
{
|
{
|
||||||
console.log('called write');
|
console.log('called write');
|
||||||
ipcRenderer.send('write', '<br>'+this.display.innerHTML);
|
let content = this.display.innerHTML.replace(/\s?(<br\s?\/?>)\s?/g, "\r\n"); // replace line breaks
|
||||||
|
content = content.replace(/ /g, ' '); // replace tabs/spaces
|
||||||
|
// var content = content.replace(/\u00a0/g, ' ');
|
||||||
|
ipcRenderer.send('write', "\r\n" + "\r\n" + content);
|
||||||
});
|
});
|
||||||
|
|
||||||
for (var i = 0; i < this.keys.length; i++)
|
for (var i = 0; i < this.keys.length; i++)
|
||||||
@ -164,15 +165,16 @@ function Add()
|
|||||||
{
|
{
|
||||||
if (parent.elementList[parent.keys[i]].elem.value != '')
|
if (parent.elementList[parent.keys[i]].elem.value != '')
|
||||||
{
|
{
|
||||||
value += parent.elementList[parent.keys[i]].elem.value.toUpperCase() + '<br>'
|
value += parent.elementList[parent.keys[i]].elem.value.toUpperCase();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
value += 'TITLE<br>';
|
value += 'TITLE';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (parent.elementList[parent.keys[i]].elem.value != '')
|
else if (parent.elementList[parent.keys[i]].elem.value != '')
|
||||||
{
|
{
|
||||||
|
value += '<br>';
|
||||||
value += ' ';
|
value += ' ';
|
||||||
value += parent.elementList[parent.keys[i]].desc.toUpperCase() + ' : ';
|
value += parent.elementList[parent.keys[i]].desc.toUpperCase() + ' : ';
|
||||||
|
|
||||||
@ -207,8 +209,6 @@ function Add()
|
|||||||
{
|
{
|
||||||
value += parent.elementList[parent.keys[i]].elem.value.toLowerCase();
|
value += parent.elementList[parent.keys[i]].elem.value.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
value += '<br>';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
parent.display.innerHTML = value;
|
parent.display.innerHTML = value;
|
||||||
|
@ -6,23 +6,41 @@ function Main()
|
|||||||
this.write = null;
|
this.write = null;
|
||||||
this.queryPrev = '';
|
this.queryPrev = '';
|
||||||
this.queryCur = '';
|
this.queryCur = '';
|
||||||
|
var parent = this;
|
||||||
|
|
||||||
this.install = function()
|
this.install = function()
|
||||||
{
|
{
|
||||||
this.db = new Wrap(DATABASE);
|
let dbLoaded = false;
|
||||||
this.db.install();
|
const FILELOCATION = 'content/data.ndtl';
|
||||||
|
var client = new XMLHttpRequest();
|
||||||
|
client.open('GET', FILELOCATION);
|
||||||
|
client.onreadystatechange = function()
|
||||||
|
{
|
||||||
|
if (!dbLoaded && client.responseText.trim() != '')
|
||||||
|
{
|
||||||
|
dbLoaded = true;
|
||||||
|
parent.setup(client.responseText);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
client.send();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setup = function(data)
|
||||||
|
{
|
||||||
|
this.db = new Wrap();
|
||||||
|
this.db.install(data);
|
||||||
this.view = new View();
|
this.view = new View();
|
||||||
this.view.install();
|
this.view.install();
|
||||||
this.add = new Add();
|
this.add = new Add();
|
||||||
this.add.install();
|
this.add.install();
|
||||||
this.write = new Write();
|
|
||||||
this.write.install();
|
|
||||||
|
|
||||||
var escape = document.getElementById("escape");
|
var escape = document.getElementById("escape");
|
||||||
escape.onclick = function()
|
escape.onclick = function()
|
||||||
{
|
{
|
||||||
main.load(main.queryPrev);
|
main.load(main.queryPrev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.start = function()
|
this.start = function()
|
||||||
|
@ -3,9 +3,9 @@ function Wrap()
|
|||||||
this.database = null;
|
this.database = null;
|
||||||
this.keys = null;
|
this.keys = null;
|
||||||
|
|
||||||
this.install = function()
|
this.install = function(data)
|
||||||
{
|
{
|
||||||
this.database = new Indental(DATABASE).parse();
|
this.database = new Indental(data).parse();
|
||||||
this.keys = Object.keys(this.database);
|
this.keys = Object.keys(this.database);
|
||||||
this.process();
|
this.process();
|
||||||
}
|
}
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
|
|
||||||
function Write()
|
|
||||||
{
|
|
||||||
|
|
||||||
this.install = function()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
this.insert = function(data)
|
|
||||||
{
|
|
||||||
let position = 5; // get insert position
|
|
||||||
|
|
||||||
let foo = fs.openSync('foo.txt','r+');
|
|
||||||
let buf = new Buffer("hello");
|
|
||||||
fs.writeSync(foo, buf, 0, buf.length, position);
|
|
||||||
fs.close(foo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// fs.appendFile('mynewfile1.txt', 'Hello content!', function (err) {
|
|
||||||
// if (err) throw err;
|
|
||||||
// console.log('Saved!');
|
|
||||||
// });
|
|
38
main.js
38
main.js
@ -4,6 +4,7 @@ const url = require('url')
|
|||||||
const shell = require('electron').shell;
|
const shell = require('electron').shell;
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const { ipcMain } = require('electron');
|
const { ipcMain } = require('electron');
|
||||||
|
const FILELOCATION = 'docs/content/data.ndtl';
|
||||||
|
|
||||||
let is_shown = true;
|
let is_shown = true;
|
||||||
|
|
||||||
@ -94,10 +95,37 @@ app.on('activate', () => {
|
|||||||
|
|
||||||
ipcMain.on('write', (event, arg) =>
|
ipcMain.on('write', (event, arg) =>
|
||||||
{
|
{
|
||||||
console.log('Write called! Entry = ' + arg);
|
// var fileLength = fs.statSync(FILELOCATION)['size'];
|
||||||
|
// console.log('Write called! Length = ' + fileLength);
|
||||||
|
// console.log('Write called! Entry = ' + arg);
|
||||||
|
|
||||||
let foo = fs.openSync('foo.txt','r+');
|
// const stream = fs.createReadStream(FILELOCATION, { encoding: 'utf8' });
|
||||||
let buf = new Buffer(arg);
|
// stream.on('data', data => {
|
||||||
fs.writeSync(foo, buf, 0, buf.length, 5);
|
// header = data.split(/\n/)[0];
|
||||||
fs.close(foo);
|
// stream.destroy();
|
||||||
|
// });
|
||||||
|
// stream.on('close', () => {
|
||||||
|
// console.timeEnd(label);
|
||||||
|
// resolve();
|
||||||
|
// });
|
||||||
|
|
||||||
|
// fs.readFile(FILELOCATION, "utf8",
|
||||||
|
// function(err, data)
|
||||||
|
// {
|
||||||
|
// console.log(data);
|
||||||
|
// var position = data.lastIndexOf('`');
|
||||||
|
// console.log('Write called! position = ' + position);
|
||||||
|
|
||||||
|
// let fileStream = fs.openSync(FILELOCATION, 'r+');
|
||||||
|
// // let buf = new Buffer(arg);
|
||||||
|
// let buf = new Buffer('_____HERE_____');
|
||||||
|
// fs.writeSync(fileStream, buf, 0, buf.length, position);
|
||||||
|
// fs.close(fileStream);
|
||||||
|
// }
|
||||||
|
// );
|
||||||
|
|
||||||
|
fs.appendFile(FILELOCATION, arg, function (err) {
|
||||||
|
if (err) throw err;
|
||||||
|
console.log('Saved!');
|
||||||
|
});
|
||||||
});
|
});
|
Loading…
Reference in New Issue
Block a user