Skip to content

Commit

Permalink
manage indexes page
Browse files Browse the repository at this point in the history
  • Loading branch information
qiuhaotc committed Nov 28, 2020
1 parent 65c9d92 commit 0bdead1
Show file tree
Hide file tree
Showing 9 changed files with 227 additions and 82 deletions.
10 changes: 10 additions & 0 deletions src/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Rules in this file were initially inferred by Visual Studio IntelliCode from the C:\Users\qiuha\Documents\CodeIndex\src codebase based on best match to current usage at 2020/11/28
# You can modify the rules from these initially generated values to suit your own policies
# You can learn more about editorconfig here: https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference
[*.cs]


#Core editorconfig formatting - indentation

#use soft tabs (spaces) for indentation
indent_style = space
6 changes: 3 additions & 3 deletions src/CodeIndex.Common/CodeIndexConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace CodeIndex.Common
{
public class CodeIndexConfiguration
{
const char SplitChar = '|';
public const char SplitChar = '|';

public string LuceneIndex { get; set; } = string.Empty;
public string MonitorFolder { get; set; } = string.Empty;
Expand All @@ -23,10 +23,10 @@ public class CodeIndexConfiguration
public string[] ExcludedExtensionsArray => excludedExtensionsArray ??= GetSplitStringArray(ExcludedExtensions);
public string[] ExcludedPathsArray => excludedPathsArray ??= GetSplitStringArray(ExcludedPaths);
public string[] IncludedExtensionsArray => includedExtensionsArray ??= GetSplitStringArray(IncludedExtensions);

public int MaximumResults
{
get => maximumResults;
get => maximumResults;
set
{
value.RequireRange(nameof(maximumResults), 10000000, 100);
Expand Down
30 changes: 15 additions & 15 deletions src/CodeIndex.Common/IndexConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@

namespace CodeIndex.Common
{
public class IndexConfig
{
public Guid Pk { get; set; }
public string IndexName { get; set; }
public string MonitorFolder { get; set; }
public IEnumerable<string> IncludedExtensions { get; set; }
public IEnumerable<string> ExcludedExtensions { get; set; }
public int MaxContentHighlightLength { get; set; }
public IEnumerable<string> ExcludedPaths { get; set; }
public int SaveIntervalSeconds { get; set; }
public string OpenIDEUriFormat { get; set; }
public string MonitorFolderRealPath { get; set; }
public DateTime IndexCreatedDate { get; set; }
public DateTime IndexLastUpdatedDate { get; set; }
}
public class IndexConfig
{
public Guid Pk { get; set; }
public string IndexName { get; set; }
public string MonitorFolder { get; set; }
public IEnumerable<string> IncludedExtensions { get; set; }
public IEnumerable<string> ExcludedExtensions { get; set; }
public int MaxContentHighlightLength { get; set; }
public IEnumerable<string> ExcludedPaths { get; set; }
public int SaveIntervalSeconds { get; set; }
public string OpenIDEUriFormat { get; set; }
public string MonitorFolderRealPath { get; set; }
public DateTime IndexCreatedDate { get; set; }
public DateTime IndexLastUpdatedDate { get; set; }
}
}
14 changes: 7 additions & 7 deletions src/CodeIndex.Common/IndexStatus.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
namespace CodeIndex.Common
{
public enum IndexStatus
{
Created,
Initializing,
Monitoring,
Deleting
}
public enum IndexStatus
{
Created,
Initializing,
Monitoring,
Deleting
}
}
22 changes: 11 additions & 11 deletions src/CodeIndex.Common/IndexStatusInfo.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
namespace CodeIndex.Common
{
public class IndexStatusInfo
{
public IndexStatusInfo(IndexStatus indexStatus, IndexConfig indexConfig)
{
indexConfig.RequireNotNull(nameof(indexConfig));
IndexStatus = indexStatus;
IndexConfig = indexConfig;
}
public class IndexStatusInfo
{
public IndexStatusInfo(IndexStatus indexStatus, IndexConfig indexConfig)
{
indexConfig.RequireNotNull(nameof(indexConfig));
IndexStatus = indexStatus;
IndexConfig = indexConfig;
}

public IndexStatus IndexStatus { get; set; }
public IndexConfig IndexConfig { get; }
}
public IndexStatus IndexStatus { get; set; }
public IndexConfig IndexConfig { get; }
}
}
130 changes: 130 additions & 0 deletions src/CodeIndex.Server/Pages/IndexManagement.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,136 @@
</div>
</div>

<hr />

<h4>Stored Indexes</h4>

<div class="row">
@foreach (var indexStatus in IndexStatusInfos)
{
<div class="col-md-3 p-1">
<div class="card">
<div class="card-body">
<p>Name: @indexStatus.IndexConfig.IndexName</p>
<p>Status: @indexStatus.IndexStatus</p>
<p>Monitor Folder: @indexStatus.IndexConfig.MonitorFolder</p>
<button class="btn btn-primary btn-sm" @onclick="() => Edit(indexStatus)">Edit</button>
<button class="btn btn-danger btn-sm" @onclick="() => Delete(indexStatus)">Delete</button>
</div>
</div>
</div>
}
</div>

<hr />

<h4>
Add or Edit Index Info
<button type="button" class="btn btn-primary btn-sm" @onclick="SaveIndexInfo">Save Index Info</button>
</h4>

<div class="row">
<div class="form-group col-md-4">
<label for="IndexName">Index Name</label>
<input type="text" class="form-control" id="IndexName" autocomplete="off" @bind-value="@IndexStatusInfoForEditOrAdd.IndexConfig.IndexName">
</div>
<div class="form-group col-md-4">
<label for="MonitorFolder">Monitor Folder</label>
<input type="text" class="form-control" id="MonitorFolder" autocomplete="off" @bind-value="@IndexStatusInfoForEditOrAdd.IndexConfig.MonitorFolder">
</div>
<div class="form-group col-md-4">
<label for="MonitorFolderRealPath">Monitor Folder Real Path</label>
<input type="text" class="form-control" id="MonitorFolderRealPath" autocomplete="off" @bind-value="@IndexStatusInfoForEditOrAdd.IndexConfig.MonitorFolderRealPath">
</div>
<div class="form-group col-md-4">
<label for="OpenIDEUriFormat">Open IDE Uri Format</label>
<input type="text" class="form-control" id="OpenIDEUriFormat" autocomplete="off" @bind-value="@IndexStatusInfoForEditOrAdd.IndexConfig.OpenIDEUriFormat">
</div>
<div class="form-group col-md-4">
<label for="IncludedExtensions">Included Extensions</label>
<input type="text" class="form-control" id="IncludedExtensions" autocomplete="off" @bind-value="@IncludedExtensions">
</div>
<div class="form-group col-md-4">
<label for="ExcludedExtensions">Excluded Extensions</label>
<input type="text" class="form-control" id="ExcludedExtensions" autocomplete="off" @bind-value="@ExcludedExtensions">
</div>
<div class="form-group col-md-4">
<label for="ExcludedPaths">Excluded Paths</label>
<input type="text" class="form-control" id="ExcludedPaths" autocomplete="off" @bind-value="@ExcludedPaths">
</div>
<div class="form-group col-md-4">
<label for="MaxContentHighlightLength">Max Content Highlight Length</label>
<input type="number" class="form-control" id="MaxContentHighlightLength" autocomplete="off" @bind-value="@IndexStatusInfoForEditOrAdd.IndexConfig.MaxContentHighlightLength">
</div>
<div class="form-group col-md-4">
<label for="SaveIntervalSeconds">Save Interval Seconds</label>
<input type="number" class="form-control" id="SaveIntervalSeconds" autocomplete="off" @bind-value="@IndexStatusInfoForEditOrAdd.IndexConfig.SaveIntervalSeconds">
</div>
</div>

@code {

public List<IndexStatusInfo> IndexStatusInfos { get; set; }

public IndexStatusInfo IndexStatusInfoForEditOrAdd { get; set; } = new IndexStatusInfo(IndexStatus.Created, new IndexConfig());

public string IncludedExtensions { get; set; } = string.Empty;
public string ExcludedExtensions { get; set; } = string.Empty;
public string ExcludedPaths { get; set; } = string.Empty;

protected override void OnInitialized()
{
base.OnInitialized();

IndexStatusInfos = new List<IndexStatusInfo>{
new IndexStatusInfo(IndexStatus.Created, new IndexConfig
{
IndexName = "Dummy1",
MonitorFolder = "c:/dummy1"
}),
new IndexStatusInfo(IndexStatus.Initializing, new IndexConfig
{
IndexName = "Dummy2",
MonitorFolder = "c:/dummy2"
}),
new IndexStatusInfo(IndexStatus.Deleting, new IndexConfig
{
IndexName = "Dummy3",
MonitorFolder = "c:/dummy3"
}),
new IndexStatusInfo(IndexStatus.Monitoring, new IndexConfig
{
IndexName = "Dummy4",
MonitorFolder = "c:/dummy4"
})
};
}

void Edit(IndexStatusInfo indexStatusInfo)
{
IndexStatusInfoForEditOrAdd = indexStatusInfo;
}

void Delete(IndexStatusInfo indexStatusInfo)
{
IndexStatusInfos.Remove(indexStatusInfo);
}

void SaveIndexInfo()
{
IndexStatusInfoForEditOrAdd.IndexConfig.IncludedExtensions = IncludedExtensions.Split(CodeIndexConfiguration.SplitChar);
IndexStatusInfoForEditOrAdd.IndexConfig.ExcludedExtensions = ExcludedExtensions.Split(CodeIndexConfiguration.SplitChar);
IndexStatusInfoForEditOrAdd.IndexConfig.ExcludedPaths = ExcludedPaths.Split(CodeIndexConfiguration.SplitChar);

if (!IndexStatusInfos.Contains(IndexStatusInfoForEditOrAdd))
{
IndexStatusInfos.Add(IndexStatusInfoForEditOrAdd);
}

IndexStatusInfoForEditOrAdd = new IndexStatusInfo(IndexStatus.Created, new IndexConfig());

IncludedExtensions = string.Empty;
ExcludedExtensions = string.Empty;
ExcludedPaths = string.Empty;
}
}
70 changes: 35 additions & 35 deletions src/CodeIndex.Test/Common/IndexConfigTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,40 @@

namespace CodeIndex.Test
{
class IndexConfigTest
{
[Test]
public void TestConstructor()
{
var pk = Guid.NewGuid();
var config = new IndexConfig
{
ExcludedExtensions = new[] { "A" },
ExcludedPaths = new[] { "B" },
IncludedExtensions = new[] { "C" },
IndexCreatedDate = new DateTime(2020, 1, 1),
IndexLastUpdatedDate = new DateTime(2020, 1, 2),
IndexName = "ABC",
MaxContentHighlightLength = 100,
MonitorFolder = "BCA",
MonitorFolderRealPath = "AAA",
OpenIDEUriFormat = "BBB",
Pk = pk,
SaveIntervalSeconds = 10
};
class IndexConfigTest
{
[Test]
public void TestConstructor()
{
var pk = Guid.NewGuid();
var config = new IndexConfig
{
ExcludedExtensions = new[] { "A" },
ExcludedPaths = new[] { "B" },
IncludedExtensions = new[] { "C" },
IndexCreatedDate = new DateTime(2020, 1, 1),
IndexLastUpdatedDate = new DateTime(2020, 1, 2),
IndexName = "ABC",
MaxContentHighlightLength = 100,
MonitorFolder = "BCA",
MonitorFolderRealPath = "AAA",
OpenIDEUriFormat = "BBB",
Pk = pk,
SaveIntervalSeconds = 10
};

CollectionAssert.AreEquivalent(config.ExcludedExtensions, new[] { "A" });
CollectionAssert.AreEquivalent(config.ExcludedPaths, new[] { "B" });
CollectionAssert.AreEquivalent(config.IncludedExtensions, new[] { "C" });
Assert.AreEqual(new DateTime(2020, 1, 1), config.IndexCreatedDate);
Assert.AreEqual(new DateTime(2020, 1, 2), config.IndexLastUpdatedDate);
Assert.AreEqual("ABC", config.IndexName);
Assert.AreEqual(100, config.MaxContentHighlightLength);
Assert.AreEqual("BCA", config.MonitorFolder);
Assert.AreEqual("AAA", config.MonitorFolderRealPath);
Assert.AreEqual("BBB", config.OpenIDEUriFormat);
Assert.AreEqual(pk, config.Pk);
Assert.AreEqual(10, config.SaveIntervalSeconds);
}
}
CollectionAssert.AreEquivalent(config.ExcludedExtensions, new[] { "A" });
CollectionAssert.AreEquivalent(config.ExcludedPaths, new[] { "B" });
CollectionAssert.AreEquivalent(config.IncludedExtensions, new[] { "C" });
Assert.AreEqual(new DateTime(2020, 1, 1), config.IndexCreatedDate);
Assert.AreEqual(new DateTime(2020, 1, 2), config.IndexLastUpdatedDate);
Assert.AreEqual("ABC", config.IndexName);
Assert.AreEqual(100, config.MaxContentHighlightLength);
Assert.AreEqual("BCA", config.MonitorFolder);
Assert.AreEqual("AAA", config.MonitorFolderRealPath);
Assert.AreEqual("BBB", config.OpenIDEUriFormat);
Assert.AreEqual(pk, config.Pk);
Assert.AreEqual(10, config.SaveIntervalSeconds);
}
}
}
22 changes: 11 additions & 11 deletions src/CodeIndex.Test/Common/IndexStatusInfoTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

namespace CodeIndex.Test
{
class IndexStatusInfoTest
{
[Test]
public void TestConstructor()
{
var statusInfo = new IndexStatusInfo(IndexStatus.Initializing, new IndexConfig());
Assert.IsNotNull(statusInfo.IndexConfig);
Assert.AreEqual(IndexStatus.Initializing, statusInfo.IndexStatus);
Assert.Throws<ArgumentException>(() => _ = new IndexStatusInfo(default, null));
}
}
class IndexStatusInfoTest
{
[Test]
public void TestConstructor()
{
var statusInfo = new IndexStatusInfo(IndexStatus.Initializing, new IndexConfig());
Assert.IsNotNull(statusInfo.IndexConfig);
Assert.AreEqual(IndexStatus.Initializing, statusInfo.IndexStatus);
Assert.Throws<ArgumentException>(() => _ = new IndexStatusInfo(default, null));
}
}
}
5 changes: 5 additions & 0 deletions src/CodeIndex.sln
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "doc", "doc", "{B0519424-9D6
..\doc\UseExtension.gif = ..\doc\UseExtension.gif
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{D0B5A7C3-31A4-463A-B27E-2D246D5BF8DD}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down

0 comments on commit 0bdead1

Please sign in to comment.