Browse Source

UI updated.

pull/341/head
Sebastian Stehle 7 years ago
parent
commit
b45d30c47e
  1. 13
      src/Squidex.Domain.Apps.Events/Rules/RuleCreated.cs
  2. 13
      src/Squidex.Domain.Apps.Events/Rules/RuleUpdated.cs
  3. 57
      src/Squidex/app/features/rules/pages/rules/triggers/asset-changed-trigger.component.html
  4. 31
      src/Squidex/app/features/rules/pages/rules/triggers/asset-changed-trigger.component.scss
  5. 13
      src/Squidex/app/features/rules/pages/rules/triggers/asset-changed-trigger.component.ts
  6. 86
      src/Squidex/app/features/rules/pages/rules/triggers/content-changed-trigger.component.html
  7. 37
      src/Squidex/app/features/rules/pages/rules/triggers/content-changed-trigger.component.scss
  8. 134
      src/Squidex/app/features/rules/pages/rules/triggers/content-changed-trigger.component.ts
  9. 8
      tools/Migrate_01/OldTriggers/AssetChangedTrigger.cs
  10. 6
      tools/Migrate_01/OldTriggers/ContentChangedTrigger.cs
  11. 8
      tools/Migrate_01/OldTriggers/ContentChangedTriggerSchema.cs

13
src/Squidex.Domain.Apps.Events/Rules/RuleCreated.cs

@ -6,15 +6,26 @@
// ========================================================================== // ==========================================================================
using Squidex.Domain.Apps.Core.Rules; using Squidex.Domain.Apps.Core.Rules;
using Squidex.Infrastructure;
using Squidex.Infrastructure.EventSourcing; using Squidex.Infrastructure.EventSourcing;
namespace Squidex.Domain.Apps.Events.Rules namespace Squidex.Domain.Apps.Events.Rules
{ {
[EventType(nameof(RuleCreated))] [EventType(nameof(RuleCreated))]
public sealed class RuleCreated : RuleEvent public sealed class RuleCreated : RuleEvent, IMigrated<IEvent>
{ {
public RuleTrigger Trigger { get; set; } public RuleTrigger Trigger { get; set; }
public RuleAction Action { get; set; } public RuleAction Action { get; set; }
public IEvent Migrate()
{
if (Trigger is IMigrated<RuleTrigger> migrated)
{
Trigger = migrated.Migrate();
}
return this;
}
} }
} }

13
src/Squidex.Domain.Apps.Events/Rules/RuleUpdated.cs

@ -6,15 +6,26 @@
// ========================================================================== // ==========================================================================
using Squidex.Domain.Apps.Core.Rules; using Squidex.Domain.Apps.Core.Rules;
using Squidex.Infrastructure;
using Squidex.Infrastructure.EventSourcing; using Squidex.Infrastructure.EventSourcing;
namespace Squidex.Domain.Apps.Events.Rules namespace Squidex.Domain.Apps.Events.Rules
{ {
[EventType(nameof(RuleUpdated))] [EventType(nameof(RuleUpdated))]
public sealed class RuleUpdated : RuleEvent public sealed class RuleUpdated : RuleEvent, IMigrated<IEvent>
{ {
public RuleTrigger Trigger { get; set; } public RuleTrigger Trigger { get; set; }
public RuleAction Action { get; set; } public RuleAction Action { get; set; }
public IEvent Migrate()
{
if (Trigger is IMigrated<RuleTrigger> migrated)
{
Trigger = migrated.Migrate();
}
return this;
}
} }
} }

57
src/Squidex/app/features/rules/pages/rules/triggers/asset-changed-trigger.component.html

