entities_attribute.js.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>JSDoc: Source: entities/attribute.js</title>
  6. <script src="scripts/prettify/prettify.js"> </script>
  7. <script src="scripts/prettify/lang-css.js"> </script>
  8. <!--[if lt IE 9]>
  9. <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  10. <![endif]-->
  11. <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
  12. <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
  13. </head>
  14. <body>
  15. <div id="main">
  16. <h1 class="page-title">Source: entities/attribute.js</h1>
  17. <section>
  18. <article>
  19. <pre class="prettyprint source linenums"><code>import promotedAttributeDefinitionParser from '../services/promoted_attribute_definition_parser.js';
  20. /**
  21. * Attribute is an abstract concept which has two real uses - label (key - value pair)
  22. * and relation (representing named relationship between source and target note)
  23. */
  24. class Attribute {
  25. constructor(froca, row) {
  26. this.froca = froca;
  27. this.update(row);
  28. }
  29. update(row) {
  30. /** @type {string} */
  31. this.attributeId = row.attributeId;
  32. /** @type {string} */
  33. this.noteId = row.noteId;
  34. /** @type {string} */
  35. this.type = row.type;
  36. /** @type {string} */
  37. this.name = row.name;
  38. /** @type {string} */
  39. this.value = row.value;
  40. /** @type {int} */
  41. this.position = row.position;
  42. /** @type {boolean} */
  43. this.isInheritable = !!row.isInheritable;
  44. }
  45. /** @returns {NoteShort} */
  46. getNote() {
  47. return this.froca.notes[this.noteId];
  48. }
  49. /** @returns {Promise&lt;NoteShort>} */
  50. async getTargetNote() {
  51. const targetNoteId = this.targetNoteId;
  52. return await this.froca.getNote(targetNoteId, true);
  53. }
  54. get targetNoteId() { // alias
  55. if (this.type !== 'relation') {
  56. throw new Error(`Attribute ${this.attributeId} is not a relation`);
  57. }
  58. return this.value;
  59. }
  60. get isAutoLink() {
  61. return this.type === 'relation' &amp;&amp; ['internalLink', 'imageLink', 'relationMapLink', 'includeNoteLink'].includes(this.name);
  62. }
  63. get toString() {
  64. return `Attribute(attributeId=${this.attributeId}, type=${this.type}, name=${this.name}, value=${this.value})`;
  65. }
  66. isDefinition() {
  67. return this.type === 'label' &amp;&amp; (this.name.startsWith('label:') || this.name.startsWith('relation:'));
  68. }
  69. getDefinition() {
  70. return promotedAttributeDefinitionParser.parse(this.value);
  71. }
  72. isDefinitionFor(attr) {
  73. return this.type === 'label' &amp;&amp; this.name === `${attr.type}:${attr.name}`;
  74. }
  75. get dto() {
  76. const dto = Object.assign({}, this);
  77. delete dto.froca;
  78. return dto;
  79. }
  80. }
  81. export default Attribute;
  82. </code></pre>
  83. </article>
  84. </section>
  85. </div>
  86. <nav>
  87. <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Attribute.html">Attribute</a></li><li><a href="Branch.html">Branch</a></li><li><a href="FrontendScriptApi.html">FrontendScriptApi</a></li><li><a href="module.exports.html">exports</a></li><li><a href="NoteComplement.html">NoteComplement</a></li><li><a href="NoteShort.html">NoteShort</a></li></ul><h3>Global</h3><ul><li><a href="global.html#doRenderBody">doRenderBody</a></li></ul>
  88. </nav>
  89. <br class="clear">
  90. <footer>
  91. Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.10</a>
  92. </footer>
  93. <script> prettyPrint(); </script>
  94. <script src="scripts/linenumber.js"> </script>
  95. </body>
  96. </html>