Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit ce20ae8
Author: StyleCI Bot <bot@styleci.io>
Date:   Thu Feb 15 12:19:33 2024 +0000

    Apply fixes from StyleCI

commit f2e6f32
Author: IanM <ian@morland.me>
Date:   Thu Feb 15 12:19:14 2024 +0000

    feat: optional poll subtitle

commit 69b47f9
Author: IanM <ian@morland.me>
Date:   Thu Feb 1 09:25:46 2024 +0000

    add isGlobal peroperty to js model

commit d130f6b
Author: IanM <ian@morland.me>
Date:   Thu Feb 1 09:21:04 2024 +0000

    list polls only shows global polls

commit 0a4dcf4
Author: IanM <ian@morland.me>
Date:   Wed Jan 31 16:49:15 2024 +0000

    add unauthorized api test

commit 6e52663
Author: IanM <ian@morland.me>
Date:   Wed Jan 31 16:45:33 2024 +0000

    fix: phpstan error

commit a322750
Author: StyleCI Bot <bot@styleci.io>
Date:   Wed Jan 31 16:42:20 2024 +0000

    Apply fixes from StyleCI

commit c8e60a0
Author: IanM <ian@morland.me>
Date:   Wed Jan 31 16:42:10 2024 +0000

    feat: allow creation of polls without post id (global poll)

commit 7abeebe
Author: IanM <ian@morland.me>
Date:   Wed Jan 31 11:49:25 2024 +0000

    ensure poll is associated with postId

commit 20b5917
Author: StyleCI Bot <bot@styleci.io>
Date:   Wed Jan 31 11:45:37 2024 +0000

    Apply fixes from StyleCI

commit fa69a3c
Author: IanM <ian@morland.me>
Date:   Wed Jan 31 11:45:24 2024 +0000

    test: create post poll via api

commit 97d6348
Author: IanM <ian@morland.me>
Date:   Wed Jan 31 08:34:08 2024 +0000

    fix: provider visibility

commit 03d355f
Author: IanM <ian@morland.me>
Date:   Wed Jan 31 08:32:26 2024 +0000

    fix: provider visibility

commit 325cc32
Author: StyleCI Bot <bot@styleci.io>
Date:   Wed Jan 31 08:30:15 2024 +0000

    Apply fixes from StyleCI

commit 822ddbf
Author: IanM <ian@morland.me>
Date:   Wed Jan 31 08:29:56 2024 +0000

    chore: add test for existing create poll functionality via posts

commit 4799bba
Author: StyleCI Bot <bot@styleci.io>
Date:   Tue Jan 30 14:37:24 2024 +0000

    Apply fixes from StyleCI

commit 4d197f3
Author: IanM <ian@morland.me>
Date:   Tue Jan 30 14:37:13 2024 +0000

    use sort

commit f897796
Author: IanM <ian@morland.me>
Date:   Tue Jan 30 14:26:03 2024 +0000

    chore: ts-ignore

commit f1e00db
Author: IanM <ian@morland.me>
Date:   Tue Jan 30 14:22:36 2024 +0000

    fix: return type

commit d56bf39
Author: StyleCI Bot <bot@styleci.io>
Date:   Tue Jan 30 14:18:49 2024 +0000

    Apply fixes from StyleCI

commit d49c1f9
Author: IanM <ian@morland.me>
Date:   Tue Jan 30 14:18:37 2024 +0000

    feat: list polls controller

commit 8fb8cc6
Author: IanM <ian@morland.me>
Date:   Tue Jan 30 14:18:13 2024 +0000

    chore: format

commit ee37ee6
Author: IanM <ian@morland.me>
Date:   Tue Jan 30 14:15:49 2024 +0000

    fix: some model props incorrect

commit 1857a44
Author: StyleCI Bot <bot@styleci.io>
Date:   Tue Jan 30 08:16:56 2024 +0000

    Apply fixes from StyleCI

commit 4b461a5
Author: IanM <ian@morland.me>
Date:   Tue Jan 30 08:16:27 2024 +0000

    wip: add polls route, begin to setup state, controls, etc

commit adf5393
Author: IanM <ian@morland.me>
Date:   Mon Jan 29 16:22:08 2024 +0000

    add nav item

commit d4032dc
Author: IanM <ian@morland.me>
Date:   Mon Jan 29 16:09:52 2024 +0000

    chore: ts

