Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/issue 68 non channel web pages after publish #70

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/xperience-administration-search-index-edit-form.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
136 changes: 68 additions & 68 deletions src/Kentico.Xperience.Lucene.Admin/LuceneConfigurationModel.cs
Original file line number Diff line number Diff line change
@@ -1,68 +1,68 @@
using System.ComponentModel.DataAnnotations;
using Kentico.Xperience.Admin.Base.FormAnnotations;
using Kentico.Xperience.Admin.Base.Forms;
using Kentico.Xperience.Lucene.Admin.Providers;
using Kentico.Xperience.Lucene.Core.Indexing;
namespace Kentico.Xperience.Lucene.Admin;
public class LuceneConfigurationModel
{
public int Id { get; set; }
[TextInputComponent(
Label = "Index Name",
ExplanationText = "Changing this value on an existing index without changing application code will cause the search experience to stop working.",
Order = 1)]
[Required]
[MinLength(1)]
public string IndexName { get; set; } = "";
[GeneralSelectorComponent(dataProviderType: typeof(LanguageOptionsProvider), Label = "Indexed Languages", Order = 2)]
public IEnumerable<string> LanguageNames { get; set; } = Enumerable.Empty<string>();
[DropDownComponent(Label = "Channel Name", DataProviderType = typeof(ChannelOptionsProvider), Order = 3)]
public string ChannelName { get; set; } = "";
[DropDownComponent(Label = "Indexing Strategy", DataProviderType = typeof(IndexingStrategyOptionsProvider), Order = 4)]
public string StrategyName { get; set; } = "";
[DropDownComponent(Label = "Lucene Analyzer", DataProviderType = typeof(AnalyzerOptionsProvider), Order = 5)]
public string AnalyzerName { get; set; } = "";
[TextInputComponent(Label = "Rebuild Hook")]
public string RebuildHook { get; set; } = "";
[LuceneIndexConfigurationComponent(Label = "Included Paths")]
public IEnumerable<LuceneIndexIncludedPath> Paths { get; set; } = Enumerable.Empty<LuceneIndexIncludedPath>();
public LuceneConfigurationModel() { }
public LuceneConfigurationModel(
LuceneIndexModel luceneModel
)
{
Id = luceneModel.Id;
IndexName = luceneModel.IndexName;
LanguageNames = luceneModel.LanguageNames;
ChannelName = luceneModel.ChannelName;
StrategyName = luceneModel.StrategyName;
AnalyzerName = luceneModel.AnalyzerName;
RebuildHook = luceneModel.RebuildHook;
Paths = luceneModel.Paths;
}
public LuceneIndexModel ToLuceneModel() =>
new()
{
Id = Id,
IndexName = IndexName,
LanguageNames = LanguageNames,
ChannelName = ChannelName,
AnalyzerName = AnalyzerName,
StrategyName = StrategyName,
RebuildHook = RebuildHook,
Paths = Paths
};
}
using System.ComponentModel.DataAnnotations;

using Kentico.Xperience.Admin.Base.FormAnnotations;
using Kentico.Xperience.Admin.Base.Forms;
using Kentico.Xperience.Lucene.Admin.Providers;
using Kentico.Xperience.Lucene.Core.Indexing;

namespace Kentico.Xperience.Lucene.Admin;

