#48 Fixes the crash when renaming files.

Merged
bentley merged 6 commits from bentley/fix_file_actions into simon/master 6 years ago

+ 20 - 7
client/file_browser.js

@@ -33,7 +33,8 @@ class FileBrowser{
                     fileb =
                         FileBrowser.getFileBrowser(fnames, false, manualInput, __getRecentDir(startDir));
 
-                new_folder_b.attr('id', 'new_folder')
+                new_folder_b
+                    .attr('id', 'new_folder')
                     .html('new folder')
                     .click(function (ev) {
                         var folder_name = prompt("please fill in a name for the folder");
@@ -57,7 +58,9 @@ class FileBrowser{
                     });
                 folder_buttons.append(new_folder_b);
 
-                rename_folder_b.html('rename folder')
+                rename_folder_b
+                    .attr('id', 'rename_folder')
+                    .html('rename folder')
                     .click(function (ev) {
                         var value = fileb['getcurrfolder']();
                         var folder_name = prompt("please fill in a new name for folder " + value);
@@ -85,7 +88,9 @@ class FileBrowser{
                     });
                 folder_buttons.append(rename_folder_b);
 
-                delete_folder_b.html('delete folder')
+                delete_folder_b
+                    .attr('id', 'delete_folder')
+                    .html('delete folder')
                     .click(function (ev) {
                         var value = fileb['getcurrfolder']();
                         if (confirm("are you sure you want to delete " + value + "?")) {
@@ -107,7 +112,9 @@ class FileBrowser{
                     });
                 folder_buttons.append(delete_folder_b);
 
-                move_folder_b.html('move folder')
+                move_folder_b
+                    .attr('id', 'move_folder')
+                    .html('move folder')
                     .click(function (ev) {
                         var value = fileb['getcurrfolder']();
                         var folder_loc = prompt("please fill in a new parent folder for folder " + value);
@@ -135,7 +142,9 @@ class FileBrowser{
                     });
                 folder_buttons.append(move_folder_b);
 
-                rename_file_b.html('rename file')
+                rename_file_b
+                    .attr('id', 'rename_file')
+                    .html('rename file')
                     .click(function (ev) {
                         var value = fileb['getselection']();
                         var file_name = prompt("please fill in a new name for file " + value);
@@ -164,7 +173,9 @@ class FileBrowser{
                     });
                 file_buttons.append(rename_file_b);
 
-                delete_file_b.html('delete file')
+                delete_file_b
+                    .attr('id', 'delete_file')
+                    .html('delete file')
                     .click(function (ev) {
                         var value = fileb['getselection']();
                         if (confirm("are you sure you want to delete " + value + "?")) {
@@ -185,7 +196,9 @@ class FileBrowser{
                     });
                 file_buttons.append(delete_file_b);
 
-                move_file_b.html('move file')
+                move_file_b
+                    .attr('id', 'move_file')
+                    .html('move file')
                     .click(function (ev) {
                         var value = fileb['getselection']();
                         var folder_loc = prompt("please fill in a new parent folder for file " + value);

+ 1 - 0
client/gui_utils.js

@@ -452,6 +452,7 @@ GUIUtils = function(){
 			cancel.click(function(ev) {
 				BehaviorManager.handleUserEvent(__EVENT_CANCELED_DIALOG);
 			});
+			cancel.attr("id", "dialog_cancel_btn");
 			cancel.html('cancel');
 			dialog.append(cancel);
 		}

+ 1 - 3
client/http_utils.js

@@ -64,9 +64,7 @@ HttpUtils = function(){
 			req.open(method, url, !sync); 
 			req.onreadystatechange = onreadystatechange;
 
-			if (typeof params != 'string'){
-				params = JSON.stringify(params);
-			}
+			params = JSON.stringify(params);
 			req.send(params);
 
 		}

+ 6 - 2
packaging/docker/Dockerfile

@@ -1,4 +1,4 @@
-FROM ubuntu:18.04
+FROM ubuntu:20.04
 
 RUN apt-get update -y && \
 		apt-get upgrade -y
@@ -7,12 +7,16 @@ RUN apt-get install -y git
 
 RUN apt-get install -y curl
 
+RUN DEBIAN_FRONTEND="noninteractive" apt-get -y install tzdata
+
 RUN apt-get install -y zlib1g-dev libxml2-dev
 
 RUN apt-get install -y pkg-config
 
 RUN apt-get install -y python3 python3-pip
 
+RUN pip3 install six
+
 RUN pip3 install python-igraph
 
 RUN apt-get install -y nodejs npm
@@ -30,4 +34,4 @@ COPY run_AToMPM_local.sh ./run_AToMPM_local.sh
 # Port
 EXPOSE 8124
 
-CMD ["bash", "run_AToMPM_local.sh"]
+CMD ["bash", "run_AToMPM_local.sh"]

+ 97 - 0
packaging/docker/ProducingDockerVM.md

@@ -0,0 +1,97 @@
+# Do Once: Creating the VM
+
+1. Create the VM:
+   1. `docker create --name atompmrun -p 8124:8124 -ti atompmvm` 
+2. Open your browser and navigate to `http://localhost:8124/atompm`
+   1. If there is a problem in this step, it might be because you are running docker on Windows. In that case, use the machine IP instead of `localhost` in the above address. Find the host's IP address by running `docker-machine ip`.
+   
+# Exporting the VM
+
+1. Install [Docker](https://www.docker.com/).
+
+1. Using docker's console, navigate to the root of this repository.
+
+1. Build the docker image. This will download all dependencies you need to run the examples. You might need root access.
+
+1. ```
+   docker build -t atompmvm .
+   ```
+
+1. Export the docker vm:
+
+   1. `docker save atompmvm | gzip > atompmvm.tar.gz`
+
+# Loading the VM
+
+```
+docker load < atompmvm.tar.gz
+```
+
+# Running the VM
+
+1. Note the host's IP address by running: 
+
+   1. `docker-machine ip`. 
+   1. Let us denote it by `MACHINE_IP`
+1. Run the docker container (one of the following)
+   1. `docker run --name atompmrun -p 8124:8124 -ti atompmvm` 
+1. Open your browser and navigate to `http://MACHINE_IP:8124/`
+
+# Starting and Stopping VM
+
+*You can run docker commands from different terminals.*
+
+To start the container (and attach):
+```
+docker start -a atompmrun 
+```
+
+To attach to a container:
+```
+docker attach atompmrun
+```
+
+Stop container:
+```
+docker stop atompmrun
+```
+
+List container status
+```
+docker container ls -a
+```
+
+# Moving files in/out of VM
+
+*You can run docker commands from different terminals.*
+
+From VM to host (backup).
+```
+docker cp atompmrun:/opt/atompm/users/. ./atompmusers/
+```
+
+From host to VM (restore):
+```
+docker cp ./atompmusers/. atompmrun:/opt/atompm/users/
+```
+
+# Do Once: Cleaning Up (!)
+
+These commands can be run from a second docker terminal.
+
+Delete container:
+**Danger: you will lose all the files modified inside the VM. This includes all models created in atompm!**
+```
+docker rm atompmrun
+```
+
+Delete image:
+```
+docker image rm atompmvm
+```
+
+Delete dangling caches:
+```
+docker system prune
+```
+

+ 0 - 61
packaging/docker/ProducingVM.md

@@ -1,61 +0,0 @@
-# Exporting the VM
-
-1. Install [Docker](https://www.docker.com/).
-
-1. Using docker's console, navigate to the root of this repository.
-
-1. Build the docker image. This will download all dependencies you need to run the examples. You might need root access.
-
-1. ```
-   docker build -t atompmvm .
-   ```
-
-1. Export the docker vm:
-
-   1. `docker save atompmvm | gzip > atompmvm.tar.gz`
-
-# Loading the VM
-
-```
-docker load < atompmvm.tar.gz
-```
-
-# Running the VM
-
-1. Note the host's ip address by running: 
-
-   1. `docker-machine ip`. 
-   1. Let us denote it by `MACHINE_IP`
-1. Run the docker container (one of the following)
-   1. `docker run --name atompmrun -p 8124:8124 -ti atompmvm` 
-1. Open your browser and navigate to `http://MACHINE_IP:8888/`
-# Stopping and Cleaning
-
-These commands can be run from a second docker terminal.
-
-Stop and remove container:
-
-```
-docker stop atompmrun 
-docker rm atompmrun
-```
-
-Delete image:
-
-```
-docker image rm atompmvm
-```
-
-Delete dangling caches:
-
-```
-docker system prune
-```
-
-# Moving files in and out of the VM
-
-```
-docker cp ./atompmuser/** atompmrun:/opt/atompm/users/atompmuser/
-docker cp atompmrun:/opt/atompm/users/atompmuser/** ./atompmuser/
-```
-

+ 2 - 2
packaging/docker/README.md

@@ -1,11 +1,11 @@
-# Student Workflow
+# Workflow
 
 ## Do Once: Creating the VM
 
 1. Create the VM:
    1. `docker create --name atompmrun -p 8124:8124 -ti atompmvm` 
 2. Open your browser and navigate to `http://localhost:8124/atompm`
-   1. If there is a problem in this step, it might be because you are running docker on windows. In that case, use the machine IP instead of `localhost` in the above address. Find the host's IP address by running `docker-machine ip`.
+   1. If there is a problem in this step, it might be because you are running docker on Windows. In that case, use the machine IP instead of `localhost` in the above address. Find the host's IP address by running `docker-machine ip`.
 
 ## Starting and Stopping VM
 

+ 22 - 5
run_AToMPM_local.sh

@@ -1,18 +1,35 @@
 #!/bin/bash
-# Author: Yentl Van Tendeloo
+# Author: Yentl Van Tendeloo and Bentley James Oakes
 
 set -e
 
+echo "Running AToMPM script..."
+echo "Starting node..."
 node httpwsd.js &
 serverpid=$!
 sleep 3
 
-python2 mt/main.py&
+echo "Starting Python model transformation engine..."
+python mt/main.py&
 mtpid=$!
 sleep 1
 
+echo "AToMPM now running. Opening browser..."
+
+echo "Trying to run Google Chrome..."
+set +e
 google-chrome-stable http://localhost:8124/atompm
 
-kill $serverpid
-kill $mtpid
-echo "All done!"
+ret=$?
+if [ $ret -ne 0 ]; then
+    echo "Google Chrome not installed. Trying Firefox..."
+    firefox http://localhost:8124/atompm
+fi
+
+ret=$?
+if [ $ret = 0 ]; then
+    echo "Stopping AToMPM"
+    kill $serverpid
+    kill $mtpid
+    echo "Finished!"
+fi

+ 2 - 2
run_tests.sh

@@ -18,7 +18,7 @@ fi
 
 #run mt script
 echo "Starting model transformation script..."
-python2 mt/main.py &
+python mt/main.py &
 mtpid=$!
 sleep 3
 
@@ -43,7 +43,7 @@ fi
 
 
 echo "Starting tests..."
-nightwatch
+./node_modules/nightwatch/bin/nightwatch
 
 echo "Stopping server and mt script..."
 kill "$serverpid"

+ 10 - 0
tests/03_model_test.js

@@ -36,6 +36,16 @@ module.exports = {
         test_utils.load_model(client, filenames);
     },
 
+    'Rename model' : function (client) {
+
+        let filename = 'Formalisms/ClassicDEVS/ClassicDEVS.model';
+        let old_filename = 'Test.model';
+        let new_filename = 'Test2.model';
+        test_utils.load_model(client, [filename]);
+        model_building_utils.save_model(client, "~", old_filename)
+        model_building_utils.rename_model(client, "~", old_filename, new_filename)
+    },
+
     after : function (client) {
         client.end();
     },

+ 40 - 0
tests/model_building_utils.js

@@ -157,6 +157,10 @@ function navigate_to_folder(client, folder_name) {
     client.waitForElementPresent(root_button, 2000, "Find root button")
         .click(root_button);
 
+    if (folder_name === "~") {
+        return;
+    }
+
     let new_folder_selector = "#new_folder";
     let folder_path = folder_name.split("/");
 
@@ -234,6 +238,41 @@ function save_model(client, folder_name, model_name) {
     );
 }
 
+function rename_model(client, folder_name, old_filename, new_filename) {
+    let load_button = "#\\2f Toolbars\\2f MainMenu\\2f MainMenu\\2e buttons\\2e model\\2f loadModel";
+
+    client.waitForElementPresent(load_button, 1000, "Looking for load button")
+        .click(load_button)
+        .waitForElementPresent("#dialog_btn", 1000, "Load menu opens");
+
+    navigate_to_folder(client, folder_name);
+
+    let rename_file_text = "#rename_file";
+    let model_selector = "#" + fix_selector(old_filename);
+    client.element('css selector', model_selector, function (result) {
+            if (result.status == -1) {
+                client.assert.ok(false, "Could not find file with name: '" + old_filename + "'");
+            } else {
+                client.click(model_selector);
+            }
+
+            client.click(rename_file_text)
+                    .pause(500)
+                    .setAlertText(new_filename)
+                    .acceptAlert();
+
+            client.assert.ok(true, "Renaming model to name: '" + new_filename + "'");
+
+            client.waitForElementPresent("#dialog_cancel_btn", 2000, "Looking for close")
+                .pause(200)
+                .click("#dialog_cancel_btn")
+                .pause(200)
+                .waitForElementNotPresent("#dialog_cancel_btn", 2000, "Load menu closes");
+
+        }
+    );
+}
+
 function load_transformation(client, folder_name, model_name) {
     compile_model(client, "transform", folder_name, model_name);
 }
@@ -326,6 +365,7 @@ module.exports = {
     click_off,
     save_model,
     load_model,
+    rename_model,
     compile_model,
     load_transformation,
     scroll_geometry_element,