first commit

This commit is contained in:
Robert Nasarek 2022-08-25 13:30:44 +02:00
commit 5ada72873f
30 changed files with 1286 additions and 0 deletions

6
.babelrc Normal file
View file

@ -0,0 +1,6 @@
{
"presets": [
"@babel/preset-react",
"@babel/preset-env"
]
}

14
.editorconfig Normal file
View file

@ -0,0 +1,14 @@
# editorconfig.org
root = true
[*]
charset = utf-8
end_of_line = crlf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false

67
.gitignore vendored Normal file
View file

@ -0,0 +1,67 @@
# Build folder and files #
##########################
builds/
# Development folders and files #
#################################
.tmp/
dist/
node_modules/
*.compiled.*
# Folder config file #
######################
Desktop.ini
# Folder notes #
################
_ignore/
# Log files & folders #
#######################
logs/
*.log
npm-debug.log*
.npm
# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
# Photoshop & Illustrator files #
#################################
*.ai
*.eps
*.psd
# Windows & Mac file caches #
#############################
.DS_Store
Thumbs.db
ehthumbs.db
# Windows shortcuts #
#####################
*.lnk
# IDE
########################
.idea
# Lock-Files
########################
package-lock.json
yarn.lock
# Miscallaneos
report.docx
misc

6
.npmignore Normal file
View file

@ -0,0 +1,6 @@
_ignore/
docs/
builds/
dist/
.editorconfig
code-of-conduct.md

21
LICENSE Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) Alex Devero <deveroalex@gmail.com> (alexdevero.com)
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.

4
README.md Normal file
View file

@ -0,0 +1,4 @@
Document manager for germanic national museum
[Boilerplate](https://github.com/alexdevero/electron-react-webpack-boilerplate.git) by [Alex Devero](https://github.com/alexdevero/)

46
code-of-conduct.md Normal file
View file

@ -0,0 +1,46 @@
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at deveroalex@gmail.com. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version].
[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

125
main.js Normal file
View file

@ -0,0 +1,125 @@
'use strict'
// Import parts of electron to use
const { app, BrowserWindow, dialog, ipcMain } = require('electron')
const path = require('path')
const url = require('url')
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow;
// Keep a reference for dev mode
let dev = false
// Broken:
// if (process.defaultApp || /[\\/]electron-prebuilt[\\/]/.test(process.execPath) || /[\\/]electron[\\/]/.test(process.execPath)) {
// dev = true
// }
if (process.env.NODE_ENV !== undefined && process.env.NODE_ENV === 'development') {
dev = true
}
// Temporary fix broken high-dpi scale factor on Windows (125% scaling)
// info: https://github.com/electron/electron/issues/9691
if (process.platform === 'win32') {
app.commandLine.appendSwitch('high-dpi-support', 'true')
app.commandLine.appendSwitch('force-device-scale-factor', '1')
}
// Functions
async function handleFileOpen() {
const { canceled, filePaths } = await dialog.showOpenDialog(mainWindow, {properties: ['openDirectory']})
if (canceled) {
return
} else {
return filePaths[0]
}
}
function createWindow() {
// Create the browser window.
mainWindow = new BrowserWindow({
width: 400,
height: 600,
show: false,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
nodeIntegration: true,
contextIsolation: false
}
})
// and load the index.html of the app.
let indexPath
if (dev && process.argv.indexOf('--noDevServer') === -1) {
indexPath = url.format({
protocol: 'http:',
host: 'localhost:8080',
pathname: 'index.html',
slashes: true
})
} else {
indexPath = url.format({
protocol: 'file:',
pathname: path.join(__dirname, 'dist', 'index.html'),
slashes: true
})
}
mainWindow.loadURL(indexPath)
// Don't show until we are ready and loaded
mainWindow.once('ready-to-show', () => {
mainWindow.show()
// Open the DevTools automatically if developing
if (dev) {
const { default: installExtension, REACT_DEVELOPER_TOOLS } = require('electron-devtools-installer')
installExtension(REACT_DEVELOPER_TOOLS)
.catch(err => console.log('Error loading React DevTools: ', err))
mainWindow.webContents.openDevTools()
}
})
// Emitted when the window is closed.
mainWindow.on('closed', function() {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null
})
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', () => {
ipcMain.handle('dialog:openFile', handleFileOpen)
createWindow();
})
// Quit when all windows are closed.
app.on('window-all-closed', () => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) {
createWindow()
}
})
// IPC-Channel handling

