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-2162] MIM-2162:Fixed bug average year #3085

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
152 changes: 7 additions & 145 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
"webpack": "~5.96.1",
"webpack-bundle-analyzer": "~4.10.2",
"webpack-cli": "~5.1.4",
"xlsx": "~0.18.5"
"xlsx": "file:src/main/resources/lib/vendor/xlsx-0.20.3.tgz"
},
"browserslist": [
"last 2 version",
Expand Down
13 changes: 9 additions & 4 deletions src/main/resources/assets/styles/_statbankBox.scss
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,15 @@
align-items: center;
margin-left: 40px;

.title {
display: inline;
border-bottom: 2px solid $ssb-green-4;
}
.title {
display: inline;
border-bottom: 2px solid $ssb-green-4;
font-size: 1.25rem;
line-height: 2rem;
@include roboto;
font-weight: bold;
color: $ssb-dark-6;
}

@include media-breakpoint-down(sm) {
margin-left: 20px;
Expand Down
40 changes: 17 additions & 23 deletions src/main/resources/lib/ssb/rss/news.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { query, type Content } from '/lib/xp/content'
import { StatisticInListing, VariantInListing } from '/lib/ssb/dashboard/statreg/types'
import { getTimeZoneIso } from '/lib/ssb/utils/dateUtils'
import { subDays, isSameDay, format, parseISO } from '/lib/vendor/dateFns'
import { fetchStatisticsWithReleaseToday } from '/lib/ssb/statreg/statistics'
import { subDays, format, parseISO } from '/lib/vendor/dateFns'
import { fetchStatisticsWithReleaseToday, fetchStatisticsDaysBack } from '/lib/ssb/statreg/statistics'
import { getMainSubjects } from '/lib/ssb/utils/subjectUtils'
import { nextReleasedPassed } from '/lib/ssb/utils/variantUtils'
// @ts-ignore
import { xmlEscape } from '/lib/text-encoding'
import { type SubjectItem } from '/lib/types/subject'
Expand All @@ -14,8 +15,8 @@ const dummyReq: Partial<XP.Request> = {
branch: 'master',
}

export function getRssItemsNews(): string | null {
const news: NewsItem[] = getNews()
export function getRssItemsNews(days: number = 1): string | null {
const news: NewsItem[] = getNews(days)
const xml = `<?xml version="1.0" encoding="utf-8"?>
<rssitems count="${news.length}">
${news
Expand All @@ -37,15 +38,15 @@ export function getRssItemsNews(): string | null {
return xml
}

export function getNews(): NewsItem[] {
export function getNews(days: number = 1): NewsItem[] {
const mainSubjects: SubjectItem[] = getMainSubjects(dummyReq as XP.Request)
const articles: NewsItem[] = getArticles(mainSubjects)
const statistics: NewsItem[] = getStatistics(mainSubjects)
const articles: NewsItem[] = getArticles(mainSubjects, days)
const statistics: NewsItem[] = getStatistics(mainSubjects, days)
return articles.concat(statistics)
}

function getArticles(mainSubjects: SubjectItem[]): NewsItem[] {
const from: string = subDays(new Date(), 1).toISOString()
function getArticles(mainSubjects: SubjectItem[], days: number): NewsItem[] {
const from: string = subDays(new Date(), days).toISOString()
const to: string = new Date().toISOString()
const serverOffsetInMilliSeconds: number = parseInt(app.config?.['serverOffsetInMs']) || 0
const timeZoneIso: string = getTimeZoneIso(serverOffsetInMilliSeconds)
Expand Down Expand Up @@ -93,8 +94,9 @@ function getArticles(mainSubjects: SubjectItem[]): NewsItem[] {
return news
}

function getStatistics(mainSubjects: SubjectItem[]): NewsItem[] {
const statregStatistics: Array<StatisticInListing> = fetchStatisticsWithReleaseToday()
function getStatistics(mainSubjects: SubjectItem[], days: number): NewsItem[] {
const statregStatistics: Array<StatisticInListing> =
days > 1 ? fetchStatisticsDaysBack(days) : fetchStatisticsWithReleaseToday()
const serverOffsetInMS: number = parseInt(app.config?.['serverOffsetInMs']) || 0
const timeZoneIso: string = getTimeZoneIso(serverOffsetInMS)

Expand All @@ -114,6 +116,7 @@ function getStatistics(mainSubjects: SubjectItem[]): NewsItem[] {
)
const variant: VariantInListing | undefined = statreg?.variants?.[0] || undefined
const pubDate: string | undefined = variant ? getPubDateStatistic(variant, timeZoneIso) : undefined

const link = getLinkByPath(statistic._path)
if (pubDate) {
statisticsNews.push({
Expand All @@ -136,18 +139,9 @@ function getStatistics(mainSubjects: SubjectItem[]): NewsItem[] {
}

function getPubDateStatistic(variant: VariantInListing, timeZoneIso: string): string | undefined {
const previousReleaseSameDayNow: boolean = variant.previousRelease
? isSameDay(new Date(variant.previousRelease), new Date())
: false
const nextReleaseSameDayNow: boolean = variant.nextRelease
? isSameDay(new Date(variant.nextRelease), new Date())
: false
if (previousReleaseSameDayNow) {
return variant.previousRelease ? formatPubDateStatistic(variant.previousRelease, timeZoneIso) : undefined
} else if (nextReleaseSameDayNow) {
return variant.nextRelease ? formatPubDateStatistic(variant.nextRelease, timeZoneIso) : undefined
}
return undefined
const nextReleaseDatePassed: boolean = variant.nextRelease ? nextReleasedPassed(variant) : false
const pubDate: string | undefined = nextReleaseDatePassed ? variant.nextRelease : variant.previousRelease
return pubDate ? formatPubDateStatistic(pubDate, timeZoneIso) : undefined
}

function formatPubDateArticle(date: string, serverOffsetInMS: number, timeZoneIso: string): string {
Expand Down
Loading
Loading