Skip to content

Commit

Permalink
wip: global polls (#86)
Browse files Browse the repository at this point in the history
* chore: ts

* add nav item

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

* Apply fixes from StyleCI

* fix: some model props incorrect

* chore: format

* feat: list polls controller

* Apply fixes from StyleCI

* fix: return type

* chore: ts-ignore

* use sort

* Apply fixes from StyleCI

* chore: add test for existing create poll functionality via posts

* Apply fixes from StyleCI

* fix: provider visibility

* fix: provider visibility

* test: create post poll via api

* Apply fixes from StyleCI

* ensure poll is associated with postId

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

* Apply fixes from StyleCI

* fix: phpstan error

* add unauthorized api test

* list polls only shows global polls

* add isGlobal peroperty to js model

* feat: optional poll subtitle

* Apply fixes from StyleCI

* Sh/form UI (#90)

* chore: design first iteration of refined polls

* refactor: break code down into components

* refactor: further break code down into components

* chore: dummy implementation

* refactor: use descriptive class names

* chore: minor styling changes

* chore: tinker with typescript

* feat: implement prototype of how results are shown

* chore: minor style changes

* refactor: break down logic

* chore: add dummy content for demo purposes

* chore: minor styling changes

* chore: add boilerplate state and model

* chore: work in progress

* Squashed commit of the following:

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

* create PollForm and adapt Create and EditPollModal

* Apply fixes from StyleCI

* wip

* style: format code

* feat: add start global poll button

* feat: add placeholder string keys

* chore: troubleshooting

* - remove legacy code from directory
- add simple acl abstraction
- add compose polls page

* - add compose poll hero
- adapt CreatePollHandler to the new data structure (similar to edit)
- add translations

* - pseudo fix poll visibility scope, requires review

* - implement frontend list and edit view for poll

* Apply fixes from StyleCI

* - implement poll detail view

* - format code

* - update poll detail view
- enhance poll list view

* refactor: change class name

* refactor: move edit, show results and delete buttons into controls dropdown.

* refactor: remove wrong css classes and add necessary ones

* feat: add missing en text keys

* feat: add link to polls page in session dropdown

* chore: cleanup

* Squashed commit of the following:

commit ce20ae8
Author: StyleCI Bot <[email protected]>
Date:   Thu Feb 15 12:19:33 2024 +0000

    Apply fixes from StyleCI

commit f2e6f32
Author: IanM <[email protected]>
Date:   Thu Feb 15 12:19:14 2024 +0000

    feat: optional poll subtitle

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

* chore: cleanup

* Apply fixes from StyleCI

* Refactor Poll related components and methods for better readability and error handling

* refactor: Add subtitle field to PollForm component

* Add check for undefined voteCount and update localization strings in PollListItem component

* Refactor PollResults component to use real data and add overallVoteCount method to PollState

* bugfix: fix bug about saving polls from posts etc. and add missing texts

* fix tests

* minor cleanup

* switch to yarn

* more cleanup

* fix compose route reload

* fix create poll

* fix edit existing post poll

* create dedicated poll view route

* refactor: add PollViewPage

* refactor: merged Subtitle and title component into PollView using ListItems & the vote button is now showing up and working

* format

* fix poll compose

* update icons, begin removing acl

* fix edit polls

* refactor: use ItemList approach for form part in PollView

* bugfix: fix when which data is provided in the form for the options for create and edit

* remove acl

* export components

* export states

* add nav to poll compose

* refactor: improve markup and css classes assignment for PostListItem

* style: improve Poll list style

* build js for demo/alpha release

* format and build

* style: add basic style for poll result bar and center icon in poll composer icon buttons

* refactor: add class and text key to poll modal delete button

* feat: add percentage position indicator in poll result bar

* format

* feat: use submit button as separate component for possible customization (animation, etc) via extend function

* Build

* fix: change syntax for delete success message

* feat: add sr only text to form

* feat: improve accessibility

* chore: remove comments

* feat: further improve accessibility

* chore: missing code replication

Perhaps it would make sense to refactor this..

* feat: use poll question as meta title

* refactor: use other icons for poll controls

Use the same as when editing or deleting discussions.

* chor: move PollForm to tsx format

* chor: move both Modal to tsx format

* wip: pollshowcase + refactoring

---------

Co-authored-by: Davide Iadeluca <[email protected]>
Co-authored-by: StyleCI Bot <[email protected]>
Co-authored-by: Gianni Guida <[email protected]>
Co-authored-by: IanM <[email protected]>

* remove commented code

* add translations

* export showcase components

* Reset dist folder to match master branch

* use abstract base

* use more of abstractpollpage

* fix: handling of relational data (PollOptions) in the form and saving process

* dont display tags in the nav for polls pages

* chor: transform ListVotersModal to typescript

* convert to ts

* add config for polls storage disk

* Apply fixes from StyleCI

* wip: poll image upload

* chor: move add* js files to tsx format

* fix: prevent unload in pollview

* chor: clean up PollState

* format js

* chor: update typing

* refactor: first attempt to merge PostPolls with PollView

* wip: poll image upload

* Apply fixes from StyleCI

* chor: remove custom poll option views

* fix: users could not vote on global polls

* chor: replace "old" PostPoll component with new PollView

* fix: result page was not shown after vote and reload full page

* fix: date could not be deleted

* chor: extend pollButtonSubmit with event

* chor: revert customization changes back to original functionality

* format js

* chor: optimize layout

* feat: poll image upload

* Apply fixes from StyleCI

* add pollimage interface

* feat: add image alt to poll

* Apply fixes from StyleCI

* fix: image alt migration and view

* chor: format

* chor: poll image styling

* fix: add image when update poll

* chor: format

* handle edit/delete of poll image

* Apply fixes from StyleCI

* style poll image

* poll footer

* title for active and ended polls on showcase page

* fix current user vote on showcase page

* further styling on showcase page

* feat: global polls feature switch

* Apply fixes from StyleCI

* set image corner

* feat: add poll option image

* Apply fixes from StyleCI

* fix: remove migration for alt image on poll option

* move + icon

* Revert "fix: remove migration for alt image on poll option"

This reverts commit be6d2cf.

* Revert "feat: add poll option image"

This reverts commit bcd2e69.

* fix broken tests

* build js

* chore: make for easier extending of certain poll components

* build js

* feat: events for polloptions

* export PollImage component

* feat: extendable include params

* chore: build js

* Apply fixes from StyleCI

* fix: extendable

* Apply fixes from StyleCI

* chore: fix issue with images being deleted after edit

* style: run formatter

* chore: export PollControls

* chore: format

* fix: view results of global polls, allow voting for normal users

* fix: view voters visibility

* Apply fixes from StyleCI

* fix: admins could not see voters

* build js

* chore: improvements for extensibility

* chore: build js

* Revert "chore: fix issue with images being deleted after edit"

This reverts commit d1bf23c.

* fix: rename image attribute to reflect backend changes

* chore: build js

* feat: option images, config resize

* build js

* Apply fixes from StyleCI

* fix: phpstan

* chore: add translations, remove unused code

* chore: build js

* feat: poll image create/delete events

* Apply fixes from StyleCI

* $option->image_url

* fix: delete poll ( & option) images

* feat: add PollPageHero

* chor: add string for poll_page.title and allow backwards date change for global polls

* fix!: change semantic markup

BREAKING CHANGE: Change markup to improve SEO

* chore: build js

* fix: update the selected/checked status correctly

* chore: make extending or overriding the answer label possible in the results modal

* chore: use h3 for option title

* chore: build js

* style: run formatter

* fix: add add translation for modal errors

* fix: change condition when generic error message is shown

* chore: build js

* chore: re-use core generic message

* chore: use more core translations

* fix: delete uploaded image when poll is not saved

* Apply fixes from StyleCI

* Improve PollOption Markup (#93)

* style: run formatter

* chore: remove empty rule

* chore: remove some unused css rules

* chore: remove commented out css rules

* feat!: first attempt to improve accessibility on PollOption

BREAKING CHANGE: The changed markup might have unintended side effects related to styling for third party vendors.

* fix: changes in selected options where not displayed

* chore: remove `aria-describedby` on input

* fix: add missing id to Poll text answer

* chor: update dist files because of merge

---------

Co-authored-by: Simon Hiller <[email protected]>

* fix: image was missing in poll serializer

---------

Co-authored-by: StyleCI Bot <[email protected]>
Co-authored-by: Simon <[email protected]>
Co-authored-by: Davide Iadeluca <[email protected]>
Co-authored-by: Gianni Guida <[email protected]>
Co-authored-by: Davide Iadeluca <[email protected]>
  • Loading branch information
6 people authored May 7, 2024
1 parent 7365c67 commit 269bffc
Show file tree
Hide file tree
Showing 102 changed files with 13,250 additions and 6,817 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

frontend_directory: ./js
backend_directory: .
js_package_manager: npm
js_package_manager: yarn
main_git_branch: master

secrets:
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
node_modules
vendor
composer.lock
js/dist
.phpunit.result.cache
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"title": "FoF Polls",
"category": "discussion",
"icon": {
"name": "fas fa-signal",
"name": "fas fa-poll",
"backgroundColor": "#e74c3c",
"color": "#fff"
}
Expand All @@ -59,7 +59,8 @@
},
"require-dev": {
"flarum/phpstan": "*",
"flarum/testing": "^1.0.0"
"flarum/testing": "^1.0.0",
"fof/upload": "*"
},
"scripts": {
"analyse:phpstan": "phpstan analyse",
Expand Down
37 changes: 30 additions & 7 deletions extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@
use Flarum\Post\Post;
use Flarum\Settings\Event\Saved as SettingsSaved;
use FoF\Polls\Api\Controllers;
use FoF\Polls\Api\Serializers\PollSerializer;

return [
(new Extend\Frontend('forum'))
->js(__DIR__.'/js/dist/forum.js')
->css(__DIR__.'/resources/less/forum.less'),
->css(__DIR__.'/resources/less/forum.less')
->route('/polls', 'fof.polls.showcase')
->route('/polls/all', 'fof.polls.list', Content\PollsDirectory::class)
->route('/polls/view/{id}', 'fof.poll.view')
->route('/polls/composer', 'fof.polls.composer'),

(new Extend\Frontend('admin'))
->js(__DIR__.'/js/dist/admin.js')
Expand All @@ -36,10 +39,19 @@

(new Extend\Routes('api'))
->post('/fof/polls', 'fof.polls.create', Controllers\CreatePollController::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)
->patch('/fof/polls/{id}/votes', 'fof.polls.votes', Controllers\MultipleVotesPollController::class),
->get('/fof/polls', 'fof.polls.index', Controllers\ListGlobalPollsController::class)
->get('/fof/polls/{id:\d+}', 'fof.polls.show', Controllers\ShowPollController::class)
->patch('/fof/polls/{id:\d+}', 'fof.polls.edit', Controllers\EditPollController::class)
->delete('/fof/polls/{id:\d+}', 'fof.polls.delete', Controllers\DeletePollController::class)
->patch('/fof/polls/{id:\d+}/votes', 'fof.polls.votes', Controllers\MultipleVotesPollController::class)
->post('/fof/polls/pollImage', 'fof.polls.upload-image', Controllers\UploadPollImageController::class)
->delete('/fof/polls/pollImage/name/{fileName}', 'fof.polls.delete-image-name', Controllers\DeletePollImageByNameController::class)
->post('/fof/polls/pollImage/{pollId:\d+}', 'fof.polls.upload-image-poll', Controllers\UploadPollImageController::class)
->delete('/fof/polls/pollImage/{pollId:\d+}', 'fof.polls.delete-image-poll', Controllers\DeletePollImageController::class)
->post('/fof/polls/pollOptionImage', 'fof.polls.upload-option-image-option', Controllers\UploadPollOptionImageController::class)
->delete('/fof/polls/pollOptionImage/name/{fileName}', 'fof.polls.delete-option-image-name', Controllers\DeletePollImageByNameController::class)
->post('/fof/polls/pollOptionImage/{optionId:\d+}', 'fof.polls.upload-option-image', Controllers\UploadPollOptionImageController::class)
->delete('/fof/polls/pollOptionImage/{optionId:\d+}', 'fof.polls.delete-option-image', Controllers\DeletePollOptionImageController::class),

(new Extend\Model(Post::class))
->hasMany('polls', Poll::class, 'post_id', 'id'),
Expand All @@ -55,7 +67,7 @@
->attributes(Api\AddDiscussionAttributes::class),

(new Extend\ApiSerializer(PostSerializer::class))
->hasMany('polls', PollSerializer::class)
->hasMany('polls', Api\Serializers\PollSerializer::class)
->attributes(Api\AddPostAttributes::class),

(new Extend\ApiSerializer(ForumSerializer::class))
Expand Down Expand Up @@ -94,6 +106,11 @@
(new Extend\Settings())
->default('fof-polls.maxOptions', 10)
->default('fof-polls.optionsColorBlend', true)
->default('fof-polls.directory-default-sort', 'default')
->default('fof-polls.enableGlobalPolls', false)
->default('fof-polls.image_height', 250)
->default('fof-polls.image_width', 250)
->serializeToForum('globalPollsEnabled', 'fof-polls.enableGlobalPolls', 'boolval')
->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 @@ -102,4 +119,10 @@

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

(new Extend\View())
->namespace('fof-polls', __DIR__.'/resources/views'),

(new Extend\Filesystem())
->disk('fof-polls', PollImageDisk::class),
];
File renamed without changes.
176 changes: 175 additions & 1 deletion js/dist/admin.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 269bffc

Please sign in to comment.