mirror of
https://github.com/flarum/framework.git
synced 2025-06-02 05:23:12 +08:00
Major refactor and improvements
- Reorganised all namespaces and class names for consistency and structure. Following PSR bylaws (Abstract prefix, Interface/Trait suffix). - Move models into root of Core, because writing `use Flarum\Core\Discussion` is nice. Namespace the rest by type. (Namespacing by entity was too arbitrary.) - Moved some non-domain stuff out of Core: Database, Formatter, Settings. - Renamed config table and all references to "settings" for consistency. - Remove Core class and add url()/isInstalled()/inDebugMode() as instance methods of Foundation\Application. - Cleanup, docblocking, etc. - Improvements to HTTP architecture - API and forum/admin Actions are now actually all the same thing (simple PSR-7 Request handlers), renamed to Controllers. - Upgrade to tobscure/json-api 0.2 branch. - Where possible, moved generic functionality to tobscure/json-api (e.g. pagination links). I'm quite happy with the backend balance now re: #262 - Improvements to other architecture - Use Illuminate's Auth\Access\Gate interface/implementation instead of our old Locked trait. We still use events to actually determine the permissions though. Our Policy classes are actually glorified event subscribers. - Extract model validation into Core\Validator classes. - Make post visibility permission stuff much more efficient and DRY. - Renamed Flarum\Event classes for consistency. ref #246 - `Configure` prefix for events dedicated to configuring an object. - `Get` prefix for events whose listeners should return something. - `Prepare` prefix when a variable is passed by reference so it can be modified. - `Scope` prefix when a query builder is passed. - Miscellaneous improvements/bug-fixes. I'm easily distracted! - Increase default height of post composer. - Improve post stream redraw flickering in Safari by keying loading post placeholders with their IDs. ref #451 - Use a PHP JavaScript minification library for minifying TextFormatter's JavaScript, instead of ClosureCompilerService (can't rely on external service!) - Use UrlGenerator properly in various places. closes #123 - Make Api\Client return Response object. closes #128 - Allow extensions to specify custom icon images. - Allow external API/admin URLs to be optionally specified in config.php. If the value or "url" is an array, we look for the corresponding path inside. Otherwise, we append the path to the base URL, using the corresponding value in "paths" if present. closes #244
This commit is contained in:
@ -2,16 +2,16 @@ import Component from 'flarum/Component';
|
||||
import Button from 'flarum/components/Button';
|
||||
import Switch from 'flarum/components/Switch';
|
||||
import EditCustomCssModal from 'flarum/components/EditCustomCssModal';
|
||||
import saveConfig from 'flarum/utils/saveConfig';
|
||||
import saveSettings from 'flarum/utils/saveSettings';
|
||||
|
||||
export default class AppearancePage extends Component {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
|
||||
this.primaryColor = m.prop(app.config.theme_primary_color);
|
||||
this.secondaryColor = m.prop(app.config.theme_secondary_color);
|
||||
this.darkMode = m.prop(app.config.theme_dark_mode === '1');
|
||||
this.coloredHeader = m.prop(app.config.theme_colored_header === '1');
|
||||
this.primaryColor = m.prop(app.settings.theme_primary_color);
|
||||
this.secondaryColor = m.prop(app.settings.theme_secondary_color);
|
||||
this.darkMode = m.prop(app.settings.theme_dark_mode === '1');
|
||||
this.coloredHeader = m.prop(app.settings.theme_colored_header === '1');
|
||||
}
|
||||
|
||||
view() {
|
||||
@ -79,7 +79,7 @@ export default class AppearancePage extends Component {
|
||||
|
||||
this.loading = true;
|
||||
|
||||
saveConfig({
|
||||
saveSettings({
|
||||
theme_primary_color: this.primaryColor(),
|
||||
theme_secondary_color: this.secondaryColor(),
|
||||
theme_dark_mode: this.darkMode(),
|
||||
|
@ -3,7 +3,7 @@ import FieldSet from 'flarum/components/FieldSet';
|
||||
import Select from 'flarum/components/Select';
|
||||
import Button from 'flarum/components/Button';
|
||||
import Alert from 'flarum/components/Alert';
|
||||
import saveConfig from 'flarum/utils/saveConfig';
|
||||
import saveSettings from 'flarum/utils/saveSettings';
|
||||
import ItemList from 'flarum/utils/ItemList';
|
||||
|
||||
export default class BasicsPage extends Component {
|
||||
@ -20,8 +20,8 @@ export default class BasicsPage extends Component {
|
||||
];
|
||||
this.values = {};
|
||||
|
||||
const config = app.config;
|
||||
this.fields.forEach(key => this.values[key] = m.prop(config[key]));
|
||||
const settings = app.settings;
|
||||
this.fields.forEach(key => this.values[key] = m.prop(settings[key]));
|
||||
|
||||
this.localeOptions = {};
|
||||
const locales = app.locales;
|
||||
@ -108,7 +108,7 @@ export default class BasicsPage extends Component {
|
||||
}
|
||||
|
||||
changed() {
|
||||
return this.fields.some(key => this.values[key]() !== app.config[key]);
|
||||
return this.fields.some(key => this.values[key]() !== app.settings[key]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -137,11 +137,11 @@ export default class BasicsPage extends Component {
|
||||
this.loading = true;
|
||||
app.alerts.dismiss(this.successAlert);
|
||||
|
||||
const config = {};
|
||||
const settings = {};
|
||||
|
||||
this.fields.forEach(key => config[key] = this.values[key]());
|
||||
this.fields.forEach(key => settings[key] = this.values[key]());
|
||||
|
||||
saveConfig(config)
|
||||
saveSettings(settings)
|
||||
.then(() => {
|
||||
app.alerts.show(this.successAlert = new Alert({type: 'success', children: 'Your changes were saved.'}));
|
||||
})
|
||||
|
@ -1,12 +1,12 @@
|
||||
import Modal from 'flarum/components/Modal';
|
||||
import Button from 'flarum/components/Button';
|
||||
import saveConfig from 'flarum/utils/saveConfig';
|
||||
import saveSettings from 'flarum/utils/saveSettings';
|
||||
|
||||
export default class EditCustomCssModal extends Modal {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
|
||||
this.customLess = m.prop(app.config.custom_less || '');
|
||||
this.customLess = m.prop(app.settings.custom_less || '');
|
||||
}
|
||||
|
||||
className() {
|
||||
@ -45,7 +45,7 @@ export default class EditCustomCssModal extends Modal {
|
||||
|
||||
this.loading = true;
|
||||
|
||||
saveConfig({
|
||||
saveSettings({
|
||||
custom_less: this.customLess()
|
||||
}).then(() => window.location.reload());
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ export default class ExtensionsPage extends Component {
|
||||
}
|
||||
|
||||
isEnabled(name) {
|
||||
const enabled = JSON.parse(app.config.extensions_enabled);
|
||||
const enabled = JSON.parse(app.settings.extensions_enabled);
|
||||
|
||||
return enabled.indexOf(name) !== -1;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import Component from 'flarum/Component';
|
||||
import PermissionDropdown from 'flarum/components/PermissionDropdown';
|
||||
import ConfigDropdown from 'flarum/components/ConfigDropdown';
|
||||
import SettingDropdown from 'flarum/components/SettingDropdown';
|
||||
import Button from 'flarum/components/Button';
|
||||
import ItemList from 'flarum/utils/ItemList';
|
||||
import icon from 'flarum/helpers/icon';
|
||||
@ -96,7 +96,7 @@ export default class PermissionGrid extends Component {
|
||||
items.add('signUp', {
|
||||
icon: 'user-plus',
|
||||
label: 'Sign up',
|
||||
setting: () => ConfigDropdown.component({
|
||||
setting: () => SettingDropdown.component({
|
||||
key: 'allow_sign_up',
|
||||
options: [
|
||||
{value: '1', label: 'Open'},
|
||||
@ -121,9 +121,9 @@ export default class PermissionGrid extends Component {
|
||||
icon: 'i-cursor',
|
||||
label: 'Allow renaming',
|
||||
setting: () => {
|
||||
const minutes = parseInt(app.config.allow_renaming, 10);
|
||||
const minutes = parseInt(app.settings.allow_renaming, 10);
|
||||
|
||||
return ConfigDropdown.component({
|
||||
return SettingDropdown.component({
|
||||
defaultLabel: minutes ? `For ${minutes} minutes` : 'Indefinitely',
|
||||
key: 'allow_renaming',
|
||||
options: [
|
||||
@ -151,9 +151,9 @@ export default class PermissionGrid extends Component {
|
||||
icon: 'pencil',
|
||||
label: 'Allow post editing',
|
||||
setting: () => {
|
||||
const minutes = parseInt(app.config.allow_post_editing, 10);
|
||||
const minutes = parseInt(app.settings.allow_post_editing, 10);
|
||||
|
||||
return ConfigDropdown.component({
|
||||
return SettingDropdown.component({
|
||||
defaultLabel: minutes ? `For ${minutes} minutes` : 'Indefinitely',
|
||||
key: 'allow_post_editing',
|
||||
options: [
|
||||
|
@ -1,23 +1,23 @@
|
||||
import SelectDropdown from 'flarum/components/SelectDropdown';
|
||||
import Button from 'flarum/components/Button';
|
||||
import saveConfig from 'flarum/utils/saveConfig';
|
||||
import saveSettings from 'flarum/utils/saveSettings';
|
||||
|
||||
export default class ConfigDropdown extends SelectDropdown {
|
||||
export default class SettingDropdown extends SelectDropdown {
|
||||
static initProps(props) {
|
||||
super.initProps(props);
|
||||
|
||||
props.className = 'ConfigDropdown';
|
||||
props.className = 'SettingDropdown';
|
||||
props.buttonClassName = 'Button Button--text';
|
||||
props.caretIcon = 'caret-down';
|
||||
props.defaultLabel = 'Custom';
|
||||
|
||||
props.children = props.options.map(({value, label}) => {
|
||||
const active = app.config[props.key] === value;
|
||||
const active = app.settings[props.key] === value;
|
||||
|
||||
return Button.component({
|
||||
children: label,
|
||||
icon: active ? 'check' : true,
|
||||
onclick: saveConfig.bind(this, {[props.key]: value}),
|
||||
onclick: saveSettings.bind(this, {[props.key]: value}),
|
||||
active
|
||||
});
|
||||
});
|
@ -1,6 +1,6 @@
|
||||
import Modal from 'flarum/components/Modal';
|
||||
import Button from 'flarum/components/Button';
|
||||
import saveConfig from 'flarum/utils/saveConfig';
|
||||
import saveSettings from 'flarum/utils/saveSettings';
|
||||
|
||||
export default class SettingsModal extends Modal {
|
||||
init() {
|
||||
@ -39,7 +39,7 @@ export default class SettingsModal extends Modal {
|
||||
}
|
||||
|
||||
setting(key, fallback = '') {
|
||||
this.settings[key] = this.settings[key] || m.prop(app.config[key] || fallback);
|
||||
this.settings[key] = this.settings[key] || m.prop(app.settings[key] || fallback);
|
||||
|
||||
return this.settings[key];
|
||||
}
|
||||
@ -50,7 +50,7 @@ export default class SettingsModal extends Modal {
|
||||
Object.keys(this.settings).forEach(key => {
|
||||
const value = this.settings[key]();
|
||||
|
||||
if (value !== app.config[key]) {
|
||||
if (value !== app.settings[key]) {
|
||||
dirty[key] = value;
|
||||
}
|
||||
});
|
||||
@ -67,7 +67,7 @@ export default class SettingsModal extends Modal {
|
||||
|
||||
this.loading = true;
|
||||
|
||||
saveConfig(this.dirty()).then(
|
||||
saveSettings(this.dirty()).then(
|
||||
() => this.hide(),
|
||||
() => {
|
||||
this.loading = false;
|
||||
|
Reference in New Issue
Block a user