Compare commits

...
This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.

5 Commits

Author SHA1 Message Date
Jarek Radosz
ede1f4bf6f
format template 2022-12-14 11:59:08 +01:00
Jarek Radosz
436cee1ad2
another controller name 2022-12-14 11:57:17 +01:00
Jarek Radosz
190d858edb
extract static page logic to a component 2022-12-14 11:57:17 +01:00
Jarek Radosz
7e50e76892
up 2022-12-14 11:57:17 +01:00
Jarek Radosz
83a7a95686
DEV: Use templateName instead of renderTemplate
`renderTemplate` is deprecated and has been removed in Ember 4.0
2022-12-14 11:57:17 +01:00
16 changed files with 93 additions and 110 deletions

View File

@ -0,0 +1,39 @@
<DSection @bodyClass={{this.bodyClass}} @class="container">
<WatchRead @action={{action "markFaqRead"}} @path={{@model.path}}>
<div class="contents clearfix body-page">
<PluginOutlet
@name="above-static"
@tagName="span"
@connectorTagName="div"
/>
{{html-safe @model.html}}
<PluginOutlet
@name="below-static"
@connectorTagName="div"
/>
{{#if this.anyButtons}}
<div class="body-page-button-container">
{{#if this.showSignupButton}}
<DButton
@action={{route-action "showCreateAccount"}}
@class="btn-primary sign-up-button"
@label="sign_up"
/>
{{/if}}
{{#if this.showLoginButton}}
<DButton
@action={{route-action "showLogin"}}
@class="btn-primary login-button"
@icon="user"
@label="log_in"
/>
{{/if}}
</div>
{{/if}}
</div>
</WatchRead>
</DSection>

View File

@ -0,0 +1,28 @@
import Component from "@glimmer/component";
import { action } from "@ember/object";
import { ajax } from "discourse/lib/ajax";
import { equal, or } from "@ember/object/computed";
import { userPath } from "discourse/lib/url";
import { getOwner } from "discourse-common/lib/get-owner";
export default class StaticPage extends Component {
@equal("model.path", "login") showLoginButton;
@or("showLoginButton", "showSignupButton") anyButtons;
get bodyClass() {
return `static-${this.args.model.path}`;
}
get showSignupButton() {
const application = getOwner(this).lookup("controller:application");
return this.args.model.path === "login" && application.canSignUp;
}
@action
async markFaqRead() {
if (this.currentUser) {
await ajax(userPath("read-faq"), { type: "POST" });
this.currentUser.set("read_faq", true);
}
}
}

View File

@ -1,33 +0,0 @@
import Controller, { inject as controller } from "@ember/controller";
import { ajax } from "discourse/lib/ajax";
import discourseComputed from "discourse-common/utils/decorators";
import { equal, or } from "@ember/object/computed";
import { userPath } from "discourse/lib/url";
export default Controller.extend({
application: controller(),
showLoginButton: equal("model.path", "login"),
anyButtons: or("showLoginButton", "showSignupButton"),
@discourseComputed("model.path")
bodyClass: (path) => `static-${path}`,
@discourseComputed("model.path")
showSignupButton() {
return (
this.get("model.path") === "login" && this.get("application.canSignUp")
);
},
actions: {
markFaqRead() {
const currentUser = this.currentUser;
if (currentUser) {
ajax(userPath("read-faq"), { type: "POST" }).then(() => {
currentUser.set("read_faq", true);
});
}
},
},
});

View File

@ -11,9 +11,8 @@ const configs = {
export default function (page) {
return DiscourseRoute.extend({
renderTemplate() {
this.render("static");
},
templateName: "static",
controllerName: "static",
beforeModel(transition) {
const configKey = configs[page];

View File

@ -5,11 +5,7 @@ import { action } from "@ember/object";
export default function (filter) {
return DiscourseRoute.extend({
@action
didTransition() {
this.controllerFor("user-posts")._showFooter();
return true;
},
templateName: "user/posts",
model() {
return this.modelFor("user").get("postsStream");
@ -32,8 +28,10 @@ export default function (filter) {
this.controllerFor("user-posts").set("model", model);
},
renderTemplate() {
this.render("user/posts");
@action
didTransition() {
this.controllerFor("user-posts")._showFooter();
return true;
},
});
}

View File

@ -2,18 +2,11 @@ import DiscourseRoute from "discourse/routes/discourse";
import StaticPage from "discourse/models/static-page";
export default function (pageName) {
const route = {
return DiscourseRoute.extend({
templateName: "static",
model() {
return StaticPage.find(pageName);
},
renderTemplate() {
this.render("static");
},
setupController(controller, model) {
this.controllerFor("static").set("model", model);
},
};
return DiscourseRoute.extend(route);
});
}

View File

@ -1,7 +1,5 @@
import UnknownRoute from "discourse/routes/unknown";
export default UnknownRoute.extend({
renderTemplate() {
this.render("unknown");
},
templateName: "unknown",
});

View File

@ -5,6 +5,7 @@ import { action, get } from "@ember/object";
export function buildGroupPage(type) {
return DiscourseRoute.extend({
type,
templateName: "group-activity-posts",
titleToken() {
return I18n.t(`groups.${type}`);
@ -25,10 +26,6 @@ export function buildGroupPage(type) {
this.controllerFor("application").set("showFooter", loadedAll);
},
renderTemplate() {
this.render("group-activity-posts");
},
@action
didTransition() {
return true;

View File

@ -4,6 +4,8 @@ import DiscourseRoute from "discourse/routes/discourse";
import { Promise } from "rsvp";
export default DiscourseRoute.extend({
templateName: "user_bookmarks",
queryParams: {
acting_username: { refreshModel: true },
q: { refreshModel: true },
@ -46,10 +48,6 @@ export default DiscourseRoute.extend({
.finally(() => controller.set("loading", false));
},
renderTemplate() {
this.render("user_bookmarks");
},
@action
didTransition() {
this.controllerFor("user-activity")._showFooter();

View File

@ -3,6 +3,8 @@ import I18n from "I18n";
import { action } from "@ember/object";
export default DiscourseRoute.extend({
templateName: "user_stream",
model() {
const user = this.modelFor("user");
const draftsStream = user.get("userDraftsStream");
@ -16,10 +18,6 @@ export default DiscourseRoute.extend({
});
},
renderTemplate() {
this.render("user_stream");
},
setupController(controller, model) {
controller.set("model", model);
},

View File

@ -4,6 +4,8 @@ import { action } from "@ember/object";
import I18n from "I18n";
export default DiscourseRoute.extend(ViewingActionType, {
templateName: "user_stream",
queryParams: {
acting_username: { refreshModel: true },
},
@ -29,10 +31,6 @@ export default DiscourseRoute.extend(ViewingActionType, {
});
},
renderTemplate() {
this.render("user_stream");
},
setupController(controller, model) {
controller.set("model", model);
this.viewingActionType(this.userActionType);

View File

@ -4,6 +4,8 @@ import ViewingActionType from "discourse/mixins/viewing-action-type";
import { action } from "@ember/object";
export default DiscourseRoute.extend(ViewingActionType, {
templateName: "user/badges",
model() {
return UserBadge.findByUsername(
this.modelFor("user").get("username_lower"),
@ -16,10 +18,6 @@ export default DiscourseRoute.extend(ViewingActionType, {
controller.set("model", model);
},
renderTemplate() {
this.render("user/badges");
},
@action
didTransition() {
this.controllerFor("application").set("showFooter", true);

View File

@ -2,9 +2,7 @@ import DiscourseRoute from "discourse/routes/discourse";
export default DiscourseRoute.extend({
controllerName: "user-notifications",
renderTemplate() {
this.render("user/notifications-index");
},
templateName: "user/notifications-index",
afterModel(model) {
if (!model) {

View File

@ -4,9 +4,7 @@ import Draft from "discourse/models/draft";
import { action } from "@ember/object";
export default DiscourseRoute.extend({
renderTemplate() {
this.render("user/messages");
},
templateName: "user/messages",
model() {
return this.modelFor("user");

View File

@ -3,9 +3,8 @@ import ViewingActionType from "discourse/mixins/viewing-action-type";
import { setTopicList } from "discourse/lib/topic-list-tracker";
export default DiscourseRoute.extend(ViewingActionType, {
renderTemplate() {
this.render("user-topics-list");
},
templateName: "user-topics-list",
controllerName: "user-topics-list",
setupController(controller, model) {
setTopicList(model);

View File

@ -1,24 +1 @@
<DSection @bodyClass={{this.bodyClass}} @class="container">
<WatchRead @action={{action "markFaqRead"}} @path={{this.model.path}}>
<div class="contents clearfix body-page">
<PluginOutlet @name="above-static" @tagName="span" @connectorTagName="div" />
{{html-safe this.model.html}}
<PluginOutlet @name="below-static" @connectorTagName="div" />
{{#if this.anyButtons}}
<div class="body-page-button-container">
{{#if this.showSignupButton}}
<DButton @action={{route-action "showCreateAccount"}} @class="btn-primary sign-up-button" @label="sign_up" />
{{/if}}
{{#if this.showLoginButton}}
<DButton @action={{route-action "showLogin"}} @class="btn-primary login-button" @icon="user" @label="log_in" />
{{/if}}
</div>
{{/if}}
</div>
</WatchRead>
</DSection>
<StaticPage @model={{this.model}} />