Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MIM-1825] RelatedArticles Fix #3063

Merged
merged 6 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/main/resources/site/content-types/statistics/statistics.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,24 @@
</input>
</items>
</field-set>
<field-set>
<label>Ds artikkel</label>
<items>
<input name="dsArticle" type="RadioButton">
<label>Hvilken artikkel skal vises som DS artikkel</label>
<help-text>Standard valg er å hente artikkel med lik dato som publiseringsdato for statistikken, ved å velge Siste artikkel for statistikken henter den sist publiserte artikkel som er tilknyttet statistikken</help-text>
<occurrences minimum="1" maximum="1"/>
<config>
<option value="default">Artikkel med lik publiseringsdato som statistikken</option>
<option value="lastArticle">Siste artikkel for statistikken</option>
</config>
<default>default</default>
</input>
</items>
</field-set>
<mixin name="relatedArticles" />
<mixin name="relatedStatistics" />
<mixin name="relatedExternalLinks" />
<mixin name="relatedArticles" />
Carl-OW marked this conversation as resolved.
Show resolved Hide resolved
<mixin name="relatedFactPage" />
<mixin name="contacts" />
<field-set>
Expand Down
26 changes: 19 additions & 7 deletions src/main/resources/site/parts/relatedArticles/relatedArticles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ function renderPart(req: XP.Request, relatedArticles: RelatedArticles['relatedAr
height: 180,
})
} else {
// use placeholder if there is no seo image on the article
const image: string = articleContent.x['com-enonic-app-metafields']?.['meta-data']?.seoImage
imageSrc = imageUrl({
id: image,
Expand Down Expand Up @@ -192,6 +191,7 @@ function addDsArticle(
): RelatedArticles['relatedArticles'] {
const statisticId: string = page._id
const statisticData: Statistics = page.data as Statistics
const dsArticleType: string = statisticData.dsArticle === 'lastArticle' ? 'lastArticle' : 'default'
Carl-OW marked this conversation as resolved.
Show resolved Hide resolved
const statistic: StatisticInListing | undefined = getStatisticByIdFromRepo(statisticData.statistic)

if (statistic) {
Expand All @@ -200,23 +200,35 @@ function addDsArticle(
const nextRelease: string = releaseDates.nextRelease[0]
const previousRelease: string = releaseDates.previousRelease[0]
const statisticPublishDate: string = showPreview && nextRelease !== '' ? nextRelease : previousRelease
const assosiatedArticle: RelatedArticle | undefined = getDsArticle(statisticId, statisticPublishDate)

if (assosiatedArticle && relatedArticles) {
relatedArticles.unshift(assosiatedArticle)
const associatedArticle: RelatedArticle | undefined = getDsArticle(statisticId, statisticPublishDate, dsArticleType)

if (associatedArticle && relatedArticles) {
relatedArticles.unshift(associatedArticle)
}
}

return relatedArticles
}

function getDsArticle(statisticId: string, statisticPublishDate: string): RelatedArticle | undefined {
function getDsArticle(
statisticId: string,
statisticPublishDate: string,
dsArticleType: string
): RelatedArticle | undefined {
statisticPublishDate = statisticPublishDate ? new Date(statisticPublishDate).toLocaleDateString() : ''

const queryString =
dsArticleType === 'lastArticle'
? `data.associatedStatistics.XP.content = "${statisticId}"`
: `data.associatedStatistics.XP.content = "${statisticId}" AND publish.from LIKE "${statisticPublishDate}*" `

const sort = dsArticleType === 'lastArticle' ? 'publish.from DESC' : 'publish.from ASC'
Carl-OW marked this conversation as resolved.
Show resolved Hide resolved

const articleContent: Array<Content<Statistics | Article>> = query({
count: 1,
sort: 'publish.from DESC',
query: `data.associatedStatistics.XP.content = "${statisticId}" AND publish.from LIKE "${statisticPublishDate}*" `,
sort,
query: queryString,
contentTypes: [`${app.name}:article`],
}).hits as unknown as Array<Content<Statistics | Article>>

Expand Down
Loading