UI 命名空间 Tableau 扩展更改未保存在 Tableau Server 中

San*_*jay 1 tableau-api

我正在开发类似于Tableau 提供的UI 命名空间示例扩展 ( Github Link ) 的扩展。

我已将文件托管在应用程序服务器中(启用 https)并将 trex 文件指向托管在那里的文件。

我能够将扩展拖到 Tableau Desktop,从对话框中选择输入,页面会根据提供的输入刷新。

在我保存仪表板并将其发布到 tableau 服务器后,我无法看到发布前保存的更改。它返回到初始状态“配置扩展以继续”。

我尝试直接在 Tableau Server 中编辑它,但仍然导致相同的问题。

发布工作簿时不会保存更改。

如果我遗漏了什么,或者是否有人遇到同样的问题能够解决它,请告诉我吗?

San*_*jay 5

经过研究和代码更改,我找到了问题的解决方案。

在 UI 命名空间示例中,我们需要包含一个函数来检查以前保存的设置并基于此填充 UI。您可以通过打开 .twb 文件查看保存的设置。 在此处输入图片说明

以前只有选定的数据源被保存为设置。但我已经包含了一个代码,除了数据源之外,还可以将选定的间隔保存为设置。这对于在用户下次单击配置时保留间隔状态非常有用。

用于检查 uiNamespace.js 中是否已存在设置的代码片段:

$(document).ready(function () {
    // When initializing an extension, an optional object is passed that maps a special ID (which
    // must be 'configure') to a function.  This, in conjuction with adding the correct context menu
    // item to the manifest, will add a new "Configure..." context menu item to the zone of extension
    // inside a dashboard.  When that context menu item is clicked by the user, the function passed
    // here will be executed.	
    tableau.extensions.initializeAsync({'configure': configure}).then(function () {
      // First, check for any saved settings and populate our UI based on them.
      checkForSettings(tableau.extensions.settings.getAll());
    }, function (err) {
      // Something went wrong in initialization
      console.log('Error while Initializing: ' + err.toString());
    })
	.then(function() { 
      // This event allows for the parent extension and popup extension to keep their
      // settings in sync.  This event will be triggered any time a setting is
      // changed for this extension, in the parent or popup (i.e. when settings.saveAsync is called).
      tableau.extensions.settings.addEventListener(tableau.TableauEventType.SettingsChanged, (settingsEvent) => {
        updateExtensionBasedOnSettings(settingsEvent.newSettings)
      });
    });
  });
  
  function checkForSettings (settings) {
	if(Object.keys(settings).length > 0)
	{
		updateExtensionBasedOnSettings(settings);
		selectedInterval = JSON.parse(settings.intervalCount);
		$('#interval').text(selectedInterval);	  
		setupRefreshInterval(selectedInterval);
		defaultIntervalInMin = selectedInterval;
		$('#inactive').hide();
		$('#active').show();
	}
	
  }
Run Code Online (Sandbox Code Playgroud)

用于将所选间隔保存为 uiNamespaceDialog.js 中的设置的代码片段:

function closeDialog() {
    let currentSettings = tableau.extensions.settings.getAll();
    tableau.extensions.settings.set(datasourcesSettingsKey, JSON.stringify(selectedDatasources));
	tableau.extensions.settings.set(intervalCountKey, JSON.stringify($('#interval').val()));

    tableau.extensions.settings.saveAsync().then((newSavedSettings) => {
      tableau.extensions.ui.closeDialog($('#interval').val());
    });
  }
Run Code Online (Sandbox Code Playgroud)

完整代码可在GitHub找到。 现在,一旦我们在 Tableau Desktop 中进行更改并将其发布到 Tableau Server,配置就会被保存。

此更改还将解决 Web 编辑问题(直接在 tableau 服务器中编辑扩展)。