Browse Source

Updates in client for partitioner.

pull/65/head
Sebastian Stehle 9 years ago
parent
commit
a799cada46
  1. 2
      src/Squidex.Events/Schemas/FieldAdded.cs
  2. 5
      src/Squidex.Events/Schemas/Utils/SchemaEventDispatcher.cs
  3. 7
      src/Squidex.Write/Schemas/Commands/AddField.cs
  4. 4
      src/Squidex/Controllers/Api/Schemas/Models/AddFieldDto.cs
  5. 8
      src/Squidex/Controllers/Api/Schemas/Models/Converters/SchemaConverter.cs
  6. 6
      src/Squidex/Controllers/Api/Schemas/Models/FieldDto.cs
  7. 2
      src/Squidex/Controllers/Api/Schemas/SchemaFieldsController.cs
  8. 7
      src/Squidex/Pipeline/ApiExceptionFilterAttribute.cs
  9. 40
      src/Squidex/app/features/content/pages/content/content-field.component.html
  10. 16
      src/Squidex/app/features/content/pages/content/content-field.component.ts
  11. 4
      src/Squidex/app/features/content/pages/content/content-page.component.ts
  12. 2
      src/Squidex/app/features/content/pages/contents/content-item.component.ts
  13. 10
      src/Squidex/app/features/schemas/pages/schema/field.component.html
  14. 4
      src/Squidex/app/features/schemas/pages/schema/field.component.ts
  15. 2
      src/Squidex/app/features/schemas/pages/schema/schema-edit-form.component.html
  16. 36
      src/Squidex/app/features/schemas/pages/schema/schema-page.component.html
  17. 5
      src/Squidex/app/features/schemas/pages/schema/schema-page.component.scss
  18. 25
      src/Squidex/app/features/schemas/pages/schema/schema-page.component.ts
  19. 2
      src/Squidex/app/features/settings/pages/clients/client.component.html
  20. 4
      src/Squidex/app/features/settings/pages/clients/clients-page.component.html
  21. 15
      src/Squidex/app/features/settings/pages/clients/clients-page.component.ts
  22. 2
      src/Squidex/app/features/settings/pages/languages/language.component.html
  23. 2
      src/Squidex/app/features/settings/pages/languages/languages-page.component.html
  24. 2
      src/Squidex/app/shared/components/app-form.component.html
  25. 23
      src/Squidex/app/shared/services/schemas.service.spec.ts
  26. 45
      src/Squidex/app/shared/services/schemas.service.ts

2
src/Squidex.Events/Schemas/FieldAdded.cs

@ -16,7 +16,7 @@ namespace Squidex.Events.Schemas
{
public string Name { get; set; }
public bool IsLocalizable { get; set; }
public string Partitioning { get; set; }
public FieldProperties Properties { get; set; }
}

5
src/Squidex.Events/Schemas/Utils/SchemaEventDispatcher.cs

