Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Epic ai rebased #3756

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest

outputs:
publish: ${{ steps.publish_vars.outputs.release != 'true' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/4.')) }}
publish: ${{ steps.publish_vars.outputs.release != 'true' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/4.') || startsWith(github.ref, 'refs/heads/epic-ai')) }}
repo: ${{ steps.publish_vars.outputs.repo }}

steps:
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/resources/assets/admin/common/icons/fonts/icomoon.woff
100755 → 100644
Binary file not shown.
Binary file modified src/main/resources/assets/admin/common/icons/fonts/icomoon.woff2
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
120 changes: 120 additions & 0 deletions src/main/resources/assets/admin/common/js/ai/AiHelper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import {PropertyPath} from '../data/PropertyPath';
import {Element} from '../dom/Element';
import {Store} from '../store/Store';
import {i18n} from '../util/Messages';
import {AiHelperState} from './AiHelperState';
import {AiActionButton} from './ui/AiActionButton';

export interface AiHelperConfig {
dataPathElement: Element;
getPathFunc: () => PropertyPath;
icon?: {
container: Element;
};
label?: string;
setValueFunc?: (value: string) => void;
}

const AI_HELPERS_KEY = 'AiHelpers';
Store.instance().set(AI_HELPERS_KEY, []);

export class AiHelper {

public static DATA_ATTR = 'data-path';

private readonly config: AiHelperConfig;

private readonly aiIcon?: AiActionButton;

private state: AiHelperState = AiHelperState.DEFAULT;

constructor(config: AiHelperConfig) {
this.config = config;

const updatePathCall = setInterval(() => {
this.updateInputElDataPath();
}, 1000);

this.config.dataPathElement.onRemoved(() => {
clearInterval(updatePathCall);
const helper: AiHelper[] = Store.instance().get(AI_HELPERS_KEY) ?? [];
Store.instance().set(AI_HELPERS_KEY, helper.filter(h => h !== this));
});

Store.instance().get(AI_HELPERS_KEY).push(this);

if (this.config.icon) {
this.aiIcon = new AiActionButton();
this.config.icon.container.appendChild(this.aiIcon);
}
}

private updateInputElDataPath(): void {
const dataPath = AiHelper.convertToPath(this.config.getPathFunc());
this.config.dataPathElement.getEl().setAttribute(AiHelper.DATA_ATTR, dataPath);
this.aiIcon?.setDataPath(dataPath);
}

setState(state: AiHelperState): this {
if (state === this.state) {
return this;
}

this.state = state;
this.aiIcon?.setState(state);

if (state === AiHelperState.COMPLETED || state === AiHelperState.FAILED) {
setTimeout(() => {
if (this.state === AiHelperState.COMPLETED || this.state === AiHelperState.FAILED) {
this.setState(AiHelperState.DEFAULT);
}
}, 1000);

this.config.dataPathElement.getEl().setDisabled(false);
this.config.dataPathElement.removeClass('ai-helper-mask');
this.resetTitle();
} else if (state === AiHelperState.PROCESSING) {
this.config.dataPathElement.getEl().setDisabled(true);
this.config.dataPathElement.addClass('ai-helper-mask');
this.updateTitle();
}

return this;
}

setValue(value: string): this {
this.config.setValueFunc?.(value);
return this;
}

getDataPath(): string {
return this.config.dataPathElement.getEl().getAttribute(AiHelper.DATA_ATTR);
}

public static convertToPath(path: PropertyPath): string {
return path?.toString().replace(/\./g, '/') || '';
}

public static getAiHelperByPath(dataPath: string): AiHelper | undefined {
return Store.instance().get(AI_HELPERS_KEY).find(helper => helper.getDataPath() === dataPath);
}

private updateTitle(): void {
const parent = this.config.dataPathElement.getEl().getParent();

if (parent.hasAttribute('title') && !parent.hasAttribute('data-title')) {
parent.setAttribute('data-title', parent.getTitle());
}

parent.setTitle(i18n('ai.field.processing', this.config.label));
}

private resetTitle(): void {
const parent = this.config.dataPathElement.getEl().getParent();
parent.removeAttribute('title');

if (parent.hasAttribute('data-title')) {
parent.setTitle(parent.getAttribute('data-title'));
}
}
}
6 changes: 6 additions & 0 deletions src/main/resources/assets/admin/common/js/ai/AiHelperState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export enum AiHelperState {
DEFAULT = 'default',
PROCESSING = 'processing',
COMPLETED = 'completed',
FAILED = 'failed',
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {ClassHelper} from '../../ClassHelper';
import {Event} from '../../event/Event';

export class EnonicAiContentOperatorOpenDialogEvent
extends Event {

private readonly sourceDataPath?: string;

constructor(dataPath?: string) {
super();

this.sourceDataPath = dataPath;
}

getSourceDataPath(): string | undefined {
return this.sourceDataPath;
}

static on(handler: (event: EnonicAiContentOperatorOpenDialogEvent) => void) {
Event.bind(ClassHelper.getFullName(this), handler);
}

static un(handler?: (event: EnonicAiContentOperatorOpenDialogEvent) => void) {
Event.unbind(ClassHelper.getFullName(this), handler);
}

}
63 changes: 63 additions & 0 deletions src/main/resources/assets/admin/common/js/ai/ui/AiActionButton.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import * as Q from 'q';
import {DivEl} from '../../dom/DivEl';
import {Button} from '../../ui/button/Button';
import {i18n} from '../../util/Messages';
import {AiHelperState} from '../AiHelperState';
import {EnonicAiContentOperatorOpenDialogEvent} from '../event/EnonicAiContentOperatorOpenDialogEvent';

export class AiActionButton
extends DivEl {

private static readonly BASE_CLASS = 'ai-button-container';

private dataPath?: string;

private button: Button;

private loader: DivEl;

constructor() {
super();

this.initElements();
this.initListeners();
}

protected initElements(): void {
this.button = new Button().addClass(`${AiActionButton.BASE_CLASS}-icon ai-icon`) as Button;
this.loader = new DivEl(`${AiActionButton.BASE_CLASS}-loader`);
this.setTitle(i18n('ai.action.contentOperator.use'));
this.setState(AiHelperState.DEFAULT);
}

setState(state: AiHelperState): this {
this.setClass(`${AiActionButton.BASE_CLASS} ${state}`);

return this;
}

setDataPath(dataPath: string): AiActionButton {
this.dataPath = dataPath;
return this;
}

getDataPath(): string {
return this.dataPath;
}

protected initListeners(): void {
this.button.onClicked(() => {
if (this.dataPath) {
new EnonicAiContentOperatorOpenDialogEvent(this.dataPath).fire();
}
});
}

doRender(): Q.Promise<boolean> {
return super.doRender().then((rendered: boolean) => {
this.appendChildren(this.loader, this.button);

return rendered;
});
}
}
23 changes: 19 additions & 4 deletions src/main/resources/assets/admin/common/js/form/FormContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ export class FormContext {

private validationErrors: ValidationError[];

private readonly aiEditable: boolean;

constructor(builder: FormContextBuilder) {
this.showEmptyFormItemSetOccurrences = builder.showEmptyFormItemSetOccurrences;
this.formState = builder.formState;
this.language = builder.language;
this.validationErrors = builder.validationErrors || [];
this.aiEditable = builder.aiEditable ?? false;
}

static create(): FormContextBuilder {
Expand Down Expand Up @@ -71,6 +74,11 @@ export class FormContext {
setLanguage(lang: string) {
this.language = lang;
}

isAiEditable(): boolean {
return this.aiEditable;
}

}

export class FormContextBuilder {
Expand All @@ -83,26 +91,33 @@ export class FormContextBuilder {

validationErrors: ValidationError[];

public setShowEmptyFormItemSetOccurrences(value: boolean): FormContextBuilder {
aiEditable: boolean;

public setShowEmptyFormItemSetOccurrences(value: boolean): this {
this.showEmptyFormItemSetOccurrences = value;
return this;
}

public setFormState(value: FormState): FormContextBuilder {
public setFormState(value: FormState): this {
this.formState = value;
return this;
}

public setLanguage(lang: string): FormContextBuilder {
public setLanguage(lang: string): this {
this.language = lang;
return this;
}

public setValidationErrors(value: ValidationError[]): FormContextBuilder {
public setValidationErrors(value: ValidationError[]): this {
this.validationErrors = value;
return this;
}

public setAiEditable(value: boolean): this {
this.aiEditable = value;
return this;
}

public build(): FormContext {
return new FormContext(this);
}
Expand Down
Loading
Loading