Skip to content

Commit

Permalink
Option to restore model on load
Browse files Browse the repository at this point in the history
  • Loading branch information
A-Herzog committed Jan 17, 2025
1 parent 8f87b95 commit 7795e9c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/js/Animator.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ function animationFastForwardShowFullData() {
}
if (recordData.name=='cBusy' && stationData.records.c) {
const rho=recordData.mean/stationData.records.c;
content+=", "+getCharacteristicsInfo("rho")+"="+(rho*100).toLocaleString()+"%"; // XXX:
content+=", "+getCharacteristicsInfo("rho")+"="+(rho*100).toLocaleString()+"%";
plainLine+=", rho="+(rho*100).toLocaleString()+"%";
}
} else {
Expand Down
13 changes: 11 additions & 2 deletions docs/js/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

export {zoomIn, zoomOut, showMessage, showConfirmationMessage, discardModel, fileNew, fileLoad, fileLoadDrag, fileLoadDragEnter, fileLoadDragLeave, fileLoadDrop, fileSave, showFileSidebar, showTemplatesSidebar, showAnimationSidebar, showMoreSidebar, allowDrop, dragElement, dragElementProgress, dragTemplate, canvasDrop, addEdgeActive, addEdgeClick, canvasClick, elements, edges, addElementToModel, addTextToModel, addDiagramToModel, getElementByBoxId, addEdgeToModel, updateModelOnCanvas, deleteSelectedElement};
export {zoomIn, zoomOut, showMessage, showConfirmationMessage, discardModel, fileNew, fileLoad, fileLodeJSON, fileLoadDrag, fileLoadDragEnter, fileLoadDragLeave, fileLoadDrop, fileSave, showFileSidebar, showTemplatesSidebar, showAnimationSidebar, showMoreSidebar, allowDrop, dragElement, dragElementProgress, dragTemplate, canvasDrop, addEdgeActive, addEdgeClick, canvasClick, elements, edges, addElementToModel, addTextToModel, addDiagramToModel, getElementByBoxId, addEdgeToModel, updateModelOnCanvas, deleteSelectedElement};

import {language} from "./Language.js";
import {animationActive} from "./Animator.js";
Expand Down Expand Up @@ -719,7 +719,11 @@ function showElementEditor(element, index) {
updateModelOnCanvas();
}

// FIXME: Doku
/**
* Deletes an element
* @param {Object} element Station object to be edited
* @param {Number} index Index of the station object in the list of all stations
*/
function deleteElement(element, index) {
deleteEdges(element.boxId);
elements.splice(index,1);
Expand Down Expand Up @@ -1302,4 +1306,9 @@ function updateModelOnCanvas() {

for (let i=0;i<elements.length;i++) addElementToCanvas(elements[i],i,elements);
for (let i=0;i<edges.length;i++) addEdgeToCanvas(edges[i],i);

/* Store current model in local storage */
const model={elements: elements, edges: edges};
const json=JSON.stringify(model);
localStorage.setItem("current_model",json);
}
8 changes: 8 additions & 0 deletions docs/js/Language.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ lang.dialog.No="Nein";
lang.dialog.Error="Fehler";
lang.dialog.CloseWindow="Fenster schließen";

lang.restore={};
lang.restore.title="Modell wiederherstellen";
lang.restore.question="Soll das zuletzt bearbeitete Modell jetzt wiederhergestellt werden?";

lang.tabFile={};
lang.tabFile.title="Datei";
lang.tabFile.button="Datei";
Expand Down Expand Up @@ -388,6 +392,10 @@ lang.dialog.No="No";
lang.dialog.Error="Error";
lang.dialog.CloseWindow="Close window";

lang.restore={};
lang.restore.title="Restore model";
lang.restore.question="Do you want to restore the last edited model now?";

lang.tabFile={};
lang.tabFile.title="File";
lang.tabFile.button="File";
Expand Down
2 changes: 1 addition & 1 deletion docs/js/Simulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class WebSimulator extends Simulator {
if (count>0) status+=", ";
if (count>0 && count%2==0) status+="<br>";
count++;
const rho=stationData[recordName].mean/stationData.c; // XXX:
const rho=stationData[recordName].mean/stationData.c;
status+=getCharacteristicsInfo("rho")+"=<span title='"+(rho*100).toLocaleString()+"%'>"+statcore.formatShorter(rho*100)+"%</span>";
}
}
Expand Down
6 changes: 5 additions & 1 deletion docs/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ limitations under the License.
*/

import {language} from './Language.js';
import {zoomIn, zoomOut, fileNew, fileLoad, fileLoadDrag, fileLoadDragEnter, fileLoadDragLeave, fileLoadDrop, fileSave, showFileSidebar, showTemplatesSidebar, showMoreSidebar, allowDrop, canvasDrop, addEdgeClick, canvasClick, deleteSelectedElement} from "./Editor.js";
import {zoomIn, zoomOut, showConfirmationMessage, fileNew, fileLoad, fileLodeJSON, fileLoadDrag, fileLoadDragEnter, fileLoadDragLeave, fileLoadDrop, fileSave, showFileSidebar, showTemplatesSidebar, showMoreSidebar, allowDrop, canvasDrop, addEdgeClick, canvasClick, deleteSelectedElement} from "./Editor.js";
import {loadExample} from "./Example.js";
import {startAnimation, animationPlayPause, animationSingleTimeStep, animationFastForward} from "./Animator.js";
import {processSeries} from "./Series.js";
Expand Down Expand Up @@ -192,4 +192,8 @@ document.addEventListener('readystatechange',event=>{if (event.target.readyState
}
mainContent.style.display="";
infoLoading.style.display="none";
const lastModel=localStorage.getItem("current_model");
if (lastModel!=null) {
showConfirmationMessage(language.restore.title,language.restore.question,()=>fileLodeJSON(lastModel));
}
}});

0 comments on commit 7795e9c

Please sign in to comment.