client/entity-editor/relationship-editor/helper.js

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.setAttribute = exports.getInitAttribute = exports.getAttributeName = void 0;
require("core-js/modules/es.array.filter.js");
require("core-js/modules/es.object.to-string.js");
require("core-js/modules/es.array.map.js");
require("core-js/modules/es.function.name.js");
require("core-js/modules/es.array.includes.js");
require("core-js/modules/es.string.includes.js");
/*
 * Copyright (C) 2021  Akash Gupta
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

/**
 * A function to extract individual attribute object corresponding to a attribute id
 * from attributes array.
 *
 * @param {array} attributes - Array of attributes.
 * @param {number} id - Attribute id.
 * @returns {void}
 */
var getInitAttribute = function getInitAttribute(attributes, id) {
  var relAttribute = attributes.filter(function (attribute) {
    return attribute.attributeType === id;
  });
  if (relAttribute.length === 0) {
    return [];
  }
  return relAttribute[0];
};

/**
 * A function to insert all the individual attribute object(number, position etc) to
 * a array.
 *
 * @param {object} state - Relationship state.
 * @param {array} attributeTypes - All the attribute types associated with a relationship type.
 * @returns {array} Array of attributes.
 */
exports.getInitAttribute = getInitAttribute;
var setAttribute = function setAttribute(state, attributeTypes) {
  var attributes = attributeTypes.map(function (attribute) {
    return attribute.name;
  });
  var result = [];
  if (attributes.includes('number')) {
    result.push(state.attributeNumber);
  }
  if (attributes.includes('position')) {
    result.push(state.attributePosition);
  }
  return result;
};

/**
 * This function returns the attribute name corresponding
 * to a attribute ID.
 *
 * @param {number} id - Attribute ID.
 * @returns {string}  returns the attribute name.
 */
exports.setAttribute = setAttribute;
var getAttributeName = function getAttributeName(id) {
  switch (id) {
    case 1:
      return 'position';
    case 2:
      return 'number';
    default:
      return 'unnamed';
  }
};
exports.getAttributeName = getAttributeName;
//# sourceMappingURL=helper.js.map