Update add. Messy but working correctly.

This commit is contained in:
kor 2018-08-09 03:49:00 +12:00
parent df6b87825b
commit dfc294ad86
7 changed files with 64 additions and 45 deletions

View File

@ -19,12 +19,10 @@
<script src="logic/lib/runic.js"></script>
<script src="logic/lib/indental.js"></script>
<script src="content/data.ndtl"></script>
<script src="logic/wrap.js"></script>
<script src="logic/view.js"></script>
<script src="logic/main.js"></script>
<script src="logic/add.js"></script>
<script src="logic/write.js"></script>
</head>
<body>
<div class="page-overlay noselect" id="overlay"></div>
@ -35,7 +33,6 @@
<script>
var main = new Main();
main.install();
main.start();
</script>
</body>
</html>

View File

@ -1,6 +1,4 @@
const { ipcRenderer } = nodeRequire('electron');
// const mainProcess = remote.nodeRequire('./main.js');
//const mainProcess = nodeRequire('./main.js');
function Add()
{
@ -95,7 +93,10 @@ function Add()
() =>
{
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(/&nbsp;/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++)
@ -164,15 +165,16 @@ function Add()
{
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
{
value += 'TITLE<br>';
value += 'TITLE';
}
}
else if (parent.elementList[parent.keys[i]].elem.value != '')
{
value += '<br>';
value += '&nbsp;&nbsp;';
value += parent.elementList[parent.keys[i]].desc.toUpperCase() + ' : ';
@ -207,8 +209,6 @@ function Add()
{
value += parent.elementList[parent.keys[i]].elem.value.toLowerCase();
}
value += '<br>';
}
}
parent.display.innerHTML = value;

View File

@ -6,23 +6,41 @@ function Main()
this.write = null;
this.queryPrev = '';
this.queryCur = '';
var parent = this;
this.install = function()
{
this.db = new Wrap(DATABASE);
this.db.install();
let dbLoaded = false;
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.install();
this.add = new Add();
this.add.install();
this.write = new Write();
this.write.install();
var escape = document.getElementById("escape");
escape.onclick = function()
{
main.load(main.queryPrev);
}
this.start();
}
this.start = function()

View File

@ -3,9 +3,9 @@ function Wrap()
this.database = 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.process();
}

View File

@ -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!');
// });

View File

@ -1 +0,0 @@
123456789

38
main.js
View File

@ -4,6 +4,7 @@ const url = require('url')
const shell = require('electron').shell;
const fs = require('fs');
const { ipcMain } = require('electron');
const FILELOCATION = 'docs/content/data.ndtl';
let is_shown = true;
@ -94,10 +95,37 @@ app.on('activate', () => {
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+');
let buf = new Buffer(arg);
fs.writeSync(foo, buf, 0, buf.length, 5);
fs.close(foo);
// const stream = fs.createReadStream(FILELOCATION, { encoding: 'utf8' });
// stream.on('data', data => {
// header = data.split(/\n/)[0];
// 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!');
});
});