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

Commit

Permalink
fix(cart): add all to cart uses my projects filter
Browse files Browse the repository at this point in the history
- add all in summary works again
Closes #236
  • Loading branch information
Christine Yu committed Feb 3, 2015
1 parent 0185e7b commit c720a8b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
12 changes: 9 additions & 3 deletions app/scripts/cart/cart.directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@ module ngApp.cart.directives {
scope:{
paging: "=",
files: "=",
removeAllInSearchResult: "&"
removeAllInSearchResult: "&",
addAllOnly: "@"
},
compile: function(element, attrs) {
if(!attrs.addAllOnly)
attrs.addAllOnly = false;
},
templateUrl: "cart/templates/add-to-cart-button-all.html",
controller: function($scope: ng.IScope, CartService: ICartService, LocationService: ILocationService,
FilesService: IFilesService) {
FilesService: IFilesService, UserService: IUserService) {

$scope.CartService = CartService;
$scope.addToCart = function(files: IFile[]) {
Expand Down Expand Up @@ -76,7 +81,8 @@ module ngApp.cart.directives {

$scope.addAll = function(){
var filters = LocationService.filters();
var size: number = ($scope.paging.total >= this.CartService.getMaxSize()) ? this.CartService.getMaxSize() : this.paging.total;
filters = UserService.addMyProjectsFilter(filters, "participants.admin.disease_code");
var size: number = ($scope.paging.total >= CartService.getMaxSize()) ? CartService.getMaxSize() : $scope.paging.total;
FilesService.getFiles({
fields: [
"data_access",
Expand Down
18 changes: 17 additions & 1 deletion app/scripts/cart/templates/add-to-cart-button-all.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="btn-group" data-dropdown>
<div data-ng-if="!addAllOnly" class="btn-group" data-dropdown>
<button data-ng-if="CartService.areInCart(files)" type="button" class="btn btn-success" disabled>
<i class="fa fa-check-circle"></i>
</button>
Expand Down Expand Up @@ -43,3 +43,19 @@
</li>
</ul>
</div>
<div data-ng-if="addAllOnly">
<button class="btn btn-primary disabled" data-ng-if="CartService.getCartVacancySize() - paging.total < 0" disabled="disabled">
<span class="fa-stack">
<i class="fa fa-shopping-cart fa-stack-1x"></i>
<i class="fa fa-ban fa-stack-2x"></i>
</span>
<span data-translate>Cart can only hold {{ CartService.getCartVacancySize() }} more items</span>
</button>
<button class="btn btn-primary" data-ng-click="addAll()" data-ng-if="CartService.getCartVacancySize() - paging.total >= 0">
<span class="fa-stack">
<i class="fa fa-shopping-cart fa-stack-1x"></i>
</span>
<span data-translate>Add all in Search Result</span>
</button>

</div>
5 changes: 3 additions & 2 deletions app/scripts/components/user/user.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module ngApp.components.user.services {
login(username: string): void;
logout(): void;
toggleFilter(): void;
addMyProjectsFilter(filters: any, key: string): void;
addMyProjectsFilter(filters: any, key: string): any;
isUserProject(file: IFile): boolean;
currentUser: IUser;
}
Expand Down Expand Up @@ -46,7 +46,7 @@ module ngApp.components.user.services {
return this.currentUser.projects.indexOf(file.archive.disease_code) !== -1;
}

addMyProjectsFilter(filters: any, key: string): void {
addMyProjectsFilter(filters: any, key: string): any {
if (this.currentUser && this.currentUser.isFiltered &&
this.currentUser.projects.length) {
var userProjects = {
Expand Down Expand Up @@ -88,6 +88,7 @@ module ngApp.components.user.services {

return filters;
}

}

angular
Expand Down
17 changes: 2 additions & 15 deletions app/scripts/search/templates/search.summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,6 @@ <h2>Summary</h2>
</tbody>
</table>

<button class="btn btn-primary disabled" data-ng-if="sc.CartService.getCartVacancySize() - sc.files.pagination.total < 0" disabled="disabled">
<span class="fa-stack">
<i class="fa fa-shopping-cart fa-stack-1x"></i>
<i class="fa fa-ban fa-stack-2x"></i>
</span>
<span data-translate>Cart can only hold {{ sc.CartService.getCartVacancySize() }} more items</span>
</button>
<button class="btn btn-primary" data-ng-click="sc.addAll()" data-ng-if="sc.CartService.getCartVacancySize() - sc.files.pagination.total >= 0">
<span class="fa-stack">
<i class="fa fa-shopping-cart fa-stack-1x"></i>
</span>
<span data-translate>Add all in Search Result</span>
</button>
<div add-to-cart-all data-files="sc.files" data-paging="sc.files.pagination" data-add-all-only=true></div>


</div>
</div>

0 comments on commit c720a8b

Please sign in to comment.