Skip to content
Snippets Groups Projects
Commit 78e34099 authored by audunrodsten's avatar audunrodsten
Browse files

First commit

parents
No related branches found
No related tags found
No related merge requests found
Pipeline #90387 failed
{
"presets": ["@babel/preset-env"],
"highlightCode": false
}
node_modules
.npmrc 0 → 100644
package-lock=false
{
"printWidth": 100,
"proseWrap": "always",
"singleQuote": true
}
{
"recommendations": ["esbenp.prettier-vscode"]
}
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
LICENSE 0 → 100644
MIT License
Copyright (c) 2020 ntnu-idri1002
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
main.js 0 → 100644
/**
* Starts the desktop application through the electron framework.
* This file is not part of the curriculum, and does not need to be altered.
*/
const electron = require('electron');
const path = require('path');
process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true';
const app = electron.app;
// See https://github.com/electron/electron/issues/22119
// Should be fixed in https://github.com/electron/electron/pull/25869,
// though these changes are not released yet (14.10.20)
app.allowRendererProcessReuse = false;
const BrowserWindow = electron.BrowserWindow;
// Reload application on changes in src folder
require('electron-reload')(path.join(__dirname, 'src'), {
electron: path.join(__dirname, 'node_modules/.bin/electron'),
ignored: /^.*\.(json|txt)$/,
});
let mainWindow;
app.on('ready', () => {
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: { nodeIntegration: true },
});
// Open Development Tools
mainWindow.openDevTools();
mainWindow.loadURL('file://' + __dirname + '/src/index.html');
});
app.on('window-all-closed', () => {
app.quit();
});
{
"name": "desktop-application",
"version": "1.0.0",
"main": "main.js",
"scripts": {
"start": "electron ."
},
"browserslist": [
"electron 10.1"
],
"dependencies": {
"@babel/core": "^7.11.6",
"@babel/preset-env": "^7.11.5",
"@babel/register": "^7.11.5",
"electron": "^10.1.3",
"electron-reload": "^1.5.0"
},
"devDependencies": {
"prettier": "^2.1.2"
}
}
[{"name":"Roger","email":"roger@gmail.com"},{"name":"Arne","email":"arne@gmail.com"},{"name":"Lise","email":"lise@gmail.com"}]
\ No newline at end of file
<html>
<head>
<meta charset="UTF-8" />
<title>Desktop application</title>
</head>
<body>
Students:
<ul id="studentList"></ul>
<div>New student:</div>
<div>
<div>Name: <input id="nameInput" type="text" /></div>
<div>Email: <input id="emailInput" type="text" /></div>
<div><button id="addButton">Add student</button></div>
<div><button id="saveButton">Save list</button></div>
<div><button id="loadButton">Load saved list</button></div>
</div>
<div id="feedback"></div>
<script>
require('@babel/register');
require('./index.js');
</script>
</body>
</html>
\ No newline at end of file
import fs from 'fs';
let studentList = document.getElementById('studentList');
let nameInput = document.getElementById('nameInput');
let emailInput = document.getElementById('emailInput');
let addButton = document.getElementById('addButton');
let feedback = document.getElementById('feedback');
let students = [];
function updateStudentList() {
while (studentList.firstChild) {
studentList.removeChild(studentList.firstChild);
}
for (let c = 0; c < students.length; c++) {
let li = document.createElement('li');
li.innerText = students[c].name + ', ' + students[c].email;
let button = document.createElement('button');
button.innerText = 'x';
button.onclick = () => {
students.splice(c, 1);
updateStudentList();
feedback.innerText = 'Student removed!';
};
li.appendChild(button);
studentList.appendChild(li);
}
}
document.getElementById('loadButton').onclick = () => {
fs.readFile('src/data.json', (error, data) => {
if (error) {
console.error('Failed to read students from file: ' + error.message);
return;
}
students = JSON.parse(data);
updateStudentList();
feedback.innerText = 'Student list loaded!';
});
};
document.getElementById('saveButton').onclick = () => {
fs.writeFile('src/data.json', JSON.stringify(students), (error) => {
if (error) {
console.error('Failed to write students to file: ' + error.message);
return;
}
feedback.innerText = 'Student list saved!';
});
};
addButton.onclick = () => {
students.push({ name: nameInput.value, email: emailInput.value });
nameInput.value = '';
emailInput.value = '';
updateStudentList();
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment