Browse Source

HUE-8330 [cluster] Hack to load editor and to list computes in editor

Romain Rigaux 7 years ago
parent
commit
4280767d28

+ 1 - 1
desktop/core/src/desktop/static/desktop/js/apiHelper.js

@@ -1297,7 +1297,7 @@ var ApiHelper = (function () {
           type: sourceType,
           source: isQuery ? 'query' : 'data',
         }),
-        cluster: '"' + options.compute.id + '"'
+        cluster: '"' + (options.compute ? options.compute.id : '') + '"'
       },
       timeout: options.timeout
     }).success(function (data) {

+ 2 - 2
desktop/core/src/desktop/static/desktop/js/dataCatalog.js

@@ -179,7 +179,7 @@ var DataCatalog = (function () {
       }
       var deferred = $.Deferred();
 
-      var identifier = dataCatalogEntry.namespace.id + '_' + dataCatalogEntry.compute.id;
+      var identifier = dataCatalogEntry.namespace.id + '_' + (dataCatalogEntry.compute ? dataCatalogEntry.compute.id : '');
       if (dataCatalogEntry.path.length) {
         identifier += '_' + dataCatalogEntry.path.join('.');
       }
@@ -361,7 +361,7 @@ var DataCatalog = (function () {
     DataCatalog.prototype.getEntry = function (options) {
       var self = this;
       var identifier = typeof options.path === 'string' ? options.path : options.path.join('.');
-      identifier = options.namespace.id + '_' + options.compute.id + (identifier ? '_' + identifier : '');
+      identifier = options.namespace.id + '_' + (options.compute ? options.compute.id : '') + (identifier ? '_' + identifier : '');
       if (self.entries[identifier]) {
         return self.entries[identifier];
       }

+ 17 - 5
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -359,15 +359,27 @@ var EditorViewModel = (function() {
     self.namespaceRefreshEnabled = ko.observable(false);
     self.availableNamespaces = ko.observableArray();
     self.namespace = ko.observable();
-    self.availableComputes = ko.pureComputed(function () {
+    self.availableComputes = ko.observableArray();/*ko.pureComputed(function () {
       if (self.namespace()) {
         return self.namespace().computes;
       }
       return [];
-    });
+    });*/
 
     self.compute = ko.observable();
 
+    var computesPromise = ContextCatalog.getComputes({ sourceType: self.type() }).done(function (computes) {
+      self.availableComputes(computes);
+      if (!snippet.compute || !computes.some(function (compute) {
+        if (compute.id === snippet.compute.id) {
+          self.compute(compute);
+          return true;
+        }
+      })) {
+        self.compute(computes[0]);
+      }
+    });
+    /*
     self.availableComputes.subscribe(function (newComputes) {
       if (!self.compute() || !newComputes.some(function (newCompute) {
         if (newCompute.id === self.compute().id) {
@@ -377,7 +389,7 @@ var EditorViewModel = (function() {
       })) {
         self.compute(newComputes.length ? newComputes[0] : undefined);
       }
-    });
+    });*/
 
     var namespacesPromise;
     self.reloadNamespaces = function () {
@@ -390,7 +402,7 @@ var EditorViewModel = (function() {
             return true;
           }})) {
           self.namespace(context.namespaces[0]);
-
+/*
           var previousComputeId;
           var newCompute;
           if (self.compute()) {
@@ -409,7 +421,7 @@ var EditorViewModel = (function() {
           if (!newCompute && self.namespace().computes.length) {
             newCompute = self.namespace().computes[0];
           }
-          self.compute(newCompute);
+          self.compute(newCompute);*/
         }
       });
     };