Liferay.Loader.define("app-builder-web@1.0.76/js/pages/object/ListObjects.es", ['module', 'exports', 'require', 'frontend-js-react-web$react', 'app-builder-web$react-router-dom', '../../App.es', '../../components/control-menu/ControlMenu.es', '../../components/list-view/ListView.es', '../../components/permissions/PermissionsModal.es', '../../pages/entry/PermissionsContext.es', '../../utils/client.es', '../../utils/lang.es', '../../utils/time.es'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    function _typeof(obj) {
      "@babel/helpers - typeof";
      if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
        _typeof = function _typeof(obj) {
          return typeof obj;
        };
      } else {
        _typeof = function _typeof(obj) {
          return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
        };
      }return _typeof(obj);
    }

    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.default = void 0;

    var _react = _interopRequireWildcard(require("frontend-js-react-web$react"));

    var _reactRouterDom = require("app-builder-web$react-router-dom");

    var _App = require("../../App.es");

    var _ControlMenu = _interopRequireDefault(require("../../components/control-menu/ControlMenu.es"));

    var _ListView = _interopRequireDefault(require("../../components/list-view/ListView.es"));

    var _PermissionsModal = _interopRequireDefault(require("../../components/permissions/PermissionsModal.es"));

    var _PermissionsContext = require("../../pages/entry/PermissionsContext.es");

    var _client = require("../../utils/client.es");

    var _lang = require("../../utils/lang.es");

    var _time = require("../../utils/time.es");

    function _interopRequireDefault(obj) {
      return obj && obj.__esModule ? obj : { default: obj };
    }

    function _getRequireWildcardCache() {
      if (typeof WeakMap !== "function") return null;var cache = new WeakMap();_getRequireWildcardCache = function _getRequireWildcardCache() {
        return cache;
      };return cache;
    }

    function _interopRequireWildcard(obj) {
      if (obj && obj.__esModule) {
        return obj;
      }if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") {
        return { default: obj };
      }var cache = _getRequireWildcardCache();if (cache && cache.has(obj)) {
        return cache.get(obj);
      }var newObj = {};var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;for (var key in obj) {
        if (Object.prototype.hasOwnProperty.call(obj, key)) {
          var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;if (desc && (desc.get || desc.set)) {
            Object.defineProperty(newObj, key, desc);
          } else {
            newObj[key] = obj[key];
          }
        }
      }newObj.default = obj;if (cache) {
        cache.set(obj, newObj);
      }return newObj;
    }

    function _extends() {
      _extends = Object.assign || function (target) {
        for (var i = 1; i < arguments.length; i++) {
          var source = arguments[i];for (var key in source) {
            if (Object.prototype.hasOwnProperty.call(source, key)) {
              target[key] = source[key];
            }
          }
        }return target;
      };return _extends.apply(this, arguments);
    }

    function ownKeys(object, enumerableOnly) {
      var keys = Object.keys(object);if (Object.getOwnPropertySymbols) {
        var symbols = Object.getOwnPropertySymbols(object);if (enumerableOnly) symbols = symbols.filter(function (sym) {
          return Object.getOwnPropertyDescriptor(object, sym).enumerable;
        });keys.push.apply(keys, symbols);
      }return keys;
    }

    function _objectSpread(target) {
      for (var i = 1; i < arguments.length; i++) {
        var source = arguments[i] != null ? arguments[i] : {};if (i % 2) {
          ownKeys(Object(source), true).forEach(function (key) {
            _defineProperty(target, key, source[key]);
          });
        } else if (Object.getOwnPropertyDescriptors) {
          Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
        } else {
          ownKeys(Object(source)).forEach(function (key) {
            Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
          });
        }
      }return target;
    }

    function _defineProperty(obj, key, value) {
      if (key in obj) {
        Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true });
      } else {
        obj[key] = value;
      }return obj;
    }

    function _toConsumableArray(arr) {
      return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
    }

    function _nonIterableSpread() {
      throw new TypeError("Invalid attempt to spread non-iterable instance");
    }

    function _iterableToArray(iter) {
      if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
    }

    function _arrayWithoutHoles(arr) {
      if (Array.isArray(arr)) {
        for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
          arr2[i] = arr[i];
        }return arr2;
      }
    }

    function _slicedToArray(arr, i) {
      return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
    }

    function _nonIterableRest() {
      throw new TypeError("Invalid attempt to destructure non-iterable instance");
    }

    function _iterableToArrayLimit(arr, i) {
      if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) {
        return;
      }var _arr = [];var _n = true;var _d = false;var _e = undefined;try {
        for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
          _arr.push(_s.value);if (i && _arr.length === i) break;
        }
      } catch (err) {
        _d = true;_e = err;
      } finally {
        try {
          if (!_n && _i["return"] != null) _i["return"]();
        } finally {
          if (_d) throw _e;
        }
      }return _arr;
    }

    function _arrayWithHoles(arr) {
      if (Array.isArray(arr)) return arr;
    }

    var columns = [{
      editable: true,
      key: 'name',
      sortable: true,
      value: Liferay.Language.get('name')
    }, {
      key: 'dateCreated',
      sortable: true,
      value: Liferay.Language.get('create-date')
    }, {
      asc: false,
      key: 'dateModified',
      sortable: true,
      value: Liferay.Language.get('modified-date')
    }];

    var _default = function _default(_ref) {
      var history = _ref.history,
          _ref$listViewProps = _ref.listViewProps,
          listViewProps = _ref$listViewProps === void 0 ? {} : _ref$listViewProps,
          objectType = _ref.objectType;

      var _useState = (0, _react.useState)({
        dataDefinitionId: null,
        endpoint: null
      }),
          _useState2 = _slicedToArray(_useState, 2),
          objectPermissionsModalState = _useState2[0],
          setObjectPermissionsModalState = _useState2[1];

      var _listViewProps$action = listViewProps.actions,
          listViewActions = _listViewProps$action === void 0 ? [] : _listViewProps$action;
      var actions = [{
        action: function action(_ref2) {
          var id = _ref2.id;
          return Promise.resolve(history.push("/".concat(objectType, "/").concat(id, "/form-views")));
        },
        name: Liferay.Language.get('form-views')
      }, {
        action: function action(_ref3) {
          var id = _ref3.id;
          return Promise.resolve(history.push("/".concat(objectType, "/").concat(id, "/table-views")));
        },
        name: Liferay.Language.get('table-views')
      }, {
        action: function action(_ref4) {
          var id = _ref4.id;
          return Promise.resolve(history.push("/".concat(objectType, "/").concat(id, "/apps")));
        },
        name: Liferay.Language.get('apps')
      }, {
        name: 'divider'
      }, {
        action: function action(_ref5) {
          var id = _ref5.id;
          return Promise.resolve(setObjectPermissionsModalState(function (prevState) {
            return _objectSpread(_objectSpread({}, prevState), {}, {
              dataDefinitionId: id
            });
          }));
        },
        name: Liferay.Language.get('app-permissions')
      }].concat(_toConsumableArray(listViewActions));

      var dataDefinitionId = objectPermissionsModalState.dataDefinitionId;
      (0, _react.useEffect)(function () {
        if (!dataDefinitionId) {
          return;
        }

        (0, _client.getItem)("/o/data-engine/v2.0/data-definitions/".concat(dataDefinitionId, "/data-record-collection")).then(function (_ref7) {
          var dataRecordCollectionId = _ref7.id;
          setObjectPermissionsModalState(function (prevState) {
            return _objectSpread(_objectSpread({}, prevState), {}, {
              endpoint: "/o/data-engine/v2.0/data-record-collections/".concat(dataRecordCollectionId, "/permissions")
            });
          });
        });
      }, [dataDefinitionId, setObjectPermissionsModalState]);
      return (/*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_ControlMenu.default, {
          title: Liferay.Language.get('javax.portlet.title.com_liferay_app_builder_web_internal_portlet_ObjectsPortlet')
        }), /*#__PURE__*/_react.default.createElement(_App.AppNavigationBar, null), /*#__PURE__*/_react.default.createElement(_ListView.default, _extends({}, listViewProps, {
          actions: actions,
          columns: columns
        }), function (item) {
          var dateCreated = item.dateCreated,
              dateModified = item.dateModified,
              defaultLanguageId = item.defaultLanguageId,
              id = item.id,
              name = item.name;
          return _objectSpread(_objectSpread({}, item), {}, {
            dateCreated: (0, _time.fromNow)(dateCreated),
            dateModified: (0, _time.fromNow)(dateModified),
            name: /*#__PURE__*/_react.default.createElement(_reactRouterDom.Link, {
              to: "/".concat(objectType, "/").concat(id, "/form-views")
            }, (0, _lang.getLocalizedValue)(defaultLanguageId, name)),
            originalItem: item
          });
        }), /*#__PURE__*/_react.default.createElement(_PermissionsModal.default, {
          actions: [{
            key: _PermissionsContext.ACTIONS.ADD_DATA_RECORD,
            sortable: false,
            value: Liferay.Language.get('add-entry')
          }, {
            key: _PermissionsContext.ACTIONS.DELETE_DATA_RECORD,
            sortable: false,
            value: Liferay.Language.get('delete-entry')
          }, {
            key: _PermissionsContext.ACTIONS.UPDATE_DATA_RECORD,
            sortable: false,
            value: Liferay.Language.get('update-entry')
          }, {
            key: _PermissionsContext.ACTIONS.VIEW_DATA_RECORD,
            sortable: false,
            value: Liferay.Language.get('view-entries')
          }],
          endpoint: objectPermissionsModalState.endpoint,
          isOpen: dataDefinitionId !== null,
          onClose: function onClose() {
            return setObjectPermissionsModalState({
              dataDefinitionId: null,
              endpoint: null
            });
          },
          onSave: function onSave(permissions) {
            var dataDefinitionPermissions = [];
            Object.values(permissions).forEach(function (_ref8) {
              var actionIds = _ref8.actionIds,
                  roleName = _ref8.roleName;

              if (actionIds.length > 0) {
                dataDefinitionPermissions.push({
                  actionIds: [_PermissionsContext.ACTIONS.VIEW],
                  roleName: roleName
                });
              }
            });
            return (0, _client.updateItem)({
              endpoint: "/o/data-engine/v2.0/data-definitions/".concat(dataDefinitionId, "/permissions"),
              item: dataDefinitionPermissions
            });
          },
          rolesFilter: function rolesFilter(_ref6) {
            var name = _ref6.name,
                roleType = _ref6.roleType;
            return name !== 'Administrator' && name !== 'Guest' && name !== 'Owner' && roleType !== 'organization' && roleType !== 'site';
          },
          title: Liferay.Language.get('app-permissions')
        }))
      );
    };

    exports.default = _default;
    //# sourceMappingURL=ListObjects.es.js.map
  }
});
//# sourceMappingURL=ListObjects.es.js.map