Skip to content

Commit

Permalink
Merge branch 'master' into release-19.05
Browse files Browse the repository at this point in the history
  • Loading branch information
jstriebel authored Apr 29, 2019
2 parents 2eada2f + 8f7664f commit 6e1c67b
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 68 deletions.
2 changes: 2 additions & 0 deletions frontend/javascripts/admin/onboarding.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import DatasetUploadView from "admin/dataset/dataset_upload_view";
import RegistrationForm from "admin/auth/registration_form";
import SampleDatasetsModal from "dashboard/dataset/sample_datasets_modal";
import Toast from "libs/toast";
import features from "features";
import renderIndependently from "libs/render_independently";

const { Step } = Steps;
Expand Down Expand Up @@ -204,6 +205,7 @@ const OrganizationForm = Form.create()(({ form, onComplete }) => {
>
{getFieldDecorator("organizationName", {
rules: [{ required: true, message: "Please enter an organization name!" }],
initialValue: features().defaultOrganization,
})(
<AutoComplete
size="large"
Expand Down
64 changes: 17 additions & 47 deletions frontend/javascripts/libs/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ class InputMouseButton {
}

export class InputMouse {
targetSelector: string;
targetId: string;
hammerManager: Hammer;
id: ?string;

Expand All @@ -314,18 +314,17 @@ export class InputMouse {
off: Function;
trigger: Function;

domElement: HTMLElement;

constructor(
targetSelector: string,
targetId: string,
initialBindings: BindingMap<MouseHandler> = {},
id: ?string = null,
) {
_.extend(this, BackboneEvents);
this.targetSelector = targetSelector;
this.domElement = document.querySelector(targetSelector);
if (!this.domElement) {
throw new Error(`Input couldn't be attached to the following selector ${targetSelector}`);
this.targetId = targetId;
const targetSelector = `#${targetId}`;
const domElement = document.getElementById(targetId);
if (!domElement) {
throw new Error(`Input couldn't be attached to the following id ${targetId}`);
}
this.id = id;

Expand All @@ -340,61 +339,32 @@ export class InputMouse {

_.extend(
this.delegatedEvents,
Utils.addEventListenerWithDelegation(
document,
"mousedown",
this.targetSelector,
this.mouseDown,
),
Utils.addEventListenerWithDelegation(document, "mousedown", targetSelector, this.mouseDown),
);
_.extend(
this.delegatedEvents,
Utils.addEventListenerWithDelegation(
document,
"mouseover",
this.targetSelector,
this.mouseOver,
),
Utils.addEventListenerWithDelegation(document, "mouseover", targetSelector, this.mouseOver),
);
_.extend(
this.delegatedEvents,
Utils.addEventListenerWithDelegation(
document,
"mouseout",
this.targetSelector,
this.mouseOut,
),
Utils.addEventListenerWithDelegation(document, "mouseout", targetSelector, this.mouseOut),
);
_.extend(
this.delegatedEvents,
Utils.addEventListenerWithDelegation(
document,
"touchstart",
this.targetSelector,
this.mouseOver,
),
Utils.addEventListenerWithDelegation(document, "touchstart", targetSelector, this.mouseOver),
);
_.extend(
this.delegatedEvents,
Utils.addEventListenerWithDelegation(
document,
"touchend",
this.targetSelector,
this.mouseOut,
),
Utils.addEventListenerWithDelegation(document, "touchend", targetSelector, this.mouseOut),
);
_.extend(
this.delegatedEvents,
Utils.addEventListenerWithDelegation(
document,
"wheel",
this.targetSelector,
this.mouseWheel,
{ passive: false },
),
Utils.addEventListenerWithDelegation(document, "wheel", targetSelector, this.mouseWheel, {
passive: false,
}),
);

this.hammerManager = new Hammer(this.domElement, {
this.hammerManager = new Hammer(domElement, {
inputClass: Hammer.TouchInput,
});
this.hammerManager.get("pan").set({ direction: Hammer.DIRECTION_ALL });
Expand Down Expand Up @@ -563,7 +533,7 @@ export class InputMouse {

getElementOffset() {
// Return the bounding rectangle relative to the top-left corner of the document
const boundingRect = this.domElement.getBoundingClientRect();
const boundingRect = document.getElementById(this.targetId).getBoundingClientRect();
return _.extend({}, boundingRect, {
left: boundingRect.left + window.scrollX,
top: boundingRect.top + window.scrollY,
Expand Down
6 changes: 3 additions & 3 deletions frontend/javascripts/libs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ export function addEventListenerWithDelegation(
) {
const wrapperFunc = function(event: Event) {
// $FlowFixMe Flow doesn't know native InputEvents
for (let target = event.target; target && target !== this; target = target.parentNode) {
for (let { target } = event; target && target !== this; target = target.parentNode) {
// $FlowFixMe Flow doesn't know native InputEvents
if (target.matches(delegateSelector)) {
handlerFunc.call(target, event);
Expand Down Expand Up @@ -554,9 +554,9 @@ export function waitForCondition(pred: () => boolean): Promise<void> {
return new Promise(tryToResolve);
}
export function waitForSelector(selector: string): Promise<*> {
export function waitForElementWithId(elementId: string): Promise<*> {
const tryToResolve = resolve => {
const el = document.querySelector(selector);
const el = document.getElementById(elementId);
if (el) {
resolve(el);
} else {
Expand Down
10 changes: 3 additions & 7 deletions frontend/javascripts/oxalis/controller/td_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,12 @@ class TDController extends React.PureComponent<Props> {

initMouse(): void {
const tdView = OrthoViews.TDView;
const inputcatcherSelector = `#inputcatcher_${tdView}`;
Utils.waitForSelector(inputcatcherSelector).then(view => {
const inputcatcherId = `inputcatcher_${tdView}`;
Utils.waitForElementWithId(inputcatcherId).then(view => {
if (!this.isStarted) {
return;
}
this.mouseController = new InputMouse(
inputcatcherSelector,
this.getTDViewMouseControls(),
tdView,
);
this.mouseController = new InputMouse(inputcatcherId, this.getTDViewMouseControls(), tdView);
this.initTrackballControls(view);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import getSceneController from "oxalis/controller/scene_controller_provider";
import messages from "messages";
import { downloadScreenshot } from "oxalis/view/rendering_utils";

const arbitraryViewportSelector = "#inputcatcher_arbitraryViewport";
const arbitraryViewportId = "inputcatcher_arbitraryViewport";

type Props = {|
viewMode: ViewMode,
Expand All @@ -70,6 +70,7 @@ class ArbitraryController extends React.PureComponent<Props> {
keyboardLoopDelayed?: InputKeyboard,
keyboardNoLoop?: InputKeyboardNoLoop,
};

storePropertyUnsubscribers: Array<Function>;

// Copied from backbone events (TODO: handle this better)
Expand All @@ -90,8 +91,8 @@ class ArbitraryController extends React.PureComponent<Props> {
}

initMouse(): void {
Utils.waitForSelector(arbitraryViewportSelector).then(() => {
this.input.mouseController = new InputMouse(arbitraryViewportSelector, {
Utils.waitForElementWithId(arbitraryViewportId).then(() => {
this.input.mouseController = new InputMouse(arbitraryViewportId, {
leftDownMove: (delta: Point2) => {
if (this.props.viewMode === constants.MODE_ARBITRARY) {
Store.dispatch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,21 @@ class PlaneController extends React.PureComponent<Props> {
}

initMouse(): void {
// Workaround: We are only waiting for tdview since this
// introduces the necessary delay to attach the events to the
// newest input catchers. We should refactor the
// Workaround: We are only waiting for tdview since this introduces
// the necessary delay to attach the events to the newest input
// catchers (only necessary for HammerJS). We should refactor the
// InputMouse handling so that this is not necessary anymore.
// See: https://github.com/scalableminds/webknossos/issues/3475
const tdSelector = `#inputcatcher_${OrthoViews.TDView}`;
Utils.waitForSelector(tdSelector).then(() => {
const tdId = `inputcatcher_${OrthoViews.TDView}`;
Utils.waitForElementWithId(tdId).then(() => {
OrthoViewValuesWithoutTDView.forEach(id => {
const inputcatcherSelector = `#inputcatcher_${OrthoViews[id]}`;
Utils.waitForSelector(inputcatcherSelector).then(el => {
const inputcatcherId = `inputcatcher_${OrthoViews[id]}`;
Utils.waitForElementWithId(inputcatcherId).then(el => {
if (!document.body.contains(el)) {
console.error("el is not attached anymore");
}
this.input.mouseControllers[id] = new InputMouse(
inputcatcherSelector,
inputcatcherId,
this.getPlaneMouseControls(id),
id,
);
Expand Down

0 comments on commit 6e1c67b

Please sign in to comment.