Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/odd 1083 rpa datacart #306

Merged
merged 14 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/python-source.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
- 'python/**'
- 'scripts/*.py'
- 'scripts/**/*.py'
- 'oar-metadata'
jobs:
testall_python:
runs-on: ubuntu-20.04
Expand Down
49 changes: 28 additions & 21 deletions angular/src/app/_helpers/fakeBackendInterceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,44 @@ export class FakeBackendInterceptor implements HttpInterceptor {
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
// array in local storage for registered users

const sampleData: any = require('../../assets/science-theme/BiometricsScienceTheme.json');
const sampleRecord: any = require('../../assets/science-theme/DNAScienceTheme.json');

const biometricsData1: any = require('../../assets/science-theme/SDB-300.json');
const biometricsData2: any = require('../../assets/science-theme/SDB-301.json');
const biometricsData3: any = require('../../assets/science-theme/SDB-302.json');
const dna1: any = require('../../assets/science-theme/dna1.json');
const dna2: any = require('../../assets/science-theme/dna2.json');
const dna3: any = require('../../assets/science-theme/dna3.json');
const dna4: any = require('../../assets/science-theme/dna4.json');
const dna5: any = require('../../assets/science-theme/dna5.json');

const testdata: any = {
PageSize: 1,
ResultCount: 8,
ResultData: [biometricsData1,biometricsData2,biometricsData3,dna1,dna2,dna3,dna4,dna5]
}
// const sampleData: any = require('../../assets/science-theme/BiometricsScienceTheme.json');
// const sampleRecord: any = require('../../assets/science-theme/DNAScienceTheme.json');

// const biometricsData1: any = require('../../assets/science-theme/SDB-300.json');
// const biometricsData2: any = require('../../assets/science-theme/SDB-301.json');
// const biometricsData3: any = require('../../assets/science-theme/SDB-302.json');
// const dna1: any = require('../../assets/science-theme/dna1.json');
// const dna2: any = require('../../assets/science-theme/dna2.json');
// const dna3: any = require('../../assets/science-theme/dna3.json');
// const dna4: any = require('../../assets/science-theme/dna4.json');
// const dna5: any = require('../../assets/science-theme/dna5.json');
const rpa: any = require('../../assets/sample-data/rpa.json');
// const rpa: any = require('../../assets/sample-data/global_cart.json');

// const testdata: any = {
// PageSize: 1,
// ResultCount: 8,
// ResultData: [biometricsData1,biometricsData2,biometricsData3,dna1,dna2,dna3,dna4,dna5]
// }

// wrap in delayed observable to simulate server api call
return of(null).pipe(mergeMap(() => {
console.log("request.url", request.url);

// RPA
if (request.url.indexOf('/rpa') > -1 && request.method === 'GET') {
return of(new HttpResponse({ status: 200, body: rpa }));
}

// metrics
// if (request.url.indexOf('usagemetrics/files') > -1 && request.method === 'GET') {
// return of(new HttpResponse({ status: 200, body: metricsRecordDetails }));
// }

if (request.url.indexOf('isPartOf.@id=ark:/88434/mds9911') > -1 && request.method === 'GET') {
// console.log("Getting forensics")
return of(new HttpResponse({ status: 200, body: testdata }));
}
// if (request.url.indexOf('isPartOf.@id=ark:/88434/mds9911') > -1 && request.method === 'GET') {
// // console.log("Getting forensics")
// return of(new HttpResponse({ status: 200, body: testdata }));
// }

if (request.url.indexOf('usagemetrics/files') > -1 && request.method === 'GET')
{
Expand Down
1 change: 1 addition & 0 deletions angular/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ enableProdMode();
AppErrorHandler,
{ provide: ErrorHandler, useClass: AppErrorHandler },
GoogleAnalyticsService,
// fakeBackendProvider,
DatePipe
],
schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA]
Expand Down
30 changes: 21 additions & 9 deletions angular/src/app/datacart/bundleplan/bundleplan.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit, Input, Output, Inject, PLATFORM_ID, EventEmitter } from '@angular/core';
import { Component, OnInit, Input, Output, Inject, PLATFORM_ID, EventEmitter, SimpleChanges } from '@angular/core';
import { ZipData } from '../../shared/download-service/zipData';
import { TreeNode } from 'primeng/api';
import { DownloadService } from '../../shared/download-service/download-service.service';
Expand Down Expand Up @@ -100,12 +100,7 @@ export class BundleplanComponent implements OnInit {
}

ngOnInit() {
if(this.inBrowser) {
this.dataCartStatus = DataCartStatus.openCartStatus();

this.dataCart = this.cartService.getCart(this.cartName);
// watch this cart?
}
this.cartInit();

this.downloadService.watchDownloadProcessStatus().subscribe(
value => {
Expand All @@ -116,6 +111,23 @@ export class BundleplanComponent implements OnInit {
);
}

ngOnChanges(changes: SimpleChanges): void {
//Called before any other lifecycle hook. Use it to inject dependencies, but avoid any serious work here.
//Add '${implements OnChanges}' to the class.
if (changes.cartName) {
this.cartInit();
}
}

cartInit() {
if(this.inBrowser) {
this.dataCartStatus = DataCartStatus.openCartStatus();

this.dataCart = this.cartService.getCart(this.cartName);
// watch this cart?
}
}

/**
* Set the overall status to complete
*/
Expand All @@ -127,7 +139,7 @@ export class BundleplanComponent implements OnInit {

if (this.dataCart && this.downloadFiles) {
let title = (this.dataCart.isGlobalCart()) ? "Global Data Cart"
: this.downloadFiles[0].resTitle.substring(0,20)+"...";
: this.downloadFiles[0].resTitle? this.downloadFiles[0].resTitle.substring(0,20)+"..." : "No title...";
this.dataCartStatus.setDownloadCompleted(this.dataCart.getName(), title);
}

Expand Down Expand Up @@ -166,7 +178,7 @@ export class BundleplanComponent implements OnInit {
updateDownloadPercentage(percentage: number){
if (this.dataCart && this.downloadFiles) {
let title = (this.dataCart.isGlobalCart()) ? "Global Data Cart"
: this.downloadFiles[0].resTitle.substring(0,20)+"...";
: this.downloadFiles[0].resTitle? this.downloadFiles[0].resTitle.substring(0,20)+"..." : "No title...";

this.dataCartStatus.updateDownloadPercentage(this.dataCart.getName(), percentage, title);
}
Expand Down
44 changes: 43 additions & 1 deletion angular/src/app/datacart/cart.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { Observable } from 'rxjs';
import { DataCart } from '../datacart/cart';
import { HttpClientModule, HttpClient, HttpHeaders, HttpRequest, HttpEventType, HttpResponse } from '@angular/common/http';
import { AppConfig } from '../config/config';

interface CartLookup {
/**
Expand All @@ -19,8 +21,19 @@ interface CartLookup {
export class CartService {
public CART_CONSTANTS: any = CartConstants.cartConst;
carts : CartLookup = {};
rpaBackend: string;
portalBase: string;

constructor() { }
constructor(
private http: HttpClient,
private cfg: AppConfig,) {
this.rpaBackend = cfg.get("APIs.rpaBackend", "/unconfigured");
if (this.rpaBackend == "/unconfigured")
throw new Error("APIs.rpaBackend endpoint not configured!");

if (! this.rpaBackend.endsWith("/")) this.rpaBackend += "/"
this.portalBase = cfg.get("locations.portalBase", "/unconfigured");
}

/**
* return the cart instance with the given name. This is normally an EDIID for a
Expand All @@ -32,6 +45,35 @@ export class CartService {
return this.carts[name];
}

public getRpaCart(id: string, cartName: string) : Observable<any> {
let backend: string = this.rpaBackend + id;

return new Observable<any>(subscriber => {
return this._getRpaCart(backend).subscribe(
(result) => {
let data = {};
result.metadata.forEach((d) =>{
let key = cartName+'/'+d.filePath;
d['key'] = key;
d["isSelected"] = true;
data[key] = d;
})
let out: DataCart = new DataCart(cartName, data, null, 0);
subscriber.next(out);
subscriber.complete();
}, (err) =>{
console.log("err", err);
subscriber.next(null);
subscriber.complete();
}
)
})
}

public _getRpaCart(url: string) : Observable<any> {
return this.http.get(url);
}

/**
* return the instance of the global cart which can contain data files from many datasets
*/
Expand Down
6 changes: 6 additions & 0 deletions angular/src/app/datacart/cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export class DataCart {
let out: DataCart = new DataCart(id, data, store, (md != null) ? parseMD(md).updated : 0);
if (saveneeded)
out.save();

return out;
}

Expand Down Expand Up @@ -280,6 +281,11 @@ export class DataCart {
*/
public getName() : string { return this.cartName; }

/**
* Set the name of this cart
*/
public setName(cartName: string) { this.cartName = cartName; }

/**
* return true if this cart serves as the global data cart
*/
Expand Down
19 changes: 13 additions & 6 deletions angular/src/app/datacart/cartcontrol/cartcontrol.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ export class CartcontrolComponent implements OnInit, OnChanges {
}

ngOnInit() {
this.cartInit();
}

ngOnChanges(changes: SimpleChanges) {
// cart name should not change
// if (changes.cartName && this.datacart)
// this.cartName = this.datacart.getName();
if (changes.cartName) {
this.cartInit();
}
}

cartInit() {
if (this.cartName) {
this.datacart = this.cartService.getCart(this.cartName);
this.updateCounts();
Expand All @@ -46,12 +59,6 @@ export class CartcontrolComponent implements OnInit, OnChanges {
});
}
}

ngOnChanges(changes: SimpleChanges) {
// cart name should not change
if (changes.cartName && this.datacart)
this.cartName = this.datacart.getName();
}

updateCounts() : void {
if (! this.datacart) return;
Expand Down
6 changes: 3 additions & 3 deletions angular/src/app/datacart/datacart.component.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<!-- Top control panel -->
<app-cartcontrol [cartName]="dataCart.getName()" (onDownloadSelected)="downloadSelectedFiles($event)"
<app-cartcontrol [cartName]="datacartName" (onDownloadSelected)="downloadSelectedFiles($event)"
(onRemoveSelected)="removeSelectedFiles($event)"
(onRemoveDownloaded)="remvoeDownloadedFiles($event)">
</app-cartcontrol>

<!-- Bundle plan -->
<app-bundleplan #bundler [cartName]="dataCart.getName()"
<app-bundleplan #bundler [cartName]="datacartName"
(outputOverallStatus)="updateCartOperationalStatus($event)">
</app-bundleplan>

<!-- Tree table -->
<app-treetable [cartName]="dataCart.getName()"></app-treetable>
<app-treetable [cartName]="datacartName" [forceReload]="forceReload"></app-treetable>
39 changes: 33 additions & 6 deletions angular/src/app/datacart/datacart.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export class DatacartComponent implements OnInit, AfterViewInit {
zipData: ZipData[] = [];

overallStatus: string = "";
datacartName: string = "";
forceReload: boolean = false;

@ViewChild('bundler', { static: true })
bundler : BundleplanComponent;
Expand All @@ -50,18 +52,43 @@ export class DatacartComponent implements OnInit, AfterViewInit {
@Inject(PLATFORM_ID) private platformId: Object )
{
this.inBrowser = isPlatformBrowser(platformId);

this.route.params.subscribe(params => {
let cartName = params['cartname'];
let id: string = "";
if(cartName == 'rpa'){
if(this.inBrowser) {
this.route.queryParams.subscribe(params => {
console.log("param", params);
id = params["id"];
})

this.cartService.getRpaCart(id, cartName).subscribe((result: DataCart) => {
let dataCart01 = result;
this.dataCart = this.cartService.getCart(cartName);
this.dataCart.contents = dataCart01.contents;
this.datacartName = cartName;
this.forceReload = true;

//Trigger propagateSelectionUp and propagateSelectionDown
//so all check boxes will be checked
setTimeout(() => {
this.dataCart.save();
}, 0);
})
}
}else{
this.datacartName = cartName;
this.dataCart = this.cartService.getCart(cartName);
this.datacartName = this.dataCart.getName();
}
});
}

/**
* Get the params OnInit
*/
ngOnInit(): void {
let currentUrl = this.router.url;

this.route.params.subscribe(params => {
let cartName = params['cartname'];
this.dataCart = this.cartService.getCart(cartName);
});
}

/**
Expand Down
4 changes: 2 additions & 2 deletions angular/src/app/datacart/treetable/treetable.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
</td>
<td [ngStyle]="bodyStyle(sizeWidth)">
<div *ngIf="rowData.cartItem;else space_holder" style="display:inline;color: green;" >
<a *ngIf="rowData.cartItem.downloadStatus != 'downloading'" href='{{rowData.cartItem.downloadURL}}' target='_blank' download="download" data-toggle="tooltip"
<a *ngIf="rowData.cartItem.downloadStatus != 'downloading'" href='{{rowData.cartItem.downloadURL}}' target='_blank' rel="noopener" download="download" data-toggle="tooltip"
title="Download this file" aria-label="Download this file">
<i class="faa faa-download"
aria-hidden="true" (click)="setFileDownloaded(rowData)"></i>
Expand Down Expand Up @@ -99,7 +99,7 @@
<ng-template pTemplate="emptymessage">
<tr>
<td align="center" colspan="3">
No records found
<!-- No records found -->
</td>
</tr>
</ng-template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { GoogleAnalyticsService } from '../../shared/ga-service/google-analytics
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { TestDataService } from '../../shared/testdata-service/testDataService';
import { TreeTableModule } from 'primeng/treetable';
import { AppConfig } from '../../config/config';
import { config, testdata } from '../../../environments/environment';

describe('CartTreeNode', () => {
it('constructor', () => {
Expand Down Expand Up @@ -176,6 +178,7 @@ describe('CartTreeNode', () => {
describe('TreetableComponent', () => {
let component: TreetableComponent;
let fixture: ComponentFixture<TreetableComponent>;
let cfg : AppConfig = new AppConfig(config);

beforeEach(waitForAsync(() => {
let dc: DataCart = DataCart.openCart("goob");
Expand All @@ -198,7 +201,8 @@ describe('TreetableComponent', () => {
CartService,
DownloadService,
TestDataService,
GoogleAnalyticsService]
GoogleAnalyticsService,
{ provide: AppConfig, useValue: cfg }]
})
.compileComponents();
}));
Expand Down
Loading
Loading