index.js aktualisiert
parent
4d1ff99d24
commit
d470d04d69
183
index.js
183
index.js
|
|
@ -5,47 +5,6 @@ var rh = 14;
|
||||||
var sp = 4;
|
var sp = 4;
|
||||||
var y = sp;
|
var y = sp;
|
||||||
|
|
||||||
|
|
||||||
let projectData = [
|
|
||||||
{
|
|
||||||
name: "Current",
|
|
||||||
entries: [
|
|
||||||
{
|
|
||||||
date: 1704067200000,
|
|
||||||
subject: '(Savings) Initial Deposit',
|
|
||||||
amount: -500,
|
|
||||||
targetAccount: "Savings"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
date: 1704067200000,
|
|
||||||
subject: 'Salary',
|
|
||||||
amount: 2182.15
|
|
||||||
},
|
|
||||||
{
|
|
||||||
date: 1704153600000,
|
|
||||||
subject: 'Rent',
|
|
||||||
amount: -800
|
|
||||||
},
|
|
||||||
{
|
|
||||||
date: 1704240000000,
|
|
||||||
subject: 'Groceries',
|
|
||||||
amount: -24.19
|
|
||||||
}
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Savings",
|
|
||||||
entries: [
|
|
||||||
{
|
|
||||||
date: 1704067200000,
|
|
||||||
subject: 'Initial Deposit',
|
|
||||||
amount: 500
|
|
||||||
}
|
|
||||||
],
|
|
||||||
}
|
|
||||||
|
|
||||||
];
|
|
||||||
|
|
||||||
function getAccounts(data) {
|
function getAccounts(data) {
|
||||||
const resultData = [];
|
const resultData = [];
|
||||||
for (let i = 0; i < data.length; i++) {
|
for (let i = 0; i < data.length; i++) {
|
||||||
|
|
@ -101,7 +60,7 @@ function subWindow(data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
let d = new Date(innerData.date);
|
let d = new Date(innerData.date);
|
||||||
let formattedDate = d.getDay() + "-" + (d.getMonth() + 1) + "-" + d.getFullYear();
|
let formattedDate = (""+d.getDay()).padStart(2, "0") + "-" + (""+(d.getMonth() + 1)).padStart(2, "0") + "-" + d.getFullYear();
|
||||||
|
|
||||||
gadgets.push({
|
gadgets.push({
|
||||||
kind: 'string', id: 1, label: 'Subject:',
|
kind: 'string', id: 1, label: 'Subject:',
|
||||||
|
|
@ -187,7 +146,11 @@ function subWindow(data) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function mainWindow() {
|
function mainWindow(projectData) {
|
||||||
|
|
||||||
|
let internalProjectData = projectData;
|
||||||
|
|
||||||
|
let invalidate = false;
|
||||||
|
|
||||||
let gadgets = [];
|
let gadgets = [];
|
||||||
|
|
||||||
|
|
@ -201,7 +164,7 @@ function mainWindow() {
|
||||||
gadgets.push({
|
gadgets.push({
|
||||||
kind: 'cycle', id: cycleId,
|
kind: 'cycle', id: cycleId,
|
||||||
left: sp, top: y, width: 120, height: rh, border: false,
|
left: sp, top: y, width: 120, height: rh, border: false,
|
||||||
items: getAccounts(projectData), value: 0
|
items: getAccounts(internalProjectData), value: 0
|
||||||
});
|
});
|
||||||
|
|
||||||
gadgets.push({ kind: 'button', id: addButtonId, left: 500 - 80 - sp, top: y, width: 80, label: "+Transfer", height: rh });
|
gadgets.push({ kind: 'button', id: addButtonId, left: 500 - 80 - sp, top: y, width: 80, label: "+Transfer", height: rh });
|
||||||
|
|
@ -209,18 +172,18 @@ function mainWindow() {
|
||||||
gadgets.push({
|
gadgets.push({
|
||||||
kind: 'listview', id: listViewId, left: sp, top: y + rh + sp, width: 500 - sp - sp, height: 186,
|
kind: 'listview', id: listViewId, left: sp, top: y + rh + sp, width: 500 - sp - sp, height: 186,
|
||||||
flex: true,
|
flex: true,
|
||||||
items: toListViewEntries(projectData[0].entries, cols), value: 0
|
items: toListViewEntries(internalProjectData[0].entries, cols), value: 0
|
||||||
});
|
});
|
||||||
|
|
||||||
gadgets.push({
|
gadgets.push({
|
||||||
kind: 'text', id: balanceId, label: 'Balance:',
|
kind: 'text', id: balanceId, label: 'Balance:',
|
||||||
left: 100, top: y + rh + sp + 186, width: 400 - sp, height: rh,
|
left: 100, top: y + rh + sp + 186, width: 400 - sp, height: rh,
|
||||||
value: getSummation(projectData[0].entries).toFixed(2)
|
value: getSummation(internalProjectData[0].entries).toFixed(2)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var win = gui.createWindow({
|
let win = gui.createWindow({
|
||||||
title: 'Budget',
|
title: 'Budget',
|
||||||
width: 500,
|
width: 500,
|
||||||
height: 14 + 4 + 4 + 200 + 4,
|
height: 14 + 4 + 4 + 200 + 4,
|
||||||
|
|
@ -245,98 +208,104 @@ function mainWindow() {
|
||||||
|
|
||||||
let currentAccountIndex = 0;
|
let currentAccountIndex = 0;
|
||||||
|
|
||||||
function updateView() {
|
let updateView = (g, w, accountIndex, data) => {
|
||||||
gui.set(win, listViewId, toListViewEntries(projectData[currentAccountIndex].entries, cols));
|
g.set(w, 2, toListViewEntries(data[accountIndex].entries, cols));
|
||||||
gui.set(win, balanceId, getSummation(projectData[currentAccountIndex].entries).toFixed(2));
|
g.set(w, 3, getSummation(data[accountIndex].entries).toFixed(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
function doNew() {
|
let doNew = () => {
|
||||||
projectData = [
|
invalidate = true;
|
||||||
|
return [
|
||||||
{
|
{
|
||||||
name: "Current",
|
name: "Current",
|
||||||
entries: []
|
entries: []
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
currentAccountIndex = 0;
|
|
||||||
gui.set(win, cycleId, getAccounts(projectData));
|
|
||||||
gui.set(win, cycleId, 0);
|
|
||||||
updateView();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function doOpen() {
|
let doOpen = () => {
|
||||||
var r = gui.fileRequest({ title: 'Open File', pattern: '#?.json' });
|
var r = gui.fileRequest({ title: 'Open File', pattern: '#?.json' });
|
||||||
if (r) {
|
if (r) {
|
||||||
projectData = JSON.parse(fs.readFileSync(r.file));
|
return JSON.parse(fs.readFileSync(r.file));
|
||||||
}
|
}
|
||||||
|
invalidate = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function doSave() {
|
function doSave() {
|
||||||
var r = gui.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(projectData));
|
fs.writeFileSync(r.file, JSON.stringify(internalProjectData));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (true) {
|
|
||||||
|
|
||||||
|
while (!invalidate) {
|
||||||
var evt = gui.waitEvent(win);
|
var evt = gui.waitEvent(win);
|
||||||
if (!evt) continue;
|
if (!evt) continue;
|
||||||
|
|
||||||
if (evt.type === 'close') break;
|
if (evt.type === 'close') {
|
||||||
|
invalidate = true;
|
||||||
|
internalProjectData = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (evt.type === 'menu') {
|
if (evt.type === 'menu') {
|
||||||
if (evt.id === 101) doNew();
|
if (evt.id === 101) {
|
||||||
else if (evt.id === 102) doOpen();
|
internalProjectData = doNew();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (evt.id === 102) {
|
||||||
|
internalProjectData = doOpen();
|
||||||
|
break;
|
||||||
|
}
|
||||||
else if (evt.id === 103) doSave();
|
else if (evt.id === 103) doSave();
|
||||||
else if (evt.id === 199) break;
|
else if (evt.id === 199) {
|
||||||
|
invalidate = true;
|
||||||
|
internalProjectData = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (evt.type === 'gadgetup') {
|
if (evt.type === 'gadgetup') {
|
||||||
|
|
||||||
if (evt.id === cycleId) {
|
if (evt.id === cycleId) {
|
||||||
currentAccountIndex = evt.code;
|
currentAccountIndex = evt.code;
|
||||||
updateView();
|
updateView(gui, win, currentAccountIndex, internalProjectData);
|
||||||
}
|
} else if (evt.id === listViewId) {
|
||||||
|
const entry = subWindow(internalProjectData[currentAccountIndex].entries[evt.code]);
|
||||||
if (evt.id === listViewId) {
|
|
||||||
const entry = subWindow(projectData[currentAccountIndex].entries[evt.code]);
|
|
||||||
if (entry != null) {
|
if (entry != null) {
|
||||||
if (entry === -1) {
|
if (entry === -1) {
|
||||||
projectData[currentAccountIndex].entries.splice(evt.code, 1);
|
internalProjectData[currentAccountIndex].entries.splice(evt.code, 1);
|
||||||
} else {
|
} else {
|
||||||
projectData[currentAccountIndex].entries[evt.code] = entry;
|
internalProjectData[currentAccountIndex].entries[evt.code] = entry;
|
||||||
}
|
}
|
||||||
if (entry.targetAccount) {
|
if (entry.targetAccount) {
|
||||||
const targetAccount = projectData.find(d => d.name === entry.targetAccount);
|
const targetAccount = internalProjectData.find(d => d.name === entry.targetAccount);
|
||||||
if (targetAccount) {
|
if (targetAccount) {
|
||||||
targetAccount.entries.push({
|
targetAccount.entries.push({
|
||||||
date: entry.date,
|
date: entry.date,
|
||||||
subject: "(" + projectData[currentAccountIndex].name + ")" + entry.subject,
|
subject: "(" + internalProjectData[currentAccountIndex].name + ")" + entry.subject,
|
||||||
amount: -entry.amount
|
amount: -entry.amount
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateView();
|
updateView(gui, win, currentAccountIndex, internalProjectData);
|
||||||
}
|
}
|
||||||
}
|
} else if (evt.id === addButtonId) {
|
||||||
if (evt.id === addButtonId) {
|
|
||||||
const entry = subWindow();
|
const entry = subWindow();
|
||||||
if (entry != null) {
|
if (entry != null) {
|
||||||
projectData[currentAccountIndex].entries.push(entry);
|
internalProjectData[currentAccountIndex].entries.push(entry);
|
||||||
|
|
||||||
if (entry.targetAccount) {
|
if (entry.targetAccount) {
|
||||||
const targetAccount = projectData.find(d => d.name === entry.targetAccount);
|
const targetAccount = internalProjectData.find(d => d.name === entry.targetAccount);
|
||||||
if (targetAccount) {
|
if (targetAccount) {
|
||||||
targetAccount.entries.push({
|
targetAccount.entries.push({
|
||||||
date: entry.date,
|
date: entry.date,
|
||||||
subject: "(" + projectData[currentAccountIndex].name + ")" + entry.subject,
|
subject: "(" + internalProjectData[currentAccountIndex].name + ")" + entry.subject,
|
||||||
amount: -entry.amount
|
amount: -entry.amount
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateView();
|
updateView(gui, win, currentAccountIndex, internalProjectData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -344,6 +313,52 @@ function mainWindow() {
|
||||||
|
|
||||||
|
|
||||||
gui.closeWindow(win);
|
gui.closeWindow(win);
|
||||||
|
return internalProjectData;
|
||||||
}
|
}
|
||||||
|
|
||||||
mainWindow();
|
|
||||||
|
let projectData = [
|
||||||
|
{
|
||||||
|
name: "Current",
|
||||||
|
entries: [
|
||||||
|
{
|
||||||
|
date: 1704067200000,
|
||||||
|
subject: '(Savings) Initial Deposit',
|
||||||
|
amount: -500,
|
||||||
|
targetAccount: "Savings"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: 1704067200000,
|
||||||
|
subject: 'Salary',
|
||||||
|
amount: 2182.15
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: 1704153600000,
|
||||||
|
subject: 'Rent',
|
||||||
|
amount: -800
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: 1704240000000,
|
||||||
|
subject: 'Groceries',
|
||||||
|
amount: -24.19
|
||||||
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Savings",
|
||||||
|
entries: [
|
||||||
|
{
|
||||||
|
date: 1704067200000,
|
||||||
|
subject: 'Initial Deposit',
|
||||||
|
amount: 500
|
||||||
|
}
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
do {
|
||||||
|
projectData = mainWindow(projectData);
|
||||||
|
} while(projectData != null);
|
||||||
|
console.log("bye!");
|
||||||
Loading…
Reference in New Issue