Browse Source

Warning when you have pending changes for a content and you want to publish it.

pull/432/head
Sebastian Stehle 6 years ago
parent
commit
5f5d2de544
  1. 27
      src/Squidex/app/features/content/pages/content/content-page.component.ts
  2. 3
      src/Squidex/app/framework/angular/modals/dialog-renderer.component.html
  3. 85
      tests/Squidex.Domain.Apps.Core.Tests/Operations/EventSynchronization/SchemaSynchronizerTests.cs

27
src/Squidex/app/features/content/pages/content/content-page.component.ts

@ -156,12 +156,7 @@ export class ContentPageComponent extends ResourceOwner implements CanComponentD
}
public canDeactivate(): Observable<boolean> {
const observable =
this.contentForm.hasChanged() ?
this.dialogs.confirm('Unsaved changes', 'You have unsaved changes, do you want to close the current content view and discard your changes?') :
of(true);
return observable.pipe(
return this.checkPendingChanges('close current content view').pipe(
tap(confirmed => {
if (confirmed) {
this.autoSaveService.remove(this.autoSaveKey);
@ -253,17 +248,29 @@ export class ContentPageComponent extends ResourceOwner implements CanComponentD
}
public publishChanges() {
this.dueTimeSelector.selectDueTime('Publish').pipe(
switchMap(d => this.contentsState.publishDraft(this.content, d)), onErrorResumeNext())
this.checkPendingChanges('publish your changes').pipe(
filter(x => !!x),
switchMap(_ => this.dueTimeSelector.selectDueTime(status)),
switchMap(d => this.contentsState.publishDraft(this.content, d)),
onErrorResumeNext())
.subscribe();
}
public changeStatus(status: string) {
this.dueTimeSelector.selectDueTime(status).pipe(
switchMap(d => this.contentsState.changeStatus(this.content, status, d)), onErrorResumeNext())
this.checkPendingChanges('change the status').pipe(
filter(x => !!x),
switchMap(_ => this.dueTimeSelector.selectDueTime(status)),
switchMap(d => this.contentsState.changeStatus(this.content, status, d)),
onErrorResumeNext())
.subscribe();
}
private checkPendingChanges(action: string) {
return this.contentForm.hasChanged() ?
this.dialogs.confirm('Unsaved changes', `You have unsaved changes. When you ${action} you will loose them.<br />Do you want to continue anyway?`) :
of(true);
}
public showLatest() {
this.loadVersion(null, false);
}

3
src/Squidex/app/framework/angular/modals/dialog-renderer.component.html

@ -1,6 +1,5 @@
<ng-content></ng-content>
<ng-container *sqxModal="dialogView">
<sqx-modal-dialog showClose="false" (close)="cancel()">
<ng-container title>
@ -8,7 +7,7 @@
</ng-container>
<ng-container content>
{{snapshot.dialogRequest?.text}}
<span [innerHTML]="snapshot.dialogRequest?.text"></span>
</ng-container>
<ng-container footer>

85
tests/Squidex.Domain.Apps.Core.Tests/Operations/EventSynchronization/SchemaSynchronizerTests.cs

@ -1,4 +1,5 @@
// ==========================================================================

// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
@ -33,8 +34,11 @@ namespace Squidex.Domain.Apps.Core.Operations.EventSynchronization
[Fact]
public void Should_create_events_if_schema_deleted()
{
var sourceSchema = new Schema("source");
var targetSchema = (Schema)null;
var sourceSchema =
new Schema("source");
var targetSchema =
(Schema)null;
var events = sourceSchema.Synchronize(targetSchema, jsonSerializer, idGenerator);
@ -46,8 +50,12 @@ namespace Squidex.Domain.Apps.Core.Operations.EventSynchronization
[Fact]
public void Should_create_events_if_category_changed()
{
var sourceSchema = new Schema("source");
var targetSchema = new Schema("target").ChangeCategory("Category");
var sourceSchema =
new Schema("source");
var targetSchema =
new Schema("target")
.ChangeCategory("Category");
var events = sourceSchema.Synchronize(targetSchema, jsonSerializer, idGenerator);
@ -64,8 +72,11 @@ namespace Squidex.Domain.Apps.Core.Operations.EventSynchronization
Create = "<create-script>"
};
var sourceSchema = new Schema("source");
var targetSchema = new Schema("target").ConfigureScripts(scripts);
var sourceSchema =
new Schema("source");
var targetSchema =
new Schema("target").ConfigureScripts(scripts);
var events = sourceSchema.Synchronize(targetSchema, jsonSerializer, idGenerator);
@ -82,8 +93,12 @@ namespace Squidex.Domain.Apps.Core.Operations.EventSynchronization
["web"] = "Url"
};
var sourceSchema = new Schema("source");
var targetSchema = new Schema("target").ConfigurePreviewUrls(previewUrls);
var sourceSchema =
new Schema("source");
var targetSchema =
new Schema("target")
.ConfigurePreviewUrls(previewUrls);
var events = sourceSchema.Synchronize(targetSchema, jsonSerializer, idGenerator);
@ -95,8 +110,12 @@ namespace Squidex.Domain.Apps.Core.Operations.EventSynchronization
[Fact]
public void Should_create_events_if_schema_published()
{
var sourceSchema = new Schema("source");
var targetSchema = new Schema("target").Publish();
var sourceSchema =
new Schema("source");
var targetSchema =
new Schema("target")
.Publish();
var events = sourceSchema.Synchronize(targetSchema, jsonSerializer, idGenerator);
@ -108,8 +127,12 @@ namespace Squidex.Domain.Apps.Core.Operations.EventSynchronization
[Fact]
public void Should_create_events_if_schema_unpublished()
{
var sourceSchema = new Schema("source").Publish();
var targetSchema = new Schema("target");
var sourceSchema =
new Schema("source")
.Publish();
var targetSchema =
new Schema("target");
var events = sourceSchema.Synchronize(targetSchema, jsonSerializer, idGenerator);
@ -207,7 +230,8 @@ namespace Squidex.Domain.Apps.Core.Operations.EventSynchronization
var targetSchema =
new Schema("target")
.AddArray(arrayId.Id, arrayId.Name, Partitioning.Invariant, f => f
.AddString(nestedId.Id, nestedId.Name)).LockField(nestedId.Id, arrayId.Id);
.AddString(nestedId.Id, nestedId.Name))
.LockField(nestedId.Id, arrayId.Id);
var events = sourceSchema.Synchronize(targetSchema, jsonSerializer, idGenerator);
@ -225,7 +249,8 @@ namespace Squidex.Domain.Apps.Core.Operations.EventSynchronization
var targetSchema =
new Schema("target")
.AddString(stringId.Id, stringId.Name, Partitioning.Invariant).LockField(stringId.Id);
.AddString(stringId.Id, stringId.Name, Partitioning.Invariant)
.LockField(stringId.Id);
var events = sourceSchema.Synchronize(targetSchema, jsonSerializer, idGenerator);
@ -245,7 +270,8 @@ namespace Squidex.Domain.Apps.Core.Operations.EventSynchronization
var targetSchema =
new Schema("target")
.AddArray(arrayId.Id, arrayId.Name, Partitioning.Invariant, f => f
.AddString(nestedId.Id, nestedId.Name)).HideField(nestedId.Id, arrayId.Id);
.AddString(nestedId.Id, nestedId.Name))
.HideField(nestedId.Id, arrayId.Id);
var events = sourceSchema.Synchronize(targetSchema, jsonSerializer, idGenerator);
@ -263,7 +289,8 @@ namespace Squidex.Domain.Apps.Core.Operations.EventSynchronization
var targetSchema =
new Schema("target")
.AddString(stringId.Id, stringId.Name, Partitioning.Invariant).HideField(stringId.Id);
.AddString(stringId.Id, stringId.Name, Partitioning.Invariant)
.HideField(stringId.Id);
var events = sourceSchema.Synchronize(targetSchema, jsonSerializer, idGenerator);
@ -278,7 +305,8 @@ namespace Squidex.Domain.Apps.Core.Operations.EventSynchronization
var sourceSchema =
new Schema("source")
.AddArray(arrayId.Id, arrayId.Name, Partitioning.Invariant, f => f
.AddString(nestedId.Id, nestedId.Name)).HideField(nestedId.Id, arrayId.Id);
.AddString(nestedId.Id, nestedId.Name))
.HideField(nestedId.Id, arrayId.Id);
var targetSchema =
new Schema("target")
@ -297,7 +325,8 @@ namespace Squidex.Domain.Apps.Core.Operations.EventSynchronization
{
var sourceSchema =
new Schema("source")
.AddString(stringId.Id, stringId.Name, Partitioning.Invariant).HideField(stringId.Id);
.AddString(stringId.Id, stringId.Name, Partitioning.Invariant)
.HideField(stringId.Id);
var targetSchema =
new Schema("target")
@ -321,7 +350,8 @@ namespace Squidex.Domain.Apps.Core.Operations.EventSynchronization
var targetSchema =
new Schema("target")
.AddArray(arrayId.Id, arrayId.Name, Partitioning.Invariant, f => f
.AddString(nestedId.Id, nestedId.Name)).DisableField(nestedId.Id, arrayId.Id);
.AddString(nestedId.Id, nestedId.Name))
.DisableField(nestedId.Id, arrayId.Id);
var events = sourceSchema.Synchronize(targetSchema, jsonSerializer, idGenerator);
@ -339,7 +369,8 @@ namespace Squidex.Domain.Apps.Core.Operations.EventSynchronization
var targetSchema =
new Schema("target")
.AddString(stringId.Id, stringId.Name, Partitioning.Invariant).DisableField(stringId.Id);
.AddString(stringId.Id, stringId.Name, Partitioning.Invariant)
.DisableField(stringId.Id);
var events = sourceSchema.Synchronize(targetSchema, jsonSerializer, idGenerator);
@ -354,7 +385,8 @@ namespace Squidex.Domain.Apps.Core.Operations.EventSynchronization
var sourceSchema =
new Schema("source")
.AddArray(arrayId.Id, arrayId.Name, Partitioning.Invariant, f => f
.AddString(nestedId.Id, nestedId.Name)).DisableField(nestedId.Id, arrayId.Id);
.AddString(nestedId.Id, nestedId.Name))
.DisableField(nestedId.Id, arrayId.Id);
var targetSchema =
new Schema("target")
@ -373,7 +405,8 @@ namespace Squidex.Domain.Apps.Core.Operations.EventSynchronization
{
var sourceSchema =
new Schema("source")
.AddString(stringId.Id, stringId.Name, Partitioning.Invariant).DisableField(stringId.Id);
.AddString(stringId.Id, stringId.Name, Partitioning.Invariant)
.DisableField(stringId.Id);
var targetSchema =
new Schema("target")
@ -394,7 +427,8 @@ namespace Squidex.Domain.Apps.Core.Operations.EventSynchronization
var targetSchema =
new Schema("target")
.AddString(stringId.Id, stringId.Name, Partitioning.Invariant).HideField(stringId.Id);
.AddString(stringId.Id, stringId.Name, Partitioning.Invariant)
.HideField(stringId.Id);
var events = sourceSchema.Synchronize(targetSchema, jsonSerializer, idGenerator);
@ -457,7 +491,8 @@ namespace Squidex.Domain.Apps.Core.Operations.EventSynchronization
var targetSchema =
new Schema("target")
.AddArray(arrayId.Id, arrayId.Name, Partitioning.Invariant, f => f
.AddString(nestedId.Id, nestedId.Name)).HideField(nestedId.Id, arrayId.Id);
.AddString(nestedId.Id, nestedId.Name))
.HideField(nestedId.Id, arrayId.Id);
var events = sourceSchema.Synchronize(targetSchema, jsonSerializer, idGenerator);

Loading…
Cancel
Save