2023-11-20 06:59:04 +08:00
|
|
|
import Component from "@glimmer/component";
|
|
|
|
import { tracked } from "@glimmer/tracking";
|
|
|
|
import didInsert from "@ember/render-modifiers/modifiers/did-insert";
|
2024-07-29 12:20:12 +08:00
|
|
|
import { service } from "@ember/service";
|
2024-11-27 07:40:55 +08:00
|
|
|
import ConditionalLoadingSpinner from "discourse/components/conditional-loading-spinner";
|
2023-11-20 06:59:04 +08:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
2024-11-27 07:40:55 +08:00
|
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
2023-11-20 06:59:04 +08:00
|
|
|
import { bind } from "discourse-common/utils/decorators";
|
2024-11-20 04:45:18 +08:00
|
|
|
import { i18n } from "discourse-i18n";
|
2024-07-29 12:20:12 +08:00
|
|
|
import AdminConfigAreaCard from "admin/components/admin-config-area-card";
|
2024-11-27 07:40:55 +08:00
|
|
|
import AdminConfigAreaEmptyList from "admin/components/admin-config-area-empty-list";
|
2023-11-20 06:59:04 +08:00
|
|
|
import DashboardNewFeatureItem from "admin/components/dashboard-new-feature-item";
|
|
|
|
|
|
|
|
export default class DashboardNewFeatures extends Component {
|
2024-07-29 12:20:12 +08:00
|
|
|
@service currentUser;
|
|
|
|
|
2023-11-20 06:59:04 +08:00
|
|
|
@tracked newFeatures = null;
|
2024-07-29 12:20:12 +08:00
|
|
|
@tracked groupedNewFeatures = null;
|
2024-11-27 07:40:55 +08:00
|
|
|
@tracked isLoading = true;
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super(...arguments);
|
|
|
|
this.args.onCheckForFeatures(this.loadNewFeatures);
|
|
|
|
}
|
2023-11-20 06:59:04 +08:00
|
|
|
|
|
|
|
@bind
|
2024-11-27 07:40:55 +08:00
|
|
|
async loadNewFeatures(opts = {}) {
|
|
|
|
opts.forceRefresh ||= false;
|
|
|
|
this.isLoading = true;
|
|
|
|
|
|
|
|
try {
|
|
|
|
const json = await ajax(
|
|
|
|
"/admin/whats-new.json?force_refresh=" + opts.forceRefresh
|
|
|
|
);
|
|
|
|
const items = json.new_features.reduce((acc, feature) => {
|
|
|
|
const key = moment(feature.released_at || feature.created_at).format(
|
|
|
|
"YYYY-MM"
|
|
|
|
);
|
|
|
|
acc[key] = acc[key] || [];
|
|
|
|
acc[key].push(feature);
|
|
|
|
return acc;
|
|
|
|
}, {});
|
2024-07-29 12:20:12 +08:00
|
|
|
|
2024-11-27 07:40:55 +08:00
|
|
|
this.groupedNewFeatures = Object.keys(items).map((date) => {
|
|
|
|
return {
|
|
|
|
date: moment
|
|
|
|
.tz(date, this.currentUser.user_option.timezone)
|
|
|
|
.format("MMMM YYYY"),
|
|
|
|
features: items[date],
|
|
|
|
};
|
2023-11-20 06:59:04 +08:00
|
|
|
});
|
2024-11-27 07:40:55 +08:00
|
|
|
} catch (err) {
|
|
|
|
popupAjaxError(err);
|
|
|
|
} finally {
|
|
|
|
this.isLoading = false;
|
|
|
|
}
|
2023-11-20 06:59:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
<template>
|
2024-10-10 09:40:05 +08:00
|
|
|
<div
|
|
|
|
class="admin-config-area__primary-content"
|
|
|
|
{{didInsert this.loadNewFeatures}}
|
|
|
|
>
|
2024-11-27 07:40:55 +08:00
|
|
|
<ConditionalLoadingSpinner @condition={{this.isLoading}}>
|
2024-07-29 12:20:12 +08:00
|
|
|
{{#each this.groupedNewFeatures as |groupedFeatures|}}
|
|
|
|
<AdminConfigAreaCard @translatedHeading={{groupedFeatures.date}}>
|
2024-10-15 23:54:38 +08:00
|
|
|
<:content>
|
|
|
|
{{#each groupedFeatures.features as |feature|}}
|
|
|
|
<DashboardNewFeatureItem @item={{feature}} />
|
|
|
|
{{/each}}
|
|
|
|
</:content>
|
2024-07-29 12:20:12 +08:00
|
|
|
</AdminConfigAreaCard>
|
2024-11-27 07:40:55 +08:00
|
|
|
{{else}}
|
|
|
|
<AdminConfigAreaEmptyList
|
2024-11-28 13:31:04 +08:00
|
|
|
@emptyLabelTranslated={{i18n
|
2024-11-28 04:49:58 +08:00
|
|
|
"admin.dashboard.new_features.previous_announcements"
|
|
|
|
url="https://meta.discourse.org/tags/c/announcements/67/release-notes"
|
2024-11-27 07:40:55 +08:00
|
|
|
}}
|
|
|
|
/>
|
2023-11-20 06:59:04 +08:00
|
|
|
{{/each}}
|
2024-11-27 07:40:55 +08:00
|
|
|
</ConditionalLoadingSpinner>
|
2023-11-20 06:59:04 +08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
}
|