80
package.json Normal file
View file

@ -0,0 +1,80 @@
{
"name": "marvin",
"version": "0.1.0",
"description": "GNM Document Manager",
"license": "MIT",
"private": false,
"repository": {
"type": "git",
"url": "https://github.com/rnsrk/marvin.git"
},
"author": {
"name": "Robert Nasarek",
"email": "r.nasarek@gnm.de",
"url": "https://github.com/rnsrk"
},
"keywords": [
"gnm",
"electron",
"react",
"react",
"webpack"
],
"engines": {
"node": ">=9.0.0",
"npm": ">=5.0.0",
"yarn": ">=1.0.0"
},
"browserslist": [
"last 4 versions"
],
"main": "main.js",
"scripts": {
"prod": "cross-env NODE_ENV=production webpack --mode production --config webpack.build.config.js && electron --noDevServer .",
"start": "cross-env NODE_ENV=development webpack serve --hot --host 0.0.0.0 --config=./webpack.dev.config.js --mode development",
"build": "cross-env NODE_ENV=production webpack --config webpack.build.config.js --mode production",
"package": "npm run build",
"postpackage": "electron-packager ./ --out=./builds"
},
"dependencies": {
"@emotion/react": "^11.10.0",
"@emotion/styled": "^11.10.0",
"@mui/icons-material": "^5.10.2",
"@mui/material": "^5.10.2",
"docx-templates": "^4.9.2",
"fast-xml-parser": "^4.0.9",
"file-saver": "^2.0.5",
"node-fetch": "^3.2.10",
"postcss": "^8.4.16",
"react": "^18.2.0",
"react-async-devtools": "^10.0.1",
"react-dom": "^18.2.0",
"react-router-dom": "^6.3.0",
"write-json-file": "^5.0.0",
"xml-parse-from-string": "^1.0.1",
"xml2js": "^0.4.23"
},
"devDependencies": {
"@babel/core": "^7.18.10",
"@babel/preset-env": "^7.18.10",
"@babel/preset-react": "^7.18.6",
"babel-loader": "^8.2.5",
"cross-env": "^7.0.3",
"css-loader": "^6.7.1",
"electron": "^20.0.3",
"electron-devtools-installer": "^3.2.0",
"electron-packager": "^15.5.1",
"file-loader": "^6.2.0",
"html-webpack-plugin": "^5.5.0",
"mini-css-extract-plugin": "^2.6.1",
"postcss-import": "^14.1.0",
"postcss-loader": "^7.0.1",
"postcss-nested": "^5.0.6",
"postcss-preset-env": "^7.8.0",
"postcss-pxtorem": "^6.0.0",
"style-loader": "^3.3.1",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0",
"webpack-dev-server": "^4.10.0"
}
}

16
postcss.config.js Normal file
View file

@ -0,0 +1,16 @@
module.exports = {
plugins: {
'postcss-import': {},
'postcss-nested': {},
'postcss-preset-env': {},
'postcss-pxtorem': {
rootValue: 16,
unitPrecision: 5,
propList: ['*'],
selectorBlackList: ['html', 'body'],
replace: true,
mediaQuery: false,
minPixelValue: 0
}
}
}

7
preload.js Normal file
View file

@ -0,0 +1,7 @@
const { ipcRenderer } = require('electron')
window.openFile = async () => {
return await ipcRenderer.invoke('dialog:openFile')
}

77
src/DocxInserter.js Normal file
View file

