Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Commit

Permalink
fix(files): seperate directives for dl & slicing
Browse files Browse the repository at this point in the history
  • Loading branch information
Christine Yu committed Nov 23, 2015
1 parent 1817704 commit d6c4dde
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 34 deletions.
114 changes: 81 additions & 33 deletions app/scripts/files/files.directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,39 +29,86 @@ module ngApp.files.directives {
$scope.active = false;
$element.removeAttr("disabled");
};
if ($scope.copy === "Download") {
FilesService.downloadFiles(_.pluck(files, "file_id"), (complete)=>{
if(complete){
turnSpinnerOff();
} else {
//Download Failed
turnSpinnerOff();
}
});
} else {
var bamModal = $modal.open({
templateUrl: "files/templates/bam-slicing.html",
controller: "BAMSlicingController",
controllerAs: "bamc",
backdrop: true,
keyboard: true,
animation: false,
size: "lg",
resolve: {
fileID: function () {
return _.first(_.pluck(files, "file_id"));
},
completeCallback: function() {
return turnSpinnerOff;
}
}
});
bamModal.result.then(turnSpinnerOff, function(reason) {
if (reason !== 'slicing') {
turnSpinnerOff();
FilesService.downloadFiles(_.pluck(files, "file_id"), (complete)=>{
if(complete){
turnSpinnerOff();
} else {
//Download Failed
turnSpinnerOff();
}
});
} else {
var template = UserService.currentUser ?
"core/templates/request-access-to-download-single.html" :
"core/templates/login-to-download-single.html";

$log.log("File not authorized.");
$modal.open({
templateUrl: template,
controller: "LoginToDownloadController",
controllerAs: "wc",
backdrop: true,
keyboard: true,
animation: false,
size: "lg"
});
}
});
}
}
}

function BAMSlicingButton($log: ng.ILogService, FilesService, UserService, $modal): ng.IDirective {
return {
restrict: "E",
replace: true,
scope: {
files:"=",
copy: "@",
dlcopy: "@",
classes: "@",
icon: "@"
},
template: "<a ng-class=\"[classes || 'btn btn-primary']\">" +
"<i class=\"fa {{icon || 'fa-download'}}\" ng-class=\"{'fa-spinner': active, 'fa-pulse': active}\"></i>" +
"<span ng-if=\"copy\"><span ng-if=\"!active\">&nbsp;{{copy}}</span><span ng-if=\"active\">&nbsp;{{dlcopy}}</span></span></a>",
link: function($scope, $element, $attrs){
var files = $scope.files;
$scope.active = false;
$element.on("click", function(a) {

if (!_.isArray(files)) {
files = [files];
}
if (UserService.userCanDownloadFiles(files)) {
$scope.active = true;
$attrs.$set("disabled", "disabled");
var turnSpinnerOff = function() {
$scope.active = false;
$element.removeAttr("disabled");
};
var bamModal = $modal.open({
templateUrl: "files/templates/bam-slicing.html",
controller: "BAMSlicingController",
controllerAs: "bamc",
backdrop: true,
keyboard: true,
animation: false,
size: "lg",
resolve: {
fileID: function () {
return _.first(_.pluck(files, "file_id"));
},
completeCallback: function() {
return turnSpinnerOff;
}
});
}
}
});
bamModal.result.then(turnSpinnerOff, function(reason) {
if (reason !== 'slicing') {
turnSpinnerOff();
}
});
} else {
var template = UserService.currentUser ?
"core/templates/request-access-to-download-single.html" :
Expand All @@ -85,5 +132,6 @@ module ngApp.files.directives {

angular
.module("files.directives", ["restangular", "components.location", "user.services", "core.services", "ui.bootstrap", "files.controller"])
.directive("downloadButton", DownloadButton);
.directive("downloadButton", DownloadButton)
.directive("bamSlicingButton", BAMSlicingButton);
}
2 changes: 1 addition & 1 deletion app/scripts/files/templates/file.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ <h1 class="col-lg-12 col-md-12">
<span data-ng-if="!fc.isInCart(fc.file.file_id)" data-translate>Add to Cart</span>
</button>
<download-button data-icon="fa-download" data-files=fc.file data-copy="Download" data-dlcopy="Downloading"></download-button>
<download-button data-icon="fa-cutlery" data-files=fc.file data-copy="BAM Slicing" data-dlcopy="Slicing BAM" data-ng-if="fc.canBAMSlice()"></download-button>
<bam-slicing-button data-icon="fa-cutlery" data-files=fc.file data-copy="BAM Slicing" data-dlcopy="Slicing BAM" data-ng-if="fc.canBAMSlice()"></download-button>
</span>
</h1>
</div>
Expand Down

0 comments on commit d6c4dde

Please sign in to comment.