From 3f42e6428512b6dd2fa483ec40cad6a7f8a570ba Mon Sep 17 00:00:00 2001
From: WojciechGrancow
Date: Tue, 2 Apr 2024 16:22:48 +0200
Subject: [PATCH 1/4] modify view in news, add helper
---
controllers/news.js | 2 +-
helpers/handlebars/helpers/index.js | 1 +
helpers/momentHelper.js | 50 +++++++++++++++++------------
helpers/timesHelper.js | 17 ++++++++++
locales/calendar/de.json | 2 +-
locales/calendar/uk.json | 12 +++----
views/news/article.hbs | 23 +++++--------
7 files changed, 63 insertions(+), 44 deletions(-)
diff --git a/controllers/news.js b/controllers/news.js
index 1982a932fd..25b0552dea 100644
--- a/controllers/news.js
+++ b/controllers/news.js
@@ -124,7 +124,7 @@ router.get('/:newsId', (req, res, next) => {
api(req, { version: VERSION })
.get(`/news/${req.params.newsId}`)
.then((news) => {
- const updatedAtNotEqualCreatedAt = !(news.updatedAt === news.createdAt);
+ const updatedAtNotEqualCreatedAt = !(news.updatedAt === news.createdAt) && (news.updatedAt !== undefined);
res.render('news/article', {
title: news.title,
news,
diff --git a/helpers/handlebars/helpers/index.js b/helpers/handlebars/helpers/index.js
index 9da6398386..538e9aa237 100644
--- a/helpers/handlebars/helpers/index.js
+++ b/helpers/handlebars/helpers/index.js
@@ -193,6 +193,7 @@ const helpers = () => ({
userIds: (users) => (users || []).map((user) => user._id).join(','),
getAssetPath: (assetPath) => getStaticAssetPath(assetPath),
timeFromNow: (date) => timesHelper.fromNow(date),
+ timeFromNowWithRule: (date) => timesHelper.fromNowWithRule(date),
datePickerTodayMinus: (years, months, days, format) => {
if (typeof (format) !== 'string') {
format = 'YYYY.MM.DD';
diff --git a/helpers/momentHelper.js b/helpers/momentHelper.js
index f016f1bd51..3cfa6fff19 100644
--- a/helpers/momentHelper.js
+++ b/helpers/momentHelper.js
@@ -23,36 +23,44 @@ const relativeTime = {
};
*/
-const createCustomRelativeTimeConfig = (localFile) => ({
- d: `${localFile['moment.relativeTime.aDay']}`,
- dd: `%d ${localFile['moment.relativeTime.days']}`,
- future: `${localFile['moment.relativeTime.futureIn']} %s`,
- h: `${localFile['moment.relativeTime.anHour']}`,
- hh: `%d ${localFile['moment.relativeTime.hours']}`,
- m: `${localFile['moment.relativeTime.aMinute']}`,
- M: `${localFile['moment.relativeTime.aMonths']}`,
- mm: `%d ${localFile['moment.relativeTime.minutes']}`,
- MM: `%d ${localFile['moment.relativeTime.months']}`,
- past: `%s ${localFile['moment.relativeTime.pastAgo']}`,
- s: `${localFile['moment.relativeTime.aFewSecondes']}`,
- ss: `%d ${localFile['moment.relativeTime.seconds']}`,
- w: `${localFile['moment.relativeTime.aWeek']}`,
- ww: `%d ${localFile['moment.relativeTime.weeks']}`,
- y: `${localFile['moment.relativeTime.aYear']}`,
- yy: `%d ${localFile['moment.relativeTime.years']}`,
-});
+const createCustomRelativeTimeConfig = (localFile, lang) => {
+ const commonConfig = {
+ d: `${localFile['moment.relativeTime.aDay']}`,
+ dd: `%d ${localFile['moment.relativeTime.days']}`,
+ future: `${localFile['moment.relativeTime.futureIn']} %s`,
+ h: `${localFile['moment.relativeTime.anHour']}`,
+ hh: `%d ${localFile['moment.relativeTime.hours']}`,
+ m: `${localFile['moment.relativeTime.aMinute']}`,
+ M: `${localFile['moment.relativeTime.aMonths']}`,
+ mm: `%d ${localFile['moment.relativeTime.minutes']}`,
+ MM: `%d ${localFile['moment.relativeTime.months']}`,
+ past: `%s ${localFile['moment.relativeTime.pastAgo']}`,
+ s: `${localFile['moment.relativeTime.aFewSecondes']}`,
+ ss: `%d ${localFile['moment.relativeTime.seconds']}`,
+ w: `${localFile['moment.relativeTime.aWeek']}`,
+ ww: `%d ${localFile['moment.relativeTime.weeks']}`,
+ y: `${localFile['moment.relativeTime.aYear']}`,
+ yy: `%d ${localFile['moment.relativeTime.years']}`,
+ };
+
+ if (lang === 'de' || lang === 'es') {
+ commonConfig.past = `${localFile['moment.relativeTime.pastAgo']} %s`;
+ }
+
+ return commonConfig;
+};
const selectMomentOptions = (langAttribute) => {
const options = {};
if (langAttribute === 'uk') {
- options.relativeTime = createCustomRelativeTimeConfig(uk);
+ options.relativeTime = createCustomRelativeTimeConfig(uk, 'uk');
}
if (langAttribute === 'es') {
- options.relativeTime = createCustomRelativeTimeConfig(es);
+ options.relativeTime = createCustomRelativeTimeConfig(es, 'es');
}
if (langAttribute === 'de') {
- options.relativeTime = createCustomRelativeTimeConfig(de);
+ options.relativeTime = createCustomRelativeTimeConfig(de, 'de');
}
return options;
diff --git a/helpers/timesHelper.js b/helpers/timesHelper.js
index 4fd5413c2b..3f41f52662 100644
--- a/helpers/timesHelper.js
+++ b/helpers/timesHelper.js
@@ -100,6 +100,22 @@ const now = () => {
*/
const fromNow = (date) => moment(date).fromNow();
+/**
+ *
+ * @param date
+ * @returns {string}
+ */
+const fromNowWithRule = (date) => {
+ let result;
+ const diff = moment() - moment(date);
+ if (moment.duration(diff).asDays() < -6 || moment.duration(diff).asDays() > 6) {
+ result = moment(date).format('DD.MM.YYYY');
+ } else {
+ result = moment(date).fromNow();
+ }
+ return result;
+};
+
/**
* @param {Date} date Date object
* @param dateFormat date format
@@ -217,6 +233,7 @@ module.exports = {
currentDate,
now,
fromNow,
+ fromNowWithRule,
timeToString,
splitDate,
formatDate,
diff --git a/locales/calendar/de.json b/locales/calendar/de.json
index b8b789e3da..58a4fc91ca 100644
--- a/locales/calendar/de.json
+++ b/locales/calendar/de.json
@@ -1,7 +1,7 @@
{
"moment.relativeTime.aDay": "ein Tag",
"moment.relativeTime.days": "Tage",
- "moment.relativeTime.futureIn": "auf",
+ "moment.relativeTime.futureIn": "in",
"moment.relativeTime.anHour": "eine Stunde",
"moment.relativeTime.hours": "Stunden",
"moment.relativeTime.aMinute": "eine Minute",
diff --git a/locales/calendar/uk.json b/locales/calendar/uk.json
index 652088f39a..9f82ad0a56 100644
--- a/locales/calendar/uk.json
+++ b/locales/calendar/uk.json
@@ -11,14 +11,14 @@
"calendar.eventLimitText": "Далі",
"calendar.noEventsMessage": "Немає подій для показу",
"calendar.weekLabel": "тиждень",
- "moment.relativeTime.aDay": "за останній день",
- "moment.relativeTime.days": "днів",
- "moment.relativeTime.futureIn": "в",
+ "moment.relativeTime.aDay": "день",
+ "moment.relativeTime.days": "дні (-в)",
+ "moment.relativeTime.futureIn": "через",
"moment.relativeTime.anHour": "годину",
- "moment.relativeTime.hours": "годин",
- "moment.relativeTime.aMinute": "хвилина",
+ "moment.relativeTime.hours": "годин (-и)",
+ "moment.relativeTime.aMinute": "хвилинy",
"moment.relativeTime.aMonths": "місяць",
- "moment.relativeTime.minutes": "хвилин",
+ "moment.relativeTime.minutes": "хвилин (-и)",
"moment.relativeTime.months": "місяців",
"moment.relativeTime.pastAgo": "тому",
"moment.relativeTime.aFewSecondes": "кілька секунд",
diff --git a/views/news/article.hbs b/views/news/article.hbs
index 803a0c7eaf..fa42ef0969 100644
--- a/views/news/article.hbs
+++ b/views/news/article.hbs
@@ -20,36 +20,29 @@
{{#unless isRSS}}
{{#if updatedAtNotEqualCreatedAt}}
- {{$t "news.text.last" }} {{$t "news.text.processed" }}
+ {{timeFromNowWithRule news.updatedAt}}
{{/if}}
{{#if news.updater}}
- {{$t "news.text.by" }} {{news.updater.firstName}} {{news.updater.lastName}}
- {{/if}}
- {{#if updatedAtNotEqualCreatedAt}}
- {{timeFromNow news.updatedAt}}
+ | {{news.updater.firstName}} {{news.updater.lastName}}
{{/if}}
{{#if updatedAtNotEqualCreatedAt}} | {{/if}}
- {{$t "news.text.created" }}
+ {{timeFromNowWithRule news.displayAt}}
{{#if news.creator}}
- {{$t "news.text.by" }} {{news.creator.firstName}} {{news.creator.lastName}}
+ | {{news.creator.firstName}} {{news.creator.lastName}}
{{/if}}
- {{timeFromNow news.displayAt}}
{{#if news.target.name}}
{{#ifCond news.targetModel '===' 'teams'}}
- {{$t "news.text.inTheTeam" }}
+ |
{{../news.target.name}}
{{/ifCond}}
{{#ifCond news.targetModel '===' 'courses'}}
- {{$t "news.text.inTheCourse" }}
- {{../news.target.name}}
+ | {{../news.target.name}}
{{/ifCond}}
{{#ifCond news.targetModel '===' 'class'}}
- {{$t "news.text.inTheClass" }}
- {{../news.target.name}}
+ | {{../news.target.name}}
{{/ifCond}}
{{/if}}
-
- {{#ifCond @root.currentUser.schoolId '!==' news.school.id}} {{$t "news.text.atSchool" }} {{../news.school.name}}
+ {{#ifCond @root.currentUser.schoolId '!==' news.school.id}} | {{../news.school.name}}
{{/ifCond}}
{{/unless}}
From c60c4e321889b4e5af0ec259ffc24710dd00f293 Mon Sep 17 00:00:00 2001
From: WojciechGrancow
Date: Thu, 4 Apr 2024 14:50:33 +0200
Subject: [PATCH 2/4] implement whole disgn required by UX
---
locales/de.json | 7 +------
locales/en.json | 7 +------
locales/es.json | 6 +-----
locales/uk.json | 13 ++++---------
static/styles/news/news.scss | 10 ++++++++++
views/news/article.hbs | 37 ++++++++++++++++++------------------
views/news/svg_clock.hbs | 3 +++
views/news/svg_school.hbs | 3 +++
views/news/svg_teacher.hbs | 3 +++
views/news/svg_team.hbs | 3 +++
10 files changed, 48 insertions(+), 44 deletions(-)
create mode 100644 views/news/svg_clock.hbs
create mode 100644 views/news/svg_school.hbs
create mode 100644 views/news/svg_teacher.hbs
create mode 100644 views/news/svg_team.hbs
diff --git a/locales/de.json b/locales/de.json
index ba33fab592..623a5c77d0 100644
--- a/locales/de.json
+++ b/locales/de.json
@@ -2645,17 +2645,12 @@
"searchForNews": "Suche nach Neuigkeiten"
},
"text": {
- "atSchool": "an der Schule",
- "atYourSchool": "an deiner Schule ",
"created": "erstellt",
- "by": "von",
+ "edited": "bearbeitet",
"inTheClass": "in der Klasse",
"inTheCourse": "im Kurs",
- "inTheTeam": "im Team",
- "last": "zuletzt",
"newsNeedContent": "News benötigen Inhalt!",
"newsNeedTitle": "News benötigen einen Titel!",
- "processed": "bearbeitet",
"released": "Veröffentlicht",
"unpublished": "Unveröffentlicht"
}
diff --git a/locales/en.json b/locales/en.json
index ef320b28cc..a789fe3a78 100644
--- a/locales/en.json
+++ b/locales/en.json
@@ -2645,17 +2645,12 @@
"searchForNews": "Search for news"
},
"text": {
- "atSchool": "at school",
- "atYourSchool": "at your school ",
- "by": "by",
"created": "created",
+ "edited": "edited",
"inTheClass": "in the class",
"inTheCourse": "in the course",
- "inTheTeam": "in the team",
- "last": "last",
"newsNeedContent": "News need content!",
"newsNeedTitle": "News need a title!",
- "processed": "edited",
"released": "Released",
"unpublished": "Unpublished"
}
diff --git a/locales/es.json b/locales/es.json
index 004675ca76..9bc400738d 100644
--- a/locales/es.json
+++ b/locales/es.json
@@ -2645,17 +2645,13 @@
"searchForNews": "Buscar noticias"
},
"text": {
- "atSchool": "en la escuela",
- "atYourSchool": "en tu escuela",
"created": "creado",
- "by": "por",
+ "edited": "editado",
"inTheClass": "en la clase",
"inTheCourse": "en el curso",
- "inTheTeam": "en el equipo",
"last": "últimamente",
"newsNeedContent": "¡Las noticias necesitan contenido!",
"newsNeedTitle": "¡Las noticias necesitan un título!",
- "processed": "editado",
"released": "Publicado",
"unpublished": "Sin publicar"
}
diff --git a/locales/uk.json b/locales/uk.json
index 5714d0bbfb..5a55c79ed8 100644
--- a/locales/uk.json
+++ b/locales/uk.json
@@ -1674,19 +1674,14 @@
"searchForNews": "Пошук новин"
},
"text": {
- "atSchool": "у школі",
- "atYourSchool": "у вашій школі ",
"created": "створено",
- "by": "",
+ "edited": "відредаговано",
"inTheClass": "в класі",
"inTheCourse": "в курсі",
- "inTheTeam": "в команді",
- "last": "останній раз було",
- "processed": "відредаговано",
- "released": "Випущено",
- "unpublished": "Не опубліковано",
"newsNeedContent": "Новинам потрібний контент!",
- "newsNeedTitle": "Новинам потрібна назва!"
+ "newsNeedTitle": "Новинам потрібна назва!",
+ "released": "Випущено",
+ "unpublished": "Не опубліковано"
},
"_news": {
"headline": {
diff --git a/static/styles/news/news.scss b/static/styles/news/news.scss
index 302bf6e215..537525d997 100644
--- a/static/styles/news/news.scss
+++ b/static/styles/news/news.scss
@@ -33,3 +33,13 @@
.tabContainer {
clear: both;
}
+.icon-custom {
+ vertical-align: middle;
+}
+.custom-style {
+ font-size: 100% !important;
+}
+.tooltip-inner {
+ max-width: 100%;
+ text-align: left !important;
+}
\ No newline at end of file
diff --git a/views/news/article.hbs b/views/news/article.hbs
index fa42ef0969..0db57633c4 100644
--- a/views/news/article.hbs
+++ b/views/news/article.hbs
@@ -1,7 +1,6 @@
{{#extend "news/news"}}
{{#content "page"}}
-
{{#if isRSS}}
{{#userHasPermission "SCHOOL_NEWS_EDIT"}}
@@ -13,27 +12,25 @@
{{/userHasPermission}}
{{/if}}
-
-
- {{{news.content}}}
-
-{{#unless isRSS}}
+ {{#unless isRSS}}
{{#if updatedAtNotEqualCreatedAt}}
- {{timeFromNowWithRule news.updatedAt}}
- {{/if}}
- {{#if news.updater}}
- | {{news.updater.firstName}} {{news.updater.lastName}}
- {{/if}}
- {{#if updatedAtNotEqualCreatedAt}} | {{/if}}
- {{timeFromNowWithRule news.displayAt}}
- {{#if news.creator}}
- | {{news.creator.firstName}} {{news.creator.lastName}}
+ {{$t "news.text.created"}} {{timeFromNowWithRule news.displayAt}} {{#if news.creator}} | {{news.creator.firstName}} {{news.creator.lastName}} {{/if}}">
+ {{> 'news/svg_clock' }} {{timeFromNowWithRule news.updatedAt}}
+
+ {{#if news.updater}}
+ | {{> 'news/svg_teacher' }} {{news.updater.firstName}} {{news.updater.lastName}}
+ {{/if}}
{{/if}}
+ {{#unless updatedAtNotEqualCreatedAt}}
+ {{> 'news/svg_clock' }} {{timeFromNowWithRule news.displayAt}}
+ {{#if news.creator}}
+ | {{> 'news/svg_teacher' }} {{news.creator.firstName}} {{news.creator.lastName}}
+ {{/if}}
+ {{/unless}}
{{#if news.target.name}}
{{#ifCond news.targetModel '===' 'teams'}}
- |
- {{../news.target.name}}
+ | {{> 'news/svg_team' }} {{../news.target.name}}
{{/ifCond}}
{{#ifCond news.targetModel '===' 'courses'}}
| {{../news.target.name}}
@@ -42,10 +39,14 @@
| {{../news.target.name}}
{{/ifCond}}
{{/if}}
- {{#ifCond @root.currentUser.schoolId '!==' news.school.id}} | {{../news.school.name}}
+ {{#ifCond @root.currentUser.schoolId '!==' news.school.id}} | {{> 'news/svg_school' }} {{../news.school.name}}
{{/ifCond}}
{{/unless}}
+
+
+ {{{news.content}}}
+
{{#unless isRSS}}
{{#inArray 'NEWS_EDIT' ../news.permissions}}
diff --git a/views/news/svg_clock.hbs b/views/news/svg_clock.hbs
new file mode 100644
index 0000000000..1c0867dba7
--- /dev/null
+++ b/views/news/svg_clock.hbs
@@ -0,0 +1,3 @@
+
diff --git a/views/news/svg_school.hbs b/views/news/svg_school.hbs
new file mode 100644
index 0000000000..4b034b0dee
--- /dev/null
+++ b/views/news/svg_school.hbs
@@ -0,0 +1,3 @@
+
diff --git a/views/news/svg_teacher.hbs b/views/news/svg_teacher.hbs
new file mode 100644
index 0000000000..6bba72209d
--- /dev/null
+++ b/views/news/svg_teacher.hbs
@@ -0,0 +1,3 @@
+
diff --git a/views/news/svg_team.hbs b/views/news/svg_team.hbs
new file mode 100644
index 0000000000..4a5439a2ec
--- /dev/null
+++ b/views/news/svg_team.hbs
@@ -0,0 +1,3 @@
+
From f0ecdcc949bdf9345bd86173232cd572309f195e Mon Sep 17 00:00:00 2001
From: WojciechGrancow
Date: Thu, 4 Apr 2024 15:18:12 +0200
Subject: [PATCH 3/4] small changes
---
locales/de.json | 1 +
locales/en.json | 1 +
locales/uk.json | 1 +
3 files changed, 3 insertions(+)
diff --git a/locales/de.json b/locales/de.json
index 623a5c77d0..4d00ccf62e 100644
--- a/locales/de.json
+++ b/locales/de.json
@@ -2649,6 +2649,7 @@
"edited": "bearbeitet",
"inTheClass": "in der Klasse",
"inTheCourse": "im Kurs",
+ "last": "zuletzt",
"newsNeedContent": "News benötigen Inhalt!",
"newsNeedTitle": "News benötigen einen Titel!",
"released": "Veröffentlicht",
diff --git a/locales/en.json b/locales/en.json
index a789fe3a78..fc8efc7d24 100644
--- a/locales/en.json
+++ b/locales/en.json
@@ -2649,6 +2649,7 @@
"edited": "edited",
"inTheClass": "in the class",
"inTheCourse": "in the course",
+ "last": "last",
"newsNeedContent": "News need content!",
"newsNeedTitle": "News need a title!",
"released": "Released",
diff --git a/locales/uk.json b/locales/uk.json
index 5a55c79ed8..995ef8b014 100644
--- a/locales/uk.json
+++ b/locales/uk.json
@@ -1678,6 +1678,7 @@
"edited": "відредаговано",
"inTheClass": "в класі",
"inTheCourse": "в курсі",
+ "last": "останній раз було",
"newsNeedContent": "Новинам потрібний контент!",
"newsNeedTitle": "Новинам потрібна назва!",
"released": "Випущено",
From 2c508c70f6ddd3bf834aa2c5bfe8bb9a0251a441 Mon Sep 17 00:00:00 2001
From: WojciechGrancow
Date: Mon, 8 Apr 2024 11:22:43 +0200
Subject: [PATCH 4/4] fixes after review
---
static/styles/news/news.scss | 9 ++++++---
views/news/article.hbs | 20 ++++++++++----------
2 files changed, 16 insertions(+), 13 deletions(-)
diff --git a/static/styles/news/news.scss b/static/styles/news/news.scss
index 537525d997..0f65503b8f 100644
--- a/static/styles/news/news.scss
+++ b/static/styles/news/news.scss
@@ -33,10 +33,13 @@
.tabContainer {
clear: both;
}
-.icon-custom {
- vertical-align: middle;
+.news-title-container {
+ display: flex;
+ align-items: center;
}
-.custom-style {
+.news-custom-style {
+ display: flex;
+ align-items: center;
font-size: 100% !important;
}
.tooltip-inner {
diff --git a/views/news/article.hbs b/views/news/article.hbs
index 0db57633c4..2207d5adbe 100644
--- a/views/news/article.hbs
+++ b/views/news/article.hbs
@@ -13,33 +13,33 @@
{{/if}}
{{#unless isRSS}}
-
+
{{#if updatedAtNotEqualCreatedAt}}
- {{$t "news.text.created"}} {{timeFromNowWithRule news.displayAt}} {{#if news.creator}} | {{news.creator.firstName}} {{news.creator.lastName}} {{/if}}">
- {{> 'news/svg_clock' }} {{timeFromNowWithRule news.updatedAt}}
+ {{$t "news.text.created"}} {{timeFromNowWithRule news.displayAt}} {{#if news.creator}} | {{news.creator.firstName}} {{news.creator.lastName}} {{/if}}">
+ {{> 'news/svg_clock' }} {{timeFromNowWithRule news.updatedAt}}
{{#if news.updater}}
- | {{> 'news/svg_teacher' }} {{news.updater.firstName}} {{news.updater.lastName}}
+ | {{> 'news/svg_teacher' }} {{news.updater.firstName}} {{news.updater.lastName}}
{{/if}}
{{/if}}
{{#unless updatedAtNotEqualCreatedAt}}
- {{> 'news/svg_clock' }} {{timeFromNowWithRule news.displayAt}}
+ {{> 'news/svg_clock' }} {{timeFromNowWithRule news.displayAt}}
{{#if news.creator}}
- | {{> 'news/svg_teacher' }} {{news.creator.firstName}} {{news.creator.lastName}}
+ | {{> 'news/svg_teacher' }} {{news.creator.firstName}} {{news.creator.lastName}}
{{/if}}
{{/unless}}
{{#if news.target.name}}
{{#ifCond news.targetModel '===' 'teams'}}
- | {{> 'news/svg_team' }} {{../news.target.name}}
+ | {{> 'news/svg_team' }} {{../news.target.name}}
{{/ifCond}}
{{#ifCond news.targetModel '===' 'courses'}}
- | {{../news.target.name}}
+ | {{../news.target.name}}
{{/ifCond}}
{{#ifCond news.targetModel '===' 'class'}}
- | {{../news.target.name}}
+ | {{../news.target.name}}
{{/ifCond}}
{{/if}}
- {{#ifCond @root.currentUser.schoolId '!==' news.school.id}} | {{> 'news/svg_school' }} {{../news.school.name}}
+ {{#ifCond @root.currentUser.schoolId '!==' news.school.id}} | {{> 'news/svg_school' }} {{../news.school.name}}
{{/ifCond}}
{{/unless}}