@ -0,0 +1,77 @@
// Config
import config from './config/config.json'
// Modules
import createReport from 'docx-templates';
import fs from 'fs';
import { mkdir } from 'node:fs/promises';
import path from 'path';
// Components
import ObjektkatalogApi from './ObjektkatalogApi';
////////////////////
// Main //
////////////////////
export async function fillTemplate(log, objectData) {
let buffer;
// Create docx document.
if (objectData.httpStatus === 200) {
try {
// Read template.
const template = fs.readFileSync('src/assets/templates/rp-template.docx');
// Create report.
buffer = await createReport({
template,
data: {
inventarnummer: objectData.inventarnummer,
titel: objectData.titel,
hersteller: objectData.hersteller,
herstellungsort: objectData.herstellungsort,
herstellungsdatum: objectData.herstellungsdatum,
materialTechnik: objectData.materialTechnik,
masse: objectData.masse
}
});
} catch (err) {
log = {
...log,
status: 'red',
message: 'Konnte Template nicht öffnen: ' + err,
tip: 'Ist das Template vorhanden?',
};
}
const folderPath = path.join(config.rootDir, objectData.inventarnummer);
// Create Folder if necessary.
try {
const createDir = await mkdir(folderPath, {recursive: true});
} catch (err) {
log = {
...log,
status: 'green',
message: 'Konnte den Pfad nicht erstellen' + err,
tip: 'Bestehen Schreibrechte auf dem Ordner?'
}
}
// Write document to disk.
if (buffer) {
fs.writeFileSync(path.join(folderPath, 'report.docx'), buffer)
log = {
...log,
status: 'green',
message: 'Dokument erstellt',
};
}
} else {
log = {
status: 'red',
message: 'Fehler bei der Kommunikation mit dem Objektkatalog',
code: objectData.httpStatus,
tip: 'Ist die Inventarnummer richtig?',
};
}
return log;
}

131
src/ObjektkatalogApi.js Normal file
View file

@ -0,0 +1,131 @@
const {parseString} = require("xml2js");
/*
* Sends Object ID to Objektkatalog-API and receives JSON
*/
class ObjektkatalogApi {
json;
short;
raw;
async getData(objectId) {
if (objectId) {
const response = await fetch('https://objektkatalog.gnm.de/rest_export/' + objectId);
if (response.status === 200) {
const responseJson = await response.json(); //extract JSON from the http response
if (responseJson.length !== 0) {
this.raw = {
eid: responseJson[0]['eid'],
allgemeineBezeichnung: responseJson[0]['fc6392714594e73ddb2fa363815a8fdf'],
beschreibung: responseJson[0]['f81f557caccf45074edfb65ff077011f'],
darstellung: responseJson[0]['f217e1053b1e29411d4b00f3b1e1d52b'],
erwerbsmethode: responseJson[0]['fa4aa035d411275cd36a2fbb5c159a2c'],
fruehstes: responseJson[0]['ff4a178095c895a12fce6320c04ba0b0'],
fundort: responseJson[0]['f1c2bf9f6f3d78302bbfa9cc8b3e439c'],
gehoertZuAggregation: responseJson[0]['fca2cff9e713e02b93be1f9f19dff88e'],
herstellerString: responseJson[0]['f9f9408fdacc1230497c591c89655777'],
herstellungsdatum: responseJson[0]['fd9f0912229c78d94dd6f807e683d06e'],
herstellungsort: responseJson[0]['fbbccf2979c1143b0fa25325a849b121'],
individuelleEinordnung: responseJson[0]['f8e7a568a6a0fb8907b41f5ba8a9cabe'],
inventarnummer: responseJson[0]['f9830c2c7747a792ebbe1ca2587d1f26'],
klassifikation: responseJson[0]['fdcd0101d5c77884d185560aa7521645'],
masse: responseJson[0]['ffdac65ffbb12438e2fef5b26533c909'],
materialTechnik: responseJson[0]['f23b67bd18913642fc3936c1f2af5682'],
muster: responseJson[0]['f88917aeadae224c8d2c1fec35720dc8'],
provisio: responseJson[0]['f930a6ca774cc5640694c5aa081c1e66'],
sammlung: responseJson[0]['ffd22ba4399f8d62e61c4e99463dddaa'],
spaetestens: responseJson[0]['f1c2bf9f6f3d78302bbfa9cc8b3e439c'],
standort: responseJson[0]['f95e9be48ed110cf4f92298712d364bd'],
titel: responseJson[0]['f2049b2456b20f8fd80f714e154f1d47'],
unterbringung: responseJson[0]['f15265e39237868a568ee63453492b17'],
vitrinentext: responseJson[0]['fe5e3ff18aedf1d25c639dc79fb24ad1'],
zustandsbeschreibung: responseJson[0]['f54b6da6006ea444c33a348b8c4370a8']
}
} else {
return {httpStatus: 404};
}
} else {
return {httpStatus: response.status};
}
} else {
return {httpStatus: 400}
}
// Inventarnummer
let inventarnummer;
if (this.raw.inventarnummer.length !== 0) {
inventarnummer = this.raw.inventarnummer[0].value;
} else {
inventarnummer = 'unbekannt';
}
// Titel
let titel;
if (this.raw.titel.length !== 0) {
titel = this.raw.titel[0].value;
} else {
titel = 'unbekannt';
}
// Hersteller
let herstellerArray = [];
let hersteller;
if (this.raw.herstellerString.length !== 0) {
this.raw.herstellerString.forEach((item) => {
parseString(item.value, (err, result) => {
herstellerArray.push(result['results']['lido:eventActor'][0]['lido:actorInRole'][0]['lido:actor'][0]['lido:nameActorSet'][0]['lido:appellationValue'][0]['_']);
return hersteller = herstellerArray.join(';')
})
});
} else {
hersteller = 'unbekannt';
}
// Herstellungsort
let herstellungsort;
if (this.raw.herstellungsort.length !== 0) {
herstellungsort = this.raw.herstellungsort[0].value
} else {
herstellungsort = 'unbekannt';
}
// Herstellungsdatum
let herstellungsdatum;
if (this.raw.herstellungsdatum.length !== 0) {
herstellungsdatum = this.raw.herstellungsdatum[0].value
} else {
herstellungsdatum = 'unbekannt';
}
// Material und Technik
let materialTechnik;
if (this.raw.materialTechnik.length !== 0) {
materialTechnik = this.raw.materialTechnik[0].value
} else {
materialTechnik = 'unbekannt';
}
// Maße
let masse;
if (this.raw.masse.length !== 0) {
parseString(this.raw.masse[0].value, (err, result) => {
return masse = result['results']['lido:objectMeasurementsSet'][0]['lido:displayObjectMeasurements'][0];
})
}
return this.short = {
inventarnummer: inventarnummer,
titel: titel,
hersteller: hersteller,
herstellungsort: herstellungsort,
herstellungsdatum: herstellungsdatum,
materialTechnik: materialTechnik,
masse: masse,
httpStatus: 200,
}
}
}
module.exports = ObjektkatalogApi;

