Browse Source

Asset dialog finalized.

pull/352/head
Sebastian Stehle 7 years ago
parent
commit
d5ddc8ae64
  1. 2
      src/Squidex.Domain.Apps.Entities/Contents/Text/IndexState.cs
  2. 13
      src/Squidex.Domain.Apps.Entities/Contents/Text/TextIndexContent.cs
  3. 3
      src/Squidex/Config/Domain/StoreServices.cs
  4. 2
      src/Squidex/app/framework/angular/modals/modal-dialog.component.html
  5. 6
      src/Squidex/app/shared/components/asset-dialog.component.html
  6. 20
      src/Squidex/app/shared/components/asset-dialog.component.scss
  7. 4
      src/Squidex/app/shared/components/asset-dialog.component.ts
  8. 2
      src/Squidex/app/shared/components/asset.component.html
  9. 18
      src/Squidex/app/shared/state/assets.forms.ts
  10. 12
      tools/Migrate_01/MigrationPath.cs
  11. 43
      tools/Migrate_01/Migrations/MongoDb/RenameSlugField.cs

2
src/Squidex.Domain.Apps.Entities/Contents/Text/IndexState.cs

@ -34,7 +34,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Text
document.AddBinaryDocValuesField(MetaFor, GetValue(forDraft, forPublished));
}
public void Index(Term term, Guid id, byte draft, byte forDraft, byte forPublished)
public void Index(Term term, byte forDraft, byte forPublished)
{
indexWriter.UpdateBinaryDocValue(term, MetaFor, GetValue(forDraft, forPublished));
}

13
src/Squidex.Domain.Apps.Entities/Contents/Text/TextIndexContent.cs

@ -139,16 +139,11 @@ namespace Squidex.Domain.Apps.Entities.Contents.Text
}
}
Document document = null;
var document = new Document();
if (languages.Count > 0)
foreach (var field in languages)
{
document = new Document();
foreach (var field in languages)
{
document.AddTextField(field.Key, field.Value.ToString(), Field.Store.NO);
}
document.AddTextField(field.Key, field.Value.ToString(), Field.Store.NO);
}
return document;
@ -158,7 +153,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Text
{
var term = new Term(MetaKey, BuildKey(draft));
indexState.Index(term, id, draft, forDraft, forPublished);
indexState.Index(term, forDraft, forPublished);
}
private int GetPublishedDocument()

3
src/Squidex/Config/Domain/StoreServices.cs

@ -76,6 +76,9 @@ namespace Squidex.Config.Domain
services.AddTransientAs<ConvertRuleEventsJson>()
.As<IMigration>();
services.AddTransientAs<RenameSlugField>()
.As<IMigration>();
services.AddHealthChecks()
.AddCheck<MongoDBHealthCheck>("MongoDB", tags: new[] { "node" });

2
src/Squidex/app/framework/angular/modals/modal-dialog.component.html

@ -8,7 +8,7 @@
<ng-content select="[title]"></ng-content>
</h4>
<button type="button" class="close" (click)="close()">
<button type="button" class="close" (click)="emitClose()">
<span aria-hidden="true">&times;</span>
</button>
</div>

6
src/Squidex/app/shared/components/asset-dialog.component.html

@ -20,7 +20,11 @@
<sqx-control-errors for="slug" [submitted]="annotateForm.submitted | async"></sqx-control-errors>
<input type="text" class="form-control" id="slug" formControlName="slug" sqxTransformInput="Slugify" />
<input type="text" class="form-control slug" id="slug" formControlName="slug" sqxTransformInput="Slugify" />
<button type="button" class="btn btn-text-secondary btn-sm btn-generate" (click)="generateSlug()">
Generate
</button>
</div>
<div class="form-group">

20
src/Squidex/app/shared/components/asset-dialog.component.scss

@ -1,2 +1,20 @@
@import '_vars';
@import '_mixins';
@import '_mixins';
.form-group {
position: relative;
}
.slug {
padding-right: 6rem;
}
.btn-generate {
& {
@include absolute(auto, 10px, 3px, auto);
}
&:focus {
@include box-shadow-none;
}
}

