Skip to content

Commit

Permalink
Show AI button based on settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianStehle committed Oct 10, 2023
1 parent 5440e68 commit 43c207b
Show file tree
Hide file tree
Showing 35 changed files with 172 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageReference Include="NJsonSchema" Version="10.9.0" />
<PackageReference Include="RefactoringEssentials" Version="5.6.0" PrivateAssets="all" />
<PackageReference Include="Squidex.Messaging.Subscriptions" Version="5.18.0" />
<PackageReference Include="Squidex.Messaging.Subscriptions" Version="5.19.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="all" />
<PackageReference Include="System.Collections.Immutable" Version="7.0.0" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="7.0.0" />
<PackageReference Include="Notifo.SDK" Version="1.7.4" />
<PackageReference Include="RefactoringEssentials" Version="5.6.0" PrivateAssets="all" />
<PackageReference Include="Squidex.CLI.Core" Version="11.1.0" />
<PackageReference Include="Squidex.CLI.Core" Version="11.2.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="all" />
<PackageReference Include="System.Collections.Immutable" Version="7.0.0" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
Expand Down
12 changes: 6 additions & 6 deletions backend/src/Squidex.Infrastructure/Squidex.Infrastructure.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
<PackageReference Include="NodaTime" Version="3.1.9" />
<PackageReference Include="OpenTelemetry.Api" Version="1.5.0" />
<PackageReference Include="RefactoringEssentials" Version="5.6.0" PrivateAssets="all" />
<PackageReference Include="Squidex.Assets" Version="5.18.0" />
<PackageReference Include="Squidex.Caching" Version="5.18.0" />
<PackageReference Include="Squidex.Hosting.Abstractions" Version="5.18.0" />
<PackageReference Include="Squidex.Log" Version="5.18.0" />
<PackageReference Include="Squidex.Messaging" Version="5.18.0" />
<PackageReference Include="Squidex.Text" Version="5.18.0" />
<PackageReference Include="Squidex.Assets" Version="5.19.0" />
<PackageReference Include="Squidex.Caching" Version="5.19.0" />
<PackageReference Include="Squidex.Hosting.Abstractions" Version="5.19.0" />
<PackageReference Include="Squidex.Log" Version="5.19.0" />
<PackageReference Include="Squidex.Messaging" Version="5.19.0" />
<PackageReference Include="Squidex.Text" Version="5.19.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="all" />
<PackageReference Include="System.Collections.Immutable" Version="7.0.0" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
using System.Text.Json;
using Microsoft.Extensions.Options;
using Squidex.Areas.Api.Controllers.UI;
using Squidex.Domain.Apps.Entities.History;
using Squidex.Web;

namespace Squidex.Areas.Frontend.Middlewares;

