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

Commit

Permalink
feat(cart): Cart page uses table directive.
Browse files Browse the repository at this point in the history
- Adds additional directives for file actions in prep for
  tableicious table config.
- Cleans up other code around other directives.
- Replaces static table with gdc-table/tableicious.
- Layout/style updates.

Closes #668
  • Loading branch information
Matthew Schranz committed Apr 1, 2015
1 parent 25aee1c commit 3791a80
Show file tree
Hide file tree
Showing 19 changed files with 514 additions and 319 deletions.
83 changes: 22 additions & 61 deletions app/scripts/cart/cart.controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ module ngApp.cart.controllers {
selectedSize(): number;
getTotalSize(): number;
removeSelected(): void;
remove(id: string): void;
selectAll(): void;
deselectAll(): void;
all(): boolean;
isUserProject(file: IFile): boolean;
getFileIds(): string[];
getRelatedFileIds(): string[];
processPaging: boolean;
Expand All @@ -41,10 +36,12 @@ module ngApp.cart.controllers {
private CoreService: ICoreService,
private CartService: ICartService,
private UserService: IUserService,
private CartTableModel,
private Restangular,
private FilesService) {
CoreService.setPageTitle("Cart", "(" + this.files.length + ")");
this.lastModified = this.CartService.lastModified;
this.cartTableConfig = CartTableModel;

this.pagination = {
from: 1,
Expand All @@ -61,8 +58,8 @@ module ngApp.cart.controllers {
$scope.$on("gdc-user-reset", () => {
this.files = CartService.getFiles();
this.setDisplayedFiles();

});

$scope.$on("cart-paging-update", (event: any, newPaging: any) => {
this.setDisplayedFiles(newPaging);
});
Expand All @@ -72,9 +69,10 @@ module ngApp.cart.controllers {

});

$scope.$on("cart.update",()=>{
$scope.$on("cart.update", () => {
this.lastModified = this.CartService.lastModified;
this.setDisplayedFiles();
})
});

}

Expand Down Expand Up @@ -132,12 +130,6 @@ module ngApp.cart.controllers {
}, 0);
}

remove(id: string) {
this.CartService.remove([id]);
this.lastModified = this.CartService.lastModified;
this.setDisplayedFiles();
}

removeAll() {
this.CartService.removeAll();
this.lastModified = this.CartService.lastModified;
Expand All @@ -151,75 +143,44 @@ module ngApp.cart.controllers {
this.setDisplayedFiles();
}

selectAll(visibleOnly): void {

var visible = this.getVisible();
var iteratee = visibleOnly ? visible : this.files;
_.each(iteratee,(file: IFile): void => {
file.selected = true;
});
}

getVisible(): any[] {
var p = this.pagination;
var visible = this.files.slice(p.from-1, p.from+p.count-1);
return visible;

}

deselectAll(visibleOnly): void {
var visible = this.getVisible();
var iteratee = visibleOnly ? visible : this.files;
_.each(iteratee,(file: IFile): void => {
file.selected = false;
});
}

all(visibleOnly): boolean {
var visible = this.getVisible();
var iteratee = visibleOnly ? visible : this.files;
// var iteratee =
return _.every(iteratee, {selected: true});
}

isUserProject(file: IFile): boolean {
return this.UserService.isUserProject(file);
}

getManifest() {
var authorizedInCart = this.CartService.getAuthorizedFiles().filter(function isSelected(a){return a.selected});
var authorizedInCart = this.CartService.getAuthorizedFiles()
.filter(function isSelected(a) {
return a.selected;
});

var file_ids = [];
_.forEach(authorizedInCart, (f) => {

if (f.hasOwnProperty('related_ids') && f.related_ids) {
file_ids = file_ids.concat(f.related_ids)
}
file_ids.push(f.file_id)
});

this.FilesService.downloadManifest(file_ids);

}

}

class LoginToDownloadController {

constructor (private $modalInstance) {}

cancel() :void {
this.$modalInstance.close(false);
}
cancel() :void {
this.$modalInstance.close(false);
}

goAuth() :void {
this.$modalInstance.close(true);
}
goAuth() :void {
this.$modalInstance.close(true);
}
}


angular
.module("cart.controller", ["cart.services", "core.services", "user.services"])
.module("cart.controller", [
"cart.services",
"core.services",
"user.services",
"cart.table.model"
])
.controller("LoginToDownloadController", LoginToDownloadController )
.controller("CartController", CartController);
}
Expand Down
82 changes: 81 additions & 1 deletion app/scripts/cart/cart.directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,80 @@ module ngApp.cart.directives {
removeFromCart(files: IFile[]): void;
}

function SelectAllCart(): ng.IDirective {
return {
restrict: "AE",
replace: true,
scope: {
paging: "="
},
templateUrl: "cart/templates/select-all.html",
controller: function($scope, CartService: ICartService) {
$scope.files = CartService.getFiles();

function getVisible() {
var p = $scope.paging;
var visible = $scope.files.slice(p.from - 1, p.from + p.count - 1);
return visible;
}

$scope.CartService = CartService;
$scope.selectAll = function(visibleOnly) {
var visible = getVisible();
var iteratee = visibleOnly ? visible : $scope.files;
_.each(iteratee,(file: IFile): void => {
file.selected = true;
});
};

$scope.deselectAll = function(visibleOnly) {
var visible = getVisible();
var iteratee = visibleOnly ? visible : $scope.files;
_.each(iteratee, (file: IFile): void => {
file.selected = false;
});
};

$scope.all = function(visibleOnly) {
var visible = getVisible();
var iteratee = visibleOnly ? visible : $scope.files;
return _.every(iteratee, {selected: true});
};
}
}
}