@ -1,34 +1,33 @@
<div [formGroup]="triggerForm" class="form-horizontal"> <div [formGroup]="triggerForm" class="form-horizontal">
<div class="form-group"> <div class="form-group">
<div class="form-check"> <label for="condition">Condition</label>
<input class="form-check-input" type="checkbox" id="sendCreate" formControlName="sendCreate" />
<label class="form-check-label" for="sendCreate"> <sqx-control-errors for="condition" [submitted]="triggerFormSubmitted"></sqx-control-errors>
created
</label> <textarea class="form-control code" id="condition" formControlName="condition"></textarea>
</div>
</div> </div>
<div class="form-group">
<div class="form-check"> <div class="help">
<input class="form-check-input" type="checkbox" id="sendUpdate" formControlName="sendUpdate" /> <h4>Conditions</h4>
<label class="form-check-label" for="sendUpdate">
updated <p>Conditions are javascript expressions that define when to trigger, for example:</p>
</label>
</div> <ul class="help-examples">
</div> <li class="help-example">
<div class="form-group"> Specific events:
<div class="form-check">
<input class="form-check-input" type="checkbox" id="sendRename" formControlName="sendRename" /> <pre>event.type == 'Created' || event.type == 'Updated'</pre>
<label class="form-check-label" for="sendRename"> </li>
renamed <li class="help-example">
</label> Large assets:
</div>
</div> <pre>event.fileSize > 100000000</pre>
<div class="form-group"> </li>
<div class="form-check"> <li class="help-example">
<input class="form-check-input" type="checkbox" id="sendDelete" formControlName="sendDelete" /> Images only:
<label class="form-check-label" for="sendDelete">
deleted <pre>event.isImage</pre>
</label> </li>
</div> </ul>
</div> </div>
</div> </div>

31
src/Squidex/app/features/rules/pages/rules/triggers/asset-changed-trigger.component.scss

@ -1,2 +1,33 @@
@import '_vars'; @import '_vars';
@import '_mixins'; @import '_mixins';
.code {
font-family: monospace;
}
textarea {
height: 100px;
}
pre {
background: $color-border;
border: 0;
padding: .25rem .5rem;
margin: 0;
}
.help {
& {
font-size: .9rem;
}
&-example {
margin-top: .375rem;
}
&-examples {
margin-top: 0;
margin-bottom: 0;
padding-left: 1.5rem;
}
}

13
src/Squidex/app/features/rules/pages/rules/triggers/asset-changed-trigger.component.ts

@ -24,16 +24,7 @@ export class AssetChangedTriggerComponent implements OnInit {
public triggerFormSubmitted = false; public triggerFormSubmitted = false;
public ngOnInit() { public ngOnInit() {
this.triggerForm.setControl('sendCreate', this.triggerForm.setControl('condition',
new FormControl(this.trigger.sendCreate || false)); new FormControl(this.trigger.condition || ''));
this.triggerForm.setControl('sendUpdate',
new FormControl(this.trigger.sendUpdate || false));
this.triggerForm.setControl('sendRename',
new FormControl(this.trigger.sendRename || false));
this.triggerForm.setControl('sendDelete',
new FormControl(this.trigger.sendDelete || false));
} }
} }

86
src/Squidex/app/features/rules/pages/rules/triggers/content-changed-trigger.component.html