Expand Down Expand Up @@ -39,28 +37,12 @@ public static string AddOptions(this string html, HttpContext httpContext)
{
var clonedOptions = uiOptions with
{
More = new Dictionary<string, object>
More = new Dictionary<string, object>(uiOptions.More)
{
["culture"] = CultureInfo.CurrentUICulture.Name
}
};

var jsonOptions = httpContext.RequestServices.GetRequiredService<JsonSerializerOptions>();

using var jsonDocument = JsonSerializer.SerializeToDocument(uiOptions, jsonOptions);

if (httpContext.RequestServices.GetService<ExposedValues>() is ExposedValues values)
{
clonedOptions.More["info"] = values.ToString();
}

var notifo = httpContext.RequestServices!.GetService<IOptions<NotifoOptions>>()?.Value;

if (notifo?.IsConfigured() == true)
{
clonedOptions.More["notifoApi"] = notifo.ApiUrl;
}

var options = httpContext.Features.Get<OptionsFeature>();

if (options != null)
Expand Down
58 changes: 58 additions & 0 deletions backend/src/Squidex/Config/Domain/FontendServices.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================

using System.Text.Json;
using Microsoft.Extensions.Options;
using Squidex.Areas.Api.Controllers.UI;
using Squidex.Domain.Apps.Entities.History;
using Squidex.Text.ChatBots;
using Squidex.Text.Translations;
using Squidex.Web;

namespace Squidex.Config.Domain;

public static class FontendServices
{
public static void AddSquidexFrontend(this IServiceCollection services)
{
services.Configure<MyUIOptions>((services, options) =>
{
var jsonOptions = services.GetRequiredService<JsonSerializerOptions>();

using var jsonDocument = JsonSerializer.SerializeToDocument(options, jsonOptions);

if (services.GetService<ExposedValues>() is ExposedValues values)
{
options.More["info"] = values.ToString();
}
});

services.Configure<MyUIOptions>((services, options) =>
{
var notifo = services.GetRequiredService<IOptions<NotifoOptions>>().Value;

if (notifo.IsConfigured())
{
options.More["notifoApi"] = notifo.ApiUrl;
}
});

services.Configure<MyUIOptions>((services, options) =>
{
var translator = services.GetRequiredService<ITranslator>();

options.More["canUseTranslator"] = translator.IsConfigured;
});

services.Configure<MyUIOptions>((services, options) =>
{
var chatBot = services.GetRequiredService<IChatBot>();

options.More["canUseChatBot"] = chatBot.IsConfigured;
});
}
}
22 changes: 11 additions & 11 deletions backend/src/Squidex/Squidex.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,18 @@
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.0.0-rc7" />
<PackageReference Include="RefactoringEssentials" Version="5.6.0" PrivateAssets="all" />
<PackageReference Include="ReportGenerator" Version="5.1.22" PrivateAssets="all" />
<PackageReference Include="Squidex.Assets.Azure" Version="5.18.0" />
<PackageReference Include="Squidex.Assets.GoogleCloud" Version="5.18.0" />
<PackageReference Include="Squidex.Assets.FTP" Version="5.18.0" />
<PackageReference Include="Squidex.Assets.ImageMagick" Version="5.18.0" />
<PackageReference Include="Squidex.Assets.ImageSharp" Version="5.18.0" />
<PackageReference Include="Squidex.Assets.Mongo" Version="5.18.0" />
<PackageReference Include="Squidex.Assets.S3" Version="5.18.0" />
<PackageReference Include="Squidex.Assets.TusAdapter" Version="5.18.0" />
<PackageReference Include="Squidex.Assets.Azure" Version="5.19.0" />
<PackageReference Include="Squidex.Assets.GoogleCloud" Version="5.19.0" />
<PackageReference Include="Squidex.Assets.FTP" Version="5.19.0" />
<PackageReference Include="Squidex.Assets.ImageMagick" Version="5.19.0" />
<PackageReference Include="Squidex.Assets.ImageSharp" Version="5.19.0" />
<PackageReference Include="Squidex.Assets.Mongo" Version="5.19.0" />
<PackageReference Include="Squidex.Assets.S3" Version="5.19.0" />
<PackageReference Include="Squidex.Assets.TusAdapter" Version="5.19.0" />
<PackageReference Include="Squidex.ClientLibrary" Version="16.1.0" />
<PackageReference Include="Squidex.Hosting" Version="5.18.0" />
<PackageReference Include="Squidex.Messaging.All" Version="5.18.0" />
<PackageReference Include="Squidex.Messaging.Subscriptions" Version="5.18.0" />
<PackageReference Include="Squidex.Hosting" Version="5.19.0" />
<PackageReference Include="Squidex.Messaging.All" Version="5.19.0" />
<PackageReference Include="Squidex.Messaging.Subscriptions" Version="5.19.0" />
<PackageReference Include="Squidex.OpenIddict.MongoDb" Version="4.0.1-dev" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="all" />
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions backend/src/Squidex/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public void ConfigureServices(IServiceCollection services)
services.AddSquidexContents(config);
services.AddSquidexControllerServices(config);
services.AddSquidexEventSourcing(config);
services.AddSquidexFrontend();
services.AddSquidexGraphQL();
services.AddSquidexHealthChecks(config);
services.AddSquidexHistory(config);
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/app/features/apps/pages/apps-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ export class AppsPageComponent implements OnInit {
private readonly tourState: TourState,
private readonly uiOptions: UIOptions,
) {
if (uiOptions.get('showInfo')) {
this.info = uiOptions.get('info');
if (uiOptions.value.showInfo) {
this.info = uiOptions.value.info;
}
}

Expand All @@ -87,7 +87,7 @@ export class AppsPageComponent implements OnInit {
this.tourState.complete();
}

if (!this.uiOptions.get('hideNews')) {
if (!this.uiOptions.value.hideNews) {
const newsVersion = this.localStore.getInt(Settings.Local.NEWS_VERSION);

this.newsService.getFeatures(newsVersion)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<sqx-field-copy-button [formModel]="formModel" [languages]="languages"></sqx-field-copy-button>

<button *ngIf="!formModel.field.isDisabled && isTranslatable" type="button" class="btn btn-sm btn-outline-secondary force no-focus-shadow ms-1" title="i18n:contents.autotranslate" (click)="translate()" tabindex="-1">
<button *ngIf="isTranslatable" type="button" [disabled]="formModel.field.isDisabled" class="btn btn-sm btn-outline-secondary force no-focus-shadow ms-1" title="i18n:contents.autotranslate" (click)="translate()" tabindex="-1">
<i class="icon-translate"></i>
</button>
</div>
Expand All @@ -32,6 +32,7 @@
[formLevel]="formLevel"
[formModel]="formModel.get(language)"
[isComparing]="!!formModelCompare"
[hasChatBot]="hasChatBot"
[language]="language"
[languages]="languages">
</sqx-field-editor>
Expand All @@ -46,6 +47,7 @@
[formLevel]="formLevel"
[formModel]="getControl()"
[isComparing]="!!formModelCompare"
[hasChatBot]="hasChatBot"
[language]="language"
[languages]="languages">
</sqx-field-editor>
Expand Down Expand Up @@ -85,6 +87,7 @@
[formLevel]="formLevel"
[formModel]="formModelCompare.get(language)"
[isComparing]="!!formModelCompare"
[hasChatBot]="hasChatBot"
[language]="language"
[languages]="languages">
</sqx-field-editor>
Expand All @@ -99,7 +102,8 @@
[formModel]="getControlCompare()!"
[language]="language"
[languages]="languages"
[isComparing]="!!formModelCompare">
[isComparing]="!!formModelCompare"
[hasChatBot]="hasChatBot">
</sqx-field-editor>
</ng-template>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
*/

import { booleanAttribute, Component, EventEmitter, HostBinding, Input, numberAttribute, Output } from '@angular/core';
import { booleanAttribute, Component, EventEmitter, HostBinding, inject, Input, numberAttribute, Output } from '@angular/core';
import { Observable } from 'rxjs';
import { AppLanguageDto, AppsState, changed$, disabled$, EditContentForm, FieldForm, invalid$, LocalStoreService, SchemaDto, Settings, TranslationsService, TypedSimpleChanges } from '@app/shared';
import { AppLanguageDto, AppsState, changed$, disabled$, EditContentForm, FieldForm, invalid$, LocalStoreService, SchemaDto, Settings, TranslationsService, TypedSimpleChanges, UIOptions } from '@app/shared';

@Component({
selector: 'sqx-content-field',
Expand Down Expand Up @@ -54,6 +54,9 @@ export class ContentFieldComponent {
public isInvalid?: Observable<boolean>;
public isDisabled?: Observable<boolean>;

public readonly hasTranslator = inject(UIOptions).value.canUseTranslator;
public readonly hasChatBot = inject(UIOptions).value.canUseChatBot;

@HostBinding('class')
public get class() {
return this.isHalfWidth ? 'col-6 half-field' : 'col-12';
Expand All @@ -64,7 +67,7 @@ export class ContentFieldComponent {
}

public get isTranslatable() {
return this.formModel.field.properties.fieldType === 'String' && this.formModel.field.isLocalizable && this.languages.length > 1;
return this.formModel.field.properties.fieldType === 'String' && this.hasTranslator && this.formModel.field.isLocalizable && this.languages.length > 1;
}

constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
*/

import { Component } from '@angular/core';
import { Component, inject } from '@angular/core';
import { UntypedFormControl } from '@angular/forms';
import { combineLatest } from 'rxjs';
import { map } from 'rxjs/operators';
Expand All @@ -19,7 +19,7 @@ import { AppsState, getCategoryTree, SchemaCategory, SchemasState, Settings, UIO
export class SchemasPageComponent {
public schemasFilter = new UntypedFormControl();

public isEmbedded = false;
public readonly isEmbedded = inject(UIOptions).value.embedded;

public schemas =
this.schemasState.schemas.pipe(
Expand All @@ -43,11 +43,10 @@ export class SchemasPageComponent {
return getCategoryTree(schemas, categories, filter);
});

constructor(uiOptions: UIOptions,
constructor(
public readonly schemasState: SchemasState,
private readonly appsState: AppsState,
) {
this.isEmbedded = uiOptions.get('embedded');
}

public trackByCategory(_index: number, category: SchemaCategory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
[isFirst]="isFirst"
[isLast]="isLast"
(itemRemove)="removeItem(i)"
(itemMove)="move(itemForm, $event)"
(itemMove)="move(itemForm, $event)"
[hasChatBot]="hasChatBot"
[language]="language"
[languages]="languages">
<i cdkDragHandle class="icon-drag2" [class.hidden]="isDisabled | async"></i>
Expand Down Expand Up @@ -53,6 +54,7 @@
(itemExpanded)="scroll.invalidateCachedMeasurementAtIndex(scroll.viewPortInfo.startIndexWithBuffer + i)"
(itemRemove)="removeItem(scroll.viewPortInfo.startIndexWithBuffer + i)"
(itemMove)="move(itemForm, $event)"
[hasChatBot]="hasChatBot"
[language]="language"
[languages]="languages">
</sqx-array-item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import { ArrayItemComponent } from './array-item.component';
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ArrayEditorComponent {
@Input({ required: true })
public hasChatBot!: boolean;

@Input({ required: true })
public form!: EditContentForm;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
[formSection]="$any(section)"
[index]="index"
[isComparing]="isComparing"
[hasChatBot]="hasChatBot"
[language]="language"
[languages]="languages">
</sqx-component-section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export class ArrayItemComponent {
@Output()
public clone = new EventEmitter();

@Input({ required: true })
public hasChatBot!: boolean;

@Input({ required: true })
public form!: EditContentForm;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ <h3>{{separator!.displayName}}</h3>
[formModel]="child"
[index]="index"
[isComparing]="isComparing"
[hasChatBot]="hasChatBot"
[language]="language"
[languages]="languages">
</sqx-field-editor>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import { FieldEditorComponent } from './field-editor.component';
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ComponentSectionComponent {
@Input({ required: true })
public hasChatBot!: boolean;

@Input({ required: true })
public form!: EditContentForm;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
[formLevel]="formLevel + 1"
[formSection]="$any(section)"
[isComparing]="isComparing"
[hasChatBot]="hasChatBot"
[language]="language"
[languages]="languages">
</sqx-component-section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import { ComponentSectionComponent } from './component-section.component';
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ComponentComponent extends ResourceOwner {
@Input({ required: true })
public hasChatBot!: boolean;

@Input({ transform: booleanAttribute })
public canUnset?: boolean | null;

Expand Down
Loading

0 comments on commit 43c207b

Please sign in to comment.