Skip to content

Commit

Permalink
feat: init new gio-el-editor to build EL with UI
Browse files Browse the repository at this point in the history
Fist step for basic UI component
  • Loading branch information
ThibaudAV committed Oct 7, 2024
1 parent a743691 commit 6ca4fe5
Show file tree
Hide file tree
Showing 40 changed files with 2,212 additions and 1 deletion.
15 changes: 15 additions & 0 deletions projects/ui-particles-angular/gio-el/README.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Meta, Story } from '@storybook/blocks';

<Meta title="Components / EL / README" />

# Expression Language (EL)

This module provides an expression language (EL) builder for Gravitee.io.

NOTE : WIP !

# Notes

- Impl custom Operators ?
- Impl IN operator ?
- Impl Condition dag and drop ?
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<!--
Copyright (C) 2024 The Gravitee team (http://gravitee.io)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<div class="conditionGroup" [formGroup]="conditionGroupFormGroup">
<div class="conditionGroup__header">
<div class="conditionGroup__header__conditionField"></div>
<mat-button-toggle-group
class="gio-button-toggle-group"
name="condition"
aria-label="Condition"
formControlName="condition"
[hideSingleSelectionIndicator]="true"
>
<mat-button-toggle class="mat-button-toggle-group" value="AND">AND</mat-button-toggle>
<mat-button-toggle class="mat-button-toggle-group" value="OR">OR</mat-button-toggle>
</mat-button-toggle-group>

<div class="conditionGroup__header__addBtn">
<button mat-button [matMenuTriggerFor]="addBtn">
<mat-icon svgIcon="gio:plus">Add</mat-icon>
</button>
<mat-menu #addBtn="matMenu">
<button mat-menu-item (click)="addConditionGroup()">Add Group</button>
<button mat-menu-item (click)="addCondition()">Add Condition</button>
</mat-menu>
</div>

@if (nodeLvl > 0) {
<button class="conditionGroup__header__removeBtn" mat-button aria-label="Remove Group" (click)="removeConditionGroup()">
<mat-icon svgIcon="gio:cancel"></mat-icon>
</button>
}
</div>

<div class="conditionGroup__conditions">
@for (condition of conditionGroupFormGroup.controls.conditions.controls; track conditionIndex; let conditionIndex = $index) {
@if (isConditionGroupForm(condition)) {
<gio-el-editor-condition-group
class="conditionGroup__conditions__conditionGroup"
[conditionGroupFormGroup]="condition"
[conditionModels]="conditionModels"
[nodeLvl]="nodeLvl + 1"
(remove)="removeCondition(conditionIndex)"
></gio-el-editor-condition-group>
} @else {
<div
class="conditionGroup__conditions__condition"
[formGroup]="conditionGroupFormGroup.controls.conditions.at(conditionIndex)"
[attr.node-lvl]="nodeLvl"
>
<mat-form-field class="conditionGroup__conditions__condition__field">
<mat-label>Field</mat-label>

<mat-select formControlName="field" placeholder="Select Field">
<mat-option *ngFor="let field of conditionModels" [value]="field">{{ field.label }}</mat-option>
</mat-select>
</mat-form-field>

@switch (condition.controls.field.value?.type) {
@case ('string') {
<gio-el-editor-type-string [conditionFormGroup]="condition"></gio-el-editor-type-string>
}
@case ('boolean') {
<gio-el-editor-type-boolean [conditionFormGroup]="condition"></gio-el-editor-type-boolean>
}
@case ('number') {
<gio-el-editor-type-number [conditionFormGroup]="condition"></gio-el-editor-type-number>
}
@case ('date') {
<gio-el-editor-type-date [conditionFormGroup]="condition"></gio-el-editor-type-date>
}
}

<button
class="conditionGroup__conditions__condition__removeBtn"
mat-button
aria-label="Remove Condition"
(click)="removeCondition(conditionIndex)"
>
<mat-icon svgIcon="gio:cancel"></mat-icon>
</button>
</div>
}
}
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (C) 2024 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

.conditionGroup {
display: flex;
flex-direction: column;
gap: 8px;

&__header {
display: flex;
flex-direction: row;
align-items: center;
gap: 8px;

.gio-button-toggle-group {
margin-bottom: 0;
}
}

&__conditions {
display: flex;
flex-direction: column;
gap: 8px;

&__condition {
display: flex;
align-items: flex-start;
gap: 8px;

&__field {
flex: 0 0 auto;
}

&__removeBtn {
align-self: center;
}
}

&__conditionGroup {
margin-left: 18px;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
* Copyright (C) 2024 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Component, EventEmitter, HostBinding, Input, Output } from '@angular/core';
import { FormArray, FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatSelectModule } from '@angular/material/select';
import { CommonModule } from '@angular/common';
import { MatButtonModule } from '@angular/material/button';
import { MatButtonToggleModule } from '@angular/material/button-toggle';
import { MatMenuModule } from '@angular/material/menu';
import { GioIconsModule } from '@gravitee/ui-particles-angular';

import { GioElEditorTypeBooleanComponent } from '../gio-el-type/gio-el-editor-type-boolean/gio-el-editor-type-boolean.component';
import { GioElEditorTypeDateComponent } from '../gio-el-type/gio-el-editor-type-date/gio-el-editor-type-date.component';
import { GioElEditorTypeNumberComponent } from '../gio-el-type/gio-el-editor-type-number/gio-el-editor-type-number.component';
import { GioElEditorTypeStringComponent } from '../gio-el-type/gio-el-editor-type-string/gio-el-editor-type-string.component';
import { ConditionModel } from '../../models/ConditionModel';
import { ConditionForm, ConditionGroupForm } from '../gio-el-editor.component';

@Component({
selector: 'gio-el-editor-condition-group',
standalone: true,
imports: [
CommonModule,
ReactiveFormsModule,
MatFormFieldModule,
MatSelectModule,
MatButtonModule,
MatButtonToggleModule,
MatMenuModule,
GioIconsModule,
GioElEditorTypeBooleanComponent,
GioElEditorTypeDateComponent,
GioElEditorTypeStringComponent,
GioElEditorTypeNumberComponent,
],
templateUrl: './gio-el-editor-condition-group.component.html',
styleUrl: './gio-el-editor-condition-group.component.scss',
})
export class GioElEditorConditionGroupComponent {
@Input({
required: true,
})
public conditionGroupFormGroup!: FormGroup<ConditionGroupForm>;

/**
* Condition models to generate the fields for the conditions.
*/
@Input({
required: true,
})
public conditionModels: ConditionModel[] = [];

/**
* Level of the node in the tree. Useful for testing with Harness to limit the scope of the query.
*/
@Input()
@HostBinding('attr.node-lvl')
public nodeLvl = 0;

@Output()
public remove = new EventEmitter<void>();

protected addConditionGroup() {
this.conditionGroupFormGroup.controls.conditions.push(newConditionGroupFormGroup(), { emitEvent: true });
this.checkMultipleCondition();
}

protected addCondition() {
this.conditionGroupFormGroup.controls.conditions.push(newConditionFormGroup());
this.checkMultipleCondition();
}

protected removeCondition(conditionIndex: number) {
this.conditionGroupFormGroup.controls.conditions.removeAt(conditionIndex);
this.checkMultipleCondition();
}

protected removeConditionGroup() {
this.remove.emit();
this.checkMultipleCondition();
}

protected isConditionGroupForm(
formGroup: FormGroup<ConditionForm> | FormGroup<ConditionGroupForm>,
): formGroup is FormGroup<ConditionGroupForm> {
return 'condition' in formGroup.controls && 'conditions' in formGroup.controls;
}

private checkMultipleCondition(): void {
if (this.conditionGroupFormGroup.controls.conditions.length > 1) {
this.conditionGroupFormGroup.controls.condition.enable();
} else {
this.conditionGroupFormGroup.controls.condition.disable();
}
}
}

const newConditionGroupFormGroup = (): FormGroup<ConditionGroupForm> => {
return new FormGroup<ConditionGroupForm>({
condition: new FormControl({ value: 'AND', disabled: true }, { nonNullable: true, validators: Validators.required }),
conditions: new FormArray<FormGroup<ConditionForm> | FormGroup<ConditionGroupForm>>([]),
});
};

const newConditionFormGroup = (): FormGroup<ConditionForm> => {
return new FormGroup<ConditionForm>({
field: new FormControl(null),
operator: new FormControl(null),
value: new FormControl(null),
});
};
Loading

0 comments on commit 6ca4fe5

Please sign in to comment.