API Docs for: 0.25.0
Show:

File: addon/models/preprint.js

  1. import Ember from 'ember';
  2. import DS from 'ember-data';
  3. import OsfModel from './osf-model';
  4. import ContributorMixin from 'ember-osf/mixins/contributor-mixin';
  5.  
  6. /**
  7. * @module ember-osf
  8. * @submodule models
  9. */
  10.  
  11. /**
  12. * Model for OSF APIv2 preprints. This model may be used with one of several API endpoints. It may be queried directly,
  13. * or accessed via relationship fields.
  14. * For field and usage information, see:
  15. * https://api.osf.io/v2/docs/#!/v2/Preprint_List_GET
  16. * https://api.osf.io/v2/docs/#!/v2/Preprint_Detail_GET
  17. * https://api.osf.io/v2/docs/#!/v2/User_Preprints_GET
  18. * @class Preprint
  19. */
  20. export default OsfModel.extend(ContributorMixin, {
  21.  
  22. title: DS.attr('fixstring'),
  23. // TODO: May be a relationship in the future pending APIv2 changes
  24. subjects: DS.attr(),
  25. dateCreated: DS.attr('date'),
  26. datePublished: DS.attr('date'),
  27. originalPublicationDate: DS.attr('date'),
  28. dateModified: DS.attr('date'),
  29. doi: DS.attr('fixstring'),
  30. isPublished: DS.attr('boolean'),
  31. isPreprintOrphan: DS.attr('boolean'),
  32. licenseRecord: DS.attr(),
  33. reviewsState: DS.attr('string'),
  34. dateLastTransitioned: DS.attr('date'),
  35. preprintDoiCreated: DS.attr('date'),
  36. description: DS.attr('fixstring'),
  37. tags: DS.attr(),
  38. public: DS.attr('boolean'),
  39. // List of strings
  40. currentUserPermissions: DS.attr(),
  41. dateWithdrawn: DS.attr('date'),
  42. withdrawalJustification: DS.attr('fixstring'),
  43.  
  44. // Relationships
  45. node: DS.belongsTo('node', { inverse: null, async: true }),
  46. license: DS.belongsTo('license', { inverse: null }),
  47. primaryFile: DS.belongsTo('file', { inverse: null }),
  48. provider: DS.belongsTo('preprint-provider', { inverse: 'preprints', async: true }),
  49. files: DS.hasMany('file-provider'),
  50. reviewActions: DS.hasMany('review-action', { inverse: 'target', async: true }),
  51. contributors: DS.hasMany('contributors', {
  52. allowBulkUpdate: true,
  53. allowBulkRemove: true,
  54. inverse: 'preprint'
  55. }),
  56. requests: DS.hasMany('preprint-requests', { inverse: 'target', async: true }),
  57. uniqueSubjects: Ember.computed('subjects', function() {
  58. if (!this.get('subjects')) return [];
  59. return this.get('subjects').reduce((acc, val) => acc.concat(val), []).uniqBy('id');
  60. }),
  61.  
  62. articleDoiUrl: Ember.computed.alias('links.doi'),
  63. preprintDoiUrl: Ember.computed.alias('links.preprint_doi'),
  64.  
  65. licenseText: Ember.computed('license', function() {
  66. const text = this.get('license.text') || '';
  67. const {year = '', copyright_holders = []} = this.get('licenseRecord');
  68.  
  69. return text
  70. .replace(/({{year}})/g, year)
  71. .replace(/({{copyrightHolders}})/g, copyright_holders.join(', '));
  72. }),
  73. });
  74.