@ -1,15 +1,8 @@
<ng-container *ngIf="!triggerForm.controls.handleAll.value"> <ng-container *ngIf="!triggerForm.controls.handleAll.value">
<table class="table table-middle table-sm table-fixed table-borderless"> <table class="table table-middle table-sm table-fixed table-borderless">
<colgroup> <colgroup>
<col style="width: 100%" /> <col style="width: 40%" />
<col style="width: 40px" /> <col style="width: 60%" />
<col style="width: 40px" />
<col style="width: 40px" />
<col style="width: 40px" />
<col style="width: 40px" />
<col style="width: 40px" />
<col style="width: 40px" />
<col style="width: 40px" />
<col style="width: 40px" /> <col style="width: 40px" />
</colgroup> </colgroup>
@ -17,29 +10,8 @@
<th> <th>
Schema Schema
</th> </th>
<th class="text-center"> <th>
<div class="rotated-label">All</div> Condition
</th>
<th class="text-center">
<div class="rotated-label">Created</div>
</th>
<th class="text-center">
<div class="rotated-label">Updated</div>
</th>
<th class="text-center">
<div class="rotated-label">Deleted</div>
</th>
<th class="text-center">
<div class="rotated-label">Published</div>
</th>
<th class="text-center">
<div class="rotated-label">Unpublished</div>
</th>
<th class="text-center">
<div class="rotated-label">Archived</div>
</th>
<th class="text-center">
<div class="rotated-label">Restored</div>
</th> </th>
<th></th> <th></th>
</tr> </tr>
@ -48,29 +20,8 @@
<td> <td>
<span class="truncate">{{schema.schema.displayName}}</span> <span class="truncate">{{schema.schema.displayName}}</span>
</td> </td>
<td class="text-center" title="Created"> <td class="text-center">
<input type="checkbox" [ngModel]="schema.sendAll" (ngModelChange)="toggleAll(schema)" /> <input type="text" class="form-control code" [(ngModel)]="schema.condition" (blur)="updateValue()" />
</td>
<td class="text-center" title="Created">
<input type="checkbox" [ngModel]="schema.sendCreate" (ngModelChange)="toggle(schema, 'sendCreate')" />
</td>
<td class="text-center" title="Updated">
<input type="checkbox" [ngModel]="schema.sendUpdate" (ngModelChange)="toggle(schema, 'sendUpdate')" />
</td>
<td class="text-center" title="Deleted">
<input type="checkbox" [ngModel]="schema.sendDelete" (ngModelChange)="toggle(schema, 'sendDelete')" />
</td>
<td class="text-center" title="Published">
<input type="checkbox" [ngModel]="schema.sendPublish" (ngModelChange)="toggle(schema, 'sendPublish')" />
</td>
<td class="text-center" title="Unpublished">
<input type="checkbox" [ngModel]="schema.sendUnpublish" (ngModelChange)="toggle(schema, 'sendUnpublish')" />
</td>
<td class="text-center" title="Archived">
<input type="checkbox" [ngModel]="schema.sendArchive" (ngModelChange)="toggle(schema, 'sendArchive')" />
</td>
<td class="text-center" title="Restored">
<input type="checkbox" [ngModel]="schema.sendRestore" (ngModelChange)="toggle(schema, 'sendRestore')" />
</td> </td>
<td class="text-center"> <td class="text-center">
<button type="button" class="btn btn-link btn-secondary" (click)="removeSchema(schema)"> <button type="button" class="btn btn-link btn-secondary" (click)="removeSchema(schema)">
@ -91,6 +42,31 @@
<button type="submit" class="btn btn-success" [disabled]="!hasSchema">Add Schema</button> <button type="submit" class="btn btn-success" [disabled]="!hasSchema">Add Schema</button>
</form> </form>
</div> </div>
<div class="help">
<h4>Conditions</h4>
<p>Conditions are javascript expressions that define when to trigger, for example:</p>
<ul class="help-examples">
<li class="help-example">
Specific events:
<pre>event.type == 'Created' || event.type == 'Published'</pre>
</li>
<li class="help-example">
Content has value:
<pre>event.data.important.iv === true</pre>
</li>
<li class="help-example">
Updated by user:
<pre>user.email === 'user@squidex.io'</pre>
</li>
</ul>
</div>
</ng-container> </ng-container>
<div class="form-group" [formGroup]="triggerForm"> <div class="form-group" [formGroup]="triggerForm">

37
src/Squidex/app/features/rules/pages/rules/triggers/content-changed-trigger.component.scss

@ -4,17 +4,40 @@
.section { .section {
border-top: 1px solid $color-border; border-top: 1px solid $color-border;
padding-top: 1rem; padding-top: 1rem;
padding-bottom: 0; padding-bottom: 1rem;
}
.table {
margin-top: 3.5rem;
} }
.form-check { .form-check {
margin-top: 1rem; margin-top: 1rem;
} }
.rotated-label { .code {
@include rotate(-45deg); font-family: monospace;
}
textarea {
height: 100px;
}
pre {
background: $color-border;
border: 0;
padding: .25rem .5rem;
margin: 0;
}
.help {
& {
font-size: .9rem;
}
&-example {
margin-top: .375rem;
}
&-examples {
margin-top: 0;
margin-bottom: 0;
padding-left: 1.5rem;
}
} }

134
src/Squidex/app/features/rules/pages/rules/triggers/content-changed-trigger.component.ts

