Skip to content
Snippets Groups Projects
Commit 0bc83ec4 authored by Etxaniz Errazkin, Iñaki's avatar Etxaniz Errazkin, Iñaki
Browse files

Filtered dataset page

parent 95f6939a
No related branches found
No related tags found
No related merge requests found
......@@ -39,4 +39,4 @@ ENV DASHBOARD_BASE_URL=http://localhost:4200 \
TRAFFIC_SIMULATION_BASE_URL=http://localhost:8082/traffic-simulation \
TRAFFIC_SIMULATION_STORAGE_URL=http://localhost:8081 \
TRAFFIC_SIMULATION_DSS_URL=http://localhost:8083 \
TRAFFIC_SIMULATION_STOMP_URL=ws://localhost:8082/gs-guide-websocket
TRAFFIC_SIMULATION_STOMP_URL=ws://localhost:/gs-guide-websocket
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';
import { ConfigService } from '@ngx-config/core';
import { IDMUser } from '../oauth/model/idmuser';
......@@ -12,9 +12,11 @@ import { map } from 'rxjs/operators';
export class KeyrockUserInformationService {
apiURL: string;
client_id: string;
realm: string;
constructor(configService: ConfigService, private http: HttpClient) {
this.apiURL = configService.getSettings("idmBaseURL");
this.client_id = configService.getSettings("client_id");
this.realm = configService.getSettings("idmRealmName");
}
getRole(): Observable<string[]> {
......@@ -32,6 +34,13 @@ export class KeyrockUserInformationService {
getUser(): Observable<IDMUser> {
return this.http.get<IDMUser>(`${this.apiURL}/user`);
}
getUsers(): any {
let httpHeaders = new HttpHeaders( {"Access-Control-Allow-Origin": "*","Access-Control-Allow-Headers": "Origin, X-Requested-With, Content-Type, Accept, Authorization", "Access-Control-Allow-Methods": "GET, POST, PUT, OPTIONS, DELETE"});
return this.http.get(`${this.apiURL}/${this.realm}/users`, {
headers: httpHeaders,
} );
}
getLogoutUrl(): string {
return `${this.apiURL}/auth/external_logout?_method=DELETE&client_id=${this.client_id}`;
......
......@@ -3,6 +3,7 @@ import { RouterModule, Routes } from '@angular/router';
import { DataCatalogueComponent } from './data-catalogue.component';
import { DatasetComponent } from './dataset/dataset.component';
import { SearchComponent } from './search/search.component';
import {DatasetFilteredComponent} from './dataset-filtered/dataset-filtered.component';
const routes: Routes = [
{
......@@ -14,10 +15,15 @@ const routes: Routes = [
path: '',
component: SearchComponent
},
{
path:'filtered',
component: DatasetFilteredComponent
},
{
path:':id',
component: DatasetComponent
}]
},
]
}];
@NgModule({
......
......@@ -12,8 +12,9 @@ import { DistributionComponent } from './distribution/distribution.component';
import { MarkdownModule } from 'ngx-markdown';
import { DataletIframeComponent } from './datalet-iframe/datalet-iframe.component';
import { ShowDataletsComponent } from './show-datalets/show-datalets.component';
import { DatasetFilteredComponent } from './dataset-filtered/dataset-filtered.component';
@NgModule({
declarations: [DataCatalogueComponent, SearchComponent, DatasetComponent, DistributionComponent, DataletIframeComponent, ShowDataletsComponent],
declarations: [DataCatalogueComponent, SearchComponent, DatasetComponent, DistributionComponent, DataletIframeComponent, ShowDataletsComponent, DatasetFilteredComponent],
imports: [
ThemeModule,
NbFormFieldModule,
......
<div [nbSpinner]="loading" nbSpinnerSize="giant" nbSpinnerStatus="primary">
<div class="row" *ngIf="searchResponse.count>0">
<div class="col-12">
<!-- results -->
<nb-card *ngFor="let dataset of searchResponse.results | slice:0:10; let i=index" class="minicard">
<nb-card-header>
<a routerLink="/pages/datasets/{{dataset.id}}">{{dataset.title}}</a>
</nb-card-header>
<nb-card-body class="content-truncated">
<span class="truncated">{{dataset.description}}</span>
</nb-card-body>
<nb-card-footer>
<nb-tag-list size="small">
<nb-tag *ngFor="let tmp of dataset.distributionFormats" text="{{tmp.format}} ({{tmp.count}})" size="tiny" [style.background]="getColor(tmp.format)">
</nb-tag>
</nb-tag-list>
</nb-card-footer>
</nb-card>
</div>
</div>
</div>
.no-border{
border: none;
:first-child{
border: none;
}
}
.truncate {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.content-truncated {
width:100%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.minicard{
height:unset;
}
\ No newline at end of file
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { DatasetFilteredComponent } from './dataset-filtered.component';
describe('DatasetFilteredComponent', () => {
let component: DatasetFilteredComponent;
let fixture: ComponentFixture<DatasetFilteredComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ DatasetFilteredComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(DatasetFilteredComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { NbTagComponent, NbTagInputAddEvent } from '@nebular/theme';
import { DCATDataset,FormatCount } from '../model/dcatdataset';
import { ODMSCatalogueInfo } from '../model/odmscatalogue-info';
import { SearchFacet } from '../model/search-facet';
import { SearchFilter } from '../model/search-filter';
import { SearchRequest } from '../model/search-request';
import { SearchResult } from '../model/search-result';
import { DataCataglogueAPIService } from '../services/data-cataglogue-api.service';
import { NbLayoutScrollService } from '@nebular/theme';
import {KeyrockUserInformationService} from '../../../auth/services/keyrock-user-information.service';
import { OidcUserInformationService } from '../../../auth/services/oidc-user-information.service';
@Component({
selector: 'ngx-dataset-filtered',
templateUrl: './dataset-filtered.component.html',
styleUrls: ['./dataset-filtered.component.scss']
})
export class DatasetFilteredComponent implements OnInit {
separatorKeys:number[] = [13, 188];
searchResponse:SearchResult=new SearchResult();
searchRequest:SearchRequest=new SearchRequest();
cataloguesInfos: Array<ODMSCatalogueInfo>=[];
user: any;
tags: string[] = [];
constructor(private restApi:DataCataglogueAPIService, private nbScroll: NbLayoutScrollService,private userService: OidcUserInformationService, private keyrockUserInformationService: KeyrockUserInformationService ) { }
loading=false;
facetLimits={};
page: number = 1;
@Input()
totalDatasets:number=0;
filters: Array<string> = [];
filtersTags: Array<string>= [];
ngOnInit(): void {
this.userService.onUserChange()
.subscribe((user: any) => {
this.user = user;
if (this.user.hasOwnProperty('topics')) {
this.tags = this.user.topics.topics;
}
if (this.tags.length > 0) {
this.tags.forEach(element => {
this.searchDatasetOnTagsValue(element);
});
}
});
}
searchDatasetOnTagsValue(tag) {
this.searchRequest.nodes.push(1);
let index = this.searchRequest.filters.findIndex(x=> x.field==="ALL");
if(index<0){
this.searchRequest.filters.push(new SearchFilter("ALL",tag));
}else{
let filter=this.searchRequest.filters[index];
filter.value=tag;
}
this.searchOnFilter();
/* tags.forEach(element => {
console.log(element);
this.searchRequest.filters.push(new SearchFilter('ALL',element));
this.searchOnFilter();
});*/
}
searchOnFilter(){
this.restApi.searchDatasets(this.searchRequest).subscribe(
res=>{
// this.searchResponse=res
if (res.count > 0){
console.log(res);
console.log(this.searchResponse);
this.totalDatasets = this.totalDatasets + res.count;
let oldResult = this.searchResponse.results;
if (oldResult === undefined){
this.searchResponse=res;
this.searchResponse.results.map((x:DCATDataset)=>{ this.processDataset(x) })
} else {
console.log(oldResult);
let newResult = oldResult.concat(res.results);
console.log(newResult);
this.searchResponse.count= this.searchResponse.count + res.count;
this.searchResponse.results= newResult;
console.log(this.searchResponse);
this.searchResponse.results.map((x:DCATDataset)=>{ this.processDataset(x) })
}
this.loading=false;
}
},
err=>{
console.log(err);
this.loading=false;
});
}
processDataset(dataset:DCATDataset):DCATDataset{
let tmp=[];
dataset.distributionFormats=[];
for(let d of dataset.distributions){
if(tmp.indexOf(d.format)<0){
let fC=new FormatCount();
fC.format=d.format;
fC.count=1;
dataset.distributionFormats.push(fC);
tmp.push(d.format);
}else{
dataset.distributionFormats[tmp.indexOf(d.format)].count++;
}
}
dataset.description = dataset.description.replace(/\*/g,'').replace(/\\n/g,'')
.replace(/\(http.*\)/g,'').replace(/##\s*/g,'')
.replace(/<.*>(.*)<\/.*>/g,'$1')
.replace(/>/g,'').replace(/\[|\]/g,'')
return dataset;
}
getColor(format:string):string{
switch(format.toLowerCase()){
case 'csv':
return '#dfb100';
case 'html':
return '#55a1ce';
case 'json':
case 'xml':
return '#ef7100';
case 'text':
case 'txt':
return '#74cbec';
case 'xls':
case 'xlsx':
return '#2db55d';
case 'zip':
return '#686868';
case 'api':
return 'ec96be';
case 'pdf':
return '#e0051e';
case 'rdf':
case 'nquad':
case 'turtle':
case 'ntriples':
return '#0b4498';
case 'fiware':
case 'ngsi':
case 'ngsi-ld':
case 'fiware-ngsi':
case 'fiware-ngsi-ld':
return '#65c3d1';
default:
return 'default';
}
}
}
......@@ -174,6 +174,14 @@ export const MENU_ITEMS: NbMenuItem[] = [
name: "dashboard-management",
},
},
{
title: "Most relevant dataset",
icon: "search-outline",
link: "/pages/datasets/filtered",
data: {
name: "catalogues",
},
},
{
title: "Data Catalogue",
icon: "search-outline",
......
......@@ -14,7 +14,7 @@
"bike_analysis_api_base_url":"http://localhost:8001/urbanite_bikes",
"biketrajectory_api_base_url":"http://localhost:8000/biketrajectories",
"bus_od_api_base_url":"http://localhost:8000/busesod",
"idra_base_url":"http://localhost:8082",
"idra_base_url":"http://localhost:8080",
"traffic_simulation_base_url":"http://localhost:8082/traffic-simulation",
"traffic_simulation_storage_url":"http://localhost:8081",
"traffic_simulation_dss_url":"http://localhost:8083",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment