Skip to content
Snippets Groups Projects
Commit 5411ef41 authored by Daviti Gogshelidze's avatar Daviti Gogshelidze
Browse files

Add download size and other buttons

parent a7243533
No related branches found
No related tags found
No related merge requests found
......@@ -120,15 +120,17 @@ datasetsRouter.post("/downloadParcellationThemself", (req,res, next) => {
var zip = new JSZip();
zip.file("Publications.txt", req.body['publicationsText'])
zip.file("credits.txt", req.body['publicationsText'])
zip.file("Terms of use.txt", termsOfUse)
//ToDo: Need to download files dynamicly. Nii folder should remove
if (req.body['fileName'].includes("JuBrain Cytoarchitectonic Atlas")) {
if (req.body['niiFiles']) {
var nii = zip.folder("nifti")
nii.file('jubrain-max-pmap-v22c_space-mnicolin27.nii', fs.readFileSync(path.join(__dirname, 'nii') + '/' + 'jubrain-max-pmap-v22c_space-mnicolin27.nii'))
req.body['niiFiles'].forEach(file => {
nii.file(file['file'], fs.readFileSync(path.join(__dirname, 'nii') + '/' + file['file']))
})
}
zip.generateAsync({type:"base64"})
......
......@@ -21,6 +21,7 @@ import { AGREE_COOKIE, AGREE_KG_TOS, SHOW_KG_TOS } from "src/services/state/uiSt
import { TabsetComponent } from "ngx-bootstrap/tabs";
import { ToastService } from "src/services/toastService.service";
import { ZipFileDownloadService } from "src/services/zipFileDownload.service";
import {forEach} from "@angular/router/src/utils/collection";
@Component({
selector: 'atlas-viewer',
......@@ -92,6 +93,8 @@ export class AtlasViewer implements OnDestroy, OnInit, AfterViewInit {
handleToast
tPublication
pPublication
downloadingProcess = false
niiFileSize = 0
get toggleMessage(){
return this.constantsService.toggleMessage
......@@ -221,6 +224,8 @@ export class AtlasViewer implements OnDestroy, OnInit, AfterViewInit {
this.subscriptions.push(
this.selectedParcellation$.subscribe(parcellation => {
this.selectedParcellation = parcellation
this.niiFileSize = 0
if (this.selectedTemplate && this.selectedParcellation) {
if (this.selectedTemplate['properties'] && this.selectedTemplate['properties']['publications']) {
......@@ -233,6 +238,12 @@ export class AtlasViewer implements OnDestroy, OnInit, AfterViewInit {
} else {
this.pPublication = null
}
if(this.selectedParcellation['properties'] && this.selectedParcellation['properties']['nifty']) {
this.selectedParcellation['properties']['nifty'].forEach(nii => {
this.niiFileSize += nii['size']
})
}
} else {
this.tPublication = null
this.pPublication = null
......@@ -247,7 +258,6 @@ export class AtlasViewer implements OnDestroy, OnInit, AfterViewInit {
this.handleToast = this.toastService.showToast(this.publications, {
timeout: 7000
})
}
})
)
......@@ -256,6 +266,8 @@ export class AtlasViewer implements OnDestroy, OnInit, AfterViewInit {
}
downloadPublications() {
this.downloadingProcess = true
const fileName = this.selectedTemplate.name + ' - ' + this.selectedParcellation.name
let publicationsText = ''
......@@ -274,7 +286,12 @@ export class AtlasViewer implements OnDestroy, OnInit, AfterViewInit {
});
}
this.zipFileDownloadService.downloadZip(publicationsText, fileName)
this.zipFileDownloadService.downloadZip(
publicationsText,
fileName,
this.selectedParcellation['properties'] && this.selectedParcellation['properties']['nifty']? this.selectedParcellation['properties']['nifty'] : 0).subscribe(data => {
this.downloadingProcess = false
})
publicationsText = ''
}
......
......@@ -287,7 +287,11 @@
<div class="download-buttons-panel">
<button mat-raised-button color="primary" class="downloadPublications" (click)="downloadPublications()">Explore &nbsp;<i class="fas fa-external-link-alt"></i></button>
<button mat-raised-button color="primary" class="downloadPublications" (click)="downloadPublications()">Download &nbsp;<i class="fas fa-download"></i></button>
<button mat-raised-button color="primary" class="downloadPublications" (click)="downloadPublications()" [disabled] = "downloadingProcess" >
Download &nbsp;
<span *ngIf="niiFileSize > 0">(.nii {{niiFileSize/10000 | number:'.1-2'}} Mb) &nbsp;</span>
<i class="fas" [ngClass]="!downloadingProcess? 'fa-download' :'fa-spinner fa-pulse'"></i>
</button>
</div>
</div>
</ng-template>
\ No newline at end of file
......@@ -8,22 +8,22 @@ import { ZipFileDownloadService } from "src/services/zipFileDownload.service";
styleUrls: [
'./radiolist.style.css'
],
// styles: [
// `
// ul > li.selected > .textSpan:before
// {
// content: '\u2022';
// width : 1em;
// display:inline-block;
// }
// ul > li:not(.selected) > .textSpan:before
// {
// content: ' ';
// width : 1em;
// display:inline-block;
// }
// `
// ],
styles: [
// `
// ul > li.selected > .textSpan:before
// {
// content: '\u2022';
// width : 1em;
// display:inline-block;
// }
// ul > li:not(.selected) > .textSpan:before
// {
// content: ' ';
// width : 1em;
// display:inline-block;
// }
// `
],
changeDetection: ChangeDetectionStrategy.OnPush
})
......@@ -50,12 +50,21 @@ export class RadioList{
@ViewChild('publicationTemplate') publicationTemplate: TemplateRef<any>
downloadingProcess = false
handleToast
niiFileSize = 0
constructor(private toastService: ToastService,
private zipFileDownloadService: ZipFileDownloadService) {}
showToast(item) {
this.niiFileSize = 0
if(item['properties']['nifty']) {
item['properties']['nifty'].forEach(nii => {
this.niiFileSize += nii['size']
})
}
if (this.handleToast) {
this.handleToast()
this.handleToast = null
......@@ -63,18 +72,20 @@ export class RadioList{
this.handleToast = this.toastService.showToast(this.publicationTemplate, {
timeout: 7000
})
}
downloadPublications(item) {
console.log(item['properties']['publications'])
this.downloadingProcess = true
const filename = item['name']
let publicationsText = item['name'] + ' Publications:\r\n'
item['properties']['publications'].forEach((p, i) => {
publicationsText += '\t' + (i+1) + '. ' + p['citation'] + ' - ' + p['doi'] + '\r\n'
});
this.zipFileDownloadService.downloadZip(publicationsText, filename)
this.zipFileDownloadService.downloadZip(publicationsText, filename, item['properties']['nifty']? item['properties']['nifty'] : 0).subscribe(data => {
this.downloadingProcess = false
})
publicationsText = ''
}
......
......@@ -26,17 +26,21 @@
</span>
<ng-template #publicationTemplate>
<div *ngIf="input['properties'] && input['properties']['publications']" class="timerToast">
<ng-template #publicationTemplate *ngIf="input['properties'] && input['properties']['publications']">
<div class="timerToast">
<p>{{input['name']}}</p>
<p class="textPartInPublications">{{input['properties']['description']}}</p>
<p>{{input['name']}} Publication(s)</p>
<p>Publication(s)</p>
<div *ngFor="let p of input['properties']['publications']" class="textPartInPublications">
<a [href]="p['doi']" target="_blank">{{p['citation']}}</a>
</div>
<div class="download-buttons-panel">
<button mat-raised-button color="primary" class="downloadPublications" (click)="downloadPublications()">Explore &nbsp;<i class="fas fa-external-link-alt"></i></button>
<button mat-raised-button color="primary" class="downloadPublications" (click)="downloadPublications()">Download &nbsp;<i class="fas fa-download"></i></button>
<button mat-raised-button color="primary" class="downloadPublications" (click)="downloadPublications(input)">Explore &nbsp;<i class="fas fa-external-link-alt"></i></button>
<button mat-raised-button color="primary" class="downloadPublications" (click)="downloadPublications(input)" [disabled] = "downloadingProcess" >
Download &nbsp;
<span *ngIf="niiFileSize > 0">(.nii {{niiFileSize/10000 | number:'.1-2'}} Mb) &nbsp;</span>
<i class="fas" [ngClass]="!downloadingProcess? 'fa-download' :'fa-spinner fa-pulse'"></i>
</button>
</div>
</div>
</ng-template>
......
This diff is collapsed.
This diff is collapsed.
import { Injectable } from "@angular/core";
import {HttpClient} from "@angular/common/http";
import {AtlasViewerConstantsServices} from "src/atlasViewer/atlasViewer.constantService.service";
import {map} from "rxjs/operators";
@Injectable({ providedIn: 'root' })
export class ZipFileDownloadService {
constructor(private httpClient: HttpClient, private constantService: AtlasViewerConstantsServices) {}
downloadZip(publicationsText, fileName) {
downloadZip(publicationsText, fileName, niiFiles) {
const correctedName = fileName.replace(/[|&;$%@"<>()+,/]/g, "")
this.httpClient.post(this.constantService.backendUrl + 'datasets/downloadParcellationThemself', {
return this.httpClient.post(this.constantService.backendUrl + 'datasets/downloadParcellationThemself', {
fileName: correctedName,
publicationsText: publicationsText,
niiFiles: niiFiles === 0 ? null : niiFiles
},{responseType: "text"}
).subscribe(data => {
this.downloadFile(data, correctedName)
})
).pipe(
map (data => {
this.downloadFile(data, correctedName)
})
)
}
downloadFile(data, fileName) {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment