Skip to content

Commit

Permalink
Added the feature to allowCommenting on a preprint document (#2082)
Browse files Browse the repository at this point in the history
* Added a min-height to the data-column for the preprint details page

* Fixed a typo in the template file

* Updated the file renderer to send a message to the iframe
  • Loading branch information
bp-cos committed Dec 8, 2023
1 parent 1cd8253 commit b0c2ab2
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 5 deletions.
1 change: 1 addition & 0 deletions app/config/environment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ declare const config: {
learnMoreUrl: string;
donateUrl: string;
renderUrl: string;
mfrUrl: string;
waterbutlerUrl: string;
helpUrl: string;
shareBaseUrl: string;
Expand Down
1 change: 1 addition & 0 deletions app/preprints/detail/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
.data-container {
padding: 30px;
width: 100%;
min-height: 1250px;
display: flex;
flex-direction: row;
justify-content: flex-start;
Expand Down
2 changes: 1 addition & 1 deletion app/preprints/detail/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
<OsfLink
data-test-supplemental-materials
data-analytics-name='supplemental material'
@href={{this.model.prepint.node.links.html}}
@href={{this.model.preprint.node.links.html}}
>
{{this.model.preprint.node.links.html}}
<FaIcon @icon='external-link-alt' />
Expand Down
2 changes: 2 additions & 0 deletions config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const {
OSF_API_URL: apiUrl = 'http://localhost:8000',
OSF_API_VERSION: apiVersion = '2.20',
OSF_RENDER_URL: renderUrl = 'http://localhost:7778/render',
OSF_MFR_URL: mfrUrl = 'http://localhost:4200',
OSF_FILE_URL: waterbutlerUrl = 'http://localhost:7777/',
OSF_HELP_URL: helpUrl = 'http://localhost:4200/help',
OSF_AUTHENTICATOR: osfAuthenticator = 'osf-cookie',
Expand Down Expand Up @@ -151,6 +152,7 @@ module.exports = function(environment) {
learnMoreUrl: 'https://cos.io/our-products/osf/',
donateUrl: 'https://cos.io/donate',
renderUrl,
mfrUrl,
waterbutlerUrl,
helpUrl,
shareBaseUrl,
Expand Down
27 changes: 25 additions & 2 deletions lib/osf-components/addon/components/file-renderer/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { tracked } from 'tracked-built-ins';

import template from './template';

const { OSF: { renderUrl } } = config;
const { OSF: { renderUrl, mfrUrl } } = config;

interface Params {
direct?: '';
Expand Down Expand Up @@ -46,6 +46,7 @@ export default class FileRenderer extends Component {
height = '100%';
allowfullscreen = true;
version?: number;
allowCommenting = false;
@tracked isLoading = true;

@computed('download', 'params', 'version')
Expand All @@ -64,7 +65,7 @@ export default class FileRenderer extends Component {
}

@computed('downloadUrl', 'isLoading')
get mfrUrl(): string {
get getMfrUrl(): string {
// Waiting until the iframe is loaded then changing the URL avoids a race condition in the MFR iframe
// This is most apparent in 3D files
const urlWithParams = new URL(renderUrl);
Expand All @@ -88,4 +89,26 @@ export default class FileRenderer extends Component {
next(this, () => this.set('isLoading', false));
}
}

private mfrOrigin(): string {
const urlParts = mfrUrl.split('/');
if (urlParts.length < 3) {
// if unable to extract mfr origin, just return config mfrUrl
return mfrUrl;
}

return `${urlParts[0]}//${urlParts[2]}`;
}

didRender() {
if (this.allowCommenting) {
const iframeElement = window.document.getElementsByTagName('iframe')[0];
iframeElement.addEventListener('load', () => {
iframeElement.contentWindow?.postMessage(
{type: 'startHypothesis', parentUrl: window.location.toString()},
this.mfrOrigin(),
);
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<LoadingIndicator @dark={{true}}/>
{{/if}}
<iframe
src={{this.mfrUrl}}
src={{this.getMfrUrl}}
width={{this.width}}
title={{t 'file-detail.mfr-iframe-title'}}
height={{this.height}}
Expand Down
1 change: 1 addition & 0 deletions mirage/fixtures/preprint-providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const preprintProviders: Array<Partial<PreprintProvider>> = [
assets: randomAssets(1),
footerLinks: 'fake footer links',
reviewsWorkflow: PreprintProviderReviewsWorkFlow.PRE_MODERATION,
allowCommenting: true,
},
{
id: 'thesiscommons',
Expand Down
2 changes: 1 addition & 1 deletion mirage/scenarios/preprints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function buildOSF(
public: true,
hasCoi: false,
isPreprintDoi: false,
isPublished: false,
isPublished: true,
}), 'isContributor');

const notPublishedPreprint = server.create('preprint', {
Expand Down

0 comments on commit b0c2ab2

Please sign in to comment.