@ -16,14 +16,8 @@ import {
export interface TriggerSchemaForm { export interface TriggerSchemaForm {
schema: SchemaDto; schema: SchemaDto;
sendAll: boolean;
sendCreate: boolean; condition?: string;
sendUpdate: boolean;
sendDelete: boolean;
sendPublish: boolean;
sendUnpublish: boolean;
sendArchive: boolean;
sendRestore: boolean;
} }
@Component({ @Component({
@ -60,125 +54,45 @@ export class ContentChangedTriggerComponent implements OnInit {
this.triggerForm.setControl('handleAll', this.triggerForm.setControl('handleAll',
new FormControl(Types.isBoolean(this.trigger.handleAll) ? this.trigger.handleAll : false)); new FormControl(Types.isBoolean(this.trigger.handleAll) ? this.trigger.handleAll : false));
const triggerSchemas: any[] = (this.trigger.schemas = this.trigger.schemas || []); const schemas: TriggerSchemaForm[] = [];
this.triggerSchemas =
ImmutableArray.of(
triggerSchemas.map(triggerSchema => {
const schema = this.schemas.find(s => s.id === triggerSchema.schemaId);
if (schema) {
return this.updateSendAll({
schema: schema,
sendAll: false,
sendCreate: triggerSchema.sendCreate,
sendUpdate: triggerSchema.sendUpdate,
sendDelete: triggerSchema.sendDelete,
sendPublish: triggerSchema.sendPublish,
sendUnpublish: triggerSchema.sendUnpublish,
sendArchive: triggerSchema.sendArchive,
sendRestore: triggerSchema.sendRestore
});
} else {
return null;
}
}).filter(s => !!s).map(s => s!)).sortByStringAsc(s => s.schema.name);
this.schemasToAdd =
this.schemas.filter(schema =>
!triggerSchemas.find(s => s.schemaId === schema.id))
.sortByStringAsc(x => x.name);
this.schemaToAdd = this.schemasToAdd.at(0);
}
public removeSchema(schemaForm: TriggerSchemaForm) { if (this.trigger.schemas) {
this.triggerSchemas = this.triggerSchemas.remove(schemaForm); for (let triggerSchema of this.trigger.schemas) {
const schema = this.schemas.find(s => s.id === triggerSchema.schemaId);
this.updateValue();
this.schemasToAdd = this.schemasToAdd.push(schemaForm.schema).sortByStringAsc(x => x.name);
this.schemaToAdd = this.schemasToAdd.at(0);
}
public addSchema() { if (schema) {
this.triggerSchemas = schemas.push({ schema, condition: triggerSchema.condition });
this.triggerSchemas.push( }
this.updateSendAll({ }
schema: this.schemaToAdd, }
sendAll: false,
sendCreate: false,
sendUpdate: false,
sendDelete: false,
sendPublish: false,
sendUnpublish: false,
sendArchive: false,
sendRestore: false
})).sortByStringAsc(x => x.schema.name);
this.updateValue(); this.triggerSchemas = ImmutableArray.of(schemas).sortByStringAsc(s => s.schema.name);
this.schemasToAdd = this.schemasToAdd.remove(this.schemaToAdd).sortByStringAsc(x => x.name); this.updateSchemaToAdd();
this.schemaToAdd = this.schemasToAdd.at(0);
} }
public toggle(schemaForm: TriggerSchemaForm, property: string) { public removeSchema(schemaForm: TriggerSchemaForm) {
const newSchema = this.updateSendAll(Object.assign({}, schemaForm, { [property]: !schemaForm[property] })); this.triggerSchemas = this.triggerSchemas.remove(schemaForm);
this.triggerSchemas = this.triggerSchemas.replace(schemaForm, newSchema);
this.updateValue(); this.updateValue();
this.updateSchemaToAdd();
} }
public toggleAll(schemaForm: TriggerSchemaForm) { public addSchema() {
const newSchema = this.updateAll(<any>{ schema: schemaForm.schema }, !schemaForm.sendAll); this.triggerSchemas = this.triggerSchemas.push({ schema: this.schemaToAdd }).sortByStringAsc(x => x.schema.name);
this.triggerSchemas = this.triggerSchemas.replace(schemaForm, newSchema);
this.updateValue(); this.updateValue();
this.updateSchemaToAdd();
} }
private updateValue() { public updateValue() {
const schemas = const schemas = this.triggerSchemas.values.map(s => ({ schemaId: s.schema.id, condition: s.condition }));
this.triggerSchemas.values.map(s => {
return {
schemaId: s.schema.id,
sendCreate: s.sendCreate,
sendUpdate: s.sendUpdate,
sendDelete: s.sendDelete,
sendPublish: s.sendPublish,
sendUnpublish: s.sendUnpublish,
sendArchive: s.sendArchive,
sendRestore: s.sendRestore
};
});
this.triggerForm.controls['schemas'].setValue(schemas); this.triggerForm.controls['schemas'].setValue(schemas);
} }
private updateAll(schemaForm: TriggerSchemaForm, value: boolean): TriggerSchemaForm { private updateSchemaToAdd() {
schemaForm.sendAll = value; this.schemasToAdd = this.schemas.filter(schema => !this.triggerSchemas.find(s => s.schema.id === schema.id)).sortByStringAsc(x => x.name);
schemaForm.sendCreate = value; this.schemaToAdd = this.schemasToAdd.at(0);
schemaForm.sendUpdate = value;
schemaForm.sendDelete = value;
schemaForm.sendPublish = value;
schemaForm.sendUnpublish = value;
schemaForm.sendArchive = value;
schemaForm.sendRestore = value;
return schemaForm;
}
private updateSendAll(schemaForm: TriggerSchemaForm): TriggerSchemaForm {
schemaForm.sendAll =
schemaForm.sendCreate &&
schemaForm.sendUpdate &&
schemaForm.sendDelete &&
schemaForm.sendPublish &&
schemaForm.sendUnpublish &&
schemaForm.sendArchive &&
schemaForm.sendRestore;
return schemaForm;
} }
} }

8
tools/Migrate_01/OldTriggers/AssetChangedTrigger.cs

@ -54,9 +54,13 @@ namespace Migrate_01.OldTriggers
conditions.Add($"event.type == '{EnrichedAssetEventType.Deleted}'"); conditions.Add($"event.type == '{EnrichedAssetEventType.Deleted}'");
} }
var condition = "false"; var condition = string.Empty;
if (conditions.Count > 0) if (conditions.Count == 0 && condition.Length < 4)
{
condition = "false";
}
else if (condition.Length < 7)
{ {
condition = string.Join(" || ", conditions); condition = string.Join(" || ", conditions);
} }

