Skip to content
Snippets Groups Projects
Unverified Commit ff65fa2c authored by clmntsl's avatar clmntsl Committed by GitHub
Browse files

Merge pull request #407 from ProgrammeVitam/vas_item_8446_dip_report_download

[VAS] Téléchargement des rapports DIPs
parents e64441da 562c5379
No related branches found
No related tags found
1 merge request!51Merge mis a jour vitam-ui
...@@ -77,6 +77,11 @@ public class LogbookService { ...@@ -77,6 +77,11 @@ public class LogbookService {
private static final VitamUILogger LOGGER = VitamUILoggerFactory.getInstance(LogbookService.class); private static final VitamUILogger LOGGER = VitamUILoggerFactory.getInstance(LogbookService.class);
private static final String INGEST_TYPE = "INGEST"; private static final String INGEST_TYPE = "INGEST";
private static final String DIP_REPORT = "dip";
private static final String TRANSFER_REPORT = "transfersip";
private static final String BATCH_REPORT = "batchreport";
private static final String RULE_REPORT = "report";
private static final String OBJECT_REPORT = "object";
private final AccessExternalClient accessExternalClient; private final AccessExternalClient accessExternalClient;
...@@ -233,26 +238,24 @@ public class LogbookService { ...@@ -233,26 +238,24 @@ public class LogbookService {
public Response downloadReport(final String id, final String downloadType, final VitamContext vitamContext) throws VitamClientException { public Response downloadReport(final String id, final String downloadType, final VitamContext vitamContext) throws VitamClientException {
Response response; Response response;
switch (downloadType) { switch (downloadType) {
case "transfersip": case TRANSFER_REPORT:
response = accessExternalClient.getTransferById(vitamContext, id); response = accessExternalClient.getTransferById(vitamContext, id);
break; break;
case "dip": case DIP_REPORT:
response = accessExternalClient.getDIPById(vitamContext, id); response = accessExternalClient.getDIPById(vitamContext, id);
break; break;
case "batchreport": case BATCH_REPORT:
response = adminExternalClient.downloadBatchReport(vitamContext, id); response = adminExternalClient.downloadBatchReport(vitamContext, id);
break; break;
case "report": case RULE_REPORT:
response = adminExternalClient.downloadRulesReport(vitamContext, id); response = adminExternalClient.downloadRulesReport(vitamContext, id);
break; break;
case "object": case OBJECT_REPORT:
response = downloadAtr(id, vitamContext); response = downloadAtr(id, vitamContext);
break; break;
default: default:
response = null; response = null;
} }
return response; return response;
} }
} }
package fr.gouv.vitamui.commons.vitam.api.access; package fr.gouv.vitamui.commons.vitam.api.access;
import static org.mockito.Mockito.spy;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import javax.ws.rs.core.Response;
import fr.gouv.vitam.access.external.client.AccessExternalClient; import fr.gouv.vitam.access.external.client.AccessExternalClient;
import fr.gouv.vitam.access.external.client.AccessExternalClientFactory; import fr.gouv.vitam.access.external.client.AccessExternalClientFactory;
import fr.gouv.vitam.access.external.client.AdminExternalClient; import fr.gouv.vitam.access.external.client.AdminExternalClient;
...@@ -25,6 +14,20 @@ import fr.gouv.vitam.ingest.external.client.IngestExternalClientFactory; ...@@ -25,6 +14,20 @@ import fr.gouv.vitam.ingest.external.client.IngestExternalClientFactory;
import fr.gouv.vitamui.commons.api.exception.ApplicationServerException; import fr.gouv.vitamui.commons.api.exception.ApplicationServerException;
import fr.gouv.vitamui.commons.test.utils.ServerIdentityConfigurationBuilder; import fr.gouv.vitamui.commons.test.utils.ServerIdentityConfigurationBuilder;
import fr.gouv.vitamui.commons.vitam.api.util.VitamRestUtils; import fr.gouv.vitamui.commons.vitam.api.util.VitamRestUtils;
import org.apache.commons.io.IOUtils;
import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import javax.ws.rs.core.Response;
import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import static org.mockito.Mockito.spy;
@RunWith(MockitoJUnitRunner.class) @RunWith(MockitoJUnitRunner.class)
public class LogbookServiceTest { public class LogbookServiceTest {
...@@ -102,4 +105,17 @@ public class LogbookServiceTest { ...@@ -102,4 +105,17 @@ public class LogbookServiceTest {
logbookService.downloadAtr("vitamId", new VitamContext(10)); logbookService.downloadAtr("vitamId", new VitamContext(10));
} }
@Test
public void testDownloadDip_whenExportIsSuccess() throws Exception {
logbookService = spy(logbookService);
final LogbookOperation operation = new LogbookOperation();
operation.setEvTypeProc("DIP_EXPORT");
final Response response = logbookService.downloadReport("aeeaaaaaaggtywctaanl4al3q2moiyyaaaaq", "dip", new VitamContext(10));
VitamRestUtils.checkResponse(response, Response.Status.OK.getStatusCode());
String reportContent = IOUtils.toString(response.readEntity(ByteArrayInputStream.class), StandardCharsets.UTF_8);
Assertions.assertThat(reportContent).isEqualTo("test");
}
} }
...@@ -34,36 +34,36 @@ ...@@ -34,36 +34,36 @@
* The fact that you are presently reading this means that you have had * The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C license and that you accept its terms. * knowledge of the CeCILL-C license and that you accept its terms.
*/ */
import {HttpClient, HttpHeaders} from '@angular/common/http'; import {HttpClient,HttpHeaders} from '@angular/common/http';
import {Injectable} from '@angular/core'; import {Injectable} from '@angular/core';
import {Subject} from 'rxjs'; import {Subject} from 'rxjs';
import {Event, LogbookApiService, SearchService, VitamUISnackBar} from 'ui-frontend-common'; import {Event,LogbookApiService,SearchService,VitamUISnackBar} from 'ui-frontend-common';
import {VitamUISnackBarComponent} from '../shared/vitamui-snack-bar'; import {VitamUISnackBarComponent} from '../shared/vitamui-snack-bar';
const DOWNLOAD_TYPE_TRANSFER_SIP = 'transfersip'; const DOWNLOAD_TYPE_TRANSFER_SIP='transfersip';
const DOWNLOAD_TYPE_DIP = 'dip'; const DOWNLOAD_TYPE_DIP='dip';
const DOWNLOAD_TYPE_BATCH_REPORT = 'batchreport'; const DOWNLOAD_TYPE_BATCH_REPORT='batchreport';
const DOWNLOAD_TYPE_REPORT = 'report'; const DOWNLOAD_TYPE_REPORT='report';
const DOWNLOAD_TYPE_OBJECT = 'object'; const DOWNLOAD_TYPE_OBJECT='object';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class LogbookDownloadService extends SearchService<Event> { export class LogbookDownloadService extends SearchService<Event> {
updated = new Subject<Event>(); updated=new Subject<Event>();
constructor( constructor(
private logbookApiService: LogbookApiService, private logbookApiService: LogbookApiService,
private snackBar: VitamUISnackBar, private snackBar: VitamUISnackBar,
http: HttpClient) { http: HttpClient) {
super(http, logbookApiService); super(http,logbookApiService);
} }
isOperationInProgress(event: Event): boolean { isOperationInProgress(event: Event): boolean {
const status = this.getOperationStatus(event); const status=this.getOperationStatus(event);
switch (status) { switch(status) {
case 'STARTED': case 'STARTED':
case 'En cours': case 'En cours':
return true; return true;
...@@ -73,11 +73,11 @@ export class LogbookDownloadService extends SearchService<Event> { ...@@ -73,11 +73,11 @@ export class LogbookDownloadService extends SearchService<Event> {
} }
getOperationStatus(event: Event): string { getOperationStatus(event: Event): string {
const eventsLength = event.events.length; const eventsLength=event.events.length;
if (eventsLength > 0) { if(eventsLength>0) {
if (event.type === event.events[eventsLength - 1].type) { if(event.type===event.events[eventsLength-1].type) {
return event.events[eventsLength - 1].outcome; return event.events[eventsLength-1].outcome;
} else { } else {
return 'En cours'; return 'En cours';
} }
...@@ -87,16 +87,16 @@ export class LogbookDownloadService extends SearchService<Event> { ...@@ -87,16 +87,16 @@ export class LogbookDownloadService extends SearchService<Event> {
} }
canDownloadReports(event: Event): string[] { canDownloadReports(event: Event): string[] {
const evType = event.type.toUpperCase(); const evType=event.type.toUpperCase();
const evTypeProc = event.typeProc.toUpperCase(); const evTypeProc=event.typeProc.toUpperCase();
// tslint:disable-next-line: max-line-length // tslint:disable-next-line: max-line-length
const evTypeAllowed = ['STP_IMPORT_RULES', 'IMPORT_AGENCIES', 'HOLDINGSCHEME', 'IMPORT_ONTOLOGY', 'STP_REFERENTIAL_FORMAT_IMPORT', 'DATA_MIGRATION', 'ELIMINATION_ACTION', 'IMPORT_PRESERVATION_SCENARIO', 'IMPORT_GRIFFIN', 'STP_IMPORT_GRIFFIN', 'PRESERVATION', 'INGEST_CLEANUP']; const evTypeAllowed=['STP_IMPORT_RULES','IMPORT_AGENCIES','HOLDINGSCHEME','IMPORT_ONTOLOGY','STP_REFERENTIAL_FORMAT_IMPORT','DATA_MIGRATION','ELIMINATION_ACTION','IMPORT_PRESERVATION_SCENARIO','IMPORT_GRIFFIN','STP_IMPORT_GRIFFIN','PRESERVATION','INGEST_CLEANUP'];
const evTypeProcAllowed = ['AUDIT', 'EXPORT_DIP', 'ARCHIVE_TRANSFER', 'TRANSFER_REPLY', 'INGEST', 'MASS_UPDATE']; const evTypeProcAllowed=['AUDIT','EXPORT_DIP','ARCHIVE_TRANSFER','TRANSFER_REPLY','INGEST','MASS_UPDATE'];
if (evTypeProcAllowed.includes(evTypeProc) || evTypeAllowed.includes(evType)) { if(evTypeProcAllowed.includes(evTypeProc)||evTypeAllowed.includes(evType)) {
if (this.isOperationInProgress(event)) { if(this.isOperationInProgress(event)) {
return ['in-progress']; return ['in-progress'];
} else { } else {
return ['download']; return ['download'];
...@@ -106,13 +106,13 @@ export class LogbookDownloadService extends SearchService<Event> { ...@@ -106,13 +106,13 @@ export class LogbookDownloadService extends SearchService<Event> {
} }
} }
getDownloadType(eventTypeProc: string, eventType: string): string { getDownloadType(eventTypeProc: string,eventType: string): string {
switch (eventTypeProc) { switch(eventTypeProc) {
case 'AUDIT': case 'AUDIT':
if (eventType === 'EXPORT_PROBATIVE_VALUE' || eventType === 'RECTIFICATION_AUDIT') { if(eventType==='EXPORT_PROBATIVE_VALUE'||eventType==='RECTIFICATION_AUDIT') {
return DOWNLOAD_TYPE_REPORT; return DOWNLOAD_TYPE_REPORT;
} }
if (eventType === 'EVIDENCE_AUDIT' || eventType === 'PROCESS_AUDIT') { if(eventType==='EVIDENCE_AUDIT'||eventType==='PROCESS_AUDIT') {
return DOWNLOAD_TYPE_BATCH_REPORT; return DOWNLOAD_TYPE_BATCH_REPORT;
} }
case 'DATA_MIGRATION': case 'DATA_MIGRATION':
...@@ -129,7 +129,7 @@ export class LogbookDownloadService extends SearchService<Event> { ...@@ -129,7 +129,7 @@ export class LogbookDownloadService extends SearchService<Event> {
case 'ARCHIVE_TRANSFER': case 'ARCHIVE_TRANSFER':
return DOWNLOAD_TYPE_TRANSFER_SIP; return DOWNLOAD_TYPE_TRANSFER_SIP;
case 'MASTERDATA': case 'MASTERDATA':
switch (eventType) { switch(eventType) {
case 'STP_IMPORT_RULES': case 'STP_IMPORT_RULES':
case 'IMPORT_AGENCIES': case 'IMPORT_AGENCIES':
case 'IMPORT_ONTOLOGY': case 'IMPORT_ONTOLOGY':
...@@ -141,7 +141,7 @@ export class LogbookDownloadService extends SearchService<Event> { ...@@ -141,7 +141,7 @@ export class LogbookDownloadService extends SearchService<Event> {
return DOWNLOAD_TYPE_OBJECT; return DOWNLOAD_TYPE_OBJECT;
} }
case 'INTERNAL_OPERATING_OP': case 'INTERNAL_OPERATING_OP':
if (eventType === 'INGEST_CLEANUP') { if(eventType==='INGEST_CLEANUP') {
return DOWNLOAD_TYPE_BATCH_REPORT; return DOWNLOAD_TYPE_BATCH_REPORT;
} }
break; break;
...@@ -150,51 +150,54 @@ export class LogbookDownloadService extends SearchService<Event> { ...@@ -150,51 +150,54 @@ export class LogbookDownloadService extends SearchService<Event> {
} }
} }
downloadReport(event: Event, tenantIdentifier: number, accessContractId: string) { downloadReport(event: Event,tenantIdentifier: number,accessContractId: string) {
if (this.isOperationInProgress(event)) { if(this.isOperationInProgress(event)) {
return; return;
} }
const id = event.id;
this.snackBar.openFromComponent(VitamUISnackBarComponent, { const id=event.id;
this.snackBar.openFromComponent(VitamUISnackBarComponent,{
panelClass: 'vitamui-snack-bar', panelClass: 'vitamui-snack-bar',
duration: 10000, duration: 10000,
data: {type: 'eventExportAll'} data: {type: 'eventExportAll'}
}); });
var eventTypeProc = event.typeProc.toUpperCase(); var eventTypeProc=event.typeProc.toUpperCase();
var eventType = event.type.toUpperCase(); var eventType=event.type.toUpperCase();
var downloadType = this.getDownloadType(eventTypeProc, eventType); var downloadType=this.getDownloadType(eventTypeProc,eventType);
if(downloadType) { if(downloadType) {
const headers = new HttpHeaders({ const headers=new HttpHeaders({
'X-Tenant-Id': tenantIdentifier.toString(), 'X-Tenant-Id': tenantIdentifier.toString(),
'X-Access-Contract-Id': accessContractId 'X-Access-Contract-Id': accessContractId
}); });
this.logbookApiService.downloadReport(id, downloadType, headers).subscribe((response) => { this.logbookApiService.downloadReport(id,downloadType,headers).subscribe((response) => {
const element = document.createElement('a'); const element=document.createElement('a');
const blob = new Blob([response.body], {type: 'octet/stream'}); const blob=new Blob([response.body],{type: 'octet/stream'});
const url = window.URL.createObjectURL(blob); const url=window.URL.createObjectURL(blob);
element.href = url; element.href=url;
element.download = id + '.json'; element.download=id+'.json';
if (DOWNLOAD_TYPE_OBJECT == downloadType) { if(DOWNLOAD_TYPE_OBJECT==downloadType) {
element.download = id + '.xml'; element.download=id+'.xml';
}
if(DOWNLOAD_TYPE_BATCH_REPORT==downloadType) {
element.download=id+'.jsonl';
} }
if (DOWNLOAD_TYPE_BATCH_REPORT == downloadType) { if(DOWNLOAD_TYPE_DIP==downloadType) {
element.download = id + '.jsonl'; element.download=id+'.zip';
} }
element.click(); element.click();
window.URL.revokeObjectURL(url); window.URL.revokeObjectURL(url);
}, (error) => { },(error) => {
this.snackBar.open(error.error.message, null, { this.snackBar.open(error.error.message,null,{
panelClass: 'vitamui-snack-bar', panelClass: 'vitamui-snack-bar',
duration: 10000 duration: 10000
}); });
}); });
} else { } else {
this.snackBar.open('Impossible de télécharger le rapport pour cette opération', null, { this.snackBar.open('Impossible de télécharger le rapport pour cette opération',null,{
panelClass: 'vitamui-snack-bar', panelClass: 'vitamui-snack-bar',
duration: 10000 duration: 10000
}); });
......
...@@ -34,16 +34,22 @@ ...@@ -34,16 +34,22 @@
* The fact that you are presently reading this means that you have had * The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C license and that you accept its terms. * knowledge of the CeCILL-C license and that you accept its terms.
*/ */
import { AuthService, LogbookService } from 'ui-frontend-common'; import {HttpClientModule} from '@angular/common/http';
import {NO_ERRORS_SCHEMA,Pipe,PipeTransform} from '@angular/core';
import {ComponentFixture,TestBed,waitForAsync} from '@angular/core/testing';
import {MatSnackBarModule} from '@angular/material/snack-bar';
import {BrowserAnimationsModule,NoopAnimationsModule} from '@angular/platform-browser/animations';
import {ActivatedRoute} from '@angular/router';
import {RouterTestingModule} from '@angular/router/testing';
import {of} from 'rxjs';
import {AuthService,ExternalParametersService,InjectorModule,LogbookService,LoggerModule} from 'ui-frontend-common';
import {VitamUICommonTestModule} from 'ui-frontend-common/testing';
import {LogbookDownloadService} from '../logbook-download.service';
import {EventTypeBadgeClassPipe} from '../logbook-operation-list/event-type-badge-class.pipe';
import {LastEventPipe} from '../logbook-operation-list/last-event.pipe';
import {LogbookOperationDetailComponent} from './logbook-operation-detail.component';
import { NO_ERRORS_SCHEMA, Pipe, PipeTransform } from '@angular/core';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { ActivatedRoute } from '@angular/router';
import { EventTypeBadgeClassPipe } from '../logbook-operation-list/event-type-badge-class.pipe';
import { LastEventPipe } from '../logbook-operation-list/last-event.pipe';
import { LogbookOperationDetailComponent } from './logbook-operation-detail.component';
import {LogbookDownloadService} from '../logbook-download.service';
@Pipe({name: 'truncate'}) @Pipe({name: 'truncate'})
class MockTruncatePipe implements PipeTransform { class MockTruncatePipe implements PipeTransform {
...@@ -52,31 +58,48 @@ class MockTruncatePipe implements PipeTransform { ...@@ -52,31 +58,48 @@ class MockTruncatePipe implements PipeTransform {
} }
} }
describe('LogbookOperationDetailComponent', () => { describe('LogbookOperationDetailComponent',() => {
let component: LogbookOperationDetailComponent; let component: LogbookOperationDetailComponent;
let fixture: ComponentFixture<LogbookOperationDetailComponent>; let fixture: ComponentFixture<LogbookOperationDetailComponent>;
beforeEach(waitForAsync(() => { beforeEach(waitForAsync(() => {
const parameters: Map<string,string>=new Map<string,string>();
const externalParametersServiceMock={
getUserExternalParameters: () => of(parameters)
};
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [LogbookOperationDetailComponent,EventTypeBadgeClassPipe,LastEventPipe,MockTruncatePipe], declarations: [LogbookOperationDetailComponent,EventTypeBadgeClassPipe,LastEventPipe,MockTruncatePipe],
imports: [
MatSnackBarModule,
InjectorModule,
RouterTestingModule,
VitamUICommonTestModule,
BrowserAnimationsModule,
LoggerModule.forRoot(),
RouterTestingModule,
NoopAnimationsModule,
HttpClientModule
],
providers: [ providers: [
{ provide: LogbookService, useValue: {} }, {provide: LogbookService,useValue: {}},
{ provide: LogbookDownloadService, useValue: {} }, {provide: LogbookDownloadService,useValue: {}},
{ provide: AuthService, useValue: {} }, {provide: AuthService,useValue: {}},
{ provide: ActivatedRoute, useValue: {} }, {provide: ActivatedRoute,useValue: {}},
{provide: ExternalParametersService,useValue: externalParametersServiceMock}
], ],
schemas: [NO_ERRORS_SCHEMA] schemas: [NO_ERRORS_SCHEMA]
}) })
.compileComponents(); .compileComponents();
})); }));
beforeEach(() => { beforeEach(() => {
fixture = TestBed.createComponent(LogbookOperationDetailComponent); fixture=TestBed.createComponent(LogbookOperationDetailComponent);
component = fixture.componentInstance; component=fixture.componentInstance;
fixture.detectChanges(); fixture.detectChanges();
}); });
it('should create', () => { it('should create',() => {
expect(component).toBeTruthy(); expect(component).toBeTruthy();
}); });
}); });
...@@ -34,9 +34,10 @@ ...@@ -34,9 +34,10 @@
* The fact that you are presently reading this means that you have had * The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C license and that you accept its terms. * knowledge of the CeCILL-C license and that you accept its terms.
*/ */
import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core'; import {Component,EventEmitter,Input,OnChanges,OnInit,Output,SimpleChanges} from '@angular/core';
import { ActivatedRoute } from '@angular/router'; import {MatSnackBar} from '@angular/material/snack-bar';
import { AuthService, Event, fadeInOutAnimation, LogbookService } from 'ui-frontend-common'; import {ActivatedRoute} from '@angular/router';
import {AuthService,Event,ExternalParameters,ExternalParametersService,fadeInOutAnimation,LogbookService} from 'ui-frontend-common';
import {LogbookDownloadService} from '../logbook-download.service'; import {LogbookDownloadService} from '../logbook-download.service';
...@@ -48,14 +49,14 @@ import {LogbookDownloadService} from '../logbook-download.service'; ...@@ -48,14 +49,14 @@ import {LogbookDownloadService} from '../logbook-download.service';
fadeInOutAnimation fadeInOutAnimation
] ]
}) })
export class LogbookOperationDetailComponent implements OnInit, OnChanges { export class LogbookOperationDetailComponent implements OnInit,OnChanges {
@Input() eventId: string; @Input() eventId: string;
@Input() tenantIdentifier: number; @Input() tenantIdentifier: number;
@Input() isPopup: boolean; @Input() isPopup: boolean;
@Output() closePanel = new EventEmitter(); @Output() closePanel=new EventEmitter();
event: Event; event: Event;
loading: boolean; loading: boolean;
...@@ -63,23 +64,39 @@ export class LogbookOperationDetailComponent implements OnInit, OnChanges { ...@@ -63,23 +64,39 @@ export class LogbookOperationDetailComponent implements OnInit, OnChanges {
hideDownload: boolean; hideDownload: boolean;
canDownload: boolean; canDownload: boolean;
couldDownload: boolean; couldDownload: boolean;
accessContractId: string;
// tslint:disable-next-line: max-line-length // tslint:disable-next-line: max-line-length
constructor(private logbookService: LogbookService, private authService: AuthService, private route: ActivatedRoute, private logbookDownloadService: LogbookDownloadService) { constructor(private logbookService: LogbookService,private authService: AuthService,
private route: ActivatedRoute,private logbookDownloadService: LogbookDownloadService,
private externalParameterService: ExternalParametersService,private snackBar: MatSnackBar) {
} }
ngOnInit() { ngOnInit() {
this.externalParameterService.getUserExternalParameters().subscribe(parameters => {
const accessContratId: string=parameters.get(ExternalParameters.PARAM_ACCESS_CONTRACT);
if(accessContratId&&accessContratId.length>0) {
this.accessContractId=accessContratId;
} else {
this.snackBar.open(
$localize`:contrat d'accès non défini: Aucun contrat d'accès n'est associé à l'utiisateur`,
null,{
panelClass: 'vitamui-snack-bar',
duration: 10000
});
}
});
} }
ngOnChanges(changes: SimpleChanges) { ngOnChanges(changes: SimpleChanges) {
if (changes.eventId || changes.tenantIdentifier) { if(changes.eventId||changes.tenantIdentifier) {
this.refreshEvents(); this.refreshEvents();
} }
} }
openPopup() { openPopup() {
window.open('/logbook-operation/tenant/' + this.tenantIdentifier + '/event/' + this.event.id, window.open('/logbook-operation/tenant/'+this.tenantIdentifier+'/event/'+this.event.id,
'detailPopup', 'width=584, height=713, resizable=no, location=no'); 'detailPopup','width=584, height=713, resizable=no, location=no');
this.emitClose(); this.emitClose();
} }
...@@ -93,59 +110,52 @@ export class LogbookOperationDetailComponent implements OnInit, OnChanges { ...@@ -93,59 +110,52 @@ export class LogbookOperationDetailComponent implements OnInit, OnChanges {
downloadReports() { downloadReports() {
if (this.tenantIdentifier === null || this.tenantIdentifier === undefined || !this.eventId) { if(this.tenantIdentifier===null||this.tenantIdentifier===undefined||!this.eventId) {
return; return;
} }
this.logbookDownloadService.downloadReport(this.event,this.tenantIdentifier,this.accessContractId);
const tenant = this.authService.getTenantByAppAndIdentifier(this.route.snapshot.data.appId, this.tenantIdentifier);
if (!tenant) {
return;
}
const accessContractLogbookIdentifier = tenant.accessContractLogbookIdentifier || '';
this.logbookDownloadService.downloadReport(this.event, this.tenantIdentifier, accessContractLogbookIdentifier);
} }
updateCanDownload(event: Event) { updateCanDownload(event: Event) {
const canDownloadReports = this.logbookDownloadService.canDownloadReports(event); const canDownloadReports=this.logbookDownloadService.canDownloadReports(event);
this.hideDownload = canDownloadReports.length < 1; this.hideDownload=canDownloadReports.length<1;
if (!this.hideDownload) { if(!this.hideDownload) {
this.canDownload = canDownloadReports.includes('download'); this.canDownload=canDownloadReports.includes('download');
this.couldDownload = canDownloadReports.includes('in-progress'); this.couldDownload=canDownloadReports.includes('in-progress');
} else { } else {
this.canDownload = false; this.canDownload=false;
this.couldDownload = false; this.couldDownload=false;
} }
} }
private refreshEvents() { private refreshEvents() {
if (this.tenantIdentifier === null || this.tenantIdentifier === undefined || !this.eventId) { if(this.tenantIdentifier===null||this.tenantIdentifier===undefined||!this.eventId) {
return; return;
} }
const tenant = this.authService.getTenantByAppAndIdentifier(this.route.snapshot.data.appId, this.tenantIdentifier); const tenant=this.authService.getTenantByAppAndIdentifier(this.route.snapshot.data.appId,this.tenantIdentifier);
if (!tenant) { if(!tenant) {
return; return;
} }
const accessContractLogbookIdentifier = tenant.accessContractLogbookIdentifier || ''; const accessContractLogbookIdentifier=tenant.accessContractLogbookIdentifier||'';
this.loading = true; this.loading=true;
this.logbookService.getOperationById(this.eventId, this.tenantIdentifier, accessContractLogbookIdentifier) this.logbookService.getOperationById(this.eventId,this.tenantIdentifier,accessContractLogbookIdentifier)
.subscribe((event) => { .subscribe((event) => {
this.event = event; this.event=event;
this.loading = false; this.loading=false;
this.updateCanDownload(event); this.updateCanDownload(event);
if (event.events.length > 0 && event.events[0].data != null) { if(event.events.length>0&&event.events[0].data!=null) {
const data = JSON.parse(this.event.events[0].data); const data=JSON.parse(this.event.events[0].data);
if (data != null && data.FileName != null) { if(data!=null&&data.FileName!=null) {
this.reportFileName = data.FileName; this.reportFileName=data.FileName;
} else { } else {
this.reportFileName = null; this.reportFileName=null;
} }
} else { } else {
this.reportFileName = null; this.reportFileName=null;
} }
}); });
} }
......
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