Skip to content

Commit

Permalink
Merge pull request #1668 from dimitarquanterall/fix-672-xsk-issue
Browse files Browse the repository at this point in the history
Fix #672 from XSK issues
  • Loading branch information
ThuF authored Mar 29, 2022
2 parents 331fe96 + b31acd6 commit 3484f77
Show file tree
Hide file tree
Showing 2 changed files with 176 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
<script type="text/javascript" src="/webjars/angularjs/1.8.2/angular-animate.min.js"></script>
<script type="text/javascript" src="/webjars/angularjs/1.8.2/angular-sanitize.min.js"></script>

<script type="text/javascript" src="js/angular-file-upload.min.js"></script>

<!-- jsTree -->
<link href="/services/v4/js/theme/resources.js/jstree.css" rel="stylesheet">
<script type="text/javascript" src="/webjars/jstree/3.3.12/jstree.min.js"></script>
Expand Down Expand Up @@ -77,6 +79,8 @@
data-target="#dialogGenerateFromModel"></button>
<button type="button" id="uploadFile" ng-show="false" data-toggle="modal"
data-target="#dialogUploadFile"></button>
<button type="button" id="uploadZipToFolder" ng-show="false" data-toggle="modal"
data-target="#dialogUploadZipToFolder"></button>
<button type="button" id="resolveConflicts" ng-show="false" data-toggle="modal"
data-target="#dialogResolveConflicts"></button>

Expand Down Expand Up @@ -313,6 +317,84 @@ <h4>Upload File</h4>
</div>
</div>

<!-- Import in folder from ZIP -->
<div class="dirigible-modal modal fade" id="dialogUploadZipToFolder" tabindex="-1" role="dialog"
aria-labelledby="dialogUploadZipToFolderLabel" aria-hidden="true">
<div class="modal-header">
<h4>Import files from ZIP</h4>
</div>
<div class="modal-body">
<div class="row">
<P>Import to project: <strong>{{projectName}}</strong><br>
Extract to path: <strong>{{pathToImportIn}}</strong></p>
</div>
<div class="row" nv-file-drop="" uploader="uploader" filters="queueLimit, customFilter">
<div class="row">
<div class="col-md-9">
<div ng-show="uploader.isHTML5">
<!-- 3. nv-file-over uploader="link" over-class="className" -->
<div class="well my-drop-zone" nv-file-over="" uploader="uploader">
Drop *.zip file(s) here
</div>
</div>
<!-- Example: nv-file-select="" uploader="{Object}" options="{Object}" filters="{String}" -->
or browse your file system
<input type="file" nv-file-select="" uploader="uploader" /><br />
</div>
</div>
<div class="col-md-12" style="margin-bottom: 40px">
<h3>Upload queue</h3>
<p>Queue length: {{ uploader.queue.length }}</p>
<table class="table">
<thead>
<tr>
<th width="50%">Name &amp; size</th>
<th ng-show="uploader.isHTML5">Progress</th>
<th ng-show="uploader.isHTML5">Remove</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in uploader.queue">
<td><strong>{{ item.file.name }}</strong><br>{{ item.file.size/1024/1024|number:2 }}
MB
</td>
<td ng-show="uploader.isHTML5">
<div class="progress" style="margin-bottom: 0;">
<div class="progress-bar" role="progressbar"
ng-style="{ 'width': item.progress + '%' }"></div>
</div>
</td>
<td nowrap>
<button type="button" class="btn btn-danger btn-xs" ng-click="item.remove()">
<span class="fa fa-trash"></span> Remove
</button>
</td>
</tr>
</tbody>
</table>
<div>
<div>
Queue progress:
<div class="progress" style="">
<div class="progress-bar" role="progressbar"
ng-style="{ 'width': uploader.progress + '%' }"></div>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<!--
data-toggle="modal" data-target="#dialogUploadZipToFolder" -->
<button class="btn btn-primary"
ng-click="workspace.okUploadZipFiles(uploader, projectName, pathToImportIn)"
ng-disabled="!uploader.getNotUploadedItems().length">Upload and extract</button>
<button class="btn btn-default" data-dismiss="modal"
ng-click="workspace.cancelImportFromZip(uploader)">Cancel</button>
</div>
</div>
</div>