@ -6,6 +6,7 @@
// All rights reserved.
// ==========================================================================
using System;
using Squidex.Core;
using Squidex.Core.Schemas;
@ -17,8 +18,8 @@ namespace Squidex.Events.Schemas.Utils
{
public static Schema Dispatch(FieldAdded @event, Schema schema, FieldRegistry registry)
{
var partitioning =
@event.IsLocalizable ?
var partitioning =
string.Equals(@event.Partitioning, "language", StringComparison.OrdinalIgnoreCase) ?
Partitioning.Language :
Partitioning.Invariant;

7
src/Squidex.Write/Schemas/Commands/AddField.cs

@ -16,10 +16,17 @@ namespace Squidex.Write.Schemas.Commands
{
public string Name { get; set; }
public string Partitioning { get; set; }
public FieldProperties Properties { get; set; }
public void Validate(IList<ValidationError> errors)
{
if (Partitioning != null && Partitioning != "language")
{
errors.Add(new ValidationError("Partitioning must be invariant or language.", nameof(Partitioning)));
}
if (!Name.IsPropertyName())
{
errors.Add(new ValidationError("Name must be a valid property name", nameof(Name)));

4
src/Squidex/Controllers/Api/Schemas/Models/AddFieldDto.cs

@ -20,9 +20,9 @@ namespace Squidex.Controllers.Api.Schemas.Models
public string Name { get; set; }
/// <summary>
/// Determines if the field is localizable.
/// Determines the optional partitioning of the field.
/// </summary>
public bool IsLocalizable { get; set; }
public string Partitioning { get; set; }
/// <summary>
/// The field properties.

8
src/Squidex/Controllers/Api/Schemas/Models/Converters/SchemaConverter.cs

@ -62,7 +62,13 @@ namespace Squidex.Controllers.Api.Schemas.Models.Converters
foreach (var field in entity.Schema.Fields)
{
var fieldPropertiesDto = Factories[field.RawProperties.GetType()](field.RawProperties);
var fieldInstanceDto = SimpleMapper.Map(field, new FieldDto { FieldId = field.Id, Properties = fieldPropertiesDto });
var fieldInstanceDto = SimpleMapper.Map(field,
new FieldDto
{
FieldId = field.Id,
Properties = fieldPropertiesDto,
Partitioning = field.Paritioning.Key
});
dto.Fields.Add(fieldInstanceDto);
}

6
src/Squidex/Controllers/Api/Schemas/Models/FieldDto.cs

@ -34,6 +34,12 @@ namespace Squidex.Controllers.Api.Schemas.Models
/// </summary>
public bool IsDisabled { get; set; }
/// <summary>
/// Defines the partitioning of the field.
/// </summary>
[Required]
public string Partitioning { get; set; }
/// <summary>
/// The field properties.
/// </summary>

2
src/Squidex/Controllers/Api/Schemas/SchemaFieldsController.cs

@ -51,7 +51,7 @@ namespace Squidex.Controllers.Api.Schemas
[ProducesResponseType(typeof(ErrorDto), 400)]
public async Task<IActionResult> PostField(string app, string name, [FromBody] AddFieldDto request)
{
var command = new AddField { Name = request.Name, Properties = request.Properties.ToProperties() };
var command = new AddField { Name = request.Name, Partitioning = request.Partitioning, Properties = request.Properties.ToProperties() };
var context = await CommandBus.PublishAsync(command);

7
src/Squidex/Pipeline/ApiExceptionFilterAttribute.cs

@ -64,7 +64,12 @@ namespace Squidex.Pipeline
{
if (!context.ModelState.IsValid)
{
var errors = context.ModelState.Values.SelectMany(g => g.Errors).Select(e => new ValidationError(e.ErrorMessage)).ToList();
var errors =
context.ModelState.SelectMany(m =>
{
return m.Value.Errors.Where(e => !string.IsNullOrWhiteSpace(e.ErrorMessage))
.Select(e => new ValidationError(e.ErrorMessage, m.Key));
}).ToList();
throw new ValidationException("The model is not valid.", errors);
}

40
src/Squidex/app/features/content/pages/content/content-field.component.html

@ -6,25 +6,25 @@
<span class="field-disabled" *ngIf="field.isDisabled">Disabled</span>
<div [formGroup]="fieldForm">
<div *ngIf="field.properties.isLocalizable && languages.length > 1">
<div *ngIf="field.partitioning === 'language' && languages.length > 1">
<sqx-language-selector size="sm" class="languages-buttons" (selectedLanguageChanged)="selectLanguage($event)" [languages]="languages"></sqx-language-selector>
</div>
<div *ngFor="let language of fieldLanguages">
<div *ngIf="language == fieldLanguage">
<sqx-control-errors [for]="language" fieldName="{{field|displayName:'properties.label':'name'}}" [submitted]="contentFormSubmitted"></sqx-control-errors>
<div *ngFor="let partition of fieldPartitions">
<div *ngIf="partition == fieldPartition">
<sqx-control-errors [for]="partition" fieldName="{{field|displayName:'properties.label':'name'}}" [submitted]="contentFormSubmitted"></sqx-control-errors>
<div [ngSwitch]="field.properties.fieldType">
<div *ngSwitchCase="'Number'">
<div [ngSwitch]="field.properties.editor">
<div *ngSwitchCase="'Input'">
<input class="form-control" type="number" [formControlName]="language">
<input class="form-control" type="number" [formControlName]="partition">
</div>
<div *ngSwitchCase="'Stars'">
<sqx-stars [formControlName]="language" [maximumStars]="field.properties.maxValue"></sqx-stars>
<sqx-stars [formControlName]="partition" [maximumStars]="field.properties.maxValue"></sqx-stars>
</div>
<div *ngSwitchCase="'Dropdown'">
<select class="form-control" [formControlName]="language">
<select class="form-control" [formControlName]="partition">
<option></option>
<option *ngFor="let value of field.properties.allowedValues" [ngValue]="value">{{value}}</option>
</select>
@ -32,7 +32,7 @@
<div *ngSwitchCase="'Radio'">
<div class="form-check form-check-inline" *ngFor="let value of field.properties.allowedValues">
<label class="form-check-label">
<input class="form-check-input" type="radio" value="{{value}}" [formControlName]="language"> {{value}}
<input class="form-check-input" type="radio" value="{{value}}" [formControlName]="partition"> {{value}}
</label>
</div>
</div>
@ -41,26 +41,26 @@
<div *ngSwitchCase="'String'">
<div [ngSwitch]="field.properties.editor">
<div *ngSwitchCase="'Input'">
<input class="form-control" type="text" [formControlName]="language">
<input class="form-control" type="text" [formControlName]="partition">
</div>
<div *ngSwitchCase="'TextArea'">
<textarea class="form-control" [formControlName]="language"></textarea>
<textarea class="form-control" [formControlName]="partition"></textarea>
</div>
<div *ngSwitchCase="'RichText'">
<sqx-rich-editor [formControlName]="language"></sqx-rich-editor>
<sqx-rich-editor [formControlName]="partition"></sqx-rich-editor>
</div>
<div *ngSwitchCase="'Markdown'">
<sqx-markdown-editor [formControlName]="language"></sqx-markdown-editor>
<sqx-markdown-editor [formControlName]="partition"></sqx-markdown-editor>
</div>
<div *ngSwitchCase="'Dropdown'">
<select class="form-control" [formControlName]="language">
<select class="form-control" [formControlName]="partition">
<option *ngFor="let value of field.properties.allowedValues" [ngValue]="value">{{value}}</option>
</select>
</div>
<div *ngSwitchCase="'Radio'">
<div class="form-check form-check-inline" *ngFor="let value of field.properties.allowedValues">
<label class="form-check-label">
<input class="form-check-input" type="radio" value="{{value}}" [formControlName]="language"> {{value}}
<input class="form-check-input" type="radio" value="{{value}}" [formControlName]="partition"> {{value}}
</label>
</div>
</div>
@ -69,28 +69,28 @@
<div *ngSwitchCase="'Boolean'">
<div [ngSwitch]="field.properties.editor">
<div *ngSwitchCase="'Toggle'">
<sqx-toggle [formControlName]="language"></sqx-toggle>
<sqx-toggle [formControlName]="partition"></sqx-toggle>
</div>
<div *ngSwitchCase="'Checkbox'">
<div class="form-check form-check-inline">
<label class="form-check-label">
<input class="form-check-input" type="checkbox" [formControlName]="language" sqxIndeterminateValue />
<input class="form-check-input" type="checkbox" [formControlName]="partition" sqxIndeterminateValue />
</label>
</div>
</div>
</div>
</div>
<div *ngSwitchCase="'DateTime'">
<sqx-date-time-editor enforceTime="true" [mode]="field.properties.editor" [formControlName]="language"></sqx-date-time-editor>
<sqx-date-time-editor enforceTime="true" [mode]="field.properties.editor" [formControlName]="partition"></sqx-date-time-editor>
</div>
<div *ngSwitchCase="'Geolocation'">
<sqx-geolocation-editor [formControlName]="language"></sqx-geolocation-editor>
<sqx-geolocation-editor [formControlName]="partition"></sqx-geolocation-editor>
</div>
<div *ngSwitchCase="'Json'">
<sqx-json-editor [formControlName]="language"></sqx-json-editor>
<sqx-json-editor [formControlName]="partition"></sqx-json-editor>
</div>
<div *ngSwitchCase="'Assets'">
<sqx-assets-editor [formControlName]="language"></sqx-assets-editor>
<sqx-assets-editor [formControlName]="partition"></sqx-assets-editor>
</div>
</div>
</div>

16
src/Squidex/app/features/content/pages/content/content-field.component.ts

@ -28,11 +28,11 @@ export class ContentFieldComponent implements OnInit {
@Input()
public contentFormSubmitted: boolean;
public fieldLanguages: string[];
public fieldLanguage: string;
public fieldPartitions: string[];
public fieldPartition: string;
public selectLanguage(language: AppLanguageDto) {
this.fieldLanguage = language.iso2Code;
this.fieldPartition = language.iso2Code;
}
public ngOnInit() {
@ -40,12 +40,12 @@ export class ContentFieldComponent implements OnInit {
this.fieldForm.disable();
}
if (this.field.properties.isLocalizable) {
this.fieldLanguages = this.languages.map(t => t.iso2Code);
this.fieldLanguage = this.fieldLanguages[0];
if (this.field.partitioning === 'language') {
this.fieldPartitions = this.languages.map(t => t.iso2Code);
this.fieldPartition = this.fieldPartitions[0];
} else {
this.fieldLanguages = ['iv'];
this.fieldLanguage = 'iv';
this.fieldPartitions = ['iv'];
this.fieldPartition = 'iv';
}
}
}

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

@ -230,7 +230,7 @@ export class ContentPageComponent extends AppComponentBase implements CanCompone
const group = new FormGroup({});
if (field.properties.isLocalizable) {
if (field.partitioning === 'language') {
for (let language of this.languages) {
group.addControl(language.iso2Code, new FormControl(undefined, validators));
}
@ -263,7 +263,7 @@ export class ContentPageComponent extends AppComponentBase implements CanCompone
const fieldValue = content.data[field.name] || {};
const fieldForm = <FormGroup>this.contentForm.controls[field.name];
if (field.properties.isLocalizable) {
if (field.partitioning === 'language') {
for (let language of this.languages) {
fieldForm.controls[language.iso2Code].setValue(fieldValue[language.iso2Code]);
}

2
src/Squidex/app/features/content/pages/contents/content-item.component.ts

@ -85,7 +85,7 @@ export class ContentItemComponent extends AppComponentBase implements OnInit, On
let value: any;
if (properties.isLocalizable) {
if (field.partitioning === 'language') {
value = contentField[this.language.iso2Code];
} else {
value = contentField['iv'];

10
src/Squidex/app/features/schemas/pages/schema/field.component.html

@ -64,7 +64,7 @@
</ul>
<div class="float-right">
<button type="reset" class="btn btn-link" (click)="cancel()">Cancel</button>
<button type="reset" class="btn btn-link" (click)="cancel()" [disabled]="editFormSubmitted">Cancel</button>
<button type="submit" class="btn btn-primary">Save</button>
</div>
</div>
@ -121,14 +121,6 @@
</div>
</div>
</div>
<div class="form-group row">
<div class="form-check offset-3 col col-9">
<label class="form-check-label">
<input class="form-check-input" type="checkbox" formControlName="isLocalizable"> Localizable
</label>
</div>
</div>
</div>
<div class="table-items-row-details-tab" [class.hidden]="selectedTab !== 1">

4
src/Squidex/app/features/schemas/pages/schema/field.component.ts

@ -66,8 +66,7 @@ export class FieldComponent implements OnInit {
Validators.maxLength(100)
]],
isRequired: [false],
isListField: [false],
isLocalizable: [false]
isListField: [false]
});
constructor(
@ -91,6 +90,7 @@ export class FieldComponent implements OnInit {
this.field.name,
this.field.isHidden,
this.field.isHidden,
this.field.partitioning,
properties);
this.saving.emit(field);

2
src/Squidex/app/features/schemas/pages/schema/schema-edit-form.component.html

@ -22,7 +22,7 @@
</div>
<div class="form-group clearfix">
<button type="reset" class="float-left btn btn-secondary" (click)="cancel()">Cancel</button>
<button type="reset" class="float-left btn btn-secondary" (click)="cancel()" [disabled]="editFormSubmitted">Cancel</button>
<button type="submit" class="float-right btn btn-primary">Save</button>
</div>
</form>

36
src/Squidex/app/features/schemas/pages/schema/schema-page.component.html

@ -48,21 +48,35 @@
</div>
<div class="table-items-footer">
<form class="form-inline" [formGroup]="addFieldForm" (ngSubmit)="addField()">
<div class="form-group mr-2">
<select class="form-control" formControlName="type">
<option *ngFor="let type of fieldTypes" [ngValue]="type">{{type}}</option>
</select>
<form [formGroup]="addFieldForm" (ngSubmit)="addField()">
<div class="form-inline">
<div class="form-group mr-1">
<select class="form-control" formControlName="type">
<option *ngFor="let type of fieldTypes" [ngValue]="type">{{type}}</option>
</select>
</div>
<div class="form-group mr-1">
<sqx-control-errors for="name" [submitted]="addFieldFormSubmitted"></sqx-control-errors>
<input type="text" class="form-control" formControlName="name" maxlength="40" placeholder="Enter field name" />
</div>
<button type="submit" class="btn btn-success" [disabled]="!hasName">Add Field</button>
<button type="reset" class="btn btn-link" (click)="resetFieldForm()" [disabled]="addFieldFormSubmitted">Cancel</button>
</div>
<div class="form-group mr-2">
<sqx-control-errors for="name" [submitted]="addFieldFormSubmitted"></sqx-control-errors>
<div>
<div class="form-check">
<label class="form-check-label pull-left">
<input class="form-check-input" type="checkbox" formControlName="isLocalizable"> Localizable
</label>
</div>
<input type="text" class="form-control" formControlName="name" maxlength="40" placeholder="Enter field name" />
<div class="form-hint">
You can the field as localizable. It means that is dependent on the language, e.g. a city name.
</div>
</div>
<button type="submit" class="btn btn-success" [disabled]="!hasName">Add Field</button>
<button type="reset" class="btn btn-link" (click)="resetFieldForm()">Cancel</button>
</form>
</div>
</div>

5
src/Squidex/app/features/schemas/pages/schema/schema-page.component.scss

@ -30,6 +30,11 @@
}
}
.form-check {
margin-top: 1rem;
margin-bottom: -.2rem;
}
.dnd-sortable-drag {
border: 0;
}

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

@ -74,7 +74,8 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit {
[
Validators.maxLength(40),
ValidatorsEx.pattern('[a-zA-Z0-9]+(\\-[a-zA-Z0-9]+)*', 'Name must be a valid javascript name in camel case.')
]]
]],
isLocalizable: [false]
});
public get hasName() {
@ -130,7 +131,7 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit {
this.appNameOnce()
.switchMap(app => this.schemasService.enableField(app, this.schemaName, field.fieldId, this.version)).retry(2)
.subscribe(() => {
this.updateField(field, new FieldDto(field.fieldId, field.name, field.isHidden, false, field.properties));
this.updateField(field, new FieldDto(field.fieldId, field.name, field.isHidden, false, field.partitioning, field.properties));
}, error => {
this.notifyError(error);
});
@ -140,7 +141,7 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit {
this.appNameOnce()
.switchMap(app => this.schemasService.disableField(app, this.schemaName, field.fieldId, this.version)).retry(2)
.subscribe(() => {
this.updateField(field, new FieldDto(field.fieldId, field.name, field.isHidden, true, field.properties));
this.updateField(field, new FieldDto(field.fieldId, field.name, field.isHidden, true, field.partitioning, field.properties));
}, error => {
this.notifyError(error);
});
@ -150,7 +151,7 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit {
this.appNameOnce()
.switchMap(app => this.schemasService.showField(app, this.schemaName, field.fieldId, this.version)).retry(2)
.subscribe(() => {
this.updateField(field, new FieldDto(field.fieldId, field.name, false, field.isDisabled, field.properties));
this.updateField(field, new FieldDto(field.fieldId, field.name, false, field.isDisabled, field.partitioning, field.properties));
}, error => {
this.notifyError(error);
});
@ -160,7 +161,7 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit {
this.appNameOnce()
.switchMap(app => this.schemasService.hideField(app, this.schemaName, field.fieldId, this.version)).retry(2)
.subscribe(() => {
this.updateField(field, new FieldDto(field.fieldId, field.name, true, field.isDisabled, field.properties));
this.updateField(field, new FieldDto(field.fieldId, field.name, true, field.isDisabled, field.partitioning, field.properties));
}, error => {
this.notifyError(error);
});
@ -194,7 +195,7 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit {
this.appNameOnce()
.switchMap(app => this.schemasService.putField(app, this.schemaName, field.fieldId, request, this.version)).retry(2)
.subscribe(() => {
this.updateField(field, new FieldDto(field.fieldId, field.name, newField.isHidden, field.isDisabled, newField.properties));
this.updateField(field, new FieldDto(field.fieldId, field.name, newField.isHidden, field.isDisabled, field.partitioning, newField.properties));
}, error => {
this.notifyError(error);
});
@ -222,11 +223,12 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit {
this.addFieldForm.disable();
const properties = createProperties(this.addFieldForm.get('type')!.value);
const partitioning = this.addFieldForm.get('isLocalizable')!.value ? 'language' : 'invariant';
const requestDto = new AddFieldDto(this.addFieldForm.get('name')!.value, properties);
const requestDto = new AddFieldDto(this.addFieldForm.get('name')!.value, partitioning, properties);
const reset = () => {
this.addFieldForm.get('name')!.reset();
this.addFieldForm.reset({ type: 'String' });
this.addFieldForm.enable();
this.addFieldFormSubmitted = false;
};
@ -236,10 +238,11 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit {
.subscribe(dto => {
const newField =
new FieldDto(parseInt(dto.id, 10),
this.addFieldForm.get('name')!.value,
requestDto.name,
false,
false,
properties);
requestDto.partitioning,
requestDto.properties);
this.updateFields(this.schemaFields.push(newField));
reset();
@ -251,8 +254,8 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit {
}
public resetFieldForm() {
this.addFieldForm.reset({ type: 'String' });
this.addFieldFormSubmitted = false;
this.addFieldForm.reset();
}
public onSchemaSaved(properties: SchemaPropertiesDto) {

2
src/Squidex/app/features/settings/pages/clients/client.component.html

@ -14,7 +14,7 @@
<div class="client-header">
<form *ngIf="isRenaming" class="form-inline" [formGroup]="renameForm" (ngSubmit)="rename()">
<div class="form-group mr-2">
<div class="form-group mr-1">
<sqx-control-errors for="name" [submitted]="renameFormSubmitted"></sqx-control-errors>
<input type="text" class="form-control client-name enabled" formControlName="name" maxlength="20" sqxFocusOnInit (keydown)="onKeyDown($event.keyCode)" />

4
src/Squidex/app/features/settings/pages/clients/clients-page.component.html

@ -25,14 +25,14 @@
<div class="table-items-footer">
<form class="form-inline" [formGroup]="addClientForm" (ngSubmit)="attachClient()">
<div class="form-group mr-2">
<div class="form-group mr-1">
<sqx-control-errors for="name" [submitted]="addClientFormSubmitted"></sqx-control-errors>
<input type="text" class="form-control" formControlName="name" maxlength="40" placeholder="Enter client name" autocomplete="off" sqxLowerCaseInput />
</div>
<button type="submit" class="btn btn-success" [disabled]="!hasName">Add Client</button>
<button type="reset" class="btn btn-link" (click)="resetClientForm()">Cancel</button>
<button type="reset" class="btn btn-link" (click)="resetClientForm()" [disabled]="addClientFormSubmitted">Cancel</button>
</form>
</div>
</div>

15
src/Squidex/app/features/settings/pages/clients/clients-page.component.ts

@ -93,32 +93,25 @@ export class ClientsPageComponent extends AppComponentBase implements OnInit {
public resetClientForm() {
this.addClientFormSubmitted = false;
this.addClientForm.enable();
this.addClientForm.reset();
}
public attachClient() {
this.addClientFormSubmitted = true;
this.addClientForm.markAsDirty();
if (this.addClientForm.valid) {
this.addClientFormSubmitted = true;
this.addClientForm.disable();
const requestDto = new CreateAppClientDto(this.addClientForm.get('name')!.value);
const reset = () => {
this.addClientFormSubmitted = false;
this.addClientForm.reset();
this.addClientForm.enable();
};
this.appNameOnce()
.switchMap(app => this.appClientsService.postClient(app, requestDto, this.version))
.subscribe(dto => {
this.updateClients(this.appClients.push(dto));
reset();
this.resetClientForm();
}, error => {
this.notifyError(error);
reset();
this.resetClientForm();
});
}
}

2
src/Squidex/app/features/settings/pages/languages/language.component.html

@ -46,7 +46,7 @@
</div>
<form class="form-inline fallback-form" [formGroup]="addLanguageForm" (ngSubmit)="addLanguage()" *ngIf="otherLanguages.length > 0">
<div class="form-group mr-2">
<div class="form-group mr-1">
<select class="form-control fallback-select" formControlName="language">
<option *ngFor="let language of otherLanguages" [ngValue]="language">{{language.englishName}}</option>
</select>

2
src/Squidex/app/features/settings/pages/languages/languages-page.component.html

@ -21,7 +21,7 @@
<div class="table-items-footer">
<form class="form-inline" [formGroup]="addLanguageForm" (ngSubmit)="addLanguage()">
<div class="form-group mr-2">
<div class="form-group mr-1">
<select class="form-control language-select" formControlName="language">
<option *ngFor="let language of newLanguages" [ngValue]="language">{{language.englishName}}</option>
</select>

2
src/Squidex/app/shared/components/app-form.component.html

@ -22,7 +22,7 @@
</div>
<div class="form-group clearfix">
<button type="reset" class="float-left btn btn-secondary" (click)="cancel()">Cancel</button>
<button type="reset" class="float-left btn btn-secondary" (click)="cancel()" [disabled]="createFormSubmitted">Cancel</button>
<button type="submit" class="float-right btn btn-success">Create</button>
</div>
</form>

23
src/Squidex/app/shared/services/schemas.service.spec.ts

@ -118,6 +118,7 @@ describe('SchemasService', () => {
name: 'field1',
isHidden: true,
isDisabled: true,
partitioning: 'language',
properties: {
fieldType: 'Number'
}
@ -127,6 +128,7 @@ describe('SchemasService', () => {
name: 'field2',
isHidden: true,
isDisabled: true,
partitioning: 'language',
properties: {
fieldType: 'String'
}
@ -136,6 +138,7 @@ describe('SchemasService', () => {
name: 'field3',
isHidden: true,
isDisabled: true,
partitioning: 'language',
properties: {
fieldType: 'Boolean'
}
@ -145,6 +148,7 @@ describe('SchemasService', () => {
name: 'field4',
isHidden: true,
isDisabled: true,
partitioning: 'language',
properties: {
fieldType: 'DateTime'
}
@ -154,6 +158,7 @@ describe('SchemasService', () => {
name: 'field5',
isHidden: true,
isDisabled: true,
partitioning: 'language',
properties: {
fieldType: 'Json'
}
@ -163,6 +168,7 @@ describe('SchemasService', () => {
name: 'field6',
isHidden: true,
isDisabled: true,
partitioning: 'language',
properties: {
fieldType: 'Geolocation'
}
@ -172,6 +178,7 @@ describe('SchemasService', () => {
name: 'field7',
isHidden: true,
isDisabled: true,
partitioning: 'language',
properties: {
fieldType: 'Assets'
}
@ -195,13 +202,13 @@ describe('SchemasService', () => {
DateTime.parseISO_UTC('2017-12-12T10:10'),
new Version('11'),
[
new FieldDto(1, 'field1', true, true, createProperties('Number')),
new FieldDto(2, 'field2', true, true, createProperties('String')),
new FieldDto(3, 'field3', true, true, createProperties('Boolean')),
new FieldDto(4, 'field4', true, true, createProperties('DateTime')),
new FieldDto(5, 'field5', true, true, createProperties('Json')),
new FieldDto(6, 'field6', true, true, createProperties('Geolocation')),
new FieldDto(7, 'field7', true, true, createProperties('Assets'))
new FieldDto(1, 'field1', true, true, 'language', createProperties('Number')),
new FieldDto(2, 'field2', true, true, 'language', createProperties('String')),
new FieldDto(3, 'field3', true, true, 'language', createProperties('Boolean')),
new FieldDto(4, 'field4', true, true, 'language', createProperties('DateTime')),
new FieldDto(5, 'field5', true, true, 'language', createProperties('Json')),
new FieldDto(6, 'field6', true, true, 'language', createProperties('Geolocation')),
new FieldDto(7, 'field7', true, true, 'language', createProperties('Assets'))
]));
authService.verifyAll();
@ -235,7 +242,7 @@ describe('SchemasService', () => {
});
it('should make post request to add field', () => {
const dto = new AddFieldDto('name', createProperties('Number'));
const dto = new AddFieldDto('name', 'invariant', createProperties('Number'));
authService.setup(x => x.authPost('http://service/p/api/apps/my-app/schemas/my-schema/fields', dto, version))
.returns(() => Observable.of(

45
src/Squidex/app/shared/services/schemas.service.ts

@ -24,25 +24,25 @@ export function createProperties(fieldType: string, values: Object | null = null
switch (fieldType) {
case 'Number':
properties = new NumberFieldPropertiesDto(null, null, null, false, false, false, 'Input');
properties = new NumberFieldPropertiesDto(null, null, null, false, false, 'Input');
break;
case 'String':
properties = new StringFieldPropertiesDto(null, null, null, false, false, false, 'Input');
properties = new StringFieldPropertiesDto(null, null, null, false, false, 'Input');
break;
case 'Boolean':
properties = new BooleanFieldPropertiesDto(null, null, null, false, false, false, 'Checkbox');
properties = new BooleanFieldPropertiesDto(null, null, null, false, false, 'Checkbox');
break;
case 'DateTime':
properties = new DateTimeFieldPropertiesDto(null, null, null, false, false, false, 'DateTime');
properties = new DateTimeFieldPropertiesDto(null, null, null, false, false, 'DateTime');
break;
case 'Geolocation':
properties = new GeolocationFieldPropertiesDto(null, null, null, false, false, false, 'Map');
properties = new GeolocationFieldPropertiesDto(null, null, null, false, false, 'Map');
break;
case 'Json':
properties = new JsonFieldPropertiesDto(null, null, null, false, false, false);
properties = new JsonFieldPropertiesDto(null, null, null, false, false);
break;
case 'Assets':
properties = new AssetsFieldPropertiesDto(null, null, null, false, false, false);
properties = new AssetsFieldPropertiesDto(null, null, null, false, false);
break;
default:
throw 'Invalid properties type';
@ -93,6 +93,7 @@ export class FieldDto {
public readonly name: string,
public readonly isHidden: boolean,
public readonly isDisabled: boolean,
public readonly partitioning: string,
public readonly properties: FieldPropertiesDto
) {
}
@ -105,8 +106,7 @@ export abstract class FieldPropertiesDto {
public readonly hints: string | null,
public readonly placeholder: string | null,
public readonly isRequired: boolean,
public readonly isListField: boolean,
public readonly isLocalizable: boolean
public readonly isListField: boolean
) {
}
}
@ -115,7 +115,6 @@ export class StringFieldPropertiesDto extends FieldPropertiesDto {
constructor(label: string | null, hints: string | null, placeholder: string | null,
isRequired: boolean,
isListField: boolean,
isLocalizable: boolean,
public readonly editor: string,
public readonly defaultValue?: string,
public readonly pattern?: string,
@ -124,7 +123,7 @@ export class StringFieldPropertiesDto extends FieldPropertiesDto {
public readonly maxLength?: number,
public readonly allowedValues?: string[]
) {
super('String', label, hints, placeholder, isRequired, isListField, isLocalizable);
super('String', label, hints, placeholder, isRequired, isListField);
}
}
@ -132,14 +131,13 @@ export class NumberFieldPropertiesDto extends FieldPropertiesDto {
constructor(label: string | null, hints: string | null, placeholder: string | null,
isRequired: boolean,
isListField: boolean,
isLocalizable: boolean,
public readonly editor: string,
public readonly defaultValue?: number,
public readonly maxValue?: number,
public readonly minValue?: number,
public readonly allowedValues?: number[]
) {
super('Number', label, hints, placeholder, isRequired, isListField, isLocalizable);
super('Number', label, hints, placeholder, isRequired, isListField);
}
}
@ -147,14 +145,13 @@ export class DateTimeFieldPropertiesDto extends FieldPropertiesDto {
constructor(label: string | null, hints: string | null, placeholder: string | null,
isRequired: boolean,
isListField: boolean,
isLocalizable: boolean,
public readonly editor: string,
public readonly defaultValue?: string,
public readonly maxValue?: string,
public readonly minValue?: string,
public readonly calculatedDefaultValue?: string
) {
super('DateTime', label, hints, placeholder, isRequired, isListField, isLocalizable);
super('DateTime', label, hints, placeholder, isRequired, isListField);
}
}
@ -162,11 +159,10 @@ export class BooleanFieldPropertiesDto extends FieldPropertiesDto {
constructor(label: string | null, hints: string | null, placeholder: string | null,
isRequired: boolean,
isListField: boolean,
isLocalizable: boolean,
public readonly editor: string,
public readonly defaultValue?: boolean
) {
super('Boolean', label, hints, placeholder, isRequired, isListField, isLocalizable);
super('Boolean', label, hints, placeholder, isRequired, isListField);
}
}
@ -174,30 +170,27 @@ export class GeolocationFieldPropertiesDto extends FieldPropertiesDto {
constructor(label: string | null, hints: string | null, placeholder: string | null,
isRequired: boolean,
isListField: boolean,
isLocalizable: boolean,
public readonly editor: string
) {
super('Geolocation', label, hints, placeholder, isRequired, isListField, isLocalizable);
super('Geolocation', label, hints, placeholder, isRequired, isListField);
}
}
export class AssetsFieldPropertiesDto extends FieldPropertiesDto {
constructor(label: string | null, hints: string | null, placeholder: string | null,
isRequired: boolean,
isListField: boolean,
isLocalizable: boolean
isListField: boolean
) {
super('Assets', label, hints, placeholder, isRequired, isListField, isLocalizable);
super('Assets', label, hints, placeholder, isRequired, isListField);
}
}
export class JsonFieldPropertiesDto extends FieldPropertiesDto {
constructor(label: string | null, hints: string | null, placeholder: string | null,
isRequired: boolean,
isListField: boolean,
isLocalizable: boolean
isListField: boolean
) {
super('Json', label, hints, placeholder, isRequired, isListField, isLocalizable);
super('Json', label, hints, placeholder, isRequired, isListField);
}
}
@ -212,6 +205,7 @@ export class UpdateSchemaDto {
export class AddFieldDto {
constructor(
public readonly name: string,
public readonly partitioning: string,
public readonly properties: FieldPropertiesDto
) {
}
@ -280,6 +274,7 @@ export class SchemasService {
item.name,
item.isHidden,
item.isDisabled,
item.partitioning,
propertiesDto);
});

Loading…
Cancel
Save