6
tools/Migrate_01/OldTriggers/ContentChangedTrigger.cs

@ -7,7 +7,9 @@
using System; using System;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq;
using Squidex.Domain.Apps.Core.Rules; using Squidex.Domain.Apps.Core.Rules;
using Squidex.Domain.Apps.Core.Rules.Triggers;
using Squidex.Infrastructure; using Squidex.Infrastructure;
namespace Migrate_01.OldTriggers namespace Migrate_01.OldTriggers
@ -39,7 +41,9 @@ namespace Migrate_01.OldTriggers
public RuleTrigger Migrate() public RuleTrigger Migrate()
{ {
throw new NotImplementedException(); var schemas = new ReadOnlyCollection<ContentChangedTriggerSchemaV2>(Schemas.Select(x => x.Migrate()).ToList());
return new ContentChangedTriggerV2 { HandleAll = HandleAll, Schemas = schemas };
} }
} }
} }

8
tools/Migrate_01/OldTriggers/ContentChangedTriggerSchema.cs

@ -70,9 +70,13 @@ namespace Migrate_01.OldTriggers
conditions.Add($"event.type == '{EnrichedAssetEventType.Deleted}'"); conditions.Add($"event.type == '{EnrichedAssetEventType.Deleted}'");
} }
var condition = "false"; var condition = string.Empty;
if (conditions.Count > 0) if (conditions.Count == 0 && condition.Length < 7)
{
condition = "false";
}
else if (condition.Length < 7)
{ {
condition = string.Join(" || ", conditions); condition = string.Join(" || ", conditions);
} }

Loading…
Cancel
Save