discourse-data-explorer/assets/javascripts/discourse/components/explorer-container.js.es6

95 lines
2.2 KiB
Plaintext
Raw Normal View History

import { observes } from "discourse-common/utils/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;
}
const $editPane = $(".query-editor");
2016-12-01 13:54:21 -05:00
if (!$editPane.length) {
return;
}
2019-04-07 02:05:43 -04:00
const oldGrippie = this.grippie;
2016-12-01 13:54:21 -05:00
if (oldGrippie) {
2018-10-10 07:56:23 -04:00
oldGrippie.off("mousedown mousemove mouseup");
2016-12-01 13:54:21 -05:00
}
2018-10-10 07:56:23 -04:00
const $grippie = $editPane.find(".grippie");
2019-04-07 02:05:43 -04:00
const $target = $editPane.find(".panels-flex");
const $document = $(document);
2019-04-07 02:05:43 -04:00
const minWidth = $target.width();
const minHeight = $target.height();
2016-12-01 13:54:21 -05:00
2018-10-10 07:56:23 -04:00
this.set("grippie", $grippie);
2016-12-01 13:54:21 -05:00
2019-04-07 02:05:43 -04:00
const mousemove = e => {
const diffY = this.startY - e.screenY;
const diffX = this.startX - e.screenX;
2016-12-01 13:54:21 -05:00
const newHeight = Math.max(minHeight, this.startHeight - diffY);
const newWidth = Math.max(minWidth, this.startWidth - diffX);
2019-04-07 02:05:43 -04:00
$target.height(newHeight);
$target.width(newWidth);
$grippie.width(newWidth);
this.appEvents.trigger("ace:resize");
2016-12-01 13:54:21 -05:00
};
2019-04-07 02:05:43 -04:00
const throttledMousemove = (event => {
event.preventDefault();
Ember.run.throttle(this, mousemove, event, 20);
}).bind(this);
2019-06-14 12:29:06 -04:00
const mouseup = (() => {
2019-04-07 02:05:43 -04:00
$document.off("mousemove", throttledMousemove);
$document.off("mouseup", mouseup);
this.setProperties({
startY: null,
startX: null,
startHeight: null,
startWidth: null
});
}).bind(this);
$grippie.on("mousedown", e => {
this.setProperties({
startY: e.screenY,
startX: e.screenX,
startHeight: $target.height(),
startWidth: $target.width()
});
2016-12-01 13:54:21 -05:00
2019-04-07 02:05:43 -04:00
$document.on("mousemove", throttledMousemove);
$document.on("mouseup", mouseup);
2016-12-01 13:54:21 -05:00
e.preventDefault();
});
},
didInsertElement() {
this._super(...arguments);
2016-12-01 13:54:21 -05:00
this._bindControls();
},
willDestroyElement() {
this._super(...arguments);
if (this.everEditing) {
this.grippie && this.grippie.off("mousedown");
2018-10-10 07:56:23 -04:00
this.set("grippie", null);
2016-12-01 13:54:21 -05:00
}
}
});