Skip to content

Commit

Permalink
Merge branch 'develop' into feat/h3
Browse files Browse the repository at this point in the history
  • Loading branch information
QuCMGisaia committed Aug 29, 2024
2 parents 2c3aed9 + 488c5b8 commit f20783b
Show file tree
Hide file tree
Showing 22 changed files with 269 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ <h2 mat-dialog-title *ngIf="this.persistenceService.isAvailable" class="title">
</ng-container>
</mat-dialog-content>

<div class="buttons">
<div class="buttons" *ngIf="canCreateForCurrentOrg">
<button mat-stroked-button color="primary" class="new_dashboard" (click)="openChoice(InitialChoice.setup)">{{'New dashboard' |
translate}}</button>
<button mat-stroked-button color="primary" (click)="openChoice(InitialChoice.load)">{{'Import from file'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { SharedModule } from '@shared/shared.module';
import {
ArlasCollaborativesearchService, ArlasConfigService, ArlasConfigurationDescriptor,
ArlasStartupService, AuthentificationService, ConfigMenuModule, getOptionsFactory, GET_OPTIONS,
ArlasSettingsService, ArlasIamService, PersistenceService
ArlasSettingsService, ArlasIamService, PersistenceService,
PermissionService
} from 'arlas-wui-toolkit';
import { NGXLogger } from 'ngx-logger';
import { of } from 'rxjs';
Expand Down Expand Up @@ -40,6 +41,7 @@ describe('LandingPageComponent', () => {
mockProvider(StartupService),
mockProvider(ArlasStartupService),
mockProvider(PersistenceService),
mockProvider(PermissionService),
mockProvider(ArlasSettingsService, {
getAuthentSettings: () => undefined
}),
Expand Down
34 changes: 31 additions & 3 deletions src/app/components/landing-page/landing-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ import { UserOrgData } from 'arlas-iam-api';
import { DataWithLinks } from 'arlas-persistence-api';
import {
ArlasAuthentificationService, ArlasIamService, ArlasSettingsService, AuthentificationService, ConfigAction,
ConfigActionEnum, ErrorService, PersistenceService, UserInfosComponent
ConfigActionEnum, ErrorService, PermissionService, PersistenceService, UserInfosComponent
} from 'arlas-wui-toolkit';
import { Resource } from 'arlas-permissions-api';
import { NGXLogger } from 'ngx-logger';
import { Subscription } from 'rxjs';
import { map } from 'rxjs/internal/operators/map';
Expand Down Expand Up @@ -74,11 +75,14 @@ export class LandingPageComponent implements OnInit, AfterViewInit, OnDestroy {
public orgs: UserOrgData[] = [];
public currentOrga = '';

public canCreateForCurrentOrg = false; // Whether the buttons to CREATE / IMPORT a dashboard are displayed

private subscription: Subscription;
private refreshSubscription: Subscription;
public constructor(
public startupService: StartupService,
public persistenceService: PersistenceService,
private permissionService: PermissionService,
public mainFormService: MainFormService,
private startingConfigFormBuilder: StartingConfigFormBuilderService,
private resourcesConfigFormBuilder: ResourcesConfigFormBuilderService,
Expand Down Expand Up @@ -144,6 +148,7 @@ export class LandingPageComponent implements OnInit, AfterViewInit, OnDestroy {
this.refreshSubscription = this.arlasIamService.tokenRefreshed$.subscribe({
next: (loginData) => {
if (!!loginData) {

this.isAuthenticated = true;
this.orgs = loginData.user.organisations.map(org => {
org.displayName = org.name === loginData.user.id ? loginData.user.email.split('@')[0] : org.name;
Expand All @@ -154,7 +159,7 @@ export class LandingPageComponent implements OnInit, AfterViewInit, OnDestroy {
this.isAuthenticated = false;
}
if (this.persistenceService.isAvailable) {
this.getConfigList();
this.checkUserRightsForOrg(this.currentOrga);
}
},
error: () => {
Expand Down Expand Up @@ -269,6 +274,13 @@ export class LandingPageComponent implements OnInit, AfterViewInit, OnDestroy {
this.configurations.forEach(c => {
c.actions.filter(a => a.type === ConfigActionEnum.VIEW)
.map(a => a.url = this.settingsService.getArlasWuiUrl());
// for IAM only, if the user doesn't have the right to create (POST)
// disabled the EDIT action
if (this.authentMode === 'iam') {
c.actions.filter(a => a.type === ConfigActionEnum.EDIT).map(a =>
a.enabled = a.enabled && this.canCreateForCurrentOrg
);
}
});
},
error: (msg) => {
Expand Down Expand Up @@ -318,7 +330,7 @@ export class LandingPageComponent implements OnInit, AfterViewInit, OnDestroy {
public changeOrg(event: MatSelectChange) {
this.arlasIamService.storeOrganisation(event.value);
this.startupService.changeOrgHeader(event.value, this.arlasIamService.getAccessToken());
this.getConfigList();
this.checkUserRightsForOrg(event.value);
}

public ngOnDestroy() {
Expand All @@ -329,6 +341,22 @@ export class LandingPageComponent implements OnInit, AfterViewInit, OnDestroy {
this.refreshSubscription.unsubscribe();
}
}

public checkUserRightsForOrg(org: string) {
const iamHeader = {
Authorization: 'Bearer ' + this.arlasIamService.getAccessToken(),
'arlas-org-filter': org
};
const fetchOptions = { headers: iamHeader };
this.permissionService.setOptions(fetchOptions);
// Check user rights on current organisation
this.permissionService.get('persist/resource/').subscribe({
next: (resources: Resource[]) => {
this.canCreateForCurrentOrg = resources.filter(r => r.verb === 'POST').length > 0;
this.getConfigList();
}
});
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@
{{'Details' | translate}}
</span>
</ng-template>

<div class="details-title">
<arlas-config-element [fullSize]="!detailsTitleControl.description">
<div form-fields>
<arlas-config-form-control [control]="detailsTitleControl"></arlas-config-form-control>
</div>
<div description *ngIf="detailsTitleControl.description">
{{ detailsTitleControl.description | translate}}
</div>
</arlas-config-element>
</div>
<arlas-edit-resultlist-details [control]="control.get('details')" [collection]="control.get('collection')">
</arlas-edit-resultlist-details>
</mat-tab>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@
.tab-error {
color: $error-color;
}

.details-title {
margin: 10px;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { ResultlistDataComponent } from './resultlist-data.component';
import { Spectator, createComponentFactory } from '@ngneat/spectator';
import { FormControl, FormGroup } from '@angular/forms';
import { Spectator, createComponentFactory, mockProvider } from '@ngneat/spectator';
import { CollectionService } from '@services/collection-service/collection.service';
import { MockComponent } from 'ng-mocks';
import { of } from 'rxjs';
import { EditResultlistColumnsComponent } from '../edit-resultlist-columns/edit-resultlist-columns.component';
import { EditResultlistDetailsComponent } from '../edit-resultlist-details/edit-resultlist-details.component';
import { FormArray, FormGroup, FormControl } from '@angular/forms';
import { ResultlistDataComponent } from './resultlist-data.component';

describe('ResultlistDataComponent', () => {
let spectator: Spectator<ResultlistDataComponent>;
Expand All @@ -13,6 +15,11 @@ describe('ResultlistDataComponent', () => {
declarations: [
MockComponent(EditResultlistColumnsComponent),
MockComponent(EditResultlistDetailsComponent),
],
providers: [
mockProvider(CollectionService, {
getCollectionFields: () => of([])
}),
]
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,72 @@
* specific language governing permissions and limitations
* under the License.
*/
import { Component, Input, OnInit } from '@angular/core';
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
import { FormGroup } from '@angular/forms';
import { marker } from '@biesbjerg/ngx-translate-extract-marker';
import { CollectionService } from '@services/collection-service/collection.service';
import { toKeywordOptionsObs } from '@services/collection-service/tools';
import { FieldTemplateControl } from '@shared-models/config-form';
import { CollectionReferenceDescriptionProperty } from 'arlas-api';
import { Subject, takeUntil } from 'rxjs';

@Component({
selector: 'arlas-resultlist-data',
templateUrl: './resultlist-data.component.html',
styleUrls: ['./resultlist-data.component.scss']
})
export class ResultlistDataComponent implements OnInit {
export class ResultlistDataComponent implements OnInit, OnDestroy {

@Input() public control: FormGroup;
public detailsTitleControl: FieldTemplateControl;

private onDestroy$ = new Subject<boolean>();

public constructor(
private collectionService: CollectionService
) { }

public ngOnInit() {
public ngOnDestroy() {
this.onDestroy$.next(true);
this.onDestroy$.complete();
}

public ngOnInit() {
const collectionControl = this.control.get('collection');
this.detailsTitleControl = new FieldTemplateControl(
'',
marker('Details title'),
marker('Details title description'),
this.collectionService.getCollectionFields(
collectionControl?.value,
[CollectionReferenceDescriptionProperty.TypeEnum.KEYWORD]
),
false,
{
optional: true
}
);

if (!!this.control.get('detailsTitle') && !!this.control.get('detailsTitle').value) {
this.detailsTitleControl.setValue(this.control.get('detailsTitle').value);
}

this.detailsTitleControl.valueChanges.pipe(takeUntil(this.onDestroy$)).subscribe({
next: (value) => {
this.control.get('detailsTitle').setValue(value);
}
});

if (!!collectionControl) {
collectionControl.valueChanges.pipe(takeUntil(this.onDestroy$)).subscribe(c => {
toKeywordOptionsObs(this.collectionService
.getCollectionFields(c))
.subscribe(collectionFs => {
this.detailsTitleControl.setValue('');
this.detailsTitleControl.fields = collectionFs;
this.detailsTitleControl.filterAutocomplete();
});
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { CollectionService } from '@services/collection-service/collection.servi
import {
NUMERIC_OR_DATE_OR_KEYWORD,
NUMERIC_OR_DATE_OR_TEXT_TYPES, TEXT_OR_KEYWORD,
toKeywordOptionsObs,
toNumericOrDateOrKeywordOrTextObs, toOptionsObs
} from '@services/collection-service/tools';
import { DefaultConfig, DefaultValuesService } from '@services/default-values/default-values.service';
Expand All @@ -36,7 +37,7 @@ import {
ButtonFormControl, ComponentFormControl, ConfigFormGroup, HiddenFormControl, InputFormControl,
MultipleSelectFormControl,
SelectFormControl, SelectOption, SliderFormControl, SlideToggleFormControl, TextareaFormControl,
TitleInputFormControl, UrlTemplateControl
TitleInputFormControl, FieldTemplateControl
} from '@shared-models/config-form';
import { Observable } from 'rxjs';
import { WidgetFormBuilder } from '../widget-form-builder';
Expand All @@ -47,6 +48,7 @@ import { EditResultlistQuicklookComponent } from '@analytics-config/components/e
import { Router } from '@angular/router';
import { ConfigFormGroupComponent } from '@shared-components/config-form-group/config-form-group.component';
import { ArlasColorGeneratorLoader } from 'arlas-wui-toolkit';
import { CollectionReferenceDescriptionProperty } from 'arlas-api';

export class ResultlistConfigForm extends WidgetConfigFormGroup {

Expand Down Expand Up @@ -102,6 +104,13 @@ export class ResultlistConfigForm extends WidgetConfigFormGroup {
validators: Validators.required,
})),
details: new FormArray([]),
detailsTitle: new HiddenFormControl(
'',
undefined,
{
optional: true
}
),
idFieldName: new HiddenFormControl(
'',
undefined,
Expand Down Expand Up @@ -248,7 +257,7 @@ export class ResultlistConfigForm extends WidgetConfigFormGroup {
}
}
),
thumbnailUrl: new UrlTemplateControl(
thumbnailUrl: new FieldTemplateControl(
'',
marker('Thumbnail url'),
marker('Thumbnail url description'),
Expand All @@ -257,9 +266,9 @@ export class ResultlistConfigForm extends WidgetConfigFormGroup {
{
optional: true,
dependsOn: () => [this.customControls.dataStep.collection],
onDependencyChange: (control: UrlTemplateControl) => {
onDependencyChange: (control: FieldTemplateControl) => {
if (!this.collection || this.customControls.dataStep.collection.dirty) {
this.updateUrlTemplateControl(collectionService, control);
this.updateFieldTemplateControl(collectionService, control);
}
}
}
Expand Down Expand Up @@ -336,6 +345,7 @@ export class ResultlistConfigForm extends WidgetConfigFormGroup {
visualisationLink: this.get('dataStep.visualisationLink') as InputFormControl,
downloadLink: this.get('dataStep.downloadLink') as InputFormControl,
columns: this.get('dataStep.columns') as FormArray,
detailsTitle: this.get('dataStep.detailsTitle') as HiddenFormControl,
details: this.get('dataStep.details') as FormArray,
idFieldName: this.get('dataStep.idFieldName') as HiddenFormControl,
},
Expand All @@ -351,7 +361,7 @@ export class ResultlistConfigForm extends WidgetConfigFormGroup {
tileLabelFieldProcess: this.get('renderStep.gridStep.tileLabelFieldProcess') as TextareaFormControl,
tooltipField: this.get('renderStep.gridStep.tooltipField') as SelectFormControl,
tooltipFieldProcess: this.get('renderStep.gridStep.tooltipFieldProcess') as TextareaFormControl,
thumbnailUrl: this.get('renderStep.gridStep.thumbnailUrl') as UrlTemplateControl,
thumbnailUrl: this.get('renderStep.gridStep.thumbnailUrl') as FieldTemplateControl,
colorIdentifier: this.get('renderStep.gridStep.colorIdentifier') as SelectFormControl,
quicklookUrls: this.get('renderStep.gridStep.quicklookUrls') as FormArray
}
Expand Down Expand Up @@ -380,7 +390,7 @@ export class ResultlistConfigForm extends WidgetConfigFormGroup {
}
};

private updateUrlTemplateControl(collectionService: CollectionService, control: UrlTemplateControl) {
private updateFieldTemplateControl(collectionService: CollectionService, control: FieldTemplateControl) {
this.setCollection(this.customControls.dataStep.collection.value);
toNumericOrDateOrKeywordOrTextObs(collectionService
.getCollectionFields(this.customControls.dataStep.collection.value))
Expand Down Expand Up @@ -601,14 +611,14 @@ export class ResultlistQuicklookFormGroup extends FormGroup {
*/
public constructor(fieldsObs: Observable<Array<CollectionField>>, collection: string, collectionService: CollectionService) {
super({
url: new UrlTemplateControl(
url: new FieldTemplateControl(
'',
marker('Quicklook url'),
marker('Quicklook url description'),
fieldsObs,
true
),
description: new UrlTemplateControl(
description: new FieldTemplateControl(
'',
marker('Quicklook description'),
marker('Quicklook description description'),
Expand Down Expand Up @@ -643,7 +653,7 @@ export class ResultlistQuicklookFormGroup extends FormGroup {
if (!this.customControls.filter.field.touched) {
// Avoid to reset the imported configuration when first loading it
} else if (this.customControls.filter.field.value !== '' && !!this.customControls.filter.field.syncOptions
&& this.customControls.filter.field.syncOptions.map(f => f.value).includes(this.customControls.filter.field.value)) {
&& this.customControls.filter.field.syncOptions.map(f => f.value).includes(this.customControls.filter.field.value)) {
control.setSyncOptions([]);
collectionService.getTermAggregation(
collection,
Expand All @@ -664,8 +674,8 @@ export class ResultlistQuicklookFormGroup extends FormGroup {
}

public customControls = {
url: this.get('url') as UrlTemplateControl,
description: this.get('description') as UrlTemplateControl,
url: this.get('url') as FieldTemplateControl,
description: this.get('description') as FieldTemplateControl,
filter: {
field: this.get('filter.field') as SelectFormControl,
values: this.get('filter.values') as MultipleSelectFormControl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('GlobalLookAndFeelComponent', () => {
lookAndFeelConfig: {
getGlobalFg: () => new FormGroup({
dragAndDrop: new FormControl(null),
zoomToData: new FormControl(null),
zoomToDataStrategy: new FormControl(null),
indicators: new FormControl(null),
spinner: new FormControl(null),
spinnerColor: new FormControl(null),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('LookAndFeelGlobalFormBuilderService', () => {
lookAndFeelConfig: {
getGlobalFg: () => new FormGroup({
dragAndDrop: new FormControl(null),
zoomToData: new FormControl(null),
zoomToDataStrategy: new FormControl(null),
indicators: new FormControl(null),
spinner: new FormControl(null),
spinnerColor: new FormControl(null),
Expand Down
Loading

0 comments on commit f20783b

Please sign in to comment.