Skip to content

Commit

Permalink
Flag to enable new file uploader
Browse files Browse the repository at this point in the history
(cherry picked from commit 4df96aa)
Change-Id: Id1eae6e920d42668858eb2b3586c5b492195e482
  • Loading branch information
Athithyaa Selvam committed Oct 12, 2023
1 parent 91b9d0e commit 98799f5
Show file tree
Hide file tree
Showing 8 changed files with 9,187 additions and 7,811 deletions.
159 changes: 109 additions & 50 deletions apps/filebrowser/src/filebrowser/templates/listdir_components.mako
Original file line number Diff line number Diff line change
Expand Up @@ -2046,48 +2046,114 @@ else:
};
self.uploadFile = (function () {
self.pendingUploads(0);
var action = "/filebrowser/uploadchunks/";
// var dest = "?%2Fuser%2Fadmin"
var uploader = new qq.FileUploader({
element: document.getElementById("fileUploader"),
request: {
endpoint: action,
paramsInBody: false,
params: {
dest: self.currentPath(),
inputName: "hdfs_file"
}
},
maxConnections: window.CONCURRENT_MAX_CONNECTIONS || 5,
chunking: {
enabled: true,
concurrent: {
enabled: true
var uploader;
if (window.ENABLE_NEW_FILE_UPLOADER) {
self.pendingUploads(0);
var action = "/filebrowser/uploadchunks/";
uploader = new qq.FileUploader({
element: document.getElementById("fileUploader"),
request: {
endpoint: action,
paramsInBody: false,
params: {
dest: self.currentPath(),
inputName: "hdfs_file"
}
},
partSize: window.FILE_UPLOAD_CHUNK_SIZE || 5000000,
success: {
endpoint: "/filebrowser/uploaddone/"
maxConnections: window.CONCURRENT_MAX_CONNECTIONS || 5,
chunking: {
enabled: true,
concurrent: {
enabled: true
},
partSize: window.FILE_UPLOAD_CHUNK_SIZE || 5000000,
success: {
endpoint: "/filebrowser/uploaddone/"
},
paramNames: {
partIndex: "qqpartindex",
partByteOffset: "qqpartbyteoffset",
chunkSize: "qqchunksize",
totalFileSize: "qqtotalfilesize",
totalParts: "qqtotalparts"
}
},
template: 'qq-template',
callbacks: {
onProgress: function (id, fileName, loaded, total) {
console.log(loaded);
$('.qq-upload-files').find('li').each(function(){
var listItem = $(this);
if (listItem.find('.qq-upload-file-selector').text() == fileName){
listItem.find('.progress-row-bar').css('width', (loaded/total)*100 + '%');
}
});
},
onComplete: function (id, fileName, response) {
self.pendingUploads(self.pendingUploads() - 1);
if (response.status != 0) {
$(document).trigger('error', "${ _('Error: ') }" + response.data);
}
else {
$(document).trigger('info', response.path + "${ _(' uploaded successfully.') }");
self.filesToHighlight.push(response.path);
}
if (self.pendingUploads() == 0) {
$('#uploadFileModal').modal('hide');
self.retrieveData(true);
}
},
onAllComplete: function(succeeded, failed){
$('#uploadFileModal').modal('hide');
},
onSubmit: function (id, fileName, responseJSON) {
var newPath = "/filebrowser/uploadchunks/file?dest=" + encodeURIComponent(self.currentPath());
this.setEndpoint(newPath);
self.pendingUploads(self.pendingUploads() + 1);
},
onCancel: function (id, fileName) {
self.pendingUploads(self.pendingUploads() - 1);
}
},
paramNames: {
partIndex: "qqpartindex",
partByteOffset: "qqpartbyteoffset",
chunkSize: "qqchunksize",
totalFileSize: "qqtotalfilesize",
totalParts: "qqtotalparts"
}
},
template: 'qq-template',
callbacks: {
debug: false
});
}
else {
self.pendingUploads(0);
var action = "/filebrowser/upload/file";
uploader = new fileuploader.FileUploader({
element: document.getElementById("fileUploader"),
action: action,
template: '<div class="qq-uploader" style="margin-left: 10px">' +
'<div class="qq-upload-drop-area"><span>${_('Drop the files here to upload')}</span></div>' +
'<div class="qq-upload-button qq-no-float">${_('Select files')}</div> &nbsp; <span class="muted">${_('or drag and drop them here')}</span>' +
'<ul class="qq-upload-list qq-upload-files unstyled qq-no-float" style="margin-right: 0;"></ul>' +
'</div>',
fileTemplate: '<li><span class="qq-upload-file-extended" style="display:none"></span><span class="qq-upload-spinner hide" style="display:none"></span>' +
'<div class="progress-row dz-processing">' +
'<span class="break-word qq-upload-file"></span>' +
'<div class="pull-right">' +
'<span class="muted qq-upload-size"></span>&nbsp;&nbsp;' +
'<a href="#" title="${_('Cancel')}" class="complex-layout"><i class="fa fa-fw fa-times qq-upload-cancel"></i></a>' +
'<span class="qq-upload-done" style="display:none"><i class="fa fa-fw fa-check muted"></i></span>' +
'<span class="qq-upload-failed-text">${_('Failed')}</span>' +
'</div>' +
'<div class="progress-row-bar" style="width: 0%;"></div>' +
'</div></li>',
params: {
dest: self.currentPath(),
fileFieldLabel: "hdfs_file"
},
onProgress: function (id, fileName, loaded, total) {
console.log(loaded);
$('.qq-upload-files').find('li').each(function(){
var listItem = $(this);
if (listItem.find('.qq-upload-file-selector').text() == fileName){
listItem.find('.progress-row-bar').css('width', (loaded/total)*100 + '%');
}
});
$('.qq-upload-files').find('li').each(function(){
var listItem = $(this);
if (listItem.find('.qq-upload-file-extended').text() == fileName){
listItem.find('.progress-row-bar').css('width', (loaded/total)*100 + '%');
}
});
},
onComplete: function (id, fileName, response) {
self.pendingUploads(self.pendingUploads() - 1);
Expand All @@ -2103,24 +2169,17 @@ else:
self.retrieveData(true);
}
},
onAllComplete: function(succeeded, failed){
$('#uploadFileModal').modal('hide');
},
onSubmit: function (id, fileName, responseJSON) {
var newPath = "/filebrowser/uploadchunks/file?dest=" + encodeURIComponent(self.currentPath());
this.setEndpoint(newPath);
self.pendingUploads(self.pendingUploads() + 1);
},
onCancel: function (id, fileName) {
self.pendingUploads(self.pendingUploads() - 1);
}
},
debug: false
});
},
debug: false
});
}
$("#fileUploader").on('fb:updatePath', function (e, options) {
$("#fileUploader").on('fb:updatePath', function (e, options) {
const uploadingToOzone = self.currentPath().startsWith("ofs://");
const ozoneSizeLimit = Math.min(
...[UPLOAD_CHUNK_SIZE, MAX_FILE_SIZE_UPLOAD_LIMIT].filter(Number.isFinite)
Expand Down
5 changes: 3 additions & 2 deletions desktop/core/src/desktop/api2.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
from beeswax.models import Namespace
from desktop import appmanager
from desktop.auth.backend import is_admin
from desktop.conf import ENABLE_CONNECTORS, ENABLE_GIST_PREVIEW, CUSTOM, get_clusters, ENABLE_SHARING
from desktop.conf import ENABLE_NEW_STORAGE_BROWSER
from desktop.conf import ENABLE_CONNECTORS, ENABLE_GIST_PREVIEW, CUSTOM, get_clusters, IS_K8S_ONLY, ENABLE_SHARING
from desktop.conf import ENABLE_NEW_STORAGE_BROWSER, ENABLE_NEW_FILE_UPLOADER
from desktop.lib.conf import BoundContainer, GLOBAL_CONFIG, is_anonymous
from desktop.lib.django_util import JsonResponse, login_notrequired, render
from desktop.lib.exceptions_renderable import PopupException
Expand Down Expand Up @@ -100,6 +100,7 @@ def get_config(request):
config['hue_config']['is_admin'] = is_admin(request.user)
config['hue_config']['is_yarn_enabled'] = is_yarn()
config['hue_config']['enable_new_storage_browser'] = ENABLE_NEW_STORAGE_BROWSER.get()
config['hue_config']['enable_new_file_uploader'] = ENABLE_NEW_FILE_UPLOADER.get()
config['clusters'] = list(get_clusters(request.user).values())
config['documents'] = {
'types': list(Document2.objects.documents(user=request.user).order_by().values_list('type', flat=True).distinct())
Expand Down
7 changes: 7 additions & 0 deletions desktop/core/src/desktop/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1818,6 +1818,13 @@ def get_instrumentation_default():
default=False
)

ENABLE_NEW_FILE_UPLOADER = Config(
key="enable_new_file_uploader",
help=_("Feature flag to enable new Hue file uploader."),
type=coerce_bool,
default=False
)

USE_NEW_EDITOR = Config( # To remove in Hue 4
key='',
default=True,
Expand Down
Loading

0 comments on commit 98799f5

Please sign in to comment.