Browse Source

Added button to clone a schema.

pull/195/head
Sebastian Stehle 8 years ago
parent
commit
b9632ca0e2
  1. 5
      src/Squidex/Areas/Api/Controllers/Schemas/Models/Converters/SchemaConverter.cs
  2. 7
      src/Squidex/app/features/schemas/pages/messages.ts
  3. 5
      src/Squidex/app/features/schemas/pages/schema/schema-page.component.html
  4. 5
      src/Squidex/app/features/schemas/pages/schema/schema-page.component.ts
  5. 13
      src/Squidex/app/features/schemas/pages/schemas/schema-form.component.ts
  6. 6
      src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.html
  7. 17
      src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.ts

5
src/Squidex/Areas/Api/Controllers/Schemas/Models/Converters/SchemaConverter.cs

@ -7,6 +7,7 @@
// ==========================================================================
using System.Collections.Generic;
using Squidex.Domain.Apps.Core.Schemas;
using Squidex.Domain.Apps.Read.Schemas;
using Squidex.Domain.Apps.Write.Schemas.Commands;
using Squidex.Infrastructure.Reflection;
@ -61,11 +62,15 @@ namespace Squidex.Areas.Api.Controllers.Schemas.Models.Converters
if (dto.Properties != null)
{
command.Properties = new SchemaProperties();
SimpleMapper.Map(dto.Properties, command.Properties);
}
if (dto.Fields != null)
{
command.Fields = new List<CreateSchemaField>();
foreach (var fieldDto in dto.Fields)
{
var fieldProperties = fieldDto?.Properties.ToProperties();

7
src/Squidex/app/features/schemas/pages/messages.ts

@ -26,4 +26,11 @@ export class SchemaDeleted {
public readonly schema: SchemaDto
) {
}
}
export class SchemaCloning {
constructor(
public readonly importing: any
) {
}
}

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

@ -25,6 +25,11 @@
<a class="dropdown-item" (click)="configureScriptsDialog.show()">
Scripts
</a>
<a class="dropdown-item" (click)="cloneSchema()">
Clone
</a>
<a class="dropdown-item dropdown-item-delete"
(sqxConfirmClick)="deleteSchema()"
confirmTitle="Delete schema"

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

@ -31,6 +31,7 @@ import {
} from 'shared';
import {
SchemaCloning,
SchemaCreated,
SchemaDeleted,
SchemaUpdated
@ -249,6 +250,10 @@ export class SchemaPageComponent implements OnDestroy, OnInit {
this.resetFieldForm();
}
public cloneSchema() {
this.ctx.bus.emit(new SchemaCloning(this.schemaExport));
}
public onSchemaSaved(properties: SchemaPropertiesDto, version: Version) {
this.updateSchema(this.schema.update(properties, this.ctx.userToken, version));

13
src/Squidex/app/features/schemas/pages/schemas/schema-form.component.ts

@ -5,7 +5,7 @@
* Copyright (c) Sebastian Stehle. All rights reserved
*/
import { Component, EventEmitter, Output } from '@angular/core';
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { FormBuilder, Validators } from '@angular/forms';
import {
@ -31,13 +31,16 @@ const FALLBACK_NAME = 'my-schema';
fadeAnimation
]
})
export class SchemaFormComponent {
export class SchemaFormComponent implements OnInit {
@Output()
public created = new EventEmitter<SchemaDetailsDto>();
@Output()
public cancelled = new EventEmitter();
@Input()
public import: any;
public showImport = false;
public createFormError = '';
@ -65,6 +68,12 @@ export class SchemaFormComponent {
) {
}
public ngOnInit() {
this.createForm.controls['import'].setValue(this.import || {});
this.showImport = !!this.import;
}
public toggleImport() {
this.showImport = !this.showImport;

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

@ -14,7 +14,7 @@
<sqx-shortcut keys="ctrl+shift+g" (trigger)="addSchemaDialog.show()"></sqx-shortcut>
<sqx-shortcut keys="ctrl+shift+f" (trigger)="inputFind.focus()"></sqx-shortcut>
<button class="btn btn-success subheader-button" (click)="addSchemaDialog.show()" title="New Schema (CTRL + SHIFT + G)">
<button class="btn btn-success subheader-button" (click)="createSchema(null)" title="New Schema (CTRL + SHIFT + G)">
<i class="icon-plus"></i>
</button>
@ -58,7 +58,8 @@
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Create Schema</h4>
<h4 class="modal-title" *ngIf="import">Clone Schema</h4>
<h4 class="modal-title" *ngIf="!import">Create Schema</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close" (click)="addSchemaDialog.hide()">
<span aria-hidden="true">&times;</span>
@ -67,6 +68,7 @@
<div class="modal-body">
<sqx-schema-form
[import]="import"
(created)="onSchemaCreated($event)"
(cancelled)="addSchemaDialog.hide()">
</sqx-schema-form>

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

@ -19,6 +19,7 @@ import {
} from 'shared';
import {
SchemaCloning,
SchemaCreated,
SchemaDeleted,
SchemaUpdated
@ -38,6 +39,7 @@ import {
export class SchemasPageComponent implements OnDestroy, OnInit {
private schemaUpdatedSubscription: Subscription;
private schemaDeletedSubscription: Subscription;
private schemaCloningSubscription: Subscription;
public addSchemaDialog = new ModalView();
@ -46,6 +48,8 @@ export class SchemasPageComponent implements OnDestroy, OnInit {
public schemasFilter = new FormControl();
public schemasFiltered = ImmutableArray.empty<SchemaDto>();
public import: any;
constructor(public readonly ctx: AppContext,
private readonly schemasService: SchemasService
) {
@ -54,6 +58,7 @@ export class SchemasPageComponent implements OnDestroy, OnInit {
public ngOnDestroy() {
this.schemaUpdatedSubscription.unsubscribe();
this.schemaDeletedSubscription.unsubscribe();
this.schemaCloningSubscription.unsubscribe();
}
public ngOnInit() {
@ -71,6 +76,12 @@ export class SchemasPageComponent implements OnDestroy, OnInit {
}
});
this.schemaCloningSubscription =
this.ctx.bus.of(SchemaCloning)
.subscribe(m => {
this.createSchema(m.importing);
});
this.schemaUpdatedSubscription =
this.ctx.bus.of(SchemaUpdated)
.subscribe(m => {
@ -86,6 +97,12 @@ export class SchemasPageComponent implements OnDestroy, OnInit {
this.load();
}
public createSchema(importing: any) {
this.import = importing;
this.addSchemaDialog.show();
}
private load() {
this.schemasService.getSchemas(this.ctx.appName)
.subscribe(dtos => {

Loading…
Cancel
Save