7
src/actions/getData.js Normal file
View file

@ -0,0 +1,7 @@
import GnmObject from "../ObjektkatalogApi";
/*
*
*/

3
src/assets/css/App.css Normal file
View file

@ -0,0 +1,3 @@
/* Main CSS file */
@import '_example/_example.css';

View file

@ -0,0 +1,22 @@
/* Example stylesheet */
@media screen and (prefers-color-scheme: light), screen and (prefers-color-scheme: no-preference) {
/* Light theme */
body{
color: #000;
background-color: #fff;
}
}
@media screen and (prefers-color-scheme: dark) {
/* Dark theme */
body {
color: #fff;
background-color: #000;
}
}
h1 {
font-family: Helvetica, Arial, sans-serif;
font-size: 21px;
font-weight: 200;
}

Binary file not shown.

Binary file not shown.

121
src/components/App.js Normal file
View file

@ -0,0 +1,121 @@
// Components
import {DataForm} from "./DataForm";
import {Log} from "./Log"
// Modules
import {fillTemplate} from "../DocxInserter";
import SettingsIcon from '@mui/icons-material/Settings';
// React
import { Link } from "react-router-dom";
import React, {useState} from 'react'
// CSS
import '../styles.css'
import ObjektkatalogApi from "../ObjektkatalogApi";
////////////////////
// Main //
////////////////////
export const App = () => {
let log;
// States
/* Initialize state of the log.
* log: variables fpr logging message.
* logClass: for visibility of log <div>.
*/
const [logState, setLogState] = useState({
log: {
status: '',
message: '',
code: '',
tip:'',
}, // with message, code, tip
logClass: 'inactive'
});
const [objectData, setObjectData] = useState(
{
inventarnummer: '',
titel: '',
hersteller: '',
herstellungsort: '',
herstellungsdatum: '',
materialTechnik: '',
masse: '',
httpStatus: 500,
}
);
const [checkUpVisibility, setCheckUpVisibility] = useState(
false
);
// Handler
async function getDataAndAskForCheckUpClickHandler(e) {
// Prevent page reload.
e.preventDefault();
// Get objectId from user input.
let objectId = document.getElementById('object-id').value
// Get object data from objektkatalog.gnm.de
let objektkatalogApi = new ObjektkatalogApi();
let objectData = await objektkatalogApi.getData(objectId);
console.log(objectData)
log = await fillTemplate(log, objectData);
// Set new state of log div with message and visibility class
setLogState({
log: log,
logStatus: 'active'
});
}
return (
<div className="App">
<header className="App-header">
<nav className={"flex justify-content-end"}>
<Link to="/settings"><SettingsIcon/></Link>
</nav>
</header>
<main>
<div className={"container"}>
<form id={"object-id-form"} className={"flex-wrap"}>
<div className={"center column flex justify-content-space-between "}>
<label htmlFor="document-type" className={"center cut v-distance"}>Dokumenttyp:</label>
<select name="document-type" id="document-type" className={"input-field center cut"}>
<option value="restaurierungsprotokoll">Restaurierungsprotokoll</option>
<option value="leihgabenbegleitblatt">Leihgabenbegleitblatt</option>
<option value="analyse">Analyse</option>
</select>
</div>
<div className={"center column flex full justify-content-space-between"}>
<label htmlFor={"object-id"} className={"center cut v-distance"}>Inventarnummer:</label>
<input id={"object-id"} type={"text"} className={"center cut input-field"}/>
</div>
<button className={'send-button center top-distance'} onClick={getDataAndAskForCheckUpClickHandler}>
Dokument vorbereiten
</button>
</form>
</div>
<DataForm/>
</main>
<footer>
{/* We give state and state setter of the parent as params to the child components, so that child events can change parent states */}
<Log logState={logState} setLogState={setLogState}/>
</footer>
</div>
)
}
export default App

