Refactor project document

pull/625/head
Halil ibrahim Kalkan 6 years ago
parent 90f4df42fc
commit 63e6853516

@ -12,6 +12,6 @@ namespace Volo.Docs.Projects
Task<ProjectDto> GetByShortNameAsync(string shortName);
Task<List<VersionInfoDto>> GetVersionsAsync(Guid id);
Task<ListResultDto<VersionInfoDto>> GetVersionsAsync(Guid id);
}
}

@ -42,7 +42,7 @@ namespace Volo.Docs.Projects
return ObjectMapper.Map<Project, ProjectDto>(project);
}
public async Task<List<VersionInfoDto>> GetVersionsAsync(Guid id)
public async Task<ListResultDto<VersionInfoDto>> GetVersionsAsync(Guid id)
{
var project = await _projectRepository.GetAsync(id);
@ -54,8 +54,10 @@ namespace Volo.Docs.Projects
SlidingExpiration = TimeSpan.FromDays(2)
}
);
return ObjectMapper.Map<List<VersionInfo>, List<VersionInfoDto>>(versions);
return new ListResultDto<VersionInfoDto>(
ObjectMapper.Map<List<VersionInfo>, List<VersionInfoDto>>(versions)
);
}
protected virtual async Task<List<VersionInfo>> GetVersionsAsync(Project project)

@ -1,6 +1,6 @@
namespace Volo.Docs.Models
{
public class VersionInfo
public class VersionInfoViewModel
{
public string DisplayText { get; set; }
@ -8,7 +8,7 @@ namespace Volo.Docs.Models
public bool IsSelected { get; set; }
public VersionInfo(string displayText, string version, bool isSelected = false)
public VersionInfoViewModel(string displayText, string version, bool isSelected = false)
{
DisplayText = displayText;
Version = version;

@ -29,13 +29,13 @@ namespace Volo.Docs.Pages.Documents.Project
public DocumentWithDetailsDto Document { get; private set; }
public List<VersionInfo> Versions { get; private set; }
public List<VersionInfoViewModel> Versions { get; private set; }
public List<SelectListItem> VersionSelectItems { get; private set; }
public NavigationWithDetailsDto Navigation { get; private set; }
public VersionInfo LatestVersionInfo { get; private set; }
public VersionInfoViewModel LatestVersionInfo { get; private set; }
private readonly IDocumentAppService _documentAppService;
private readonly IDocumentToHtmlConverterFactory _documentToHtmlConverterFactory;
@ -73,11 +73,15 @@ namespace Volo.Docs.Pages.Documents.Project
private async Task SetVersionAsync()
{
var versionInfoDtos = await _projectAppService.GetVersionsAsync(Project.Id);
var output = await _projectAppService.GetVersionsAsync(Project.Id);
Versions = versionInfoDtos.Select(v => new VersionInfo(v.DisplayName, v.Name)).ToList();
Versions = output.Items
.Select(v => new VersionInfoViewModel(v.DisplayName, v.Name))
.ToList();
LatestVersionInfo = GetLatestVersion();
LatestVersionInfo = Versions.First();
LatestVersionInfo.DisplayText = $"{LatestVersionInfo.DisplayText} ({DocsAppConsts.Latest})";
LatestVersionInfo.Version = LatestVersionInfo.Version;
if (string.Equals(Version, DocsAppConsts.Latest, StringComparison.OrdinalIgnoreCase))
{
@ -128,10 +132,8 @@ namespace Volo.Docs.Pages.Documents.Project
Navigation.ConvertItems();
}
public string CreateLink(VersionInfo latestVersion, string version, string documentName = null)
public string CreateLink(VersionInfoViewModel latestVersion, string version, string documentName = null)
{
if (latestVersion.Version == version)
{
@ -148,16 +150,6 @@ namespace Volo.Docs.Pages.Documents.Project
return link;
}
private VersionInfo GetLatestVersion()
{
var latestVersion = Versions.First();
latestVersion.DisplayText = $"{latestVersion.DisplayText} ({DocsAppConsts.Latest})";
latestVersion.Version = latestVersion.Version;
return latestVersion;
}
public string GetSpecificVersionOrLatest()
{
if (Document?.Version == null)
@ -198,6 +190,7 @@ namespace Volo.Docs.Pages.Documents.Project
}
catch (DocumentNotFoundException)
{
//TODO: Handle it!
return;
}
@ -211,6 +204,5 @@ namespace Volo.Docs.Pages.Documents.Project
Document.Content = content;
}
}
}
Loading…
Cancel
Save