<!-- Delete -->
<div class="dirigible-modal modal fade" id="dialogDelete" tabindex="-1" role="dialog"
aria-labelledby="dialogDeleteLabel" aria-hidden="true">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ let pasteObject = {
canPaste: false,
type: "#"
};
let uploader = null;
/**
* Utility URL builder
*/
Expand Down Expand Up @@ -487,11 +488,15 @@ WorkspaceTreeAdapter.prototype.init = function (containerEl, workspaceController
.on('jstree.workspace.paste', function (e, data) {
this.paste(data);
}.bind(this))
.on('jstree.workspace.uploadZipToFolder', function (e, data) {
this.uploadZipToFolder(data, scope);
}.bind(this))
.on('jstree.workspace.delete', function (e, data) {
this.workspaceController.showDeleteDialog(this.workspaceController.selectedNodeData.length == 1
? this.workspaceController.selectedNodeData[0].type :
this.workspaceController.selectedNodeData.length + ' file nodes');
}.bind(this));
}.bind(this))
;

this.jstree = $.jstree.reference(jstree);
return this;
Expand Down Expand Up @@ -761,8 +766,10 @@ WorkspaceTreeAdapter.prototype.unpublish = function (resource) {
}.bind(this));
};
WorkspaceTreeAdapter.prototype.exportProject = function (resource) {
if (resource.type === 'project') {
return this.exportService.exportProject(resource.path);
if (resource.type === 'project' || resource.type == 'folder') {
let segments = resource.path.split('/');
let callExportPath = segments.slice(0, 3).join("/") + '/' + encodeURIComponent(segments.slice(3).join("/"));
return this.exportService.exportProject(callExportPath);
}
};
WorkspaceTreeAdapter.prototype.generateFile = function (resource, scope) {
Expand Down Expand Up @@ -790,6 +797,16 @@ WorkspaceTreeAdapter.prototype.uploadFileInPlace = function (resource, scope) {
}
};

WorkspaceTreeAdapter.prototype.uploadZipToFolder = function (resource, scope) {
let segments = resource.path.split('/');
this.workspaceController.projectName = segments[2];
let relativePath = '/';
if (resource.type == "folder") {
relativePath = this.removeKnownRoot([resource], "/" + this.workspaceController.selectedWorkspace + "/" + this.workspaceController.projectName)[0].norootpath;
}
this.workspaceController.showImportFromZipDialog(this.workspaceController.selectedWorkspace, this.workspaceController.projectName, relativePath);
};

let TemplatesService = function ($http, $window, TEMPLATES_SVC_URL) {
this.$http = $http;
this.$window = $window;
Expand All @@ -808,7 +825,7 @@ angular.module('workspace.config', [])
.constant('TEMPLATES_SVC_URL', '/services/v4/js/ide-core/services/templates.js')
.constant('GENERATION_SVC_URL', '/services/v4/ide/generate');

angular.module('workspace', ['workspace.config', 'ideUiCore', 'ngAnimate', 'ngSanitize', 'ui.bootstrap'])
angular.module('workspace', ['workspace.config', 'ideUiCore', 'ngAnimate', 'ngSanitize', 'ui.bootstrap', 'angularFileUpload'])
.factory('httpRequestInterceptor', function () {
let csrfToken = null;
return {
Expand Down Expand Up @@ -1227,7 +1244,20 @@ angular.module('workspace', ['workspace.config', 'ideUiCore', 'ngAnimate', 'ngSa
};
}

if (this.get_type(node) === "project") {
if (this.get_type(node) === "folder" || this.get_type(node) == "project") {
/*Import from zip*/
ctxmenu.uploadZipToFolder = {
"separator_before": true,
"label": "Import files from ZIP",
"action": function (data) {
let tree = $.jstree.reference(data.reference);
let node = tree.get_node(data.reference);
tree.element.trigger('jstree.workspace.uploadZipToFolder', [node.original._file]);
}.bind(this)
};
}

if (this.get_type(node) === "project" || this.get_type(node) === "folder") {
/*Export*/
ctxmenu.exportProject = {
"separator_before": true,
Expand Down Expand Up @@ -1304,11 +1334,10 @@ angular.module('workspace', ['workspace.config', 'ideUiCore', 'ngAnimate', 'ngSa
.factory('workspaceTreeAdapter', ['$treeConfig', 'workspaceService', 'publishService', 'exportService', 'messageHub', function ($treeConfig, WorkspaceService, publishService, exportService, messageHub) {
return new WorkspaceTreeAdapter($treeConfig, WorkspaceService, publishService, exportService, messageHub);
}])
.controller('WorkspaceController', ['workspaceService', 'workspaceTreeAdapter', 'publishService', 'exportService', 'templatesService', 'generationService', 'messageHub', '$scope', function (workspaceService, workspaceTreeAdapter, publishService, exportService, templatesService, generationService, messageHub, $scope) {
.controller('WorkspaceController', ['workspaceService', 'FileUploader', 'workspaceTreeAdapter', 'publishService', 'exportService', 'templatesService', 'generationService', 'messageHub', '$scope', function (workspaceService, FileUploader, workspaceTreeAdapter, publishService, exportService, templatesService, generationService, messageHub, $scope) {
$scope.selectedNodeType = "";
this.wsTree;
this.workspaces;
this.selectedWorkspace;
this.selectedTemplate;
this.workspaceService = workspaceService;
this.unpublishOnDelete = true;
Expand All @@ -1318,6 +1347,55 @@ angular.module('workspace', ['workspace.config', 'ideUiCore', 'ngAnimate', 'ngSa
$scope.resolvedConflicts = [];
$scope.copyWhich = [];
$scope.copyTo = {};
$scope.projectName = '';
$scope.pathToImportIn = '';

$scope.TRANSPORT_PROJECT_URL = "/services/v4/transport/project";
$scope.TRANSPORT_ZIPTOFOLDER_URL = "/services/v4/transport/zipimport";

// FILE UPLOADER
$scope.uploader = uploader = new FileUploader({
url: $scope.TRANSPORT_ZIPTOFOLDER_URL,
removeAfterUpload: true
});

// UPLOADER FILTERS
uploader.filters.push({
name: 'customFilter',
fn: function (item /*{File|FileLikeObject}*/, options) {
return this.queue.length < 100;
}
});

// UPLOADER CALLBACKS

uploader.onWhenAddingFileFailed = function (item /*{File|FileLikeObject}*/, filter, options) {
console.info('onWhenAddingFileFailed', item, filter, options);
};
uploader.onBeforeUploadItem = function (item) {
let internalPath = $scope.pathToImportIn;
let pathSegments = [$scope.selectedWorkspace, $scope.projectName, encodeURIComponent(internalPath)];
let buildPath = new UriBuilder();
buildPath.path(pathSegments)
item.url = $scope.TRANSPORT_ZIPTOFOLDER_URL + buildPath.build();
$scope.uploader.url = item.url;
};
uploader.onCompleteAll = function () {
this.clearQueue();
$('#uploadZipToFolder').click();
$('#refreshButton').click();
};

this.cancelImportFromZip = function (uploader) {
if (uploader.isUploading) {
uploader.cancelAll();
}
uploader.clearQueue();
}

this.okUploadZipFiles = function (uploader) {
uploader.uploadAll();
}

this.showDeleteDialog = function (type) {
this.unpublishOnDelete = true;
Expand All @@ -1334,7 +1412,15 @@ angular.module('workspace', ['workspace.config', 'ideUiCore', 'ngAnimate', 'ngSa
$scope.copyNode = copyNode;
$scope.$apply(); // Because of JQuery and the bootstrap modal
$('#resolveConflicts').click();
};
}

this.showImportFromZipDialog = function (workspace, project, pathToImportIn) {
$scope.selectedWorkspace = workspace;
$scope.projectName = project;
$scope.pathToImportIn = pathToImportIn;
$scope.$apply(); // Because of JQuery and the bootstrap modal
$('#uploadZipToFolder').click();
}

this.resolveConflict = function (resolution) {
let startRange = $scope.resolvedConflicts.length;
Expand Down

0 comments on commit 3484f77

Please sign in to comment.