FEATURE: 'Download Result' removes 250-row limit

This commit is contained in:
Kane York
2015-07-09 12:03:25 -07:00
parent 7b6b4f9222
commit 71c3b73ef8
6 changed files with 86 additions and 49 deletions
@@ -10,6 +10,11 @@ var defaultFallback = function(buffer, content, defaultRender) { defaultRender(b
function isoYMD(date) {
return date.getUTCFullYear() + "-" + date.getUTCMonth() + "-" + date.getUTCDate();
}
function randomIdShort() {
return 'xxxxxxxx'.replace(/[xy]/g, function() {
return (Math.random() * 16 | 0).toString(16);
});
}
const QueryResultComponent = Ember.Component.extend({
layoutName: 'explorer-query-result',
@@ -25,10 +30,6 @@ const QueryResultComponent = Ember.Component.extend({
return this.get('content.columns').length;
}.property('content.columns.length'),
downloadName: function() {
return this.get('query.name') + "@" + window.location.host + "-" + isoYMD(new Date()) + ".dcqresult.json";
}.property(),
duration: function() {
return I18n.t('explorer.run_time', {value: I18n.toNumber(this.get('content.duration'), {precision: 1})});
}.property('content.duration'),
@@ -99,19 +100,45 @@ const QueryResultComponent = Ember.Component.extend({
});
}.property('content', 'columns.@each'),
_clickDownloadButton: function() {
const self = this;
const $button = this.$().find("#result-download");
// use $.one to do once
$button.one('mouseover', function(e) {
const a = e.target;
let resultString = "data:text/plain;base64,";
var jsonString = JSON.stringify(self.get('content'));
resultString += btoa(jsonString);
actions: {
downloadResult() {
const blankUrl = "about:blank";
const windowName = randomIdShort();
a.href = resultString;
});
}.on('didInsertElement'),
let form = document.createElement("form");
form.setAttribute('id', 'query-download-result');
form.setAttribute('method', 'post');
form.setAttribute('action', Discourse.getURL('/admin/plugins/explorer/queries/' + this.get('query.id') + '/run.json?download=1'));
form.setAttribute('target', windowName);
form.setAttribute('style', 'display:none;');
function addInput(form, name, value) {
let field;
field = document.createElement('input');
field.setAttribute('name', name);
field.setAttribute('value', value);
form.appendChild(field);
}
addInput(form, 'params', JSON.stringify(this.get('params')));
addInput(form, 'explain', this.get('hasExplain'));
addInput(form, 'limit', '1000000');
const newWindow = window.open(blankUrl, windowName);
Discourse.ajax('/session/csrf.json').then(function(csrf) {
addInput(form, 'authenticity_token', csrf.csrf);
document.body.appendChild(form);
form.submit();
Em.run.next('afterRender', function() {
document.body.removeChild(form);
newWindow.close();
});
});
}
},
parent: function() { return this; }.property()
@@ -48,7 +48,7 @@ export default Ember.ArrayController.extend({
return this.get('selectedItem').save().then(function() {
const query = self.get('selectedItem');
query.markNotDirty();
self.set('editName', false);
self.set('editing', false);
}).catch(function(x) {
popupAjaxError(x);
throw x;
@@ -70,7 +70,7 @@ export default Ember.ArrayController.extend({
},
editName() {
this.set('editName', true);
this.set('editing', true);
},
download() {
@@ -112,7 +112,7 @@ export default Ember.ArrayController.extend({
const query = self.get('selectedItem');
query.setProperties(result.getProperties(Query.updatePropertyNames));
query.markNotDirty();
self.set('editName', false);
self.set('editing', false);
}).catch(popupAjaxError).finally(function() {
self.set('loading', false);
});
@@ -145,6 +145,9 @@ export default Ember.ArrayController.extend({
if (this.get('selectedItem.dirty')) {
return;
}
if (this.get('runDisabled')) {
return;
}
this.set('loading', true);
this.set('showResults', false);
@@ -28,7 +28,7 @@
<div class="query-edit {{if editName "editing"}}">
{{#if selectedItem}}
<div class="name">
{{#if editName}}
{{#if editing}}
{{text-field value=selectedItem.name}}
{{else}}
<h2>{{selectedItem.name}}</h2>
@@ -36,7 +36,7 @@
{{/if}}
</div>
<div class="desc">
{{#if editName}}
{{#if editing}}
{{textarea value=selectedItem.description}}
{{else}}
{{selectedItem.description}}
@@ -46,9 +46,7 @@
<div class="query-editor">
<div class="editor-panel">
<div class="sql">
{{textarea value=selectedItem.sql class="grippie-target"}}
</div>
{{ace-editor content=selectedItem.sql mode="sql"}}
</div>
<div class="right-panel">
<div class="schema grippie-target">
@@ -76,12 +74,12 @@
{{/if}}
</div>
<div class="query-run">
<form class="query-run" {{action "run" on="submit"}}>
{{#if selectedItem.param_names}}
<div class="query-params">
<div class="param-save">
{{d-button action="saveDefaults" label="explorer.save_params"}}
{{d-button action="resetParams" label="explorer.reset_params"}}
{{d-button action="saveDefaults" label="explorer.save_params" type="button"}}
{{d-button action="resetParams" label="explorer.reset_params" type="button"}}
</div>
{{#each selectedItem.param_names as |pname|}}
<div class="param">
@@ -101,9 +99,9 @@
{{d-button action="saverun" label="explorer.saverun"}}
{{/if}}
{{else}}
{{d-button action="run" label="explorer.run" disabled=runDisabled class="btn-primary"}}
{{d-button action="run" label="explorer.run" disabled=runDisabled class="btn-primary" type="submit"}}
{{/if}}
</div>
</form>
<hr>
{{/if}}
@@ -1,8 +1,5 @@
<div class="result-info">
<a class="btn" id="result-download" {{bind-attr download=downloadName}} data-auto-route="true">
{{fa-icon "download"}}
{{i18n "explorer.download_json"}}
</a>
{{d-button action="downloadResult" icon="download" label="explorer.download_json"}}
<div class="result-about">
{{duration}}
</div>