index.js aktualisiert
parent
36e4881904
commit
8ce0dfce1e
107
index.js
107
index.js
|
|
@ -1,6 +1,5 @@
|
||||||
var gui = require('gui');
|
var gui = require('gui');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var ui = require('intuition');
|
|
||||||
|
|
||||||
var rh = 14;
|
var rh = 14;
|
||||||
var sp = 4;
|
var sp = 4;
|
||||||
|
|
@ -21,7 +20,7 @@ function toListViewEntries(entries, visibleCols) {
|
||||||
const subject = ("" + e.subject).substr(0, cols - 20).padEnd(cols - 20, ' ');
|
const subject = ("" + e.subject).substr(0, cols - 20).padEnd(cols - 20, ' ');
|
||||||
const sum = ((amount >= 0 ? "+" : "") + amount.toFixed(2)).substr(0, 10).padStart(10, ' ');
|
const sum = ((amount >= 0 ? "+" : "") + amount.toFixed(2)).substr(0, 10).padStart(10, ' ');
|
||||||
const d = new Date(e.date);
|
const d = new Date(e.date);
|
||||||
const date = d.getDay().toString().padStart(2, '0') + "-" + (d.getMonth() + 1).toString().padStart(2, '0') + "-" + d.getFullYear();
|
const date = d.getDate().toString().padStart(2, '0') + "-" + (d.getMonth() + 1).toString().padStart(2, '0') + "-" + d.getFullYear();
|
||||||
let s = (date.substr(0, 10)) + " " + subject + " " + sum;
|
let s = (date.substr(0, 10)) + " " + subject + " " + sum;
|
||||||
return s;
|
return s;
|
||||||
});
|
});
|
||||||
|
|
@ -44,18 +43,24 @@ function toDateByComponents(s) {
|
||||||
function closeAccount(data, selectedAccount) {
|
function closeAccount(data, selectedAccount) {
|
||||||
let gadgets = [];
|
let gadgets = [];
|
||||||
|
|
||||||
gadgets.push({ kind: 'text', id: 301, label: "Account:", left: sp+128, top: y, width: 200, height: rh, value: selectedAccount.name});
|
const accountNameId = 301;
|
||||||
|
const remainingId = 302;
|
||||||
|
const transferCheckboxId = 303;
|
||||||
|
const targetAccountId = 304;
|
||||||
|
const executeButtonId = 305;
|
||||||
|
|
||||||
|
gadgets.push({ kind: 'text', id: accountNameId, label: "Account:", left: sp+128, top: y, width: 200, height: rh, value: selectedAccount.name});
|
||||||
const openStanding = getSummation(selectedAccount.entries);
|
const openStanding = getSummation(selectedAccount.entries);
|
||||||
gadgets.push({ kind: 'text', id: 302, label: "Remaining " + (openStanding>0? "funds": "debt"), left: sp+128, top: y+rh+sp, width: 100, height: rh})
|
gadgets.push({ kind: 'text', id: remainingId, label: "Remaining " + (openStanding>0? "funds": "debt"), left: sp+128, top: y+rh+sp, width: 100, height: rh})
|
||||||
gadgets.push({ kind: 'checkbox', id: 303, label: "Transfer to:", left: sp, top: y+rh+sp+rh+sp, height: rh, value: 0});
|
gadgets.push({ kind: 'checkbox', id: transferCheckboxId, label: "Transfer to:", left: sp, top: y+rh+sp+rh+sp, height: rh, value: 0});
|
||||||
let accounts = [];
|
let accounts = [];
|
||||||
for (let i = 0; i < data.length; ++i) {
|
for (let i = 0; i < data.length; ++i) {
|
||||||
if (data[i].name != selectedAccount.name) {
|
if (data[i].name != selectedAccount.name) {
|
||||||
accounts.push(data[i].name);
|
accounts.push(data[i].name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gadgets.push({ kind: 'cycle', id: 304, left: sp+128, top: y+rh+sp+rh+sp, width: 120, height: rh, items: accounts, value: 0 });
|
gadgets.push({ kind: 'cycle', id: targetAccountId, left: sp+128, top: y+rh+sp+rh+sp, width: 120, height: rh, items: accounts, value: 0 });
|
||||||
gadgets.push({ kind: 'button', id: 305, left: sp+128, top: y+rh+sp+rh+sp+rh+sp, height: rh, width: 120, label: "Close Account"})
|
gadgets.push({ kind: 'button', id: executeButtonId, left: sp+128, top: y+rh+sp+rh+sp+rh+sp, height: rh, width: 120, label: "Close Account"})
|
||||||
|
|
||||||
let win = gui.createWindow({
|
let win = gui.createWindow({
|
||||||
title: "Close Account '" + selectedAccount.name + "'",
|
title: "Close Account '" + selectedAccount.name + "'",
|
||||||
|
|
@ -66,8 +71,8 @@ function closeAccount(data, selectedAccount) {
|
||||||
gadgets: gadgets
|
gadgets: gadgets
|
||||||
});
|
});
|
||||||
|
|
||||||
gui.setDisabled(win, 304, true);
|
gui.setDisabled(win, targetAccountId, true);
|
||||||
gui.set(win, 302, openStanding.toFixed(2));
|
gui.set(win, remainingId, openStanding.toFixed(2));
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
var evt = gui.waitEvent(win);
|
var evt = gui.waitEvent(win);
|
||||||
|
|
@ -78,13 +83,13 @@ function closeAccount(data, selectedAccount) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (evt.type === 'gadgetup') {
|
if (evt.type === 'gadgetup') {
|
||||||
if (evt.id === 303) {
|
if (evt.id === transferCheckboxId) {
|
||||||
gui.setDisabled(win, 304, !gui.get(win, 303));
|
gui.setDisabled(win, targetAccountId, !gui.get(win, transferCheckboxId));
|
||||||
}
|
}
|
||||||
if (evt.id === 305) {
|
if (evt.id === executeButtonId) {
|
||||||
if (gui.get(win, 303)) {
|
if (gui.get(win, transferCheckboxId)) {
|
||||||
let otherAccount;
|
let otherAccount;
|
||||||
let target = accounts[gui.get(win, 304)];
|
let target = accounts[gui.get(win, targetAccountId)];
|
||||||
for (let i = 0; data.length;++i) {
|
for (let i = 0; data.length;++i) {
|
||||||
if (data[i].name === target) {
|
if (data[i].name === target) {
|
||||||
otherAccount = data[i];
|
otherAccount = data[i];
|
||||||
|
|
@ -153,6 +158,14 @@ function subWindow(data) {
|
||||||
let gadgets = [];
|
let gadgets = [];
|
||||||
let removable = false;
|
let removable = false;
|
||||||
|
|
||||||
|
const subjectInputId = 401;
|
||||||
|
const amountInputId = 402;
|
||||||
|
const dateInputId = 403;
|
||||||
|
const transferCheckboxId = 404;
|
||||||
|
const transferAccountInputId = 405;
|
||||||
|
const executeButtonId = 406;
|
||||||
|
const deleteButtonId = 407;
|
||||||
|
|
||||||
const innerData = {
|
const innerData = {
|
||||||
date: Date.now(),
|
date: Date.now(),
|
||||||
subject: '',
|
subject: '',
|
||||||
|
|
@ -169,31 +182,31 @@ function subWindow(data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
let d = new Date(innerData.date);
|
let d = new Date(innerData.date);
|
||||||
let formattedDate = (""+d.getDay()).padStart(2, "0") + "-" + (""+(d.getMonth() + 1)).padStart(2, "0") + "-" + d.getFullYear();
|
let formattedDate = (""+d.getDate()).padStart(2, "0") + "-" + (""+(d.getMonth() + 1)).padStart(2, "0") + "-" + d.getFullYear();
|
||||||
|
|
||||||
gadgets.push({
|
gadgets.push({
|
||||||
kind: 'string', id: 1, label: 'Subject:',
|
kind: 'string', id: subjectInputId, label: 'Subject:',
|
||||||
left: sp + 80, top: y, width: 400 - sp - 80 - sp, height: rh,
|
left: sp + 80, top: y, width: 400 - sp - 80 - sp, height: rh,
|
||||||
value: innerData.subject
|
value: innerData.subject
|
||||||
});
|
});
|
||||||
gadgets.push({
|
gadgets.push({
|
||||||
kind: 'string', id: 2, label: 'Amount:',
|
kind: 'string', id: amountInputId, label: 'Amount:',
|
||||||
left: sp + 80, top: sp + rh + sp, width: 100, height: rh,
|
left: sp + 80, top: sp + rh + sp, width: 100, height: rh,
|
||||||
value: innerData.amount.toFixed(2)
|
value: innerData.amount.toFixed(2)
|
||||||
});
|
});
|
||||||
gadgets.push({
|
gadgets.push({
|
||||||
kind: 'string', id: 3, label: 'Date:',
|
kind: 'string', id: dateInputId, label: 'Date:',
|
||||||
left: sp + 80, top: sp + rh + sp + rh + sp, width: 150, height: rh,
|
left: sp + 80, top: sp + rh + sp + rh + sp, width: 150, height: rh,
|
||||||
value: formattedDate
|
value: formattedDate
|
||||||
});
|
});
|
||||||
gadgets.push({ kind: 'checkbox', id: 6, label: "Account:", left: sp + 80, top: sp + rh + sp + rh + sp + rh + sp + 2, width: rh, height: rh, value: 0 });
|
gadgets.push({ kind: 'checkbox', id: transferCheckboxId, label: "Account:", left: sp + 80, top: sp + rh + sp + rh + sp + rh + sp + 2, width: rh, height: rh, value: 0 });
|
||||||
|
|
||||||
const accounts = getAccounts(projectData);
|
const accounts = getAccounts(projectData);
|
||||||
|
|
||||||
gadgets.push({ kind: 'cycle', id: 7, left: sp + 160 + rh + sp, top: sp + rh + sp + rh + sp + rh + sp, width: 120, height: rh, items: accounts, value: 0 });
|
gadgets.push({ kind: 'cycle', id: transferAccountInputId, left: sp + 160 + rh + sp, top: sp + rh + sp + rh + sp + rh + sp, width: 120, height: rh, items: accounts, value: 0 });
|
||||||
|
|
||||||
gadgets.push({ kind: 'button', id: 4, left: sp + 80, top: sp + rh + sp + rh + sp + rh + sp + rh + sp, width: 80, label: "Save", height: rh });
|
gadgets.push({ kind: 'button', id: executeButtonId, left: sp + 80, top: sp + rh + sp + rh + sp + rh + sp + rh + sp, width: 80, label: "Save", height: rh });
|
||||||
gadgets.push({ kind: 'button', id: 5, left: sp + 80 + sp + 80, top: sp + rh + sp + rh + sp + rh + sp + rh + sp, width: 80, label: "Remove", height: rh });
|
gadgets.push({ kind: 'button', id: deleteButtonId, left: sp + 80 + sp + 80, top: sp + rh + sp + rh + sp + rh + sp + rh + sp, width: 80, label: "Remove", height: rh });
|
||||||
|
|
||||||
let win = gui.createWindow({
|
let win = gui.createWindow({
|
||||||
title: 'Entry Details',
|
title: 'Entry Details',
|
||||||
|
|
@ -205,7 +218,7 @@ function subWindow(data) {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (innerData.targetAccount) {
|
if (innerData.targetAccount) {
|
||||||
gui.set(win, 6, 1);
|
gui.set(win, transferCheckboxId, 1);
|
||||||
let i = -1;
|
let i = -1;
|
||||||
for (i = 0; i < accounts.length; i++) {
|
for (i = 0; i < accounts.length; i++) {
|
||||||
if (accounts[i] === innerData.targetAccount) {
|
if (accounts[i] === innerData.targetAccount) {
|
||||||
|
|
@ -213,12 +226,12 @@ function subWindow(data) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gui.set(win, 7, i);
|
gui.set(win, 7, i);
|
||||||
gui.setDisabled(win, 7, false);
|
gui.setDisabled(win, transferAccountInputId, false);
|
||||||
} else {
|
} else {
|
||||||
gui.setDisabled(win, 7, true);
|
gui.setDisabled(win, transferAccountInputId, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
gui.setDisabled(win, 5, !removable);
|
gui.setDisabled(win, deleteButtonId, !removable);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
var evt = gui.waitEvent(win);
|
var evt = gui.waitEvent(win);
|
||||||
|
|
@ -229,16 +242,16 @@ function subWindow(data) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (evt.type === 'gadgetup') {
|
if (evt.type === 'gadgetup') {
|
||||||
if (evt.id === 6) {
|
if (evt.id === transferCheckboxId) {
|
||||||
gui.setDisabled(win, 7, !gui.get(win, 6));
|
gui.setDisabled(win, transferAccountInputId, !gui.get(win, transferAccountInputId));
|
||||||
}
|
}
|
||||||
if (evt.id === 4) {
|
if (evt.id === executeButtonId) {
|
||||||
innerData.subject = gui.get(win, 1);
|
innerData.subject = gui.get(win, subjectInputId);
|
||||||
innerData.amount = parseFloat(gui.get(win, 2));
|
innerData.amount = parseFloat(gui.get(win, amountInputId));
|
||||||
innerData.date = toDateByComponents(gui.get(win, 3));
|
innerData.date = toDateByComponents(gui.get(win, dateInputId));
|
||||||
|
|
||||||
if (gui.get(win, 6)) {
|
if (gui.get(win, transferCheckboxId)) {
|
||||||
const targetAccountIndex = gui.get(win, 7);
|
const targetAccountIndex = gui.get(win, transferAccountInputId);
|
||||||
if (targetAccountIndex !== null && targetAccountIndex !== undefined) {
|
if (targetAccountIndex !== null && targetAccountIndex !== undefined) {
|
||||||
innerData.targetAccount = data[targetAccountIndex].name;
|
innerData.targetAccount = data[targetAccountIndex].name;
|
||||||
}
|
}
|
||||||
|
|
@ -247,7 +260,7 @@ function subWindow(data) {
|
||||||
gui.closeWindow(win);
|
gui.closeWindow(win);
|
||||||
return innerData;
|
return innerData;
|
||||||
}
|
}
|
||||||
if (evt.id === 5) {
|
if (evt.id === deleteButtonId) {
|
||||||
gui.closeWindow(win);
|
gui.closeWindow(win);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
@ -324,9 +337,9 @@ function mainWindow(projectData) {
|
||||||
|
|
||||||
let currentAccountIndex = 0;
|
let currentAccountIndex = 0;
|
||||||
|
|
||||||
let updateView = (g, w, accountIndex, data) => {
|
let updateView = (accountIndex, data) => {
|
||||||
g.set(w, 2, toListViewEntries(data[accountIndex].entries, cols));
|
gui.set(win, 2, toListViewEntries(data[accountIndex].entries, cols));
|
||||||
g.set(w, 3, getSummation(data[accountIndex].entries).toFixed(2));
|
gui.set(win, 3, getSummation(data[accountIndex].entries).toFixed(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
let doNew = () => {
|
let doNew = () => {
|
||||||
|
|
@ -347,13 +360,14 @@ function mainWindow(projectData) {
|
||||||
invalidate = false;
|
invalidate = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let doSave = (g, data) => {
|
let doSave = () => {
|
||||||
var r = g.fileRequest({ title: 'Save File', pattern: '#?.json', save: true });
|
var r = gui.fileRequest({ title: 'Save File', pattern: '#?.json', save: true });
|
||||||
if (r) {
|
if (r) {
|
||||||
fs.writeFileSync(r.file, JSON.stringify(data));
|
fs.writeFileSync(r.file, JSON.stringify(internalProjectData));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gui.setMenuItem(win, 105, {disabled: internalProjectData.length<=1});
|
||||||
|
|
||||||
|
|
||||||
while (!invalidate) {
|
while (!invalidate) {
|
||||||
|
|
@ -375,7 +389,7 @@ function mainWindow(projectData) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (evt.id === 103) {
|
else if (evt.id === 103) {
|
||||||
doSave(gui, internalProjectData);
|
doSave();
|
||||||
}
|
}
|
||||||
else if (evt.id === 104) {
|
else if (evt.id === 104) {
|
||||||
addAccount(internalProjectData);
|
addAccount(internalProjectData);
|
||||||
|
|
@ -389,8 +403,9 @@ function mainWindow(projectData) {
|
||||||
invalidate = true;
|
invalidate = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ui.alert("Cannot close last remaining Account");
|
gui.alert("Cannot close last remaining Account");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (evt.id === 199) {
|
else if (evt.id === 199) {
|
||||||
invalidate = true;
|
invalidate = true;
|
||||||
|
|
@ -402,7 +417,7 @@ function mainWindow(projectData) {
|
||||||
|
|
||||||
if (evt.id === cycleId) {
|
if (evt.id === cycleId) {
|
||||||
currentAccountIndex = evt.code;
|
currentAccountIndex = evt.code;
|
||||||
updateView(gui, win, currentAccountIndex, internalProjectData);
|
updateView(currentAccountIndex, internalProjectData);
|
||||||
} else if (evt.id === listViewId) {
|
} else if (evt.id === listViewId) {
|
||||||
const entry = subWindow(internalProjectData[currentAccountIndex].entries[evt.code]);
|
const entry = subWindow(internalProjectData[currentAccountIndex].entries[evt.code]);
|
||||||
if (entry != null) {
|
if (entry != null) {
|
||||||
|
|
@ -421,7 +436,7 @@ function mainWindow(projectData) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateView(gui, win, currentAccountIndex, internalProjectData);
|
updateView(currentAccountIndex, internalProjectData);
|
||||||
}
|
}
|
||||||
} else if (evt.id === addButtonId) {
|
} else if (evt.id === addButtonId) {
|
||||||
const entry = subWindow();
|
const entry = subWindow();
|
||||||
|
|
@ -438,7 +453,7 @@ function mainWindow(projectData) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateView(gui, win, currentAccountIndex, internalProjectData);
|
updateView(currentAccountIndex, internalProjectData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue