Skip to content

Commit

Permalink
Merge pull request #804 from gisaia/fix/fga
Browse files Browse the repository at this point in the history
Update configuration using FGA base on each collection
  • Loading branch information
MohamedHamouGisaia authored and Mohamed Hamou committed Jun 27, 2024
2 parents 710a710 + 2cb991b commit b663277
Show file tree
Hide file tree
Showing 11 changed files with 284 additions and 96 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<ng-container *ngIf="shortcut">
<ng-container *ngIf="shortcut && shortcut.component">
<div class="container" id="{{'shortcut-' + shortcut.uuid}}">
<section #title class="title" [class.open_title]="isOpen" (click)="toggle()"
[style.min-width.px]="shortcutWidth / 2">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class FilterShortcutComponent implements OnInit {
if (this.isOpen) {
this.activateContributor();
}
this.inputs = Object.assign({}, this.shortcut.component.input);
this.inputs = Object.assign({}, this.shortcut?.component?.input);
this.setHistogramInput();
this.setPowerbarsInput();
}
Expand All @@ -96,8 +96,10 @@ export class FilterShortcutComponent implements OnInit {
}

private activateContributor(): Contributor {
const contributor: Contributor = this.collaborativeSearchService.registry.get(this.shortcut.component.contributorId);
contributor.updateData = true;
const contributor: Contributor = this.collaborativeSearchService.registry.get(this.shortcut?.component?.contributorId);
if (contributor) {
contributor.updateData = true;
}
return contributor;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="arlas-search-container">
<div class="arlas-search-container" *ngIf="searchContributor">
<mat-icon class="search">search</mat-icon>
<div class="search-text" [class.search-text-empty]="searchValue === searchPlaceholder" (click)="openDialog()">
{{ searchValue }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ export class SearchComponent implements OnInit, OnDestroy, OnChanges {
public ngOnInit(): void {
// Retrieve value from the url and future collaborations
this.retrieveSearchValueSub = this.collaborativeService.collaborationBus.pipe(
filter(e => this.searchContributor.isMyOwnCollaboration(e) || e.id === 'url' || e.id === 'all')
filter(e => this.searchContributor?.isMyOwnCollaboration(e) || e.id === 'url' || e.id === 'all')
).subscribe(
e => {
const collaboration = this.collaborativeService.getCollaboration(this.searchContributor.identifier);
const collaboration = this.collaborativeService.getCollaboration(this.searchContributor?.identifier);
if (collaboration) {
collaboration.filters.forEach((f, collection) => {
let initSearchValue = '';
Expand Down Expand Up @@ -129,7 +129,7 @@ export class SearchComponent implements OnInit, OnDestroy, OnChanges {
enabled: true
};

this.collaborativeService.setFilter(this.searchContributor.identifier, collaboration);
this.collaborativeService.setFilter(this.searchContributor?.identifier, collaboration);
}
}

Expand Down Expand Up @@ -161,7 +161,7 @@ export class SearchComponent implements OnInit, OnDestroy, OnChanges {

public clearSearch() {
this.searchValue = this.searchPlaceholder;
this.collaborativeService.removeFilter(this.searchContributor.identifier);
this.collaborativeService.removeFilter(this.searchContributor?.identifier);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,7 @@

</arlas-metric>
</div>

<div *ngIf="componentType === 'metricstable'">
<arlas-metrics-table [multiBarTable]="contributor.data"></arlas-metrics-table>
</div>

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"resultlist",
"swimlane",
"tree",
"metric"
"metric",
"metricstable"
]
}
}
Expand Down Expand Up @@ -155,6 +156,19 @@
"then": {
"$ref": "computeContributorConf.schema.json#"
}
},
{
"if": {
"type": "object",
"properties": {
"type": {
"const": "metricstable"
}
}
},
"then": {
"$ref": "metricsTableContributorConf.schema.json#"
}
}
]
}
Expand Down Expand Up @@ -224,7 +238,8 @@
"swimlane",
"resultlist",
"donut",
"metric"
"metric",
"metricstable"
]
},
"title": {
Expand Down Expand Up @@ -343,6 +358,23 @@
]
}
}
},
{
"properties": {
"componentType": {
"enum": [
"metricstable"
]
},
"input": {
"description": "Input of metrics table component.",
"allOf": [
{
"$ref": "metrics-table.schema.json#"
}
]
}
}
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import {
ComputeContributor,
TreeContributor,
ChipsSearchContributor,
MapContributor
MapContributor,
MetricsTableContributor
} from 'arlas-web-contributors';
import { ArlasConfigService, ArlasCollaborativesearchService } from './startup.service';
import { ArlasSettingsService } from '../settings/arlas.settings.service';
Expand Down Expand Up @@ -109,8 +110,31 @@ export class ContributorBuilder {
groupIdToValues
);
break;
case 'metricstable':
contributor = new MetricsTableContributor(identifier, collaborativesearchService, configService);
break;
}
contributor.updateData = false;
return contributor;
}

/** Returns all the collections that are configured in each type of contributor. */
public static getCollections(contributorsConfig: any[]): Set<string> {
const collections = new Set<string>();
contributorsConfig.forEach(contributor => {
if (contributor.collection) {
collections.add(contributor.collection);
}
/** For histograms, multi-collection is possible. We need to check the 'additionalCollections' attribute.*/
if (contributor.type === 'histogram') {
if (contributor.additionalCollections && Array.isArray(contributor.additionalCollections)) {
contributor.additionalCollections.forEach(ac => {
collections.add(ac.collectionName);
});
}
}
});
return collections;
}
}

41 changes: 24 additions & 17 deletions projects/arlas-toolkit/src/lib/services/startup/startup.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ import * as draftSchema from 'ajv/lib/refs/json-schema-draft-06.json';
import { CollectionReferenceDescription, CollectionReferenceParameters, CollectionsApi, Configuration, ExploreApi } from 'arlas-api';
import { Configuration as IamConfiguration, DefaultApi } from 'arlas-iam-api';
import { DataWithLinks } from 'arlas-persistence-api';
import { DonutComponent, HistogramComponent, MapglComponent, MetricComponent, PowerbarsComponent } from 'arlas-web-components';
import {
DonutComponent, HistogramComponent, MapglComponent, MetricComponent,
MetricsTableComponent, PowerbarsComponent
} from 'arlas-web-components';
import {
ChipsSearchContributor, ComputeContributor, DetailedHistogramContributor, HistogramContributor,
MapContributor,
MetricsTableContributor,
ResultListContributor,
SwimLaneContributor, TreeContributor
} from 'arlas-web-contributors';
Expand Down Expand Up @@ -59,7 +63,6 @@ import { ContributorBuilder } from './contributorBuilder';
import * as arlasSettingsSchema from './settings.schema.json';
import { FilterShortcutConfiguration } from '../../components/filter-shortcut/filter-shortcut.utils';
import { AnalyticGroupConfiguration } from '../../components/analytics/analytics.utils';
import { ArlasAuthentificationService } from '../arlas-authentification/arlas-authentification.service';
import { Filter } from 'arlas-api';
import { ProcessService } from '../process/process.service';
import { DashboardError } from '../../tools/errors/dashboard-error';
Expand Down Expand Up @@ -200,9 +203,10 @@ export class ArlasCollaborativesearchService extends CollaborativesearchService
collab.filters.forEach((filters: any[], collection: string) => {
const exp = filters[0].f[0][0];
const op = exp.op;
if (op !== contributor.getFilterOperator()) {
if (contributor.allowOperatorChange) {
contributor.setFilterOperator(op, true);
const treecontributor = contributor as TreeContributor;
if (op !== treecontributor.getFilterOperator()) {
if (treecontributor.allowOperatorChange) {
treecontributor.setFilterOperator(op, true);
} else {
delete dataModel['' + key];
this.collaborations.delete(key);
Expand Down Expand Up @@ -294,7 +298,7 @@ export class ArlasStartupService {

public validateSettings(settings) {
return new Promise<any>((resolve, reject) => {
const ajvObj = new Ajv({allowUnionTypes:true});
const ajvObj = new Ajv({ allowUnionTypes: true });
ajvKeywords(ajvObj, 'uniqueItemProperties');
const validateConfig = ajvObj
.addMetaSchema(draftSchema.default)
Expand All @@ -314,7 +318,7 @@ export class ArlasStartupService {

public validateConfiguration(data) {
return new Promise<any>((resolve, reject) => {
const ajvObj = new Ajv({allowUnionTypes:true});
const ajvObj = new Ajv({ allowUnionTypes: true });
ajvKeywords(ajvObj, 'uniqueItemProperties');
const validateConfig = ajvObj
.addMetaSchema(draftSchema.default)
Expand All @@ -328,12 +332,14 @@ export class ArlasStartupService {
.addSchema(ChipsSearchContributor.getJsonSchema())
.addSchema(AnalyticsContributor.getJsonSchema())
.addSchema(ComputeContributor.getJsonSchema())
.addSchema(MetricsTableContributor.getJsonSchema())
.addSchema((<any>HistogramComponent.getHistogramJsonSchema()).default)
.addSchema((<any>HistogramComponent.getSwimlaneJsonSchema()).default)
.addSchema((<any>PowerbarsComponent.getPowerbarsJsonSchema()).default)
.addSchema((<any>MapglComponent.getMapglJsonSchema()).default)
.addSchema((<any>DonutComponent.getDonutJsonSchema()).default)
.addSchema((<any>MetricComponent.getMetricJsonSchema()).default)
.addSchema((<any>MetricsTableComponent.getJsonSchema()).default)
.compile((<any>arlasConfSchema).default);
if (validateConfig(data) === false) {
const errorMessagesList = new Array<string>();
Expand Down Expand Up @@ -401,7 +407,7 @@ export class ArlasStartupService {
* @param availableFields list of fields that are available for exploration
* @returns the updated configuration object
*/
public updateConfiguration(data, availableFields: Set<string>): any {
public updateConfiguration(data, availableFields: Map<string, Set<string>>): any {
if (!this.emptyMode) {
const contributorsToRemove: Set<string> = this.configurationUpdaterService.getContributorsToRemove(data, availableFields);
let updatedConfig = this.configurationUpdaterService.removeContributors(data, contributorsToRemove);
Expand All @@ -422,11 +428,10 @@ export class ArlasStartupService {
public applyFGA(data) {
if (!this.emptyMode) {
const defaultCollection = this.configService.getValue('arlas.server.collection.name');
const collectionNames: Set<string> = new Set(this.configService.getValue('arlas.web.contributors')
.map(c => (c.collection as string)));
const collectionNames: Set<string> = ContributorBuilder.getCollections(this.configService.getValue('arlas.web.contributors'));
collectionNames.add(defaultCollection);
return this.listAvailableFields(collectionNames)
.then((availableFields: Set<string>) => this.updateConfiguration(data[0], availableFields))
.then((availableFieldsPerCollection: Map<string, Set<string>>) => this.updateConfiguration(data[0], availableFieldsPerCollection))
.then((d) => {
this.configService.setConfig(d);
return d;
Expand Down Expand Up @@ -751,17 +756,18 @@ export class ArlasStartupService {
}
}
/**
* Lists the fields of `collectionName` that are available for exploration with `arlasExploreApi`
* @param collectionName collection name
* @returns available fields
* Lists the fields for each collection in `collectionNames` list; that are available for exploration with `arlasExploreApi`
* @param collectionNames collection names
* @returns available fields per collection
*/
public listAvailableFields(collectionNames: Set<string>): Promise<Set<string>> {
const availableFields = new Set<string>();
public listAvailableFields(collectionNames: Set<string>): Promise<Map<string, Set<string>>> {
const availableFieldsPerCollection = new Map<string, Set<string>>();
const hiddenAvailableFields = [];
return this.collaborativesearchService.list().toPromise().then(
(collectionDescriptions: Array<CollectionReferenceDescription>) => {
collectionDescriptions.filter((cd: CollectionReferenceDescription) => collectionNames.has(cd.collection_name))
.forEach((cd: CollectionReferenceDescription) => {
const availableFields = new Set<string>();
getFieldProperties(cd.properties).map(p => {
if (p.type === 'GEO_POINT') {
hiddenAvailableFields.push(p.label + '.lon');
Expand All @@ -774,8 +780,9 @@ export class ArlasStartupService {
availableFields.add(cd.params.geometry_path);
availableFields.add(cd.params.centroid_path);
hiddenAvailableFields.forEach(f => availableFields.add(f));
availableFieldsPerCollection.set(cd.collection_name, availableFields);
});
return availableFields;
return availableFieldsPerCollection;
});
}

Expand Down
Empty file.
45 changes: 40 additions & 5 deletions src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,43 @@
"autocomplete_field": "internal.autocomplete",
"autocomplete_size": 10
},
{
"type": "metricstable",
"identifier": "metricstable-1",
"name": "Metrics table",
"nbterms": 3,
"sort": {
"collection": "demo_ais_flow",
"order": "asc",
"on": "metric",
"metric": {
"metric": "sum",
"field": "course.distance.gps.travelled_m"
}
},
"configuration": {
"demo_ais_flow": {
"termfield": "course.arrival.address.country",
"metrics": [
{
"metric": "count"
},
{
"metric": "sum",
"field": "course.distance.gps.travelled_m"
}
]
},
"demo_ais_course": {
"termfield": "arrival.address.country",
"metrics": [
{
"metric": "count"
}
]
}
}
},
{
"type": "histogram",
"identifier": "timeline",
Expand Down Expand Up @@ -369,7 +406,6 @@
}
],
"linked_contributor_id": "demo_algoe-valeurfonc-numeric-bucket-Count--50"

},
{
"identifier": "d0fc0203-e56c-4c36-a330-dda760344196",
Expand Down Expand Up @@ -769,7 +805,7 @@
"icon": "business",
"components": [
{
"componentType": "donut",
"componentType": "metricstable",
"showExportCsv": "",
"input": {
"id": "demo_algoe-libtypbien-10-",
Expand All @@ -779,8 +815,7 @@
"multiselectable": true,
"opacity": 0.4
},
"contributorId": "demo_algoe-libtypbien-10-",
"uuid": "9479877b-e362-4764-93cc-6c24cb20b18c",
"contributorId": "metricstable-1",
"usage": "analytics"
},
{
Expand Down Expand Up @@ -1258,4 +1293,4 @@
}
}
}
}
}

0 comments on commit b663277

Please sign in to comment.