Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSV Export #165

Merged
merged 5 commits into from
Jun 4, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/controllers/mixins/downloads.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Balanced.DownloadControllerMixin = Ember.Mixin.create({
email_address: null,

download_primary: function () {
var uri = window.location.hash.substr(1);
var uri = this.getSearchUri();
var self = this;
if (this.email_address) {
var download = Balanced.Download.create({
Expand All @@ -22,6 +22,10 @@ Balanced.DownloadControllerMixin = Ember.Mixin.create({
}
},

getSearchUri: function () {
return window.location.hash.substr(1);
},

download_close: function () {
this.set('show_download', false);
},
Expand Down
36 changes: 26 additions & 10 deletions app/controllers/search.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Balanced.SearchController = Balanced.ObjectController.extend({
Balanced.SearchController = Balanced.ObjectController.extend(Balanced.DownloadControllerMixin, {
needs: ["marketplace"],

search: '',
Expand Down Expand Up @@ -42,6 +42,15 @@ Balanced.SearchController = Balanced.ObjectController.extend({
return this.getLabel(typesToLabels, types, this.type);
}.property('content.type'),

getSearchUri: function () {
var query = this.get('search');
var marketplaceUri = this.get('controllers').get('marketplace').get('uri');
var params = this.searchParams({
query: query
});
return Balanced.SearchQuery.createUri(marketplaceUri, params);
},

////
// Wrapper
////
Expand Down Expand Up @@ -76,23 +85,30 @@ Balanced.SearchController = Balanced.ObjectController.extend({
this.set('isLoading', true);

var _this = this;

Balanced.SearchQuery.search(marketplaceUri, {
var params = this.searchParams({
query: query,
limit: this.get('limit'),
minDate: this.get('minDate'),
maxDate: this.get('maxDate'),
sortField: this.get('sortField'),
sortOrder: this.get('sortOrder'),
type: this.get('type'),
requestTimeStamp: requestTimeStamp
}, {
});

Balanced.SearchQuery.search(marketplaceUri, params, {
observer: function (result) {
_this.onSearchCallback(result, callback);
}
});
},

searchParams: function (params) {
var defaults = {
limit: this.get('limit'),
minDate: this.get('minDate'),
maxDate: this.get('maxDate'),
sortField: this.get('sortField'),
sortOrder: this.get('sortOrder'),
type: this.get('type')
};
return $.extend({}, defaults, params);
},

loadMoreFromQuery: function () {
this.set('isLoading', true);

Expand Down
22 changes: 21 additions & 1 deletion app/lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ Balanced.Helpers = (function () {

function calculateContentHeight() {
var $content = $('#content');
if (!$content.length) {
return;
}
var height = $content.height();
var padding = (+$content.css('padding-top').replace('px', '')) + (+$content.css('padding-bottom').replace('px', ''));
return (+height + (+padding)) + 'px';
Expand All @@ -179,7 +182,9 @@ Balanced.Helpers = (function () {

updateNavigationHeight: function () {
var height = calculateContentHeight();
$('#marketplace-nav').height(height);
if (height) {
$('#marketplace-nav').height(height);
}
}
};
})();
Expand Down Expand Up @@ -220,6 +225,21 @@ Balanced.Utils = {
}
},

sortDict: function (dict) {
var sorted = [];
for (var key in dict) {
sorted[sorted.length] = key;
}
sorted.sort();

var tempDict = {};
for (var i = 0; i < sorted.length; i++) {
tempDict[sorted[i]] = dict[sorted[i]];
}

return tempDict;
},

formatCurrency: function (cents) {
if (cents !== null) {
return '$' + (cents / 100).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,');
Expand Down
22 changes: 14 additions & 8 deletions app/models/search_query.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,23 @@ Balanced.SearchQuery.reopenClass({
json.total_funding_instruments = json.total;
}
},

search: function (marketplaceUri, params, options) {
var uri = this.createUri(marketplaceUri, params);
var res = this.find(uri, options);
return res;
},

createUri: function (marketplaceUri, params) {
var uri = marketplaceUri + '/search?';
var searchParams = {
limit: params.limit || 10,
offset: params.offset || 0,
sortOrder: params.sortOrder || '',
sortField: params.sortField || '',
q: params.query,
requestTimeStamp: params.requestTimeStamp
q: params.query
};
if (params.requestTimeStamp) {
searchParams.requestTimeStamp = params.requestTimeStamp;
}
if (params.sortOrder && params.sortField && !params.sort) {
searchParams.sort = [params.sortField, params.sortOrder].join(',');
}
Expand All @@ -97,14 +104,13 @@ Balanced.SearchQuery.reopenClass({
searchParams.sort = params.sortField + ',' + params.sortOrder;
}

searchParams = Balanced.Utils.sortDict(searchParams);

var queryString = $.map(searchParams,function (v, k) {
return k + '=' + v;
}).join('&');

uri += encodeURI(queryString);

var res = this.find(uri, options);

return res;
return uri;
}
});
62 changes: 30 additions & 32 deletions app/templates/date_picker.hbs
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
<li class="timing dropdown label4a">
<a class="dropdown-toggle"
data-toggle="dropdown"
href="#"
{{action "toggleDateTimePicker" target="view"}}>
<span>Any time</span>
<b class="caret"></b>
</a>
<ul class="dropdown-menu date-picker right">
<li>
<ul class="set-times">
{{#view Balanced.DatePickerPresetView}}<a href="#">Anytime</a>{{/view}}
{{#view Balanced.DatePickerPresetView}}<a href="#">Past hour</a>{{/view}}
{{#view Balanced.DatePickerPresetView}}<a href="#">Past 24 hours</a>{{/view}}
{{#view Balanced.DatePickerPresetView}}<a href="#">Past week</a>{{/view}}
{{#view Balanced.DatePickerPresetView}}<a href="#">Past month</a>{{/view}}
</ul>
<div class="date-picker">
<div class="after selected">
{{#view Balanced.DatePickerDateFieldView class="dt"}}
<input type="text" name="after" class="dp" data-element="#search .timing .after">
{{/view}}
</div>
<div class="before">
{{#view Balanced.DatePickerDateFieldView class="dt"}}
<input type="text" name="before" class="dp" data-element="#search .timing .before">
{{/view}}
</div>
<button class="btn go" {{action "setDateVariable" target="view"}}>Go</button>
<a class="dropdown-toggle"
data-toggle="dropdown"
href="#"
{{action "toggleDateTimePicker" target="view"}}>
<span>Any time</span>
<b class="caret"></b>
</a>
<ul class="dropdown-menu date-picker right">
<li>
<ul class="set-times">
{{#view Balanced.DatePickerPresetView}}<a href="#">Anytime</a>{{/view}}
{{#view Balanced.DatePickerPresetView}}<a href="#">Past hour</a>{{/view}}
{{#view Balanced.DatePickerPresetView}}<a href="#">Past 24 hours</a>{{/view}}
{{#view Balanced.DatePickerPresetView}}<a href="#">Past week</a>{{/view}}
{{#view Balanced.DatePickerPresetView}}<a href="#">Past month</a>{{/view}}
</ul>
<div class="date-picker">
<div class="after selected">
{{#view Balanced.DatePickerDateFieldView class="dt"}}
<input type="text" name="after" class="dp" data-element="#search .timing .after">
{{/view}}
</div>
</li>
</ul>
</li>
<div class="before">
{{#view Balanced.DatePickerDateFieldView class="dt"}}
<input type="text" name="before" class="dp" data-element="#search .timing .before">
{{/view}}
</div>
<button class="btn go" {{action "setDateVariable" target="view"}}>Go</button>
</div>
</li>
</ul>
1 change: 0 additions & 1 deletion app/templates/marketplace/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

<div class="row">
<div class="span11">

<section class="marketplace-info">
<form class="form-horizontal edit-inline">
<header>
Expand Down
11 changes: 9 additions & 2 deletions app/templates/search.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,12 @@
</ul>
</div>
</li>

{{view Balanced.DatePickerView}}
<li class="timing dropdown label4a">
{{view Balanced.DatePickerView}}
</li>
<!--<li class="download">-->
<!--<a href="#" {{action download_show}} class="icon-download right">Download</a>-->
<!--</li>-->
</nav>
</header>

Expand Down Expand Up @@ -239,4 +243,7 @@
</table>
</div>
</div>
{{#if show_download}}
{{view Balanced.DownloadModalView }}
{{/if}}
</div>
2 changes: 1 addition & 1 deletion app/views/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Balanced.ModalView = Balanced.View.extend({
return this.eventPrefix + '_' + eventName;
},
didInsertElement: function () {
$(this.element).modal('show');
$(this.element).modal('show').find('input[type="email"]').focus();
Ember.assert(this.eventPrefix !== null, 'No event prefix given');
Ember.assert(this.element !== null, 'No element specified');
},
Expand Down
13 changes: 10 additions & 3 deletions static/less/search.less
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
outline: none;
}
}
.close {
> .close {
display: block;
right: 10px;
top: 18px;
Expand Down Expand Up @@ -110,7 +110,6 @@
font-family: fanwoodtext-regular;
font-weight: normal;
font-size: 16px;

a {
text-decoration: none;
color: @gray5;
Expand Down Expand Up @@ -141,6 +140,14 @@
display: none;
}
}
&.download {
float: right;
padding: 9px 0 0;
margin: 0 10px;
&:hover {
border-bottom: 0;
}
}
.selector {
display: inline-block;
padding: 4px 2px 0;
Expand Down Expand Up @@ -203,7 +210,7 @@
}
.caret {
position: absolute;
top: 13px;
top: 21px;
right: 22px;
border-top-color: @searchTimingColor;
}
Expand Down
10 changes: 5 additions & 5 deletions test/support/fixtures/search_query.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Balanced.Adapter.addFixtures([
"last_uri": "/v1/marketplaces/MP5m04ORxNlNDm1bB7nkcgSY/search?q=t&limit=10&offset=20"
},
{
"first_uri": "/v1/marketplaces/MP5m04ORxNlNDm1bB7nkcgSY/search?requestTimeStamp=0&sortField=&type%5Bin%5D=credit%2Cdebit%2Crefund%2Chold&q=&limit=10&sortOrder=&offset=0",
"first_uri": "/v1/marketplaces/MP5m04ORxNlNDm1bB7nkcgSY/search?limit=10&offset=0&q=&type%5Bin%5D=credit,debit,refund,hold",
"_type": "page",
"items": [
{
Expand Down Expand Up @@ -1717,7 +1717,7 @@ Balanced.Adapter.addFixtures([
}
],
"previous_uri": null,
"uri": "/v1/marketplaces/MP5m04ORxNlNDm1bB7nkcgSY/search?limit=10&offset=0&sortOrder=&sortField=&q=&requestTimeStamp=0&type%5Bin%5D=credit,debit,refund,hold",
"uri": "/v1/marketplaces/MP5m04ORxNlNDm1bB7nkcgSY/search?limit=10&offset=0&q=&type%5Bin%5D=credit,debit,refund,hold",
"_uris": {
"first_uri": {
"_type": "page",
Expand Down Expand Up @@ -2323,7 +2323,7 @@ Balanced.Adapter.addFixtures([
}
],
"previous_uri": null,
"uri": "/v1/marketplaces/MP5m04ORxNlNDm1bB7nkcgSY/search?limit=10&offset=0&sortOrder=&sortField=&q=&requestTimeStamp=0&type=account",
"uri": "/v1/marketplaces/MP5m04ORxNlNDm1bB7nkcgSY/search?limit=10&offset=0&q=&type=account",
"_uris": {
"first_uri": {
"_type": "page",
Expand Down Expand Up @@ -4220,7 +4220,7 @@ Balanced.Adapter.addFixtures([
}
],
"previous_uri": null,
"uri": "/v1/marketplaces/MP5m04ORxNlNDm1bB7nkcgSY/search?limit=10&offset=0&sortOrder=&sortField=&q=&requestTimeStamp=0&type=hold",
"uri": "/v1/marketplaces/MP5m04ORxNlNDm1bB7nkcgSY/search?limit=10&offset=0&q=&type=hold",
"_uris": {
"first_uri": {
"_type": "page",
Expand Down Expand Up @@ -4255,4 +4255,4 @@ Balanced.Adapter.addFixtures([
"id": null,
"last_uri": "/v1/marketplaces/MP5m04ORxNlNDm1bB7nkcgSY/search?requestTimeStamp=0&sortField=&q=&limit=10&sortOrder=&offset=0&type=hold"
}
]);
]);
16 changes: 16 additions & 0 deletions test/unit/models/search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module('Balanced.Search', {

});

test('search query generation', function (assert) {
var expected = '/v1/marketplaces/MP123/search/search?limit=10&offset=0&q=hodor';
var params = {
query: 'hodor'
};
var uri = Balanced.SearchQuery.createUri('/v1/marketplaces/MP123/search', params);
assert.equal(uri, expected);

params.offset = 20;
uri = Balanced.SearchQuery.createUri('/v1/marketplaces/MP123/search', params);
assert.notEqual(uri, expected);
});