Browse Source

Merge branch 'master' of github.com:Squidex/squidex

pull/118/head
Sebastian Stehle 9 years ago
parent
commit
38a96287d4
  1. 2
      src/Squidex.Domain.Apps.Core/ContentEnricher.cs
  2. 6
      src/Squidex.Domain.Apps.Core/Schemas/FieldProperties.cs
  3. 6
      src/Squidex.Domain.Apps.Core/Schemas/StringFieldProperties.cs
  4. 3
      src/Squidex.Domain.Apps.Events/Webhooks/WebhookDeleted.cs
  5. 1
      src/Squidex.Infrastructure/CQRS/Events/NoopEvent.cs
  6. 2
      src/Squidex/Config/Domain/Serializers.cs
  7. 2
      src/Squidex/Docs/schemabody.md
  8. 2
      src/Squidex/Docs/schemaquery.md
  9. 10
      src/Squidex/app/features/schemas/pages/schema/schema-page.component.ts
  10. 62
      tests/Squidex.Domain.Apps.Core.Tests/ContentEnrichmentTests.cs

2
src/Squidex.Domain.Apps.Core/ContentEnricher.cs

@ -64,7 +64,7 @@ namespace Squidex.Domain.Apps.Core
var key = partitionItem.Key;
if (!fieldData.TryGetValue(key, out var value) || value == null || value.Type == JTokenType.Null)
if (!fieldData.TryGetValue(key, out var value) || field.RawProperties.ShouldApplyDefaultValue(value))
{
fieldData.AddValue(key, defaultValue);
}

6
src/Squidex.Domain.Apps.Core/Schemas/FieldProperties.cs

