Skip to content

Commit

Permalink
Merge pull request #73 from ellinge/issue/55
Browse files Browse the repository at this point in the history
Fix selection of Siteurl on edit
  • Loading branch information
marisks authored Jan 27, 2023
2 parents c3a8b9e + 8cdb276 commit 59625a6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
{
<tr>
<td>
@sitemapViewModel.SiteUrl
@sitemapViewModel.SitemapUrl
</td>
<td>
@sitemapViewModel.PathsToInclude
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using EPiServer.Data;
using EPiServer.DataAbstraction;
using EPiServer.Web;
Expand All @@ -6,12 +8,10 @@
using Geta.Optimizely.Sitemaps.Models;
using Geta.Optimizely.Sitemaps.Repositories;
using Geta.Optimizely.Sitemaps.Utils;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.Rendering;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Authorization;

namespace Geta.Optimizely.Sitemaps.Pages.Geta.Optimizely.Sitemaps;

Expand Down Expand Up @@ -98,12 +98,12 @@ public IActionResult OnPostCancelCreate()
public IActionResult OnPostEdit(string id)
{
LoadSiteHosts();
EditItemId = id;
var sitemapData = _sitemapRepository.GetSitemapData(Identity.Parse(id));
SitemapViewModel = _entityToModelCreator.Create(sitemapData);
EditItemId = id;
LoadLanguageBranches();
BindSitemapDataList();
PopulateHostListControl();
PopulateHostListControl(sitemapData.SiteUrl);
return Page();
}

Expand Down Expand Up @@ -167,10 +167,11 @@ private void LoadSiteHosts()

foreach (var siteInformation in hosts)
{
var siteUrl = siteInformation.SiteUrl.ToString();
siteUrls.Add(new()
{
Text = siteInformation.SiteUrl.ToString(),
Value = siteInformation.SiteUrl.ToString()
Text = siteUrl,
Value = siteUrl
});

var hostUrls = siteInformation.Hosts
Expand All @@ -189,15 +190,15 @@ private static bool ShouldAddToSiteHosts(HostDefinition host, SiteDefinition sit
return !UriComparer.SchemeAndServerEquals(host.GetUri(), siteInformation.SiteUrl);
}

private void PopulateHostListControl()
private void PopulateHostListControl(string selected = null)
{
if (SiteHosts.Count > 1)
{
ShowHostsDropDown = true;
}
else
{
HostLabel = SiteHosts.ElementAt(0).Value;
HostLabel = selected ?? SiteHosts.FirstOrDefault()?.Value;
}
}

Expand Down
14 changes: 8 additions & 6 deletions src/Geta.Optimizely.Sitemaps/Models/SitemapViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Castle.Core.Internal;
using EPiServer.Web;
using Geta.Mapping;
using Geta.Optimizely.Sitemaps.Entities;
using System;
using System.Collections.Generic;
using Castle.Core.Internal;
using EPiServer.DataAbstraction;
using EPiServer.Web;
using Geta.Mapping;
using Geta.Optimizely.Sitemaps.Entities;

namespace Geta.Optimizely.Sitemaps.Models
{
Expand All @@ -14,6 +14,7 @@ public class SitemapViewModel

public string Id { get; set; }
public string SiteUrl { get; set; }
public string SitemapUrl { get; set; }
public string LanguageBranch { get; set; }
public string RelativePath { get; set; }
public string RelativePathEditPart { get; set; }
Expand All @@ -39,7 +40,8 @@ public MapperFromEntity(ILanguageBranchRepository languageBranchRepository)
public override void Map(SitemapData @from, SitemapViewModel to)
{
to.Id = from.Id.ToString();
to.SiteUrl = GetSiteUrl(from);
to.SiteUrl = from.SiteUrl;
to.SitemapUrl = GetSitemapUrl(from);
to.RelativePath = from.Host;
to.RelativePathEditPart = GetRelativePathEditPart(from.Host);
to.EnableLanguageFallback = from.EnableLanguageFallback;
Expand All @@ -65,7 +67,7 @@ private string GetLanguage(string language)
return $"{languageBranch.URLSegment}/";
}

private string GetSiteUrl(SitemapData sitemapData)
private string GetSitemapUrl(SitemapData sitemapData)
{
var language = GetLanguage(sitemapData.Language);

Expand Down

0 comments on commit 59625a6

Please sign in to comment.