generated from DFE-Digital/govuk-dotnet-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #532 from DFE-Digital/SWCD-2457-credits-block-comp…
…onent Swcd 2457 credits block component
- Loading branch information
Showing
15 changed files
with
230 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
Childrens-Social-Care-CPD/Contentful/Models/CreditBlock.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Contentful.Core.Models; | ||
|
||
namespace Childrens_Social_Care_CPD.Contentful.Models; | ||
|
||
public class CreditBlock : IContent | ||
{ | ||
public Document DeveloperOfResource { get; set; } | ||
public Document SecondaryDevelopersOfResource { get; set; } | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
Childrens-Social-Care-CPD/Views/Shared/_CreditBlock.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
@using Childrens_Social_Care_CPD.Contentful.Models; | ||
|
||
@model CreditBlock | ||
|
||
@{ | ||
var contextModel = (ContextModel)ViewData["ContextModel"]; | ||
var dateFormat = "dd MMMM yyyy"; | ||
ViewData["RenderStyle"] = "inline"; | ||
} | ||
|
||
<div class="govuk-grid-row"> | ||
<div class="credit-block govuk-details"> | ||
The resources have been developed by <partial name="_RichText" model="Model.DeveloperOfResource" view-data="ViewData" /> | ||
@if (@Model.SecondaryDevelopersOfResource != null) | ||
{ | ||
@:in collaboration with | ||
<partial name="_RichText" model="Model.SecondaryDevelopersOfResource" view-data="ViewData" /> | ||
} | ||
<br /> | ||
Published: @contextModel.PublishDates.FirstPublishedAt.Value.ToString(dateFormat) | ||
<br /> | ||
Last updated: @contextModel.PublishDates.LastPublishedAt.Value.ToString(dateFormat) | ||
<br /> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
Contentful-Schema/migrations/0012-credit-block-component.cjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
module.exports = async function (migration, { makeRequest }) { | ||
const creditBlock = migration | ||
.createContentType("creditBlock") | ||
.name("Credit Block") | ||
.description( | ||
"Shows who developed a resource, the date it was published and the date it was last updated." | ||
) | ||
.displayField("name"); | ||
|
||
creditBlock | ||
.createField("name") | ||
.name("Name") | ||
.type("Symbol") | ||
.localized(false) | ||
.required(true) | ||
.validations([ | ||
{ | ||
unique: true, | ||
}, | ||
]) | ||
.disabled(false) | ||
.omitted(false); | ||
|
||
creditBlock | ||
.createField("developerOfResource") | ||
.name("Developer of resource") | ||
.type("RichText") | ||
.localized(false) | ||
.required(true) | ||
.validations([ | ||
{ | ||
enabledMarks: [], | ||
message: "Marks are not allowed", | ||
}, | ||
{ | ||
enabledNodeTypes: ["hyperlink"], | ||
message: "Only link to Url nodes are allowed", | ||
}, | ||
{ | ||
nodes: {}, | ||
}, | ||
]) | ||
.disabled(false) | ||
.omitted(false); | ||
|
||
creditBlock | ||
.createField("secondaryDevelopersOfResource") | ||
.name("Secondary developer(s) of resource") | ||
.type("RichText") | ||
.localized(false) | ||
.required(false) | ||
.validations([ | ||
{ | ||
enabledMarks: [], | ||
message: "Marks are not allowed", | ||
}, | ||
{ | ||
enabledNodeTypes: ["hyperlink"], | ||
message: "Only link to Url nodes are allowed", | ||
}, | ||
{ | ||
nodes: {}, | ||
}, | ||
]) | ||
.disabled(false) | ||
.omitted(false); | ||
|
||
creditBlock.changeFieldControl( | ||
"name", | ||
"builtin", | ||
"singleLine", | ||
{ | ||
helpText: | ||
"Name is only for internal reference, and will not display on website", | ||
} | ||
); | ||
|
||
creditBlock.changeFieldControl( | ||
"developerOfResource", | ||
"builtin", | ||
"richTextEditor", | ||
{ | ||
helpText: | ||
"Who created this resource? You can make their name a hyperlink to their website if appropriate.", | ||
} | ||
); | ||
|
||
creditBlock.changeFieldControl( | ||
"secondaryDevelopersOfResource", | ||
"builtin", | ||
"richTextEditor", | ||
{ | ||
helpText: | ||
"Optional: Include anyone that this resource was created in collaboration with. E.g. 'DfE'.", | ||
} | ||
); | ||
|
||
/* | ||
* Add creditBlock to list of content types allowed in content pages | ||
*/ | ||
const contentTypeId = "content", | ||
linkingFieldId = "items", | ||
creditBlockTypeId = "creditBlock"; | ||
|
||
const response = await makeRequest({ | ||
method: "GET", | ||
url: `/content_types?sys.id[in]=${contentTypeId}`, | ||
}); | ||
|
||
const validations = response.items[0].fields | ||
.filter((field) => field.id == linkingFieldId)[0] | ||
.items.validations.map((rule) => { | ||
if ( | ||
rule.linkContentType && | ||
!rule.linkContentType.includes(creditBlockTypeId) | ||
) { | ||
rule.linkContentType.push(creditBlockTypeId); | ||
} | ||
return rule; | ||
}); | ||
|
||
migration.editContentType(contentTypeId).editField(linkingFieldId).items({ | ||
type: "Link", | ||
linkType: "Entry", | ||
validations: validations, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.