View file

@ -0,0 +1,43 @@
// React
import React from 'react'
////////////////////
// Main //
////////////////////
export const DataForm = () => {
return (<div>
<form className={'flex column'}>
<div >
<label htmlFor={'template-inventarnummer'} >Inventarnummer</label>
<input className={"full input-field"}/>
</div>
<div >
<label htmlFor={'template-titel'}>Titel</label>
<input type={"text"} className={"full input-field"}/>
</div>
<div>
<label htmlFor={'template-hersteller'}>Hersteller</label>
<input type={"text"} className={"full input-field"}/>
</div>
<div>
<label htmlFor={'template-herstellungsort'}>Herstellungsort</label>
<input type={"text"} className={"full input-field"}/>
</div>
<div >
<label htmlFor={'template-herstellungsdatum'}>Herstellungsdatum</label>
<input type={"text"} className={"full input-field"}/>
</div>
<div >
<label htmlFor={'template-materialTechnik'}>Material und Technik</label>
<input type={"text"} className={"full input-field"}/>
</div>
<div>
<label htmlFor={'template-masse'}>Maße</label>
<input type={"text"} className={"full input-field"}/>
</div>
<button type={"submit"} className={'send-button center top-distance'} >Dokument erstellen</button>
</form>
</div>
)
}

45
src/components/Log.js Normal file
View file

@ -0,0 +1,45 @@
// React
import React from 'react'
////////////////////
// Main //
////////////////////
export const Log = ({logState, setLogState}) => {
let code;
let tip;
const closeLog = (e, logClass) => {
e.preventDefault()
setLogState({log: logState.log,
logClass: 'inactive'});
}
const classes = 'round-box flex ' + logState.log.status + ' ' + logState.logClass
if (logState.log.code) {
code = ' Code: ' + logState.log.code
} else {
code = ''
}
if (logState.log.tip) {
tip = ' Tipp: ' + logState.log.tip
} else {
tip = ''
}
return (
<div className={'log '}>
<div id={'log-content'} className={classes}>
<div>
<button onClick={(e) => {closeLog(e)}}>x</button>
</div>
<div className={'scroll-y flex-full'} style={{maxHeight: 4 + 'em'}}>
<p>{logState.log.message}</p>
<p>{code}</p>
<p>{tip}</p>
</div>
</div>
</div>
)
}

