Skip to content

Commit

Permalink
Merge pull request #290 from Sitecore/feature/180-contribution-edit
Browse files Browse the repository at this point in the history
Fix #180
  • Loading branch information
robearlam authored Nov 13, 2023
2 parents b0539fc + b4aae38 commit 2fe91d0
Show file tree
Hide file tree
Showing 10 changed files with 177 additions and 9 deletions.
1 change: 1 addition & 0 deletions Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@
<PackageReference Update="Mvp.Selections.Client" Version="4.4.0" />
<PackageReference Update="StyleCop.Analyzers" Version="1.1.118" />
<PackageReference Update="Microsoft.ApplicationInsights.AspNetCore" Version="2.21.0" />
<PackageReference Update="Markdig" Version="0.33.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
ID: "c8c9c14b-396d-4070-ad58-5299e283e68b"
Parent: "69554c9a-4da4-419f-a199-d036f3fa042b"
Template: "455a3e98-a627-4b40-8035-e683a0331ac7"
Path: /sitecore/templates/Feature/Selections/Apply/ApplicationForm/Contributions Step/ContributionConfirmDeleteLabel
SharedFields:
- ID: "ab162cc0-dc80-4abf-8871-998ee5d7ba32"
Hint: Type
Value: "Single-Line Text"
- ID: "ba3f86a2-4a1c-4d78-b63d-91c2779c1b5e"
Hint: __Sortorder
Value: 1000
Languages:
- Language: en
Fields:
- ID: "19a69332-a23e-4e70-8d16-b2640cb24cc8"
Hint: Title
Value: Confirm Delete
Versions:
- Version: 1
Fields:
- ID: "25bed78c-4957-4165-998a-ca1b52f67497"
Hint: __Created
Value: 20231110T115256Z
- ID: "52807595-0f8f-4b20-8d2a-cb71d28c6103"
Hint: __Owner
Value: |
sitecore\ed7gR4aY22
- ID: "5dd74568-4d4b-44c1-b513-0af5f4cda34f"
Hint: __Created by
Value: |
sitecore\ed7gR4aY22
- ID: "8cdc337e-a112-42fb-bbb4-4143751e123f"
Hint: __Revision
Value: "a9157a77-4777-4add-bfba-330169411fd5"
- ID: "badd9cf9-53e0-4d0c-bcc0-2d784c282f6a"
Hint: __Updated by
Value: |
sitecore\ed7gR4aY22
- ID: "d9cf14b1-fa16-4ba6-9288-e8a174d4d522"
Hint: __Updated
Value: 20231110T115308Z
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
ID: "0a7f8beb-4172-4149-8e75-6402ca9666a6"
Parent: "69554c9a-4da4-419f-a199-d036f3fa042b"
Template: "455a3e98-a627-4b40-8035-e683a0331ac7"
Path: /sitecore/templates/Feature/Selections/Apply/ApplicationForm/Contributions Step/UpdateLabel
SharedFields:
- ID: "ab162cc0-dc80-4abf-8871-998ee5d7ba32"
Hint: Type
Value: "Single-Line Text"
- ID: "ba3f86a2-4a1c-4d78-b63d-91c2779c1b5e"
Hint: __Sortorder
Value: 900
Languages:
- Language: en
Fields:
- ID: "19a69332-a23e-4e70-8d16-b2640cb24cc8"
Hint: Title
Value: Update
Versions:
- Version: 1
Fields:
- ID: "25bed78c-4957-4165-998a-ca1b52f67497"
Hint: __Created
Value: 20231109T215046Z
- ID: "52807595-0f8f-4b20-8d2a-cb71d28c6103"
Hint: __Owner
Value: |
sitecore\ed7gR4aY22
- ID: "5dd74568-4d4b-44c1-b513-0af5f4cda34f"
Hint: __Created by
Value: |
sitecore\ed7gR4aY22
- ID: "8cdc337e-a112-42fb-bbb4-4143751e123f"
Hint: __Revision
Value: "44321f5a-5c92-4095-b4ef-42f707ac98b2"
- ID: "badd9cf9-53e0-4d0c-bcc0-2d784c282f6a"
Hint: __Updated by
Value: |
sitecore\ed7gR4aY22
- ID: "d9cf14b1-fa16-4ba6-9288-e8a174d4d522"
Hint: __Updated
Value: 20231110T115256Z
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Languages:
- ID: "095894c5-c355-40f8-b47e-045c65af22f2"
Hint: ContributionsHelpText
Value: <p>Please submit contributions according to good judgement. If you have multiple links related to a single contribution submit them with logical type, name and description on the same date.</p>
- ID: "0a7f8beb-4172-4149-8e75-6402ca9666a6"
Hint: UpdateLabel
Value: Update
- ID: "16fd47dc-1e00-4631-a016-2d948cd684c8"
Hint: ObjectivesTitleLabel
Value: Objectives
Expand Down Expand Up @@ -91,14 +94,14 @@ Languages:
Value: "What are your objectives for the next year?"
- ID: "8cdc337e-a112-42fb-bbb4-4143751e123f"
Hint: __Revision
Value: "fcee729a-0dc1-471d-99ad-7139a08965a4"
Value: "17b2ec1f-950c-456b-8bdd-ec87bf9c4ff7"
- ID: "9c31ec21-8cc9-452c-aecd-63feaa35ec6f"
Hint: StartLabel
Value: Begin Application
- ID: "badd9cf9-53e0-4d0c-bcc0-2d784c282f6a"
Hint: __Updated by
Value: |
sitecore\[email protected]
sitecore\ed7gR4aY22
- ID: "be5de310-fa69-4be7-9aaa-81171ca518b4"
Hint: ContributionDescriptionLabel
Value: Description
Expand All @@ -111,6 +114,9 @@ Languages:
- ID: "c7d26ded-fb4a-4c3a-98b8-4a784562a0c1"
Hint: ConsentTitleLabel
Value: Welcome
- ID: "c8c9c14b-396d-4070-ad58-5299e283e68b"
Hint: ContributionConfirmDeleteLabel
Value: "Are you sure you want to delete this contribution?"
- ID: "d83af848-62a5-4c21-99ad-b18d38c043c6"
Hint: ContributionLinkLabel
Value: Link
Expand All @@ -119,7 +125,7 @@ Languages:
Value: MVP Category
- ID: "d9cf14b1-fa16-4ba6-9288-e8a174d4d522"
Hint: __Updated
Value: 20221005T162310Z
Value: 20231110T115329Z
- ID: "e9631ea3-2df0-4c18-8e6d-9a84e06717c8"
Hint: NextLabel
Value: Next
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,16 @@ public class ApplicationFormModel : BaseModel

