API Docs for: 0.25.0
Show:

File: addon/models/node.js

  1. import Ember from 'ember';
  2. import DS from 'ember-data';
  3. import OsfModel from './osf-model';
  4.  
  5. import FileItemMixin from 'ember-osf/mixins/file-item';
  6. import ContributorMixin from 'ember-osf/mixins/contributor-mixin';
  7. /**
  8. * @module ember-osf
  9. * @submodule models
  10. */
  11.  
  12. /**
  13. * Model for OSF APIv2 nodes. This model may be used with one of several API endpoints. It may be queried directly,
  14. * or accessed via relationship fields.
  15. * For field and usage information, see:
  16. * * https://api.osf.io/v2/docs/#!/v2/Node_List_GET
  17. * * https://api.osf.io/v2/docs/#!/v2/Node_Detail_GET
  18. * * https://api.osf.io/v2/docs/#!/v2/Node_Children_List_GET
  19. * * https://api.osf.io/v2/docs/#!/v2/Linked_Nodes_List_GET
  20. * * https://api.osf.io/v2/docs/#!/v2/Node_Forks_List_GET
  21. * * https://api.osf.io/v2/docs/#!/v2/User_Nodes_GET
  22. * @class Node
  23. */
  24. export default OsfModel.extend(FileItemMixin, ContributorMixin, {
  25. isNode: true,
  26.  
  27. title: DS.attr('fixstring'),
  28. description: DS.attr('fixstring'),
  29. category: DS.attr('fixstring'),
  30.  
  31. // List of strings
  32. currentUserPermissions: DS.attr(),
  33.  
  34. fork: DS.attr('boolean'),
  35. collection: DS.attr('boolean'),
  36. registration: DS.attr('boolean'),
  37. public: DS.attr('boolean'),
  38.  
  39. dateCreated: DS.attr('date'),
  40. dateModified: DS.attr('date'),
  41.  
  42. forkedDate: DS.attr('date'),
  43.  
  44. nodeLicense: DS.attr(),
  45. tags: DS.attr(),
  46.  
  47. templateFrom: DS.attr('fixstring'),
  48.  
  49. parent: DS.belongsTo('node', {
  50. inverse: 'children'
  51. }),
  52. children: DS.hasMany('nodes', {
  53. inverse: 'parent'
  54. }),
  55. preprints: DS.hasMany('preprints', {
  56. inverse: 'node'
  57. }),
  58. affiliatedInstitutions: DS.hasMany('institutions', {
  59. inverse: 'nodes'
  60. }),
  61. comments: DS.hasMany('comments'),
  62. contributors: DS.hasMany('contributors', {
  63. allowBulkUpdate: true,
  64. allowBulkRemove: true,
  65. inverse: 'node'
  66. }),
  67. citation: DS.belongsTo('citation'),
  68.  
  69. license: DS.belongsTo('license', {
  70. inverse: null
  71. }),
  72.  
  73. files: DS.hasMany('file-provider'),
  74. //forkedFrom: DS.belongsTo('node'),
  75. linkedNodes: DS.hasMany('nodes', {
  76. inverse: null,
  77. serializerType: 'linked-node'
  78. }),
  79. registrations: DS.hasMany('registrations', {
  80. inverse: 'registeredFrom'
  81. }),
  82.  
  83. draftRegistrations: DS.hasMany('draft-registrations', {
  84. inverse: 'branchedFrom'
  85. }),
  86.  
  87. forks: DS.hasMany('nodes', {
  88. inverse: 'forkedFrom'
  89. }),
  90.  
  91. forkedFrom: DS.belongsTo('node', {
  92. inverse: 'forks'
  93. }),
  94.  
  95. root: DS.belongsTo('node', {
  96. inverse: null
  97. }),
  98.  
  99. wikis: DS.hasMany('wikis', {
  100. inverse: 'node'
  101. }),
  102.  
  103. logs: DS.hasMany('logs'),
  104.  
  105. // These are only computeds because maintaining separate flag values on different classes would be a headache TODO: Improve.
  106. /**
  107. * Is this a project? Flag can be used to provide template-specific behavior for different resource types.
  108. * @property isProject
  109. * @type boolean
  110. */
  111. isProject: Ember.computed.equal('constructor.modelName', 'node'),
  112. /**
  113. * Is this a registration? Flag can be used to provide template-specific behavior for different resource types.
  114. * @property isRegistration
  115. * @type boolean
  116. */
  117. isRegistration: Ember.computed.equal('constructor.modelName', 'registration'),
  118.  
  119. /**
  120. * Is this node being viewed through an anonymized, view-only link?
  121. * @property isAnonymous
  122. * @type boolean
  123. */
  124. isAnonymous: Ember.computed.bool('meta.anonymous'),
  125.  
  126. addChild(title, description=null, category='project', isPublic) {
  127. let child = this.store.createRecord('node', {
  128. title,
  129. category,
  130. description,
  131. parent: this,
  132. public: isPublic
  133. });
  134.  
  135. return child.save();
  136. },
  137. });
  138.