Skip to content

Commit

Permalink
Added logic to be able to version a file
Browse files Browse the repository at this point in the history
  • Loading branch information
bp-cos committed Jun 21, 2024
1 parent 73aab04 commit e8c5907
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 26 deletions.
26 changes: 26 additions & 0 deletions app/preprints/-components/preprint-file-display/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.display {
width: 100%;
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: flex-start;

.text {
width: calc(100% - 50px);
height: 30px;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
padding: 6px 0;
}

.action {
width: 50px;
height: 30px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}

}
26 changes: 26 additions & 0 deletions app/preprints/-components/preprint-file-display/template.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<div>
<h4 data-test-uploaded-file-label>
{{t 'preprints.submit.step-file.uploaded-file-title'}}
</h4>
<div local-class='display'>
<div local-class='text' data-test-uploaded-file-name>
{{ @file.name }}
</div>
{{#if @addNewFile}}
<div local-class='action'>
<DeleteButton
data-test-delete-button
@small={{true}}
@icon='trash'
@noBackground={{true}}
@delete={{action @addNewFile}}
@modalTitle={{t 'preprints.submit.step-file.delete-modal-title'}}
@modalBody={{t 'preprints.submit.step-file.delete-warning'}}
/>
<EmberTooltip>
{{t 'preprints.submit.step-file.delete-warning'}}
</EmberTooltip>
</div>
{{/if}}
</div>
</div>
6 changes: 3 additions & 3 deletions app/preprints/-components/preprint-node-display/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
{{#if this.loadNode.isRunning}}
<LoadingIndicator data-test-loading-indicator @dark={{true}} />
{{else}}
<h4>
<h4 data-test-uploaded-supplement-label>
{{t 'preprints.submit.step-review.supplement-title'}}
</h4>
<div local-class='display'>
<div local-class='text'>
<div local-class='text' data-test-uploaded-supplement-name>
{{ this.nodeDisplay}}
</div>
{{#if @removeNode}}
Expand All @@ -17,7 +17,7 @@
@icon='trash'
@noBackground={{true}}
@delete={{perform @removeNode}}
@modalTitle={{t 'preprints.submit.step-supplements.delete-modalTitle'}}
@modalTitle={{t 'preprints.submit.step-supplements.delete-modal-title'}}
@modalBody={{t 'preprints.submit.step-supplements.delete-warning'}}
/>
<EmberTooltip>
Expand Down
12 changes: 12 additions & 0 deletions app/preprints/-components/submit/file/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default class PreprintFile extends Component<FileArgs>{
@tracked isProjectSelectDisplayed = false;
@tracked isFileSelectDisplayed = false;
@tracked isFileAttached = false;
@tracked isEdit = false;
@tracked dragging = false;
@tracked file!: any;
@tracked selectedProjectNode!: NodeModel;
Expand Down Expand Up @@ -74,6 +75,17 @@ export default class PreprintFile extends Component<FileArgs>{
return this.isProjectSelectDisplayed || this.isFileUploadDisplayed;
}

@action
public async addNewfile(): Promise<void> {
this.isEdit = true;
this.file = null;
this.isFileAttached = false;
this.isFileUploadDisplayed = false;
this.isProjectSelectDisplayed = false;
this.isFileSelectDisplayed = false;
this.args.manager.validateFile(false);
}

@action
public onCancelSelectAction(): void {
this.isFileUploadDisplayed = false;
Expand Down
6 changes: 0 additions & 6 deletions app/preprints/-components/submit/file/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@
overflow: hidden;
white-space: nowrap;
}

h4 {
margin-top: 10px;
margin-bottom: 10px;
font-weight: bold;
}
}

.upload-container {
Expand Down
12 changes: 6 additions & 6 deletions app/preprints/-components/submit/file/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
{{else}}
{{#if this.isFileAttached}}
<div local-class='file-container'>
<h4 data-test-uploaded-file-label>
{{t 'preprints.submit.step-file.uploaded-file-title'}}
</h4>

<div local-class='file' data-test-uploaded-file-name>
{{this.file.name}}
<div local-class='file'>
<Preprints::-Components::PreprintFileDisplay
@file={{this.file}}
@addNewFile={{this.addNewfile}}
/>
</div>
</div>
{{else}}
Expand Down Expand Up @@ -55,6 +54,7 @@
@dragLeave={{fn (mut this.dragging) false}}
@drop={{fn (mut this.dragging) false}}
@validate={{action this.validate}}
@isEdit={{this.isEdit}}
>
<div
data-test-file-drag-and-drop-area
Expand Down
17 changes: 13 additions & 4 deletions app/preprints/-components/submit/file/upload-file/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface PreprintUploadArgs {
manager: PreprintStateMachine;
preprint: PreprintModel;
allowVersioning: boolean;
isEdit: boolean;
validate: (_: FileModel) => {};
clickableElementId: string;
dragEnter: () => {};
Expand Down Expand Up @@ -59,19 +60,27 @@ export default class PreprintUpload extends Component<PreprintUploadArgs> {
@task
@waitFor
async prepUrl() {
let urlString: string;
const theFiles = await this.args.preprint.files;
const rootFolder = await theFiles.firstObject!.rootFolder;
const urlString = await theFiles.firstObject!.links.upload as string;
const url = new URL( urlString );
this.url = url;
if(this.args.isEdit) {
const primaryFile = await this.args.preprint.primaryFile;
urlString = primaryFile?.links?.upload as string;
} else {
urlString = await theFiles.firstObject!.links.upload as string;
}

this.url = new URL( urlString );
this.rootFolder = rootFolder;
}

@action
buildUrl(files: any[]): string {
const { name } = files[0];
this.url!.searchParams.append('kind', 'file');
this.url!.searchParams.append('name', name);
if(!this.args.isEdit) {
this.url!.searchParams.append('name', name);
}
return this.url!.toString();
}

Expand Down
6 changes: 0 additions & 6 deletions app/preprints/-components/submit/supplements/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;

h4 {
margin-top: 10px;
margin-bottom: 10px;
font-weight: bold;
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion translations/en-us.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,8 @@ preprints:
file-upload-label-one: 'Drag and drop files here to upload'
file-upload-label-two: 'or click to browse for files.'
file-select-label: 'Select from an existing OSF project'
delete-modal-title: 'Add a new preprint file'
delete-warning: 'This will allow a new version of the preprint file to be uploaded to the preprint. The existing file will be retained as a version of the preprint.'
step-metadata:
title: 'Metadata'
contributors-input: 'Contributors'
Expand Down Expand Up @@ -1247,7 +1249,7 @@ preprints:
project-title: 'New project title for supplemental materials.'
create-button: 'Create a new OSF project'
create-project: 'Create project'
delete-modalTitle: 'Disconnect supplemental material'
delete-modal-title: 'Disconnect supplemental material'
delete-warning: 'This will disconnect the selected project. You can select new supplemental material or re-add the same supplemental material at a later date.'
step-review:
title: 'Review'
Expand Down

0 comments on commit e8c5907

Please sign in to comment.