4
src/Squidex/app/shared/components/asset-dialog.component.ts

@ -55,6 +55,10 @@ export class AssetDialogComponent extends StatefulComponent implements OnInit {
this.annotateForm.load(this.asset);
}
public generateSlug() {
this.annotateForm.generateSlug(this.asset);
}
public emitCancel() {
this.cancel.emit();
}

2
src/Squidex/app/shared/components/asset.component.html

@ -63,7 +63,7 @@
</div>
</div>
<div class="file-tags tags">
<sqx-tag-editor [disabled]="true" [ngModel]="asset.tags" class="blank"></sqx-tag-editor>
<sqx-tag-editor [disabled]="true" [ngModel]="asset.tags" class="blank" placeholder="+Tag"></sqx-tag-editor>
</div>
<div class="file-info">
<ng-container *ngIf="asset.pixelWidth">{{asset.pixelWidth}}x{{asset.pixelHeight}}px, </ng-container> {{asset.fileSize | sqxFileSize}}

18
src/Squidex/app/shared/state/assets.forms.ts

@ -7,6 +7,8 @@
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import slugify from 'slugify';
import { Form, Types } from '@app/framework';
import { AssetDto } from './../services/assets.service';
@ -62,6 +64,22 @@ export class AnnotateAssetForm extends Form<FormGroup> {
return result;
}
public generateSlug(asset: AssetDto) {
const fileName = this.form.get('fileName')!.value;
if (fileName) {
let slug = slugify(fileName, { lower: true });
let index = asset.fileName.lastIndexOf('.');
if (index > 0) {
slug += asset.fileName.substr(index);
}
this.form.get('slug')!.setValue(slug);
}
}
public load(asset: AssetDto) {
let fileName = asset.fileName;

12
tools/Migrate_01/MigrationPath.cs

@ -17,7 +17,7 @@ namespace Migrate_01
{
public sealed class MigrationPath : IMigrationPath
{
private const int CurrentVersion = 16;
private const int CurrentVersion = 17;
private readonly IServiceProvider serviceProvider;
public MigrationPath(IServiceProvider serviceProvider)
@ -100,13 +100,19 @@ namespace Migrate_01
// Version 15: Introduce custom full text search actors.
if (version < 15)
{
yield return serviceProvider.GetService<RestructureContentCollection>();
yield return serviceProvider.GetRequiredService<RestructureContentCollection>();
}
// Version 16: Introduce file name slugs for assets.
if (version < 16)
{
yield return serviceProvider.GetService<CreateAssetSlugs>();
yield return serviceProvider.GetRequiredService<CreateAssetSlugs>();
}
// Version 17: Rename slug field.
if (version < 17)
{
yield return serviceProvider.GetService<RenameSlugField>();
}
yield return serviceProvider.GetRequiredService<StartEventConsumers>();

43
tools/Migrate_01/Migrations/MongoDb/RenameSlugField.cs

@ -0,0 +1,43 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using MongoDB.Bson;
using MongoDB.Driver;
using Squidex.Infrastructure.Migrations;
using Squidex.Infrastructure.MongoDb;
using Squidex.Infrastructure.Tasks;
namespace Migrate_01.Migrations.MongoDb
{
public sealed class RenameSlugField : IMigration
{
private readonly IMongoDatabase database;
private readonly MongoDbOptions options;
public RenameSlugField(IMongoDatabase database, IOptions<MongoDbOptions> options)
{
this.database = database;
this.options = options.Value;
}
public Task UpdateAsync()
{
if (options.IsCosmosDb)
{
return TaskHelper.Done;
}
var collection = database.GetCollection<BsonDocument>("States_Assets");
var update = Builders<BsonDocument>.Update.Rename("FileNameSlug", "Slug");
return collection.UpdateManyAsync(new BsonDocument(), update);
}
}
}
Loading…
Cancel
Save