Browse Source

Easy cloning of references.

release/5.7
Sebastian 5 years ago
parent
commit
8c44f1ed38
  1. 31
      backend/src/Squidex.Web/ApiExceptionConverter.cs
  2. 16
      frontend/app/features/content/shared/references/content-creator.component.ts
  3. 4
      frontend/app/features/content/shared/references/reference-item.component.html
  4. 3
      frontend/app/features/content/shared/references/reference-item.component.ts
  5. 5
      frontend/app/features/content/shared/references/references-editor.component.html
  6. 8
      frontend/app/features/content/shared/references/references-editor.component.ts

31
backend/src/Squidex.Web/ApiExceptionConverter.cs

@ -1,4 +1,4 @@
// ==========================================================================
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
@ -84,31 +84,31 @@ namespace Squidex.Web
switch (exception)
{
case ValidationException ex:
return (CreateError(400, T.Get("common.httpValidationError"), ToErrors(ex.Errors).ToArray()), true);
return (CreateError(400, T.Get("common.httpValidationError"), null, ToErrors(ex.Errors)), true);
case DomainObjectNotFoundException ex:
return (CreateError(404, errorCode: ex.ErrorCode), true);
return (CreateError(404, ex.ErrorCode), true);
case DomainObjectVersionException ex:
return (CreateError(412, exception.Message, errorCode: ex.ErrorCode), true);
return (CreateError(412, ex.Message, ex.ErrorCode), true);
case DomainObjectDeletedException ex:
return (CreateError(410, exception.Message, errorCode: ex.ErrorCode), true);
return (CreateError(410, ex.Message, ex.ErrorCode), true);
case DomainObjectConflictException ex:
return (CreateError(409, exception.Message, errorCode: ex.ErrorCode), true);
return (CreateError(409, ex.Message, ex.ErrorCode), true);
case DomainForbiddenException ex:
return (CreateError(403, exception.Message, errorCode: ex.ErrorCode), true);
return (CreateError(403, ex.Message, ex.ErrorCode), true);
case DomainException ex:
return (CreateError(400, exception.Message, errorCode: ex.ErrorCode), true);
return (CreateError(400, ex.Message, ex.ErrorCode), true);
case SecurityException:
return (CreateError(403), false);
case DecoderFallbackException:
return (CreateError(400, exception.Message), true);
case DecoderFallbackException ex:
return (CreateError(400, ex.Message), true);
case BadHttpRequestException ex:
return (CreateError(ex.StatusCode, ex.Message), true);
@ -118,9 +118,16 @@ namespace Squidex.Web
}
}
private static ErrorDto CreateError(int status, string? message = null, string[]? details = null, string? errorCode = null)
private static ErrorDto CreateError(int status, string? message = null, string? errorCode = null, IEnumerable<string>? details = null)
{
var error = new ErrorDto { StatusCode = status, Message = message, Details = details, ErrorCode = errorCode };
var error = new ErrorDto { StatusCode = status, Message = message };
if (!string.IsNullOrWhiteSpace(errorCode))
{
error.ErrorCode = errorCode;
}
error.Details = details?.ToArray();
return error;
}

16
frontend/app/features/content/shared/references/content-creator.component.ts

@ -20,6 +20,12 @@ export class ContentCreatorComponent extends ResourceOwner implements OnInit {
@Output()
public select = new EventEmitter<ReadonlyArray<ContentDto>>();
@Input()
public initialData: any;
@Input()
public schemaName: string;
@Input()
public schemaIds: ReadonlyArray<string>;
@ -52,7 +58,9 @@ export class ContentCreatorComponent extends ResourceOwner implements OnInit {
this.schemas = this.schemas.filter(x => this.schemaIds.indexOf(x.id) >= 0);
}
this.selectSchema(this.schemas[0]);
const selectedSchema = this.schemas.find(x => x.name === this.schemaName) || this.schemas[0];
this.selectSchema(selectedSchema);
}
public selectSchema(selected: string | SchemaDto) {
@ -68,6 +76,12 @@ export class ContentCreatorComponent extends ResourceOwner implements OnInit {
this.contentsState.schema = schema;
this.contentForm = new EditContentForm(this.languages, this.schema, { user: this.formContext.user });
if (this.initialData) {
this.contentForm.load(this.initialData, true);
this.initialData = null;
}
this.changeDetector.markForCheck();
}
});

4
frontend/app/features/content/shared/references/reference-item.component.html

@ -31,6 +31,10 @@
</button>
<div class="reference-menu">
<button class="btn btn-text-secondary" title="{{ 'common.clone' | sqxTranslate }}" (click)="clone.emit()">
<i class="icon-copy"></i>
</button>
<a class="btn btn-text-secondary" target="_blank" [routerLink]="['../..', content.schemaName, content.id]">
<i class="icon-pencil"></i>
</a>

3
frontend/app/features/content/shared/references/reference-item.component.ts

@ -20,6 +20,9 @@ export class ReferenceItemComponent implements OnChanges {
@Output()
public delete = new EventEmitter();
@Output()
public clone = new EventEmitter();
@Input()
public language: AppLanguageDto;

5
frontend/app/features/content/shared/references/references-editor.component.html

@ -5,7 +5,7 @@
<ng-container>
<div class="drop-area-container">
<div class="drop-area">
<a (click)="contentCreatorDialog.show()">{{ 'contents.referencesCreateNew' | sqxTranslate }}</a>
<a (click)="createContent()">{{ 'contents.referencesCreateNew' | sqxTranslate }}</a>
&middot;
@ -23,6 +23,7 @@
class="table-drag"
cdkDrag
cdkDragLockAxis="y"
(clone)="createContent(content)"
[columns]="snapshot.contentItems | sqxContentsColumns"
[isCompact]="snapshot.isCompact"
[isDisabled]="snapshot.isDisabled"
@ -38,8 +39,10 @@
<sqx-content-creator
(select)="select($event)"
[formContext]="formContext"
[initialData]="clonedContent?.data"
[language]="language"
[languages]="languages"
[schemaName]="clonedContent?.schemaName"
[schemaIds]="schemaIds">
</sqx-content-creator>
</ng-container>

8
frontend/app/features/content/shared/references/references-editor.component.ts

@ -52,6 +52,8 @@ export class ReferencesEditorComponent extends StatefulControlComponent<State, R
this.setDisabledState(value === true);
}
public clonedContent?: ContentDto;
public contentCreatorDialog = new DialogModel();
public contentSelectorDialog = new DialogModel();
@ -114,6 +116,12 @@ export class ReferencesEditorComponent extends StatefulControlComponent<State, R
}
}
public createContent(clone?: ContentDto) {
this.clonedContent = clone;
this.contentCreatorDialog.show();
}
private updateValue() {
const ids = this.snapshot.contentItems.map(x => x.id);

Loading…
Cancel
Save