Skip to content
Snippets Groups Projects
Select Git revision
  • 4d0f1588bfc580c7e6b243e85d196e2bf8985013
  • master default protected
  • multiprocessing
  • experiment/clara
  • experiment/spec2B-poc
  • experiment/qivalio-poc
  • experiment/ertms
  • MAY-2023
  • FEB-2023
  • EGC-2023
  • 0.2.1
  • v0.2.0
  • v0.1.2
13 results

SolarSystemDev01_factoid.ttl

Blame
  • workspace.js 3.19 KiB
    import settings from '../../config/settings';
    import ActionTypes from '../actions/action-types';
    
    /** Check if the viewport dimensions are fully specified */
    function hasViewportPosition(viewportPosition) {
      return viewportPosition.x !== undefined
        && viewportPosition.y !== undefined
        && viewportPosition.width !== undefined
        && viewportPosition.height !== undefined;
    }
    
    /** Check if the containee is fully within the bounds on the container */
    function contains(container, containee) {
      return containee.x - containee.width / 2 > container.x - container.width / 2
        && containee.y - containee.height / 2 > container.y - container.height / 2
        && containee.x + containee.width / 2 < container.x + container.width / 2
        && containee.y + containee.height / 2 < container.y + container.height / 2;
    }
    
    /**
     * workspaceReducer
     */
    export const workspaceReducer = (
      state = settings.workspace,
      action,
    ) => {
      let newWorkspaceDimensions;
      let viewportPosition;
      switch (action.type) {
        case ActionTypes.UPDATE_WORKSPACE:
          return {
            ...state,
            ...action.config,
          };
        case ActionTypes.FOCUS_WINDOW:
          return {
            ...state,
            focusedWindowId: action.windowId,
            viewportPosition: {
              ...state.viewportPosition,
              ...action.position,
            },
          };
        case ActionTypes.ADD_WINDOW:
          return {
            ...state,
            focusedWindowId: action.window.id,
          };
        case ActionTypes.REMOVE_WINDOW:
          if (Object.keys(action.windows).length > 2) return state;
          return {
            ...state,
            focusedWindowId: Object.keys(action.windows).find(e => e !== action.windowId),
          };
        case ActionTypes.SET_WORKSPACE_FULLSCREEN:
          return { ...state, isFullscreenEnabled: action.isFullscreenEnabled };
        case ActionTypes.TOGGLE_ZOOM_CONTROLS:
          return { ...state, showZoomControls: action.showZoomControls };
        case ActionTypes.UPDATE_WORKSPACE_MOSAIC_LAYOUT:
          return { ...state, layout: action.layout };
        case ActionTypes.SET_WORKSPACE_ADD_VISIBILITY:
          return { ...state, isWorkspaceAddVisible: action.isWorkspaceAddVisible };
        case ActionTypes.SET_WORKSPACE_VIEWPORT_POSITION:
          newWorkspaceDimensions = {};
    
          viewportPosition = {
            ...state.viewportPosition,
            ...action.payload.position,
          };
    
          if (
            hasViewportPosition(viewportPosition)
            && !contains({
              height: state.height, width: state.width, x: 0, y: 0,
            }, viewportPosition)
          ) {
            newWorkspaceDimensions = {
              height: state.height * 2,
              width: state.width * 2,
            };
          }
    
          return {
            ...state,
            ...newWorkspaceDimensions,
            viewportPosition,
          };
        case ActionTypes.TOGGLE_WORKSPACE_EXPOSE_MODE:
          return { ...state, exposeModeOn: !state.exposeModeOn };
        case ActionTypes.SET_CONFIG:
        case ActionTypes.IMPORT_CONFIG:
        case ActionTypes.UPDATE_CONFIG:
          return { ...state, ...action.config.workspace };
        case ActionTypes.IMPORT_MIRADOR_STATE:
          return action.state.workspace || {};
        case ActionTypes.TOGGLE_DRAGGING:
          return { ...state, draggingEnabled: !state.draggingEnabled };
        default:
          return state;
      }
    };