Skip to content

Commit

Permalink
Update for Flarum beta 14
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkwinkelmann committed Nov 8, 2020
1 parent e326999 commit 286e964
Show file tree
Hide file tree
Showing 44 changed files with 852 additions and 909 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"source": "https://github.com/FriendsOfFlarum/mason"
},
"require": {
"flarum/core": ">=0.1.0-beta.8 <0.1.0-beta.14"
"flarum/core": ">=0.1.0-beta.14 <0.1.0-beta.15"
},
"replace": {
"flagrow/mason": "*"
Expand Down
20 changes: 15 additions & 5 deletions extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

namespace FoF\Mason;

use Flarum\Discussion\Discussion;
use Flarum\Extend;

return [
(new Extend\Frontend('forum'))
->css(__DIR__.'/resources/less/forum.less')
->js(__DIR__.'/js/dist/forum.js'),
->css(__DIR__ . '/resources/less/forum.less')
->js(__DIR__ . '/js/dist/forum.js'),
(new Extend\Frontend('admin'))
->css(__DIR__.'/resources/less/admin.less')
->js(__DIR__.'/js/dist/admin.js'),
->css(__DIR__ . '/resources/less/admin.less')
->js(__DIR__ . '/js/dist/admin.js'),
(new Extend\Routes('api'))
// Fields
->post('/fof/mason/fields/order', 'fof-mason.api.fields.order', Api\Controllers\FieldOrderController::class)
Expand All @@ -24,7 +25,16 @@
->post('/fof/mason/fields/{id:[0-9]+}/answers', 'fof-mason.api.answers.create', Api\Controllers\AnswerStoreController::class)
->patch('/fof/mason/answers/{id:[0-9]+}', 'fof-mason.api.answers.update', Api\Controllers\AnswerUpdateController::class)
->delete('/fof/mason/answers/{id:[0-9]+}', 'fof-mason.api.answers.delete', Api\Controllers\AnswerDeleteController::class),
(new Extend\Locales(__DIR__.'/resources/locale')),
(new Extend\Locales(__DIR__ . '/resources/locale')),
(new Extend\Model(Discussion::class))
->relationship('masonAnswers', function (Discussion $discussion) {
return $discussion->belongsToMany(Answer::class, 'fof_mason_discussion_answer', 'discussion_id', 'answer_id')
->withTimestamps()
->whereHas('field', function ($query) {
// Only load answers to fields that have not been deleted
$query->whereNull('deleted_at');
});
}),
new Extenders\ForumAttributes,
new Extenders\DiscussionAttributes,
new Extenders\Policies,
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.

2 changes: 1 addition & 1 deletion js/dist/forum.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

1,062 changes: 536 additions & 526 deletions js/package-lock.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,23 @@ import {extend} from 'flarum/extend';
import app from 'flarum/app';
import AdminNav from 'flarum/components/AdminNav';
import AdminLinkButton from 'flarum/components/AdminLinkButton';
import MasonFieldsPane from './panes/MasonFieldsPane';
import MasonFieldsPage from './pages/MasonFieldsPage';

/* global m */

export default function () {
// create the route
app.routes['fof-mason-page'] = {
path: '/mason',
component: MasonFieldsPane.component(),
component: MasonFieldsPage,
};

// bind the route we created to the three dots settings button
app.extensionSettings['fof-mason'] = () => m.route(app.route('fof-mason-page'));
app.extensionSettings['fof-mason'] = () => m.route.set(app.route('fof-mason-page'));

extend(AdminNav.prototype, 'items', items => {
// add the Image Upload tab to the admin navigation menu
items.add('fof-mason', AdminLinkButton.component({
href: app.route('fof-mason-page'),
icon: 'fas fa-dungeon',
children: 'Mason',
description: app.translator.trans('fof-mason.admin.menu.description'),
}));
}, app.translator.trans('fof-mason.admin.menu.title')));
});
}
25 changes: 12 additions & 13 deletions js/src/admin/components/AnswerEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@ import Component from 'flarum/Component';
import Button from 'flarum/components/Button';
import Switch from 'flarum/components/Switch';

/* global m */