3
src/config/config.json Normal file
View file

@ -0,0 +1,3 @@
{
"rootDir": "/home/rbrt/Dokumente/marvin"
}

18
src/index.html Normal file
View file

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<title>Marvin</title>
</head>
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
</body>
</html>

26
src/index.js Normal file
View file

@ -0,0 +1,26 @@
// React
import {createRoot} from 'react-dom/client'
import {
HashRouter,
Routes,
Route} from "react-router-dom";
import React from "react";
// Components
import App from './components/App'
// Routes
import Settings from "./routes/settings";
// entry index.html is managed by webpack via HtmlWebpackPlugin
const container = document.getElementById('root');
const root = createRoot(container);
root.render(
<HashRouter>
<Routes>
<Route path='/' element={<App />} />
<Route path='settings' element={<Settings />} />
</Routes>
</HashRouter>
);

79
src/routes/settings.js Normal file
View file

@ -0,0 +1,79 @@
import config from '../config/config.json'
// Icons
import ArrowBackIosIcon from '@mui/icons-material/ArrowBackIos';
import EditIcon from '@mui/icons-material/Edit';
// Modules
const {writeFile} = require('fs');
// React
import React, {useState} from "react";
import {Link} from "react-router-dom";
////////////////////
// Main //
////////////////////
export default function Settings() {
let rootDir;
const [disableButton, setDisableButton] = useState(true)
async function selectFolderHandler() {
return rootDir = await window.openFile();
}
// Handler
function saveInputClickHandler(rootDir) {
if (rootDir) {
config.rootDir = rootDir
writeFile('src/config/config.json', JSON.stringify(config, null, 2), (error) => {
if (error) {
console.log('An error has occurred ', error);
return;
}
console.log('Data written successfully to disk');
});
}
}
return (
<div className="App">
<header className="App-header">
<Link to="/"><ArrowBackIosIcon/></Link>
</header>
<main>
<form>
<label htmlFor={"output-root"}>
Wurzelverzeichnis
</label>
<div className="col-sm-10 d-flex align-items-center flex sticky-edit">
<input
id={"root-dir"}
className={"form-control select-folder-field edit-input"}
defaultValue={config.rootDir}
disabled={true}
/>
<button className="edit-button text-end" onClick={
(e) => {
console.log(e)
e.preventDefault()
selectFolderHandler().then((rootDir) => {saveInputClickHandler(rootDir)})
}
}>
<i className="fas fa-edit d-block">
<EditIcon sx={{fontSize: 16}} color={'#d5d5d5'}/>
</i>
</button>
</div>
</form>
</main>
<footer>
</footer>
</div>
);
}

7
src/shared/constants.js Normal file
View file

@ -0,0 +1,7 @@
module.exports = {
channels: {
GET_DATA: 'get_data',
},
log: {
}
};

195
src/styles.css Normal file
View file

