|
|
@@ -45,11 +45,11 @@ const TEMPLATE = `
|
|
|
|
|
|
<script type="text/html" id="assist-storage-header-actions">
|
|
|
<div class="assist-db-header-actions">
|
|
|
- <!-- ko if: type !== 's3' && type !== 'abfs' -->
|
|
|
+ <!-- ko if: source.type !== 's3' && source.type !== 'abfs' -->
|
|
|
<a class="inactive-action" href="javascript:void(0)" data-bind="click: goHome, attr: { title: I18n('Go to ' + window.USER_HOME_DIR) }"><i class="pointer fa fa-home"></i></a>
|
|
|
<!-- ko if: window.SHOW_UPLOAD_BUTTON -->
|
|
|
<a class="inactive-action" data-bind="dropzone: {
|
|
|
- url: '/filebrowser/upload/file?dest=' + (type === 'adls' ? 'adl:' : '') + path,
|
|
|
+ url: '/filebrowser/upload/file?dest=' + (source.type === 'adls' ? 'adl:' : '') + path,
|
|
|
params: { dest: path },
|
|
|
paramName: 'hdfs_file',
|
|
|
onError: function(x, e){ $(document).trigger('error', e); },
|
|
|
@@ -62,7 +62,7 @@ const TEMPLATE = `
|
|
|
</a>
|
|
|
<!-- /ko -->
|
|
|
<!-- /ko -->
|
|
|
- <!-- ko if: type === 'abfs' && path !== '/' && window.SHOW_UPLOAD_BUTTON -->
|
|
|
+ <!-- ko if: source.type === 'abfs' && path !== '/' && window.SHOW_UPLOAD_BUTTON -->
|
|
|
<a class="inactive-action" data-bind="dropzone: {
|
|
|
url: '/filebrowser/upload/file?dest=' + 'abfs:/' + path,
|
|
|
params: { dest: 'abfs:/' + path },
|
|
|
@@ -93,7 +93,7 @@ const TEMPLATE = `
|
|
|
<div class="assist-flex-fill">
|
|
|
<ul class="assist-tables" data-bind="foreach: sources">
|
|
|
<li class="assist-table">
|
|
|
- <a class="assist-table-link" href="javascript: void(0);" data-bind="click: function () { $parent.activeSource($data); }"><i class="fa fa-fw fa-server muted valign-middle"></i> <span data-bind="text: $data.toUpperCase()"></span></a>
|
|
|
+ <a class="assist-table-link" href="javascript: void(0);" data-bind="click: function () { $parent.activeSource($data); }"><i class="fa fa-fw fa-server muted valign-middle"></i> <span data-bind="text: $data.displayName"></span></a>
|
|
|
</li>
|
|
|
</ul>
|
|
|
</div>
|
|
|
@@ -118,7 +118,7 @@ const TEMPLATE = `
|
|
|
<a href="javascript: void(0);" data-bind="click: function () { $parent.activeSource(undefined) }">
|
|
|
<i class="fa fa-fw fa-chevron-left"></i>
|
|
|
<i class="fa fa-fw fa-server"></i>
|
|
|
- <span data-bind="text: $parent.activeSource().toUpperCase()"></span>
|
|
|
+ <span data-bind="text: $parent.activeSource().displayName"></span>
|
|
|
</a>
|
|
|
<!-- /ko -->
|
|
|
<!-- ko template: 'assist-storage-header-actions' --><!-- /ko -->
|
|
|
@@ -152,7 +152,7 @@ const TEMPLATE = `
|
|
|
<!-- ko if: definition.type === 'file' -->
|
|
|
<i class="fa fa-fw fa-file-o muted valign-middle"></i>
|
|
|
<!-- /ko -->
|
|
|
- <span draggable="true" data-bind="text: definition.name, draggableText: { text: '\\'' + path + '\\'', meta: {'type': type, 'definition': definition} }"></span>
|
|
|
+ <span draggable="true" data-bind="text: definition.name, draggableText: { text: '\\'' + path + '\\'', meta: {'type': source.type, 'definition': definition} }"></span>
|
|
|
</a>
|
|
|
</li>
|
|
|
</ul>
|
|
|
@@ -174,30 +174,49 @@ const TEMPLATE = `
|
|
|
<!-- /ko -->
|
|
|
`;
|
|
|
|
|
|
+const rootPathRegex = /.*%3A%2F%2F(.+)$/;
|
|
|
+
|
|
|
+/**
|
|
|
+ * This takes the initial path from the "browser" config, used in cases where the users can't access '/'
|
|
|
+ */
|
|
|
+const getRootPath = source => {
|
|
|
+ if (source) {
|
|
|
+ const match = source.page.match(rootPathRegex);
|
|
|
+ if (match) {
|
|
|
+ return match[1] + '/';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return '';
|
|
|
+};
|
|
|
+
|
|
|
class AssistStoragePanel {
|
|
|
/**
|
|
|
* @param {Object} options
|
|
|
- * @param {String[]} options.sources
|
|
|
+ * @param {Interpreter[]} options.sources
|
|
|
* @constructor
|
|
|
**/
|
|
|
constructor(options) {
|
|
|
this.sources = ko.observableArray(options.sources);
|
|
|
|
|
|
- let lastSource = apiHelper.getFromTotalStorage('assist', 'lastStorageSource', 'hdfs');
|
|
|
+ const lastSourceType = apiHelper.getFromTotalStorage('assist', 'lastStorageSource', 'hdfs');
|
|
|
+
|
|
|
+ let foundLastSource = this.sources().find(source => source.type === lastSourceType);
|
|
|
|
|
|
- if (options.sources.indexOf(lastSource) === -1) {
|
|
|
- lastSource = options.sources.indexOf('hdfs') !== -1 ? 'hdfs' : options.sources[0];
|
|
|
+ if (!foundLastSource && this.sources().length) {
|
|
|
+ foundLastSource = this.sources().find(source => source.type === 'hdfs') || this.sources()[0];
|
|
|
}
|
|
|
|
|
|
- this.activeSource = ko.observable(lastSource);
|
|
|
+ this.activeSource = ko.observable(foundLastSource);
|
|
|
this.loading = ko.observable();
|
|
|
this.initialized = false;
|
|
|
+ this.rootPath = getRootPath(this.activeSource());
|
|
|
|
|
|
this.selectedStorageEntry = ko.observable();
|
|
|
|
|
|
this.activeSource.subscribe(newValue => {
|
|
|
if (newValue) {
|
|
|
- apiHelper.setInTotalStorage('assist', 'lastStorageSource', newValue);
|
|
|
+ this.rootPath = getRootPath(this.activeSource());
|
|
|
+ apiHelper.setInTotalStorage('assist', 'lastStorageSource', newValue.type);
|
|
|
this.selectedStorageEntry(undefined);
|
|
|
this.reload();
|
|
|
}
|
|
|
@@ -209,15 +228,17 @@ class AssistStoragePanel {
|
|
|
});
|
|
|
|
|
|
huePubSub.subscribe('assist.storage.refresh', () => {
|
|
|
- apiHelper.clearStorageCache(this.activeSource());
|
|
|
+ apiHelper.clearStorageCache(this.activeSource().type);
|
|
|
this.reload();
|
|
|
});
|
|
|
|
|
|
huePubSub.subscribe('assist.storage.go.home', () => {
|
|
|
const path =
|
|
|
- this.activeSource() === 's3' || this.activeSource() === 'abfs' ? '/' : window.USER_HOME_DIR;
|
|
|
+ this.activeSource().type === 's3' || this.activeSource().type === 'abfs'
|
|
|
+ ? '/'
|
|
|
+ : window.USER_HOME_DIR;
|
|
|
this.loadPath(path);
|
|
|
- apiHelper.setInTotalStorage('assist', 'currentStoragePath_' + this.activeSource(), path);
|
|
|
+ apiHelper.setInTotalStorage('assist', 'currentStoragePath_' + this.activeSource().type, path);
|
|
|
});
|
|
|
|
|
|
this.init();
|
|
|
@@ -225,13 +246,18 @@ class AssistStoragePanel {
|
|
|
|
|
|
loadPath(path) {
|
|
|
this.loading(true);
|
|
|
- const parts = path.split('/');
|
|
|
+ let relativePath = path;
|
|
|
+ if (this.rootPath) {
|
|
|
+ relativePath = relativePath.replace(this.rootPath, '/');
|
|
|
+ }
|
|
|
+ const parts = relativePath.split('/');
|
|
|
parts.shift();
|
|
|
|
|
|
const currentEntry = new AssistStorageEntry({
|
|
|
- type: this.activeSource(),
|
|
|
+ source: this.activeSource(),
|
|
|
+ rootPath: this.rootPath,
|
|
|
definition: {
|
|
|
- name: '/',
|
|
|
+ name: this.rootPath,
|
|
|
type: 'dir'
|
|
|
},
|
|
|
parent: null
|
|
|
@@ -248,8 +274,8 @@ class AssistStoragePanel {
|
|
|
this.loadPath(
|
|
|
apiHelper.getFromTotalStorage(
|
|
|
'assist',
|
|
|
- 'currentStoragePath_' + this.activeSource(),
|
|
|
- this.activeSource() === 'hdfs' ? window.USER_HOME_DIR : '/'
|
|
|
+ 'currentStoragePath_' + this.activeSource().type,
|
|
|
+ this.activeSource().type === 'hdfs' ? window.USER_HOME_DIR : '/'
|
|
|
)
|
|
|
);
|
|
|
}
|