Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 69b47f9
Author: IanM <[email protected]>
Date:   Thu Feb 1 09:25:46 2024 +0000

    add isGlobal peroperty to js model

commit d130f6b
Author: IanM <[email protected]>
Date:   Thu Feb 1 09:21:04 2024 +0000

    list polls only shows global polls

commit 0a4dcf4
Author: IanM <[email protected]>
Date:   Wed Jan 31 16:49:15 2024 +0000

    add unauthorized api test

commit 6e52663
Author: IanM <[email protected]>
Date:   Wed Jan 31 16:45:33 2024 +0000

    fix: phpstan error

commit a322750
Author: StyleCI Bot <[email protected]>
Date:   Wed Jan 31 16:42:20 2024 +0000

    Apply fixes from StyleCI

commit c8e60a0
Author: IanM <[email protected]>
Date:   Wed Jan 31 16:42:10 2024 +0000

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

commit 7abeebe
Author: IanM <[email protected]>
Date:   Wed Jan 31 11:49:25 2024 +0000

    ensure poll is associated with postId

commit 20b5917
Author: StyleCI Bot <[email protected]>
Date:   Wed Jan 31 11:45:37 2024 +0000

    Apply fixes from StyleCI

commit fa69a3c
Author: IanM <[email protected]>
Date:   Wed Jan 31 11:45:24 2024 +0000

    test: create post poll via api

commit 97d6348
Author: IanM <[email protected]>
Date:   Wed Jan 31 08:34:08 2024 +0000

    fix: provider visibility

commit 03d355f
Author: IanM <[email protected]>
Date:   Wed Jan 31 08:32:26 2024 +0000

    fix: provider visibility

commit 325cc32
Author: StyleCI Bot <[email protected]>
Date:   Wed Jan 31 08:30:15 2024 +0000

    Apply fixes from StyleCI

commit 822ddbf
Author: IanM <[email protected]>
Date:   Wed Jan 31 08:29:56 2024 +0000

    chore: add test for existing create poll functionality via posts

commit 4799bba
Author: StyleCI Bot <[email protected]>
Date:   Tue Jan 30 14:37:24 2024 +0000

    Apply fixes from StyleCI

commit 4d197f3
Author: IanM <[email protected]>
Date:   Tue Jan 30 14:37:13 2024 +0000

    use sort

commit f897796
Author: IanM <[email protected]>
Date:   Tue Jan 30 14:26:03 2024 +0000

    chore: ts-ignore

commit f1e00db
Author: IanM <[email protected]>
Date:   Tue Jan 30 14:22:36 2024 +0000

    fix: return type

commit d56bf39
Author: StyleCI Bot <[email protected]>
Date:   Tue Jan 30 14:18:49 2024 +0000

    Apply fixes from StyleCI

commit d49c1f9
Author: IanM <[email protected]>
Date:   Tue Jan 30 14:18:37 2024 +0000

    feat: list polls controller

commit 8fb8cc6
Author: IanM <[email protected]>
Date:   Tue Jan 30 14:18:13 2024 +0000

    chore: format

commit ee37ee6
Author: IanM <[email protected]>
Date:   Tue Jan 30 14:15:49 2024 +0000

    fix: some model props incorrect

commit 1857a44
Author: StyleCI Bot <[email protected]>
Date:   Tue Jan 30 08:16:56 2024 +0000

    Apply fixes from StyleCI

commit 4b461a5
Author: IanM <[email protected]>
Date:   Tue Jan 30 08:16:27 2024 +0000

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

commit adf5393
Author: IanM <[email protected]>
Date:   Mon Jan 29 16:22:08 2024 +0000

    add nav item

commit d4032dc
Author: IanM <[email protected]>
Date:   Mon Jan 29 16:09:52 2024 +0000

    chore: ts

commit 7365c67
Author: IanM <[email protected]>
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 <[email protected]>

commit f460073
Author: IanM <[email protected]>
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 <[email protected]>

commit 9acbd74
Author: IanM <[email protected]>
Date:   Mon Jan 29 11:10:32 2024 +0000

    Chore: include discuss link

commit a2af115
Author: IanM <[email protected]>
Date:   Mon Jan 29 11:00:51 2024 +0000

    chore: use 1.x workflows
  • Loading branch information
DavideIadeluca committed Feb 1, 2024
1 parent 1bcfee8 commit d2eb935
Show file tree
Hide file tree
Showing 47 changed files with 1,524 additions and 129 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ on: [workflow_dispatch, push, pull_request]

jobs:
run:
uses: flarum/framework/.github/workflows/REUSABLE_backend.yml@main
uses: flarum/framework/.github/workflows/REUSABLE_backend.yml@1.x
with:
enable_backend_testing: false
enable_backend_testing: true
enable_phpstan: true