@ -9,6 +9,7 @@
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Json;
namespace Squidex.Domain.Apps.Core.Schemas
{
@ -62,6 +63,11 @@ namespace Squidex.Domain.Apps.Core.Schemas
public abstract JToken GetDefaultValue();
public virtual bool ShouldApplyDefaultValue(JToken value)
{
return value.IsNull();
}
public void Validate(IList<ValidationError> errors)
{
foreach (var error in ValidateCore())

6
src/Squidex.Domain.Apps.Core/Schemas/StringFieldProperties.cs

@ -10,6 +10,7 @@ using System.Collections.Generic;
using System.Collections.Immutable;
using Newtonsoft.Json.Linq;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Json;
namespace Squidex.Domain.Apps.Core.Schemas
{
@ -127,6 +128,11 @@ namespace Squidex.Domain.Apps.Core.Schemas
return DefaultValue;
}
public override bool ShouldApplyDefaultValue(JToken value)
{
return value.IsNull() || (value is JValue jValue && Equals(jValue.Value, string.Empty));
}
protected override IEnumerable<ValidationError> ValidateCore()
{
if (!Editor.IsEnumValue())

3
src/Squidex.Domain.Apps.Events/Webhooks/WebhookDeleted.cs

@ -6,12 +6,11 @@
// All rights reserved.
// ==========================================================================
using Squidex.Infrastructure;
using Squidex.Infrastructure.CQRS.Events;
namespace Squidex.Domain.Apps.Events.Webhooks
{
[EventType(nameof(WebhookUpdated), 2)]
[EventType(nameof(WebhookDeleted), 2)]
public sealed class WebhookDeleted : WebhookEvent
{
}

1
src/Squidex.Infrastructure/CQRS/Events/NoopEvent.cs

@ -8,6 +8,7 @@
namespace Squidex.Infrastructure.CQRS.Events
{
[TypeName(nameof(NoopEvent))]
public sealed class NoopEvent : IEvent
{
}

2
src/Squidex/Config/Domain/Serializers.cs

@ -14,6 +14,7 @@ using NodaTime;
using NodaTime.Serialization.JsonNet;
using Squidex.Domain.Apps.Events;
using Squidex.Infrastructure;
using Squidex.Infrastructure.CQRS.Events;
using Squidex.Infrastructure.Json;
namespace Squidex.Config.Domain
@ -51,6 +52,7 @@ namespace Squidex.Config.Domain
static Serializers()
{
TypeNameRegistry.Map(typeof(SquidexEvent).GetTypeInfo().Assembly);
TypeNameRegistry.Map(typeof(NoopEvent).GetTypeInfo().Assembly);
}
private static JsonSerializerSettings CreateSettings()

2
src/Squidex/Docs/schemabody.md

@ -4,4 +4,4 @@ Please note that each field is an object with one entry per language.
If the field is not localizable you must use iv (Invariant Language) as a key.
When you change the field to be localizable the value will become the value for the master language, depending what the master language is at this point of time.
Read more about it at: https://docs.squidex.io/04-guides/01-api.html
Read more about it at: https://docs.squidex.io/04-guides/02-api.html

2
src/Squidex/Docs/schemaquery.md

@ -8,4 +8,4 @@ We support the following query options.
* **$filter**: The $filter query option allows clients to filter a collection of resources that are addressed by a request URL.
* **$orderby**: The $orderby query option allows clients to request resources in a particular order.
Read more about it at: https://docs.squidex.io/04-guides/01-api.html
Read more about it at: https://docs.squidex.io/04-guides/02-api.html

10
src/Squidex/app/features/schemas/pages/schema/schema-page.component.ts

@ -156,6 +156,16 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit {
});
}
public showField(field: FieldDto) {
this.appNameOnce()
.switchMap(app => this.schemasService.showField(app, this.schema.name, field.fieldId, this.schema.version)).retry(2)
.subscribe(() => {
this.updateSchema(this.schema.updateField(field.show(), this.authService.user!.token));
}, error => {
this.notifyError(error);
});
}
public hideField(field: FieldDto) {
this.appNameOnce()
.switchMap(app => this.schemasService.hideField(app, this.schema.name, field.fieldId, this.schema.version)).retry(2)

62
tests/Squidex.Domain.Apps.Core.Tests/ContentEnrichmentTests.cs

@ -18,32 +18,30 @@ namespace Squidex.Domain.Apps.Core
{
public class ContentEnrichmentTests
{
private static readonly Instant Now = Instant.FromUnixTimeSeconds(SystemClock.Instance.GetCurrentInstant().ToUnixTimeSeconds());
private readonly LanguagesConfig languagesConfig = LanguagesConfig.Create(Language.DE, Language.EN);
private readonly Schema schema =
Schema.Create("my-schema", new SchemaProperties())
.AddOrUpdateField(new JsonField(1, "my-json", Partitioning.Invariant,
new JsonFieldProperties()))
.AddOrUpdateField(new StringField(2, "my-string", Partitioning.Language,
new StringFieldProperties { DefaultValue = "en-string" }))
.AddOrUpdateField(new NumberField(3, "my-number", Partitioning.Invariant,
new NumberFieldProperties { DefaultValue = 123 }))
.AddOrUpdateField(new AssetsField(4, "my-assets", Partitioning.Invariant,
new AssetsFieldProperties()))
.AddOrUpdateField(new BooleanField(5, "my-boolean", Partitioning.Invariant,
new BooleanFieldProperties { DefaultValue = true }))
.AddOrUpdateField(new DateTimeField(6, "my-datetime", Partitioning.Invariant,
new DateTimeFieldProperties { DefaultValue = Now }))
.AddOrUpdateField(new ReferencesField(7, "my-references", Partitioning.Invariant,
new ReferencesFieldProperties { SchemaId = Guid.NewGuid() }))
.AddOrUpdateField(new GeolocationField(8, "my-geolocation", Partitioning.Invariant,
new GeolocationFieldProperties()));
[Fact]
private void Should_enrich_with_default_values()
{
var now = Instant.FromUnixTimeSeconds(SystemClock.Instance.GetCurrentInstant().ToUnixTimeSeconds());
var schema =
Schema.Create("my-schema", new SchemaProperties())
.AddOrUpdateField(new JsonField(1, "my-json", Partitioning.Invariant,
new JsonFieldProperties()))
.AddOrUpdateField(new StringField(2, "my-string", Partitioning.Language,
new StringFieldProperties { DefaultValue = "en-string" }))
.AddOrUpdateField(new NumberField(3, "my-number", Partitioning.Invariant,
new NumberFieldProperties { DefaultValue = 123 }))
.AddOrUpdateField(new AssetsField(4, "my-assets", Partitioning.Invariant,
new AssetsFieldProperties()))
.AddOrUpdateField(new BooleanField(5, "my-boolean", Partitioning.Invariant,
new BooleanFieldProperties { DefaultValue = true }))
.AddOrUpdateField(new DateTimeField(6, "my-datetime", Partitioning.Invariant,
new DateTimeFieldProperties { DefaultValue = now }))
.AddOrUpdateField(new ReferencesField(7, "my-references", Partitioning.Invariant,
new ReferencesFieldProperties { SchemaId = Guid.NewGuid() }))
.AddOrUpdateField(new GeolocationField(8, "my-geolocation", Partitioning.Invariant,
new GeolocationFieldProperties()));
var data =
new NamedContentData()
.AddField("my-string",
@ -60,9 +58,29 @@ namespace Squidex.Domain.Apps.Core
Assert.Equal("de-string", (string)data["my-string"]["de"]);
Assert.Equal("en-string", (string)data["my-string"]["en"]);
Assert.Equal(now, InstantPattern.General.Parse((string)data["my-datetime"]["iv"]).Value);
Assert.Equal(Now, InstantPattern.General.Parse((string)data["my-datetime"]["iv"]).Value);
Assert.Equal(true, (bool)data["my-boolean"]["iv"]);
}
[Fact]
private void Should_also_enrich_with_default_values_when_string_is_empty()
{
var now = Instant.FromUnixTimeSeconds(SystemClock.Instance.GetCurrentInstant().ToUnixTimeSeconds());
var data =
new NamedContentData()
.AddField("my-string",
new ContentFieldData()
.AddValue("de", string.Empty))
.AddField("my-number",
new ContentFieldData()
.AddValue("iv", 456));
data.Enrich(schema, languagesConfig.ToResolver());
Assert.Equal("en-string", (string)data["my-string"]["de"]);
Assert.Equal("en-string", (string)data["my-string"]["en"]);
}
}
}

Loading…
Cancel
Save