Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: bitmasking first pass #2301

Merged
merged 13 commits into from
Nov 24, 2023
2 changes: 0 additions & 2 deletions packages/client/hmi-client/src/services/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
WorkflowNode,
WorkflowPortStatus,
OperatorStatus,
OperatorInteractionStatus,
WorkflowPort
} from '@/types/workflow';
import { v4 as uuidv4 } from 'uuid';
Expand Down Expand Up @@ -69,7 +68,6 @@ export const addNode = (
})),
*/
status: OperatorStatus.INVALID,
interactionStatus: OperatorInteractionStatus.FOUND,

width: options?.size?.width ?? defaultNodeSize.width,
height: options?.size?.height ?? defaultNodeSize.height
Expand Down
15 changes: 8 additions & 7 deletions packages/client/hmi-client/src/types/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ export enum WorkflowOperationTypes {
CODE = 'Code'
}

export enum OperatorInteractionStatus {
FOCUS = 'focus', // Hover/drag
FOUND = 'found',
NOT_FOUND = 'not found'
}

export enum OperatorStatus {
DEFAULT = 'default',
IN_PROGRESS = 'in progress',
Expand All @@ -35,6 +29,14 @@ export enum OperatorStatus {
DISABLED = 'disabled'
}

// Multiple states can be on at once - using bitmasking
export enum OperatorInteractionStatus {
Found = 0x0001,
Hover = 0x0010,
Focus = 0x0100,
Drag = 0x1000
}

export enum WorkflowPortStatus {
CONNECTED = 'connected',
NOT_CONNECTED = 'not connected'
Expand Down Expand Up @@ -97,7 +99,6 @@ export interface WorkflowNode<S> {
state: S;

status: OperatorStatus;
interactionStatus: OperatorInteractionStatus;
}

export interface WorkflowEdge {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<header :class="`${status} ${interactionStatus}`">
<header :class="`${status} ${interactionClasses}`">
<h5>{{ name }}</h5>
<Button
icon="pi pi-ellipsis-v"
Expand All @@ -11,14 +11,14 @@
</template>

<script setup lang="ts">
import { ref, PropType } from 'vue';
import { OperatorInteractionStatus, OperatorStatus } from '@/types/workflow';
import { ref, PropType, computed } from 'vue';
import { OperatorStatus, OperatorInteractionStatus } from '@/types/workflow';
import Button from 'primevue/button';
import Menu from 'primevue/menu';

const emit = defineEmits(['remove-operator', 'bring-to-front', 'open-in-new-window']);

defineProps({
const props = defineProps({
name: {
type: String,
default: ''
Expand All @@ -28,11 +28,18 @@ defineProps({
default: OperatorStatus.DEFAULT
},
interactionStatus: {
type: String as PropType<OperatorInteractionStatus>,
default: OperatorInteractionStatus.FOUND
type: Number,
default: 0
}
});

const interactionClasses = computed(() => {
const classes: string[] = [];
// eslint-disable-next-line no-bitwise
if (props.interactionStatus & OperatorInteractionStatus.Drag) classes.push('focus');
return classes.join(' ');
});

const menu = ref();
const toggleMenu = (event) => {
menu.value.toggle(event);
Expand Down
29 changes: 23 additions & 6 deletions packages/client/hmi-client/src/workflow/tera-operator.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
<template>
<main :style="nodeStyle" ref="operator">
<main
:style="nodeStyle"
ref="operator"
@mouseenter="interactionStatus |= OperatorInteractionStatus.Hover"
@mouseleave="interactionStatus &= ~OperatorInteractionStatus.Hover"
shawnyama marked this conversation as resolved.
Show resolved Hide resolved
@focus="() => {}"
@focusout="() => {}"
>
<tera-operator-header
:name="node.displayName"
:status="node.status"
:interaction-status="interactionStatus"
@open-in-new-window="openInNewWindow"
@remove-operator="emit('remove-operator', props.node.id)"
@bring-to-front="bringToFront"
Expand Down Expand Up @@ -34,7 +42,13 @@
</template>

<script setup lang="ts">
import { Position, WorkflowNode, WorkflowDirection, WorkflowPort } from '@/types/workflow';
import {
Position,
WorkflowNode,
WorkflowDirection,
WorkflowPort,
OperatorInteractionStatus
} from '@/types/workflow';
import { ref, computed, onMounted, onBeforeUnmount } from 'vue';
import floatingWindow from '@/utils/floating-window';
import router from '@/router';
Expand Down Expand Up @@ -74,18 +88,20 @@ const nodeStyle = computed(() => ({
const portBaseSize: number = 8;
const operator = ref<HTMLElement>();

const interactionStatus = ref(0);
let tempX = 0;
let tempY = 0;
let dragStart = false;

const startDrag = (evt: MouseEvent) => {
tempX = evt.x;
tempY = evt.y;
dragStart = true;
// eslint-disable-next-line no-bitwise
interactionStatus.value |= OperatorInteractionStatus.Drag;
};

const drag = (evt: MouseEvent) => {
if (dragStart === false) return;
// eslint-disable-next-line no-bitwise
if (!(interactionStatus.value & OperatorInteractionStatus.Drag)) return;

const dx = evt.x - tempX;
const dy = evt.y - tempY;
Expand All @@ -103,7 +119,8 @@ const drag = (evt: MouseEvent) => {
const stopDrag = (/* evt: MouseEvent */) => {
tempX = 0;
tempY = 0;
dragStart = false;
// eslint-disable-next-line no-bitwise
interactionStatus.value &= ~OperatorInteractionStatus.Drag;
};

onMounted(() => {
Expand Down