Browse Source

Refactored docs

pull/570/head
Halil ibrahim Kalkan 8 years ago
parent
commit
4b447e0e16
  1. 75
      modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/ContentWithDetailsDto.cs
  2. 21
      modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/IDocumentAppService.cs
  3. 53
      modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/NavigationNode.cs
  4. 30
      modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/NavigationWithDetailsDto.cs
  5. 2
      modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Projects/IProjectAppService.cs
  6. 5
      modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Projects/ProjectDto.cs
  7. 6
      modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs
  8. 8
      modules/docs/src/Volo.Docs.Application/Volo/Docs/Projects/ProjectAppService.cs
  9. 2
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/Projects/IProjectRepository.cs
  10. 12
      modules/docs/src/Volo.Docs.EntityFrameworkCore/Volo/Docs/Projects/EfCoreProjectRepository.cs
  11. 2
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs

75
modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/ContentWithDetailsDto.cs

@ -1,7 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Volo.Docs.Projects;
namespace Volo.Docs.Documents
@ -30,75 +26,4 @@ namespace Volo.Docs.Documents
public bool SuccessfullyRetrieved { get; set; }
}
public class NavigationNode
{
[JsonProperty("text")]
public string Text { get; set; }
[JsonProperty("path")]
public string Path { get; set; }
[JsonProperty("items")]
public List<NavigationNode> Items { get; set; }
public bool IsLeaf => !HasChildItems;
public bool HasChildItems => Items != null && Items.Any();
public bool IsEmpty => Text == null && Path == null;
public bool IsSelected(string documentName)
{
if (documentName == null)
{
return false;
}
if (string.Equals(documentName, Path, StringComparison.OrdinalIgnoreCase))
{
return true;
}
if (Items == null)
{
return false;
}
foreach (var childItem in Items)
{
if (childItem.IsSelected(documentName))
{
return true;
}
}
return false;
}
}
public class NavigationWithDetailsDto : DocumentWithDetailsDto
{
[JsonProperty("items")]
public NavigationNode RootNode { get; set; }
public void ConvertItems()
{
if (!SuccessfullyRetrieved || Content.IsNullOrEmpty())
{
RootNode = new NavigationNode();
return;
}
try
{
RootNode = JsonConvert.DeserializeObject<NavigationNode>(Content);
}
catch (JsonException ex)
{
//todo: should log the exception?
RootNode = new NavigationNode();
}
}
}
}

21
modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/IDocumentAppService.cs