export default class FieldEdit extends Component {
init() {
this.answer = this.props.answer;
oninit(vnode) {
super.oninit(vnode);

this.answer = this.attrs.answer;
this.dirty = false;
this.processing = false;
}

view() {
return m('form.Mason-Box', [
return m('.Mason-Box', [
// Only suggested answers can be reordered
(this.answer.is_suggested() ? [
m('span.fas.fa-arrows-alt.Mason-Box--handle.js-answer-handle'),
Expand Down Expand Up @@ -42,24 +46,19 @@ export default class FieldEdit extends Component {
// And the unsaved state won't be preserved because the AnswerEdit component changes its place
this.saveAnswer();
},
children: app.translator.trans('fof-mason.admin.fields.is_suggested'),
}),
}, app.translator.trans('fof-mason.admin.fields.is_suggested')),
m('.ButtonGroup', [
Button.component({
type: 'submit',
className: 'Button Button--primary',
children: app.translator.trans('fof-mason.admin.buttons.save-answer'),
loading: this.processing,
disabled: !this.readyToSave(),
onclick: this.saveAnswer.bind(this),
}),
}, app.translator.trans('fof-mason.admin.buttons.save-answer')),
Button.component({
type: 'submit',
className: 'Button Button--danger',
children: app.translator.trans('fof-mason.admin.buttons.delete-answer'),
loading: this.processing,
onclick: this.deleteAnswer.bind(this),
}),
}, app.translator.trans('fof-mason.admin.buttons.delete-answer')),
]),
]);
}
Expand Down Expand Up @@ -93,8 +92,8 @@ export default class FieldEdit extends Component {

deleteAnswer() {
if (!confirm(extractText(app.translator.trans('fof-mason.admin.messages.delete-answer-confirmation', {
content: this.answer.content(),
})))) {
content: this.answer.content(),
})))) {
return;
}

Expand Down
71 changes: 44 additions & 27 deletions js/src/admin/components/FieldAnswersEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,27 @@ import Button from 'flarum/components/Button';
import AnswerEdit from './AnswerEdit';
import sortByAttribute from './../../lib/helpers/sortByAttribute';

/* global m, $ */

export default class FieldAnswersEdit extends Component {
init() {
this.field = this.props.field;
oninit(vnode) {
super.oninit(vnode);

this.field = this.attrs.field;
this.processing = false;
this.new_content = '';
this.showUserAnswers = false;
}

config() {
sortable(this.element.querySelector('.js-answers-container'), {
configSortable() {
const container = this.element.querySelector('.js-answers-container');

// If the field doesn't exist, it doesn't have a field edit area
if (!container) {
return;
}

sortable(container, {
handle: '.js-answer-handle',
})[0].addEventListener('sortupdate', () => {
const sorting = this.$('.js-answer-data')
Expand All @@ -29,6 +40,16 @@ export default class FieldAnswersEdit extends Component {
});
}

oncreate(vnode) {
super.oncreate(vnode);

this.configSortable();
}

onupdate() {
this.configSortable();
}

view() {
if (!this.field.exists) {
return m('div', app.translator.trans('fof-mason.admin.fields.save-field-for-answers'));
Expand Down Expand Up @@ -83,27 +104,23 @@ export default class FieldAnswersEdit extends Component {
}))
)) : null),
] : null),
m('form', [
m('.Form-group', [
m('label', app.translator.trans('fof-mason.admin.fields.new-answer')),
m('input.FormControl', {
value: this.new_content,
oninput: m.withAttr('value', value => {
this.new_content = value;
}),
placeholder: app.translator.trans('fof-mason.admin.fields.new-answer-placeholder'),
}),
]),
m('.Form-group', [
Button.component({
type: 'submit',
className: 'Button Button--primary',
children: app.translator.trans('fof-mason.admin.buttons.add-answer'),
loading: this.processing,
disabled: !this.new_content,
onclick: this.saveField.bind(this),
}),
]),
m('.Form-group', [
m('label', app.translator.trans('fof-mason.admin.fields.new-answer')),
m('input.FormControl', {
value: this.new_content,
oninput: event => {
this.new_content = event.target.value;
},
placeholder: app.translator.trans('fof-mason.admin.fields.new-answer-placeholder'),
}),
]),
m('.Form-group', [
Button.component({
className: 'Button Button--primary',
loading: this.processing,
disabled: !this.new_content,
onclick: this.saveField.bind(this),
}, app.translator.trans('fof-mason.admin.buttons.add-answer')),
]),
]);
}
Expand All @@ -114,7 +131,7 @@ export default class FieldAnswersEdit extends Component {
app.request({
method: 'POST',
url: app.forum.attribute('apiUrl') + this.field.apiEndpoint() + '/answers',
data: {
body: {
data: {
attributes: {
content: this.new_content,
Expand All @@ -135,7 +152,7 @@ export default class FieldAnswersEdit extends Component {
app.request({
method: 'POST',
url: app.forum.attribute('apiUrl') + this.field.apiEndpoint() + '/answers/order',
data: {
body: {
sort: sorting,
},
}).then(result => {
Expand Down
Loading

0 comments on commit 286e964

Please sign in to comment.