public TextField AddLabel { get; set; }

public TextField UpdateLabel { get; set; }

public Guid? DeleteContributionId { get; set; }

public Guid? UpdateContributionId { get; set; }

public bool IsUpdate { get; set; } = false;

public TextField ContributionConfirmDeleteLabel { get; set; }

public TextField ConfirmationTitleLabel { get; set; }

public TextField ReviewConsentLabel { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Markdig" />
<PackageReference Include="Mvp.Selections.Client" />
<PackageReference Include="Sitecore.AspNet.RenderingEngine" />
<PackageReference Include="Sitecore.LayoutService.Client" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,27 @@ private async Task ExecuteContributionsStep(ApplicationFormModel model)
await LoadProducts(model);
model.NextStep = ApplicationStep.Contributions;
}
else if (model.IsNavigation.HasValue && !model.IsNavigation.Value && model.UpdateContributionId.HasValue && !model.IsUpdate)
{
Contribution editContribution =
model.CurrentApplication.Contributions.FirstOrDefault(c =>
c.Id == model.UpdateContributionId.Value);
if (editContribution != null)
{
model.ContributionDate = editContribution.Date;
model.ContributionName = editContribution.Name;
model.ContributionDescription = editContribution.Description;
model.ContributionLink = editContribution.Uri;
model.ContributionType = editContribution.Type;
foreach (Product product in editContribution.RelatedProducts)
{
model.ContributionProductIds.Add(product.Id);
}
}

await LoadProducts(model);
model.NextStep = ApplicationStep.Contributions;
}
else if (
model.IsNavigation.HasValue
&& !model.IsNavigation.Value
Expand All @@ -423,7 +444,7 @@ private async Task ExecuteContributionsStep(ApplicationFormModel model)
&& model.ContributionDate.Value >= model.CurrentSelection.ApplicationsEnd.AddMonths(-_options.TimeFrameMonths)
&& model.ContributionDate.Value <= model.CurrentSelection.ApplicationsEnd)
{
Contribution contribution = new (Guid.Empty)
Contribution contribution = new (model.UpdateContributionId ?? Guid.Empty)
{
Date = model.ContributionDate.Value,
Name = model.ContributionName,
Expand All @@ -436,9 +457,23 @@ private async Task ExecuteContributionsStep(ApplicationFormModel model)
contribution.RelatedProducts.Add(new Product(productId));
}

Response<Contribution> contributionResponse = await Client.AddContributionAsync(model.CurrentApplication.Id, contribution);
if (contributionResponse.StatusCode == HttpStatusCode.Created && contributionResponse.Result != null)
Response<Contribution> contributionResponse = model.UpdateContributionId.HasValue
? await Client.UpdateContributionAsync(model.UpdateContributionId.Value, contribution)
: await Client.AddContributionAsync(model.CurrentApplication.Id, contribution);
if (contributionResponse.StatusCode is HttpStatusCode.Created or HttpStatusCode.OK && contributionResponse.Result != null)
{
if (model.UpdateContributionId.HasValue)
{
Contribution editContribution =
model.CurrentApplication.Contributions.FirstOrDefault(c =>
c.Id == model.UpdateContributionId.Value);
if (editContribution != null)
{
model.CurrentApplication.Contributions.Remove(editContribution);
}
}

model.UpdateContributionId = null;
model.CurrentApplication.Contributions.Add(contributionResponse.Result);
model.ContributionDate = null;
model.ContributionName = null;
Expand All @@ -448,6 +483,11 @@ private async Task ExecuteContributionsStep(ApplicationFormModel model)
model.ContributionProductIds = new List<int>();
ModelState.Clear();
}
else
{
model.ErrorMessages.Add(contributionResponse.Message);
model.NextStep = ApplicationStep.Error;
}

await LoadProducts(model);
model.NextStep = ApplicationStep.Contributions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<form method="post">
<input asp-for="IsNavigation" type="hidden" value="false"/>
<input asp-for="CurrentStep" type="hidden" value="Contributions"/>
<input asp-for="UpdateContributionId" type="hidden"/>
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-row">
<div class="form-group col-sm-12 col-md-12">
Expand Down Expand Up @@ -76,7 +77,15 @@
</div>

<div class="col-12">
<button asp-for="AddLabel" type="submit" class="btn btn-primary"></button>
@if (Model.UpdateContributionId.HasValue)
{
<input asp-for="IsUpdate" type="hidden" value="true"/>
<button asp-for="UpdateLabel" type="submit" class="btn btn-primary"></button>
}
else
{
<button asp-for="AddLabel" type="submit" class="btn btn-primary"></button>
}
</div>
</div>
</form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,24 @@
@contribution.Date.ToString("d")
@if (Model.NextStep == ApplicationStep.Contributions)
{
<form method="post" class="float-right">
<form method="post" class="float-right" onsubmit="return confirm('@Model.ContributionConfirmDeleteLabel.Value');">
<input asp-for="IsNavigation" type="hidden" value="false" />
<input asp-for="CurrentStep" type="hidden" value="Contributions" />
<input asp-for="DeleteContributionId" type="hidden" value="@contribution.Id" />
<button type="submit" class="btn btn-danger"><i class="fa fa-trash" aria-hidden="true"></i></button>
</form>

<form method="post" class="float-right">
<input asp-for="IsNavigation" type="hidden" value="false" />
<input asp-for="CurrentStep" type="hidden" value="Contributions" />
<input asp-for="UpdateContributionId" type="hidden" value="@contribution.Id" />
<button type="submit" class="btn btn-primary"><i class="fa fa-pencil" aria-hidden="true"></i></button>
</form>
}
</div>
<div class="card-body">
<h5 class="card-title"><span class="badge badge-info">@contribution.Type</span> @contribution.Name</h5>
<p class="card-text">@contribution.Description</p>
<p class="card-text">@Html.Raw(Markdig.Markdown.ToHtml(contribution.Description))</p>
@if (contribution.Uri != null)
{
<a href="@contribution.Uri" target="_blank" class="card-link">@Model.ContributionLinkLabel.Value</a><br/>
Expand Down
12 changes: 12 additions & 0 deletions up.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ $sugconNaHost = $envContent | Where-Object { $_ -imatch "^SUGCON_NA_HOST=.+" }
$sitecoreDockerRegistry = $envContent | Where-Object { $_ -imatch "^SITECORE_DOCKER_REGISTRY=.+" }
$sitecoreVersion = $envContent | Where-Object { $_ -imatch "^SITECORE_VERSION=.+" }

if ([string]::IsNullOrEmpty($xmCloudHost) -or
[string]::IsNullOrEmpty($mvpHost) -or
[string]::IsNullOrEmpty($sugconeuHost) -or
[string]::IsNullOrEmpty($sugconanzHost) -or
[string]::IsNullOrEmpty($sugconindiaHost) -or
[string]::IsNullOrEmpty($sugconNaHost) -or
[string]::IsNullOrEmpty($sitecoreDockerRegistry) -or
[string]::IsNullOrEmpty($sitecoreVersion))
{
throw "Missing hostname, docker registry or sitecore version ENV variable!"
}

$xmCloudHost = $xmCloudHost.Split("=")[1]
$mvpHost = $mvpHost.Split("=")[1]
$sugconeuHost = $sugconeuHost.Split("=")[1]
Expand Down

0 comments on commit 2fe91d0

Please sign in to comment.