Visual improvements and new menu with cool buttons

This commit is contained in:
KingOfDog 2019-03-04 19:17:00 +01:00
parent 4d4f470de5
commit 9c5ead9ffa
2 changed files with 295 additions and 1 deletions

View File

@ -3,19 +3,220 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>FSM Designer</title> <title>FSM Designer</title>
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,700" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css"
integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
<link href="lib/tingle/tingle.min.css" rel="stylesheet">
<style>
/**
* General
*/
html, body {
font-family: Roboto, Arial, sans-serif;
font-size: 16px;
}
body {
margin: 0;
background: #eee;
}
.container {
max-width: 800px;
margin: 20px auto;
padding: 0 40px;
}
input {
width: 100%;
font-size: 16px;
padding: 8px 16px;
border-radius: 10px;
border: none;
color: #333;
background-color: rgba(0, 0, 0, .1);
}
input:focus {
background-color: rgba(0, 0, 0, .2);
}
/**
* Buttons
*/
.btn {
padding: 8px 16px;
border-radius: 10px;
border: 1px solid transparent;
background: none;
font-weight: bold;
font-family: Roboto, Arial, sans-serif;
}
.btn:hover {
border: 1px solid rgba(0, 0, 0, .33);
background: rgba(0, 0, 0, .15);
}
.btn:active {
box-shadow: 0 0 5px rgba(0, 0, 0, .25);
}
.btn-close {
padding: 4px 6px;
}
/**
* FSMDocument tabs
*/
#document-tabs {
list-style: none;
padding: 0;
margin: 0;
height: 44px;
}
#document-tabs .document-tab {
display: inline-block;
border: 1px solid rgba(0, 0, 0, .33);
margin: 0;
padding: 8px 16px;
}
#document-tabs .document-tab:first-child {
border-top-left-radius: 10px;
border-bottom-left-radius: 10px;
}
#document-tabs .document-tab:last-child {
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
}
#document-tabs .document-tab .document-name {
font-weight: normal;
margin-right: 4px;
}
#document-tabs .document-tab.active {
background: #fff;
}
#document-tabs .document-tab.active .document-name {
font-weight: bold;
}
/**
* Action Buttons
*/
.action-buttons {
margin: 20px 0;
}
.action-button {
background: #fff;
margin: 0 8px;
}
.action-button .fa {
margin: 4px;
}
/**
* List in Open Modal
*/
.file-list {
list-style-type: none;
width: 100%;
padding: 0;
}
.file-list .file-list-item {
padding: 16px 32px;
border-bottom: 1px solid rgba(0, 0, 0, .33);
width: 100%;
}
.file-list .file-list-item:first-child {
border-top-left-radius: 10px;
border-top-right-radius: 10px;
}
.file-list .file-list-item:last-child {
border: none;
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
}
.file-list .file-list-item:hover {
background: rgba(0, 0, 0, .1);
}
.file-list .file-list-item:active {
background: rgba(0, 0, 0, .2);
}
/**
* Canvas
*/
#canvas {
display: block;
margin: 0 auto;
background: #fff;
border-radius: 10px;
}
#previewImage {
width: 100%;
}
</style>
</head> </head>
<body> <body>
<div class="container">
<nav>
<ul id="document-tabs">
</ul>
</nav>
<div class="action-buttons">
<button class="btn action-button" id="saveBtn"><i class="fa fa-save"></i> Speichern</button>
<button class="btn action-button" id="openBtn"><i class="fa fa-folder-open"></i> Öffnen</button>
<button class="btn action-button" id="importBtn"><i class="fa fa-upload"></i> Importieren</button>
<button class="btn action-button" id="exportBtn"><i class="fa fa-download"></i> Exportieren</button>
</div>
</div>
<canvas id="canvas"></canvas> <canvas id="canvas"></canvas>
<script src="lib/tingle/tingle.min.js"></script>
<script src="js/math.js"></script> <script src="js/math.js"></script>
<script src="js/export.js"></script> <script src="js/export/export.js"></script>
<script src="js/export/export-image.js"></script>
<script src="js/components/connection.js"></script> <script src="js/components/connection.js"></script>
<script src="js/components/start-connection.js"></script> <script src="js/components/start-connection.js"></script>
<script src="js/components/self-connection.js"></script> <script src="js/components/self-connection.js"></script>
<script src="js/components/temporary-connection.js"></script> <script src="js/components/temporary-connection.js"></script>
<script src="js/components/state.js"></script> <script src="js/components/state.js"></script>
<script src="js/FSMDocument.js"></script>
<script src="js/main.js"></script> <script src="js/main.js"></script>
<script src="js/simulate.js"></script> <script src="js/simulate.js"></script>
<script src="js/menu.js"></script>
</body> </body>
</html> </html>

93
js/menu.js Normal file
View File

@ -0,0 +1,93 @@
const modalSave = new tingle.modal({
footer: true,
});
modalSave.setContent('<h3>Dokument speichern</h3><input type="text" id="saveName" placeholder="Bitte gib den Namen des Dokuments ein">');
modalSave.addFooterBtn('Schließen', 'btn', () => {
document.getElementById('saveName').value = "";
modalSave.close();
});
modalSave.addFooterBtn('Speichern', 'btn', () => {
const input = document.getElementById('saveName');
const name = input.value;
if(name.trim().length > 0) {
documents[activeDocument].name = name;
saveToLocalStorage();
modalSave.close();
} else {
}
});
const modalOpen = new tingle.modal({
beforeOpen: () => {
const entries = getLocalStorageEntries().sort((a, b) => {
console.log(a, b);
return b.document.createdAt - a.document.createdAt
});
console.log(entries);
let html = '<h3>Gespeicherte Dokumente</h3><ul class="file-list">';
entries.forEach(entry => html += `<li class="file-list-item" data-id="${entry.document.id}">${entry.document.name} (${new Date(entry.document.createdAt).toLocaleString()})</li>`);
html += '</ul>';
modalOpen.setContent(html);
for(let element of document.getElementsByClassName('file-list-item')) {
element.addEventListener('click', () => {
const entry = entries.find(entry => entry.document.id === element.getAttribute('data-id'));
addDocument(entry.document);
switchDocument(entry.document);
modalOpen.close();
});
}
},
});
const modalExport = new tingle.modal({
footer: true,
beforeOpen: () => {
const el = document.getElementById('previewImage');
el.src = canvas.toDataURL('image/png');
}
});
modalExport.setContent('<h3>Dokument exportieren</h3><img src="" id="previewImage">');
modalExport.addFooterBtn('Download .png', 'btn', () => {
exportToImageFile();
modalExport.close();
});
modalExport.addFooterBtn('Download .svg', 'btn', () => {
});
modalExport.addFooterBtn('Download .fsm', 'btn', () => {
exportToFile();
modalExport.close();
});
const modalImport = new tingle.modal({
footer: true,
});
modalImport.setContent('<h3>Dokument importieren</h3><label for="importUpload" class="btn upload-btn"><input type="file" class="upload-input"> <i class="fa fa-upload"></i> Datei auswählen</label>');
document.getElementById('saveBtn').addEventListener('click', () => {
if(activeDocument === null) {
return;
}
if(documents[activeDocument].name !== null) {
saveToLocalStorage();
} else {
modalSave.open();
}
});
document.getElementById('openBtn').addEventListener('click', () => {
modalOpen.open();
});
document.getElementById('importBtn').addEventListener('click', () => {
modalImport.open();
});
document.getElementById('exportBtn').addEventListener('click', () => {
modalExport.open();
});