@ -0,0 +1,195 @@
@import url('https://fonts.googleapis.com/css?family=Roboto');
a {
color: #d5d5d5;
}
.active {
display: block;
}
body {
background-color: #00152E ;
color: #d5d5d5;
font-family: 'Roboto', regular, serif;
font-size: larger;
}
.center {
margin: 0 auto;
}
.column {
flex-direction: column;
}
.container {
width: 300px;
margin: 0 auto;
}
.cut {
max-width: max-content;
}
div {
padding: 0.5em;
}
.edit-button {
background-color: #d5d5d5;
font-family: roboto, sans-serif;
font-size: 1rem;
border-radius: 0 0.4rem 0.4rem 0;
border: unset;
padding: 0 4px;
height: 1.1rem;
}
.edit-input {
border-radius: 0.4rem 0 0 0.4rem;
}
.flex {
display: flex;
}
.flex-full {
flex: 1
}
.flex-wrap {
display: flex;
flex-wrap: wrap;
}
.full {
width: 100%;
}
.green {
background-color: darkgreen;
}
.inactive {
display: none;
}
input {
border-top: none;
border-right: none;
border-left: none;
border-bottom: 2px solid darkred;
border-radius: 3px;
}
input:focus {
background-color: #d5d5d5;
color: #00152E;
}
input.edit-input:not(:disabled) {
background-color: #d5d5d5;
color: #00152E;
}
.input-field {
background-color: #00152E ;
color: #d5d5d5;
font-size: medium;
}
.justify-content-end {
justify-content: end;
}
.justify-content-space-between {
justify-content: space-between;
}
label {
padding-right: 5px;
}
.log {
font-size: 0.75em;
height: 5em;
}
p {
margin: 0;
}
.position-absolute {
position: absolute;
}
.position-relative {
position: relative;
}
.red {
background-color: crimson;
}
.round-box {
border-radius: 6px;
}
select {
border: none;
font-size: medium;
outline: none;
}
.send-button {
font-family: roboto, sans-serif;
font-size: 1rem;
border-radius: 0.4rem;
border: unset;
background-color: darkred;
color: #d5d5d5;
}
.scroll-y {
overflow-y: scroll;
}
.select-folder-field {
background-color: #00152E ;
color: #d5d5d5;
width: 100%;
font-size: .85rem;
}
.sticky-edit {
display: flex;
align-items: flex-start;
}
textarea, textarea:focus, input:focus{
outline: none;
font-size: medium;
;
}
textarea.select-folder-field, textarea.select-folder-field:focus, input.select-folder-field:focus {
font-size: .85rem;
}
.top-distance {
margin-top: 1em;
}
.v-distance {
margin-top: 0.25em;
margin-bottom: 0.25em;
}
.yellow{
background-color: goldenrod;
}

61
webpack.build.config.js Normal file
View file

@ -0,0 +1,61 @@
const webpack = require('webpack')
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
// Any directories you will be adding code/files into, need to be added to this array so webpack will pick them up
const defaultInclude = path.resolve(__dirname, 'src')
module.exports = {
module: {
rules: [
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader'
],
include: defaultInclude
},
{
test: /\.jsx?$/,
use: [{ loader: 'babel-loader' }],
include: defaultInclude
},
{
test: /\.(jpe?g|png|gif)$/,
use: [{ loader: 'file-loader?name=img/[name]__[hash:base64:5].[ext]' }],
include: defaultInclude
},
{
test: /\.(eot|svg|ttf|woff|woff2)$/,
use: [{ loader: 'file-loader?name=font/[name]__[hash:base64:5].[ext]' }],
include: defaultInclude
}
]
},
target: 'electron-renderer',
plugins: [
new HtmlWebpackPlugin({title: 'Marvin'}),
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: 'bundle.css',
chunkFilename: '[id].css'
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
}),
// new MinifyPlugin()
],
stats: {
colors: true,
children: false,
chunks: false,
modules: false
},
optimization: {
minimize: true
}
}

56
webpack.dev.config.js Normal file
View file

@ -0,0 +1,56 @@
const webpack = require('webpack')
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { spawn } = require('child_process')
// Any directories you will be adding code/files into, need to be added to this array so webpack will pick them up
const defaultInclude = path.resolve(__dirname, 'src')
module.exports = {
module: {
rules: [
{
test: /\.css$/,
use: [{ loader: 'style-loader' }, { loader: 'css-loader' }, { loader: 'postcss-loader' }],
include: defaultInclude
},
{
test: /\.jsx?$/,
use: [{ loader: 'babel-loader' }],
include: defaultInclude
},
{
test: /\.(jpe?g|png|gif)$/,
use: [{ loader: 'file-loader?name=img/[name]__[hash:base64:5].[ext]' }],
include: defaultInclude
},
{
test: /\.(eot|svg|ttf|woff|woff2)$/,
use: [{ loader: 'file-loader?name=font/[name]__[hash:base64:5].[ext]' }],
include: defaultInclude
}
]
},
target: 'electron-renderer',
plugins: [
new HtmlWebpackPlugin({
title: 'Marvin',
template: 'src/index.html'}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development')
})
],
devtool: 'cheap-source-map',
devServer: {
static: path.resolve(__dirname, 'dist'),
onBeforeSetupMiddleware() {
spawn(
'electron',
['.'],
{ shell: true, env: process.env, stdio: 'inherit' }
)
.on('close', code => process.exit(0))
.on('error', spawnError => console.error(spawnError))
}
}
}