API Docs for: 0.25.0
Show:

File: addon/components/eosf-project-nav/component.js

  1. import Ember from 'ember';
  2. import DS from 'ember-data';
  3.  
  4. import layout from './template';
  5.  
  6. import permissions from '../../const/permissions';
  7.  
  8. /**
  9. * @module ember-osf
  10. * @submodule components
  11. */
  12.  
  13. /**
  14. * Project header navigation bar, with links to various sub-pages within a project
  15. * Sample usage:
  16. * ```handlebars
  17. * {{eosf-project-nav
  18. * node=node
  19. * user=user}}
  20. * ```
  21. * @class eosf-project-nav
  22. */
  23. export default Ember.Component.extend({
  24. layout,
  25. i18n: Ember.inject.service(),
  26. node: null,
  27. user: null,
  28.  
  29. projectLabel: Ember.computed('node.category', function() {
  30. let category = this.get('node.category');
  31. return category === 'project' ? 'Project' : 'Component';
  32. }),
  33.  
  34. isProjectContributor: Ember.computed('user', 'node', function() {
  35. // Is the user a contributor on this node? (returns false if the user is not logged in)
  36. let node = this.get('node');
  37. let userID = this.get('user.id');
  38.  
  39. return DS.PromiseObject.create({
  40. promise: node.isContributor(userID)
  41. });
  42. }),
  43.  
  44. /**
  45. * If this is a withdrawn registration, hide a block of buttons.
  46. * @property isWithdrawnRegistration
  47. */
  48. isWithdrawnRegistration: Ember.computed.and('node.isRegistration', 'node.withdrawn'),
  49.  
  50. parentExists: Ember.computed('node', function() {
  51. // Determine if a parent exists (field not empty), without trying to fetch it.
  52. // This provides a way to use conditionals without errors that hang the page
  53. let node = this.get('node');
  54. return !!node.belongsTo('parent').link();
  55. }),
  56. showParentProjectLink: Ember.computed('node.parent', function() {
  57. // TODO: Rewrite this to rely on embeds, which are more efficient
  58. // If the parent node is not visible to the contributor, it will be identified in the API response, but not accessible.
  59. // Only show the parent link if the relationship resolves to a successful response.
  60. let parent = this.get('node.parent');
  61. if (parent) {
  62. // Report whether the parent relationship request failed.
  63. let response = parent.then(()=> true).catch(()=> false);
  64. return DS.PromiseObject.create({
  65. promise: response
  66. });
  67. }
  68. // If no parent, don't show parent link.
  69. return false;
  70. }),
  71. showAnalyticsTab: Ember.computed.or('node.public', 'isProjectContributor'),
  72. showRegistrationsTab: Ember.computed('node.isRegistration', 'node.isAnonymous', function() {
  73. // Do not show registrations tab for view-only links
  74. return !this.get('node.isRegistration') && !this.get('node.isAnonymous');
  75. }),
  76. showForksTab: Ember.computed.not('node.isAnonymous'),
  77. showContributorsTab: Ember.computed.alias('isProjectContributor'),
  78. showSettingsTab: Ember.computed('node', function() {
  79. let node = this.get('node');
  80. if (node.get('isProject')) {
  81. return node.get('currentUserPermissions').indexOf(permissions.WRITE) !== -1;
  82. } else if (node.get('isRegistration')) {
  83. return node.get('currentUserPermissions').indexOf(permissions.ADMIN) !== -1;
  84. }
  85. return false; // No idea what this resource is, so don't show tab
  86. }),
  87.  
  88. showCommentsButton: Ember.computed('node', function() {
  89. // TODO: Implement. Depends on resolution of https://openscience.atlassian.net/browse/OSF-6701
  90. // <!--% if user['can_comment'] or node['has_comments']:-->
  91. return false;
  92. })
  93. });
  94.