Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
35 changes: 35 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Dependencies
node_modules/

# Build outputs
dist/
build/
out/

# Database files
*.db
data.db

# Excel exports
*.xlsx
records.xlsx

# IDE files
.vscode/
.idea/
*.swp
*.swo
*~

# OS files
.DS_Store
Thumbs.db

# Logs
logs/
*.log
npm-debug.log*

# Environment variables
.env
.env.local
15 changes: 15 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ISC License

Copyright (c) 2024, Anik Chowdhury

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
68 changes: 64 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,83 @@
# Data Entry App

An offline data entry and data collection application for managing data efficiently.
An offline data entry and data collection application built with Electron for managing data efficiently.

## Features

- Offline data entry
- Data collection
- Data management
- ✅ Offline data entry and storage using SQL.js (embedded SQLite)
- ✅ Data collection with form validation
- ✅ Real-time data management (Add, Edit, Delete)
- ✅ Search functionality
- ✅ Auto-export to Excel (xlsx format)
- ✅ Cross-platform support (Windows, macOS, Linux)
- ✅ No native dependencies required (pure JavaScript SQLite)

## Prerequisites

- Node.js (v14 or higher)
- npm (v6 or higher)

## Installation

1. Clone the repository:
```bash
git clone https://github.com/Sundarban-Lab/data-entry-app.git
cd data-entry-app
```

2. Install dependencies:
```bash
npm install
```

## Usage

Start the application:
```bash
npm start
```

The application will open in a desktop window where you can:
- Add new records with name, email, and age
- Edit existing records
- Delete records
- Search records by name or email
- Export data to Excel (records.xlsx)

## Data Storage

- Data is stored locally in `data.db` SQLite database
- Excel exports are automatically saved as `records.xlsx`
- Both files are created in the application directory

## Building for Production

To package the application for distribution:
```bash
npm run package
```

## Technologies Used

- **Electron**: Desktop application framework (v39.1.0)
- **SQL.js**: Pure JavaScript SQLite implementation (no native dependencies)
- **ExcelJS**: Excel file generation
- **HTML/CSS/JavaScript**: User interface

## Security

- All dependencies are up-to-date with no known vulnerabilities
- Uses ExcelJS instead of vulnerable xlsx library
- Proper error handling for database operations

## Author

Anik Chowdhury

## License

ISC

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.
41 changes: 0 additions & 41 deletions create-repo.js

This file was deleted.

115 changes: 115 additions & 0 deletions database.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
const fs = require('fs');
const initSqlJs = require('sql.js');
const ExcelJS = require('exceljs');

const DB_FILE = 'data.db';

class Database {
constructor() {
this.ready = this._init();
}

async _init() {
try {
const SQL = await initSqlJs();
if (fs.existsSync(DB_FILE)) {
const fileBuffer = fs.readFileSync(DB_FILE);
this.db = new SQL.Database(fileBuffer);
console.log('Database loaded from file.');
} else {
this.db = new SQL.Database();
this.db.run('CREATE TABLE records (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, email TEXT, age INTEGER)');
this._persist();
console.log('New database created.');
}
} catch (error) {
console.error('Database initialization error:', error);
throw error;
}
}

_persist() {
try {
const data = this.db.export();
const buffer = Buffer.from(data);
fs.writeFileSync(DB_FILE, buffer);
} catch (error) {
console.error('Database persist error:', error);
throw error;
}
}

async insertData({ name, email, age }) {
await this.ready;
const stmt = this.db.prepare('INSERT INTO records (name, email, age) VALUES (?, ?, ?)');
const ageValue = age !== undefined && age !== '' ? parseInt(age, 10) : null;
stmt.run([name, email, isNaN(ageValue) ? null : ageValue]);
stmt.free();
this._persist();
return true;
}

async getAllData() {
await this.ready;
const stmt = this.db.prepare('SELECT * FROM records ORDER BY id DESC');
const rows = [];
while (stmt.step()) rows.push(stmt.getAsObject());
stmt.free();
return rows;
}

async updateData({ id, name, email, age }) {
await this.ready;
const idValue = parseInt(id, 10);
if (isNaN(idValue)) {
throw new Error('Invalid ID provided for update');
}
const ageValue = age !== undefined && age !== '' ? parseInt(age, 10) : null;
const stmt = this.db.prepare('UPDATE records SET name=?, email=?, age=? WHERE id=?');
stmt.run([name, email, isNaN(ageValue) ? null : ageValue, idValue]);
stmt.free();
this._persist();
return true;
}

async deleteData(id) {
await this.ready;
const idValue = parseInt(id, 10);
if (isNaN(idValue)) {
throw new Error('Invalid ID provided for deletion');
}
const stmt = this.db.prepare('DELETE FROM records WHERE id=?');
stmt.run([idValue]);
stmt.free();
this._persist();
return true;
}

async exportToExcel() {
const rows = await this.getAllData();
try {
const workbook = new ExcelJS.Workbook();
const worksheet = workbook.addWorksheet('Data');

// Add headers if there's data
if (rows.length > 0) {
worksheet.columns = Object.keys(rows[0]).map(key => ({
header: key.charAt(0).toUpperCase() + key.slice(1),
key: key,
width: 15
}));

// Add rows
rows.forEach(row => worksheet.addRow(row));
}

await workbook.xlsx.writeFile('records.xlsx');
return 'records.xlsx';
} catch (error) {
console.error('Excel export error:', error);
throw error;
}
}
}

module.exports = Database;
84 changes: 84 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>Offline Data Manager</title>
<style>
body {
font-family: Arial;
margin: 20px;
background: #fafafa;
}

h2 {
color: #333;
}

input,
button {
margin: 5px;
padding: 8px;
}

table {
width: 100%;
border-collapse: collapse;
margin-top: 15px;
}

th,
td {
border: 1px solid #ccc;
padding: 8px;
text-align: left;
}

tr:nth-child(even) {
background: #f2f2f2;
}

#search {
margin-top: 10px;
width: 300px;
padding: 6px;
}

.actions button {
margin-right: 5px;
}
</style>
</head>

<body>
<h2>Offline Data Manager</h2>

<form id="dataForm">
<input type="hidden" id="recordId">
<input type="text" id="name" placeholder="Name" required>
<input type="email" id="email" placeholder="Email" required>
<input type="number" id="age" placeholder="Age">
<button type="submit" id="addBtn">Add</button>
<button type="button" id="updateBtn" style="display:none;">Update</button>
</form>

<input type="text" id="search" placeholder="Search by name or email...">
<button id="exportBtn">Export to Excel</button>

<table id="dataTable">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
<th>Age</th>
<th>Actions</th>
</tr>
</thead>
<tbody></tbody>
</table>

<script src="renderer.js"></script>
</body>

</html>
Loading