Skip to content

Commit

Permalink
More alerts and MAXFILES validation
Browse files Browse the repository at this point in the history
  • Loading branch information
vilarodr committed Mar 19, 2024
1 parent 8b50ccf commit 8ee9048
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 48 deletions.
18 changes: 8 additions & 10 deletions src/index-renderer/components/data-files-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export class DataFilesInput extends Cmp<HTMLDivElement, HTMLFormElement> {
}

configure():void {
this.MAXFILES = 2000;
const regexp = /[:;#<>"\*\?\/\|]/ ;
const regexp2 = /[^A-Za-z0-9_ .\/\-]+/ ;

Expand All @@ -66,13 +65,12 @@ export class DataFilesInput extends Cmp<HTMLDivElement, HTMLFormElement> {
this.backdropElement.style.visibility = "hidden";

ipcRenderer.on('DO_FILE_SELECT', (event: Event, folder: string, filesCount: number) => {
if (this.isDSSelected) {
if (this.isDSSelected()) {
this.filesButtonElement.disabled = false;
} else {
this.filesButtonElement.disabled = true;
}
//dataFiles.clear();
this.remainingFiles = this.MAXFILES - filesCount;
dataFiles.clear();
})

ipcRenderer.on('FILE_SELECT_DONE', (event: Event, enteredFiles: FileInfo[]) => {
Expand All @@ -87,7 +85,7 @@ export class DataFilesInput extends Cmp<HTMLDivElement, HTMLFormElement> {
}
});
if (dataFiles.length()) {
if (this.isDSSelected) {
if (this.isDSSelected()) {
this.submitButtonElement.disabled = false;
}
this.resetButtonElement.disabled = false;
Expand All @@ -96,17 +94,17 @@ export class DataFilesInput extends Cmp<HTMLDivElement, HTMLFormElement> {
})

ipcRenderer.on('DO_FOLDER_SELECT', (event: Event, folder: string, filesCount: number) => {
if (this.isDSSelected) {
if (this.isDSSelected()) {
this.folderButtonElement.disabled = false;
} else {
this.folderButtonElement.disabled = true;
}
this.remainingFiles = this.MAXFILES - filesCount;
dataFiles.clear();
})

ipcRenderer.on('FOLDER_SELECT_DONE', (event: Event, enteredFiles: FileInfo[]) => {
this.clearView();
if (enteredFiles.length) {
if (enteredFiles.length) {;
let lastPath = '';
const files = Array.from(enteredFiles);
enteredFiles.forEach((file) => {
Expand All @@ -124,7 +122,7 @@ export class DataFilesInput extends Cmp<HTMLDivElement, HTMLFormElement> {
}
});
if (dataFiles.length()) {
if (this.isDSSelected) {
if (this.isDSSelected()) {
this.submitButtonElement.disabled = false;
}
this.resetButtonElement.disabled = false;
Expand Down Expand Up @@ -260,4 +258,4 @@ export class DataFilesInput extends Cmp<HTMLDivElement, HTMLFormElement> {
this.modalElement.classList.remove("show");
}

}
}
1 change: 1 addition & 0 deletions src/index-renderer/components/user-dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export class UserDataset extends Cmp<HTMLDivElement, HTMLDivElement> {

private refreshHandler(event: Event) {
event.preventDefault();
(document.getElementById("upload") as HTMLButtonElement).disabled = true;
ipcRenderer.send('DO_DS_LIST_REFRESH');
}

Expand Down
25 changes: 19 additions & 6 deletions src/main/controllers/upload-controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { calcChecksum, getUploadUrls, uploadSinglepartToStore, uploadMultipartToStore, completeMultipartUpload, abortMultipartUpload, addMultipleFilesToDataset } from '../services/upload-service';

import { FileInfo } from '../../model/file-info';
import { IpcMainEvent, Notification } from "electron";
import { IpcMainEvent, Notification, dialog } from "electron";
import { Observable } from 'rxjs';

let abort = false;
Expand Down Expand Up @@ -49,7 +49,7 @@ export const filesTransfer = (event: IpcMainEvent, persistentId: string, items:
}
} catch (err) {
const title = `Error uploading file ${itemInfo.name} to store.`
new Notification({ title: title, body: err }).show();
alert(title, err);
event.sender.send('actionFor' + itemInfo.id.toString(), 'fail', 0);
itemsFailed++;
continue;
Expand Down Expand Up @@ -84,7 +84,7 @@ export const filesTransfer = (event: IpcMainEvent, persistentId: string, items:
}
} catch (err) {
const title = `Error uploading file ${itemInfo.name} to store.`
new Notification({ title: title, body: err }).show();
alert(title, err);
event.sender.send('actionFor' + itemInfo.id.toString(), 'fail', 0);
itemsFailed++;
continue;
Expand All @@ -104,7 +104,7 @@ export const filesTransfer = (event: IpcMainEvent, persistentId: string, items:
}
} catch (err) {
const title = `Error uploading part of file ${itemInfo.name} to store.`
new Notification({ title: title, body: err }).show();
alert(title, err);
throw new Error(title + '\n' + err);
}
const responseHeaders = JSON.parse(JSON.stringify(uploadToStoreResponse.headers));
Expand All @@ -125,7 +125,7 @@ export const filesTransfer = (event: IpcMainEvent, persistentId: string, items:
};
} catch (err) {
const title = 'Error aborting multipart upload.';
new Notification({ title: title, body: err }).show();
alert(title, err);
throw new Error(title + '\n' + err);
}
} else {
Expand All @@ -136,7 +136,7 @@ export const filesTransfer = (event: IpcMainEvent, persistentId: string, items:
}
} catch (err) {
const title = 'Error completing multipart upload to store.';
new Notification({ title: title, body: err }).show();
alert(title, err);
throw new Error(title + '\n' + err);
}
itemInfo.etag = await calcChecksum(itemInfo);
Expand Down Expand Up @@ -177,3 +177,16 @@ export const filesTransfer = (event: IpcMainEvent, persistentId: string, items:
}
)
}

function alert(message: string, detail: string) {
console.log(message);
new Notification({ title: 'Upverse upload alert', body: message }).show();
const options = {
buttons: ['OK'],
defaultId: 0,
title: 'Upverse upload alert',
message: message,
detail: detail,
};
dialog.showMessageBox(null, options);
}
2 changes: 1 addition & 1 deletion src/main/controllers/user-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const getUserDatasets = () => {
selectedPage++;
await getMyDatasetsPage(selectedPage).then((responseBody: Datasets) => {
responseBody.data.items.forEach((item: Item) => {
const datasetInfo = new DatasetInfo(item.name, item.global_id, responseBody.data.dvobject_counts.files_count);
const datasetInfo = new DatasetInfo(item.name, item.global_id, item.fileCount);
datasetList.push(Object.assign({}, datasetInfo));
})
nextPage = responseBody.data.pagination.nextPageNumber;
Expand Down
13 changes: 13 additions & 0 deletions src/main/interfaces/repository-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,22 @@ export interface Item {
description: string;
published_at: Date;
citationHtml: string;
identifier_of_dataverse: string;
name_of_dataverse: string;
citation: string;
matches: any[];
score: number;
entity_id: number;
storageIdentifier: string;
subjects: any[];
fileCount: number;
versionId: number;
versionState: string;
majorVersion: number;
minorVersion: number;
createdAt: Date;
updatedAt: Date;
contacts: {}[];
api_url: string;
authors: string[];
publication_statuses: string[];
Expand All @@ -40,6 +52,7 @@ export interface Item {
is_unpublished_state: boolean;
is_published: boolean;
is_deaccesioned: boolean;
is_valid: boolean;
date_to_display_on_card: string;
parentId: string;
parentName: string;
Expand Down
Loading

0 comments on commit 8ee9048

Please sign in to comment.