From 59373c158e9ca4d0e48bb934cd8befac785208d6 Mon Sep 17 00:00:00 2001
From: Juan Fuentes <juanf@bs-mbpr28.d.ethz.ch>
Date: Mon, 20 May 2019 15:36:23 +0200
Subject: [PATCH] setting history id when is available on the jupyter notebook
 and the selected dataset type, comments

---
 jupyter-openbis-extension/static/uploadDialog.js | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/jupyter-openbis-extension/static/uploadDialog.js b/jupyter-openbis-extension/static/uploadDialog.js
index 6b0ac72..11cc7f6 100644
--- a/jupyter-openbis-extension/static/uploadDialog.js
+++ b/jupyter-openbis-extension/static/uploadDialog.js
@@ -59,13 +59,16 @@ define([
         }
 
         function getOpenBISHistoryId() {
+            // Default empty history id
             var resultDatasetHistoryId = "";
+            // Search for the history id on the metadata, new format, hidden from the user
             if(Jupyter && 
                 Jupyter.notebook && 
                 Jupyter.notebook.metadata && 
                 Jupyter.notebook.metadata.openbisHistoryId) {
                 resultDatasetHistoryId = Jupyter.notebook.metadata.openbisHistoryId;
             }
+            // Search for the history id on the cells, older format
             if (!resultDatasetHistoryId) {
                 var resultDatasetHistoryIdIdx = 0;
                 while(Jupyter.notebook.get_cell(resultDatasetHistoryIdIdx) != null) {
@@ -79,7 +82,7 @@ define([
                     resultDatasetHistoryIdIdx++;
                 }
             }
-            return resultDatasetHistoryId;
+            return resultDatasetHistoryId; // We always return at least the empty one
         }
 
         function getDatasetTypes(env, connection_name, dataset_types, input_fields) {
@@ -129,7 +132,7 @@ define([
                                         var mem = state.uploadDataSetTypes[dts[dataset_types.selectedIndex].code]
                                         if (mem == null) {
                                             mem = {
-                                                "$HISTORY_ID" : getOpenBISHistoryId()
+                                                "$HISTORY_ID" : getOpenBISHistoryId() // History Id should get automatically populated if available
                                             }
                                         }
                                         input_field.value = pa.code in mem ? mem[pa.code] : ""
-- 
GitLab