Skip to content

Commit

Permalink
Synced result, import and explorer views
Browse files Browse the repository at this point in the history
  • Loading branch information
StanZGenchev committed Jan 16, 2025
1 parent f1fa783 commit db4883e
Show file tree
Hide file tree
Showing 9 changed files with 362 additions and 342 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ database.controller('DatabaseController', function ($scope, $http, messageHub) {
}.bind(this)
};
}

// Export metadata
ctxmenu.exportMetadata = {
"separator_before": true,
Expand Down Expand Up @@ -495,7 +495,7 @@ database.controller('DatabaseController', function ($scope, $http, messageHub) {
}.bind(this)
};
}

// Collection related actions
if (node.original.kind === 'table' && node.original.type === 'collection') {
ctxmenu.showContents = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ importView.controller('ImportViewController', [
$scope.dropAreaTitle = 'Import files';
$scope.dropAreaSubtitle = 'Drop file(s) here, or use the "+" button.';
$scope.dropAreaMore = `Files will be imported in "${params.uploadPath}"`;
} if (params.importType === 'data') {
} else if (params.importType === 'data') {
$scope.inputAccept = 'csv';
$scope.importType = params.importType;
$scope.dropAreaTitle = 'Import data files';
$scope.dropAreaSubtitle = 'Drop file(s) here, or use the "+" button.';
$scope.dropAreaMore = `Files will be imported in "${params.table}"`;
} if (params.importType === 'sql') {
} else if (params.importType === 'sql') {
$scope.inputAccept = 'sql';
$scope.importType = params.importType;
$scope.dropAreaTitle = 'Import SQL files';
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,16 @@ database.controller('DatabaseController', function ($scope, $http, MessageHub, N

// Schema related actions
if (node.original.kind === 'schema') {
ctxmenu.importScript = {
"separator_before": false,
"label": "Import SQL",
"action": function (data) {
let tree = $.jstree.reference(data.reference);
let node = tree.get_node(data.reference);
let sqlCommand = node.original.text;
MessageHub.postMessage({ topic: 'database.data.import.sql', data: sqlCommand });
}.bind(this)
};
ctxmenu.exportData = {
separator_before: false,
label: 'Export Data',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,156 +13,153 @@ const importView = angular.module('import', ['blimpKit', 'platformView', 'Worksp
importView.constant('StatusBar', new StatusBarHub());
importView.constant('Workspace', new WorkspaceHub());
importView.constant('Repository', new RepositoryHub());
importView.controller('ImportViewController',
function (
$scope,
$window,
ViewParameters,
WorkspaceService,
TransportService,
FileUploader,
StatusBar,
Workspace,
Repository
) {
const projectImportUrl = TransportService.getProjectImportUrl();
$scope.selectedWorkspace = WorkspaceService.getCurrentWorkspace();
$scope.workspaceNames = [];
$scope.projectsViewId = undefined;
$scope.inDialog = false;
$scope.importRepository = false;
$scope.inputAccept = '.zip';
$scope.dropAreaTitle = 'Import Projects';
$scope.dropAreaSubtitle = 'Drop zip file(s) here, or use the "+" button.';
$scope.dropAreaMore = '';
$scope.uploadPath = '';
$scope.queueLength = 100;
$scope.uploader = new FileUploader({
url: projectImportUrl
});
importView.controller('ImportViewController', ($scope, $window, ViewParameters, WorkspaceService, TransportService, FileUploader, StatusBar, Workspace, Repository) => {
const projectImportUrl = TransportService.getProjectImportUrl();
const fileImportUrl = TransportService.getFileImportUrl();
const zipImportUrl = TransportService.getZipImportUrl();
$scope.selectedWorkspace = WorkspaceService.getCurrentWorkspace();
$scope.workspaceNames = [];
$scope.projectsViewId = undefined;
$scope.inDialog = false;
$scope.importRepository = false;
$scope.inputAccept = '.zip';
$scope.dropAreaTitle = 'Import Projects';
$scope.dropAreaSubtitle = 'Drop zip file(s) here, or use the "+" button.';
$scope.dropAreaMore = '';
$scope.uploadPath = '';
$scope.queueLength = 100;
$scope.uploader = new FileUploader({
url: projectImportUrl
});

$scope.initImport = () => {
let params = ViewParameters.get();
if (params.container === 'window') {
$scope.inDialog = true;
if (params.importRepository) {
$scope.importRepository = true;
$scope.queueLength = 1;
$scope.uploader.url = TransportService.getSnapshotUrl();
$scope.dropAreaTitle = 'Import repository from zip';
$scope.dropAreaSubtitle = 'Drop snaphot here, or use the "+" button.';
$scope.initImport = () => {
let params = ViewParameters.get();
if (params.container === 'window') {
$scope.inDialog = true;
if (params.importRepository) {
$scope.importRepository = true;
$scope.queueLength = 1;
$scope.uploader.url = TransportService.getSnapshotUrl();
$scope.dropAreaTitle = 'Import repository from zip';
$scope.dropAreaSubtitle = 'Drop snaphot here, or use the "+" button.';
} else {
$scope.uploadPath = params.uploadPath;
if (params.workspace) $scope.selectedWorkspace = params.workspace;
if (params.importType === 'file') {
$scope.inputAccept = '';
$scope.importType = params.importType;
$scope.dropAreaTitle = 'Import files';
$scope.dropAreaSubtitle = 'Drop file(s) here, or use the "+" button.';
$scope.dropAreaMore = `Files will be imported in "${params.uploadPath}"`;
} else if (params.importType === 'data') {
$scope.inputAccept = 'csv';
$scope.importType = params.importType;
$scope.dropAreaTitle = 'Import data files';
$scope.dropAreaSubtitle = 'Drop file(s) here, or use the "+" button.';
$scope.dropAreaMore = `Files will be imported in "${params.table}"`;
} else if (params.importType === 'sql') {
$scope.inputAccept = 'sql';
$scope.importType = params.importType;
$scope.dropAreaTitle = 'Import SQL files';
$scope.dropAreaSubtitle = 'Drop file(s) here, or use the "+" button.';
$scope.dropAreaMore = `Files will be imported in "${params.schema}"`;
} else {
$scope.uploadPath = params.uploadPath;
if (params.workspace) $scope.selectedWorkspace = params.workspace;
if (params.importType === 'file') {
$scope.inputAccept = '';
$scope.importType = params.importType;
$scope.dropAreaTitle = 'Import files';
$scope.dropAreaSubtitle = 'Drop file(s) here, or use the "+" button.';
$scope.dropAreaMore = `Files will be imported in "${params.uploadPath}"`;
} if (params.importType === 'data') {
$scope.inputAccept = 'csv';
$scope.importType = params.importType;
$scope.dropAreaTitle = 'Import data files';
$scope.dropAreaSubtitle = 'Drop file(s) here, or use the "+" button.';
$scope.dropAreaMore = `Files will be imported in "${params.table}"`;
} else {
$scope.dropAreaTitle = 'Import files from zip';
$scope.dropAreaMore = `Files will be extracted in "${params.uploadPath}"`;
let pathSegments = params.uploadPath.split('/');
$scope.uploader.url = UriBuilder().path(TransportService.getZipImportUrl().split('/')).path(pathSegments).build();
if (pathSegments.length <= 2) $scope.uploader.url += '/%252F';
}
$scope.dropAreaTitle = 'Import files from zip';
$scope.dropAreaMore = `Files will be extracted in "${params.uploadPath}"`;
let pathSegments = params.uploadPath.split('/');
$scope.uploader.url = UriBuilder().path(zipImportUrl.split('/')).path(pathSegments).build();
if (pathSegments.length <= 2) $scope.uploader.url += '/%252F';
}
$scope.projectsViewId = params.projectsViewId;
} else $scope.reloadWorkspaceList();
}

$scope.uploader.filters.push({
name: 'customFilter',
fn: function (item /*{File|FileLikeObject}*/, _options) {
let type = item.type.slice(item.type.lastIndexOf('/') + 1);
if ($scope.importType !== 'file' && $scope.importType !== 'data')
if (type != 'zip' && type != 'x-zip' && type != 'x-zip-compressed') {
return false;
}
return this.queue.length < $scope.queueLength;
}
});
$scope.projectsViewId = params.projectsViewId;
} else $scope.reloadWorkspaceList();
}

$scope.uploader.onBeforeUploadItem = (item) => {
if (!$scope.importRepository) {
if (!$scope.inDialog) {
item.url = UriBuilder().path(projectImportUrl.split('/')).path($scope.selectedWorkspace).build();
} else if ($scope.inDialog && $scope.importType === 'file') {
item.headers = {
'Dirigible-Editor': 'Editor'
};
item.url = UriBuilder().path(TransportService.getFileImportUrl().split('/')).path($scope.uploadPath.split('/')).path(item.name).build();
} else if ($scope.inDialog && $scope.importType === 'data') {
item.headers = { 'Dirigible-Editor': 'Editor' };
item.url = UriBuilder().path($scope.uploadPath.split('/')).path(item.name).build();
} else {
item.url = UriBuilder().path(TransportService.getZipImportUrl().split('/')).path($scope.uploadPath.split('/')).build();
$scope.uploader.filters.push({
name: 'customFilter',
fn: function (item /*{File|FileLikeObject}*/, _options) {
let type = item.type.slice(item.type.lastIndexOf('/') + 1);
if ($scope.importType !== 'file' && $scope.importType !== 'data' && $scope.importType !== 'sql')
if (type != 'zip' && type != 'x-zip' && type != 'x-zip-compressed') {
return false;
}
}
};
return this.queue.length < $scope.queueLength;
}
});

$scope.uploader.onCompleteAll = () => {
if ($scope.importRepository) {
Repository.announceRepositoryModified();
} else if ($scope.inDialog) {
// Temporary, publishes all files in the import directory, not just imported ones
Workspace.announceWorkspaceChanged({
workspace: $scope.selectedWorkspace,
params: {
projectsViewId: $scope.projectsViewId,
publish: { path: $scope.uploadPath }
}
});
$scope.uploader.onBeforeUploadItem = (item) => {
if (!$scope.importRepository) {
if (!$scope.inDialog) {
item.url = UriBuilder().path(projectImportUrl.split('/')).path($scope.selectedWorkspace).build();
} else if ($scope.inDialog && $scope.importType === 'file') {
item.headers = {
'Dirigible-Editor': 'Editor'
};
item.url = UriBuilder().path(fileImportUrl.split('/')).path($scope.uploadPath.split('/')).path(item.name).build();
} else if ($scope.inDialog && ($scope.importType === 'data' || $scope.importType === 'sql')) {
item.headers = { 'Dirigible-Editor': 'Editor' };
item.url = UriBuilder().path($scope.uploadPath.split('/')).path(item.name).build();
} else {
Workspace.announceWorkspaceChanged({ workspace: $scope.selectedWorkspace, params: { publish: { workspace: true } } });
item.url = UriBuilder().path(zipImportUrl.split('/')).path($scope.uploadPath.split('/')).build();
}
};
}
};

$scope.isSelectedWorkspace = (name) => $scope.selectedWorkspace === name;
$scope.uploader.onCompleteAll = () => {
if ($scope.importRepository) {
Repository.announceRepositoryModified();
} else if ($scope.inDialog) {
// Temporary, publishes all files in the import directory, not just imported ones
Workspace.announceWorkspaceChanged({
workspace: $scope.selectedWorkspace,
params: {
projectsViewId: $scope.projectsViewId,
publish: { path: $scope.uploadPath }
}
});
} else {
Workspace.announceWorkspaceChanged({ workspace: $scope.selectedWorkspace, params: { publish: { workspace: true } } });
}
};

$scope.isUploadEnabled = () => {
if ($scope.uploader.getNotUploadedItems().length) return false;
return true;
};
$scope.isSelectedWorkspace = (name) => $scope.selectedWorkspace === name;

$scope.addFiles = () => {
$window.document.getElementById('input').click();
};
$scope.isUploadEnabled = () => {
if ($scope.uploader.getNotUploadedItems().length) return false;
return true;
};

$scope.switchWorkspace = (workspace) => {
if ($scope.selectedWorkspace !== workspace) {
$scope.selectedWorkspace = workspace;
}
};
$scope.addFiles = () => {
$window.document.getElementById('input').click();
};

$scope.reloadWorkspaceList = () => {
WorkspaceService.listWorkspaceNames().then((response) => {
$scope.$evalAsync(() => {
$scope.workspaceNames = response.data;
if (!$scope.workspaceNames.includes($scope.selectedWorkspace))
$scope.selectedWorkspace = 'workspace'; // Default
});
}, (response) => {
console.error(response);
StatusBar.showError('Unable to load workspace list');
$scope.switchWorkspace = (workspace) => {
if ($scope.selectedWorkspace !== workspace) {
$scope.selectedWorkspace = workspace;
}
};

$scope.reloadWorkspaceList = () => {
WorkspaceService.listWorkspaceNames().then((response) => {
$scope.$evalAsync(() => {
$scope.workspaceNames = response.data;
if (!$scope.workspaceNames.includes($scope.selectedWorkspace))
$scope.selectedWorkspace = 'workspace'; // Default
});
};
}, (response) => {
console.error(response);
StatusBar.showError('Unable to load workspace list');
});
};

const workspaceCreatedListener = Workspace.onWorkspaceCreated($scope.reloadWorkspaceList);
const workspaceDeletedListener = Workspace.onWorkspaceDeleted($scope.reloadWorkspaceList);
const workspaceCreatedListener = Workspace.onWorkspaceCreated($scope.reloadWorkspaceList);
const workspaceDeletedListener = Workspace.onWorkspaceDeleted($scope.reloadWorkspaceList);

// Initialization
$scope.initImport();
// Initialization
$scope.initImport();

$scope.$on('$destroy', () => {
Workspace.removeMessageListener(workspaceCreatedListener);
Workspace.removeMessageListener(workspaceDeletedListener);
});
});
$scope.$on('$destroy', () => {
Workspace.removeMessageListener(workspaceCreatedListener);
Workspace.removeMessageListener(workspaceDeletedListener);
});
});
Loading

0 comments on commit db4883e

Please sign in to comment.