Skip to content

Commit

Permalink
Beta14 compatability (#10)
Browse files Browse the repository at this point in the history
* beta 14

* Apply fixes from StyleCI

* Update default templates, mark $baseUrl deprecated

* Reword deprecation comment

* Update resources

* typo

* re-work user mention template

* re-work postmention template

* Rework dafult template, new post template

* Update base mailer, use $url

* Check for deprecated content, lint

* Forgot to change search values

* Build dist

Co-authored-by: Charlie <[email protected]>
  • Loading branch information
karaok491 and KyrneDev authored Nov 14, 2020
1 parent e6e7b74 commit d27ff82
Show file tree
Hide file tree
Showing 15 changed files with 369 additions and 352 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"source": "https://github.com/FriendsOfFlarum/pretty-mail"
},
"require": {
"flarum/core": "^0.1.0-beta.10"
"flarum/core": "^0.1.0-beta.14"
},
"replace": {
"reflar/pretty-mail": "*"
Expand Down
6 changes: 3 additions & 3 deletions extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@

namespace FoF\PrettyMail;

use Flarum\Extend as Native;
use Flarum\Extend;
use Flarum\Foundation\Application;

return [
(new Native\Frontend('admin'))
(new Extend\Frontend('admin'))
->js(__DIR__.'/js/dist/admin.js'),
new Native\Locales(__DIR__.'/resources/locale'),
new Extend\Locales(__DIR__.'/resources/locale'),
function (Application $app) {
$app->register(Providers\MailerProvider::class);
},
Expand Down
2 changes: 1 addition & 1 deletion js/dist/admin.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/dist/admin.js.map

Large diffs are not rendered by default.

18 changes: 10 additions & 8 deletions js/src/admin/addSettingsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@ import AdminLinkButton from 'flarum/components/AdminLinkButton';
import SettingsPage from './components/SettingsPage';

export default function() {
app.routes['fof-pretty-mail'] = { path: '/fof/pretty-mail', component: SettingsPage.component() };
app.routes['fof-pretty-mail'] = { path: '/fof/pretty-mail', component: SettingsPage };

app.extensionSettings['fof-pretty-mail'] = () => m.route(app.route('fof-pretty-mail'));
app.extensionSettings['fof-pretty-mail'] = () => m.route.get(app.route('fof-pretty-mail'));

extend(AdminNav.prototype, 'items', items => {
items.add(
'fof-pretty-mail',
AdminLinkButton.component({
href: app.route('fof-pretty-mail'),
icon: 'fas fa-envelope-open',
children: 'Pretty Mail',
description: app.translator.trans('fof-pretty-mail.admin.nav.desc'),
})
AdminLinkButton.component(
{
href: app.route('fof-pretty-mail'),
icon: 'fas fa-envelope-open',
description: app.translator.trans('fof-pretty-mail.admin.nav.desc'),
},
'Pretty Mail'
)
);
});
}
153 changes: 85 additions & 68 deletions js/src/admin/components/SettingsPage.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import Alert from 'flarum/components/Alert';
import Button from 'flarum/components/Button';
import Page from 'flarum/components/Page';
import saveSettings from 'flarum/utils/saveSettings';
import Switch from 'flarum/components/Switch';
import withAttr from 'flarum/utils/withAttr';
import Stream from 'flarum/utils/Stream';

import * as defaults from '../defaults';

export default class SettingsPage extends Page {
init() {
oninit(vnode) {
super.oninit(vnode);
this.fields = ['mailhtml', 'newPost', 'postMentioned', 'userMentioned', 'includeCSS'];

this.values = {};
Expand All @@ -16,7 +18,7 @@ export default class SettingsPage extends Page {

const settings = app.data.settings;

this.fields.forEach(key => (this.values[key] = m.prop(settings[this.addPrefix(key)])));
this.fields.forEach(key => (this.values[key] = Stream(settings[this.addPrefix(key)])));
}

view() {
Expand All @@ -36,22 +38,24 @@ export default class SettingsPage extends Page {
),
m('label', app.translator.trans('fof-pretty-mail.admin.settings.default')),
m('br'),
Button.component({
type: 'button',
style: 'margin-bottom: 10px',
className: 'Button Button--primary',
children: app.translator.trans('fof-pretty-mail.admin.settings.reset'),
onclick: () => {
if (confirm(app.translator.trans('fof-pretty-mail.admin.settings.confirm') + ' default?')) {
this.values.mailhtml(defaults.mailto);
}
Button.component(
{
type: 'button',
style: 'margin-bottom: 10px',
className: 'Button Button--primary',
onclick: () => {
if (confirm(app.translator.trans('fof-pretty-mail.admin.settings.confirm') + ' default?')) {
this.values.mailhtml(defaults.mailto);
}
},
},
}),
app.translator.trans('fof-pretty-mail.admin.settings.reset')
),
m('textarea.FormControl', {
rows: '15',
value: this.values.mailhtml(),
style: 'margin: 10px 0 10px',
oninput: m.withAttr('value', this.values.mailhtml),
oninput: withAttr('value', this.values.mailhtml),
}),
m('h3', app.translator.trans('fof-pretty-mail.admin.settings.notifications')),
m(
Expand All @@ -64,60 +68,66 @@ export default class SettingsPage extends Page {
),
m('label', app.translator.trans('fof-pretty-mail.admin.settings.newPost')),
m('br'),
Button.component({
type: 'button',
style: 'margin: 10px 0 10px',
className: 'Button Button--primary',
children: app.translator.trans('fof-pretty-mail.admin.settings.reset'),
onclick: () => {
if (confirm(app.translator.trans('fof-pretty-mail.admin.settings.confirm') + ' newPost?')) {
this.values.newPost(defaults.newPost);
}
Button.component(
{
type: 'button',
style: 'margin: 10px 0 10px',
className: 'Button Button--primary',
onclick: () => {
if (confirm(app.translator.trans('fof-pretty-mail.admin.settings.confirm') + ' newPost?')) {
this.values.newPost(defaults.newPost);
}
},
},
}),
app.translator.trans('fof-pretty-mail.admin.settings.reset')
),
m('textarea.FormControl', {
rows: '15',
value: this.values.newPost(),
style: 'margin-bottom: 10px',
oninput: m.withAttr('value', this.values.newPost),
oninput: withAttr('value', this.values.newPost),
}),
m('label', app.translator.trans('fof-pretty-mail.admin.settings.userMentioned')),
m('br'),
Button.component({
type: 'button',
style: 'margin: 10px 0 10px',
className: 'Button Button--primary',
children: app.translator.trans('fof-pretty-mail.admin.settings.reset'),
onclick: () => {
if (confirm(app.translator.trans('fof-pretty-mail.admin.settings.confirm') + ' userMentioned?')) {
this.values.userMentioned(defaults.userMentioned);
}
Button.component(
{
type: 'button',
style: 'margin: 10px 0 10px',
className: 'Button Button--primary',
onclick: () => {
if (confirm(app.translator.trans('fof-pretty-mail.admin.settings.confirm') + ' userMentioned?')) {
this.values.userMentioned(defaults.userMentioned);
}
},
},
}),
app.translator.trans('fof-pretty-mail.admin.settings.reset')
),
m('textarea.FormControl', {
rows: '15',
value: this.values.userMentioned(),
style: 'margin-bottom: 10px',
oninput: m.withAttr('value', this.values.userMentioned),
oninput: withAttr('value', this.values.userMentioned),
}),
m('label', app.translator.trans('fof-pretty-mail.admin.settings.postMentioned')),
m('br'),
Button.component({
type: 'button',
style: 'margin: 10px 0 10px',
className: 'Button Button--primary',
children: app.translator.trans('fof-pretty-mail.admin.settings.reset'),
onclick: () => {
if (confirm(app.translator.trans('fof-pretty-mail.admin.settings.confirm') + ' postMentioned?')) {
this.values.postMentioned(defaults.postMentioned);
}
Button.component(
{
type: 'button',
style: 'margin: 10px 0 10px',
className: 'Button Button--primary',
onclick: () => {
if (confirm(app.translator.trans('fof-pretty-mail.admin.settings.confirm') + ' postMentioned?')) {
this.values.postMentioned(defaults.postMentioned);
}
},
},
}),
app.translator.trans('fof-pretty-mail.admin.settings.reset')
),
m('textarea.FormControl', {
rows: '15',
value: this.values.postMentioned(),
style: 'margin-bottom: 10px',
oninput: m.withAttr('value', this.values.postMentioned),
oninput: withAttr('value', this.values.postMentioned),
}),
m('h1', app.translator.trans('fof-pretty-mail.admin.css_settings.label')),
m(
Expand All @@ -128,19 +138,23 @@ export default class SettingsPage extends Page {
},
app.translator.trans('fof-pretty-mail.admin.css_settings.help', { strong: <strong /> })
),
Switch.component({
className: 'Form-group',
state: this.values.includeCSS() === '1',
onchange: enabled => this.values.includeCSS(enabled ? '1' : '0'),
children: app.translator.trans('fof-pretty-mail.admin.css_settings.switch_label'),
}),
Button.component({
type: 'submit',
className: 'Button Button--primary',
children: app.translator.trans('core.admin.settings.submit_button'),
loading: this.loading,
disabled: !this.changed(),
}),
Switch.component(
{
className: 'Form-group',
state: this.values.includeCSS() === '1',
onchange: enabled => this.values.includeCSS(enabled ? '1' : '0'),
},
app.translator.trans('fof-pretty-mail.admin.css_settings.switch_label')
),
Button.component(
{
type: 'submit',
className: 'Button Button--primary',
loading: this.loading,
disabled: !this.changed(),
},
app.translator.trans('core.admin.settings.submit_button')
),
]),
]),
]),
Expand All @@ -161,25 +175,19 @@ export default class SettingsPage extends Page {
*/
onsubmit(e) {
e.preventDefault();
this.fields.forEach(key => this.checkContent(key));

if (this.loading) return;

this.loading = true;

app.alerts.dismiss(this.successAlert);

const settings = {};

this.fields.forEach(key => (settings[this.addPrefix(key)] = this.values[key]()));

saveSettings(settings).then(() => {
this.loading = false;
app.alerts.show(
(this.successAlert = new Alert({
type: 'success',
children: app.translator.trans('core.admin.basics.saved_message'),
}))
);
app.alerts.show({ type: 'success' }, app.translator.trans('core.admin.basics.saved_message'));
});
}

Expand All @@ -189,4 +197,13 @@ export default class SettingsPage extends Page {
addPrefix(key) {
return this.settingsPrefix + '.' + key;
}

checkContent(key) {
if (this.values[key]().includes('$baseUrl')) {
app.alerts.show({ type: 'warning' }, key + ": The use of $baseUrl is deprecated. Use $url->to('forum')->base() instead.");
}
if (this.values[key]().includes('app()->url()')) {
app.alerts.show({ type: 'error' }, key + ": app()->url() has been replaced. Use $url->to('forum')->base() instead.");
}
}
}
Loading

0 comments on commit d27ff82

Please sign in to comment.