function SelectSingleCart(): ng.IDirective {
return {
restrict: "AE",
replace: true,
scope: {
file: "="
},
templateUrl: "cart/templates/select-single.html",
controller: function($scope, CartService) {
$scope.CartService = CartService;
}
};
}

function RemoveSingleCart(): ng.IDirective {
return {
restrict: "A",
replace: true,
scope: {
file: "="
},
templateUrl: "cart/templates/remove-single.html",
controller: function($scope, CartService: ICartService) {
$scope.remove = function(id: string) {
CartService.remove([id]);
$scope.$emit("cart-update");
}
}
};
}

function AddToCartSingle(): ng.IDirective {
return {
restrict: "AE",
Expand Down Expand Up @@ -93,6 +167,7 @@ module ngApp.cart.directives {
var size: number = ($scope.paging.total >= CartService.getMaxSize()) ? CartService.getMaxSize() : $scope.paging.total;
FilesService.getFiles({
fields: SearchTableFilesModel.fields,
expand: SearchTableFilesModel.expand,
filters: filters,
size: size,
from: 0
Expand Down Expand Up @@ -241,6 +316,7 @@ module ngApp.cart.directives {

FilesService.getFiles({
fields: SearchTableFilesModel.fields,
expand: SearchTableFilesModel.expand,
filters: filters,
size: CartService.getCartVacancySize()
}).then((data) => {
Expand All @@ -267,6 +343,7 @@ module ngApp.cart.directives {
};
FilesService.getFiles({
fields: SearchTableFilesModel.fields,
expand: SearchTableFilesModel.expand,
filters: filters,
size: CartService.getCartVacancySize()
}).then((data) => {
Expand Down Expand Up @@ -348,6 +425,9 @@ module ngApp.cart.directives {
.directive("addToCartFiltered", AddToCartFiltered)
.directive("downloadButtonAllCart", DownloadButtonAllCart)
.directive("cartDisplayingPieChart", CartDisplayingPieChart)
.directive("removeUnauthorizedFilesButton", RemoveUnauthorizedFilesButton);
.directive("removeUnauthorizedFilesButton", RemoveUnauthorizedFilesButton)
.directive("selectSingleCart", SelectSingleCart)
.directive("removeSingleCart", RemoveSingleCart)
.directive("selectAllCart", SelectAllCart);
}

48 changes: 36 additions & 12 deletions app/scripts/cart/cart.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module ngApp.cart.services {
getMaxSize(): number;
isFull(): boolean;
getCartVacancySize(): number;
selectFile(file: IFile): void;
}

class CartService implements ICartService {
Expand Down Expand Up @@ -63,16 +64,20 @@ module ngApp.cart.services {
return this.files;
}

getFile(fileId: string) {
return _.find(this.getFiles(), { "file_id": fileId });
}

getAuthorizedFiles() {
return this.files.filter((file)=>{
return this.UserService.userCanDownloadFile(file);
})
});
}

getUnauthorizedFiles() {
return this.files.filter((file)=>{
return !this.UserService.userCanDownloadFile(file);
})
});
}

getSelectedFiles(): IFile[] {
Expand All @@ -96,21 +101,32 @@ module ngApp.cart.services {
var alreadyIn:IFile[] = [];
_.forEach(files, (file) => {
if (!this.isInCart(file.file_id)) {
file.projectIds = _.unique(_.map(file.participants, (participant) => {
return participant.project.project_id;
}));
file.annotationIds = _.map(file.annotations, (annotation) => {
return annotation.annotation_id;
});
var projectIds = file.projects;
var annotationIds = file.annotationIds;
var participantIds = file.participantId;

// We are not loading a file in from an undo action
if (file.participants) {
projectIds = _.unique(_.map(file.participants, (participant) => {
return participant.project.project_id;
}));
annotationIds = _.map(file.annotations, (annotation) => {
return annotation.annotation_id;
});
participantIds = _.map(file.participants, (participant) => {
return participant.participant_id;
});
}

var fileNeededFieldsOnly = {
'selected': true,
'access': file.access || '--',
'file_name': file.file_name || '--',
'file_id': file.file_id || '--',
'annotationIds': file.annotationIds,
'participantNum': file.participants ? file.participants.length : 0,
'participantId': file.participants && file.participants.length > 0 ? file.participants[0].participant_id : "--",
'projects': file.projectIds,
'annotationIds': annotationIds,
'participantNum': participantIds.length ? participantIds.length : 0,
'participantId': participantIds.length > 0 ? participantIds : [],
'projects': projectIds,
'data_type': file.data_type || '--',
'data_format': file.data_format || '--',
'file_size': file.file_size || 0,
Expand Down Expand Up @@ -224,6 +240,14 @@ module ngApp.cart.services {
this.$window.localStorage.setItem(CartService.GDC_CART_KEY, JSON.stringify(this.files));
}

selectFile(file: IFile) {
var fileInCart = this.getFile(file.file_id);

if (fileInCart) {
fileInCart.selected = !fileInCart.selected;
}
}

}

angular
Expand Down
Loading

0 comments on commit 3791a80

Please sign in to comment.