feat: What's New

This commit is contained in:
Bread Genie 2023-05-16 10:38:07 +05:30
parent 2e2c8316c6
commit 533b80651b
4 changed files with 79 additions and 0 deletions

View file

@ -424,3 +424,12 @@ after_job = [
extend_bootinfo = [
"frappe.utils.telemetry.add_bootinfo",
]
get_changelog_feed = [
{
"title": "Spid",
"creation": "2023-04-03 16:56:51.436456",
"app_name": "Frappe Framework",
"link": "https://frappe.io/wiki",
}
]

View file

@ -15,6 +15,7 @@ frappe.ui.Notifications = class Notifications {
this.body = this.dropdown_list.find(".notification-list-body");
this.panel_events = this.dropdown_list.find(".panel-events");
this.panel_notifications = this.dropdown_list.find(".panel-notifications");
this.panel_changelog_feed = this.dropdown_list.find(".panel-changelog-feed");
this.user = frappe.session.user;
@ -57,6 +58,12 @@ frappe.ui.Notifications = class Notifications {
view: EventsView,
el: this.panel_events,
},
{
label: __("What's New"),
id: "changelog_feed",
view: ChangelogFeedView,
el: this.panel_changelog_feed,
},
];
let get_headers_html = (item) => {
@ -438,3 +445,53 @@ class EventsView extends BaseNotificationsView {
this.container.html(html);
}
}
class ChangelogFeedView extends BaseNotificationsView {
make() {
frappe
.xcall("frappe.utils.change_log.get_changelog_feed_items", {})
.then((changelog_feed_list) => {
this.render_changelog_feed_html(changelog_feed_list);
});
}
render_changelog_feed_html(changelog_feed_list) {
let html = "";
if (changelog_feed_list.length) {
this.container.empty();
const get_changelog_feed_html = (changelog_feed_item) => {
const timestamp = frappe.datetime.comment_when(changelog_feed_item.creation);
const message_html = `<div class="message">
<div>${changelog_feed_item.title}</div>
<div class="notification-timestamp text-muted">
${changelog_feed_item.app_name} | ${timestamp}
</div>
</div>`;
const item_html = `<a class="recent-item notification-item"
href="${changelog_feed_item.link}"
data-name="${changelog_feed_item.title}"
>
<div class="notification-body">
${message_html}
</div>
</div>
</a>`;
return item_html;
};
html = changelog_feed_list.map(get_changelog_feed_html).join("");
} else {
html = `
<div class="notification-null-state">
<div class="text-center">
<img src="/assets/frappe/images/ui-states/notification-empty-state.svg" alt="Generic Empty State" class="null-state">
<div class="title">${__("Nothing New")}</div>
<div class="subtitle">
${__("There is nothing new for you.")}
</div></div></div>
`;
}
this.container.html(html);
}
}

View file

@ -48,6 +48,7 @@
<div class="notification-list-body">
<div class="panel-notifications"></div>
<div class="panel-events"></div>
<div class="panel-changelog-feed"></div>
</div>
</div>
</li>

View file

@ -309,3 +309,15 @@ def show_update_popup():
if update_message:
frappe.msgprint(update_message, title=_("New updates are available"), indicator="green")
cache.srem("update-user-set", user)
@frappe.whitelist()
def get_changelog_feed_items():
"""Returns a list of all fetched changelog feed items"""
changelog_feed_items = frappe.cache().get_value("changelog_feed")
if not changelog_feed_items:
changelog_feed_items = frappe.get_hooks("get_changelog_feed")
frappe.cache().set_value("changelog_feed", changelog_feed_items, expires_in_sec=60 * 60)
return changelog_feed_items