@ -7,14 +7,27 @@ namespace Volo.Docs.Documents
{
public interface IDocumentAppService : IApplicationService
{
Task<DocumentWithDetailsDto> GetByNameAsync(string projectShortName, string documentName, string version,
Task<DocumentWithDetailsDto> GetByNameAsync(
string projectShortName,
string documentName,
string version,
bool normalize);
Task<NavigationWithDetailsDto> GetNavigationDocumentAsync(string projectShortName, string version,
Task<NavigationWithDetailsDto> GetNavigationDocumentAsync(
string projectShortName,
string version,
bool normalize);
Task<List<VersionInfoDto>> GetVersions(string projectShortName, string defaultDocumentName, string documentStoreType, string documentName);
Task<List<VersionInfoDto>> GetVersions(
string projectShortName,
string defaultDocumentName,
string documentStoreType,
string documentName);
Task<DocumentWithDetailsDto> GetDocument(ProjectDto projectDto, string documentName, string version, bool normalize);
Task<DocumentWithDetailsDto> GetDocument(
ProjectDto projectDto,
string documentName,
string version,
bool normalize);
}
}

53
modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/NavigationNode.cs

@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
namespace Volo.Docs.Documents
{
public class NavigationNode
{
[JsonProperty("text")]
public string Text { get; set; }
[JsonProperty("path")]
public string Path { get; set; }
[JsonProperty("items")]
public List<NavigationNode> Items { get; set; }
public bool IsLeaf => !HasChildItems;
public bool HasChildItems => Items != null && Items.Any();
public bool IsEmpty => Text == null && Path == null;
public bool IsSelected(string documentName)
{
if (documentName == null)
{
return false;
}
if (string.Equals(documentName, Path, StringComparison.OrdinalIgnoreCase))
{
return true;
}
if (Items == null)
{
return false;
}
foreach (var childItem in Items)
{
if (childItem.IsSelected(documentName))
{
return true;
}
}
return false;
}
}
}

30
modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/NavigationWithDetailsDto.cs

@ -0,0 +1,30 @@
using System;
using Newtonsoft.Json;
namespace Volo.Docs.Documents
{
public class NavigationWithDetailsDto : DocumentWithDetailsDto
{
[JsonProperty("items")]
public NavigationNode RootNode { get; set; }
public void ConvertItems()
{
if (!SuccessfullyRetrieved || Content.IsNullOrEmpty())
{
RootNode = new NavigationNode();
return;
}
try
{
RootNode = JsonConvert.DeserializeObject<NavigationNode>(Content);
}
catch (JsonException ex)
{
//todo: should log the exception?
RootNode = new NavigationNode();
}
}
}
}

2
modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Projects/IProjectAppService.cs

@ -8,6 +8,6 @@ namespace Volo.Docs.Projects
{
Task<ListResultDto<ProjectDto>> GetListAsync();
Task<ProjectDto> FindByShortNameAsync(string shortName);
Task<ProjectDto> GetByShortNameAsync(string shortName);
}
}

5
modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Projects/ProjectDto.cs

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using Volo.Abp.Application.Dtos;
namespace Volo.Docs.Projects
@ -12,10 +11,6 @@ namespace Volo.Docs.Projects
public string DefaultDocumentName { get; set; }
public string NavigationDocumentName { get; set; }
public string GoogleCustomSearchId { get; set; }
public string MainWebsiteUrl { get; set; }
public virtual string DocumentStoreType { get; protected set; }

6
modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs

@ -27,14 +27,14 @@ namespace Volo.Docs.Documents
public async Task<DocumentWithDetailsDto> GetByNameAsync(string projectShortName, string documentName, string version, bool normalize)
{
var project = await _projectRepository.FindByShortNameAsync(projectShortName);
var project = await _projectRepository.GetByShortNameAsync(projectShortName);
return await GetDocument(ObjectMapper.Map<Project, ProjectDto>(project), documentName, version, normalize);
}
public async Task<NavigationWithDetailsDto> GetNavigationDocumentAsync(string projectShortName, string version, bool normalize)
{
var project = await _projectRepository.FindByShortNameAsync(projectShortName);
var project = await _projectRepository.GetByShortNameAsync(projectShortName);
return ObjectMapper.Map<DocumentWithDetailsDto, NavigationWithDetailsDto>(
await GetDocument(ObjectMapper.Map<Project, ProjectDto>(project), project.NavigationDocumentName,
@ -69,7 +69,7 @@ namespace Volo.Docs.Documents
public async Task<List<VersionInfoDto>> GetVersions(string projectShortName, string defaultDocumentName,
string documentStoreType, string documentName)
{
var project = await _projectRepository.FindByShortNameAsync(projectShortName);
var project = await _projectRepository.GetByShortNameAsync(projectShortName);
if (string.IsNullOrWhiteSpace(documentName))
{

8
modules/docs/src/Volo.Docs.Application/Volo/Docs/Projects/ProjectAppService.cs

@ -24,13 +24,9 @@ namespace Volo.Docs.Projects
);
}
public async Task<ProjectDto> FindByShortNameAsync(string shortName)
public async Task<ProjectDto> GetByShortNameAsync(string shortName)
{
var project = await _projectRepository.FindByShortNameAsync(shortName);
if (project == null)
{
throw new EntityNotFoundException($"Project with the name {shortName} not found!");
}
var project = await _projectRepository.GetByShortNameAsync(shortName);
return ObjectMapper.Map<Project, ProjectDto>(project);
}

2
modules/docs/src/Volo.Docs.Domain/Volo/Docs/Projects/IProjectRepository.cs

@ -6,6 +6,6 @@ namespace Volo.Docs.Projects
{
public interface IProjectRepository : IBasicRepository<Project, Guid>
{
Task<Project> FindByShortNameAsync(string shortName);
Task<Project> GetByShortNameAsync(string shortName);
}
}

12
modules/docs/src/Volo.Docs.EntityFrameworkCore/Volo/Docs/Projects/EfCoreProjectRepository.cs

@ -1,6 +1,7 @@
using System;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
using Volo.Docs.EntityFrameworkCore;
@ -15,9 +16,16 @@ namespace Volo.Docs.Projects
}
public async Task<Project> FindByShortNameAsync(string shortName)
public async Task<Project> GetByShortNameAsync(string shortName)
{
return await DbSet.FirstOrDefaultAsync(p => p.ShortName == shortName);
var project = await DbSet.FirstOrDefaultAsync(p => p.ShortName == shortName);
if (project == null)
{
throw new EntityNotFoundException($"Project with the name {shortName} not found!");
}
return project;
}
}
}

2
modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs

@ -55,7 +55,7 @@ namespace Volo.Docs.Pages.Documents.Project
public async Task OnGet()
{
var project = await _projectAppService.FindByShortNameAsync(ProjectName);
var project = await _projectAppService.GetByShortNameAsync(ProjectName);
SetPageParams(project);

Loading…
Cancel
Save