backend_directory: .
2 changes: 1 addition & 1 deletion .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [workflow_dispatch, push, pull_request]

jobs:
run:
uses: flarum/framework/.github/workflows/REUSABLE_frontend.yml@main
uses: flarum/framework/.github/workflows/REUSABLE_frontend.yml@1.x
with:
enable_bundlewatch: false
enable_prettier: true
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
vendor
composer.lock
js/dist
.phpunit.result.cache
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ A [Flarum](http://flarum.org) extension. A Flarum extension that adds polls to y
### Installation

```sh
composer require fof/polls
composer require fof/polls:"*"
```

#### Migrating from ReFlar Polls
Expand Down Expand Up @@ -48,5 +48,6 @@ You can only run the command when the extension is enabled in the admin panel.

- [Packagist](https://packagist.org/packages/fof/polls)
- [GitHub](https://github.com/packages/FriendsOfFlarum/polls)
- [Discuss](https://discuss.flarum.org/d/20586)

An extension by [FriendsOfFlarum](https://github.com/FriendsOfFlarum).
26 changes: 22 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,36 @@
},
"flarum-cli": {
"modules": {
"githubActions": true
"githubActions": true,
"backendTesting": true
}
}
},
"require-dev": {
"flarum/phpstan": "*"
"flarum/phpstan": "*",
"flarum/testing": "^1.0.0"
},
"scripts": {
"analyse:phpstan": "phpstan analyse",
"clear-cache:phpstan": "phpstan clear-result-cache"
"clear-cache:phpstan": "phpstan clear-result-cache",
"test": [
"@test:unit",
"@test:integration"
],
"test:unit": "phpunit -c tests/phpunit.unit.xml",
"test:integration": "phpunit -c tests/phpunit.integration.xml",
"test:setup": "@php tests/integration/setup.php"
},
"scripts-descriptions": {
"analyse:phpstan": "Run static analysis"
"analyse:phpstan": "Run static analysis",
"test": "Runs all tests.",
"test:unit": "Runs all unit tests.",
"test:integration": "Runs all integration tests.",
"test:setup": "Sets up a database for use with integration tests. Execute this only once."
},
"autoload-dev": {
"psr-4": {
"FoF\\Polls\\Tests\\": "tests/"
}
}
}
42 changes: 15 additions & 27 deletions extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,19 @@

return [
(new Extend\Frontend('forum'))
->js(__DIR__.'/js/dist/forum.js')
->css(__DIR__.'/resources/less/forum.less')
->route('/polls', 'polls'),
->js(__DIR__ . '/js/dist/forum.js')
->css(__DIR__ . '/resources/less/forum.less')
->route('/polls', 'fof_polls_directory', Content\PollsDirectory::class),

(new Extend\Frontend('admin'))
->js(__DIR__.'/js/dist/admin.js')
->css(__DIR__.'/resources/less/admin.less'),
->js(__DIR__ . '/js/dist/admin.js')
->css(__DIR__ . '/resources/less/admin.less'),

new Extend\Locales(__DIR__.'/resources/locale'),
new Extend\Locales(__DIR__ . '/resources/locale'),

(new Extend\Routes('api'))
->post('/fof/polls', 'fof.polls.create', Controllers\CreatePollController::class)
->get('/fof/polls', 'fof.polls.index', Controllers\ListGlobalPollsController::class)
->get('/fof/polls/{id}', 'fof.polls.show', Controllers\ShowPollController::class)
->patch('/fof/polls/{id}', 'fof.polls.edit', Controllers\EditPollController::class)
->delete('/fof/polls/{id}', 'fof.polls.delete', Controllers\DeletePollController::class)
Expand All @@ -50,34 +51,17 @@

(new Extend\Event())
->listen(PostSaving::class, Listeners\SavePollsToDatabase::class)
->listen(SettingsSaved::class, function (SettingsSaved $event) {
foreach ($event->settings as $key => $value) {
if ($key === 'fof-polls.optionsColorBlend') {
resolve('fof-user-bio.formatter')->flush();

return;
}
}
}),
->listen(SettingsSaved::class, Listeners\ClearFormatterCache::class),

(new Extend\ApiSerializer(DiscussionSerializer::class))
->attribute('hasPoll', function (DiscussionSerializer $serializer, Discussion $discussion): bool {
return $discussion->polls()->exists();
})
->attribute('canStartPoll', function (DiscussionSerializer $serializer, Discussion $discussion): bool {
return $serializer->getActor()->can('polls.start', $discussion);
}),
->attributes(Api\AddDiscussionAttributes::class),

(new Extend\ApiSerializer(PostSerializer::class))
->hasMany('polls', PollSerializer::class)
->attribute('canStartPoll', function (PostSerializer $serializer, Post $post): bool {
return $serializer->getActor()->can('startPoll', $post);
}),
->attributes(Api\AddPostAttributes::class),

(new Extend\ApiSerializer(ForumSerializer::class))
->attribute('canStartPolls', function (ForumSerializer $serializer): bool {
return $serializer->getActor()->can('discussion.polls.start');
}),
->attributes(Api\AddForumAttributes::class),

(new Extend\ApiController(Controller\ListDiscussionsController::class))
->addOptionalInclude(['firstPost.polls']),
Expand Down Expand Up @@ -112,6 +96,7 @@
(new Extend\Settings())
->default('fof-polls.maxOptions', 10)
->default('fof-polls.optionsColorBlend', true)
->default('fof-polls.directory-default-sort', 'default')
->serializeToForum('allowPollOptionImage', 'fof-polls.allowOptionImage', 'boolval')
->serializeToForum('pollMaxOptions', 'fof-polls.maxOptions', 'intval')
->registerLessConfigVar('fof-polls-options-color-blend', 'fof-polls.optionsColorBlend', function ($value) {
Expand All @@ -120,4 +105,7 @@

(new Extend\ModelVisibility(Poll::class))
->scope(Access\ScopePollVisibility::class),

(new Extend\View())
->namespace('fof-polls', __DIR__ . '/resources/views'),
];
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions js/src/admin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ app.initializers.add('fof/polls', () => {
},
'start'
)
.registerPermission(
{
icon: 'fas fa-signal',
label: app.translator.trans('fof-polls.admin.permissions.start_global'),
permission: 'startGlobalPoll',
},
'start'
)
.registerPermission(
{
icon: 'fas fa-pencil-alt',
Expand Down
20 changes: 20 additions & 0 deletions js/src/forum/addNavItem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import app from 'flarum/forum/app';
import { extend } from 'flarum/common/extend';
import IndexPage from 'flarum/forum/components/IndexPage';
import LinkButton from 'flarum/common/components/LinkButton';

export default function addNavItem() {
extend(IndexPage.prototype, 'navItems', (items) => {
items.add(
'fof-polls-directory',
LinkButton.component(
{
href: app.route('fof_polls_directory'),
icon: 'fas fa-poll',
},
app.translator.trans('fof-polls.forum.page.nav')
),
35
);
});
}
148 changes: 148 additions & 0 deletions js/src/forum/components/PollsDirectory.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import app from 'flarum/forum/app';
import Page from 'flarum/common/components/Page';
import extractText from 'flarum/common/utils/extractText';
import IndexPage from 'flarum/forum/components/IndexPage';
import ItemList from 'flarum/common/utils/ItemList';
import listItems from 'flarum/common/helpers/listItems';
import SelectDropdown from 'flarum/common/components/SelectDropdown';
import LinkButton from 'flarum/common/components/LinkButton';
import Select from 'flarum/common/components/Select';
import Button from 'flarum/common/components/Button';
import Mithril from 'mithril';

export default class PollsDirectory extends Page {
oncreate(vnode: Mithril.Vnode) {
super.oncreate(vnode);

app.setTitle(extractText(app.translator.trans('fof-polls.forum.page.nav')));
}

view() {
return (
<div className="IndexPage">
{IndexPage.prototype.hero()}
<div className="container">
<div className="sideNavContainer">
<nav className="IndexPage-nav sideNav">
<ul>{listItems(this.sidebarItems().toArray())}</ul>
</nav>
<div className="IndexPage-results sideNavOffset">
<div className="IndexPage-toolbar">
<ul className="IndexPage-toolbar-view">{listItems(this.viewItems().toArray())}</ul>
<ul className="IndexPage-toolbar-action">{listItems(this.actionItems().toArray())}</ul>
</div>
{/* <UserDirectoryList state={this.state} /> */}
</div>
</div>
</div>
</div>
);
}

/**
* Our own sidebar. Re-uses Index.sidebarItems as the base
* Elements added here will only show up on the user directory page
*/
sidebarItems(): ItemList<Mithril.Children> {
const items = IndexPage.prototype.sidebarItems();

items.setContent(
'nav',
SelectDropdown.component(
{
buttonClassName: 'Button',
className: 'App-titleControl',
},
this.navItems().toArray()
)
);

return items;
}

/**
* Our own sidebar navigation. Re-uses Index.navItems as the base
* Elements added here will only show up on the user directory page
*/
navItems(): ItemList<Mithril.Children> {
const items = IndexPage.prototype.navItems();
const params = this.stickyParams();

items.setContent(
'fof-polls-directory',
LinkButton.component(
{
href: app.route('fof_polls_directory', params),
icon: 'fas fa-poll',
},
app.translator.trans('fof-polls.forum.page.nav')
)
);

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;
}
}
File renamed without changes.
21 changes: 0 additions & 21 deletions js/src/forum/extend.js

This file was deleted.

Loading

0 comments on commit d2eb935

Please sign in to comment.