Added path to contexts in dropdown widget

This commit is contained in:
Maria Teresa Paratore 2023-12-01 18:41:58 +01:00
parent a3e84a3185
commit b2786fb527
5 changed files with 63 additions and 10 deletions

View File

@ -19,6 +19,7 @@ import org.gcube.common.authorization.utils.secret.Secret;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.contexts.reference.entities.Context;
import org.gcube.informationsystem.contexts.reference.relations.IsParentOf;
import org.gcube.informationsystem.model.knowledge.ModelKnowledge;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
@ -85,6 +86,30 @@ public class InformationSystemService {
}
private String extractPath(Context ctx) {
String res = "/"+ctx.getName();
if(ctx.getParent()==null) {
return res;
}
Context dad = ctx.getParent().getSource();
res = "/"+ctx.getParent().getSource().getName()+res;
if(dad.getParent()==null) {
return res;
}
Context gdad = dad.getParent().getSource();
res = "/"+dad.getParent().getSource().getName()+res;
if(gdad.getParent()==null) {
return res;
}
Context g2dad = gdad.getParent().getSource();
res = "/"+gdad.getParent().getSource().getName()+res;
if(g2dad.getParent()==null) {
return res;
}
return res;
}
public List<ContextDTO> getAllContexts() throws Exception {
ArrayList<ContextDTO> res = new ArrayList<ContextDTO>();
@ -92,9 +117,18 @@ public class InformationSystemService {
ResourceRegistryClient resourceRegistryClient= ResourceRegistryClientFactory.create();
List<Context>contexts=resourceRegistryClient.getAllContext();
for(Context ctx:contexts) {
String pnt = " - "; //for the root
//TODO: da dove tiro fuori il path?
ContextDTO dto = new ContextDTO();
dto.setId(ctx.getID().toString());
dto.setName(ctx.getName());
if(ctx.getParent()!=null) {
if(ctx.getParent().getSource()!=null) {
pnt = ctx.getParent().getSource().getName();
}
}
dto.setParent(pnt);
dto.setPath(extractPath(ctx));
res.add(dto);
}
log.debug("AllContexts: {}",contexts);

View File

@ -10,4 +10,6 @@ import lombok.NoArgsConstructor;
public class ContextDTO {
private String id;
private String name;
private String parent;
private String path;
}

View File

@ -15,8 +15,6 @@
<jhi-rsc-tree id="leftTree" (resourceTypeEm)="buildTableData($event)"></jhi-rsc-tree>
</div>
</div>
</div>
<div class="col-md-9">
@ -37,7 +35,6 @@
</mat-form-field>
</div>
-->
<div>
<div class="d-inline-block my-3" ngbDropdown #myDrop="ngbDropdown" ></div>
@ -52,12 +49,9 @@
[formControl]="namefield"
/>
<mat-error>Please, enter a valid name!</mat-error>
<mat-autocomplete #auto="matAutocomplete" [panelWidth]=400
[displayWith]="displayFn.bind(this)">
<mat-autocomplete #auto="matAutocomplete" [panelWidth]=350 [displayWith]="displayFn.bind(this)">
<mat-option *ngFor="let fctx of filteredContexts | async" [value]="fctx">
<span>{{ fctx.name }}
<small> | ID: {{ fctx.id }}</small>
</span>
<span>{{ fctx.path }}</span>
</mat-option>
</mat-autocomplete>
</mat-form-field>
@ -68,6 +62,9 @@
<button mat-button (click)="copyUid(namefield)" color="primary" matTooltip="copy UUID" matTooltipPosition="below">
<mat-icon class="icon-wide2">content_copy</mat-icon>
</button>
<button mat-button color="primary" matTooltip="locate" matTooltipPosition="below">
<mat-icon class="icon-wide2">location_searching</mat-icon>
</button>
</form>

View File

@ -88,6 +88,24 @@ export class HomeComponent implements OnInit, OnDestroy {
);
}
/*
getContexts(): string[] {
if (this.account != null && this.account.resourceAccessDTO != null) {
// eslint-disable-next-line no-console
var sc=this.account.resourceAccessDTO.resourceAccess;
var contexts=Array.from(Object.keys(sc));
contexts=contexts.filter(element=>
element!==null&&element.startsWith("%2F"));
contexts=contexts.sort();
// eslint-disable-next-line no-console
console.log(contexts);
return contexts;
} else {
return [];
}
}
*/
//TODO: CHECK WHY UNSUBSCRIBE DOES NOT WORK
ngOnDestroy(): void {

View File

@ -1,4 +1,6 @@
export interface IContextNode{
name: string;
id: string;
parent: string;
path: string;
}