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

Commit

Permalink
feat(search): search table header actions
Browse files Browse the repository at this point in the history
- size-dependent cart actions
- update README.md with changes needed to ES config

Closes #193
  • Loading branch information
Christine Yu committed Jan 15, 2015
1 parent cdaa865 commit f929b2a
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 10 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ Installing NPM dependencies...
Setup Successful!
```

### ElasticSearch
Edit path-to-elastic-search/config/elasticsearch.yml, find the line with http.max_content_length, add
```
http.max_initial_line_length: 1000mb
```
to increase the max length of a HTTP URL

### Git hooks

Git commit-msg hook is based on Angular's [Guidelines](https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y/edit#)
Expand Down Expand Up @@ -143,4 +150,4 @@ Serving HTTP on 0.0.0.0 port 8000

- [angularjs-via-typescript-controllers](http://kodeyak.wordpress.com/2014/02/12/angularjs-via-typescript-controllers/)
- [AngularJS + TypeScript : Controllers, Best Practice](https://www.youtube.com/watch?v=WdtVn_8K17E)
- [Angular Services using TypeScript : Best Practices](https://www.youtube.com/watch?v=Yis8m3BdnEM)
- [Angular Services using TypeScript : Best Practices](https://www.youtube.com/watch?v=Yis8m3BdnEM)
13 changes: 12 additions & 1 deletion app/scripts/cart/cart.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ module ngApp.cart.services {
removeFiles(files: IFile[]): void;
buildAddedMsg(addedAndAlreadyIn: Object): string;
buildRemovedMsg(removedFiles: IFile[]): string;
//undo(): void;
undoAdded(): void;
undoRemoved(): void;
getMaxSize(): number;
isFull(): boolean;
}

class CartService implements ICartService {
Expand All @@ -34,6 +35,7 @@ module ngApp.cart.services {

private static GDC_CART_KEY = "gdc-cart-items";
private static GDC_CART_UPDATE = "gdc-cart-updated";
private static MAX_SIZE: number = 1000;

/* @ngInject */
constructor(private $window: IGDCWindowService,
Expand All @@ -45,6 +47,14 @@ module ngApp.cart.services {
this.files = local_files ? JSON.parse(local_files) : [];
}

getMaxSize(): number {
return CartService.MAX_SIZE;
}

isFull(): boolean {
return this.files.length >= CartService.MAX_SIZE;
}

getFiles(): IFile[] {
return this.files;
}
Expand Down Expand Up @@ -151,6 +161,7 @@ module ngApp.cart.services {
classes: "alert-warning"
});
this.files = remaining;
this._sync();
}

removeFiles(files: IFile[]): void {
Expand Down
63 changes: 60 additions & 3 deletions app/scripts/search/search.controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ module ngApp.search.controllers {
addFilteredRelatedFiles(participant: IParticipant): void;
addToCart(files: IFile[]): void;
isUserProject(file: IFile): boolean;
addAll(): void;
removeAllinSearchResult(): void;
}

class SearchController implements ISearchController {
files: IFiles;
participants: IParticipants;
lastAddedFiles: IFile[];
fileSortColumns: any = [
{
key: "file_size",
Expand Down Expand Up @@ -129,6 +130,7 @@ module ngApp.search.controllers {
"file_extension"
]
}).then((data) => this.files = data);

this.ParticipantsService.getParticipants({
fields: [
"bcr_patient_barcode",
Expand Down Expand Up @@ -160,7 +162,6 @@ module ngApp.search.controllers {
"vital_status"
]
}).then((data) => {

// TODO - remove when aggregations done on server
var participants = data.hits.map((participant)=>{
participant.filesByType = participant.files.reduce((a,b)=>{
Expand Down Expand Up @@ -223,7 +224,61 @@ module ngApp.search.controllers {
}

addToCart(files: IFile[]): void {
var cartReturned = this.CartService.addFiles(files);
this.CartService.addFiles(files);
}

addAll(): void {
console.log("SearchController::addAll");
var filters = this.LocationService.filters();
var size: number = (this.files.pagination.total >= this.CartService.getMaxSize()) ? this.CartService.getMaxSize() : this.files.pagination.total;
this.FilesService.getFiles({
fields: [
"data_access",
"data_format",
"data_level",
"data_subtype",
"data_type",
"file_extension",
"file_name",
"file_size",
"file_uuid",
"platform",
"updated",
"archive.disease_code",
"archive.revision",
"participants.bcr_patient_uuid"
],
filters: filters,
size: size
}).then((data) => this.CartService.addFiles(data.hits));
}

removeAllInSearchResult(): void {
// Query ES using the current filter and the file uuids in the Cart
// If an id is in the result, then it is both in the Cart and in the current Search query
var filters = this.LocationService.filters();
var size: number = this.CartService.getFiles().length;
if (!filters.content) {
filters.op = "and";
filters.content = [];
}
filters.content.push({
content: {
field: "files.file_uuid",
value: _.pluck(this.CartService.getFiles(), "file_uuid")
},
op: "is"
});
this.FilesService.getFiles({
fields:[
"file_uuid"
],
filters: filters,
size: size,
from: 0
}).then((data) => {
this.CartService.remove(_.pluck(data.hits, "file_uuid"));
});
}

removeFiles(files: IFile[]): void {
Expand Down Expand Up @@ -272,11 +327,13 @@ module ngApp.search.controllers {
filters: filters,
size: 100
}).then((data) => participant.filteredRelatedFiles = data);

}

addFilteredRelatedFiles(participant: IParticipant): void {
this.addToCart(participant.filteredRelatedFiles.hits);
}

}

angular
Expand Down
17 changes: 12 additions & 5 deletions app/scripts/search/templates/search.files.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<div class="panel panel-default">

<div class="panel-heading clearfix">
<h3 class="panel-title pull-left" data-translate>Files</h3>
<div class="pull-right">
Expand All @@ -16,21 +14,30 @@ <h3 class="panel-title pull-left" data-translate>Files</h3>
<i class="fa fa-check-circle"></i>
</button>
<button data-ng-if="!sc.CartService.areInCart(sc.files.hits)" type="button" class="btn btn-primary"
data-ng-click="sc.CartService.addFiles(sc.files.hits)">
data-ng-click="sc.CartService.addFiles(sc.files.hits)"
data-ng-disabled="(sc.CartService.getFiles().length + sc.files.hits.length) > sc.CartService.getMaxSize()">
<i class="fa fa-shopping-cart"></i>
</button>
<button type="button" class="btn btn-default dropdown-toggle">
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li>
<a>
<a data-ng-if="sc.CartService.isFull()">
<i class="fa fa-shopping-cart fa-stack"></i>
<span data-translate>Cart Full</span>
</a>
<a data-ng-if="(sc.CartService.getFiles().length + sc.files.pagination.total) > sc.CartService.getMaxSize()" disabled>
<i class="fa fa-shopping-cart fa-stack"></i>
<span data-translate>Cart can only hold {{sc.CartService.getMaxSize() - sc.CartService.getFiles().length }} more items</span>
</a>
<a data-ng-if="(sc.CartService.getFiles().length + sc.files.pagination.total) <= sc.CartService.getMaxSize()" data-ng-click="sc.addAll()">
<i class="fa fa-shopping-cart fa-stack"></i>
<span data-translate>Add all in Search Result</span>
</a>
</li>
<li>
<a>
<a data-ng-click="sc.removeAllInSearchResult()">
<i class="fa fa-shopping-cart fa-stack"></i>
<span data-translate>Remove all in Search Result</span>
</a>
Expand Down

0 comments on commit f929b2a

Please sign in to comment.