forked from CenterForOpenScience/ember-osf-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
417 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
app/preprints/-components/preprint-file-render/component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import Component from '@glimmer/component'; | ||
import { inject as service } from '@ember/service'; | ||
import FileModel from 'ember-osf-web/models/file'; | ||
import PreprintProviderModel from 'ember-osf-web/models/preprint-provider'; | ||
import PreprintModel from 'ember-osf-web/models/preprint'; | ||
import Theme from 'ember-osf-web/services/theme'; | ||
import { tracked } from '@glimmer/tracking'; | ||
import { task } from 'ember-concurrency'; | ||
import { waitFor } from '@ember/test-waiters'; | ||
import { taskFor } from 'ember-concurrency-ts'; | ||
import FileVersionModel from 'ember-osf-web/models/file-version'; | ||
import Media from 'ember-responsive'; | ||
|
||
|
||
interface InputArgs { | ||
preprint: PreprintModel; | ||
provider: PreprintProviderModel; | ||
primaryFile: FileModel; | ||
} | ||
|
||
export interface VersionModel extends FileVersionModel { | ||
downloadUrl?: string; | ||
} | ||
|
||
export default class PreprintFileRender extends Component<InputArgs> { | ||
@service theme!: Theme; | ||
@service media!: Media; | ||
|
||
@tracked allowCommenting = false; | ||
@tracked primaryFileHasVersions = false; | ||
@tracked fileVersions: VersionModel[] = []; | ||
|
||
primaryFile = this.args.primaryFile; | ||
provider = this.args.provider; | ||
preprint = this.args.preprint; | ||
|
||
constructor(owner: unknown, args: InputArgs) { | ||
super(owner, args); | ||
|
||
taskFor(this.loadPrimaryFileVersions).perform(); | ||
|
||
this.allowCommenting = this.provider.allowCommenting && this.preprint.isPublished && this.preprint.public; | ||
} | ||
|
||
@task | ||
@waitFor | ||
private async loadPrimaryFileVersions() { | ||
const primaryFileVersions = (await this.primaryFile.queryHasMany('versions', { | ||
sort: '-id', 'page[size]': 50, | ||
})).toArray(); | ||
this.serializeVersions(primaryFileVersions); | ||
this.primaryFileHasVersions = primaryFileVersions.length > 0; | ||
} | ||
|
||
private serializeVersions(versions: FileVersionModel[]) { | ||
const downloadUrl = this.primaryFile.links.download as string || ''; | ||
|
||
versions.map((version: VersionModel) => { | ||
const dateFormatted = encodeURIComponent(version.dateCreated.toISOString()); | ||
const displayName = version.name.replace(/(\.\w+)?$/, ext => `-${dateFormatted}${ext}`); | ||
|
||
this.fileVersions.push( | ||
{ | ||
name: version.name, | ||
id: version.id, | ||
dateCreated: version.dateCreated, | ||
downloadUrl: `${downloadUrl}?version=${version.id}&displayName=${displayName}`, | ||
} as VersionModel, | ||
); | ||
return version; | ||
}); | ||
} | ||
|
||
get isMobile() { | ||
return this.media.isMobile; | ||
} | ||
} |
122 changes: 122 additions & 0 deletions
122
app/preprints/-components/preprint-file-render/styles.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
// stylelint-disable max-nesting-depth, selector-max-compound-selectors | ||
|
||
.file-renderer-container { | ||
width: 100%; | ||
height: 1150px; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: flex-start; | ||
justify-content: flex-start; | ||
|
||
.file-container { | ||
width: 100%; | ||
height: 1100px; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: flex-start; | ||
justify-content: flex-start; | ||
} | ||
|
||
.details-container { | ||
width: 100%; | ||
height: 50px; | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
justify-content: flex-start; | ||
|
||
.name-container { | ||
width: 60%; | ||
height: 50px; | ||
overflow: hidden; | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
justify-content: space-between; | ||
|
||
.name, | ||
.version { | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
justify-content: flex-start; | ||
height: 25px; | ||
} | ||
} | ||
|
||
.version-container { | ||
width: 40%; | ||
height: 50px; | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
justify-content: flex-end; | ||
|
||
.version-menu { | ||
background-color: $color-bg-white; | ||
border: 1px solid rgba(0, 0, 0, 0.15); | ||
border-radius: 4px; | ||
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175); | ||
padding: 5px; | ||
margin: 2px 0 0; | ||
|
||
ul { | ||
list-style: none; | ||
padding-inline-start: 0; | ||
} | ||
|
||
.li-container { | ||
margin-top: 10px; | ||
margin-bottom: 10px; | ||
|
||
.btn { | ||
display: inline-block; | ||
margin-bottom: 0; | ||
font-weight: 400; | ||
text-align: center; | ||
white-space: nowrap; | ||
touch-action: manipulation; | ||
cursor: pointer; | ||
background-image: none; | ||
border: 1px solid transparent; | ||
border-radius: 2px; | ||
padding: 6px 12px; | ||
font-size: 14px; | ||
line-height: 1.42857; | ||
user-select: none; | ||
vertical-align: middle; | ||
color: $color-text-white; | ||
} | ||
|
||
.btn-primary { | ||
color: $color-text-white; | ||
background-color: $color-bg-blue-dark; | ||
border-color: #2e6da4; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
&.mobile { | ||
height: 500px; | ||
|
||
.file-container { | ||
height: 400px; | ||
} | ||
|
||
.details-container { | ||
height: 100px; | ||
flex-direction: column; | ||
|
||
.version-container, | ||
.name-container { | ||
height: 50px; | ||
width: 100%; | ||
justify-content: center; | ||
align-items: flex-start; | ||
flex-direction: column; | ||
} | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
app/preprints/-components/preprint-file-render/template.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<div local-class='file-renderer-container {{if this.isMobile 'mobile'}}'> | ||
<div local-class='file-container'> | ||
<FileRenderer | ||
@allowCommenting={{this.allowCommenting}} | ||
@download={{this.primaryFile.links.download}} | ||
/> | ||
</div> | ||
|
||
<div local-class='details-container'> | ||
<div local-class='name-container'> | ||
<div data-test-selected-file-name local-class='name'> | ||
{{this.primaryFile.name}} | ||
</div> | ||
<div data-test-file-version local-class='version'> | ||
{{t 'preprints.detail.file_renderer.version'}}: {{this.primaryFile.currentVersion}} | ||
</div> | ||
</div> | ||
<div local-class='version-container'> | ||
{{#if this.primaryFileHasVersions}} | ||
<ResponsiveDropdown | ||
@renderInPlace={{true}} | ||
@buttonStyling={{true}} | ||
as |dd| | ||
> | ||
<dd.trigger> | ||
{{t 'preprints.detail.file_renderer.download_previous_versions'}} | ||
<span class='fa fa-caret-down'></span> | ||
</dd.trigger> | ||
<dd.content local-class='version-menu'> | ||
<ul role='menu' tabindex='-1'> | ||
{{#each this.fileVersions as |version|}} | ||
<li role='menuitem' local-class='li-container'> | ||
<OsfLink | ||
data-test-get-started-button | ||
data-analytics-name='Content - Download Previous Version' | ||
local-class='btn btn-primary' | ||
@href={{version.downloadUrl}} | ||
> | ||
{{t 'preprints.detail.file_renderer.version'}} {{version.id}}, {{moment-format version.dateCreated 'MM/DD/YYYY HH:mm:SS'}} | ||
</OsfLink> | ||
</li> | ||
{{/each}} | ||
</ul> | ||
</dd.content> | ||
</ResponsiveDropdown> | ||
{{/if}} | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.