2018-10-10 07:56:23 -04:00
|
|
|
import { observes } from "ember-addons/ember-computed-decorators";
|
2016-12-01 13:54:21 -05:00
|
|
|
|
|
|
|
export default Ember.Component.extend({
|
2018-10-10 07:56:23 -04:00
|
|
|
@observes("hideSchema")
|
2016-12-01 13:54:21 -05:00
|
|
|
_onHideSchema() {
|
2018-10-10 07:56:23 -04:00
|
|
|
this.appEvents.trigger("ace:resize");
|
2016-12-01 13:54:21 -05:00
|
|
|
},
|
|
|
|
|
2018-10-10 07:56:23 -04:00
|
|
|
@observes("everEditing")
|
2016-12-01 13:54:21 -05:00
|
|
|
_onInsertEditor() {
|
2018-10-10 07:56:23 -04:00
|
|
|
Ember.run.schedule("afterRender", this, () => this._bindControls());
|
2016-12-01 13:54:21 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_bindControls() {
|
|
|
|
if (this._state !== "inDOM") {
|
|
|
|
return;
|
|
|
|
}
|
2018-10-10 07:56:23 -04:00
|
|
|
const $editPane = this.$().find(".query-editor");
|
2016-12-01 13:54:21 -05:00
|
|
|
if (!$editPane.length) {
|
|
|
|
return;
|
|
|
|
}
|
2018-10-10 07:56:23 -04:00
|
|
|
const oldGrippie = this.get("grippie");
|
2016-12-01 13:54:21 -05:00
|
|
|
if (oldGrippie) {
|
2018-10-10 07:56:23 -04:00
|
|
|
oldGrippie.off("mousedown mousemove mouseup");
|
|
|
|
$editPane.off("mousemove mouseup");
|
2016-12-01 13:54:21 -05:00
|
|
|
}
|
|
|
|
|
2018-10-10 07:56:23 -04:00
|
|
|
const $grippie = $editPane.find(".grippie");
|
|
|
|
const $targets = $editPane.find(".ace-wrapper,.grippie-target");
|
|
|
|
const $body = $("body");
|
2016-12-01 13:54:21 -05:00
|
|
|
const self = this;
|
|
|
|
|
2018-10-10 07:56:23 -04:00
|
|
|
this.set("grippie", $grippie);
|
2016-12-01 13:54:21 -05:00
|
|
|
|
|
|
|
const mousemove = function(e) {
|
2018-10-10 07:56:23 -04:00
|
|
|
const diff = self.get("startY") - e.screenY;
|
|
|
|
const newHeight = self.get("startSize") - diff;
|
2016-12-01 13:54:21 -05:00
|
|
|
$targets.height(newHeight);
|
2018-10-10 07:56:23 -04:00
|
|
|
self.appEvents.trigger("ace:resize");
|
2016-12-01 13:54:21 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
let mouseup;
|
|
|
|
mouseup = function(e) {
|
|
|
|
mousemove(e);
|
2018-10-10 07:56:23 -04:00
|
|
|
$body.off("mousemove", mousemove);
|
|
|
|
$body.off("mouseup", mouseup);
|
|
|
|
self.set("startY", null);
|
|
|
|
self.set("startSize", null);
|
2016-12-01 13:54:21 -05:00
|
|
|
};
|
|
|
|
|
2018-10-10 07:56:23 -04:00
|
|
|
$grippie.on("mousedown", function(e) {
|
|
|
|
self.set("startY", e.screenY);
|
|
|
|
self.set("startSize", $targets.height());
|
2016-12-01 13:54:21 -05:00
|
|
|
|
2018-10-10 07:56:23 -04:00
|
|
|
$body.on("mousemove", mousemove);
|
|
|
|
$body.on("mouseup", mouseup);
|
2016-12-01 13:54:21 -05:00
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
didInsertElement() {
|
|
|
|
this._super();
|
|
|
|
this._bindControls();
|
|
|
|
},
|
|
|
|
|
|
|
|
willDestroyElement() {
|
|
|
|
this._super();
|
2018-10-10 07:56:23 -04:00
|
|
|
if (this.get("everEditing")) {
|
|
|
|
this.get("grippie").off("mousedown");
|
|
|
|
this.set("grippie", null);
|
2016-12-01 13:54:21 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|