commit 7365c67
Author: IanM <16573496+imorland@users.noreply.github.com>
Date:   Mon Jan 29 14:01:09 2024 +0000

    chore: add tests for forum serializer props (#85)

    * chore: forum serializer test

    * Apply fixes from StyleCI

    ---------

    Co-authored-by: StyleCI Bot <bot@styleci.io>

commit f460073
Author: IanM <16573496+imorland@users.noreply.github.com>
Date:   Mon Jan 29 11:46:12 2024 +0000

    chore: cleanup extend, create serializer mutators (#84)

    * chore: cleanup extend, create serializer mutators

    * Apply fixes from StyleCI

    ---------

    Co-authored-by: StyleCI Bot <bot@styleci.io>

commit 9acbd74
Author: IanM <ian@morland.me>
Date:   Mon Jan 29 11:10:32 2024 +0000

    Chore: include discuss link

commit a2af115
Author: IanM <ian@morland.me>
Date:   Mon Jan 29 11:00:51 2024 +0000

    chore: use 1.x workflows
  • Loading branch information
DavideIadeluca committed Feb 19, 2024
1 parent 3dd4843 commit 313ebfc
Show file tree
Hide file tree
Showing 14 changed files with 279 additions and 92 deletions.
13 changes: 13 additions & 0 deletions js/src/forum/components/CreatePollModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default class CreatePollModal extends Modal {
this.optionImageUrls = [Stream(''), Stream('')];

this.question = Stream('');
this.subtitle = Stream('');

this.endDate = Stream();

Expand All @@ -38,6 +39,7 @@ export default class CreatePollModal extends Modal {
});

this.question(poll.question);
this.subtitle(poll.subtitle);
this.publicPoll(poll.publicPoll);
this.hideVotes(poll.hideVotes);
this.allowChangeVote(poll.allowChangeVote);
Expand Down Expand Up @@ -82,6 +84,16 @@ export default class CreatePollModal extends Modal {
100
);

items.add(
'subtitle',
<div className="Form-group">
<label className="label">{app.translator.trans('fof-polls.forum.modal.subtitle_placeholder')}</label>

<input type="text" name="subtitle" className="FormControl" bidi={this.subtitle} />
</div>,
95
);

items.add(
'answers',
<div className="PollModal--answers Form-group">
Expand Down Expand Up @@ -266,6 +278,7 @@ export default class CreatePollModal extends Modal {
data() {
const poll = {
question: this.question(),
subtitle: this.subtitle(),
endDate: this.dateToTimestamp(this.endDate()),
publicPoll: this.publicPoll(),
hideVotes: this.hideVotes(),
Expand Down
2 changes: 2 additions & 0 deletions js/src/forum/components/EditPollModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default class EditPollModal extends CreatePollModal {
this.optionAnswers = this.options.map((o) => Stream(o.answer()));
this.optionImageUrls = this.options.map((o) => Stream(o.imageUrl()));
this.question = Stream(this.poll.question());
this.subtitle = Stream(this.poll.subtitle());
this.endDate = Stream(this.formatDate(this.poll.endDate()));
this.publicPoll = Stream(this.poll.publicPoll());
this.allowMultipleVotes = Stream(this.poll.allowMultipleVotes());
Expand Down Expand Up @@ -95,6 +96,7 @@ export default class EditPollModal extends CreatePollModal {

return {
question: this.question(),
subtitle: this.subtitle(),
endDate: this.dateToTimestamp(this.endDate()),
publicPoll: this.publicPoll(),
hideVotes: this.hideVotes(),
Expand Down
129 changes: 63 additions & 66 deletions js/src/forum/components/PollsDirectory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import Select from 'flarum/common/components/Select';
import Button from 'flarum/common/components/Button';
import Mithril from 'mithril';

import PollList from './Poll/PollList';

export default class PollsDirectory extends Page {
oncreate(vnode: Mithril.Vnode) {
super.oncreate(vnode);
Expand All @@ -34,7 +32,6 @@ export default class PollsDirectory extends Page {
<ul className="IndexPage-toolbar-action">{listItems(this.actionItems().toArray())}</ul>
</div>
{/* <UserDirectoryList state={this.state} /> */}
<PollList />
</div>
</div>
</div>
Expand Down Expand Up @@ -85,67 +82,67 @@ export default class PollsDirectory extends Page {
return items;
}

// stickyParams() {
// return {
// sort: m.route.param('sort'),
// q: m.route.param('q'),
// };
// }

// changeParams(sort: string) {
// const params = this.params();

// if (sort === app.forum.attribute('pollsDirectoryDefaultSort')) {
// delete params.sort;
// } else {
// params.sort = sort;
// }

// this.state.refreshParams(params);

// const routeParams = { ...params };
// delete routeParams.qBuilder;

// m.route.set(app.route('fof_polls_directory', routeParams));
// }

// viewItems() {
// const items = new ItemList();
// const sortMap = this.state.sortMap();

// const sortOptions = {};
// for (const i in sortMap) {
// sortOptions[i] = app.translator.trans('fof-polls.lib.sort.' + i);
// }

// items.add(
// 'sort',
// Select.component({
// options: sortOptions,
// value: this.state.getParams().sort || app.forum.attribute('pollsDirectoryDefaultSort'),
// onchange: this.changeParams.bind(this),
// }),
// 100
// );

// return items;
// }

// actionItems(): ItemList<Mithril.Children> {
// const items = new ItemList<Mithril.Children>();

// items.add(
// 'refresh',
// Button.component({
// title: app.translator.trans('fof-polls.forum.page.refresh_tooltip'),
// icon: 'fas fa-sync',
// className: 'Button Button--icon',
// onclick: () => {
// this.state.refresh();
// },
// })
// );

// return items;
// }
stickyParams() {
return {
sort: m.route.param('sort'),
q: m.route.param('q'),
};
}

changeParams(sort: string) {
const params = this.params();

if (sort === app.forum.attribute('pollsDirectoryDefaultSort')) {
delete params.sort;
} else {
params.sort = sort;
}

this.state.refreshParams(params);

const routeParams = { ...params };
delete routeParams.qBuilder;

m.route.set(app.route('fof_polls_directory', routeParams));
}

viewItems() {
const items = new ItemList();
const sortMap = this.state.sortMap();

const sortOptions = {};
for (const i in sortMap) {
sortOptions[i] = app.translator.trans('fof-polls.lib.sort.' + i);
}

items.add(
'sort',
Select.component({
options: sortOptions,
value: this.state.getParams().sort || app.forum.attribute('pollsDirectoryDefaultSort'),
onchange: this.changeParams.bind(this),
}),
100
);

return items;
}

actionItems(): ItemList<Mithril.Children> {
const items = new ItemList<Mithril.Children>();

items.add(
'refresh',
Button.component({
title: app.translator.trans('fof-polls.forum.page.refresh_tooltip'),
icon: 'fas fa-sync',
className: 'Button Button--icon',
onclick: () => {
this.state.refresh();
},
})
);

return items;
}
}
41 changes: 23 additions & 18 deletions js/src/forum/components/PostPoll.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,29 @@ export default class PostPoll extends Component {
return (
<div className="Post-poll" data-id={poll.id()}>
<div className="PollHeading">
<h3 className="PollHeading-title">{poll.question()}</h3>

{poll.canSeeVoters() && (
<Tooltip text={app.translator.trans('fof-polls.forum.public_poll')}>
<Button className="Button PollHeading-voters" onclick={this.showVoters.bind(this)} icon="fas fa-poll" />
</Tooltip>
)}

{poll.canEdit() && (
<Tooltip text={app.translator.trans('fof-polls.forum.moderation.edit')}>
<Button className="Button PollHeading-edit" onclick={app.modal.show.bind(app.modal, EditPollModal, { poll })} icon="fas fa-pen" />
</Tooltip>
)}
{poll.canDelete() && (
<Tooltip text={app.translator.trans('fof-polls.forum.moderation.delete')}>
<Button className="Button PollHeading-delete" onclick={this.deletePoll.bind(this)} icon="fas fa-trash" />
</Tooltip>
)}
<div className="PollHeading-title-container">
<h3 className="PollHeading-title">{poll.question()}</h3>
{poll.subtitle() && <p className="helpText PollHeading-subtitle">{poll.subtitle()}</p>}
</div>

<div className="PollHeading-actions">
{poll.canSeeVoters() && (
<Tooltip text={app.translator.trans('fof-polls.forum.public_poll')}>
<Button className="Button PollHeading-voters" onclick={this.showVoters.bind(this)} icon="fas fa-poll" />
</Tooltip>
)}

{poll.canEdit() && (
<Tooltip text={app.translator.trans('fof-polls.forum.moderation.edit')}>
<Button className="Button PollHeading-edit" onclick={app.modal.show.bind(app.modal, EditPollModal, { poll })} icon="fas fa-pen" />
</Tooltip>
)}
{poll.canDelete() && (
<Tooltip text={app.translator.trans('fof-polls.forum.moderation.delete')}>
<Button className="Button PollHeading-delete" onclick={this.deletePoll.bind(this)} icon="fas fa-trash" />
</Tooltip>
)}
</div>
</div>

<div>
Expand Down
4 changes: 4 additions & 0 deletions js/src/forum/models/Poll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ export default class Poll extends Model {
return Model.attribute<string>('question').call(this);
}

subtitle() {
return Model.attribute<string | null>('subtitle').call(this);
}

hasEnded() {
return Model.attribute<boolean>('hasEnded').call(this);
}
Expand Down
26 changes: 26 additions & 0 deletions migrations/2024_02_15_000000_modify_polls_add_subtitle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/*
* This file is part of fof/polls.
*
* Copyright (c) FriendsOfFlarum.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;

return [
'up' => function (Builder $schema) {
$schema->table('polls', function (Blueprint $table) {
$table->text('subtitle')->nullable()->after('question');
});
},
'down' => function (Builder $schema) {
$schema->table('polls', function (Blueprint $table) {
$table->dropColumn('subtitle');
});
},
];
6 changes: 5 additions & 1 deletion resources/less/forum.less
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,18 @@
align-items: baseline;
gap: 10px;

&-title {
&-title-container {
flex-grow: 1;
}

&-voters {
.Button--color-auto("button-primary");
}

&-actions {

}

.Button {
flex-shrink: 1;
padding: 6px 10px;
Expand Down
1 change: 1 addition & 0 deletions resources/locale/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ fof-polls:
hide_votes_label: Hide votes until poll ends
allow_change_vote_label: Allow users to change their vote
question_placeholder: Question
subtitle_placeholder: Subtitle/Description (Optional)
submit: Submit

moderation:
Expand Down
5 changes: 4 additions & 1 deletion src/Api/AddPostAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@

namespace FoF\Polls\Api;

use Flarum\Api\Serializer\PostSerializer;
use Flarum\Post\Post;

class AddPostAttributes
{
public function __invoke($serializer, $post, $attributes)
public function __invoke(PostSerializer $serializer, Post $post, array $attributes): array
{
$attributes['canStartPoll'] = $serializer->getActor()->can('startPoll', $post);

Expand Down
1 change: 1 addition & 0 deletions src/Api/Serializers/PollSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ protected function getDefaultAttributes($poll)

$attributes = [
'question' => $poll->question,
'subtitle' => $poll->subtitle,
'hasEnded' => $poll->hasEnded(),
'allowMultipleVotes' => $poll->allow_multiple_votes,
'maxVotes' => $poll->max_votes,
Expand Down
1 change: 1 addition & 0 deletions src/Commands/CreatePollHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public function handle(CreatePoll $command)
Arr::get($attributes, 'maxVotes'),
Arr::get($attributes, 'hideVotes'),
Arr::get($attributes, 'allowChangeVote'),
Arr::get($attributes, 'subtitle')
);

$this->events->dispatch(new SavingPollAttributes($command->actor, $poll, $attributes, $attributes));
Expand Down
4 changes: 4 additions & 0 deletions src/Commands/EditPollHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public function handle(EditPoll $command)
$poll->question = $attributes['question'];
}

if (isset($attributes['subtitle'])) {
$poll->subtitle = empty($attributes['subtitle']) ? null : $attributes['subtitle'];
}

foreach (['publicPoll', 'allowMultipleVotes', 'hideVotes', 'allowChangeVote'] as $key) {
if (isset($attributes[$key])) {
$poll->settings[Str::snake($key)] = (bool) $attributes[$key];
Expand Down
10 changes: 6 additions & 4 deletions src/Poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
use Illuminate\Support\Arr;

/**
* @property int $id
* @property string $question
* @property int $id
* @property string $question
* @property string|null $subtitle
* @property-read bool $public_poll
* @property-read bool $allow_multiple_votes
* @property-read int $max_votes
Expand All @@ -30,7 +31,7 @@
* @property int $vote_count
* @property Post $post
* @property User $user
* @property int $post_id
* @property int|null $post_id
* @property int $user_id
* @property \Carbon\Carbon|null $end_date
* @property \Carbon\Carbon $created_at
Expand Down Expand Up @@ -66,11 +67,12 @@ class Poll extends AbstractModel
*
* @return static
*/
public static function build($question, $postId, $actorId, $endDate, $publicPoll, $allowMultipleVotes = false, $maxVotes = 0, $hideVotes = false, $allowChangeVote = true)
public static function build($question, $postId, $actorId, $endDate, $publicPoll, $allowMultipleVotes = false, $maxVotes = 0, $hideVotes = false, $allowChangeVote = true, $subtitle = null)
{
$poll = new static();

$poll->question = $question;
$poll->subtitle = $subtitle;
$poll->post_id = $postId;
$poll->user_id = $actorId;
$poll->end_date = $endDate;
Expand Down
Loading

0 comments on commit 313ebfc

Please sign in to comment.