public class LuceneConfigurationModel
{
public int Id { get; set; }

[TextInputComponent(
Label = "Index Name",
ExplanationText = "Changing this value on an existing index without changing application code will cause the search experience to stop working.",
Order = 1)]
[Required]
[MinLength(1)]
public string IndexName { get; set; } = "";

[GeneralSelectorComponent(dataProviderType: typeof(LanguageOptionsProvider), Label = "Indexed Languages", Order = 2)]
public IEnumerable<string> LanguageNames { get; set; } = Enumerable.Empty<string>();

[DropDownComponent(Label = "Channel Name", DataProviderType = typeof(ChannelOptionsProvider), Order = 3)]
public string ChannelName { get; set; } = "";

[DropDownComponent(Label = "Indexing Strategy", DataProviderType = typeof(IndexingStrategyOptionsProvider), Order = 4)]
public string StrategyName { get; set; } = "";

[DropDownComponent(Label = "Lucene Analyzer", DataProviderType = typeof(AnalyzerOptionsProvider), Order = 5)]
public string AnalyzerName { get; set; } = "";

[TextInputComponent(Label = "Rebuild Hook")]
public string RebuildHook { get; set; } = "";

[LuceneIndexConfigurationComponent(Label = "Included Paths")]
public IEnumerable<LuceneIndexIncludedPath> Paths { get; set; } = Enumerable.Empty<LuceneIndexIncludedPath>();

public LuceneConfigurationModel() { }

public LuceneConfigurationModel(
LuceneIndexModel luceneModel
)
{
Id = luceneModel.Id;
IndexName = luceneModel.IndexName;
LanguageNames = luceneModel.LanguageNames;
ChannelName = luceneModel.ChannelName;
StrategyName = luceneModel.StrategyName;
AnalyzerName = luceneModel.AnalyzerName;
RebuildHook = luceneModel.RebuildHook;
Paths = luceneModel.Paths;
}

public LuceneIndexModel ToLuceneModel() =>
new()
{
Id = Id,
IndexName = IndexName,
LanguageNames = LanguageNames,
ChannelName = ChannelName,
AnalyzerName = AnalyzerName,
StrategyName = StrategyName,
RebuildHook = RebuildHook,
Paths = Paths
};
}
150 changes: 75 additions & 75 deletions src/Kentico.Xperience.Lucene.Admin/UIPages/BaseIndexEditPage.cs
Original file line number Diff line number Diff line change
@@ -1,75 +1,75 @@
using System.Text;
using Kentico.Xperience.Admin.Base;
using Kentico.Xperience.Admin.Base.Forms;
using Kentico.Xperience.Lucene.Core.Indexing;
using IFormItemCollectionProvider = Kentico.Xperience.Admin.Base.Forms.Internal.IFormItemCollectionProvider;
namespace Kentico.Xperience.Lucene.Admin;
internal abstract class BaseIndexEditPage : ModelEditPage<LuceneConfigurationModel>
{
protected readonly ILuceneConfigurationStorageService StorageService;
private readonly ILuceneIndexManager indexManager;
protected BaseIndexEditPage(
IFormItemCollectionProvider formItemCollectionProvider,
IFormDataBinder formDataBinder,
ILuceneConfigurationStorageService storageService,
ILuceneIndexManager indexManager)
: base(formItemCollectionProvider, formDataBinder)
{
this.indexManager = indexManager;
StorageService = storageService;
}
protected async Task<IndexModificationResult> ValidateAndProcess(LuceneConfigurationModel configuration)
{
configuration.IndexName = RemoveWhitespacesUsingStringBuilder(configuration.IndexName ?? "");
if (StorageService.GetIndexIds().Exists(x => x == configuration.Id))
{
bool edited = await StorageService.TryEditIndexAsync(configuration.ToLuceneModel());
if (edited)
{
return IndexModificationResult.Success;
}
return IndexModificationResult.Failure;
}
else
{
if (!string.IsNullOrWhiteSpace(configuration.IndexName))
{
indexManager.AddIndex(configuration.ToLuceneModel());
return IndexModificationResult.Success;
}
return IndexModificationResult.Failure;
}
}
protected static string RemoveWhitespacesUsingStringBuilder(string source)
{
var builder = new StringBuilder(source.Length);
for (int i = 0; i < source.Length; i++)
{
char c = source[i];
if (!char.IsWhiteSpace(c))
{
builder.Append(c);
}
}
return source.Length == builder.Length ? source : builder.ToString();
}
}
internal enum IndexModificationResult
{
Success,
Failure
}
using System.Text;

using Kentico.Xperience.Admin.Base;
using Kentico.Xperience.Admin.Base.Forms;
using Kentico.Xperience.Lucene.Core.Indexing;

using IFormItemCollectionProvider = Kentico.Xperience.Admin.Base.Forms.Internal.IFormItemCollectionProvider;

namespace Kentico.Xperience.Lucene.Admin;

internal abstract class BaseIndexEditPage : ModelEditPage<LuceneConfigurationModel>
{
protected readonly ILuceneConfigurationStorageService StorageService;

private readonly ILuceneIndexManager indexManager;

protected BaseIndexEditPage(
IFormItemCollectionProvider formItemCollectionProvider,
IFormDataBinder formDataBinder,
ILuceneConfigurationStorageService storageService,
ILuceneIndexManager indexManager)
: base(formItemCollectionProvider, formDataBinder)
{
this.indexManager = indexManager;
StorageService = storageService;
}

protected async Task<IndexModificationResult> ValidateAndProcess(LuceneConfigurationModel configuration)
{
configuration.IndexName = RemoveWhitespacesUsingStringBuilder(configuration.IndexName ?? "");

if (StorageService.GetIndexIds().Exists(x => x == configuration.Id))
{
bool edited = await StorageService.TryEditIndexAsync(configuration.ToLuceneModel());

if (edited)
{
return IndexModificationResult.Success;
}

return IndexModificationResult.Failure;
}
else
{
if (!string.IsNullOrWhiteSpace(configuration.IndexName))
{
indexManager.AddIndex(configuration.ToLuceneModel());

return IndexModificationResult.Success;
}

return IndexModificationResult.Failure;
}
}

protected static string RemoveWhitespacesUsingStringBuilder(string source)
{
var builder = new StringBuilder(source.Length);
for (int i = 0; i < source.Length; i++)
{
char c = source[i];
if (!char.IsWhiteSpace(c))
{
builder.Append(c);
}
}
return source.Length == builder.Length ? source : builder.ToString();
}
}

internal enum IndexModificationResult
{
Success,
Failure
}
Loading
Loading