Skip to content

Commit

Permalink
Merge pull request getredash#2225 from kravets-levko/feature/insert-s…
Browse files Browse the repository at this point in the history
…chema-doubleclick

Insert schema node into editor by click
  • Loading branch information
arikfr committed Jan 18, 2018
2 parents c2e28b2 + c0d86c2 commit 0efdd47
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 7 deletions.
40 changes: 38 additions & 2 deletions client/app/assets/less/inc/schema-browser.less
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,20 @@ div.table-name {
text-overflow: ellipsis;
white-space: nowrap;
cursor: pointer;
padding: 2px 10px;
padding: 2px 22px 2px 10px;
border-radius: @redash-radius;
position: relative;

.copy-to-editor {
display: none;
}

&:hover {
background: fade(@redash-gray, 10%);

.copy-to-editor {
display: flex;
}
}
}

Expand All @@ -28,8 +37,35 @@ div.table-name {
background: transparent;
}

.copy-to-editor {
color: fade(@redash-gray, 90%);
cursor: pointer;
position: absolute;
top: 0;
right: 0;
bottom: 0;
width: 20px;
display: flex;
align-items: center;
justify-content: center;
}

.table-open {
padding-left: 26px;
padding: 0 22px 0 26px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
position: relative;

.copy-to-editor {
display: none;
}

&:hover {
.copy-to-editor {
display: flex;
}
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions client/app/components/queries/query-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ function queryEditor(QuerySnippet) {
autoScrollEditorIntoView: true,
},
onLoad(editor) {
$scope.$on('query-editor.paste', ($event, text) => {
editor.session.doc.replace(editor.selection.getRange(), text);
});

// Release Cmd/Ctrl+L to the browser
editor.commands.bindKey('Cmd+L', null);
editor.commands.bindKey('Ctrl+L', null);
Expand Down
7 changes: 6 additions & 1 deletion client/app/components/queries/schema-browser.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@
<span title="{{table.name}}">{{table.name}}</span>
<span ng-if="table.size !== undefined"> ({{table.size}})</span>
</strong>
<i class="fa fa-angle-double-right copy-to-editor" aria-hidden="true"
ng-click="$ctrl.itemSelected($event, [table.name])"></i>
</div>
<div uib-collapse="table.collapsed">
<div ng-repeat="column in table.columns track by column" class="table-open">{{column}}</div>
<div ng-repeat="column in table.columns track by column" class="table-open">{{column}}
<i class="fa fa-angle-double-right copy-to-editor" aria-hidden="true"
ng-click="$ctrl.itemSelected($event, [table.name, column])"></i>
</div>
</div>
</div>
</div>
Expand Down
8 changes: 7 additions & 1 deletion client/app/components/queries/schema-browser.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import template from './schema-browser.html';

function SchemaBrowserCtrl($scope) {
function SchemaBrowserCtrl($rootScope, $scope) {
'ngInject';

this.showTable = (table) => {
Expand All @@ -21,6 +21,12 @@ function SchemaBrowserCtrl($scope) {
this.isEmpty = function isEmpty() {
return this.schema === undefined || this.schema.length === 0;
};

this.itemSelected = ($event, hierarchy) => {
$rootScope.$broadcast('query-editor.paste', hierarchy.join('.'));
$event.preventDefault();
$event.stopPropagation();
};
}

const SchemaBrowser = {
Expand Down
6 changes: 3 additions & 3 deletions client/app/pages/queries/queries-search-results-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ function QuerySearchCtrl($location, $filter, currentUser, Events, Query) {

this.createdAtSort = row => row.created_at.valueOf();
this.createdBySort = row => row.user.name;
this.scheduleSort = function (row) {
this.scheduleSort = (row) => {
if (!row.schedule) {
return null;
}
if (row.schedule.match(/\d\d:\d\d/) !== null) {
const parts = row.schedule.split(':');
const localTime = moment.utc()
.hour(parts[0])
.minute(parts[1]);
.hour(parts[0])
.minute(parts[1]);
return localTime.valueOf();
}
return parseInt(row.schedule, 10);
Expand Down

0 comments on commit 0efdd47

Please sign in to comment.