cncjs

Форк
0
78 строк · 2.9 Кб
1
import difference from 'lodash/difference';
2
import includes from 'lodash/includes';
3
import union from 'lodash/union';
4
import React from 'react';
5
import ReactDOM from 'react-dom';
6
import { GRBL, MARLIN, SMOOTHIE, TINYG } from 'app/constants';
7
import controller from 'app/lib/controller';
8
import store from 'app/store';
9
import defaultState from 'app/store/defaultState';
10
import WidgetManager from './WidgetManager';
11

12
export const getActiveWidgets = () => {
13
  const defaultWidgets = store.get('workspace.container.default.widgets', [])
14
    .map(widgetId => widgetId.split(':')[0]);
15
  const primaryWidgets = store.get('workspace.container.primary.widgets', [])
16
    .map(widgetId => widgetId.split(':')[0]);
17
  const secondaryWidgets = store.get('workspace.container.secondary.widgets', [])
18
    .map(widgetId => widgetId.split(':')[0]);
19
  const activeWidgets = union(defaultWidgets, primaryWidgets, secondaryWidgets)
20
    .filter(widget => {
21
      if (widget === 'grbl' && !includes(controller.loadedControllers, GRBL)) {
22
        return false;
23
      }
24
      if (widget === 'marlin' && !includes(controller.loadedControllers, MARLIN)) {
25
        return false;
26
      }
27
      if (widget === 'smoothie' && !includes(controller.loadedControllers, SMOOTHIE)) {
28
        return false;
29
      }
30
      if (widget === 'tinyg' && !includes(controller.loadedControllers, TINYG)) {
31
        return false;
32
      }
33
      return true;
34
    });
35

36
  return activeWidgets;
37
};
38

39
export const getInactiveWidgets = () => {
40
  const allWidgets = Object.keys(defaultState.widgets);
41
  const defaultWidgets = store.get('workspace.container.default.widgets', [])
42
    .map(widgetId => widgetId.split(':')[0]);
43
  const primaryWidgets = store.get('workspace.container.primary.widgets', [])
44
    .map(widgetId => widgetId.split(':')[0]);
45
  const secondaryWidgets = store.get('workspace.container.secondary.widgets', [])
46
    .map(widgetId => widgetId.split(':')[0]);
47
  const inactiveWidgets = difference(allWidgets, defaultWidgets, primaryWidgets, secondaryWidgets)
48
    .filter(widget => {
49
      if (widget === 'grbl' && !includes(controller.loadedControllers, GRBL)) {
50
        return false;
51
      }
52
      if (widget === 'marlin' && !includes(controller.loadedControllers, MARLIN)) {
53
        return false;
54
      }
55
      if (widget === 'smoothie' && !includes(controller.loadedControllers, SMOOTHIE)) {
56
        return false;
57
      }
58
      if (widget === 'tinyg' && !includes(controller.loadedControllers, TINYG)) {
59
        return false;
60
      }
61
      return true;
62
    });
63

64
  return inactiveWidgets;
65
};
66

67
// @param {string} targetContainer The target container: primary|secondary
68
export const show = (callback) => {
69
  const el = document.body.appendChild(document.createElement('div'));
70
  const handleClose = (e) => {
71
    ReactDOM.unmountComponentAtNode(el);
72
    setTimeout(() => {
73
      el.remove();
74
    }, 0);
75
  };
76

77
  ReactDOM.render(<WidgetManager onSave={callback} onClose={handleClose} />, el);
78
};
79

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.