mirror of
https://github.com/flarum/core.git
synced 2025-08-16 05:14:20 +02:00
Compare commits
270 Commits
as/depreca
...
dk/harden-
Author | SHA1 | Date | |
---|---|---|---|
|
e3435a3f30 | ||
|
cd0a31a6e7 | ||
|
43d6b3104d | ||
|
33bd99d376 | ||
|
eb4b18a979 | ||
|
b62debf031 | ||
|
1f2411e15e | ||
|
d99df936b1 | ||
|
9716a15c31 | ||
|
5e2340bf10 | ||
|
c84939b19c | ||
|
4974c91481 | ||
|
f67149bb06 | ||
|
a2d77d7b81 | ||
|
da4264c8a3 | ||
|
0f9526ba9f | ||
|
e77365f32f | ||
|
c7c456cb3e | ||
|
fb51fb4e6d | ||
|
5b7d364b87 | ||
|
39a6106854 | ||
|
9e3699ea47 | ||
|
b6f0b01307 | ||
|
548f1321f1 | ||
|
e376cf2079 | ||
|
286027ff27 | ||
|
e52b769ceb | ||
|
b1f166d82a | ||
|
63675c81d6 | ||
|
f76524a5de | ||
|
c006931798 | ||
|
a5ec39b5cf | ||
|
c75db75efe | ||
|
300dadff60 | ||
|
94d69fe15f | ||
|
da598db376 | ||
|
d31e0573f8 | ||
|
2968341f77 | ||
|
9839370701 | ||
|
40dc6d0feb | ||
|
945f6478b5 | ||
|
69a10c97be | ||
|
0074f0c984 | ||
|
19465fb522 | ||
|
0fe7723a7f | ||
|
fbe2813378 | ||
|
4b69a35260 | ||
|
5e8155e1cc | ||
|
0f0f2b6d4e | ||
|
3dae397c65 | ||
|
7025a7f5e0 | ||
|
12f6b1b375 | ||
|
2de57af7c8 | ||
|
1c4817a0b3 | ||
|
0eefbf0374 | ||
|
90c0bc410e | ||
|
d642fb531c | ||
|
706eaeda41 | ||
|
3cc18c1da2 | ||
|
8dd57ffed2 | ||
|
d29495203b | ||
|
783c563305 | ||
|
908d087e00 | ||
|
374189d48e | ||
|
fe8dda6fd0 | ||
|
cd9ee48af6 | ||
|
2e9078a7cf | ||
|
0cc12aed95 | ||
|
59fdd7628a | ||
|
298f6c39f2 | ||
|
233b97329c | ||
|
1b5b143930 | ||
|
0d139e6133 | ||
|
0e6a60bd5b | ||
|
6e4c75eba6 | ||
|
386f3d3db1 | ||
|
9fffb8ec1a | ||
|
92e590f1ab | ||
|
098908cb4a | ||
|
901846d0cf | ||
|
5a3aefb76c | ||
|
cf2a636e81 | ||
|
a8ba510655 | ||
|
9c3b6c596f | ||
|
2310d782a3 | ||
|
e9642250ae | ||
|
a6dd545dbc | ||
|
a64c39835a | ||
|
db0d8e89c7 | ||
|
4e126708e9 | ||
|
b88a7cb33b | ||
|
a2f52c09fd | ||
|
30017eef09 | ||
|
d0ffa26b0b | ||
|
612a57c466 | ||
|
91e8b56961 | ||
|
ba9665e9db | ||
|
8eea0985a4 | ||
|
1bcb9d3ea1 | ||
|
2c3e1f9923 | ||
|
bc607e089e | ||
|
91d5d9c176 | ||
|
3aa118ab94 | ||
|
4b0ad6972d | ||
|
84ded0ce50 | ||
|
725863a6e2 | ||
|
c81f629b0b | ||
|
15cbe4daaa | ||
|
ddac07d991 | ||
|
08ba2599d7 | ||
|
8eef7230e9 | ||
|
a61f9e7328 | ||
|
a65e1de641 | ||
|
bed3207798 | ||
|
fc73d47e4c | ||
|
6e01c47c11 | ||
|
a9526917b8 | ||
|
e37fdef709 | ||
|
56d7796c47 | ||
|
b7379bf91b | ||
|
7fa22a131f | ||
|
f0c6050654 | ||
|
9627eb73f1 | ||
|
d0adb244da | ||
|
458a5cc6be | ||
|
ea840ba594 | ||
|
ea291508ab | ||
|
7d79912d36 | ||
|
67306a9d34 | ||
|
8cc207b139 | ||
|
023871ef86 | ||
|
1c578a83e4 | ||
|
454c525cb2 | ||
|
49009d268f | ||
|
ef2d6a65f4 | ||
|
509adf228a | ||
|
fa10d794a4 | ||
|
40ede179cd | ||
|
0ed71ed581 | ||
|
dc75ebad00 | ||
|
900711687f | ||
|
71ccdc00e6 | ||
|
c4ebebe48e | ||
|
56d8301b2d | ||
|
09076e005b | ||
|
73a8efaec2 | ||
|
cdeb229396 | ||
|
122a99b51e | ||
|
e7aed89e8f | ||
|
a1254bc21a | ||
|
03231b2931 | ||
|
a2901cef23 | ||
|
95b021a839 | ||
|
76d6442557 | ||
|
5df22e92ae | ||
|
7306d8ef13 | ||
|
0595aba76a | ||
|
8366ec720e | ||
|
17f15e36eb | ||
|
ac249e5b07 | ||
|
e13772075c | ||
|
0fa33439d7 | ||
|
a4880453a4 | ||
|
964f827ee5 | ||
|
843daf633d | ||
|
930fcf9250 | ||
|
9bb4423dd7 | ||
|
9347b12b47 | ||
|
65b5c2043c | ||
|
08f72e7135 | ||
|
26c4e492fe | ||
|
00913d5b0b | ||
|
1851d1678e | ||
|
14dc46e226 | ||
|
be163412ab | ||
|
92d5c716be | ||
|
e42df50d31 | ||
|
203a6456ee | ||
|
40b918e139 | ||
|
f8eea5b7c7 | ||
|
b50d806534 | ||
|
cbcf83ed3b | ||
|
3394ff31e9 | ||
|
86d39fb003 | ||
|
bbb7679417 | ||
|
46248f601d | ||
|
a68e2b27a4 | ||
|
e2335e867d | ||
|
a10da427ff | ||
|
4561f56fb9 | ||
|
fae79ea910 | ||
|
9493e6230d | ||
|
927ea4eec5 | ||
|
89e821e70f | ||
|
9b2d7856d1 | ||
|
f93ec1b3b8 | ||
|
2e3197d510 | ||
|
85210ff6a1 | ||
|
e5f277e640 | ||
|
4bac667dfd | ||
|
6771b3e3b7 | ||
|
fd79a14cac | ||
|
c1aa1455d3 | ||
|
ae280016e7 | ||
|
0a8816938a | ||
|
008ec95505 | ||
|
925628c208 | ||
|
aae83c4fbc | ||
|
cacc8b4945 | ||
|
31765388c1 | ||
|
a08fd3e475 | ||
|
d4b2d89da0 | ||
|
9b27b0d9d7 | ||
|
a47187462d | ||
|
843a149b80 | ||
|
94381dca62 | ||
|
a2d5dd3397 | ||
|
f8edc2d827 | ||
|
62235a16ca | ||
|
36c55e8f69 | ||
|
859f014539 | ||
|
06e1d21331 | ||
|
fd5de6929e | ||
|
84b1666b24 | ||
|
0c61fcc61c | ||
|
8e25bcb68f | ||
|
fad783547c | ||
|
210a6b3e25 | ||
|
73409184b9 | ||
|
afe038699e | ||
|
649851d356 | ||
|
d1dfa758e4 | ||
|
8901073d12 | ||
|
e0437d237a | ||
|
07a43f52b4 | ||
|
9e9118fa0d | ||
|
4679448300 | ||
|
ef4bf8128e | ||
|
67a2aac635 | ||
|
51a97fb12e | ||
|
056d420c7b | ||
|
cfa533ebd6 | ||
|
eed407812f | ||
|
641619e820 | ||
|
984f751c71 | ||
|
8830e9dd09 | ||
|
fe41bc1fdc | ||
|
5a763050a6 | ||
|
8c813bc340 | ||
|
f67dee0a9e | ||
|
f968420216 | ||
|
d5e124b4a2 | ||
|
09e2736cbc | ||
|
ddb3d3edb0 | ||
|
28d56f5fc8 | ||
|
9b4012bbb5 | ||
|
1a5e4d454e | ||
|
387b4fd315 | ||
|
66482c2815 | ||
|
277a5c3fac | ||
|
286d8dec5b | ||
|
e1c61a0e85 | ||
|
102e76b084 | ||
|
d09d4bc507 | ||
|
c3989cc952 | ||
|
967cd0e3ca | ||
|
b79152b977 | ||
|
ace624db66 | ||
|
9b9f2c4bb7 | ||
|
8b1de457bf |
@@ -15,5 +15,5 @@ indent_size = 2
|
|||||||
[*.{diff,md}]
|
[*.{diff,md}]
|
||||||
trim_trailing_whitespace = false
|
trim_trailing_whitespace = false
|
||||||
|
|
||||||
[*.{php,xml}]
|
[*.{php,xml,json}]
|
||||||
indent_size = 4
|
indent_size = 4
|
||||||
|
18
.github/workflows/build.yml
vendored
18
.github/workflows/build.yml
vendored
@@ -7,10 +7,24 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
name: JS / Build
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@master
|
- name: Check out code
|
||||||
- uses: flarum/action-build@master
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Restore npm cache
|
||||||
|
uses: actions/cache@v2
|
||||||
|
with:
|
||||||
|
path: ~/.npm
|
||||||
|
key: ${{ runner.os }}-node-${{ hashFiles('js/package-lock.json') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-node-
|
||||||
|
|
||||||
|
# Our action will install npm, cd into `./js`, run `npm run build`,
|
||||||
|
# then commit and upload any changes
|
||||||
|
- name: Build production JS
|
||||||
|
uses: flarum/action-build@master
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
76
.github/workflows/codeql-analysis.yml
vendored
Normal file
76
.github/workflows/codeql-analysis.yml
vendored
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
# For most projects, this workflow file will not need changing; you simply need
|
||||||
|
# to commit it to your repository.
|
||||||
|
#
|
||||||
|
# You may wish to alter this file to override the set of languages analyzed,
|
||||||
|
# or to provide custom queries or build logic.
|
||||||
|
#
|
||||||
|
# ******** NOTE ********
|
||||||
|
# We have attempted to detect the languages in your repository. Please check
|
||||||
|
# the `language` matrix defined below to confirm you have the correct set of
|
||||||
|
# supported CodeQL languages.
|
||||||
|
#
|
||||||
|
name: "CodeQL"
|
||||||
|
|
||||||
|
# Run on:
|
||||||
|
# - pushes to master, or
|
||||||
|
# - PRs with a base of `master`
|
||||||
|
# - which do not **only** consist of changes to .md or .less files
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ master ]
|
||||||
|
paths-ignore:
|
||||||
|
- '**/*.md'
|
||||||
|
- '**/*.less'
|
||||||
|
pull_request:
|
||||||
|
branches: [ master ]
|
||||||
|
paths-ignore:
|
||||||
|
- '**/*.md'
|
||||||
|
- '**/*.less'
|
||||||
|
schedule:
|
||||||
|
- cron: '0 0 * * 1,3,5'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
analyze:
|
||||||
|
name: Analyze / ${{ matrix.language }}
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
language: [ 'javascript' ]
|
||||||
|
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
|
||||||
|
# Learn more:
|
||||||
|
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
# Initializes the CodeQL tools for scanning.
|
||||||
|
- name: Initialize CodeQL
|
||||||
|
uses: github/codeql-action/init@v1
|
||||||
|
with:
|
||||||
|
languages: ${{ matrix.language }}
|
||||||
|
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||||
|
# By default, queries listed here will override any specified in a config file.
|
||||||
|
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||||
|
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
||||||
|
|
||||||
|
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||||
|
# If this step fails, then you should remove it and run the build manually (see below)
|
||||||
|
- name: Autobuild
|
||||||
|
uses: github/codeql-action/autobuild@v1
|
||||||
|
|
||||||
|
# ℹ️ Command-line programs to run using the OS shell.
|
||||||
|
# 📚 https://git.io/JvXDl
|
||||||
|
|
||||||
|
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
||||||
|
# and modify them (or add more) to build your code if your project
|
||||||
|
# uses a compiled language
|
||||||
|
|
||||||
|
#- run: |
|
||||||
|
# make bootstrap
|
||||||
|
# make release
|
||||||
|
|
||||||
|
- name: Perform CodeQL Analysis
|
||||||
|
uses: github/codeql-action/analyze@v1
|
21
.github/workflows/lint.yml
vendored
21
.github/workflows/lint.yml
vendored
@@ -1,6 +1,7 @@
|
|||||||
name: Lint
|
name: Lint
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
push:
|
push:
|
||||||
paths:
|
paths:
|
||||||
- 'js/src/**'
|
- 'js/src/**'
|
||||||
@@ -10,22 +11,18 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
prettier:
|
prettier:
|
||||||
|
name: JS / Prettier
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
name: JS / Prettier
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@master
|
- name: Check out code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Setup Node.js
|
- name: Set up Node
|
||||||
uses: actions/setup-node@v1
|
uses: actions/setup-node@v2
|
||||||
with:
|
with:
|
||||||
node-version: "12"
|
node-version: "14"
|
||||||
|
|
||||||
- name: Install JS dependencies
|
- name: Check JS formatting
|
||||||
run: npm ci
|
run: npx prettier --check src
|
||||||
working-directory: ./js
|
|
||||||
|
|
||||||
- name: Check JS code for formatting
|
|
||||||
run: node_modules/.bin/prettier --check src
|
|
||||||
working-directory: ./js
|
working-directory: ./js
|
||||||
|
45
.github/workflows/pr_size_change.yml
vendored
Normal file
45
.github/workflows/pr_size_change.yml
vendored
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
name: Bundle size checker
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
push:
|
||||||
|
paths:
|
||||||
|
- "js/**"
|
||||||
|
pull_request:
|
||||||
|
paths:
|
||||||
|
- "js/**"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
bundlewatch:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
name: Bundlewatch
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Check out code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: "14"
|
||||||
|
|
||||||
|
- name: Use npm v7
|
||||||
|
run: sudo npm install -g npm@7.x.x
|
||||||
|
|
||||||
|
- name: Install JS dependencies
|
||||||
|
# We need to use `npm install` here. If we don't, the workflow will fail.
|
||||||
|
run: npm install
|
||||||
|
working-directory: ./js
|
||||||
|
|
||||||
|
- name: Build production assets
|
||||||
|
run: npm run build
|
||||||
|
working-directory: ./js
|
||||||
|
|
||||||
|
- name: Check bundle size change
|
||||||
|
run: node_modules/.bin/bundlewatch --config .bundlewatch.config.json
|
||||||
|
working-directory: ./js
|
||||||
|
env:
|
||||||
|
BUNDLEWATCH_GITHUB_TOKEN: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}
|
||||||
|
CI_COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
|
28
.github/workflows/test.yml
vendored
28
.github/workflows/test.yml
vendored
@@ -8,7 +8,7 @@ jobs:
|
|||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
php: [7.2, 7.3, 7.4]
|
php: [7.3, 7.4, '8.0']
|
||||||
service: ['mysql:5.7', mariadb]
|
service: ['mysql:5.7', mariadb]
|
||||||
prefix: ['', flarum_]
|
prefix: ['', flarum_]
|
||||||
|
|
||||||
@@ -21,16 +21,16 @@ jobs:
|
|||||||
prefixStr: (prefix)
|
prefixStr: (prefix)
|
||||||
|
|
||||||
exclude:
|
exclude:
|
||||||
- php: 7.2
|
- php: 7.3
|
||||||
service: 'mysql:5.7'
|
service: 'mysql:5.7'
|
||||||
prefix: flarum_
|
prefix: flarum_
|
||||||
- php: 7.2
|
- php: 7.3
|
||||||
service: mariadb
|
service: mariadb
|
||||||
prefix: flarum_
|
prefix: flarum_
|
||||||
- php: 7.3
|
- php: 8.0
|
||||||
service: 'mysql:5.7'
|
service: 'mysql:5.7'
|
||||||
prefix: flarum_
|
prefix: flarum_
|
||||||
- php: 7.3
|
- php: 8.0
|
||||||
service: mariadb
|
service: mariadb
|
||||||
prefix: flarum_
|
prefix: flarum_
|
||||||
|
|
||||||
@@ -43,15 +43,25 @@ jobs:
|
|||||||
name: 'PHP ${{ matrix.php }} / ${{ matrix.db }} ${{ matrix.prefixStr }}'
|
name: 'PHP ${{ matrix.php }} / ${{ matrix.db }} ${{ matrix.prefixStr }}'
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@master
|
- name: Check out code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Select PHP version
|
- name: Setup PHP
|
||||||
run: sudo update-alternatives --set php $(which php${{ matrix.php }})
|
uses: shivammathur/setup-php@0b9d33cd0782337377999751fc10ea079fdd7104 # pin@v2
|
||||||
|
with:
|
||||||
|
php-version: ${{ matrix.php }}
|
||||||
|
coverage: xdebug
|
||||||
|
extensions: curl, dom, gd, json, mbstring, openssl, pdo_mysql, tokenizer, zip
|
||||||
|
tools: phpunit, composer:v2
|
||||||
|
|
||||||
|
# The authentication alter is necessary because newer mysql versions use the `caching_sha2_password` driver,
|
||||||
|
# which isn't supported prior to PHP7.4
|
||||||
|
# When we drop support for PHP7.3, we should remove this from the setup.
|
||||||
- name: Create MySQL Database
|
- name: Create MySQL Database
|
||||||
run: |
|
run: |
|
||||||
sudo systemctl start mysql
|
sudo systemctl start mysql
|
||||||
mysql -uroot -proot -e 'CREATE DATABASE flarum_test;' --port 13306
|
mysql -uroot -proot -e 'CREATE DATABASE flarum_test;' --port 13306
|
||||||
|
mysql -uroot -proot -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';" --port 13306
|
||||||
|
|
||||||
- name: Install Composer dependencies
|
- name: Install Composer dependencies
|
||||||
run: composer install
|
run: composer install
|
||||||
@@ -65,3 +75,5 @@ jobs:
|
|||||||
|
|
||||||
- name: Run Composer tests
|
- name: Run Composer tests
|
||||||
run: composer test
|
run: composer test
|
||||||
|
env:
|
||||||
|
COMPOSER_PROCESS_TIMEOUT: 600
|
||||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@@ -4,6 +4,8 @@ composer.phar
|
|||||||
node_modules
|
node_modules
|
||||||
.DS_Store
|
.DS_Store
|
||||||
Thumbs.db
|
Thumbs.db
|
||||||
|
tests/.phpunit.result.cache
|
||||||
/tests/integration/tmp
|
/tests/integration/tmp
|
||||||
.vagrant
|
.vagrant
|
||||||
.idea/*
|
.idea/*
|
||||||
|
.vscode
|
||||||
|
@@ -12,7 +12,3 @@ disabled:
|
|||||||
- phpdoc_order
|
- phpdoc_order
|
||||||
- phpdoc_separation
|
- phpdoc_separation
|
||||||
- phpdoc_types
|
- phpdoc_types
|
||||||
|
|
||||||
finder:
|
|
||||||
exclude:
|
|
||||||
- "stubs"
|
|
||||||
|
161
CHANGELOG.md
161
CHANGELOG.md
@@ -1,5 +1,164 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## [0.1.0-beta.16](https://github.com/flarum/core/compare/v0.1.0-beta.15...v0.1.0-beta.16)
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Allow event subscribers (https://github.com/flarum/core/pull/2535)
|
||||||
|
- Allow Settings extender to have a default value (https://github.com/flarum/core/pull/2495)
|
||||||
|
- Allow hooking into the sending of notifications before being send (https://github.com/flarum/core/pull/2533)
|
||||||
|
- PHP 8 support (https://github.com/flarum/core/pull/2507)
|
||||||
|
- Search extender (https://github.com/flarum/core/pull/2483)
|
||||||
|
- User badges to post preview (https://github.com/flarum/core/pull/2555)
|
||||||
|
- Optional extension dependencies allow a booting order (https://github.com/flarum/core/pull/2579)
|
||||||
|
- Auth extender (https://github.com/flarum/core/pull/2176)
|
||||||
|
- `X-Powered-By` header added to allow indexers easier data aggregation of Flarum adoption (https://github.com/flarum/core/pull/2618)
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Run integration tests in transaction (https://github.com/flarum/core/pull/2304)
|
||||||
|
- Allow policies to return a boolean for simplified allow/deny (https://github.com/flarum/core/pull/2534)
|
||||||
|
- Converted highlight helper to typescript (https://github.com/flarum/core/pull/2532)
|
||||||
|
- Add accessibility attributes to Mark as Read button (https://github.com/flarum/core/pull/2564)
|
||||||
|
- Dismiss errors on change email modal upon a new request ([00913d5](https://github.com/flarum/core/commit/00913d5b0be2172cfce1f16aaf64a24f3d2e6d4b))
|
||||||
|
- Disabled extensions now are marked with a red circle instead of a red dot (https://github.com/flarum/core/pull/2562)
|
||||||
|
- Extension dependency errors now show the extension title instead of the ID (https://github.com/flarum/core/pull/2563)
|
||||||
|
- Change `mutate` method on ApiSerializer extender to `attributes` (https://github.com/flarum/core/pull/2578)
|
||||||
|
- Moved locale files to the core from the language pack (https://github.com/flarum/core/pull/2408)
|
||||||
|
- AdminPage extensibility and generic improvements (https://github.com/flarum/core/pull/2593)
|
||||||
|
- Remove entry of authors, link to https://flarum.org/team (https://github.com/flarum/core/pull/2625)
|
||||||
|
- Search and filtering are split (https://github.com/flarum/core/pull/2454)
|
||||||
|
- Move IP identification into a middleware (https://github.com/flarum/core/pull/2624)
|
||||||
|
- Editor Driver abstraction introduced (https://github.com/flarum/core/pull/2594)
|
||||||
|
- Allow overriding routes (https://github.com/flarum/core/pull/2577)
|
||||||
|
- Split user edit permissions into permissions for editing of user credentials, username, groups and suspending (https://github.com/flarum/core/pull/2620)
|
||||||
|
- Reduced number of admin extension categories (https://github.com/flarum/core/pull/2604)
|
||||||
|
- Move search related classes to a dedicated Query namespace (https://github.com/flarum/core/pull/2645)
|
||||||
|
- Rewrite common helpers into typescript (https://github.com/flarum/core/pull/2541)
|
||||||
|
- `TextEditor` is moved to the common namespace for use in the admin frontend (https://github.com/flarum/core/pull/2649)
|
||||||
|
- Update Laravel/Illuminate components to 8 (https://github.com/flarum/core/pull/2576)
|
||||||
|
- Eager load relations in discussion listing to improve performance (https://github.com/flarum/core/pull/2639)
|
||||||
|
- Adopt flarum/testing package (https://github.com/flarum/core/pull/2545)
|
||||||
|
- Replace `user` gambit with `author` gambit ([612a57c](https://github.com/flarum/core/commit/612a57c4664415a3ea120103483645c32acc6f12))
|
||||||
|
- Posts page of on user profile loads posts using username instead of id ([30017ee](https://github.com/flarum/core/commit/30017eef09ae9e78640c4e2cacd4909fffa8d775))
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Transform css breaks iOS scroll functionality (https://github.com/flarum/core/pull/2527)
|
||||||
|
- Composer header is hidden on mobile devices (https://github.com/flarum/core/pull/2279)
|
||||||
|
- Cannot delete a post or discussion of a deleted user (https://github.com/flarum/core/pull/2521)
|
||||||
|
- DiscussionListPane jumps around not keeping the scroll position (https://github.com/flarum/core/pull/2402)
|
||||||
|
- Infinite scroll on notifications dropdown broken (https://github.com/flarum/core/pull/2524)
|
||||||
|
- The show language selector switch remains toggled on ([9347b12](https://github.com/flarum/core/commit/9347b12b47bf4ab97ffb7ca92673604b237c1012))
|
||||||
|
- Model Visibility extender throws exception on extensions that aren't installed or enabled (https://github.com/flarum/core/pull/2580)
|
||||||
|
- Extensions are marked as enabled when enabling fails to unmet extension dependencies (https://github.com/flarum/core/pull/2558)
|
||||||
|
- Routes to admin extension pages without a valid ID break the admin page (https://github.com/flarum/core/pull/2584)
|
||||||
|
- Disabled fieldset use an incorrect CSS property `disallowed` (https://github.com/flarum/core/pull/2585)
|
||||||
|
- Scrolling to a post that is already loaded the Load More button shows and does not trigger (https://github.com/flarum/core/pull/2388)
|
||||||
|
- Opening discussions on some mobile devices require a double tap (https://github.com/flarum/core/pull/2607)
|
||||||
|
- iOS devices show erratic behavior in the post stream while updating (https://github.com/flarum/core/pull/2548)
|
||||||
|
- Small mobile screens partially hides the composer when the keyboard is open (https://github.com/flarum/core/pull/2631)
|
||||||
|
- Clearing cache does not clear the template cache in storage/views (https://github.com/flarum/core/pull/2648)
|
||||||
|
- Boot errors show critical information (https://github.com/flarum/core/pull/2633)
|
||||||
|
- List user endpoint discloses last online even if user choose against it (https://github.com/flarum/core/pull/2634)
|
||||||
|
- Group gambit disclosed hidden groups (https://github.com/flarum/core/pull/2657)
|
||||||
|
- Search results on small windows not fully visible (https://github.com/flarum/core/pull/2650)
|
||||||
|
- Composer goes off screen on Safari when starting to type (https://github.com/flarum/core/pull/2660)
|
||||||
|
- A search that has no results shows the search results dropdown ([b88a7cb](https://github.com/flarum/core/commit/b88a7cb33b56e318f11670e9e2d563aef94db039))
|
||||||
|
- The composer modal moves around when typing on Safari ([a64c398](https://github.com/flarum/core/commit/a64c39835aba43e831209609f4a9638ae589aa41))
|
||||||
|
|
||||||
|
### Removed
|
||||||
|
- Deprecated CSRF wildcard path match
|
||||||
|
- Deprecated policy and visibility scoping events
|
||||||
|
- Deprecated post types event
|
||||||
|
- Deprecated validation events
|
||||||
|
- Deprecated notification events
|
||||||
|
- Deprecated floodgate
|
||||||
|
- Deprecated user preferences event
|
||||||
|
- Deprecated formatting events
|
||||||
|
- Deprecated api events
|
||||||
|
- Deprecated bootstrap.php support
|
||||||
|
- PHP 7.2 support (https://github.com/flarum/core/pull/2507)
|
||||||
|
- Bidi attribute in the rendered HTML (https://github.com/flarum/core/pull/2602)
|
||||||
|
- `AccessToken::find`, use `AccessToken::findValid` instead (https://github.com/flarum/core/pull/2651)
|
||||||
|
|
||||||
|
### Deprecated
|
||||||
|
- `GetModelIsPrivate` event (https://github.com/flarum/core/pull/2587)
|
||||||
|
- `CheckingPassword` event (https://github.com/flarum/core/pull/2176)
|
||||||
|
- `event()` helper (https://github.com/flarum/core/pull/2608)
|
||||||
|
- `AccessToken::generate` argument `$lifetime` (https://github.com/flarum/core/pull/2651)
|
||||||
|
- `Rememberer::remember` argument `$token` should receive an instance of `RememberAccessToken` with `AccessToken` being deprecated (https://github.com/flarum/core/pull/2651)
|
||||||
|
- `Rememberer::rememberUser` (https://github.com/flarum/core/pull/2651)
|
||||||
|
- `SessionAuthenticator::logIn` argument `$userId`, should be replaced with `AccessToken` (https://github.com/flarum/core/pull/2651)
|
||||||
|
- `TextEditor` has been moved to `common` (https://github.com/flarum/core/pull/2649)
|
||||||
|
- `UserFilter` ([91e8b56](https://github.com/flarum/core/commit/91e8b569618957c86757ef89bac666e9102db5ae))
|
||||||
|
|
||||||
|
|
||||||
|
## [0.1.0-beta.15](https://github.com/flarum/core/compare/v0.1.0-beta.14.1...v0.1.0-beta.15)
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Slug drivers support (https://github.com/flarum/core/pull/2456).
|
||||||
|
- Notification type extender (https://github.com/flarum/core/pull/2424).
|
||||||
|
- Validation extender (https://github.com/flarum/core/pull/2102).
|
||||||
|
- Post extender (https://github.com/flarum/core/pull/2101).
|
||||||
|
- Notification channel extender (https://github.com/flarum/core/pull/2432).
|
||||||
|
- Service provider extender (https://github.com/flarum/core/pull/2437).
|
||||||
|
- API serializer extender (https://github.com/flarum/core/pull/2438).
|
||||||
|
- User preferences extender (https://github.com/flarum/core/pull/2463).
|
||||||
|
- Settings extender (https://github.com/flarum/core/pull/2452).
|
||||||
|
- ApiController extender (https://github.com/flarum/core/pull/2451).
|
||||||
|
- Model visibility extender (https://github.com/flarum/core/pull/2460).
|
||||||
|
- Policy extender (https://github.com/flarum/core/pull/2461).
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Time helpers converted to Typescript (https://github.com/flarum/core/pull/2391).
|
||||||
|
- Improved the formatter extender (https://github.com/flarum/core/pull/2098).
|
||||||
|
- Improve wording on installer when facing file permission issues (https://github.com/flarum/core/pull/2435).
|
||||||
|
- Background color of checkbox toggles improved for better usability (https://github.com/flarum/core/pull/2443).
|
||||||
|
- Route resolving refactored (https://github.com/flarum/core/pull/2425).
|
||||||
|
- Administration panel UX refactored (https://github.com/flarum/core/pull/2409).
|
||||||
|
- Floodgate moved to middleware and extender added (https://github.com/flarum/core/pull/2170).
|
||||||
|
- DRY up image uploading logic (https://github.com/flarum/core/pull/2477).
|
||||||
|
- Process isolation on testing (https://github.com/flarum/core/commit/984f751c718c89501cc09857bc271efa2c7eea8c).
|
||||||
|
- Forum and admin javascript exports namespaced (https://github.com/flarum/core/pull/2488).
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Web updater does not take into account subfolder installations (https://github.com/flarum/core/pull/2426).
|
||||||
|
- Callables handling in extenders failed (https://github.com/flarum/core/pull/2423).
|
||||||
|
- Scrolling on mobile from PostSteam changes didn't work correctly (https://github.com/flarum/core/pull/2385).
|
||||||
|
- Side pane covers part of the discussion page due to `app.discussions` being empty (https://github.com/flarum/core/commit/102e76b084bf47fdfb4c73f95e1fbb322537f7aa).
|
||||||
|
- Change email modal keeps showing the previous error message even on success (https://github.com/flarum/core/pull/2467).
|
||||||
|
- Comment count not updated when discussions are deleted (https://github.com/flarum/core/pull/2472).
|
||||||
|
- `goToIndex` in PostStream does not trigger an xhr to retrieve new data (https://github.com/flarum/core/commit/09e2736cbcc267594b660beabbd001d9030f9880).
|
||||||
|
- On refresh the post number is reduced by one (https://github.com/flarum/core/pull/2476).
|
||||||
|
- Queue worker would instantiate a new Queue factory, not the bound one (https://github.com/flarum/core/pull/2481).
|
||||||
|
- Header accidentally has a border bottom (https://github.com/flarum/core/pull/2489).
|
||||||
|
- Namespace mentioned in docblock is incorrect (https://github.com/flarum/core/pull/2494).
|
||||||
|
- Scrolling inside longer discussions (especially Firefox) skips posts (https://github.com/flarum/core/commit/210a6b3e253d7917bd1eacd3ed8d2f95073ae99d).
|
||||||
|
- Uploading avatars that are jpg/jpeg fails with a validation error (https://github.com/flarum/core/pull/2497).
|
||||||
|
|
||||||
|
### Removed
|
||||||
|
|
||||||
|
- MomentJS alias (https://github.com/flarum/core/pull/2428).
|
||||||
|
- Deprecated user events `GetDisplayName` and `PrepareUserGroups` (https://github.com/flarum/core/pull/2428).
|
||||||
|
- AssertPermissionTrait (https://github.com/flarum/core/pull/2428).
|
||||||
|
- Path related helpers and methods in Application (https://github.com/flarum/core/pull/2428).
|
||||||
|
- Backward compatibility layers from the frontend rewrite (https://github.com/flarum/core/pull/2428).
|
||||||
|
|
||||||
|
### Deprecated
|
||||||
|
|
||||||
|
- `CheckingForFlooding` (https://github.com/flarum/core/commit/8e25bcb68f86cc992c46dfa70368419fe9f936ac).
|
||||||
|
|
||||||
|
## [0.1.0-beta.14.1](https://github.com/flarum/core/compare/v0.1.0-beta.14...v0.1.0-beta.14.1)
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- SuperTextarea component is not exported.
|
||||||
|
- Symfony dependencies do not match those depended on by Laravel (https://github.com/flarum/core/pull/2407).
|
||||||
|
- Scripts from textformatter aren't executed (https://github.com/flarum/core/pull/2415)
|
||||||
|
- Sub path installations have no page title.
|
||||||
|
- Losing focus of Composer area when coming from fullscreen.
|
||||||
|
|
||||||
## [0.1.0-beta.14](https://github.com/flarum/core/compare/v0.1.0-beta.13...v0.1.0-beta.14)
|
## [0.1.0-beta.14](https://github.com/flarum/core/compare/v0.1.0-beta.13...v0.1.0-beta.14)
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
@@ -142,7 +301,7 @@
|
|||||||
- SES mail support (#2011)
|
- SES mail support (#2011)
|
||||||
- Backward compatibility layer for `Flarum\Mail\DriverInterface`, new methods from beta.12 are now required
|
- Backward compatibility layer for `Flarum\Mail\DriverInterface`, new methods from beta.12 are now required
|
||||||
- `Flarum\Util\Str` helper class
|
- `Flarum\Util\Str` helper class
|
||||||
- `Flarum\Event\ConfigureMiddleware` event
|
- `Flarum\Event\ConfigureMiddleware` event
|
||||||
|
|
||||||
### Deprecated
|
### Deprecated
|
||||||
- `Flarum\Event\AbstractConfigureRoutes` event class
|
- `Flarum\Event\AbstractConfigureRoutes` event class
|
||||||
|
@@ -1,36 +1,17 @@
|
|||||||
{
|
{
|
||||||
"name": "flarum/core",
|
"name": "flarum/core",
|
||||||
"description": "Delightfully simple forum software.",
|
"description": "Delightfully simple forum software.",
|
||||||
"keywords": ["forum", "discussion"],
|
"keywords": [
|
||||||
|
"forum",
|
||||||
|
"discussion"
|
||||||
|
],
|
||||||
"homepage": "https://flarum.org/",
|
"homepage": "https://flarum.org/",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "Franz Liedke",
|
"name": "Flarum",
|
||||||
"email": "franz@develophp.org"
|
"email": "info@flarum.org",
|
||||||
},
|
"homepage": "https://flarum.org/team"
|
||||||
{
|
|
||||||
"name": "Daniël Klabbers",
|
|
||||||
"email": "daniel@klabbers.email",
|
|
||||||
"homepage": "https://luceos.com"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "David Sevilla Martin",
|
|
||||||
"email": "me+flarum@datitisev.me",
|
|
||||||
"homepage": "https://datitisev.me"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Clark Winkelmann",
|
|
||||||
"email": "clark.winkelmann@gmail.com",
|
|
||||||
"homepage": "https://clarkwinkelmann.com"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Matthew Kilgore",
|
|
||||||
"email": "matthew@kilgore.dev"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Alexander (Sasha) Skvortsov",
|
|
||||||
"email": "askvortsov@flarum.org"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"support": {
|
"support": {
|
||||||
@@ -39,36 +20,38 @@
|
|||||||
"docs": "https://flarum.org/docs/"
|
"docs": "https://flarum.org/docs/"
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=7.2",
|
"php": ">=7.3",
|
||||||
"axy/sourcemap": "^0.1.4",
|
"axy/sourcemap": "^0.1.4",
|
||||||
"components/font-awesome": "^5.14.0",
|
"components/font-awesome": "^5.14.0",
|
||||||
"dflydev/fig-cookies": "^2.0.1",
|
"dflydev/fig-cookies": "^3.0.0",
|
||||||
"doctrine/dbal": "^2.7",
|
"doctrine/dbal": "^2.7",
|
||||||
"franzl/whoops-middleware": "^0.4.0",
|
"dragonmantank/cron-expression": "^3.1.0",
|
||||||
"illuminate/bus": "^6.0",
|
"franzl/whoops-middleware": "^2.0.0",
|
||||||
"illuminate/cache": "^6.0",
|
"illuminate/bus": "^8.0",
|
||||||
"illuminate/config": "^6.0",
|
"illuminate/cache": "^8.0",
|
||||||
"illuminate/container": "^6.0",
|
"illuminate/config": "^8.0",
|
||||||
"illuminate/contracts": "^6.0",
|
"illuminate/console": "^8.0",
|
||||||
"illuminate/database": "^6.0",
|
"illuminate/container": "^8.0",
|
||||||
"illuminate/events": "^6.0",
|
"illuminate/contracts": "^8.0",
|
||||||
"illuminate/filesystem": "^6.0",
|
"illuminate/database": "^8.0",
|
||||||
"illuminate/hashing": "^6.0",
|
"illuminate/events": "^8.0",
|
||||||
"illuminate/mail": "^6.0",
|
"illuminate/filesystem": "^8.0",
|
||||||
"illuminate/queue": "^6.0",
|
"illuminate/hashing": "^8.0",
|
||||||
"illuminate/session": "^6.0",
|
"illuminate/mail": "^8.0",
|
||||||
"illuminate/support": "^6.0",
|
"illuminate/queue": "^8.0",
|
||||||
"illuminate/validation": "^6.0",
|
"illuminate/session": "^8.0",
|
||||||
"illuminate/view": "^6.0",
|
"illuminate/support": "^8.0",
|
||||||
|
"illuminate/validation": "^8.0",
|
||||||
|
"illuminate/view": "^8.0",
|
||||||
"intervention/image": "^2.5.0",
|
"intervention/image": "^2.5.0",
|
||||||
"laminas/laminas-diactoros": "^1.8.4",
|
"laminas/laminas-diactoros": "^2.4.1",
|
||||||
"laminas/laminas-httphandlerrunner": "^1.0",
|
"laminas/laminas-httphandlerrunner": "^1.2.0",
|
||||||
"laminas/laminas-stratigility": "^3.0",
|
"laminas/laminas-stratigility": "^3.2.2",
|
||||||
"league/flysystem": "^1.0.11",
|
"league/flysystem": "^1.0.11",
|
||||||
"matthiasmullie/minify": "^1.3",
|
"matthiasmullie/minify": "^1.3",
|
||||||
"middlewares/base-path": "^1.1",
|
"middlewares/base-path": "^2.0.1",
|
||||||
"middlewares/base-path-router": "^0.2.1",
|
"middlewares/base-path-router": "^2.0.1",
|
||||||
"middlewares/request-handler": "^1.2",
|
"middlewares/request-handler": "^2.0.1",
|
||||||
"monolog/monolog": "^1.16.0",
|
"monolog/monolog": "^1.16.0",
|
||||||
"nesbot/carbon": "^2.0",
|
"nesbot/carbon": "^2.0",
|
||||||
"nikic/fast-route": "^0.6",
|
"nikic/fast-route": "^0.6",
|
||||||
@@ -76,17 +59,17 @@
|
|||||||
"psr/http-server-handler": "^1.0",
|
"psr/http-server-handler": "^1.0",
|
||||||
"psr/http-server-middleware": "^1.0",
|
"psr/http-server-middleware": "^1.0",
|
||||||
"s9e/text-formatter": "^2.3.6",
|
"s9e/text-formatter": "^2.3.6",
|
||||||
"symfony/config": "^4.3.4",
|
"symfony/config": "^5.2.2",
|
||||||
"symfony/console": "^4.3.4",
|
"symfony/console": "^5.2.2",
|
||||||
"symfony/event-dispatcher": "^4.3.4",
|
"symfony/event-dispatcher": "^5.2.2",
|
||||||
"symfony/translation": "^4.3.4",
|
"symfony/mime": "^5.2.0",
|
||||||
"symfony/yaml": "^4.3.4",
|
"symfony/translation": "^5.1.5",
|
||||||
|
"symfony/yaml": "^5.2.2",
|
||||||
"tobscure/json-api": "^0.3.0",
|
"tobscure/json-api": "^0.3.0",
|
||||||
"wikimedia/less.php": "^3.0"
|
"wikimedia/less.php": "^3.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"mockery/mockery": "^1.0",
|
"flarum/testing": "^0.1.0-beta.16"
|
||||||
"phpunit/phpunit": "^7.0"
|
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
8
js/.bundlewatch.config.json
Normal file
8
js/.bundlewatch.config.json
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"files": [
|
||||||
|
{
|
||||||
|
"path": "./dist/*.js"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"defaultCompression": "gzip"
|
||||||
|
}
|
16
js/dist/admin.js
vendored
16
js/dist/admin.js
vendored
File diff suppressed because one or more lines are too long
2
js/dist/admin.js.map
vendored
2
js/dist/admin.js.map
vendored
File diff suppressed because one or more lines are too long
18
js/dist/forum.js
vendored
18
js/dist/forum.js
vendored
File diff suppressed because one or more lines are too long
2
js/dist/forum.js.map
vendored
2
js/dist/forum.js.map
vendored
File diff suppressed because one or more lines are too long
12681
js/package-lock.json
generated
12681
js/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -2,32 +2,40 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"name": "@flarum/core",
|
"name": "@flarum/core",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/preset-typescript": "^7.10.1",
|
|
||||||
"@types/mithril": "^2.0.3",
|
|
||||||
"bootstrap": "^3.4.1",
|
"bootstrap": "^3.4.1",
|
||||||
"classnames": "^2.2.5",
|
"clsx": "^1.1.1",
|
||||||
"color-thief-browser": "^2.0.2",
|
"color-thief-browser": "^2.0.2",
|
||||||
"dayjs": "^1.8.28",
|
"dayjs": "^1.10.4",
|
||||||
"expose-loader": "^0.7.5",
|
"expose-loader": "^1.0.3",
|
||||||
"flarum-webpack-config": "0.1.0-beta.10",
|
"jquery": "^3.6.0",
|
||||||
"jquery": "^3.5.1",
|
|
||||||
"jquery.hotkeys": "^0.1.0",
|
"jquery.hotkeys": "^0.1.0",
|
||||||
"lodash-es": "^4.17.14",
|
"lodash-es": "^4.17.21",
|
||||||
"m.attrs.bidi": "github:tobscure/m.attrs.bidi",
|
|
||||||
"mithril": "^2.0.4",
|
"mithril": "^2.0.4",
|
||||||
"punycode": "^2.1.1",
|
"punycode": "^2.1.1",
|
||||||
"spin.js": "^3.1.0",
|
"spin.js": "^3.1.0",
|
||||||
"webpack": "^4.43.0",
|
"textarea-caret": "^3.1.0"
|
||||||
"webpack-cli": "^3.3.11",
|
|
||||||
"webpack-merge": "^4.1.4"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"husky": "^4.2.5",
|
"@babel/preset-typescript": "^7.13.0",
|
||||||
"prettier": "2.0.2"
|
"@types/jquery": "^3.5.5",
|
||||||
|
"@types/lodash-es": "^4.17.4",
|
||||||
|
"@types/mithril": "^2.0.7",
|
||||||
|
"@types/punycode": "^2.1.0",
|
||||||
|
"@types/textarea-caret": "^3.0.0",
|
||||||
|
"bundlewatch": "^0.3.2",
|
||||||
|
"cross-env": "^7.0.3",
|
||||||
|
"flarum-webpack-config": "0.1.0-beta.10",
|
||||||
|
"husky": "^4.3.8",
|
||||||
|
"prettier": "^2.2.1",
|
||||||
|
"webpack": "^4.46.0",
|
||||||
|
"webpack-bundle-analyzer": "^4.4.0",
|
||||||
|
"webpack-cli": "^3.3.12",
|
||||||
|
"webpack-merge": "^4.2.2"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "webpack --mode development --watch",
|
"dev": "webpack --mode development --watch",
|
||||||
"build": "webpack --mode production",
|
"build": "webpack --mode production",
|
||||||
|
"analyze": "cross-env ANALYZER=true npm run build",
|
||||||
"format": "prettier --write src",
|
"format": "prettier --write src",
|
||||||
"format-check": "prettier --check src"
|
"format-check": "prettier --check src"
|
||||||
},
|
},
|
||||||
|
14
js/shims.d.ts
vendored
14
js/shims.d.ts
vendored
@@ -19,9 +19,21 @@ import Application from './src/common/Application';
|
|||||||
* to (and should not) bundle these themselves.
|
* to (and should not) bundle these themselves.
|
||||||
*/
|
*/
|
||||||
declare global {
|
declare global {
|
||||||
const $: typeof _$;
|
// $ is already defined by `@types/jquery`
|
||||||
const m: Mithril.Static;
|
const m: Mithril.Static;
|
||||||
const dayjs: typeof _dayjs;
|
const dayjs: typeof _dayjs;
|
||||||
|
|
||||||
|
// Extend JQuery with our custom functions, defined with $.fn
|
||||||
|
interface JQuery {
|
||||||
|
/**
|
||||||
|
* Creates a tooltip on a jQuery element reference.
|
||||||
|
*
|
||||||
|
* Optionally accepts placement and delay options.
|
||||||
|
*
|
||||||
|
* Returns the same reference to allow for method chaining.
|
||||||
|
*/
|
||||||
|
tooltip: (tooltipOptions?: { placement?: 'top' | 'bottom' | 'left' | 'right'; delay?: number }) => JQuery;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -4,9 +4,16 @@ import routes from './routes';
|
|||||||
import Application from '../common/Application';
|
import Application from '../common/Application';
|
||||||
import Navigation from '../common/components/Navigation';
|
import Navigation from '../common/components/Navigation';
|
||||||
import AdminNav from './components/AdminNav';
|
import AdminNav from './components/AdminNav';
|
||||||
|
import ExtensionData from './utils/ExtensionData';
|
||||||
|
|
||||||
export default class AdminApplication extends Application {
|
export default class AdminApplication extends Application {
|
||||||
extensionSettings = {};
|
extensionData = new ExtensionData();
|
||||||
|
|
||||||
|
extensionCategories = {
|
||||||
|
feature: 30,
|
||||||
|
theme: 20,
|
||||||
|
language: 10,
|
||||||
|
};
|
||||||
|
|
||||||
history = {
|
history = {
|
||||||
canGoBack: () => true,
|
canGoBack: () => true,
|
||||||
@@ -34,19 +41,17 @@ export default class AdminApplication extends Application {
|
|||||||
m.route.prefix = '#';
|
m.route.prefix = '#';
|
||||||
super.mount();
|
super.mount();
|
||||||
|
|
||||||
m.mount(document.getElementById('app-navigation'), { view: () => Navigation.component({ className: 'App-backControl', drawer: true }) });
|
m.mount(document.getElementById('app-navigation'), {
|
||||||
|
view: () =>
|
||||||
|
Navigation.component({
|
||||||
|
className: 'App-backControl',
|
||||||
|
drawer: true,
|
||||||
|
}),
|
||||||
|
});
|
||||||
m.mount(document.getElementById('header-navigation'), Navigation);
|
m.mount(document.getElementById('header-navigation'), Navigation);
|
||||||
m.mount(document.getElementById('header-primary'), HeaderPrimary);
|
m.mount(document.getElementById('header-primary'), HeaderPrimary);
|
||||||
m.mount(document.getElementById('header-secondary'), HeaderSecondary);
|
m.mount(document.getElementById('header-secondary'), HeaderSecondary);
|
||||||
m.mount(document.getElementById('admin-navigation'), AdminNav);
|
m.mount(document.getElementById('admin-navigation'), AdminNav);
|
||||||
|
|
||||||
// If an extension has just been enabled, then we will run its settings
|
|
||||||
// callback.
|
|
||||||
const enabled = localStorage.getItem('enabledExtension');
|
|
||||||
if (enabled && this.extensionSettings[enabled]) {
|
|
||||||
this.extensionSettings[enabled]();
|
|
||||||
localStorage.removeItem('enabledExtension');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getRequiredPermissions(permission) {
|
getRequiredPermissions(permission) {
|
||||||
|
8
js/src/admin/app.ts
Normal file
8
js/src/admin/app.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import Admin from './AdminApplication';
|
||||||
|
|
||||||
|
const app = new Admin();
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
window.app = app;
|
||||||
|
|
||||||
|
export default app;
|
@@ -1,19 +1,24 @@
|
|||||||
import compat from '../common/compat';
|
import compat from '../common/compat';
|
||||||
|
|
||||||
import saveSettings from './utils/saveSettings';
|
import saveSettings from './utils/saveSettings';
|
||||||
|
import ExtensionData from './utils/ExtensionData';
|
||||||
|
import isExtensionEnabled from './utils/isExtensionEnabled';
|
||||||
|
import getCategorizedExtensions from './utils/getCategorizedExtensions';
|
||||||
import SettingDropdown from './components/SettingDropdown';
|
import SettingDropdown from './components/SettingDropdown';
|
||||||
import EditCustomFooterModal from './components/EditCustomFooterModal';
|
import EditCustomFooterModal from './components/EditCustomFooterModal';
|
||||||
import SessionDropdown from './components/SessionDropdown';
|
import SessionDropdown from './components/SessionDropdown';
|
||||||
import HeaderPrimary from './components/HeaderPrimary';
|
import HeaderPrimary from './components/HeaderPrimary';
|
||||||
|
import AdminPage from './components/AdminPage';
|
||||||
import AppearancePage from './components/AppearancePage';
|
import AppearancePage from './components/AppearancePage';
|
||||||
import StatusWidget from './components/StatusWidget';
|
import StatusWidget from './components/StatusWidget';
|
||||||
|
import ExtensionsWidget from './components/ExtensionsWidget';
|
||||||
import HeaderSecondary from './components/HeaderSecondary';
|
import HeaderSecondary from './components/HeaderSecondary';
|
||||||
import SettingsModal from './components/SettingsModal';
|
import SettingsModal from './components/SettingsModal';
|
||||||
import DashboardWidget from './components/DashboardWidget';
|
import DashboardWidget from './components/DashboardWidget';
|
||||||
import AddExtensionModal from './components/AddExtensionModal';
|
import ExtensionPage from './components/ExtensionPage';
|
||||||
import ExtensionsPage from './components/ExtensionsPage';
|
import ExtensionLinkButton from './components/ExtensionLinkButton';
|
||||||
import AdminLinkButton from './components/AdminLinkButton';
|
|
||||||
import PermissionGrid from './components/PermissionGrid';
|
import PermissionGrid from './components/PermissionGrid';
|
||||||
|
import ExtensionPermissionGrid from './components/ExtensionPermissionGrid';
|
||||||
import MailPage from './components/MailPage';
|
import MailPage from './components/MailPage';
|
||||||
import UploadImageButton from './components/UploadImageButton';
|
import UploadImageButton from './components/UploadImageButton';
|
||||||
import LoadingModal from './components/LoadingModal';
|
import LoadingModal from './components/LoadingModal';
|
||||||
@@ -23,6 +28,7 @@ import EditCustomHeaderModal from './components/EditCustomHeaderModal';
|
|||||||
import PermissionsPage from './components/PermissionsPage';
|
import PermissionsPage from './components/PermissionsPage';
|
||||||
import PermissionDropdown from './components/PermissionDropdown';
|
import PermissionDropdown from './components/PermissionDropdown';
|
||||||
import AdminNav from './components/AdminNav';
|
import AdminNav from './components/AdminNav';
|
||||||
|
import AdminHeader from './components/AdminHeader';
|
||||||
import EditCustomCssModal from './components/EditCustomCssModal';
|
import EditCustomCssModal from './components/EditCustomCssModal';
|
||||||
import EditGroupModal from './components/EditGroupModal';
|
import EditGroupModal from './components/EditGroupModal';
|
||||||
import routes from './routes';
|
import routes from './routes';
|
||||||
@@ -30,19 +36,24 @@ import AdminApplication from './AdminApplication';
|
|||||||
|
|
||||||
export default Object.assign(compat, {
|
export default Object.assign(compat, {
|
||||||
'utils/saveSettings': saveSettings,
|
'utils/saveSettings': saveSettings,
|
||||||
|
'utils/ExtensionData': ExtensionData,
|
||||||
|
'utils/isExtensionEnabled': isExtensionEnabled,
|
||||||
|
'utils/getCategorizedExtensions': getCategorizedExtensions,
|
||||||
'components/SettingDropdown': SettingDropdown,
|
'components/SettingDropdown': SettingDropdown,
|
||||||
'components/EditCustomFooterModal': EditCustomFooterModal,
|
'components/EditCustomFooterModal': EditCustomFooterModal,
|
||||||
'components/SessionDropdown': SessionDropdown,
|
'components/SessionDropdown': SessionDropdown,
|
||||||
'components/HeaderPrimary': HeaderPrimary,
|
'components/HeaderPrimary': HeaderPrimary,
|
||||||
|
'components/AdminPage': AdminPage,
|
||||||
'components/AppearancePage': AppearancePage,
|
'components/AppearancePage': AppearancePage,
|
||||||
'components/StatusWidget': StatusWidget,
|
'components/StatusWidget': StatusWidget,
|
||||||
|
'components/ExtensionsWidget': ExtensionsWidget,
|
||||||
'components/HeaderSecondary': HeaderSecondary,
|
'components/HeaderSecondary': HeaderSecondary,
|
||||||
'components/SettingsModal': SettingsModal,
|
'components/SettingsModal': SettingsModal,
|
||||||
'components/DashboardWidget': DashboardWidget,
|
'components/DashboardWidget': DashboardWidget,
|
||||||
'components/AddExtensionModal': AddExtensionModal,
|
'components/ExtensionPage': ExtensionPage,
|
||||||
'components/ExtensionsPage': ExtensionsPage,
|
'components/ExtensionLinkButton': ExtensionLinkButton,
|
||||||
'components/AdminLinkButton': AdminLinkButton,
|
|
||||||
'components/PermissionGrid': PermissionGrid,
|
'components/PermissionGrid': PermissionGrid,
|
||||||
|
'components/ExtensionPermissionGrid': ExtensionPermissionGrid,
|
||||||
'components/MailPage': MailPage,
|
'components/MailPage': MailPage,
|
||||||
'components/UploadImageButton': UploadImageButton,
|
'components/UploadImageButton': UploadImageButton,
|
||||||
'components/LoadingModal': LoadingModal,
|
'components/LoadingModal': LoadingModal,
|
||||||
@@ -52,6 +63,7 @@ export default Object.assign(compat, {
|
|||||||
'components/PermissionsPage': PermissionsPage,
|
'components/PermissionsPage': PermissionsPage,
|
||||||
'components/PermissionDropdown': PermissionDropdown,
|
'components/PermissionDropdown': PermissionDropdown,
|
||||||
'components/AdminNav': AdminNav,
|
'components/AdminNav': AdminNav,
|
||||||
|
'components/AdminHeader': AdminHeader,
|
||||||
'components/EditCustomCssModal': EditCustomCssModal,
|
'components/EditCustomCssModal': EditCustomCssModal,
|
||||||
'components/EditGroupModal': EditGroupModal,
|
'components/EditGroupModal': EditGroupModal,
|
||||||
routes: routes,
|
routes: routes,
|
||||||
|
@@ -1,32 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of Flarum.
|
|
||||||
*
|
|
||||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import Modal from '../../common/components/Modal';
|
|
||||||
|
|
||||||
export default class AddExtensionModal extends Modal {
|
|
||||||
className() {
|
|
||||||
return 'AddExtensionModal Modal--small';
|
|
||||||
}
|
|
||||||
|
|
||||||
title() {
|
|
||||||
return app.translator.trans('core.admin.add_extension.title');
|
|
||||||
}
|
|
||||||
|
|
||||||
content() {
|
|
||||||
return (
|
|
||||||
<div className="Modal-body">
|
|
||||||
<p>{app.translator.trans('core.admin.add_extension.temporary_text')}</p>
|
|
||||||
<p>
|
|
||||||
{app.translator.trans('core.admin.add_extension.install_text', { a: <a href="https://discuss.flarum.org/t/extensions" target="_blank" /> })}
|
|
||||||
</p>
|
|
||||||
<p>{app.translator.trans('core.admin.add_extension.developer_text', { a: <a href="http://flarum.org/docs/extend" target="_blank" /> })}</p>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
19
js/src/admin/components/AdminHeader.js
Normal file
19
js/src/admin/components/AdminHeader.js
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import Component from '../../common/Component';
|
||||||
|
import classList from '../../common/utils/classList';
|
||||||
|
import icon from '../../common/helpers/icon';
|
||||||
|
|
||||||
|
export default class AdminHeader extends Component {
|
||||||
|
view(vnode) {
|
||||||
|
return [
|
||||||
|
<div className={classList(['AdminHeader', this.attrs.className])}>
|
||||||
|
<div className="container">
|
||||||
|
<h2>
|
||||||
|
{icon(this.attrs.icon)}
|
||||||
|
{vnode.children}
|
||||||
|
</h2>
|
||||||
|
<div className="AdminHeader-description">{this.attrs.description}</div>
|
||||||
|
</div>
|
||||||
|
</div>,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
@@ -1,16 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of Flarum.
|
|
||||||
*
|
|
||||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import LinkButton from '../../common/components/LinkButton';
|
|
||||||
|
|
||||||
export default class AdminLinkButton extends LinkButton {
|
|
||||||
getButtonContent(children) {
|
|
||||||
return [...super.getButtonContent(children), <div className="AdminLinkButton-description">{this.attrs.description}</div>];
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,106 +1,151 @@
|
|||||||
/*
|
import ExtensionLinkButton from './ExtensionLinkButton';
|
||||||
* This file is part of Flarum.
|
|
||||||
*
|
|
||||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import Component from '../../common/Component';
|
import Component from '../../common/Component';
|
||||||
import AdminLinkButton from './AdminLinkButton';
|
import LinkButton from '../../common/components/LinkButton';
|
||||||
import SelectDropdown from '../../common/components/SelectDropdown';
|
import SelectDropdown from '../../common/components/SelectDropdown';
|
||||||
|
import getCategorizedExtensions from '../utils/getCategorizedExtensions';
|
||||||
import ItemList from '../../common/utils/ItemList';
|
import ItemList from '../../common/utils/ItemList';
|
||||||
|
import Stream from '../../common/utils/Stream';
|
||||||
|
|
||||||
export default class AdminNav extends Component {
|
export default class AdminNav extends Component {
|
||||||
|
oninit(vnode) {
|
||||||
|
super.oninit(vnode);
|
||||||
|
|
||||||
|
this.query = Stream('');
|
||||||
|
}
|
||||||
|
|
||||||
view() {
|
view() {
|
||||||
return (
|
return (
|
||||||
<SelectDropdown className="AdminNav App-titleControl" buttonClassName="Button">
|
<SelectDropdown className="AdminNav App-titleControl AdminNav-Main" buttonClassName="Button">
|
||||||
{this.items().toArray()}
|
{this.items().toArray().concat(this.extensionItems().toArray())}
|
||||||
</SelectDropdown>
|
</SelectDropdown>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
oncreate(vnode) {
|
||||||
|
super.oncreate(vnode);
|
||||||
|
|
||||||
|
this.scrollToActive();
|
||||||
|
}
|
||||||
|
|
||||||
|
onupdate() {
|
||||||
|
this.scrollToActive();
|
||||||
|
}
|
||||||
|
|
||||||
|
scrollToActive() {
|
||||||
|
const children = $('.Dropdown-menu').children('.active');
|
||||||
|
const nav = $('#admin-navigation');
|
||||||
|
const time = app.previous.type ? 250 : 0;
|
||||||
|
|
||||||
|
if (
|
||||||
|
children.length > 0 &&
|
||||||
|
(children[0].offsetTop > nav.scrollTop() + nav.outerHeight() || children[0].offsetTop + children[0].offsetHeight < nav.scrollTop())
|
||||||
|
) {
|
||||||
|
nav.animate(
|
||||||
|
{
|
||||||
|
scrollTop: children[0].offsetTop - nav.height() / 2,
|
||||||
|
},
|
||||||
|
time
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build an item list of links to show in the admin navigation.
|
* Build an item list of main links to show in the admin navigation.
|
||||||
*
|
*
|
||||||
* @return {ItemList}
|
* @return {ItemList}
|
||||||
*/
|
*/
|
||||||
items() {
|
items() {
|
||||||
const items = new ItemList();
|
const items = new ItemList();
|
||||||
|
|
||||||
|
items.add('category-core', <h4 className="ExtensionListTitle">{app.translator.trans('core.admin.nav.categories.core')}</h4>);
|
||||||
|
|
||||||
items.add(
|
items.add(
|
||||||
'dashboard',
|
'dashboard',
|
||||||
AdminLinkButton.component(
|
<LinkButton href={app.route('dashboard')} icon="far fa-chart-bar" title={app.translator.trans('core.admin.nav.dashboard_title')}>
|
||||||
{
|
{app.translator.trans('core.admin.nav.dashboard_button')}
|
||||||
href: app.route('dashboard'),
|
</LinkButton>
|
||||||
icon: 'far fa-chart-bar',
|
|
||||||
description: app.translator.trans('core.admin.nav.dashboard_text'),
|
|
||||||
},
|
|
||||||
app.translator.trans('core.admin.nav.dashboard_button')
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
items.add(
|
items.add(
|
||||||
'basics',
|
'basics',
|
||||||
AdminLinkButton.component(
|
<LinkButton href={app.route('basics')} icon="fas fa-pencil-alt" title={app.translator.trans('core.admin.nav.basics_title')}>
|
||||||
{
|
{app.translator.trans('core.admin.nav.basics_button')}
|
||||||
href: app.route('basics'),
|
</LinkButton>
|
||||||
icon: 'fas fa-pencil-alt',
|
|
||||||
description: app.translator.trans('core.admin.nav.basics_text'),
|
|
||||||
},
|
|
||||||
app.translator.trans('core.admin.nav.basics_button')
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
items.add(
|
items.add(
|
||||||
'mail',
|
'mail',
|
||||||
AdminLinkButton.component(
|
<LinkButton href={app.route('mail')} icon="fas fa-envelope" title={app.translator.trans('core.admin.nav.email_title')}>
|
||||||
{
|
{app.translator.trans('core.admin.nav.email_button')}
|
||||||
href: app.route('mail'),
|
</LinkButton>
|
||||||
icon: 'fas fa-envelope',
|
|
||||||
description: app.translator.trans('core.admin.nav.email_text'),
|
|
||||||
},
|
|
||||||
app.translator.trans('core.admin.nav.email_button')
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
items.add(
|
items.add(
|
||||||
'permissions',
|
'permissions',
|
||||||
AdminLinkButton.component(
|
<LinkButton href={app.route('permissions')} icon="fas fa-key" title={app.translator.trans('core.admin.nav.permissions_title')}>
|
||||||
{
|
{app.translator.trans('core.admin.nav.permissions_button')}
|
||||||
href: app.route('permissions'),
|
</LinkButton>
|
||||||
icon: 'fas fa-key',
|
|
||||||
description: app.translator.trans('core.admin.nav.permissions_text'),
|
|
||||||
},
|
|
||||||
app.translator.trans('core.admin.nav.permissions_button')
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
items.add(
|
items.add(
|
||||||
'appearance',
|
'appearance',
|
||||||
AdminLinkButton.component(
|
<LinkButton href={app.route('appearance')} icon="fas fa-paint-brush" title={app.translator.trans('core.admin.nav.appearance_title')}>
|
||||||
{
|
{app.translator.trans('core.admin.nav.appearance_button')}
|
||||||
href: app.route('appearance'),
|
</LinkButton>
|
||||||
icon: 'fas fa-paint-brush',
|
|
||||||
description: app.translator.trans('core.admin.nav.appearance_text'),
|
|
||||||
},
|
|
||||||
app.translator.trans('core.admin.nav.appearance_button')
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
items.add(
|
items.add(
|
||||||
'extensions',
|
'search',
|
||||||
AdminLinkButton.component(
|
<div className="Search-input">
|
||||||
{
|
<input
|
||||||
href: app.route('extensions'),
|
className="FormControl SearchBar"
|
||||||
icon: 'fas fa-puzzle-piece',
|
bidi={this.query}
|
||||||
description: app.translator.trans('core.admin.nav.extensions_text'),
|
type="search"
|
||||||
},
|
placeholder={app.translator.trans('core.admin.nav.search_placeholder')}
|
||||||
app.translator.trans('core.admin.nav.extensions_button')
|
/>
|
||||||
)
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extensionItems() {
|
||||||
|
const items = new ItemList();
|
||||||
|
|
||||||
|
const categorizedExtensions = getCategorizedExtensions();
|
||||||
|
const categories = app.extensionCategories;
|
||||||
|
|
||||||
|
Object.keys(categorizedExtensions).map((category) => {
|
||||||
|
if (!this.query()) {
|
||||||
|
items.add(
|
||||||
|
`category-${category}`,
|
||||||
|
<h4 className="ExtensionListTitle">{app.translator.trans(`core.admin.nav.categories.${category}`)}</h4>,
|
||||||
|
categories[category]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
categorizedExtensions[category].map((extension) => {
|
||||||
|
const query = this.query().toUpperCase();
|
||||||
|
const title = extension.extra['flarum-extension'].title || '';
|
||||||
|
const description = extension.description || '';
|
||||||
|
|
||||||
|
if (!query || title.toUpperCase().includes(query) || description.toUpperCase().includes(query)) {
|
||||||
|
items.add(
|
||||||
|
`extension-${extension.id}`,
|
||||||
|
<ExtensionLinkButton
|
||||||
|
href={app.route('extension', { id: extension.id })}
|
||||||
|
extensionId={extension.id}
|
||||||
|
className="ExtensionNavButton"
|
||||||
|
title={description}
|
||||||
|
>
|
||||||
|
{title}
|
||||||
|
</ExtensionLinkButton>,
|
||||||
|
categories[category]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return items;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
180
js/src/admin/components/AdminPage.js
Normal file
180
js/src/admin/components/AdminPage.js
Normal file
@@ -0,0 +1,180 @@
|
|||||||
|
import Page from '../../common/components/Page';
|
||||||
|
import Button from '../../common/components/Button';
|
||||||
|
import Switch from '../../common/components/Switch';
|
||||||
|
import Select from '../../common/components/Select';
|
||||||
|
import classList from '../../common/utils/classList';
|
||||||
|
import Stream from '../../common/utils/Stream';
|
||||||
|
import saveSettings from '../utils/saveSettings';
|
||||||
|
import AdminHeader from './AdminHeader';
|
||||||
|
|
||||||
|
export default class AdminPage extends Page {
|
||||||
|
oninit(vnode) {
|
||||||
|
super.oninit(vnode);
|
||||||
|
|
||||||
|
this.settings = {};
|
||||||
|
|
||||||
|
this.loading = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
view() {
|
||||||
|
const className = classList(['AdminPage', this.headerInfo().className]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={className}>
|
||||||
|
{this.header()}
|
||||||
|
<div className="container">{this.content()}</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
content() {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
submitButton() {
|
||||||
|
return (
|
||||||
|
<Button onclick={this.saveSettings.bind(this)} className="Button Button--primary" loading={this.loading} disabled={!this.isChanged()}>
|
||||||
|
{app.translator.trans('core.admin.settings.submit_button')}
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
header() {
|
||||||
|
const headerInfo = this.headerInfo();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AdminHeader icon={headerInfo.icon} description={headerInfo.description} className={headerInfo.className + '-header'}>
|
||||||
|
{headerInfo.title}
|
||||||
|
</AdminHeader>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
headerInfo() {
|
||||||
|
return {
|
||||||
|
className: '',
|
||||||
|
icon: '',
|
||||||
|
title: '',
|
||||||
|
description: '',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* buildSettingComponent takes a settings object and turns it into a component.
|
||||||
|
* Depending on the type of input, you can set the type to 'bool', 'select', or
|
||||||
|
* any standard <input> type. Any values inside the 'extra' object will be added
|
||||||
|
* to the component as an attribute.
|
||||||
|
*
|
||||||
|
* Alternatively, you can pass a callback that will be executed in ExtensionPage's
|
||||||
|
* context to include custom JSX elements.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
*
|
||||||
|
* {
|
||||||
|
* setting: 'acme.checkbox',
|
||||||
|
* label: app.translator.trans('acme.admin.setting_label'),
|
||||||
|
* type: 'bool',
|
||||||
|
* help: app.translator.trans('acme.admin.setting_help'),
|
||||||
|
* className: 'Setting-item'
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
*
|
||||||
|
* {
|
||||||
|
* setting: 'acme.select',
|
||||||
|
* label: app.translator.trans('acme.admin.setting_label'),
|
||||||
|
* type: 'select',
|
||||||
|
* options: {
|
||||||
|
* 'option1': 'Option 1 label',
|
||||||
|
* 'option2': 'Option 2 label',
|
||||||
|
* },
|
||||||
|
* default: 'option1',
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* @param setting
|
||||||
|
* @returns {JSX.Element}
|
||||||
|
*/
|
||||||
|
buildSettingComponent(entry) {
|
||||||
|
if (typeof entry === 'function') {
|
||||||
|
return entry.call(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { setting, help, ...componentAttrs } = entry;
|
||||||
|
|
||||||
|
delete componentAttrs.help;
|
||||||
|
|
||||||
|
const value = this.setting([setting])();
|
||||||
|
if (['bool', 'checkbox', 'switch', 'boolean'].includes(componentAttrs.type)) {
|
||||||
|
return (
|
||||||
|
<div className="Form-group">
|
||||||
|
<Switch state={!!value && value !== '0'} onchange={this.settings[setting]} {...componentAttrs}>
|
||||||
|
{componentAttrs.label}
|
||||||
|
</Switch>
|
||||||
|
<div className="helpText">{help}</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
} else if (['select', 'dropdown', 'selectdropdown'].includes(componentAttrs.type)) {
|
||||||
|
return (
|
||||||
|
<div className="Form-group">
|
||||||
|
<label>{componentAttrs.label}</label>
|
||||||
|
<div className="helpText">{help}</div>
|
||||||
|
<Select
|
||||||
|
value={value || componentAttrs.default}
|
||||||
|
options={componentAttrs.options}
|
||||||
|
buttonClassName="Button"
|
||||||
|
onchange={this.settings[setting]}
|
||||||
|
{...componentAttrs}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
componentAttrs.className = classList(['FormControl', componentAttrs.className]);
|
||||||
|
return (
|
||||||
|
<div className="Form-group">
|
||||||
|
{componentAttrs.label ? <label>{componentAttrs.label}</label> : ''}
|
||||||
|
<div className="helpText">{help}</div>
|
||||||
|
<input type={componentAttrs.type} bidi={this.setting(setting)} {...componentAttrs} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onsaved() {
|
||||||
|
this.loading = false;
|
||||||
|
|
||||||
|
app.alerts.show({ type: 'success' }, app.translator.trans('core.admin.settings.saved_message'));
|
||||||
|
}
|
||||||
|
|
||||||
|
setting(key, fallback = '') {
|
||||||
|
this.settings[key] = this.settings[key] || Stream(app.data.settings[key] || fallback);
|
||||||
|
|
||||||
|
return this.settings[key];
|
||||||
|
}
|
||||||
|
|
||||||
|
dirty() {
|
||||||
|
const dirty = {};
|
||||||
|
|
||||||
|
Object.keys(this.settings).forEach((key) => {
|
||||||
|
const value = this.settings[key]();
|
||||||
|
|
||||||
|
if (value !== app.data.settings[key]) {
|
||||||
|
dirty[key] = value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return dirty;
|
||||||
|
}
|
||||||
|
|
||||||
|
isChanged() {
|
||||||
|
return Object.keys(this.dirty()).length;
|
||||||
|
}
|
||||||
|
|
||||||
|
saveSettings(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
app.alerts.clear();
|
||||||
|
|
||||||
|
this.loading = true;
|
||||||
|
|
||||||
|
return saveSettings(this.dirty()).then(this.onsaved.bind(this));
|
||||||
|
}
|
||||||
|
}
|
@@ -1,133 +1,120 @@
|
|||||||
import Page from '../../common/components/Page';
|
|
||||||
import Button from '../../common/components/Button';
|
import Button from '../../common/components/Button';
|
||||||
import Switch from '../../common/components/Switch';
|
|
||||||
import Stream from '../../common/utils/Stream';
|
|
||||||
import EditCustomCssModal from './EditCustomCssModal';
|
import EditCustomCssModal from './EditCustomCssModal';
|
||||||
import EditCustomHeaderModal from './EditCustomHeaderModal';
|
import EditCustomHeaderModal from './EditCustomHeaderModal';
|
||||||
import EditCustomFooterModal from './EditCustomFooterModal';
|
import EditCustomFooterModal from './EditCustomFooterModal';
|
||||||
import UploadImageButton from './UploadImageButton';
|
import UploadImageButton from './UploadImageButton';
|
||||||
import saveSettings from '../utils/saveSettings';
|
import AdminPage from './AdminPage';
|
||||||
|
|
||||||
export default class AppearancePage extends Page {
|
export default class AppearancePage extends AdminPage {
|
||||||
oninit(vnode) {
|
headerInfo() {
|
||||||
super.oninit(vnode);
|
return {
|
||||||
|
className: 'AppearancePage',
|
||||||
this.primaryColor = Stream(app.data.settings.theme_primary_color);
|
icon: 'fas fa-paint-brush',
|
||||||
this.secondaryColor = Stream(app.data.settings.theme_secondary_color);
|
title: app.translator.trans('core.admin.appearance.title'),
|
||||||
this.darkMode = Stream(app.data.settings.theme_dark_mode);
|
description: app.translator.trans('core.admin.appearance.description'),
|
||||||
this.coloredHeader = Stream(app.data.settings.theme_colored_header);
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
view() {
|
content() {
|
||||||
return (
|
return [
|
||||||
<div className="AppearancePage">
|
<div className="Form">
|
||||||
<div className="container">
|
<fieldset className="AppearancePage-colors">
|
||||||
<form onsubmit={this.onsubmit.bind(this)}>
|
<legend>{app.translator.trans('core.admin.appearance.colors_heading')}</legend>
|
||||||
<fieldset className="AppearancePage-colors">
|
<div className="helpText">{app.translator.trans('core.admin.appearance.colors_text')}</div>
|
||||||
<legend>{app.translator.trans('core.admin.appearance.colors_heading')}</legend>
|
|
||||||
<div className="helpText">{app.translator.trans('core.admin.appearance.colors_text')}</div>
|
|
||||||
|
|
||||||
<div className="AppearancePage-colors-input">
|
<div className="AppearancePage-colors-input">
|
||||||
<input className="FormControl" type="text" placeholder="#aaaaaa" bidi={this.primaryColor} />
|
{this.buildSettingComponent({
|
||||||
<input className="FormControl" type="text" placeholder="#aaaaaa" bidi={this.secondaryColor} />
|
type: 'text',
|
||||||
</div>
|
setting: 'theme_primary_color',
|
||||||
|
placeholder: '#aaaaaa',
|
||||||
|
})}
|
||||||
|
{this.buildSettingComponent({
|
||||||
|
type: 'text',
|
||||||
|
setting: 'theme_secondary_color',
|
||||||
|
placeholder: '#aaaaaa',
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
|
||||||
{Switch.component(
|
{this.buildSettingComponent({
|
||||||
{
|
type: 'switch',
|
||||||
state: this.darkMode(),
|
setting: 'theme_dark_mode',
|
||||||
onchange: this.darkMode,
|
label: app.translator.trans('core.admin.appearance.dark_mode_label'),
|
||||||
},
|
})}
|
||||||
app.translator.trans('core.admin.appearance.dark_mode_label')
|
|
||||||
)}
|
|
||||||
|
|
||||||
{Switch.component(
|
{this.buildSettingComponent({
|
||||||
{
|
type: 'switch',
|
||||||
state: this.coloredHeader(),
|
setting: 'theme_colored_header',
|
||||||
onchange: this.coloredHeader,
|
label: app.translator.trans('core.admin.appearance.colored_header_label'),
|
||||||
},
|
})}
|
||||||
app.translator.trans('core.admin.appearance.colored_header_label')
|
|
||||||
)}
|
|
||||||
|
|
||||||
{Button.component(
|
{this.submitButton()}
|
||||||
{
|
</fieldset>
|
||||||
className: 'Button Button--primary',
|
</div>,
|
||||||
type: 'submit',
|
|
||||||
loading: this.loading,
|
|
||||||
},
|
|
||||||
app.translator.trans('core.admin.appearance.submit_button')
|
|
||||||
)}
|
|
||||||
</fieldset>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>{app.translator.trans('core.admin.appearance.logo_heading')}</legend>
|
<legend>{app.translator.trans('core.admin.appearance.logo_heading')}</legend>
|
||||||
<div className="helpText">{app.translator.trans('core.admin.appearance.logo_text')}</div>
|
<div className="helpText">{app.translator.trans('core.admin.appearance.logo_text')}</div>
|
||||||
<UploadImageButton name="logo" />
|
<UploadImageButton name="logo" />
|
||||||
</fieldset>
|
</fieldset>,
|
||||||
|
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>{app.translator.trans('core.admin.appearance.favicon_heading')}</legend>
|
<legend>{app.translator.trans('core.admin.appearance.favicon_heading')}</legend>
|
||||||
<div className="helpText">{app.translator.trans('core.admin.appearance.favicon_text')}</div>
|
<div className="helpText">{app.translator.trans('core.admin.appearance.favicon_text')}</div>
|
||||||
<UploadImageButton name="favicon" />
|
<UploadImageButton name="favicon" />
|
||||||
</fieldset>
|
</fieldset>,
|
||||||
|
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>{app.translator.trans('core.admin.appearance.custom_header_heading')}</legend>
|
<legend>{app.translator.trans('core.admin.appearance.custom_header_heading')}</legend>
|
||||||
<div className="helpText">{app.translator.trans('core.admin.appearance.custom_header_text')}</div>
|
<div className="helpText">{app.translator.trans('core.admin.appearance.custom_header_text')}</div>
|
||||||
{Button.component(
|
{Button.component(
|
||||||
{
|
{
|
||||||
className: 'Button',
|
className: 'Button',
|
||||||
onclick: () => app.modal.show(EditCustomHeaderModal),
|
onclick: () => app.modal.show(EditCustomHeaderModal),
|
||||||
},
|
},
|
||||||
app.translator.trans('core.admin.appearance.edit_header_button')
|
app.translator.trans('core.admin.appearance.edit_header_button')
|
||||||
)}
|
)}
|
||||||
</fieldset>
|
</fieldset>,
|
||||||
|
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>{app.translator.trans('core.admin.appearance.custom_footer_heading')}</legend>
|
<legend>{app.translator.trans('core.admin.appearance.custom_footer_heading')}</legend>
|
||||||
<div className="helpText">{app.translator.trans('core.admin.appearance.custom_footer_text')}</div>
|
<div className="helpText">{app.translator.trans('core.admin.appearance.custom_footer_text')}</div>
|
||||||
{Button.component(
|
{Button.component(
|
||||||
{
|
{
|
||||||
className: 'Button',
|
className: 'Button',
|
||||||
onclick: () => app.modal.show(EditCustomFooterModal),
|
onclick: () => app.modal.show(EditCustomFooterModal),
|
||||||
},
|
},
|
||||||
app.translator.trans('core.admin.appearance.edit_footer_button')
|
app.translator.trans('core.admin.appearance.edit_footer_button')
|
||||||
)}
|
)}
|
||||||
</fieldset>
|
</fieldset>,
|
||||||
|
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>{app.translator.trans('core.admin.appearance.custom_styles_heading')}</legend>
|
<legend>{app.translator.trans('core.admin.appearance.custom_styles_heading')}</legend>
|
||||||
<div className="helpText">{app.translator.trans('core.admin.appearance.custom_styles_text')}</div>
|
<div className="helpText">{app.translator.trans('core.admin.appearance.custom_styles_text')}</div>
|
||||||
{Button.component(
|
{Button.component(
|
||||||
{
|
{
|
||||||
className: 'Button',
|
className: 'Button',
|
||||||
onclick: () => app.modal.show(EditCustomCssModal),
|
onclick: () => app.modal.show(EditCustomCssModal),
|
||||||
},
|
},
|
||||||
app.translator.trans('core.admin.appearance.edit_css_button')
|
app.translator.trans('core.admin.appearance.edit_css_button')
|
||||||
)}
|
)}
|
||||||
</fieldset>
|
</fieldset>,
|
||||||
</div>
|
];
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onsubmit(e) {
|
onsaved() {
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
saveSettings(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
const hex = /^#[0-9a-f]{3}([0-9a-f]{3})?$/i;
|
const hex = /^#[0-9a-f]{3}([0-9a-f]{3})?$/i;
|
||||||
|
|
||||||
if (!hex.test(this.primaryColor()) || !hex.test(this.secondaryColor())) {
|
if (!hex.test(this.settings['theme_primary_color']()) || !hex.test(this.settings['theme_secondary_color']())) {
|
||||||
alert(app.translator.trans('core.admin.appearance.enter_hex_message'));
|
alert(app.translator.trans('core.admin.appearance.enter_hex_message'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.loading = true;
|
super.saveSettings(e);
|
||||||
|
|
||||||
saveSettings({
|
|
||||||
theme_primary_color: this.primaryColor(),
|
|
||||||
theme_secondary_color: this.secondaryColor(),
|
|
||||||
theme_dark_mode: this.darkMode(),
|
|
||||||
theme_colored_header: this.coloredHeader(),
|
|
||||||
}).then(() => window.location.reload());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,34 +1,11 @@
|
|||||||
import Page from '../../common/components/Page';
|
|
||||||
import FieldSet from '../../common/components/FieldSet';
|
import FieldSet from '../../common/components/FieldSet';
|
||||||
import Select from '../../common/components/Select';
|
|
||||||
import Button from '../../common/components/Button';
|
|
||||||
import saveSettings from '../utils/saveSettings';
|
|
||||||
import ItemList from '../../common/utils/ItemList';
|
import ItemList from '../../common/utils/ItemList';
|
||||||
import Switch from '../../common/components/Switch';
|
import AdminPage from './AdminPage';
|
||||||
import Stream from '../../common/utils/Stream';
|
|
||||||
import withAttr from '../../common/utils/withAttr';
|
|
||||||
|
|
||||||
export default class BasicsPage extends Page {
|
export default class BasicsPage extends AdminPage {
|
||||||
oninit(vnode) {
|
oninit(vnode) {
|
||||||
super.oninit(vnode);
|
super.oninit(vnode);
|
||||||
|
|
||||||
this.loading = false;
|
|
||||||
|
|
||||||
this.fields = [
|
|
||||||
'forum_title',
|
|
||||||
'forum_description',
|
|
||||||
'default_locale',
|
|
||||||
'show_language_selector',
|
|
||||||
'default_route',
|
|
||||||
'welcome_title',
|
|
||||||
'welcome_message',
|
|
||||||
'display_name_driver',
|
|
||||||
];
|
|
||||||
this.values = {};
|
|
||||||
|
|
||||||
const settings = app.data.settings;
|
|
||||||
this.fields.forEach((key) => (this.values[key] = Stream(settings[key])));
|
|
||||||
|
|
||||||
this.localeOptions = {};
|
this.localeOptions = {};
|
||||||
const locales = app.data.locales;
|
const locales = app.data.locales;
|
||||||
for (const i in locales) {
|
for (const i in locales) {
|
||||||
@@ -41,125 +18,101 @@ export default class BasicsPage extends Page {
|
|||||||
this.displayNameOptions[identifier] = identifier;
|
this.displayNameOptions[identifier] = identifier;
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
if (!this.values.display_name_driver() && displayNameDrivers.includes('username')) this.values.display_name_driver('username');
|
this.slugDriverOptions = {};
|
||||||
|
Object.keys(app.data.slugDrivers).forEach((model) => {
|
||||||
|
this.slugDriverOptions[model] = {};
|
||||||
|
|
||||||
if (typeof this.values.show_language_selector() !== 'number') this.values.show_language_selector(1);
|
app.data.slugDrivers[model].forEach((option) => {
|
||||||
|
this.slugDriverOptions[model][option] = option;
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
view() {
|
headerInfo() {
|
||||||
return (
|
return {
|
||||||
<div className="BasicsPage">
|
className: 'BasicsPage',
|
||||||
<div className="container">
|
icon: 'fas fa-pencil-alt',
|
||||||
<form onsubmit={this.onsubmit.bind(this)}>
|
title: app.translator.trans('core.admin.basics.title'),
|
||||||
{FieldSet.component(
|
description: app.translator.trans('core.admin.basics.description'),
|
||||||
{
|
};
|
||||||
label: app.translator.trans('core.admin.basics.forum_title_heading'),
|
}
|
||||||
},
|
|
||||||
[<input className="FormControl" bidi={this.values.forum_title} />]
|
|
||||||
)}
|
|
||||||
|
|
||||||
{FieldSet.component(
|
content() {
|
||||||
{
|
return [
|
||||||
label: app.translator.trans('core.admin.basics.forum_description_heading'),
|
<div className="Form">
|
||||||
},
|
{this.buildSettingComponent({
|
||||||
[
|
type: 'text',
|
||||||
<div className="helpText">{app.translator.trans('core.admin.basics.forum_description_text')}</div>,
|
setting: 'forum_title',
|
||||||
<textarea className="FormControl" bidi={this.values.forum_description} />,
|
label: app.translator.trans('core.admin.basics.forum_title_heading'),
|
||||||
]
|
})}
|
||||||
)}
|
{this.buildSettingComponent({
|
||||||
|
type: 'text',
|
||||||
|
setting: 'forum_description',
|
||||||
|
label: app.translator.trans('core.admin.basics.forum_description_heading'),
|
||||||
|
help: app.translator.trans('core.admin.basics.forum_description_text'),
|
||||||
|
})}
|
||||||
|
|
||||||
{Object.keys(this.localeOptions).length > 1
|
{Object.keys(this.localeOptions).length > 1
|
||||||
? FieldSet.component(
|
? [
|
||||||
{
|
this.buildSettingComponent({
|
||||||
label: app.translator.trans('core.admin.basics.default_language_heading'),
|
type: 'select',
|
||||||
},
|
setting: 'default_locale',
|
||||||
[
|
options: this.localeOptions,
|
||||||
Select.component({
|
label: app.translator.trans('core.admin.basics.default_language_heading'),
|
||||||
options: this.localeOptions,
|
}),
|
||||||
value: this.values.default_locale(),
|
this.buildSettingComponent({
|
||||||
onchange: this.values.default_locale,
|
type: 'switch',
|
||||||
}),
|
setting: 'show_language_selector',
|
||||||
Switch.component(
|
label: app.translator.trans('core.admin.basics.show_language_selector_label'),
|
||||||
{
|
}),
|
||||||
state: this.values.show_language_selector(),
|
]
|
||||||
onchange: this.values.show_language_selector,
|
: ''}
|
||||||
},
|
|
||||||
app.translator.trans('core.admin.basics.show_language_selector_label')
|
|
||||||
),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
: ''}
|
|
||||||
|
|
||||||
{FieldSet.component(
|
<FieldSet className="BasicsPage-homePage Form-group" label={app.translator.trans('core.admin.basics.home_page_heading')}>
|
||||||
{
|
<div className="helpText">{app.translator.trans('core.admin.basics.home_page_text')}</div>
|
||||||
label: app.translator.trans('core.admin.basics.home_page_heading'),
|
{this.homePageItems()
|
||||||
className: 'BasicsPage-homePage',
|
.toArray()
|
||||||
},
|
.map(({ path, label }) => (
|
||||||
[
|
<label className="checkbox">
|
||||||
<div className="helpText">{app.translator.trans('core.admin.basics.home_page_text')}</div>,
|
<input type="radio" name="homePage" value={path} bidi={this.setting('default_route')} />
|
||||||
this.homePageItems()
|
{label}
|
||||||
.toArray()
|
</label>
|
||||||
.map(({ path, label }) => (
|
))}
|
||||||
<label className="checkbox">
|
</FieldSet>
|
||||||
<input
|
|
||||||
type="radio"
|
|
||||||
name="homePage"
|
|
||||||
value={path}
|
|
||||||
checked={this.values.default_route() === path}
|
|
||||||
onclick={withAttr('value', this.values.default_route)}
|
|
||||||
/>
|
|
||||||
{label}
|
|
||||||
</label>
|
|
||||||
)),
|
|
||||||
]
|
|
||||||
)}
|
|
||||||
|
|
||||||
{FieldSet.component(
|
<div className="Form-group BasicsPage-welcomeBanner-input">
|
||||||
{
|
<label>{app.translator.trans('core.admin.basics.welcome_banner_heading')}</label>
|
||||||
label: app.translator.trans('core.admin.basics.welcome_banner_heading'),
|
<div className="helpText">{app.translator.trans('core.admin.basics.welcome_banner_text')}</div>
|
||||||
className: 'BasicsPage-welcomeBanner',
|
<input type="text" className="FormControl" bidi={this.setting('welcome_title')} />
|
||||||
},
|
<textarea className="FormControl" bidi={this.setting('welcome_message')} />
|
||||||
[
|
|
||||||
<div className="helpText">{app.translator.trans('core.admin.basics.welcome_banner_text')}</div>,
|
|
||||||
<div className="BasicsPage-welcomeBanner-input">
|
|
||||||
<input className="FormControl" bidi={this.values.welcome_title} />
|
|
||||||
<textarea className="FormControl" bidi={this.values.welcome_message} />
|
|
||||||
</div>,
|
|
||||||
]
|
|
||||||
)}
|
|
||||||
|
|
||||||
{Object.keys(this.displayNameOptions).length > 1
|
|
||||||
? FieldSet.component(
|
|
||||||
{
|
|
||||||
label: app.translator.trans('core.admin.basics.display_name_heading'),
|
|
||||||
},
|
|
||||||
[
|
|
||||||
<div className="helpText">{app.translator.trans('core.admin.basics.display_name_text')}</div>,
|
|
||||||
Select.component({
|
|
||||||
options: this.displayNameOptions,
|
|
||||||
bidi: this.values.display_name_driver,
|
|
||||||
}),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
: ''}
|
|
||||||
|
|
||||||
{Button.component(
|
|
||||||
{
|
|
||||||
type: 'submit',
|
|
||||||
className: 'Button Button--primary',
|
|
||||||
loading: this.loading,
|
|
||||||
disabled: !this.changed(),
|
|
||||||
},
|
|
||||||
app.translator.trans('core.admin.basics.submit_button')
|
|
||||||
)}
|
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
changed() {
|
{Object.keys(this.displayNameOptions).length > 1
|
||||||
return this.fields.some((key) => this.values[key]() !== app.data.settings[key]);
|
? this.buildSettingComponent({
|
||||||
|
type: 'select',
|
||||||
|
setting: 'display_name_driver',
|
||||||
|
options: this.displayNameOptions,
|
||||||
|
label: app.translator.trans('core.admin.basics.display_name_heading'),
|
||||||
|
help: app.translator.trans('core.admin.basics.display_name_text'),
|
||||||
|
})
|
||||||
|
: ''}
|
||||||
|
|
||||||
|
{Object.keys(this.slugDriverOptions).map((model) => {
|
||||||
|
const options = this.slugDriverOptions[model];
|
||||||
|
if (Object.keys(options).length > 1) {
|
||||||
|
return this.buildSettingComponent({
|
||||||
|
type: 'select',
|
||||||
|
setting: `slug_driver_${model}`,
|
||||||
|
options,
|
||||||
|
label: app.translator.trans('core.admin.basics.slug_driver_heading', { model }),
|
||||||
|
help: app.translator.trans('core.admin.basics.slug_driver_text', { model }),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})}
|
||||||
|
|
||||||
|
{this.submitButton()}
|
||||||
|
</div>,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -179,27 +132,4 @@ export default class BasicsPage extends Page {
|
|||||||
|
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
onsubmit(e) {
|
|
||||||
e.preventDefault();
|
|
||||||
|
|
||||||
if (this.loading) return;
|
|
||||||
|
|
||||||
this.loading = true;
|
|
||||||
app.alerts.dismiss(this.successAlert);
|
|
||||||
|
|
||||||
const settings = {};
|
|
||||||
|
|
||||||
this.fields.forEach((key) => (settings[key] = this.values[key]()));
|
|
||||||
|
|
||||||
saveSettings(settings)
|
|
||||||
.then(() => {
|
|
||||||
this.successAlert = app.alerts.show({ type: 'success' }, app.translator.trans('core.admin.basics.saved_message'));
|
|
||||||
})
|
|
||||||
.catch(() => {})
|
|
||||||
.then(() => {
|
|
||||||
this.loading = false;
|
|
||||||
m.redraw();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -1,16 +1,29 @@
|
|||||||
import Page from '../../common/components/Page';
|
|
||||||
import StatusWidget from './StatusWidget';
|
import StatusWidget from './StatusWidget';
|
||||||
|
import ExtensionsWidget from './ExtensionsWidget';
|
||||||
|
import ItemList from '../../common/utils/ItemList';
|
||||||
|
import AdminPage from './AdminPage';
|
||||||
|
|
||||||
export default class DashboardPage extends Page {
|
export default class DashboardPage extends AdminPage {
|
||||||
view() {
|
headerInfo() {
|
||||||
return (
|
return {
|
||||||
<div className="DashboardPage">
|
className: 'DashboardPage',
|
||||||
<div className="container">{this.availableWidgets()}</div>
|
icon: 'fas fa-chart-bar',
|
||||||
</div>
|
title: app.translator.trans('core.admin.dashboard.title'),
|
||||||
);
|
description: app.translator.trans('core.admin.dashboard.description'),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
content() {
|
||||||
|
return this.availableWidgets().toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
availableWidgets() {
|
availableWidgets() {
|
||||||
return [<StatusWidget />];
|
const items = new ItemList();
|
||||||
|
|
||||||
|
items.add('status', <StatusWidget />, 30);
|
||||||
|
|
||||||
|
items.add('extensions', <ExtensionsWidget />, 10);
|
||||||
|
|
||||||
|
return items;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
29
js/src/admin/components/ExtensionLinkButton.js
Normal file
29
js/src/admin/components/ExtensionLinkButton.js
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import isExtensionEnabled from '../utils/isExtensionEnabled';
|
||||||
|
import LinkButton from '../../common/components/LinkButton';
|
||||||
|
import icon from '../../common/helpers/icon';
|
||||||
|
import ItemList from '../../common/utils/ItemList';
|
||||||
|
|
||||||
|
export default class ExtensionLinkButton extends LinkButton {
|
||||||
|
getButtonContent(children) {
|
||||||
|
const content = super.getButtonContent(children);
|
||||||
|
const extension = app.data.extensions[this.attrs.extensionId];
|
||||||
|
const statuses = this.statusItems(extension.id).toArray();
|
||||||
|
|
||||||
|
content.unshift(
|
||||||
|
<span className="ExtensionListItem-icon ExtensionIcon" style={extension.icon}>
|
||||||
|
{extension.icon ? icon(extension.icon.name) : ''}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
content.push(statuses);
|
||||||
|
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
statusItems(name) {
|
||||||
|
const items = new ItemList();
|
||||||
|
|
||||||
|
items.add('enabled', <span class={'ExtensionListItem-Dot ' + (isExtensionEnabled(name) ? 'enabled' : 'disabled')} />);
|
||||||
|
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
}
|
248
js/src/admin/components/ExtensionPage.js
Normal file
248
js/src/admin/components/ExtensionPage.js
Normal file
@@ -0,0 +1,248 @@
|
|||||||
|
import Button from '../../common/components/Button';
|
||||||
|
import Link from '../../common/components/Link';
|
||||||
|
import LinkButton from '../../common/components/LinkButton';
|
||||||
|
import Switch from '../../common/components/Switch';
|
||||||
|
import icon from '../../common/helpers/icon';
|
||||||
|
import punctuateSeries from '../../common/helpers/punctuateSeries';
|
||||||
|
import listItems from '../../common/helpers/listItems';
|
||||||
|
import ItemList from '../../common/utils/ItemList';
|
||||||
|
import LoadingModal from './LoadingModal';
|
||||||
|
import ExtensionPermissionGrid from './ExtensionPermissionGrid';
|
||||||
|
import isExtensionEnabled from '../utils/isExtensionEnabled';
|
||||||
|
import AdminPage from './AdminPage';
|
||||||
|
|
||||||
|
export default class ExtensionPage extends AdminPage {
|
||||||
|
oninit(vnode) {
|
||||||
|
super.oninit(vnode);
|
||||||
|
|
||||||
|
this.extension = app.data.extensions[this.attrs.id];
|
||||||
|
this.changingState = false;
|
||||||
|
|
||||||
|
this.infoFields = {
|
||||||
|
discuss: 'fas fa-comment-alt',
|
||||||
|
documentation: 'fas fa-book',
|
||||||
|
support: 'fas fa-life-ring',
|
||||||
|
website: 'fas fa-link',
|
||||||
|
donate: 'fas fa-donate',
|
||||||
|
source: 'fas fa-code',
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!this.extension) {
|
||||||
|
return m.route.set(app.route('dashboard'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
className() {
|
||||||
|
if (!this.extension) return '';
|
||||||
|
|
||||||
|
return this.extension.id + '-Page';
|
||||||
|
}
|
||||||
|
|
||||||
|
view() {
|
||||||
|
if (!this.extension) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={'ExtensionPage ' + this.className()}>
|
||||||
|
{this.header()}
|
||||||
|
{!this.isEnabled() ? (
|
||||||
|
<div className="container">
|
||||||
|
<h3 className="ExtensionPage-subHeader">{app.translator.trans('core.admin.extension.enable_to_see')}</h3>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="ExtensionPage-body">{this.sections().toArray()}</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
header() {
|
||||||
|
const isEnabled = this.isEnabled();
|
||||||
|
|
||||||
|
return [
|
||||||
|
<div className="ExtensionPage-header">
|
||||||
|
<div className="container">
|
||||||
|
<div className="ExtensionTitle">
|
||||||
|
<span className="ExtensionIcon" style={this.extension.icon}>
|
||||||
|
{this.extension.icon ? icon(this.extension.icon.name) : ''}
|
||||||
|
</span>
|
||||||
|
<div className="ExtensionName">
|
||||||
|
<h2>{this.extension.extra['flarum-extension'].title}</h2>
|
||||||
|
</div>
|
||||||
|
<div className="ExtensionPage-headerTopItems">
|
||||||
|
<ul>{listItems(this.topItems().toArray())}</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="helpText">{this.extension.description}</div>
|
||||||
|
<div className="ExtensionPage-headerItems">
|
||||||
|
<Switch
|
||||||
|
state={this.changingState ? !isEnabled : isEnabled}
|
||||||
|
loading={this.changingState}
|
||||||
|
onchange={this.toggle.bind(this, this.extension.id)}
|
||||||
|
>
|
||||||
|
{isEnabled ? app.translator.trans('core.admin.extension.enabled') : app.translator.trans('core.admin.extension.disabled')}
|
||||||
|
</Switch>
|
||||||
|
<aside className="ExtensionInfo">
|
||||||
|
<ul>{listItems(this.infoItems().toArray())}</ul>
|
||||||
|
</aside>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
sections() {
|
||||||
|
const items = new ItemList();
|
||||||
|
|
||||||
|
items.add('content', this.content());
|
||||||
|
|
||||||
|
items.add('permissions', [
|
||||||
|
<div className="ExtensionPage-permissions">
|
||||||
|
<div className="ExtensionPage-permissions-header">
|
||||||
|
<div className="container">
|
||||||
|
<h2 className="ExtensionTitle">{app.translator.trans('core.admin.extension.permissions_title')}</h2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="container">
|
||||||
|
{app.extensionData.extensionHasPermissions(this.extension.id) ? (
|
||||||
|
ExtensionPermissionGrid.component({ extensionId: this.extension.id })
|
||||||
|
) : (
|
||||||
|
<h3 className="ExtensionPage-subHeader">{app.translator.trans('core.admin.extension.no_permissions')}</h3>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
content() {
|
||||||
|
const settings = app.extensionData.getSettings(this.extension.id);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="ExtensionPage-settings">
|
||||||
|
<div className="container">
|
||||||
|
{settings ? (
|
||||||
|
<div className="Form">
|
||||||
|
{settings.map(this.buildSettingComponent.bind(this))}
|
||||||
|
<div className="Form-group">{this.submitButton()}</div>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<h3 className="ExtensionPage-subHeader">{app.translator.trans('core.admin.extension.no_settings')}</h3>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
topItems() {
|
||||||
|
const items = new ItemList();
|
||||||
|
|
||||||
|
items.add('version', <span className="ExtensionVersion">{this.extension.version}</span>);
|
||||||
|
|
||||||
|
if (!this.isEnabled()) {
|
||||||
|
const uninstall = () => {
|
||||||
|
if (confirm(app.translator.trans('core.admin.extension.confirm_uninstall'))) {
|
||||||
|
app
|
||||||
|
.request({
|
||||||
|
url: app.forum.attribute('apiUrl') + '/extensions/' + this.extension.id,
|
||||||
|
method: 'DELETE',
|
||||||
|
})
|
||||||
|
.then(() => window.location.reload());
|
||||||
|
|
||||||
|
app.modal.show(LoadingModal);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
items.add(
|
||||||
|
'uninstall',
|
||||||
|
<Button icon="fas fa-trash-alt" className="Button Button--primary" onclick={uninstall.bind(this)}>
|
||||||
|
{app.translator.trans('core.admin.extension.uninstall_button')}
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
infoItems() {
|
||||||
|
const items = new ItemList();
|
||||||
|
|
||||||
|
const links = this.extension.links;
|
||||||
|
|
||||||
|
if (links.authors.length) {
|
||||||
|
let authors = [];
|
||||||
|
|
||||||
|
links.authors.map((author) => {
|
||||||
|
authors.push(
|
||||||
|
<Link href={author.link} external={true} target="_blank">
|
||||||
|
{author.name}
|
||||||
|
</Link>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
items.add('authors', [icon('fas fa-user'), <span>{punctuateSeries(authors)}</span>]);
|
||||||
|
}
|
||||||
|
|
||||||
|
Object.keys(this.infoFields).map((field) => {
|
||||||
|
if (links[field]) {
|
||||||
|
items.add(
|
||||||
|
field,
|
||||||
|
<LinkButton href={links[field]} icon={this.infoFields[field]} external={true} target="_blank">
|
||||||
|
{app.translator.trans(`core.admin.extension.info_links.${field}`)}
|
||||||
|
</LinkButton>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
toggle() {
|
||||||
|
const enabled = this.isEnabled();
|
||||||
|
|
||||||
|
this.changingState = true;
|
||||||
|
|
||||||
|
app
|
||||||
|
.request({
|
||||||
|
url: app.forum.attribute('apiUrl') + '/extensions/' + this.extension.id,
|
||||||
|
method: 'PATCH',
|
||||||
|
body: { enabled: !enabled },
|
||||||
|
errorHandler: this.onerror.bind(this),
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
if (!enabled) localStorage.setItem('enabledExtension', this.extension.id);
|
||||||
|
window.location.reload();
|
||||||
|
});
|
||||||
|
|
||||||
|
app.modal.show(LoadingModal);
|
||||||
|
}
|
||||||
|
|
||||||
|
isEnabled() {
|
||||||
|
return isExtensionEnabled(this.extension.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
onerror(e) {
|
||||||
|
// We need to give the modal animation time to start; if we close the modal too early,
|
||||||
|
// it breaks the bootstrap modal library.
|
||||||
|
// TODO: This workaround should be removed when we move away from bootstrap JS for modals.
|
||||||
|
setTimeout(() => {
|
||||||
|
app.modal.close();
|
||||||
|
}, 300); // Bootstrap's Modal.TRANSITION_DURATION is 300 ms.
|
||||||
|
|
||||||
|
this.changingState = false;
|
||||||
|
|
||||||
|
if (e.status !== 409) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
const error = e.response.errors[0];
|
||||||
|
|
||||||
|
app.alerts.show(
|
||||||
|
{ type: 'error' },
|
||||||
|
app.translator.trans(`core.lib.error.${error.code}_message`, {
|
||||||
|
extension: error.extension,
|
||||||
|
extensions: error.extensions.join(', '),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
53
js/src/admin/components/ExtensionPermissionGrid.js
Normal file
53
js/src/admin/components/ExtensionPermissionGrid.js
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
import PermissionGrid from './PermissionGrid';
|
||||||
|
import Button from '../../common/components/Button';
|
||||||
|
import ItemList from '../../common/utils/ItemList';
|
||||||
|
|
||||||
|
export default class ExtensionPermissionGrid extends PermissionGrid {
|
||||||
|
oninit(vnode) {
|
||||||
|
super.oninit(vnode);
|
||||||
|
|
||||||
|
this.extensionId = this.attrs.extensionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
permissionItems() {
|
||||||
|
const permissionCategories = super.permissionItems();
|
||||||
|
|
||||||
|
permissionCategories.items = Object.entries(permissionCategories.items)
|
||||||
|
.filter(([category, info]) => info.content.children.length > 0)
|
||||||
|
.reduce((obj, [category, info]) => {
|
||||||
|
obj[category] = info;
|
||||||
|
return obj;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
return permissionCategories;
|
||||||
|
}
|
||||||
|
|
||||||
|
viewItems() {
|
||||||
|
return app.extensionData.getExtensionPermissions(this.extensionId, 'view') || new ItemList();
|
||||||
|
}
|
||||||
|
|
||||||
|
startItems() {
|
||||||
|
return app.extensionData.getExtensionPermissions(this.extensionId, 'start') || new ItemList();
|
||||||
|
}
|
||||||
|
|
||||||
|
replyItems() {
|
||||||
|
return app.extensionData.getExtensionPermissions(this.extensionId, 'reply') || new ItemList();
|
||||||
|
}
|
||||||
|
|
||||||
|
moderateItems() {
|
||||||
|
return app.extensionData.getExtensionPermissions(this.extensionId, 'moderate') || new ItemList();
|
||||||
|
}
|
||||||
|
|
||||||
|
scopeControlItems() {
|
||||||
|
const items = new ItemList();
|
||||||
|
|
||||||
|
items.add(
|
||||||
|
'configureScopes',
|
||||||
|
<Button className="Button Button--text" onclick={() => m.route.set(app.route('permissions'))}>
|
||||||
|
{app.translator.trans('core.admin.extension.configure_scopes')}
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
}
|
@@ -1,158 +0,0 @@
|
|||||||
import Page from '../../common/components/Page';
|
|
||||||
import Button from '../../common/components/Button';
|
|
||||||
import Dropdown from '../../common/components/Dropdown';
|
|
||||||
import AddExtensionModal from './AddExtensionModal';
|
|
||||||
import LoadingModal from './LoadingModal';
|
|
||||||
import ItemList from '../../common/utils/ItemList';
|
|
||||||
import icon from '../../common/helpers/icon';
|
|
||||||
|
|
||||||
export default class ExtensionsPage extends Page {
|
|
||||||
view() {
|
|
||||||
return (
|
|
||||||
<div className="ExtensionsPage">
|
|
||||||
<div className="ExtensionsPage-header">
|
|
||||||
<div className="container">
|
|
||||||
{Button.component(
|
|
||||||
{
|
|
||||||
icon: 'fas fa-plus',
|
|
||||||
className: 'Button Button--primary',
|
|
||||||
onclick: () => app.modal.show(AddExtensionModal),
|
|
||||||
},
|
|
||||||
app.translator.trans('core.admin.extensions.add_button')
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="ExtensionsPage-list">
|
|
||||||
<div className="container">
|
|
||||||
<ul className="ExtensionList">
|
|
||||||
{Object.keys(app.data.extensions).map((id) => {
|
|
||||||
const extension = app.data.extensions[id];
|
|
||||||
const controls = this.controlItems(extension.id).toArray();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<li className={'ExtensionListItem ' + (!this.isEnabled(extension.id) ? 'disabled' : '')}>
|
|
||||||
<div className="ExtensionListItem-content">
|
|
||||||
<span className="ExtensionListItem-icon ExtensionIcon" style={extension.icon}>
|
|
||||||
{extension.icon ? icon(extension.icon.name) : ''}
|
|
||||||
</span>
|
|
||||||
{controls.length ? (
|
|
||||||
<Dropdown
|
|
||||||
className="ExtensionListItem-controls"
|
|
||||||
buttonClassName="Button Button--icon Button--flat"
|
|
||||||
menuClassName="Dropdown-menu--right"
|
|
||||||
icon="fas fa-ellipsis-h"
|
|
||||||
>
|
|
||||||
{controls}
|
|
||||||
</Dropdown>
|
|
||||||
) : (
|
|
||||||
''
|
|
||||||
)}
|
|
||||||
<div className="ExtensionListItem-main">
|
|
||||||
<label className="ExtensionListItem-title">
|
|
||||||
<input type="checkbox" checked={this.isEnabled(extension.id)} onclick={this.toggle.bind(this, extension.id)} />{' '}
|
|
||||||
{extension.extra['flarum-extension'].title}
|
|
||||||
</label>
|
|
||||||
<div className="ExtensionListItem-version">{extension.version}</div>
|
|
||||||
<div className="ExtensionListItem-description">{extension.description}</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</li>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
controlItems(name) {
|
|
||||||
const items = new ItemList();
|
|
||||||
const enabled = this.isEnabled(name);
|
|
||||||
|
|
||||||
if (app.extensionSettings[name]) {
|
|
||||||
items.add(
|
|
||||||
'settings',
|
|
||||||
Button.component(
|
|
||||||
{
|
|
||||||
icon: 'fas fa-cog',
|
|
||||||
onclick: app.extensionSettings[name],
|
|
||||||
},
|
|
||||||
app.translator.trans('core.admin.extensions.settings_button')
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!enabled) {
|
|
||||||
items.add(
|
|
||||||
'uninstall',
|
|
||||||
Button.component(
|
|
||||||
{
|
|
||||||
icon: 'far fa-trash-alt',
|
|
||||||
onclick: () => {
|
|
||||||
app
|
|
||||||
.request({
|
|
||||||
url: app.forum.attribute('apiUrl') + '/extensions/' + name,
|
|
||||||
method: 'DELETE',
|
|
||||||
})
|
|
||||||
.then(() => window.location.reload());
|
|
||||||
|
|
||||||
app.modal.show(LoadingModal);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
app.translator.trans('core.admin.extensions.uninstall_button')
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return items;
|
|
||||||
}
|
|
||||||
|
|
||||||
isEnabled(name) {
|
|
||||||
const enabled = JSON.parse(app.data.settings.extensions_enabled);
|
|
||||||
|
|
||||||
return enabled.indexOf(name) !== -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
toggle(id) {
|
|
||||||
const enabled = this.isEnabled(id);
|
|
||||||
|
|
||||||
app
|
|
||||||
.request({
|
|
||||||
url: app.forum.attribute('apiUrl') + '/extensions/' + id,
|
|
||||||
method: 'PATCH',
|
|
||||||
body: { enabled: !enabled },
|
|
||||||
errorHandler: this.onerror.bind(this),
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
if (!enabled) localStorage.setItem('enabledExtension', id);
|
|
||||||
window.location.reload();
|
|
||||||
});
|
|
||||||
|
|
||||||
app.modal.show(LoadingModal);
|
|
||||||
}
|
|
||||||
|
|
||||||
onerror(e) {
|
|
||||||
// We need to give the modal animation time to start; if we close the modal too early,
|
|
||||||
// it breaks the bootstrap modal library.
|
|
||||||
// TODO: This workaround should be removed when we move away from bootstrap JS for modals.
|
|
||||||
setTimeout(() => {
|
|
||||||
app.modal.close();
|
|
||||||
}, 300); // Bootstrap's Modal.TRANSITION_DURATION is 300 ms.
|
|
||||||
|
|
||||||
if (e.status !== 409) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
const error = e.response.errors[0];
|
|
||||||
|
|
||||||
app.alerts.show(
|
|
||||||
{ type: 'error' },
|
|
||||||
app.translator.trans(`core.lib.error.${error.code}_message`, {
|
|
||||||
extension: error.extension,
|
|
||||||
extensions: error.extensions.join(', '),
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
51
js/src/admin/components/ExtensionsWidget.js
Normal file
51
js/src/admin/components/ExtensionsWidget.js
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
import DashboardWidget from './DashboardWidget';
|
||||||
|
import isExtensionEnabled from '../utils/isExtensionEnabled';
|
||||||
|
import getCategorizedExtensions from '../utils/getCategorizedExtensions';
|
||||||
|
import Link from '../../common/components/Link';
|
||||||
|
import icon from '../../common/helpers/icon';
|
||||||
|
|
||||||
|
export default class ExtensionsWidget extends DashboardWidget {
|
||||||
|
oninit(vnode) {
|
||||||
|
super.oninit(vnode);
|
||||||
|
|
||||||
|
this.categorizedExtensions = getCategorizedExtensions();
|
||||||
|
}
|
||||||
|
|
||||||
|
className() {
|
||||||
|
return 'ExtensionsWidget';
|
||||||
|
}
|
||||||
|
|
||||||
|
content() {
|
||||||
|
const categories = app.extensionCategories;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="ExtensionsWidget-list">
|
||||||
|
{Object.keys(categories).map((category) => (this.categorizedExtensions[category] ? this.extensionCategory(category) : ''))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
extensionCategory(category) {
|
||||||
|
return (
|
||||||
|
<div className="ExtensionList-Category">
|
||||||
|
<h4 className="ExtensionList-Label">{app.translator.trans(`core.admin.nav.categories.${category}`)}</h4>
|
||||||
|
<ul className="ExtensionList">{this.categorizedExtensions[category].map((extension) => this.extensionWidget(extension))}</ul>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
extensionWidget(extension) {
|
||||||
|
return (
|
||||||
|
<li className={'ExtensionListItem ' + (!isExtensionEnabled(extension.id) ? 'disabled' : '')}>
|
||||||
|
<Link href={app.route('extension', { id: extension.id })}>
|
||||||
|
<div className="ExtensionListItem-content">
|
||||||
|
<span className="ExtensionListItem-icon ExtensionIcon" style={extension.icon}>
|
||||||
|
{extension.icon ? icon(extension.icon.name) : ''}
|
||||||
|
</span>
|
||||||
|
<span className="ExtensionListItem-title">{extension.extra['flarum-extension'].title}</span>
|
||||||
|
</div>
|
||||||
|
</Link>
|
||||||
|
</li>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@@ -1,4 +1,5 @@
|
|||||||
import Component from '../../common/Component';
|
import Component from '../../common/Component';
|
||||||
|
import LinkButton from '../../common/components/LinkButton';
|
||||||
import SessionDropdown from './SessionDropdown';
|
import SessionDropdown from './SessionDropdown';
|
||||||
import ItemList from '../../common/utils/ItemList';
|
import ItemList from '../../common/utils/ItemList';
|
||||||
import listItems from '../../common/helpers/listItems';
|
import listItems from '../../common/helpers/listItems';
|
||||||
@@ -19,6 +20,13 @@ export default class HeaderSecondary extends Component {
|
|||||||
items() {
|
items() {
|
||||||
const items = new ItemList();
|
const items = new ItemList();
|
||||||
|
|
||||||
|
items.add(
|
||||||
|
'help',
|
||||||
|
<LinkButton href="https://docs.flarum.org/troubleshoot.html" icon="fas fa-question-circle" external={true} target="_blank">
|
||||||
|
{app.translator.trans('core.admin.header.get_help')}
|
||||||
|
</LinkButton>
|
||||||
|
);
|
||||||
|
|
||||||
items.add('session', SessionDropdown.component());
|
items.add('session', SessionDropdown.component());
|
||||||
|
|
||||||
return items;
|
return items;
|
||||||
|
@@ -1,32 +1,31 @@
|
|||||||
import Page from '../../common/components/Page';
|
|
||||||
import FieldSet from '../../common/components/FieldSet';
|
import FieldSet from '../../common/components/FieldSet';
|
||||||
import Button from '../../common/components/Button';
|
import Button from '../../common/components/Button';
|
||||||
import Alert from '../../common/components/Alert';
|
import Alert from '../../common/components/Alert';
|
||||||
import Select from '../../common/components/Select';
|
|
||||||
import LoadingIndicator from '../../common/components/LoadingIndicator';
|
import LoadingIndicator from '../../common/components/LoadingIndicator';
|
||||||
import saveSettings from '../utils/saveSettings';
|
import AdminPage from './AdminPage';
|
||||||
import Stream from '../../common/utils/Stream';
|
|
||||||
|
|
||||||
export default class MailPage extends Page {
|
export default class MailPage extends AdminPage {
|
||||||
oninit(vnode) {
|
oninit(vnode) {
|
||||||
super.oninit(vnode);
|
super.oninit(vnode);
|
||||||
|
|
||||||
this.saving = false;
|
|
||||||
this.sendingTest = false;
|
this.sendingTest = false;
|
||||||
this.refresh();
|
this.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
headerInfo() {
|
||||||
|
return {
|
||||||
|
className: 'MailPage',
|
||||||
|
icon: 'fas fa-envelope',
|
||||||
|
title: app.translator.trans('core.admin.email.title'),
|
||||||
|
description: app.translator.trans('core.admin.email.description'),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
refresh() {
|
refresh() {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
|
|
||||||
this.driverFields = {};
|
|
||||||
this.fields = ['mail_driver', 'mail_from'];
|
|
||||||
this.values = {};
|
|
||||||
this.status = { sending: false, errors: {} };
|
this.status = { sending: false, errors: {} };
|
||||||
|
|
||||||
const settings = app.data.settings;
|
|
||||||
this.fields.forEach((key) => (this.values[key] = Stream(settings[key])));
|
|
||||||
|
|
||||||
app
|
app
|
||||||
.request({
|
.request({
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
@@ -37,150 +36,78 @@ export default class MailPage extends Page {
|
|||||||
this.status.sending = response['data']['attributes']['sending'];
|
this.status.sending = response['data']['attributes']['sending'];
|
||||||
this.status.errors = response['data']['attributes']['errors'];
|
this.status.errors = response['data']['attributes']['errors'];
|
||||||
|
|
||||||
for (const driver in this.driverFields) {
|
|
||||||
for (const field in this.driverFields[driver]) {
|
|
||||||
this.fields.push(field);
|
|
||||||
this.values[field] = Stream(settings[field]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
m.redraw();
|
m.redraw();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
view() {
|
content() {
|
||||||
if (this.loading || this.saving) {
|
if (this.loading) {
|
||||||
return (
|
return <LoadingIndicator />;
|
||||||
<div className="MailPage">
|
|
||||||
<div className="container">
|
|
||||||
<LoadingIndicator />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const fields = this.driverFields[this.values.mail_driver()];
|
const fields = this.driverFields[this.setting('mail_driver')()];
|
||||||
const fieldKeys = Object.keys(fields);
|
const fieldKeys = Object.keys(fields);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="MailPage">
|
<div className="Form">
|
||||||
<div className="container">
|
{this.buildSettingComponent({
|
||||||
<form onsubmit={this.onsubmit.bind(this)}>
|
type: 'text',
|
||||||
<h2>{app.translator.trans('core.admin.email.heading')}</h2>
|
setting: 'mail_from',
|
||||||
<div className="helpText">{app.translator.trans('core.admin.email.text')}</div>
|
label: app.translator.trans('core.admin.email.addresses_heading'),
|
||||||
|
className: 'MailPage-MailSettings',
|
||||||
|
})}
|
||||||
|
{this.buildSettingComponent({
|
||||||
|
type: 'select',
|
||||||
|
setting: 'mail_driver',
|
||||||
|
options: Object.keys(this.driverFields).reduce((memo, val) => ({ ...memo, [val]: val }), {}),
|
||||||
|
label: app.translator.trans('core.admin.email.driver_heading'),
|
||||||
|
className: 'MailPage-MailSettings',
|
||||||
|
})}
|
||||||
|
{this.status.sending ||
|
||||||
|
Alert.component(
|
||||||
|
{
|
||||||
|
dismissible: false,
|
||||||
|
},
|
||||||
|
app.translator.trans('core.admin.email.not_sending_message')
|
||||||
|
)}
|
||||||
|
|
||||||
{FieldSet.component(
|
{fieldKeys.length > 0 && (
|
||||||
{
|
<FieldSet label={app.translator.trans(`core.admin.email.${this.setting('mail_driver')()}_heading`)} className="MailPage-MailSettings">
|
||||||
label: app.translator.trans('core.admin.email.addresses_heading'),
|
<div className="MailPage-MailSettings-input">
|
||||||
className: 'MailPage-MailSettings',
|
{fieldKeys.map((field) => {
|
||||||
},
|
const fieldInfo = fields[field];
|
||||||
[
|
|
||||||
<div className="MailPage-MailSettings-input">
|
|
||||||
<label>
|
|
||||||
{app.translator.trans('core.admin.email.from_label')}
|
|
||||||
<input className="FormControl" bidi={this.values.mail_from} />
|
|
||||||
</label>
|
|
||||||
</div>,
|
|
||||||
]
|
|
||||||
)}
|
|
||||||
|
|
||||||
{FieldSet.component(
|
return [
|
||||||
{
|
this.buildSettingComponent({
|
||||||
label: app.translator.trans('core.admin.email.driver_heading'),
|
type: typeof this.setting(field)() === 'string' ? 'text' : 'select',
|
||||||
className: 'MailPage-MailSettings',
|
label: app.translator.trans(`core.admin.email.${field}_label`),
|
||||||
},
|
setting: field,
|
||||||
[
|
options: fieldInfo,
|
||||||
<div className="MailPage-MailSettings-input">
|
}),
|
||||||
<label>
|
this.status.errors[field] && <p className="ValidationError">{this.status.errors[field]}</p>,
|
||||||
{app.translator.trans('core.admin.email.driver_label')}
|
];
|
||||||
<Select
|
})}
|
||||||
value={this.values.mail_driver()}
|
</div>
|
||||||
options={Object.keys(this.driverFields).reduce((memo, val) => ({ ...memo, [val]: val }), {})}
|
</FieldSet>
|
||||||
onchange={this.values.mail_driver}
|
)}
|
||||||
/>
|
{this.submitButton()}
|
||||||
</label>
|
|
||||||
</div>,
|
|
||||||
]
|
|
||||||
)}
|
|
||||||
|
|
||||||
{this.status.sending ||
|
<FieldSet label={app.translator.trans('core.admin.email.send_test_mail_heading')} className="MailPage-MailSettings">
|
||||||
Alert.component(
|
<div className="helpText">{app.translator.trans('core.admin.email.send_test_mail_text', { email: app.session.user.email() })}</div>
|
||||||
{
|
{Button.component(
|
||||||
dismissible: false,
|
{
|
||||||
},
|
className: 'Button Button--primary',
|
||||||
app.translator.trans('core.admin.email.not_sending_message')
|
disabled: this.sendingTest || this.isChanged(),
|
||||||
)}
|
onclick: () => this.sendTestEmail(),
|
||||||
|
},
|
||||||
{fieldKeys.length > 0 &&
|
app.translator.trans('core.admin.email.send_test_mail_button')
|
||||||
FieldSet.component(
|
)}
|
||||||
{
|
</FieldSet>
|
||||||
label: app.translator.trans(`core.admin.email.${this.values.mail_driver()}_heading`),
|
|
||||||
className: 'MailPage-MailSettings',
|
|
||||||
},
|
|
||||||
[
|
|
||||||
<div className="MailPage-MailSettings-input">
|
|
||||||
{fieldKeys.map((field) => [
|
|
||||||
<label>
|
|
||||||
{app.translator.trans(`core.admin.email.${field}_label`)}
|
|
||||||
{this.renderField(field)}
|
|
||||||
</label>,
|
|
||||||
this.status.errors[field] && <p className="ValidationError">{this.status.errors[field]}</p>,
|
|
||||||
])}
|
|
||||||
</div>,
|
|
||||||
]
|
|
||||||
)}
|
|
||||||
|
|
||||||
<FieldSet>
|
|
||||||
{Button.component(
|
|
||||||
{
|
|
||||||
type: 'submit',
|
|
||||||
className: 'Button Button--primary',
|
|
||||||
disabled: !this.changed(),
|
|
||||||
},
|
|
||||||
app.translator.trans('core.admin.email.submit_button')
|
|
||||||
)}
|
|
||||||
</FieldSet>
|
|
||||||
|
|
||||||
{FieldSet.component(
|
|
||||||
{
|
|
||||||
label: app.translator.trans('core.admin.email.send_test_mail_heading'),
|
|
||||||
className: 'MailPage-MailSettings',
|
|
||||||
},
|
|
||||||
[
|
|
||||||
<div className="helpText">{app.translator.trans('core.admin.email.send_test_mail_text', { email: app.session.user.email() })}</div>,
|
|
||||||
Button.component(
|
|
||||||
{
|
|
||||||
className: 'Button Button--primary',
|
|
||||||
disabled: this.sendingTest || this.changed(),
|
|
||||||
onclick: () => this.sendTestEmail(),
|
|
||||||
},
|
|
||||||
app.translator.trans('core.admin.email.send_test_mail_button')
|
|
||||||
),
|
|
||||||
]
|
|
||||||
)}
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
renderField(name) {
|
|
||||||
const driver = this.values.mail_driver();
|
|
||||||
const field = this.driverFields[driver][name];
|
|
||||||
const prop = this.values[name];
|
|
||||||
|
|
||||||
if (typeof field === 'string') {
|
|
||||||
return <input className="FormControl" bidi={prop} />;
|
|
||||||
} else {
|
|
||||||
return <Select value={prop()} options={field} onchange={prop} />;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
changed() {
|
|
||||||
return this.fields.some((key) => this.values[key]() !== app.data.settings[key]);
|
|
||||||
}
|
|
||||||
|
|
||||||
sendTestEmail() {
|
sendTestEmail() {
|
||||||
if (this.saving || this.sendingTest) return;
|
if (this.saving || this.sendingTest) return;
|
||||||
|
|
||||||
@@ -203,26 +130,7 @@ export default class MailPage extends Page {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onsubmit(e) {
|
saveSettings(e) {
|
||||||
e.preventDefault();
|
super.saveSettings(e).then(this.refresh());
|
||||||
|
|
||||||
if (this.saving || this.sendingTest) return;
|
|
||||||
|
|
||||||
this.saving = true;
|
|
||||||
app.alerts.dismiss(this.successAlert);
|
|
||||||
|
|
||||||
const settings = {};
|
|
||||||
|
|
||||||
this.fields.forEach((key) => (settings[key] = this.values[key]()));
|
|
||||||
|
|
||||||
saveSettings(settings)
|
|
||||||
.then(() => {
|
|
||||||
this.successAlert = app.alerts.show({ type: 'success' }, app.translator.trans('core.admin.basics.saved_message'));
|
|
||||||
})
|
|
||||||
.catch(() => {})
|
|
||||||
.then(() => {
|
|
||||||
this.saving = false;
|
|
||||||
this.refresh();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -6,12 +6,6 @@ import ItemList from '../../common/utils/ItemList';
|
|||||||
import icon from '../../common/helpers/icon';
|
import icon from '../../common/helpers/icon';
|
||||||
|
|
||||||
export default class PermissionGrid extends Component {
|
export default class PermissionGrid extends Component {
|
||||||
oninit(vnode) {
|
|
||||||
super.oninit(vnode);
|
|
||||||
|
|
||||||
this.permissions = this.permissionItems().toArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
view() {
|
view() {
|
||||||
const scopes = this.scopeItems().toArray();
|
const scopes = this.scopeItems().toArray();
|
||||||
|
|
||||||
@@ -35,25 +29,27 @@ export default class PermissionGrid extends Component {
|
|||||||
<th>{this.scopeControlItems().toArray()}</th>
|
<th>{this.scopeControlItems().toArray()}</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
{this.permissions.map((section) => (
|
{this.permissionItems()
|
||||||
<tbody>
|
.toArray()
|
||||||
<tr className="PermissionGrid-section">
|
.map((section) => (
|
||||||
<th>{section.label}</th>
|
<tbody>
|
||||||
{permissionCells(section)}
|
<tr className="PermissionGrid-section">
|
||||||
<td />
|
<th>{section.label}</th>
|
||||||
</tr>
|
{permissionCells(section)}
|
||||||
{section.children.map((child) => (
|
|
||||||
<tr className="PermissionGrid-child">
|
|
||||||
<th>
|
|
||||||
{icon(child.icon)}
|
|
||||||
{child.label}
|
|
||||||
</th>
|
|
||||||
{permissionCells(child)}
|
|
||||||
<td />
|
<td />
|
||||||
</tr>
|
</tr>
|
||||||
))}
|
{section.children.map((child) => (
|
||||||
</tbody>
|
<tr className="PermissionGrid-child">
|
||||||
))}
|
<th>
|
||||||
|
{icon(child.icon)}
|
||||||
|
{child.label}
|
||||||
|
</th>
|
||||||
|
{permissionCells(child)}
|
||||||
|
<td />
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
))}
|
||||||
</table>
|
</table>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -158,6 +154,8 @@ export default class PermissionGrid extends Component {
|
|||||||
permission: 'user.viewLastSeenAt',
|
permission: 'user.viewLastSeenAt',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
items.merge(app.extensionData.getAllExtensionPermissions('view'));
|
||||||
|
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,6 +196,8 @@ export default class PermissionGrid extends Component {
|
|||||||
90
|
90
|
||||||
);
|
);
|
||||||
|
|
||||||
|
items.merge(app.extensionData.getAllExtensionPermissions('start'));
|
||||||
|
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,6 +238,8 @@ export default class PermissionGrid extends Component {
|
|||||||
90
|
90
|
||||||
);
|
);
|
||||||
|
|
||||||
|
items.merge(app.extensionData.getAllExtensionPermissions('reply'));
|
||||||
|
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -325,15 +327,37 @@ export default class PermissionGrid extends Component {
|
|||||||
);
|
);
|
||||||
|
|
||||||
items.add(
|
items.add(
|
||||||
'userEdit',
|
'userEditCredentials',
|
||||||
{
|
{
|
||||||
icon: 'fas fa-user-cog',
|
icon: 'fas fa-user-cog',
|
||||||
|
label: app.translator.trans('core.admin.permissions.edit_users_credentials_label'),
|
||||||
|
permission: 'user.editCredentials',
|
||||||
|
},
|
||||||
|
60
|
||||||
|
);
|
||||||
|
|
||||||
|
items.add(
|
||||||
|
'userEditGroups',
|
||||||
|
{
|
||||||
|
icon: 'fas fa-users-cog',
|
||||||
|
label: app.translator.trans('core.admin.permissions.edit_users_groups_label'),
|
||||||
|
permission: 'user.editGroups',
|
||||||
|
},
|
||||||
|
60
|
||||||
|
);
|
||||||
|
|
||||||
|
items.add(
|
||||||
|
'userEdit',
|
||||||
|
{
|
||||||
|
icon: 'fas fa-address-card',
|
||||||
label: app.translator.trans('core.admin.permissions.edit_users_label'),
|
label: app.translator.trans('core.admin.permissions.edit_users_label'),
|
||||||
permission: 'user.edit',
|
permission: 'user.edit',
|
||||||
},
|
},
|
||||||
60
|
60
|
||||||
);
|
);
|
||||||
|
|
||||||
|
items.merge(app.extensionData.getAllExtensionPermissions('moderate'));
|
||||||
|
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,40 +1,43 @@
|
|||||||
import Page from '../../common/components/Page';
|
|
||||||
import GroupBadge from '../../common/components/GroupBadge';
|
import GroupBadge from '../../common/components/GroupBadge';
|
||||||
import EditGroupModal from './EditGroupModal';
|
import EditGroupModal from './EditGroupModal';
|
||||||
import Group from '../../common/models/Group';
|
import Group from '../../common/models/Group';
|
||||||
import icon from '../../common/helpers/icon';
|
import icon from '../../common/helpers/icon';
|
||||||
import PermissionGrid from './PermissionGrid';
|
import PermissionGrid from './PermissionGrid';
|
||||||
|
import AdminPage from './AdminPage';
|
||||||
|
|
||||||
export default class PermissionsPage extends Page {
|
export default class PermissionsPage extends AdminPage {
|
||||||
view() {
|
headerInfo() {
|
||||||
return (
|
return {
|
||||||
<div className="PermissionsPage">
|
className: 'PermissionsPage',
|
||||||
<div className="PermissionsPage-groups">
|
icon: 'fas fa-key',
|
||||||
<div className="container">
|
title: app.translator.trans('core.admin.permissions.title'),
|
||||||
{app.store
|
description: app.translator.trans('core.admin.permissions.description'),
|
||||||
.all('groups')
|
};
|
||||||
.filter((group) => [Group.GUEST_ID, Group.MEMBER_ID].indexOf(group.id()) === -1)
|
}
|
||||||
.map((group) => (
|
|
||||||
<button className="Button Group" onclick={() => app.modal.show(EditGroupModal, { group })}>
|
content() {
|
||||||
{GroupBadge.component({
|
return [
|
||||||
group,
|
<div className="PermissionsPage-groups">
|
||||||
className: 'Group-icon',
|
{app.store
|
||||||
label: null,
|
.all('groups')
|
||||||
})}
|
.filter((group) => [Group.GUEST_ID, Group.MEMBER_ID].indexOf(group.id()) === -1)
|
||||||
<span className="Group-name">{group.namePlural()}</span>
|
.map((group) => (
|
||||||
</button>
|
<button className="Button Group" onclick={() => app.modal.show(EditGroupModal, { group })}>
|
||||||
))}
|
{GroupBadge.component({
|
||||||
<button className="Button Group Group--add" onclick={() => app.modal.show(EditGroupModal)}>
|
group,
|
||||||
{icon('fas fa-plus', { className: 'Group-icon' })}
|
className: 'Group-icon',
|
||||||
<span className="Group-name">{app.translator.trans('core.admin.permissions.new_group_button')}</span>
|
label: null,
|
||||||
|
})}
|
||||||
|
<span className="Group-name">{group.namePlural()}</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
))}
|
||||||
</div>
|
<button className="Button Group Group--add" onclick={() => app.modal.show(EditGroupModal)}>
|
||||||
|
{icon('fas fa-plus', { className: 'Group-icon' })}
|
||||||
|
<span className="Group-name">{app.translator.trans('core.admin.permissions.new_group_button')}</span>
|
||||||
|
</button>
|
||||||
|
</div>,
|
||||||
|
|
||||||
<div className="PermissionsPage-permissions">
|
<div className="PermissionsPage-permissions">{PermissionGrid.component()}</div>,
|
||||||
<div className="container">{PermissionGrid.component()}</div>
|
];
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,17 +1,13 @@
|
|||||||
import AdminApplication from './AdminApplication';
|
import app from './app';
|
||||||
|
|
||||||
const app = new AdminApplication();
|
|
||||||
|
|
||||||
// Backwards compatibility
|
|
||||||
window.app = app;
|
|
||||||
|
|
||||||
export { app };
|
export { app };
|
||||||
|
|
||||||
// Export public API
|
// Export public API
|
||||||
|
|
||||||
// Export compat API
|
// Export compat API
|
||||||
import compat from './compat';
|
import compatObj from './compat';
|
||||||
|
import proxifyCompat from '../common/utils/proxifyCompat';
|
||||||
|
|
||||||
compat.app = app;
|
compatObj.app = app;
|
||||||
|
|
||||||
export { compat };
|
export const compat = proxifyCompat(compatObj, 'admin');
|
||||||
|
19
js/src/admin/resolvers/ExtensionPageResolver.ts
Normal file
19
js/src/admin/resolvers/ExtensionPageResolver.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import DefaultResolver from '../../common/resolvers/DefaultResolver';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A custom route resolver for ExtensionPage that generates handles routes
|
||||||
|
* to default extension pages or a page provided by an extension.
|
||||||
|
*/
|
||||||
|
export default class ExtensionPageResolver extends DefaultResolver {
|
||||||
|
static extension: string | null = null;
|
||||||
|
|
||||||
|
onmatch(args, requestedPath, route) {
|
||||||
|
const extensionPage = app.extensionData.getPage(args.id);
|
||||||
|
|
||||||
|
if (extensionPage) {
|
||||||
|
return extensionPage;
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.onmatch(args, requestedPath, route);
|
||||||
|
}
|
||||||
|
}
|
@@ -2,8 +2,9 @@ import DashboardPage from './components/DashboardPage';
|
|||||||
import BasicsPage from './components/BasicsPage';
|
import BasicsPage from './components/BasicsPage';
|
||||||
import PermissionsPage from './components/PermissionsPage';
|
import PermissionsPage from './components/PermissionsPage';
|
||||||
import AppearancePage from './components/AppearancePage';
|
import AppearancePage from './components/AppearancePage';
|
||||||
import ExtensionsPage from './components/ExtensionsPage';
|
|
||||||
import MailPage from './components/MailPage';
|
import MailPage from './components/MailPage';
|
||||||
|
import ExtensionPage from './components/ExtensionPage';
|
||||||
|
import ExtensionPageResolver from './resolvers/ExtensionPageResolver';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The `routes` initializer defines the forum app's routes.
|
* The `routes` initializer defines the forum app's routes.
|
||||||
@@ -16,7 +17,7 @@ export default function (app) {
|
|||||||
basics: { path: '/basics', component: BasicsPage },
|
basics: { path: '/basics', component: BasicsPage },
|
||||||
permissions: { path: '/permissions', component: PermissionsPage },
|
permissions: { path: '/permissions', component: PermissionsPage },
|
||||||
appearance: { path: '/appearance', component: AppearancePage },
|
appearance: { path: '/appearance', component: AppearancePage },
|
||||||
extensions: { path: '/extensions', component: ExtensionsPage },
|
|
||||||
mail: { path: '/mail', component: MailPage },
|
mail: { path: '/mail', component: MailPage },
|
||||||
|
extension: { path: '/extension/:id', component: ExtensionPage, resolverClass: ExtensionPageResolver },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
177
js/src/admin/utils/ExtensionData.js
Normal file
177
js/src/admin/utils/ExtensionData.js
Normal file
@@ -0,0 +1,177 @@
|
|||||||
|
import ItemList from '../../common/utils/ItemList';
|
||||||
|
|
||||||
|
export default class ExtensionData {
|
||||||
|
constructor() {
|
||||||
|
this.data = {};
|
||||||
|
this.currentExtension = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function simply takes the extension id
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* app.extensionData.load('flarum-tags')
|
||||||
|
*
|
||||||
|
* flarum/flags -> flarum-flags | acme/extension -> acme-extension
|
||||||
|
*
|
||||||
|
* @param extension
|
||||||
|
*/
|
||||||
|
for(extension) {
|
||||||
|
this.currentExtension = extension;
|
||||||
|
this.data[extension] = this.data[extension] || {};
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function registers your settings with Flarum
|
||||||
|
*
|
||||||
|
* It takes either a settings object or a callback.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
*
|
||||||
|
* .registerSetting({
|
||||||
|
* setting: 'flarum-flags.guidelines_url',
|
||||||
|
* type: 'text', // This will be inputted into the input tag for the setting (text/number/etc)
|
||||||
|
* label: app.translator.trans('flarum-flags.admin.settings.guidelines_url_label')
|
||||||
|
* }, 15) // priority is optional (ItemList)
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param content
|
||||||
|
* @param priority
|
||||||
|
* @returns {ExtensionData}
|
||||||
|
*/
|
||||||
|
registerSetting(content, priority = 0) {
|
||||||
|
this.data[this.currentExtension].settings = this.data[this.currentExtension].settings || new ItemList();
|
||||||
|
|
||||||
|
// Callbacks can be passed in instead of settings to display custom content.
|
||||||
|
// By default, they will be added with the `null` key, since they don't have a `.setting` attr.
|
||||||
|
// To support multiple such items for one extension, we assign a random ID.
|
||||||
|
// 36 is arbitrary length, but makes collisions very unlikely.
|
||||||
|
if (typeof content === 'function') {
|
||||||
|
content.setting = Math.random().toString(36);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.data[this.currentExtension].settings.add(content.setting, content, priority);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function registers your permission with Flarum
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
*
|
||||||
|
* .registerPermission('permissions', {
|
||||||
|
* icon: 'fas fa-flag',
|
||||||
|
* label: app.translator.trans('flarum-flags.admin.permissions.view_flags_label'),
|
||||||
|
* permission: 'discussion.viewFlags'
|
||||||
|
* }, 'moderate', 65)
|
||||||
|
*
|
||||||
|
* @param content
|
||||||
|
* @param permissionType
|
||||||
|
* @param priority
|
||||||
|
* @returns {ExtensionData}
|
||||||
|
*/
|
||||||
|
registerPermission(content, permissionType = null, priority = 0) {
|
||||||
|
this.data[this.currentExtension].permissions = this.data[this.currentExtension].permissions || {};
|
||||||
|
|
||||||
|
if (!this.data[this.currentExtension].permissions[permissionType]) {
|
||||||
|
this.data[this.currentExtension].permissions[permissionType] = new ItemList();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.data[this.currentExtension].permissions[permissionType].add(content.permission, content, priority);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replace the default extension page with a custom component.
|
||||||
|
* This component would typically extend ExtensionPage
|
||||||
|
*
|
||||||
|
* @param component
|
||||||
|
* @returns {ExtensionData}
|
||||||
|
*/
|
||||||
|
registerPage(component) {
|
||||||
|
this.data[this.currentExtension].page = component;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an extension's registered settings
|
||||||
|
*
|
||||||
|
* @param extensionId
|
||||||
|
* @returns {boolean|*}
|
||||||
|
*/
|
||||||
|
getSettings(extensionId) {
|
||||||
|
if (this.data[extensionId] && this.data[extensionId].settings) {
|
||||||
|
return this.data[extensionId].settings.toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Get an ItemList of all extensions' registered permissions
|
||||||
|
*
|
||||||
|
* @param extension
|
||||||
|
* @param type
|
||||||
|
* @returns {ItemList}
|
||||||
|
*/
|
||||||
|
getAllExtensionPermissions(type) {
|
||||||
|
const items = new ItemList();
|
||||||
|
|
||||||
|
Object.keys(this.data).map((extension) => {
|
||||||
|
if (this.extensionHasPermissions(extension) && this.data[extension].permissions[type]) {
|
||||||
|
items.merge(this.data[extension].permissions[type]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a singular extension's registered permissions
|
||||||
|
*
|
||||||
|
* @param extension
|
||||||
|
* @param type
|
||||||
|
* @returns {boolean|*}
|
||||||
|
*/
|
||||||
|
getExtensionPermissions(extension, type) {
|
||||||
|
if (this.extensionHasPermissions(extension) && this.data[extension].permissions[type]) {
|
||||||
|
return this.data[extension].permissions[type];
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ItemList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether a given extension has registered permissions.
|
||||||
|
*
|
||||||
|
* @param extension
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
extensionHasPermissions(extension) {
|
||||||
|
if (this.data[extension] && this.data[extension].permissions) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an extension's custom page component if it exists.
|
||||||
|
*
|
||||||
|
* @param extension
|
||||||
|
* @returns {boolean|*}
|
||||||
|
*/
|
||||||
|
getPage(extension) {
|
||||||
|
if (this.data[extension]) {
|
||||||
|
return this.data[extension].page;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
25
js/src/admin/utils/getCategorizedExtensions.js
Normal file
25
js/src/admin/utils/getCategorizedExtensions.js
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
export default function getCategorizedExtensions() {
|
||||||
|
let extensions = {};
|
||||||
|
|
||||||
|
Object.keys(app.data.extensions).map((id) => {
|
||||||
|
const extension = app.data.extensions[id];
|
||||||
|
let category = extension.extra['flarum-extension'].category;
|
||||||
|
|
||||||
|
// Wrap languages packs into new system
|
||||||
|
if (extension.extra['flarum-locale']) {
|
||||||
|
category = 'language';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (category in app.extensionCategories) {
|
||||||
|
extensions[category] = extensions[category] || [];
|
||||||
|
|
||||||
|
extensions[category].push(extension);
|
||||||
|
} else {
|
||||||
|
extensions.feature = extensions.feature || [];
|
||||||
|
|
||||||
|
extensions.feature.push(extension);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return extensions;
|
||||||
|
}
|
5
js/src/admin/utils/isExtensionEnabled.js
Normal file
5
js/src/admin/utils/isExtensionEnabled.js
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
export default function isExtensionEnabled(name) {
|
||||||
|
const enabled = JSON.parse(app.data.settings.extensions_enabled);
|
||||||
|
|
||||||
|
return enabled.includes(name);
|
||||||
|
}
|
@@ -159,6 +159,8 @@ export default class Application {
|
|||||||
title = '';
|
title = '';
|
||||||
titleCount = 0;
|
titleCount = 0;
|
||||||
|
|
||||||
|
initialRoute;
|
||||||
|
|
||||||
load(payload) {
|
load(payload) {
|
||||||
this.data = payload;
|
this.data = payload;
|
||||||
this.translator.locale = payload.locale;
|
this.translator.locale = payload.locale;
|
||||||
@@ -174,6 +176,8 @@ export default class Application {
|
|||||||
this.session = new Session(this.store.getById('users', this.data.session.userId), this.data.session.csrfToken);
|
this.session = new Session(this.store.getById('users', this.data.session.userId), this.data.session.csrfToken);
|
||||||
|
|
||||||
this.mount();
|
this.mount();
|
||||||
|
|
||||||
|
this.initialRoute = window.location.href;
|
||||||
}
|
}
|
||||||
|
|
||||||
bootExtensions(extensions) {
|
bootExtensions(extensions) {
|
||||||
@@ -226,7 +230,8 @@ export default class Application {
|
|||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
preloadedApiDocument() {
|
preloadedApiDocument() {
|
||||||
if (this.data.apiDocument) {
|
// If the URL has changed, the preloaded Api document is invalid.
|
||||||
|
if (this.data.apiDocument && window.location.href === this.initialRoute) {
|
||||||
const results = this.store.pushPayload(this.data.apiDocument);
|
const results = this.store.pushPayload(this.data.apiDocument);
|
||||||
|
|
||||||
this.data.apiDocument = null;
|
this.data.apiDocument = null;
|
||||||
@@ -270,7 +275,7 @@ export default class Application {
|
|||||||
|
|
||||||
updateTitle() {
|
updateTitle() {
|
||||||
const count = this.titleCount ? `(${this.titleCount}) ` : '';
|
const count = this.titleCount ? `(${this.titleCount}) ` : '';
|
||||||
const pageTitleWithSeparator = this.title && m.route.get() !== '/' ? this.title + ' - ' : '';
|
const pageTitleWithSeparator = this.title && m.route.get() !== this.forum.attribute('basePath') + '/' ? this.title + ' - ' : '';
|
||||||
const title = this.forum.attribute('title');
|
const title = this.forum.attribute('title');
|
||||||
document.title = count + pageTitleWithSeparator + title;
|
document.title = count + pageTitleWithSeparator + title;
|
||||||
}
|
}
|
||||||
|
@@ -1,8 +1,5 @@
|
|||||||
import * as Mithril from 'mithril';
|
import * as Mithril from 'mithril';
|
||||||
|
|
||||||
let deprecatedPropsWarned = false;
|
|
||||||
let deprecatedInitPropsWarned = false;
|
|
||||||
|
|
||||||
export interface ComponentAttrs extends Mithril.Attributes {}
|
export interface ComponentAttrs extends Mithril.Attributes {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -80,12 +77,12 @@ export default abstract class Component<T extends ComponentAttrs = ComponentAttr
|
|||||||
* containing all of the `li` elements inside the DOM element of this
|
* containing all of the `li` elements inside the DOM element of this
|
||||||
* component.
|
* component.
|
||||||
*
|
*
|
||||||
* @param {String} [selector] a jQuery-compatible selector string
|
* @param [selector] a jQuery-compatible selector string
|
||||||
* @returns {jQuery} the jQuery object for the DOM node
|
* @returns the jQuery object for the DOM node
|
||||||
* @final
|
* @final
|
||||||
*/
|
*/
|
||||||
protected $(selector) {
|
protected $(selector: string): JQuery {
|
||||||
const $element = $(this.element);
|
const $element = $(this.element) as JQuery<HTMLElement>;
|
||||||
|
|
||||||
return selector ? $element.find(selector) : $element;
|
return selector ? $element.find(selector) : $element;
|
||||||
}
|
}
|
||||||
@@ -97,7 +94,7 @@ export default abstract class Component<T extends ComponentAttrs = ComponentAttr
|
|||||||
* @see https://mithril.js.org/hyperscript.html#mselector,-attributes,-children
|
* @see https://mithril.js.org/hyperscript.html#mselector,-attributes,-children
|
||||||
*/
|
*/
|
||||||
static component(attrs = {}, children = null): Mithril.Vnode {
|
static component(attrs = {}, children = null): Mithril.Vnode {
|
||||||
const componentAttrs = Object.assign({}, attrs);
|
const componentAttrs = Object.assign({}, attrs) as Record<string, unknown>;
|
||||||
|
|
||||||
return m(this as any, componentAttrs, children);
|
return m(this as any, componentAttrs, children);
|
||||||
}
|
}
|
||||||
@@ -131,38 +128,5 @@ export default abstract class Component<T extends ComponentAttrs = ComponentAttr
|
|||||||
*
|
*
|
||||||
* This can be used to assign default values for missing, optional attrs.
|
* This can be used to assign default values for missing, optional attrs.
|
||||||
*/
|
*/
|
||||||
protected static initAttrs<T>(attrs: T): void {
|
protected static initAttrs<T>(attrs: T): void {}
|
||||||
// Deprecated, part of Mithril 2 BC layer
|
|
||||||
if ('initProps' in this && !deprecatedInitPropsWarned) {
|
|
||||||
deprecatedInitPropsWarned = true;
|
|
||||||
console.warn('initProps is deprecated, please use initAttrs instead.');
|
|
||||||
(this as any).initProps(attrs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// BEGIN DEPRECATED MITHRIL 2 BC LAYER
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The attributes passed into the component.
|
|
||||||
*
|
|
||||||
* @see https://mithril.js.org/components.html#passing-data-to-components
|
|
||||||
*
|
|
||||||
* @deprecated, use attrs instead.
|
|
||||||
*/
|
|
||||||
get props() {
|
|
||||||
if (!deprecatedPropsWarned) {
|
|
||||||
deprecatedPropsWarned = true;
|
|
||||||
console.warn('this.props is deprecated, please use this.attrs instead.');
|
|
||||||
}
|
|
||||||
return this.attrs;
|
|
||||||
}
|
|
||||||
set props(props) {
|
|
||||||
if (!deprecatedPropsWarned) {
|
|
||||||
deprecatedPropsWarned = true;
|
|
||||||
console.warn('this.props is deprecated, please use this.attrs instead.');
|
|
||||||
}
|
|
||||||
this.attrs = props;
|
|
||||||
}
|
|
||||||
|
|
||||||
// END DEPRECATED MITHRIL 2 BC LAYER
|
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
import * as extend from './extend';
|
import * as extend from './extend';
|
||||||
import Session from './Session';
|
import Session from './Session';
|
||||||
import Store from './Store';
|
import Store from './Store';
|
||||||
|
import BasicEditorDriver from './utils/BasicEditorDriver';
|
||||||
import evented from './utils/evented';
|
import evented from './utils/evented';
|
||||||
import liveHumanTimes from './utils/liveHumanTimes';
|
import liveHumanTimes from './utils/liveHumanTimes';
|
||||||
import ItemList from './utils/ItemList';
|
import ItemList from './utils/ItemList';
|
||||||
@@ -19,8 +20,8 @@ import extract from './utils/extract';
|
|||||||
import ScrollListener from './utils/ScrollListener';
|
import ScrollListener from './utils/ScrollListener';
|
||||||
import stringToColor from './utils/stringToColor';
|
import stringToColor from './utils/stringToColor';
|
||||||
import subclassOf from './utils/subclassOf';
|
import subclassOf from './utils/subclassOf';
|
||||||
import SuperTextarea from './utils/SuperTextarea';
|
|
||||||
import patchMithril from './utils/patchMithril';
|
import patchMithril from './utils/patchMithril';
|
||||||
|
import proxifyCompat from './utils/proxifyCompat';
|
||||||
import classList from './utils/classList';
|
import classList from './utils/classList';
|
||||||
import extractText from './utils/extractText';
|
import extractText from './utils/extractText';
|
||||||
import formatNumber from './utils/formatNumber';
|
import formatNumber from './utils/formatNumber';
|
||||||
@@ -56,6 +57,8 @@ import ModalManager from './components/ModalManager';
|
|||||||
import Button from './components/Button';
|
import Button from './components/Button';
|
||||||
import Modal from './components/Modal';
|
import Modal from './components/Modal';
|
||||||
import GroupBadge from './components/GroupBadge';
|
import GroupBadge from './components/GroupBadge';
|
||||||
|
import TextEditor from './components/TextEditor';
|
||||||
|
import TextEditorButton from './components/TextEditorButton';
|
||||||
import Model from './Model';
|
import Model from './Model';
|
||||||
import Application from './Application';
|
import Application from './Application';
|
||||||
import fullTime from './helpers/fullTime';
|
import fullTime from './helpers/fullTime';
|
||||||
@@ -74,6 +77,7 @@ export default {
|
|||||||
extend: extend,
|
extend: extend,
|
||||||
Session: Session,
|
Session: Session,
|
||||||
Store: Store,
|
Store: Store,
|
||||||
|
'utils/BasicEditorDriver': BasicEditorDriver,
|
||||||
'utils/evented': evented,
|
'utils/evented': evented,
|
||||||
'utils/liveHumanTimes': liveHumanTimes,
|
'utils/liveHumanTimes': liveHumanTimes,
|
||||||
'utils/ItemList': ItemList,
|
'utils/ItemList': ItemList,
|
||||||
@@ -91,9 +95,9 @@ export default {
|
|||||||
'utils/stringToColor': stringToColor,
|
'utils/stringToColor': stringToColor,
|
||||||
'utils/Stream': Stream,
|
'utils/Stream': Stream,
|
||||||
'utils/subclassOf': subclassOf,
|
'utils/subclassOf': subclassOf,
|
||||||
'utils/SuperTextarea': SuperTextarea,
|
|
||||||
'utils/setRouteWithForcedRefresh': setRouteWithForcedRefresh,
|
'utils/setRouteWithForcedRefresh': setRouteWithForcedRefresh,
|
||||||
'utils/patchMithril': patchMithril,
|
'utils/patchMithril': patchMithril,
|
||||||
|
'utils/proxifyCompat': proxifyCompat,
|
||||||
'utils/classList': classList,
|
'utils/classList': classList,
|
||||||
'utils/extractText': extractText,
|
'utils/extractText': extractText,
|
||||||
'utils/formatNumber': formatNumber,
|
'utils/formatNumber': formatNumber,
|
||||||
@@ -130,6 +134,8 @@ export default {
|
|||||||
'components/Button': Button,
|
'components/Button': Button,
|
||||||
'components/Modal': Modal,
|
'components/Modal': Modal,
|
||||||
'components/GroupBadge': GroupBadge,
|
'components/GroupBadge': GroupBadge,
|
||||||
|
'components/TextEditor': TextEditor,
|
||||||
|
'components/TextEditorButton': TextEditorButton,
|
||||||
Model: Model,
|
Model: Model,
|
||||||
Application: Application,
|
Application: Application,
|
||||||
'helpers/fullTime': fullTime,
|
'helpers/fullTime': fullTime,
|
||||||
|
@@ -35,6 +35,11 @@ export default class Button extends Component {
|
|||||||
attrs['aria-label'] = attrs.title;
|
attrs['aria-label'] = attrs.title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If given a translation object, extract the text.
|
||||||
|
if (typeof attrs.title === 'object') {
|
||||||
|
attrs.title = extractText(attrs.title);
|
||||||
|
}
|
||||||
|
|
||||||
// If nothing else is provided, we use the textual button content as tooltip
|
// If nothing else is provided, we use the textual button content as tooltip
|
||||||
if (!attrs.title && vnode.children) {
|
if (!attrs.title && vnode.children) {
|
||||||
attrs.title = extractText(vnode.children);
|
attrs.title = extractText(vnode.children);
|
||||||
@@ -64,7 +69,7 @@ export default class Button extends Component {
|
|||||||
return [
|
return [
|
||||||
iconName && iconName !== true ? icon(iconName, { className: 'Button-icon' }) : '',
|
iconName && iconName !== true ? icon(iconName, { className: 'Button-icon' }) : '',
|
||||||
children ? <span className="Button-label">{children}</span> : '',
|
children ? <span className="Button-label">{children}</span> : '',
|
||||||
this.attrs.loading ? <LoadingIndicator size="tiny" className="LoadingIndicator--inline" /> : '',
|
this.attrs.loading ? <LoadingIndicator size="small" display="inline" /> : '',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -46,7 +46,7 @@ export default class Checkbox extends Component {
|
|||||||
* @protected
|
* @protected
|
||||||
*/
|
*/
|
||||||
getDisplay() {
|
getDisplay() {
|
||||||
return this.attrs.loading ? <LoadingIndicator size="tiny" /> : icon(this.attrs.state ? 'fas fa-check' : 'fas fa-times');
|
return this.attrs.loading ? <LoadingIndicator display="unset" size="small" /> : icon(this.attrs.state ? 'fas fa-check' : 'fas fa-times');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -13,6 +13,7 @@ import listItems from '../helpers/listItems';
|
|||||||
* - `icon` The name of an icon to show in the dropdown toggle button.
|
* - `icon` The name of an icon to show in the dropdown toggle button.
|
||||||
* - `caretIcon` The name of an icon to show on the right of the button.
|
* - `caretIcon` The name of an icon to show on the right of the button.
|
||||||
* - `label` The label of the dropdown toggle button. Defaults to 'Controls'.
|
* - `label` The label of the dropdown toggle button. Defaults to 'Controls'.
|
||||||
|
* - `accessibleToggleLabel` The label used to describe the dropdown toggle button to assistive readers. Defaults to 'Toggle dropdown menu'.
|
||||||
* - `onhide`
|
* - `onhide`
|
||||||
* - `onshow`
|
* - `onshow`
|
||||||
*
|
*
|
||||||
@@ -25,6 +26,7 @@ export default class Dropdown extends Component {
|
|||||||
attrs.menuClassName = attrs.menuClassName || '';
|
attrs.menuClassName = attrs.menuClassName || '';
|
||||||
attrs.label = attrs.label || '';
|
attrs.label = attrs.label || '';
|
||||||
attrs.caretIcon = typeof attrs.caretIcon !== 'undefined' ? attrs.caretIcon : 'fas fa-caret-down';
|
attrs.caretIcon = typeof attrs.caretIcon !== 'undefined' ? attrs.caretIcon : 'fas fa-caret-down';
|
||||||
|
attrs.accessibleToggleLabel = attrs.accessibleToggleLabel || app.translator.trans('core.lib.dropdown.toggle_dropdown_accessible_label');
|
||||||
}
|
}
|
||||||
|
|
||||||
oninit(vnode) {
|
oninit(vnode) {
|
||||||
@@ -92,7 +94,13 @@ export default class Dropdown extends Component {
|
|||||||
*/
|
*/
|
||||||
getButton(children) {
|
getButton(children) {
|
||||||
return (
|
return (
|
||||||
<button className={'Dropdown-toggle ' + this.attrs.buttonClassName} data-toggle="dropdown" onclick={this.attrs.onclick}>
|
<button
|
||||||
|
className={'Dropdown-toggle ' + this.attrs.buttonClassName}
|
||||||
|
aria-haspopup="menu"
|
||||||
|
aria-label={this.attrs.accessibleToggleLabel}
|
||||||
|
data-toggle="dropdown"
|
||||||
|
onclick={this.attrs.onclick}
|
||||||
|
>
|
||||||
{this.getButtonContent(children)}
|
{this.getButtonContent(children)}
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
|
@@ -1,43 +0,0 @@
|
|||||||
import Component from '../Component';
|
|
||||||
import { Spinner } from 'spin.js';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The `LoadingIndicator` component displays a loading spinner with spin.js.
|
|
||||||
*
|
|
||||||
* ### Attrs
|
|
||||||
*
|
|
||||||
* - `size` The spin.js size preset to use. Defaults to 'small'.
|
|
||||||
*
|
|
||||||
* All other attrs will be assigned as attributes on the DOM element.
|
|
||||||
*/
|
|
||||||
export default class LoadingIndicator extends Component {
|
|
||||||
view() {
|
|
||||||
const attrs = Object.assign({}, this.attrs);
|
|
||||||
|
|
||||||
attrs.className = 'LoadingIndicator ' + (attrs.className || '');
|
|
||||||
delete attrs.size;
|
|
||||||
|
|
||||||
return <div {...attrs}>{m.trust(' ')}</div>;
|
|
||||||
}
|
|
||||||
|
|
||||||
oncreate(vnode) {
|
|
||||||
super.oncreate(vnode);
|
|
||||||
|
|
||||||
const options = { zIndex: 'auto', color: this.$().css('color') };
|
|
||||||
|
|
||||||
switch (this.attrs.size) {
|
|
||||||
case 'large':
|
|
||||||
Object.assign(options, { lines: 10, length: 8, width: 4, radius: 8 });
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'tiny':
|
|
||||||
Object.assign(options, { lines: 8, length: 2, width: 2, radius: 3 });
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
Object.assign(options, { lines: 8, length: 4, width: 3, radius: 5 });
|
|
||||||
}
|
|
||||||
|
|
||||||
new Spinner(options).spin(this.element);
|
|
||||||
}
|
|
||||||
}
|
|
80
js/src/common/components/LoadingIndicator.tsx
Normal file
80
js/src/common/components/LoadingIndicator.tsx
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
import Component, { ComponentAttrs } from '../Component';
|
||||||
|
import classList from '../utils/classList';
|
||||||
|
|
||||||
|
export interface LoadingIndicatorAttrs extends ComponentAttrs {
|
||||||
|
/**
|
||||||
|
* Custom classes fro the loading indicator's container.
|
||||||
|
*/
|
||||||
|
className?: string;
|
||||||
|
/**
|
||||||
|
* Custom classes for the loading indicator's container.
|
||||||
|
*/
|
||||||
|
containerClassName?: string;
|
||||||
|
/**
|
||||||
|
* Optional size to specify for the loading indicator.
|
||||||
|
*/
|
||||||
|
size?: 'large' | 'medium' | 'small';
|
||||||
|
/**
|
||||||
|
* Optional attributes to apply to the loading indicator's container.
|
||||||
|
*/
|
||||||
|
containerAttrs?: Partial<ComponentAttrs>;
|
||||||
|
/**
|
||||||
|
* Display type of the spinner.
|
||||||
|
*
|
||||||
|
* @default 'block'
|
||||||
|
*/
|
||||||
|
display?: 'block' | 'inline' | 'unset';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The `LoadingIndicator` component displays a simple CSS-based loading spinner.
|
||||||
|
*
|
||||||
|
* To set a custom color, use the CSS `color` property.
|
||||||
|
*
|
||||||
|
* To increase spacing around the spinner, use the CSS `height` property on the
|
||||||
|
* spinner's **container**. Setting the `display` attribute to `block` will set
|
||||||
|
* a height of `100px` by default.
|
||||||
|
*
|
||||||
|
* To apply a custom size to the loading indicator, set the `--size` and
|
||||||
|
* `--thickness` CSS custom properties on the loading indicator container.
|
||||||
|
*
|
||||||
|
* If you *really* want to change how this looks as part of your custom theme,
|
||||||
|
* you can override the `border-radius` and `border` then set either a
|
||||||
|
* background image, or use `content: "\<glyph>"` (e.g. `content: "\f1ce"`)
|
||||||
|
* and `font-family: 'Font Awesome 5 Free'` to set an FA icon if you'd rather.
|
||||||
|
*
|
||||||
|
* ### Attrs
|
||||||
|
*
|
||||||
|
* - `containerClassName` Class name(s) to apply to the indicator's parent
|
||||||
|
* - `className` Class name(s) to apply to the indicator itself
|
||||||
|
* - `display` Determines how the spinner should be displayed (`inline`, `block` (default) or `unset`)
|
||||||
|
* - `size` Size of the loading indicator (`small`, `medium` or `large`)
|
||||||
|
* - `containerAttrs` Optional attrs to be applied to the container DOM element
|
||||||
|
*
|
||||||
|
* All other attrs will be assigned as attributes on the DOM element.
|
||||||
|
*/
|
||||||
|
export default class LoadingIndicator extends Component<LoadingIndicatorAttrs> {
|
||||||
|
view() {
|
||||||
|
const { display = 'block', size = 'medium', containerClassName, className, ...attrs } = this.attrs;
|
||||||
|
|
||||||
|
const completeClassName = classList('LoadingIndicator', className);
|
||||||
|
const completeContainerClassName = classList(
|
||||||
|
'LoadingIndicator-container',
|
||||||
|
display !== 'unset' && `LoadingIndicator-container--${display}`,
|
||||||
|
size && `LoadingIndicator-container--${size}`,
|
||||||
|
containerClassName
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
aria-label={app.translator.trans('core.lib.loading_indicator.accessible_label')}
|
||||||
|
role="status"
|
||||||
|
{...attrs.containerAttrs}
|
||||||
|
data-size={size}
|
||||||
|
className={completeContainerClassName}
|
||||||
|
>
|
||||||
|
<div aria-hidden className={completeClassName} {...attrs} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@@ -29,6 +29,13 @@ export default class Page extends Component {
|
|||||||
* @type {Boolean}
|
* @type {Boolean}
|
||||||
*/
|
*/
|
||||||
this.scrollTopOnCreate = true;
|
this.scrollTopOnCreate = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the browser should restore scroll state on refreshes.
|
||||||
|
*
|
||||||
|
* @type {Boolean}
|
||||||
|
*/
|
||||||
|
this.useBrowserScrollRestoration = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
oncreate(vnode) {
|
oncreate(vnode) {
|
||||||
@@ -41,6 +48,10 @@ export default class Page extends Component {
|
|||||||
if (this.scrollTopOnCreate) {
|
if (this.scrollTopOnCreate) {
|
||||||
$(window).scrollTop(0);
|
$(window).scrollTop(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ('scrollRestoration' in history) {
|
||||||
|
history.scrollRestoration = this.useBrowserScrollRestoration ? 'auto' : 'manual';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onremove() {
|
onremove() {
|
||||||
|
@@ -12,6 +12,9 @@ import icon from '../helpers/icon';
|
|||||||
function isActive(vnode) {
|
function isActive(vnode) {
|
||||||
const tag = vnode.tag;
|
const tag = vnode.tag;
|
||||||
|
|
||||||
|
// Allow non-selectable dividers/headers to be added.
|
||||||
|
if (typeof tag === 'string' && tag !== 'a' && tag !== 'button') return false;
|
||||||
|
|
||||||
if ('initAttrs' in tag) {
|
if ('initAttrs' in tag) {
|
||||||
tag.initAttrs(vnode.attrs);
|
tag.initAttrs(vnode.attrs);
|
||||||
}
|
}
|
||||||
|
@@ -24,7 +24,12 @@ export default class SplitDropdown extends Dropdown {
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
Button.component(buttonAttrs, firstChild.children),
|
Button.component(buttonAttrs, firstChild.children),
|
||||||
<button className={'Dropdown-toggle Button Button--icon ' + this.attrs.buttonClassName} data-toggle="dropdown">
|
<button
|
||||||
|
className={'Dropdown-toggle Button Button--icon ' + this.attrs.buttonClassName}
|
||||||
|
aria-haspopup="menu"
|
||||||
|
aria-label={this.attrs.accessibleToggleLabel}
|
||||||
|
data-toggle="dropdown"
|
||||||
|
>
|
||||||
{icon(this.attrs.icon, { className: 'Button-icon' })}
|
{icon(this.attrs.icon, { className: 'Button-icon' })}
|
||||||
{icon('fas fa-caret-down', { className: 'Button-caret' })}
|
{icon('fas fa-caret-down', { className: 'Button-caret' })}
|
||||||
</button>,
|
</button>,
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
import Component from '../../common/Component';
|
import Component from '../Component';
|
||||||
import ItemList from '../../common/utils/ItemList';
|
import ItemList from '../utils/ItemList';
|
||||||
import SuperTextarea from '../../common/utils/SuperTextarea';
|
import listItems from '../helpers/listItems';
|
||||||
import listItems from '../../common/helpers/listItems';
|
import Button from './Button';
|
||||||
import Button from '../../common/components/Button';
|
|
||||||
|
import BasicEditorDriver from '../utils/BasicEditorDriver';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The `TextEditor` component displays a textarea with controls, including a
|
* The `TextEditor` component displays a textarea with controls, including a
|
||||||
@@ -22,25 +23,22 @@ export default class TextEditor extends Component {
|
|||||||
super.oninit(vnode);
|
super.oninit(vnode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The value of the textarea.
|
* The value of the editor.
|
||||||
*
|
*
|
||||||
* @type {String}
|
* @type {String}
|
||||||
*/
|
*/
|
||||||
this.value = this.attrs.value || '';
|
this.value = this.attrs.value || '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the editor is disabled.
|
||||||
|
*/
|
||||||
|
this.disabled = !!this.attrs.disabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
view() {
|
view() {
|
||||||
return (
|
return (
|
||||||
<div className="TextEditor">
|
<div className="TextEditor">
|
||||||
<textarea
|
<div className="TextEditor-editorContainer"></div>
|
||||||
className="FormControl Composer-flexible"
|
|
||||||
oninput={(e) => {
|
|
||||||
this.oninput(e.target.value, e);
|
|
||||||
}}
|
|
||||||
placeholder={this.attrs.placeholder || ''}
|
|
||||||
disabled={!!this.attrs.disabled}
|
|
||||||
value={this.value}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<ul className="TextEditor-controls Composer-footer">
|
<ul className="TextEditor-controls Composer-footer">
|
||||||
{listItems(this.controlItems().toArray())}
|
{listItems(this.controlItems().toArray())}
|
||||||
@@ -53,15 +51,35 @@ export default class TextEditor extends Component {
|
|||||||
oncreate(vnode) {
|
oncreate(vnode) {
|
||||||
super.oncreate(vnode);
|
super.oncreate(vnode);
|
||||||
|
|
||||||
const handler = () => {
|
this.attrs.composer.editor = this.buildEditor(this.$('.TextEditor-editorContainer')[0]);
|
||||||
this.onsubmit();
|
}
|
||||||
m.redraw();
|
|
||||||
|
onupdate() {
|
||||||
|
const newDisabled = !!this.attrs.disabled;
|
||||||
|
|
||||||
|
if (this.disabled !== newDisabled) {
|
||||||
|
this.disabled = newDisabled;
|
||||||
|
this.attrs.composer.editor.disabled(newDisabled);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
buildEditorParams() {
|
||||||
|
return {
|
||||||
|
classNames: ['FormControl', 'Composer-flexible', 'TextEditor-editor'],
|
||||||
|
disabled: this.disabled,
|
||||||
|
placeholder: this.attrs.placeholder || '',
|
||||||
|
value: this.value,
|
||||||
|
oninput: this.oninput.bind(this),
|
||||||
|
inputListeners: [],
|
||||||
|
onsubmit: () => {
|
||||||
|
this.onsubmit();
|
||||||
|
m.redraw();
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
this.$('textarea').bind('keydown', 'meta+return', handler);
|
buildEditor(dom) {
|
||||||
this.$('textarea').bind('keydown', 'ctrl+return', handler);
|
return new BasicEditorDriver(dom, this.buildEditorParams());
|
||||||
|
|
||||||
this.attrs.composer.editor = new SuperTextarea(this.$('textarea')[0]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -115,12 +133,10 @@ export default class TextEditor extends Component {
|
|||||||
*
|
*
|
||||||
* @param {String} value
|
* @param {String} value
|
||||||
*/
|
*/
|
||||||
oninput(value, e) {
|
oninput(value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
|
|
||||||
this.attrs.onchange(this.value);
|
this.attrs.onchange(this.value);
|
||||||
|
|
||||||
e.redraw = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
@@ -1,4 +1,4 @@
|
|||||||
import Button from '../../common/components/Button';
|
import Button from './Button';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The `TextEditorButton` component displays a button suitable for the text
|
* The `TextEditorButton` component displays a button suitable for the text
|
@@ -1,26 +1,28 @@
|
|||||||
|
import * as Mithril from 'mithril';
|
||||||
|
import User from '../models/User';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The `avatar` helper displays a user's avatar.
|
* The `avatar` helper displays a user's avatar.
|
||||||
*
|
*
|
||||||
* @param {User} user
|
* @param user
|
||||||
* @param {Object} attrs Attributes to apply to the avatar element
|
* @param attrs Attributes to apply to the avatar element
|
||||||
* @return {Object}
|
|
||||||
*/
|
*/
|
||||||
export default function avatar(user, attrs = {}) {
|
export default function avatar(user: User, attrs: Object = {}): Mithril.Vnode {
|
||||||
attrs.className = 'Avatar ' + (attrs.className || '');
|
attrs.className = 'Avatar ' + (attrs.className || '');
|
||||||
let content = '';
|
let content: string = '';
|
||||||
|
|
||||||
// If the `title` attribute is set to null or false, we don't want to give the
|
// If the `title` attribute is set to null or false, we don't want to give the
|
||||||
// avatar a title. On the other hand, if it hasn't been given at all, we can
|
// avatar a title. On the other hand, if it hasn't been given at all, we can
|
||||||
// safely default it to the user's username.
|
// safely default it to the user's username.
|
||||||
const hasTitle = attrs.title === 'undefined' || attrs.title;
|
const hasTitle: boolean | string = attrs.title === 'undefined' || attrs.title;
|
||||||
if (!hasTitle) delete attrs.title;
|
if (!hasTitle) delete attrs.title;
|
||||||
|
|
||||||
// If a user has been passed, then we will set up an avatar using their
|
// If a user has been passed, then we will set up an avatar using their
|
||||||
// uploaded image, or the first letter of their username if they haven't
|
// uploaded image, or the first letter of their username if they haven't
|
||||||
// uploaded one.
|
// uploaded one.
|
||||||
if (user) {
|
if (user) {
|
||||||
const username = user.displayName() || '?';
|
const username: string = user.displayName() || '?';
|
||||||
const avatarUrl = user.avatarUrl();
|
const avatarUrl: string = user.avatarUrl();
|
||||||
|
|
||||||
if (hasTitle) attrs.title = attrs.title || username;
|
if (hasTitle) attrs.title = attrs.title || username;
|
||||||
|
|
@@ -1,16 +1,16 @@
|
|||||||
|
import * as Mithril from 'mithril';
|
||||||
import { truncate } from '../utils/string';
|
import { truncate } from '../utils/string';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The `highlight` helper searches for a word phrase in a string, and wraps
|
* The `highlight` helper searches for a word phrase in a string, and wraps
|
||||||
* matches with the <mark> tag.
|
* matches with the <mark> tag.
|
||||||
*
|
*
|
||||||
* @param {String} string The string to highlight.
|
* @param string The string to highlight.
|
||||||
* @param {String|RegExp} phrase The word or words to highlight.
|
* @param phrase The word or words to highlight.
|
||||||
* @param {Integer} [length] The number of characters to truncate the string to.
|
* @param [length] The number of characters to truncate the string to.
|
||||||
* The string will be truncated surrounding the first match.
|
* The string will be truncated surrounding the first match.
|
||||||
* @return {Object}
|
|
||||||
*/
|
*/
|
||||||
export default function highlight(string, phrase, length) {
|
export default function highlight(string: string, phrase: string | RegExp, length?: number): Mithril.Vnode<any, any> | string {
|
||||||
if (!phrase && !length) return string;
|
if (!phrase && !length) return string;
|
||||||
|
|
||||||
// Convert the word phrase into a global regular expression (if it isn't
|
// Convert the word phrase into a global regular expression (if it isn't
|
@@ -1,15 +1,16 @@
|
|||||||
|
import * as Mithril from 'mithril';
|
||||||
import Separator from '../components/Separator';
|
import Separator from '../components/Separator';
|
||||||
import classList from '../utils/classList';
|
import classList from '../utils/classList';
|
||||||
|
|
||||||
function isSeparator(item) {
|
function isSeparator(item): boolean {
|
||||||
return item.tag === Separator;
|
return item.tag === Separator;
|
||||||
}
|
}
|
||||||
|
|
||||||
function withoutUnnecessarySeparators(items) {
|
function withoutUnnecessarySeparators(items: Array<Mithril.Vnode>): Array<Mithril.Vnode> {
|
||||||
const newItems = [];
|
const newItems = [];
|
||||||
let prevItem;
|
let prevItem;
|
||||||
|
|
||||||
items.filter(Boolean).forEach((item, i) => {
|
items.filter(Boolean).forEach((item: Mithril.Vnode, i: number) => {
|
||||||
if (!isSeparator(item) || (prevItem && !isSeparator(prevItem) && i !== items.length - 1)) {
|
if (!isSeparator(item) || (prevItem && !isSeparator(prevItem) && i !== items.length - 1)) {
|
||||||
prevItem = item;
|
prevItem = item;
|
||||||
newItems.push(item);
|
newItems.push(item);
|
||||||
@@ -22,14 +23,11 @@ function withoutUnnecessarySeparators(items) {
|
|||||||
/**
|
/**
|
||||||
* The `listItems` helper wraps a collection of components in <li> tags,
|
* The `listItems` helper wraps a collection of components in <li> tags,
|
||||||
* stripping out any unnecessary `Separator` components.
|
* stripping out any unnecessary `Separator` components.
|
||||||
*
|
|
||||||
* @param {*} items
|
|
||||||
* @return {Array}
|
|
||||||
*/
|
*/
|
||||||
export default function listItems(items) {
|
export default function listItems(items: Mithril.Vnode | Array<Mithril.Vnode>): Array<Mithril.Vnode> {
|
||||||
if (!(items instanceof Array)) items = [items];
|
if (!(items instanceof Array)) items = [items];
|
||||||
|
|
||||||
return withoutUnnecessarySeparators(items).map((item) => {
|
return withoutUnnecessarySeparators(items).map((item: Mithril.Vnode) => {
|
||||||
const isListItem = item.tag && item.tag.isListItem;
|
const isListItem = item.tag && item.tag.isListItem;
|
||||||
const active = item.tag && item.tag.isActive && item.tag.isActive(item.attrs);
|
const active = item.tag && item.tag.isActive && item.tag.isActive(item.attrs);
|
||||||
const className = (item.attrs && item.attrs.itemClassName) || item.itemClassName;
|
const className = (item.attrs && item.attrs.itemClassName) || item.itemClassName;
|
||||||
@@ -40,7 +38,7 @@ export default function listItems(items) {
|
|||||||
item.key = item.attrs.key;
|
item.key = item.attrs.key;
|
||||||
}
|
}
|
||||||
|
|
||||||
const node = isListItem ? (
|
const node: Mithril.Vnode = isListItem ? (
|
||||||
item
|
item
|
||||||
) : (
|
) : (
|
||||||
<li
|
<li
|
@@ -1,12 +1,11 @@
|
|||||||
|
import * as Mithril from 'mithril';
|
||||||
|
import User from '../models/User';
|
||||||
import icon from './icon';
|
import icon from './icon';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The `useronline` helper displays a green circle if the user is online
|
* The `useronline` helper displays a green circle if the user is online
|
||||||
*
|
|
||||||
* @param {User} user
|
|
||||||
* @return {Object}
|
|
||||||
*/
|
*/
|
||||||
export default function userOnline(user) {
|
export default function userOnline(user: User): Mithril.Vnode {
|
||||||
if (user.lastSeenAt() && user.isOnline()) {
|
if (user.lastSeenAt() && user.isOnline()) {
|
||||||
return <span className="UserOnline">{icon('fas fa-circle')}</span>;
|
return <span className="UserOnline">{icon('fas fa-circle')}</span>;
|
||||||
}
|
}
|
@@ -1,11 +1,11 @@
|
|||||||
|
import * as Mithril from 'mithril';
|
||||||
|
import User from '../models/User';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The `username` helper displays a user's username in a <span class="username">
|
* The `username` helper displays a user's username in a <span class="username">
|
||||||
* tag. If the user doesn't exist, the username will be displayed as [deleted].
|
* tag. If the user doesn't exist, the username will be displayed as [deleted].
|
||||||
*
|
|
||||||
* @param {User} user
|
|
||||||
* @return {Object}
|
|
||||||
*/
|
*/
|
||||||
export default function username(user) {
|
export default function username(user: User): Mithril.Vnode {
|
||||||
const name = (user && user.displayName()) || app.translator.trans('core.lib.username.deleted_text');
|
const name = (user && user.displayName()) || app.translator.trans('core.lib.username.deleted_text');
|
||||||
|
|
||||||
return <span className="username">{name}</span>;
|
return <span className="username">{name}</span>;
|
@@ -1,7 +1,8 @@
|
|||||||
import 'expose-loader?$!expose-loader?jQuery!jquery';
|
// Expose jQuery, mithril and dayjs to the window browser object
|
||||||
import 'expose-loader?m!mithril';
|
import 'expose-loader?exposes[]=$&exposes[]=jQuery!jquery';
|
||||||
import 'expose-loader?moment!expose-loader?dayjs!dayjs';
|
import 'expose-loader?exposes=m!mithril';
|
||||||
import 'expose-loader?m.bidi!m.attrs.bidi';
|
import 'expose-loader?exposes=dayjs!dayjs';
|
||||||
|
|
||||||
import 'bootstrap/js/affix';
|
import 'bootstrap/js/affix';
|
||||||
import 'bootstrap/js/dropdown';
|
import 'bootstrap/js/dropdown';
|
||||||
import 'bootstrap/js/modal';
|
import 'bootstrap/js/modal';
|
||||||
|
@@ -10,6 +10,7 @@ export default class User extends Model {}
|
|||||||
|
|
||||||
Object.assign(User.prototype, {
|
Object.assign(User.prototype, {
|
||||||
username: Model.attribute('username'),
|
username: Model.attribute('username'),
|
||||||
|
slug: Model.attribute('slug'),
|
||||||
displayName: Model.attribute('displayName'),
|
displayName: Model.attribute('displayName'),
|
||||||
email: Model.attribute('email'),
|
email: Model.attribute('email'),
|
||||||
isEmailConfirmed: Model.attribute('isEmailConfirmed'),
|
isEmailConfirmed: Model.attribute('isEmailConfirmed'),
|
||||||
@@ -29,6 +30,8 @@ Object.assign(User.prototype, {
|
|||||||
commentCount: Model.attribute('commentCount'),
|
commentCount: Model.attribute('commentCount'),
|
||||||
|
|
||||||
canEdit: Model.attribute('canEdit'),
|
canEdit: Model.attribute('canEdit'),
|
||||||
|
canEditCredentials: Model.attribute('canEditCredentials'),
|
||||||
|
canEditGroups: Model.attribute('canEditGroups'),
|
||||||
canDelete: Model.attribute('canDelete'),
|
canDelete: Model.attribute('canDelete'),
|
||||||
|
|
||||||
avatarColor: null,
|
avatarColor: null,
|
||||||
|
124
js/src/common/utils/BasicEditorDriver.ts
Normal file
124
js/src/common/utils/BasicEditorDriver.ts
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
import getCaretCoordinates from 'textarea-caret';
|
||||||
|
import EditorDriverInterface, { EditorDriverParams } from './EditorDriverInterface';
|
||||||
|
|
||||||
|
export default class BasicEditorDriver implements EditorDriverInterface {
|
||||||
|
el: HTMLTextAreaElement;
|
||||||
|
|
||||||
|
constructor(dom: HTMLElement, params: EditorDriverParams) {
|
||||||
|
this.el = document.createElement('textarea');
|
||||||
|
|
||||||
|
this.build(dom, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
build(dom: HTMLElement, params: EditorDriverParams) {
|
||||||
|
this.el.className = params.classNames.join(' ');
|
||||||
|
this.el.disabled = params.disabled;
|
||||||
|
this.el.placeholder = params.placeholder;
|
||||||
|
this.el.value = params.value;
|
||||||
|
|
||||||
|
const callInputListeners = (e) => {
|
||||||
|
params.inputListeners.forEach((listener) => {
|
||||||
|
listener();
|
||||||
|
});
|
||||||
|
|
||||||
|
e.redraw = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.el.oninput = (e) => {
|
||||||
|
params.oninput(this.el.value);
|
||||||
|
callInputListeners(e);
|
||||||
|
};
|
||||||
|
|
||||||
|
this.el.onclick = callInputListeners;
|
||||||
|
this.el.onkeyup = callInputListeners;
|
||||||
|
|
||||||
|
this.el.addEventListener('keydown', function (e) {
|
||||||
|
if ((e.metaKey || e.ctrlKey) && e.key === 'Enter') {
|
||||||
|
params.onsubmit();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
dom.append(this.el);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected setValue(value: string) {
|
||||||
|
$(this.el).val(value).trigger('input');
|
||||||
|
|
||||||
|
this.el.dispatchEvent(new CustomEvent('input', { bubbles: true, cancelable: true }));
|
||||||
|
}
|
||||||
|
|
||||||
|
moveCursorTo(position: number) {
|
||||||
|
this.setSelectionRange(position, position);
|
||||||
|
}
|
||||||
|
|
||||||
|
getSelectionRange(): Array<number> {
|
||||||
|
return [this.el.selectionStart, this.el.selectionEnd];
|
||||||
|
}
|
||||||
|
|
||||||
|
getLastNChars(n: number): string {
|
||||||
|
const value = this.el.value;
|
||||||
|
|
||||||
|
return value.slice(Math.max(0, this.el.selectionStart - n), this.el.selectionStart);
|
||||||
|
}
|
||||||
|
|
||||||
|
insertAtCursor(text: string) {
|
||||||
|
this.insertAt(this.el.selectionStart, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
insertAt(pos: number, text: string) {
|
||||||
|
this.insertBetween(pos, pos, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
insertBetween(start: number, end: number, text: string) {
|
||||||
|
const value = this.el.value;
|
||||||
|
|
||||||
|
const before = value.slice(0, start);
|
||||||
|
const after = value.slice(end);
|
||||||
|
|
||||||
|
this.setValue(`${before}${text}${after}`);
|
||||||
|
|
||||||
|
// Move the textarea cursor to the end of the content we just inserted.
|
||||||
|
this.moveCursorTo(start + text.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
replaceBeforeCursor(start: number, text: string) {
|
||||||
|
this.insertBetween(start, this.el.selectionStart, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected setSelectionRange(start: number, end: number) {
|
||||||
|
this.el.setSelectionRange(start, end);
|
||||||
|
this.focus();
|
||||||
|
}
|
||||||
|
|
||||||
|
getCaretCoordinates(position: number) {
|
||||||
|
const relCoords = getCaretCoordinates(this.el, position);
|
||||||
|
|
||||||
|
return {
|
||||||
|
top: relCoords.top - this.el.scrollTop,
|
||||||
|
left: relCoords.left,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// DOM Interactions
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the disabled status of the editor.
|
||||||
|
*/
|
||||||
|
disabled(disabled: boolean) {
|
||||||
|
this.el.disabled = disabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Focus on the editor.
|
||||||
|
*/
|
||||||
|
focus() {
|
||||||
|
this.el.focus();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroy the editor
|
||||||
|
*/
|
||||||
|
destroy() {
|
||||||
|
this.el.remove();
|
||||||
|
}
|
||||||
|
}
|
@@ -31,7 +31,24 @@ export default class Drawer {
|
|||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
hide() {
|
hide() {
|
||||||
$('#app').removeClass('drawerOpen');
|
/**
|
||||||
|
* As part of hiding the drawer, this function also ensures that the drawer
|
||||||
|
* correctly animates out, while ensuring it is not part of the navigation
|
||||||
|
* tree while off-screen.
|
||||||
|
*
|
||||||
|
* More info: https://github.com/flarum/core/pull/2666#discussion_r595381014
|
||||||
|
*/
|
||||||
|
|
||||||
|
const $app = $('#app');
|
||||||
|
|
||||||
|
if (!$app.hasClass('drawerOpen')) return;
|
||||||
|
|
||||||
|
const $drawer = $('#drawer');
|
||||||
|
|
||||||
|
// Used to prevent `visibility: hidden` from breaking the exit animation
|
||||||
|
$drawer.css('visibility', 'visible').one('transitionend', () => $drawer.css('visibility', ''));
|
||||||
|
|
||||||
|
$app.removeClass('drawerOpen');
|
||||||
|
|
||||||
if (this.$backdrop) this.$backdrop.remove();
|
if (this.$backdrop) this.$backdrop.remove();
|
||||||
}
|
}
|
||||||
|
105
js/src/common/utils/EditorDriverInterface.ts
Normal file
105
js/src/common/utils/EditorDriverInterface.ts
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
export interface EditorDriverParams {
|
||||||
|
/**
|
||||||
|
* An array of HTML class names to apply to the editor's main DOM element.
|
||||||
|
*/
|
||||||
|
classNames: string[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the editor should be initially disabled.
|
||||||
|
*/
|
||||||
|
disabled: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An optional placeholder for the editor.
|
||||||
|
*/
|
||||||
|
placeholder: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An optional initial value for the editor.
|
||||||
|
*/
|
||||||
|
value: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is separate from inputListeners since the full serialized content will be passed to it.
|
||||||
|
* It is considered private API, and should not be used/modified by extensions not implementing
|
||||||
|
* EditorDriverInterface.
|
||||||
|
*/
|
||||||
|
oninput: Function;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Each of these functions will be called on click, input, and keyup.
|
||||||
|
* No arguments will be passed.
|
||||||
|
*/
|
||||||
|
inputListeners: Function[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function will be called if submission is triggered programmatically via keybind.
|
||||||
|
* No arguments should be passed.
|
||||||
|
*/
|
||||||
|
onsubmit: Function;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default interface EditorDriverInterface {
|
||||||
|
/**
|
||||||
|
* Focus the editor and place the cursor at the given position.
|
||||||
|
*/
|
||||||
|
moveCursorTo(position: number): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the selected range of the editor.
|
||||||
|
*/
|
||||||
|
getSelectionRange(): Array<number>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the last N characters from the current "text block".
|
||||||
|
*
|
||||||
|
* A textarea-based driver would just return the last N characters,
|
||||||
|
* but more advanced implementations might restrict to the current block.
|
||||||
|
*
|
||||||
|
* This is useful for monitoring recent user input to trigger autocomplete.
|
||||||
|
*/
|
||||||
|
getLastNChars(n: number): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Insert content into the editor at the position of the cursor.
|
||||||
|
*/
|
||||||
|
insertAtCursor(text: string, escape: boolean): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Insert content into the editor at the given position.
|
||||||
|
*/
|
||||||
|
insertAt(pos: number, text: string, escape: boolean): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Insert content into the editor between the given positions.
|
||||||
|
*
|
||||||
|
* If the start and end positions are different, any text between them will be
|
||||||
|
* overwritten.
|
||||||
|
*/
|
||||||
|
insertBetween(start: number, end: number, text: string, escape: boolean): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replace existing content from the start to the current cursor position.
|
||||||
|
*/
|
||||||
|
replaceBeforeCursor(start: number, text: string, escape: boolean): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get left and top coordinates of the caret relative to the editor viewport.
|
||||||
|
*/
|
||||||
|
getCaretCoordinates(position: number): { left: number; top: number };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the disabled status of the editor.
|
||||||
|
*/
|
||||||
|
disabled(disabled: boolean): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Focus on the editor.
|
||||||
|
*/
|
||||||
|
focus(): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroy the editor
|
||||||
|
*/
|
||||||
|
destroy(): void;
|
||||||
|
}
|
@@ -1,109 +0,0 @@
|
|||||||
/**
|
|
||||||
* A textarea wrapper with powerful helpers for text manipulation.
|
|
||||||
*
|
|
||||||
* This wraps a <textarea> DOM element and allows directly manipulating its text
|
|
||||||
* contents and cursor positions.
|
|
||||||
*
|
|
||||||
* I apologize for the pretentious name. :)
|
|
||||||
*/
|
|
||||||
export default class SuperTextarea {
|
|
||||||
/**
|
|
||||||
* @param {HTMLTextAreaElement} textarea
|
|
||||||
*/
|
|
||||||
constructor(textarea) {
|
|
||||||
this.el = textarea;
|
|
||||||
this.$ = $(textarea);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the value of the text editor.
|
|
||||||
*
|
|
||||||
* @param {String} value
|
|
||||||
*/
|
|
||||||
setValue(value) {
|
|
||||||
this.$.val(value).trigger('input');
|
|
||||||
|
|
||||||
this.el.dispatchEvent(new CustomEvent('input', { bubbles: true, cancelable: true }));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Focus the textarea and place the cursor at the given index.
|
|
||||||
*
|
|
||||||
* @param {number} position
|
|
||||||
*/
|
|
||||||
moveCursorTo(position) {
|
|
||||||
this.setSelectionRange(position, position);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the selected range of the textarea.
|
|
||||||
*
|
|
||||||
* @return {Array}
|
|
||||||
*/
|
|
||||||
getSelectionRange() {
|
|
||||||
return [this.el.selectionStart, this.el.selectionEnd];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Insert content into the textarea at the position of the cursor.
|
|
||||||
*
|
|
||||||
* @param {String} text
|
|
||||||
*/
|
|
||||||
insertAtCursor(text) {
|
|
||||||
this.insertAt(this.el.selectionStart, text);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Insert content into the textarea at the given position.
|
|
||||||
*
|
|
||||||
* @param {number} pos
|
|
||||||
* @param {String} text
|
|
||||||
*/
|
|
||||||
insertAt(pos, text) {
|
|
||||||
this.insertBetween(pos, pos, text);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Insert content into the textarea between the given positions.
|
|
||||||
*
|
|
||||||
* If the start and end positions are different, any text between them will be
|
|
||||||
* overwritten.
|
|
||||||
*
|
|
||||||
* @param start
|
|
||||||
* @param end
|
|
||||||
* @param text
|
|
||||||
*/
|
|
||||||
insertBetween(start, end, text) {
|
|
||||||
const value = this.el.value;
|
|
||||||
|
|
||||||
const before = value.slice(0, start);
|
|
||||||
const after = value.slice(end);
|
|
||||||
|
|
||||||
this.setValue(`${before}${text}${after}`);
|
|
||||||
|
|
||||||
// Move the textarea cursor to the end of the content we just inserted.
|
|
||||||
this.moveCursorTo(start + text.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Replace existing content from the start to the current cursor position.
|
|
||||||
*
|
|
||||||
* @param start
|
|
||||||
* @param text
|
|
||||||
*/
|
|
||||||
replaceBeforeCursor(start, text) {
|
|
||||||
this.insertBetween(start, this.el.selectionStart, text);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the selected range of the textarea.
|
|
||||||
*
|
|
||||||
* @param {number} start
|
|
||||||
* @param {number} end
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
setSelectionRange(start, end) {
|
|
||||||
this.el.setSelectionRange(start, end);
|
|
||||||
this.$.focus();
|
|
||||||
}
|
|
||||||
}
|
|
50
js/src/common/utils/bidi.js
Normal file
50
js/src/common/utils/bidi.js
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
function bidi(node, prop) {
|
||||||
|
var type = node.tag === 'select' ? (node.attrs.multi ? 'multi' : 'select') : node.attrs.type;
|
||||||
|
|
||||||
|
// Setup: bind listeners
|
||||||
|
if (type === 'multi') {
|
||||||
|
node.attrs.onchange = function () {
|
||||||
|
prop(
|
||||||
|
[].slice.call(this.selectedOptions, function (x) {
|
||||||
|
return x.value;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
};
|
||||||
|
} else if (type === 'select') {
|
||||||
|
node.attrs.onchange = function (e) {
|
||||||
|
prop(this.selectedOptions[0].value);
|
||||||
|
};
|
||||||
|
} else if (type === 'checkbox') {
|
||||||
|
node.attrs.onchange = function (e) {
|
||||||
|
prop(this.checked);
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
node.attrs.onchange = node.attrs.oninput = function (e) {
|
||||||
|
prop(this.value);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.tag === 'select') {
|
||||||
|
node.children.forEach(function (option) {
|
||||||
|
if (option.attrs.value === prop() || option.children[0] === prop()) {
|
||||||
|
option.attrs.selected = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else if (type === 'checkbox') {
|
||||||
|
node.attrs.checked = prop();
|
||||||
|
} else if (type === 'radio') {
|
||||||
|
node.attrs.checked = prop() === node.attrs.value;
|
||||||
|
} else {
|
||||||
|
node.attrs.value = prop();
|
||||||
|
}
|
||||||
|
|
||||||
|
node.attrs.bidi = null;
|
||||||
|
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
bidi.view = function (ctrl, node, prop) {
|
||||||
|
return bidi(node, node.attrs.bidi);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default bidi;
|
@@ -1,26 +0,0 @@
|
|||||||
/**
|
|
||||||
* The `classList` utility creates a list of class names by joining an object's
|
|
||||||
* keys, but only for values which are truthy.
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
* classList({ foo: true, bar: false, qux: 'qaz' });
|
|
||||||
* // "foo qux"
|
|
||||||
*
|
|
||||||
* @param {Object} classes
|
|
||||||
* @return {String}
|
|
||||||
*/
|
|
||||||
export default function classList(classes) {
|
|
||||||
let classNames;
|
|
||||||
|
|
||||||
if (classes instanceof Array) {
|
|
||||||
classNames = classes.filter((name) => name);
|
|
||||||
} else {
|
|
||||||
classNames = [];
|
|
||||||
|
|
||||||
for (const i in classes) {
|
|
||||||
if (classes[i]) classNames.push(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return classNames.join(' ');
|
|
||||||
}
|
|
12
js/src/common/utils/classList.ts
Normal file
12
js/src/common/utils/classList.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import clsx from 'clsx';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This util exposes `clsx` to core and extensions as a re-usable utility.
|
||||||
|
*
|
||||||
|
* For full documentation, see `clsx` on GitHub.
|
||||||
|
*
|
||||||
|
* @see https://github.com/lukeed/clsx
|
||||||
|
*/
|
||||||
|
const classList = clsx;
|
||||||
|
|
||||||
|
export default classList;
|
@@ -1,8 +1,4 @@
|
|||||||
import withAttr from './withAttr';
|
import bidi from './bidi';
|
||||||
import Stream from './Stream';
|
|
||||||
|
|
||||||
let deprecatedMPropWarned = false;
|
|
||||||
let deprecatedMWithAttrWarned = false;
|
|
||||||
|
|
||||||
export default function patchMithril(global) {
|
export default function patchMithril(global) {
|
||||||
const defaultMithril = global.m;
|
const defaultMithril = global.m;
|
||||||
@@ -14,7 +10,7 @@ export default function patchMithril(global) {
|
|||||||
|
|
||||||
// Allows the use of the bidi attr.
|
// Allows the use of the bidi attr.
|
||||||
if (node.attrs.bidi) {
|
if (node.attrs.bidi) {
|
||||||
modifiedMithril.bidi(node, node.attrs.bidi);
|
bidi(node, node.attrs.bidi);
|
||||||
}
|
}
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
@@ -22,23 +18,5 @@ export default function patchMithril(global) {
|
|||||||
|
|
||||||
Object.keys(defaultMithril).forEach((key) => (modifiedMithril[key] = defaultMithril[key]));
|
Object.keys(defaultMithril).forEach((key) => (modifiedMithril[key] = defaultMithril[key]));
|
||||||
|
|
||||||
// BEGIN DEPRECATED MITHRIL 2 BC LAYER
|
|
||||||
modifiedMithril.prop = function (...args) {
|
|
||||||
if (!deprecatedMPropWarned) {
|
|
||||||
deprecatedMPropWarned = true;
|
|
||||||
console.warn('m.prop() is deprecated, please use the Stream util (flarum/utils/Streams) instead.');
|
|
||||||
}
|
|
||||||
return Stream.bind(this)(...args);
|
|
||||||
};
|
|
||||||
|
|
||||||
modifiedMithril.withAttr = function (...args) {
|
|
||||||
if (!deprecatedMWithAttrWarned) {
|
|
||||||
deprecatedMWithAttrWarned = true;
|
|
||||||
console.warn("m.withAttr() is deprecated, please use flarum's withAttr util (flarum/utils/withAttr) instead.");
|
|
||||||
}
|
|
||||||
return withAttr.bind(this)(...args);
|
|
||||||
};
|
|
||||||
// END DEPRECATED MITHRIL 2 BC LAYER
|
|
||||||
|
|
||||||
global.m = modifiedMithril;
|
global.m = modifiedMithril;
|
||||||
}
|
}
|
||||||
|
10
js/src/common/utils/proxifyCompat.ts
Normal file
10
js/src/common/utils/proxifyCompat.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
export default (compat: { [key: string]: any }, namespace: string) => {
|
||||||
|
// regex to replace common/ and NAMESPACE/ for core & core extensions
|
||||||
|
// e.g. admin/utils/extract --> utils/extract
|
||||||
|
// e.g. tags/common/utils/sortTags --> tags/utils/sortTags
|
||||||
|
const regex = new RegExp(`(\\w+\\/)?(${namespace}|common)\\/`);
|
||||||
|
|
||||||
|
return new Proxy(compat, {
|
||||||
|
get: (obj, prop: string) => obj[prop] || obj[prop.replace(regex, '$1')],
|
||||||
|
});
|
||||||
|
};
|
@@ -16,6 +16,7 @@ import NotificationListState from './states/NotificationListState';
|
|||||||
import GlobalSearchState from './states/GlobalSearchState';
|
import GlobalSearchState from './states/GlobalSearchState';
|
||||||
import DiscussionListState from './states/DiscussionListState';
|
import DiscussionListState from './states/DiscussionListState';
|
||||||
import ComposerState from './states/ComposerState';
|
import ComposerState from './states/ComposerState';
|
||||||
|
import isSafariMobile from './utils/isSafariMobile';
|
||||||
|
|
||||||
export default class ForumApplication extends Application {
|
export default class ForumApplication extends Application {
|
||||||
/**
|
/**
|
||||||
@@ -90,11 +91,6 @@ export default class ForumApplication extends Application {
|
|||||||
* @type {DiscussionListState}
|
* @type {DiscussionListState}
|
||||||
*/
|
*/
|
||||||
this.discussions = new DiscussionListState({}, this);
|
this.discussions = new DiscussionListState({}, this);
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated beta 14, remove in beta 15.
|
|
||||||
*/
|
|
||||||
this.cache.discussionList = this.discussions;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -143,6 +139,12 @@ export default class ForumApplication extends Application {
|
|||||||
m.redraw();
|
m.redraw();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (isSafariMobile()) {
|
||||||
|
$(() => {
|
||||||
|
$('.App').addClass('mobile-safari');
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
8
js/src/forum/app.ts
Normal file
8
js/src/forum/app.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import Forum from './ForumApplication';
|
||||||
|
|
||||||
|
const app = new Forum();
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
window.app = app;
|
||||||
|
|
||||||
|
export default app;
|
@@ -16,6 +16,7 @@ import PostStreamState from './states/PostStreamState';
|
|||||||
import SearchState from './states/SearchState';
|
import SearchState from './states/SearchState';
|
||||||
import AffixedSidebar from './components/AffixedSidebar';
|
import AffixedSidebar from './components/AffixedSidebar';
|
||||||
import DiscussionPage from './components/DiscussionPage';
|
import DiscussionPage from './components/DiscussionPage';
|
||||||
|
import DiscussionListPane from './components/DiscussionListPane';
|
||||||
import LogInModal from './components/LogInModal';
|
import LogInModal from './components/LogInModal';
|
||||||
import ComposerBody from './components/ComposerBody';
|
import ComposerBody from './components/ComposerBody';
|
||||||
import ForgotPasswordModal from './components/ForgotPasswordModal';
|
import ForgotPasswordModal from './components/ForgotPasswordModal';
|
||||||
@@ -35,8 +36,6 @@ import HeaderSecondary from './components/HeaderSecondary';
|
|||||||
import ComposerButton from './components/ComposerButton';
|
import ComposerButton from './components/ComposerButton';
|
||||||
import DiscussionList from './components/DiscussionList';
|
import DiscussionList from './components/DiscussionList';
|
||||||
import ReplyPlaceholder from './components/ReplyPlaceholder';
|
import ReplyPlaceholder from './components/ReplyPlaceholder';
|
||||||
import TextEditor from './components/TextEditor';
|
|
||||||
import TextEditorButton from './components/TextEditorButton';
|
|
||||||
import AvatarEditor from './components/AvatarEditor';
|
import AvatarEditor from './components/AvatarEditor';
|
||||||
import Post from './components/Post';
|
import Post from './components/Post';
|
||||||
import SettingsPage from './components/SettingsPage';
|
import SettingsPage from './components/SettingsPage';
|
||||||
@@ -72,6 +71,7 @@ import DiscussionListItem from './components/DiscussionListItem';
|
|||||||
import LoadingPost from './components/LoadingPost';
|
import LoadingPost from './components/LoadingPost';
|
||||||
import PostsUserPage from './components/PostsUserPage';
|
import PostsUserPage from './components/PostsUserPage';
|
||||||
import DiscussionPageResolver from './resolvers/DiscussionPageResolver';
|
import DiscussionPageResolver from './resolvers/DiscussionPageResolver';
|
||||||
|
import BasicEditorDriver from '../common/utils/BasicEditorDriver';
|
||||||
import routes from './routes';
|
import routes from './routes';
|
||||||
import ForumApplication from './ForumApplication';
|
import ForumApplication from './ForumApplication';
|
||||||
|
|
||||||
@@ -84,6 +84,7 @@ export default Object.assign(compat, {
|
|||||||
'utils/alertEmailConfirmation': alertEmailConfirmation,
|
'utils/alertEmailConfirmation': alertEmailConfirmation,
|
||||||
'utils/UserControls': UserControls,
|
'utils/UserControls': UserControls,
|
||||||
'utils/Pane': Pane,
|
'utils/Pane': Pane,
|
||||||
|
'utils/BasicEditorDriver': BasicEditorDriver,
|
||||||
'states/ComposerState': ComposerState,
|
'states/ComposerState': ComposerState,
|
||||||
'states/DiscussionListState': DiscussionListState,
|
'states/DiscussionListState': DiscussionListState,
|
||||||
'states/GlobalSearchState': GlobalSearchState,
|
'states/GlobalSearchState': GlobalSearchState,
|
||||||
@@ -92,6 +93,7 @@ export default Object.assign(compat, {
|
|||||||
'states/SearchState': SearchState,
|
'states/SearchState': SearchState,
|
||||||
'components/AffixedSidebar': AffixedSidebar,
|
'components/AffixedSidebar': AffixedSidebar,
|
||||||
'components/DiscussionPage': DiscussionPage,
|
'components/DiscussionPage': DiscussionPage,
|
||||||
|
'components/DiscussionListPane': DiscussionListPane,
|
||||||
'components/LogInModal': LogInModal,
|
'components/LogInModal': LogInModal,
|
||||||
'components/ComposerBody': ComposerBody,
|
'components/ComposerBody': ComposerBody,
|
||||||
'components/ForgotPasswordModal': ForgotPasswordModal,
|
'components/ForgotPasswordModal': ForgotPasswordModal,
|
||||||
@@ -111,8 +113,6 @@ export default Object.assign(compat, {
|
|||||||
'components/ComposerButton': ComposerButton,
|
'components/ComposerButton': ComposerButton,
|
||||||
'components/DiscussionList': DiscussionList,
|
'components/DiscussionList': DiscussionList,
|
||||||
'components/ReplyPlaceholder': ReplyPlaceholder,
|
'components/ReplyPlaceholder': ReplyPlaceholder,
|
||||||
'components/TextEditor': TextEditor,
|
|
||||||
'components/TextEditorButton': TextEditorButton,
|
|
||||||
'components/AvatarEditor': AvatarEditor,
|
'components/AvatarEditor': AvatarEditor,
|
||||||
'components/Post': Post,
|
'components/Post': Post,
|
||||||
'components/SettingsPage': SettingsPage,
|
'components/SettingsPage': SettingsPage,
|
||||||
|
@@ -52,7 +52,13 @@ export default class AvatarEditor extends Component {
|
|||||||
ondragend={this.disableDragover.bind(this)}
|
ondragend={this.disableDragover.bind(this)}
|
||||||
ondrop={this.dropUpload.bind(this)}
|
ondrop={this.dropUpload.bind(this)}
|
||||||
>
|
>
|
||||||
{this.loading ? <LoadingIndicator /> : user.avatarUrl() ? icon('fas fa-pencil-alt') : icon('fas fa-plus-circle')}
|
{this.loading ? (
|
||||||
|
<LoadingIndicator display="unset" size="large" />
|
||||||
|
) : user.avatarUrl() ? (
|
||||||
|
icon('fas fa-pencil-alt')
|
||||||
|
) : (
|
||||||
|
icon('fas fa-plus-circle')
|
||||||
|
)}
|
||||||
</a>
|
</a>
|
||||||
<ul className="Dropdown-menu Menu">{listItems(this.controlItems().toArray())}</ul>
|
<ul className="Dropdown-menu Menu">{listItems(this.controlItems().toArray())}</ul>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -106,9 +106,8 @@ export default class ChangeEmailModal extends Modal {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const oldEmail = app.session.user.email();
|
|
||||||
|
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
|
this.alertAttrs = null;
|
||||||
|
|
||||||
app.session.user
|
app.session.user
|
||||||
.save(
|
.save(
|
||||||
@@ -118,7 +117,9 @@ export default class ChangeEmailModal extends Modal {
|
|||||||
meta: { password: this.password() },
|
meta: { password: this.password() },
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.then(() => (this.success = true))
|
.then(() => {
|
||||||
|
this.success = true;
|
||||||
|
})
|
||||||
.catch(() => {})
|
.catch(() => {})
|
||||||
.then(this.loaded.bind(this));
|
.then(this.loaded.bind(this));
|
||||||
}
|
}
|
||||||
|
@@ -76,13 +76,13 @@ export default class Composer extends Component {
|
|||||||
|
|
||||||
// Whenever any of the inputs inside the composer are have focus, we want to
|
// Whenever any of the inputs inside the composer are have focus, we want to
|
||||||
// add a class to the composer to draw attention to it.
|
// add a class to the composer to draw attention to it.
|
||||||
this.$().on('focus blur', ':input', (e) => {
|
this.$().on('focus blur', ':input,.TextEditor-editorContainer', (e) => {
|
||||||
this.active = e.type === 'focusin';
|
this.active = e.type === 'focusin';
|
||||||
m.redraw();
|
m.redraw();
|
||||||
});
|
});
|
||||||
|
|
||||||
// When the escape key is pressed on any inputs, close the composer.
|
// When the escape key is pressed on any inputs, close the composer.
|
||||||
this.$().on('keydown', ':input', 'esc', () => this.state.close());
|
this.$().on('keydown', ':input,.TextEditor-editorContainer', 'esc', () => this.state.close());
|
||||||
|
|
||||||
this.handlers = {};
|
this.handlers = {};
|
||||||
|
|
||||||
@@ -157,7 +157,7 @@ export default class Composer extends Component {
|
|||||||
* Draw focus to the first focusable content element (the text editor).
|
* Draw focus to the first focusable content element (the text editor).
|
||||||
*/
|
*/
|
||||||
focus() {
|
focus() {
|
||||||
this.$('.Composer-content :input:enabled:visible:first').focus();
|
this.$('.Composer-content :input:enabled:visible, .TextEditor-editor').first().focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -199,7 +199,7 @@ export default class Composer extends Component {
|
|||||||
*/
|
*/
|
||||||
animatePositionChange() {
|
animatePositionChange() {
|
||||||
// When exiting full-screen mode: focus content
|
// When exiting full-screen mode: focus content
|
||||||
if (this.prevPosition === ComposerState.Position.FULLSCREEN) {
|
if (this.prevPosition === ComposerState.Position.FULLSCREEN && this.state.position === ComposerState.Position.NORMAL) {
|
||||||
this.focus();
|
this.focus();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -265,7 +265,17 @@ export default class Composer extends Component {
|
|||||||
this.animateHeightChange().then(() => this.focus());
|
this.animateHeightChange().then(() => this.focus());
|
||||||
|
|
||||||
if (app.screen() === 'phone') {
|
if (app.screen() === 'phone') {
|
||||||
this.$().css('top', $(window).scrollTop());
|
// On safari fixed position doesn't properly work on mobile,
|
||||||
|
// So we use absolute and set the top value.
|
||||||
|
// https://github.com/flarum/core/issues/2652
|
||||||
|
|
||||||
|
// Due to another safari bug, `scrollTop` is unreliable when
|
||||||
|
// at the very bottom of the page AND opening the composer.
|
||||||
|
// So we fallback to a calculated version of scrollTop.
|
||||||
|
// https://github.com/flarum/core/issues/2683
|
||||||
|
const scrollElement = document.documentElement;
|
||||||
|
const topOfViewport = Math.min(scrollElement.scrollTop, scrollElement.scrollHeight - scrollElement.clientHeight);
|
||||||
|
this.$().css('top', $('.App').is('.mobile-safari') ? topOfViewport : 0);
|
||||||
this.showBackdrop();
|
this.showBackdrop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,10 +1,11 @@
|
|||||||
import Component from '../../common/Component';
|
import Component from '../../common/Component';
|
||||||
import LoadingIndicator from '../../common/components/LoadingIndicator';
|
import LoadingIndicator from '../../common/components/LoadingIndicator';
|
||||||
import ConfirmDocumentUnload from '../../common/components/ConfirmDocumentUnload';
|
import ConfirmDocumentUnload from '../../common/components/ConfirmDocumentUnload';
|
||||||
import TextEditor from './TextEditor';
|
import TextEditor from '../../common/components/TextEditor';
|
||||||
import avatar from '../../common/helpers/avatar';
|
import avatar from '../../common/helpers/avatar';
|
||||||
import listItems from '../../common/helpers/listItems';
|
import listItems from '../../common/helpers/listItems';
|
||||||
import ItemList from '../../common/utils/ItemList';
|
import ItemList from '../../common/utils/ItemList';
|
||||||
|
import classList from '../../common/utils/classList';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The `ComposerBody` component handles the body, or the content, of the
|
* The `ComposerBody` component handles the body, or the content, of the
|
||||||
@@ -44,12 +45,6 @@ export default class ComposerBody extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.composer.fields.content(this.attrs.originalContent || '');
|
this.composer.fields.content(this.attrs.originalContent || '');
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated BC layer, remove in Beta 15.
|
|
||||||
*/
|
|
||||||
this.content = this.composer.fields.content;
|
|
||||||
this.editor = this.composer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
view() {
|
view() {
|
||||||
@@ -72,7 +67,7 @@ export default class ComposerBody extends Component {
|
|||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{LoadingIndicator.component({ className: 'ComposerBody-loading' + (this.loading ? ' active' : '') })}
|
<LoadingIndicator display="unset" containerClassName={classList('ComposerBody-loading', this.loading && 'active')} size="large" />
|
||||||
</div>
|
</div>
|
||||||
</ConfirmDocumentUnload>
|
</ConfirmDocumentUnload>
|
||||||
);
|
);
|
||||||
|
@@ -100,7 +100,7 @@ export default class DiscussionComposer extends ComposerBody {
|
|||||||
.save(data)
|
.save(data)
|
||||||
.then((discussion) => {
|
.then((discussion) => {
|
||||||
this.composer.hide();
|
this.composer.hide();
|
||||||
app.discussions.refresh();
|
app.discussions.refresh({ deferClear: true });
|
||||||
m.route.set(app.route.discussion(discussion));
|
m.route.set(app.route.discussion(discussion));
|
||||||
}, this.loaded.bind(this));
|
}, this.loaded.bind(this));
|
||||||
}
|
}
|
||||||
|
@@ -19,7 +19,7 @@ export default class DiscussionList extends Component {
|
|||||||
let loading;
|
let loading;
|
||||||
|
|
||||||
if (state.isLoading()) {
|
if (state.isLoading()) {
|
||||||
loading = LoadingIndicator.component();
|
loading = <LoadingIndicator />;
|
||||||
} else if (state.moreResults) {
|
} else if (state.moreResults) {
|
||||||
loading = Button.component(
|
loading = Button.component(
|
||||||
{
|
{
|
||||||
|
@@ -14,6 +14,7 @@ import DiscussionControls from '../utils/DiscussionControls';
|
|||||||
import slidable from '../utils/slidable';
|
import slidable from '../utils/slidable';
|
||||||
import extractText from '../../common/utils/extractText';
|
import extractText from '../../common/utils/extractText';
|
||||||
import classList from '../../common/utils/classList';
|
import classList from '../../common/utils/classList';
|
||||||
|
import DiscussionPage from './DiscussionPage';
|
||||||
|
|
||||||
import { escapeRegExp } from 'lodash-es';
|
import { escapeRegExp } from 'lodash-es';
|
||||||
/**
|
/**
|
||||||
@@ -86,6 +87,7 @@ export default class DiscussionListItem extends Component {
|
|||||||
icon: 'fas fa-ellipsis-v',
|
icon: 'fas fa-ellipsis-v',
|
||||||
className: 'DiscussionListItem-controls',
|
className: 'DiscussionListItem-controls',
|
||||||
buttonClassName: 'Button Button--icon Button--flat Slidable-underneath Slidable-underneath--right',
|
buttonClassName: 'Button Button--icon Button--flat Slidable-underneath Slidable-underneath--right',
|
||||||
|
accessibleToggleLabel: app.translator.trans('core.forum.discussion_controls.toggle_dropdown_accessible_label'),
|
||||||
},
|
},
|
||||||
controls
|
controls
|
||||||
)
|
)
|
||||||
@@ -120,6 +122,8 @@ export default class DiscussionListItem extends Component {
|
|||||||
</Link>
|
</Link>
|
||||||
|
|
||||||
<span
|
<span
|
||||||
|
tabindex="0"
|
||||||
|
role="button"
|
||||||
className="DiscussionListItem-count"
|
className="DiscussionListItem-count"
|
||||||
onclick={this.markAsRead.bind(this)}
|
onclick={this.markAsRead.bind(this)}
|
||||||
title={showUnread ? app.translator.trans('core.forum.discussion_list.mark_as_read_tooltip') : ''}
|
title={showUnread ? app.translator.trans('core.forum.discussion_list.mark_as_read_tooltip') : ''}
|
||||||
@@ -156,9 +160,7 @@ export default class DiscussionListItem extends Component {
|
|||||||
* @return {Boolean}
|
* @return {Boolean}
|
||||||
*/
|
*/
|
||||||
active() {
|
active() {
|
||||||
const idParam = m.route.param('id');
|
return app.current.matches(DiscussionPage, { discussion: this.attrs.discussion });
|
||||||
|
|
||||||
return idParam && idParam.split('-')[0] === this.attrs.discussion.id();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
import DiscussionList from './DiscussionList';
|
import DiscussionList from './DiscussionList';
|
||||||
import Component from '../../common/Component';
|
import Component from '../../common/Component';
|
||||||
|
import DiscussionPage from './DiscussionPage';
|
||||||
|
|
||||||
const hotEdge = (e) => {
|
const hotEdge = (e) => {
|
||||||
if (e.pageX < 10) app.pane.show();
|
if (e.pageX < 10) app.pane.show();
|
||||||
@@ -36,23 +37,31 @@ export default class DiscussionListPane extends Component {
|
|||||||
|
|
||||||
$(document).on('mousemove', hotEdge);
|
$(document).on('mousemove', hotEdge);
|
||||||
|
|
||||||
// If the discussion we are viewing is listed in the discussion list, then
|
// When coming from another discussion, scroll to the previous postition
|
||||||
// we will make sure it is visible in the viewport – if it is not we will
|
// to prevent the discussion list jumping around.
|
||||||
// scroll the list down to it.
|
if (app.previous.matches(DiscussionPage)) {
|
||||||
const $discussion = $list.find('.DiscussionListItem.active');
|
const top = app.cache.discussionListPaneScrollTop || 0;
|
||||||
if ($discussion.length) {
|
$list.scrollTop(top);
|
||||||
const listTop = $list.offset().top;
|
} else {
|
||||||
const listBottom = listTop + $list.outerHeight();
|
// If the discussion we are viewing is listed in the discussion list, then
|
||||||
const discussionTop = $discussion.offset().top;
|
// we will make sure it is visible in the viewport – if it is not we will
|
||||||
const discussionBottom = discussionTop + $discussion.outerHeight();
|
// scroll the list down to it.
|
||||||
|
const $discussion = $list.find('.DiscussionListItem.active');
|
||||||
|
if ($discussion.length) {
|
||||||
|
const listTop = $list.offset().top;
|
||||||
|
const listBottom = listTop + $list.outerHeight();
|
||||||
|
const discussionTop = $discussion.offset().top;
|
||||||
|
const discussionBottom = discussionTop + $discussion.outerHeight();
|
||||||
|
|
||||||
if (discussionTop < listTop || discussionBottom > listBottom) {
|
if (discussionTop < listTop || discussionBottom > listBottom) {
|
||||||
$list.scrollTop($list.scrollTop() - listTop + discussionTop);
|
$list.scrollTop($list.scrollTop() - listTop + discussionTop);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onremove() {
|
onremove(vnode) {
|
||||||
|
app.cache.discussionListPaneScrollTop = $(vnode.dom).scrollTop();
|
||||||
$(document).off('mousemove', hotEdge);
|
$(document).off('mousemove', hotEdge);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -18,6 +18,8 @@ export default class DiscussionPage extends Page {
|
|||||||
oninit(vnode) {
|
oninit(vnode) {
|
||||||
super.oninit(vnode);
|
super.oninit(vnode);
|
||||||
|
|
||||||
|
this.useBrowserScrollRestoration = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The discussion that is being viewed.
|
* The discussion that is being viewed.
|
||||||
*
|
*
|
||||||
@@ -71,23 +73,25 @@ export default class DiscussionPage extends Page {
|
|||||||
<div className="DiscussionPage">
|
<div className="DiscussionPage">
|
||||||
<DiscussionListPane state={app.discussions} />
|
<DiscussionListPane state={app.discussions} />
|
||||||
<div className="DiscussionPage-discussion">
|
<div className="DiscussionPage-discussion">
|
||||||
{discussion
|
{discussion ? (
|
||||||
? [
|
[
|
||||||
DiscussionHero.component({ discussion }),
|
DiscussionHero.component({ discussion }),
|
||||||
<div className="container">
|
<div className="container">
|
||||||
<nav className="DiscussionPage-nav">
|
<nav className="DiscussionPage-nav">
|
||||||
<ul>{listItems(this.sidebarItems().toArray())}</ul>
|
<ul>{listItems(this.sidebarItems().toArray())}</ul>
|
||||||
</nav>
|
</nav>
|
||||||
<div className="DiscussionPage-stream">
|
<div className="DiscussionPage-stream">
|
||||||
{PostStream.component({
|
{PostStream.component({
|
||||||
discussion,
|
discussion,
|
||||||
stream: this.stream,
|
stream: this.stream,
|
||||||
onPositionChange: this.positionChanged.bind(this),
|
onPositionChange: this.positionChanged.bind(this),
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
</div>,
|
</div>,
|
||||||
]
|
]
|
||||||
: LoadingIndicator.component({ className: 'LoadingIndicator--block' })}
|
) : (
|
||||||
|
<LoadingIndicator />
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -107,7 +111,7 @@ export default class DiscussionPage extends Page {
|
|||||||
} else {
|
} else {
|
||||||
const params = this.requestParams();
|
const params = this.requestParams();
|
||||||
|
|
||||||
app.store.find('discussions', m.route.param('id').split('-')[0], params).then(this.show.bind(this));
|
app.store.find('discussions', m.route.param('id'), params).then(this.show.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
m.redraw();
|
m.redraw();
|
||||||
@@ -121,6 +125,7 @@ export default class DiscussionPage extends Page {
|
|||||||
*/
|
*/
|
||||||
requestParams() {
|
requestParams() {
|
||||||
return {
|
return {
|
||||||
|
bySlug: true,
|
||||||
page: { near: this.near },
|
page: { near: this.near },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -186,6 +191,7 @@ export default class DiscussionPage extends Page {
|
|||||||
icon: 'fas fa-ellipsis-v',
|
icon: 'fas fa-ellipsis-v',
|
||||||
className: 'App-primaryControl',
|
className: 'App-primaryControl',
|
||||||
buttonClassName: 'Button--primary',
|
buttonClassName: 'Button--primary',
|
||||||
|
accessibleToggleLabel: app.translator.trans('core.forum.discussion_controls.toggle_dropdown_accessible_label'),
|
||||||
},
|
},
|
||||||
DiscussionControls.controls(this.discussion, this).toArray()
|
DiscussionControls.controls(this.discussion, this).toArray()
|
||||||
)
|
)
|
||||||
|
@@ -37,9 +37,10 @@ export default class EditUserModal extends Modal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
content() {
|
content() {
|
||||||
|
const fields = this.fields().toArray();
|
||||||
return (
|
return (
|
||||||
<div className="Modal-body">
|
<div className="Modal-body">
|
||||||
<div className="Form">{this.fields().toArray()}</div>
|
{fields.length > 1 ? <div className="Form">{this.fields().toArray()}</div> : app.translator.trans('core.forum.edit_user.nothing_available')}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -47,96 +48,112 @@ export default class EditUserModal extends Modal {
|
|||||||
fields() {
|
fields() {
|
||||||
const items = new ItemList();
|
const items = new ItemList();
|
||||||
|
|
||||||
items.add(
|
if (app.session.user.canEditCredentials()) {
|
||||||
'username',
|
|
||||||
<div className="Form-group">
|
|
||||||
<label>{app.translator.trans('core.forum.edit_user.username_heading')}</label>
|
|
||||||
<input className="FormControl" placeholder={extractText(app.translator.trans('core.forum.edit_user.username_label'))} bidi={this.username} />
|
|
||||||
</div>,
|
|
||||||
40
|
|
||||||
);
|
|
||||||
|
|
||||||
if (app.session.user !== this.attrs.user) {
|
|
||||||
items.add(
|
items.add(
|
||||||
'email',
|
'username',
|
||||||
<div className="Form-group">
|
<div className="Form-group">
|
||||||
<label>{app.translator.trans('core.forum.edit_user.email_heading')}</label>
|
<label>{app.translator.trans('core.forum.edit_user.username_heading')}</label>
|
||||||
<div>
|
<input
|
||||||
<input className="FormControl" placeholder={extractText(app.translator.trans('core.forum.edit_user.email_label'))} bidi={this.email} />
|
className="FormControl"
|
||||||
</div>
|
placeholder={extractText(app.translator.trans('core.forum.edit_user.username_label'))}
|
||||||
{!this.isEmailConfirmed() ? (
|
bidi={this.username}
|
||||||
<div>
|
disabled={this.nonAdminEditingAdmin()}
|
||||||
{Button.component(
|
/>
|
||||||
{
|
|
||||||
className: 'Button Button--block',
|
|
||||||
loading: this.loading,
|
|
||||||
onclick: this.activate.bind(this),
|
|
||||||
},
|
|
||||||
app.translator.trans('core.forum.edit_user.activate_button')
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
''
|
|
||||||
)}
|
|
||||||
</div>,
|
</div>,
|
||||||
30
|
40
|
||||||
);
|
);
|
||||||
|
|
||||||
items.add(
|
if (app.session.user !== this.attrs.user) {
|
||||||
'password',
|
items.add(
|
||||||
<div className="Form-group">
|
'email',
|
||||||
<label>{app.translator.trans('core.forum.edit_user.password_heading')}</label>
|
<div className="Form-group">
|
||||||
<div>
|
<label>{app.translator.trans('core.forum.edit_user.email_heading')}</label>
|
||||||
<label className="checkbox">
|
<div>
|
||||||
<input
|
|
||||||
type="checkbox"
|
|
||||||
onchange={(e) => {
|
|
||||||
this.setPassword(e.target.checked);
|
|
||||||
m.redraw.sync();
|
|
||||||
if (e.target.checked) this.$('[name=password]').select();
|
|
||||||
e.redraw = false;
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
{app.translator.trans('core.forum.edit_user.set_password_label')}
|
|
||||||
</label>
|
|
||||||
{this.setPassword() ? (
|
|
||||||
<input
|
<input
|
||||||
className="FormControl"
|
className="FormControl"
|
||||||
type="password"
|
placeholder={extractText(app.translator.trans('core.forum.edit_user.email_label'))}
|
||||||
name="password"
|
bidi={this.email}
|
||||||
placeholder={extractText(app.translator.trans('core.forum.edit_user.password_label'))}
|
disabled={this.nonAdminEditingAdmin()}
|
||||||
bidi={this.password}
|
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
|
{!this.isEmailConfirmed() && this.userIsAdmin(app.session.user) ? (
|
||||||
|
<div>
|
||||||
|
{Button.component(
|
||||||
|
{
|
||||||
|
className: 'Button Button--block',
|
||||||
|
loading: this.loading,
|
||||||
|
onclick: this.activate.bind(this),
|
||||||
|
},
|
||||||
|
app.translator.trans('core.forum.edit_user.activate_button')
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
) : (
|
) : (
|
||||||
''
|
''
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>,
|
||||||
</div>,
|
30
|
||||||
20
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
items.add(
|
items.add(
|
||||||
'groups',
|
'password',
|
||||||
<div className="Form-group EditUserModal-groups">
|
<div className="Form-group">
|
||||||
<label>{app.translator.trans('core.forum.edit_user.groups_heading')}</label>
|
<label>{app.translator.trans('core.forum.edit_user.password_heading')}</label>
|
||||||
<div>
|
<div>
|
||||||
{Object.keys(this.groups)
|
|
||||||
.map((id) => app.store.getById('groups', id))
|
|
||||||
.map((group) => (
|
|
||||||
<label className="checkbox">
|
<label className="checkbox">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
bidi={this.groups[group.id()]}
|
onchange={(e) => {
|
||||||
disabled={this.attrs.user.id() === '1' && group.id() === Group.ADMINISTRATOR_ID}
|
this.setPassword(e.target.checked);
|
||||||
|
m.redraw.sync();
|
||||||
|
if (e.target.checked) this.$('[name=password]').select();
|
||||||
|
e.redraw = false;
|
||||||
|
}}
|
||||||
|
disabled={this.nonAdminEditingAdmin()}
|
||||||
/>
|
/>
|
||||||
{GroupBadge.component({ group, label: '' })} {group.nameSingular()}
|
{app.translator.trans('core.forum.edit_user.set_password_label')}
|
||||||
</label>
|
</label>
|
||||||
))}
|
{this.setPassword() ? (
|
||||||
</div>
|
<input
|
||||||
</div>,
|
className="FormControl"
|
||||||
10
|
type="password"
|
||||||
);
|
name="password"
|
||||||
|
placeholder={extractText(app.translator.trans('core.forum.edit_user.password_label'))}
|
||||||
|
bidi={this.password}
|
||||||
|
disabled={this.nonAdminEditingAdmin()}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
''
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>,
|
||||||
|
20
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (app.session.user.canEditGroups()) {
|
||||||
|
items.add(
|
||||||
|
'groups',
|
||||||
|
<div className="Form-group EditUserModal-groups">
|
||||||
|
<label>{app.translator.trans('core.forum.edit_user.groups_heading')}</label>
|
||||||
|
<div>
|
||||||
|
{Object.keys(this.groups)
|
||||||
|
.map((id) => app.store.getById('groups', id))
|
||||||
|
.map((group) => (
|
||||||
|
<label className="checkbox">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
bidi={this.groups[group.id()]}
|
||||||
|
disabled={group.id() === Group.ADMINISTRATOR_ID && (this.attrs.user === app.session.user || !this.userIsAdmin(app.session.user))}
|
||||||
|
/>
|
||||||
|
{GroupBadge.component({ group, label: '' })} {group.nameSingular()}
|
||||||
|
</label>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>,
|
||||||
|
10
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
items.add(
|
items.add(
|
||||||
'submit',
|
'submit',
|
||||||
@@ -176,21 +193,26 @@ export default class EditUserModal extends Modal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
const groups = Object.keys(this.groups)
|
|
||||||
.filter((id) => this.groups[id]())
|
|
||||||
.map((id) => app.store.getById('groups', id));
|
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
username: this.username(),
|
relationships: {},
|
||||||
relationships: { groups },
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (app.session.user !== this.attrs.user) {
|
if (this.attrs.user.canEditCredentials() && !this.nonAdminEditingAdmin()) {
|
||||||
data.email = this.email();
|
data.username = this.username();
|
||||||
|
|
||||||
|
if (app.session.user !== this.attrs.user) {
|
||||||
|
data.email = this.email();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.setPassword()) {
|
||||||
|
data.password = this.password();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.setPassword()) {
|
if (this.attrs.user.canEditGroups()) {
|
||||||
data.password = this.password();
|
data.relationships.groups = Object.keys(this.groups)
|
||||||
|
.filter((id) => this.groups[id]())
|
||||||
|
.map((id) => app.store.getById('groups', id));
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
@@ -209,4 +231,16 @@ export default class EditUserModal extends Modal {
|
|||||||
m.redraw();
|
m.redraw();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nonAdminEditingAdmin() {
|
||||||
|
return this.userIsAdmin(this.attrs.user) && !this.userIsAdmin(app.session.user);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
* @protected
|
||||||
|
*/
|
||||||
|
userIsAdmin(user) {
|
||||||
|
return user.groups().some((g) => g.id() === Group.ADMINISTRATOR_ID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -57,6 +57,7 @@ export default class HeaderSecondary extends Component {
|
|||||||
SelectDropdown.component(
|
SelectDropdown.component(
|
||||||
{
|
{
|
||||||
buttonClassName: 'Button Button--link',
|
buttonClassName: 'Button Button--link',
|
||||||
|
accessibleToggleLabel: app.translator.trans('core.forum.header.locale_dropdown_accessible_label'),
|
||||||
},
|
},
|
||||||
locales
|
locales
|
||||||
),
|
),
|
||||||
|
@@ -172,6 +172,7 @@ export default class IndexPage extends Page {
|
|||||||
{
|
{
|
||||||
buttonClassName: 'Button',
|
buttonClassName: 'Button',
|
||||||
className: 'App-titleControl',
|
className: 'App-titleControl',
|
||||||
|
accessibleToggleLabel: app.translator.trans('core.forum.index.toggle_sidenav_dropdown_accessible_label'),
|
||||||
},
|
},
|
||||||
this.navItems(this).toArray()
|
this.navItems(this).toArray()
|
||||||
)
|
)
|
||||||
@@ -227,6 +228,7 @@ export default class IndexPage extends Page {
|
|||||||
{
|
{
|
||||||
buttonClassName: 'Button',
|
buttonClassName: 'Button',
|
||||||
label: sortOptions[app.search.params().sort] || Object.keys(sortMap).map((key) => sortOptions[key])[0],
|
label: sortOptions[app.search.params().sort] || Object.keys(sortMap).map((key) => sortOptions[key])[0],
|
||||||
|
accessibleToggleLabel: app.translator.trans('core.forum.index_sort.toggle_dropdown_accessible_label'),
|
||||||
},
|
},
|
||||||
Object.keys(sortOptions).map((value) => {
|
Object.keys(sortOptions).map((value) => {
|
||||||
const label = sortOptions[value];
|
const label = sortOptions[value];
|
||||||
|
@@ -84,7 +84,7 @@ export default class NotificationList extends Component {
|
|||||||
})
|
})
|
||||||
: ''}
|
: ''}
|
||||||
{state.isLoading() ? (
|
{state.isLoading() ? (
|
||||||
<LoadingIndicator className="LoadingIndicator--block" />
|
<LoadingIndicator />
|
||||||
) : pages.length ? (
|
) : pages.length ? (
|
||||||
''
|
''
|
||||||
) : (
|
) : (
|
||||||
@@ -99,7 +99,9 @@ export default class NotificationList extends Component {
|
|||||||
super.oncreate(vnode);
|
super.oncreate(vnode);
|
||||||
|
|
||||||
this.$notifications = this.$('.NotificationList-content');
|
this.$notifications = this.$('.NotificationList-content');
|
||||||
this.$scrollParent = this.$notifications.css('overflow') === 'auto' ? this.$notifications : $(window);
|
|
||||||
|
// If we are on the notifications page, the window will be scrolling and not the $notifications element.
|
||||||
|
this.$scrollParent = this.inPanel() ? this.$notifications : $(window);
|
||||||
|
|
||||||
this.boundScrollHandler = this.scrollHandler.bind(this);
|
this.boundScrollHandler = this.scrollHandler.bind(this);
|
||||||
this.$scrollParent.on('scroll', this.boundScrollHandler);
|
this.$scrollParent.on('scroll', this.boundScrollHandler);
|
||||||
@@ -112,14 +114,24 @@ export default class NotificationList extends Component {
|
|||||||
scrollHandler() {
|
scrollHandler() {
|
||||||
const state = this.attrs.state;
|
const state = this.attrs.state;
|
||||||
|
|
||||||
const scrollTop = this.$scrollParent.scrollTop();
|
// Whole-page scroll events are listened to on `window`, but we need to get the actual
|
||||||
const viewportHeight = this.$scrollParent.height();
|
// scrollHeight, scrollTop, and clientHeight from the document element.
|
||||||
|
const scrollParent = this.inPanel() ? this.$scrollParent[0] : document.documentElement;
|
||||||
|
|
||||||
const contentTop = this.$scrollParent === this.$notifications ? 0 : this.$notifications.offset().top;
|
// On very short screens, the scrollHeight + scrollTop might not reach the clientHeight
|
||||||
const contentHeight = this.$notifications[0].scrollHeight;
|
// by a fraction of a pixel, so we compensate for that.
|
||||||
|
const atBottom = Math.abs(scrollParent.scrollHeight - scrollParent.scrollTop - scrollParent.clientHeight) <= 1;
|
||||||
|
|
||||||
if (state.hasMoreResults() && !state.isLoading() && scrollTop + viewportHeight >= contentTop + contentHeight) {
|
if (state.hasMoreResults() && !state.isLoading() && atBottom) {
|
||||||
state.loadMore();
|
state.loadMore();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the NotificationList component isn't in a panel (e.g. on NotificationPage when mobile),
|
||||||
|
* we need to listen to scroll events on the window, and get scroll state from the body.
|
||||||
|
*/
|
||||||
|
inPanel() {
|
||||||
|
return this.$notifications.css('overflow') === 'auto';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,6 +9,8 @@ export default class NotificationsDropdown extends Dropdown {
|
|||||||
attrs.menuClassName = attrs.menuClassName || 'Dropdown-menu--right';
|
attrs.menuClassName = attrs.menuClassName || 'Dropdown-menu--right';
|
||||||
attrs.label = attrs.label || app.translator.trans('core.forum.notifications.tooltip');
|
attrs.label = attrs.label || app.translator.trans('core.forum.notifications.tooltip');
|
||||||
attrs.icon = attrs.icon || 'fas fa-bell';
|
attrs.icon = attrs.icon || 'fas fa-bell';
|
||||||
|
// For best a11y support, both `title` and `aria-label` should be used
|
||||||
|
attrs.accessibleToggleLabel = attrs.accessibleToggleLabel || app.translator.trans('core.forum.notifications.toggle_dropdown_accessible_label');
|
||||||
|
|
||||||
super.initAttrs(attrs);
|
super.initAttrs(attrs);
|
||||||
}
|
}
|
||||||
|
@@ -61,6 +61,7 @@ export default class Post extends Component {
|
|||||||
icon="fas fa-ellipsis-h"
|
icon="fas fa-ellipsis-h"
|
||||||
onshow={() => this.$('.Post-actions').addClass('open')}
|
onshow={() => this.$('.Post-actions').addClass('open')}
|
||||||
onhide={() => this.$('.Post-actions').removeClass('open')}
|
onhide={() => this.$('.Post-actions').removeClass('open')}
|
||||||
|
accessibleToggleLabel={app.translator.trans('core.forum.post_controls.toggle_dropdown_accessible_label')}
|
||||||
>
|
>
|
||||||
{controls}
|
{controls}
|
||||||
</Dropdown>
|
</Dropdown>
|
||||||
|
@@ -142,13 +142,29 @@ export default class PostStream extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When the window is scrolled, check if either extreme of the post stream is
|
|
||||||
* in the viewport, and if so, trigger loading the next/previous page.
|
|
||||||
*
|
*
|
||||||
* @param {Integer} top
|
* @param {Integer} top
|
||||||
*/
|
*/
|
||||||
onscroll(top = window.pageYOffset) {
|
onscroll(top = window.pageYOffset) {
|
||||||
if (this.stream.paused) return;
|
if (this.stream.paused || this.stream.pagesLoading) return;
|
||||||
|
|
||||||
|
this.updateScrubber(top);
|
||||||
|
|
||||||
|
this.loadPostsIfNeeded(top);
|
||||||
|
|
||||||
|
// Throttle calculation of our position (start/end numbers of posts in the
|
||||||
|
// viewport) to 100ms.
|
||||||
|
clearTimeout(this.calculatePositionTimeout);
|
||||||
|
this.calculatePositionTimeout = setTimeout(this.calculatePosition.bind(this, top), 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if either extreme of the post stream is in the viewport,
|
||||||
|
* and if so, trigger loading the next/previous page.
|
||||||
|
*
|
||||||
|
* @param {Integer} top
|
||||||
|
*/
|
||||||
|
loadPostsIfNeeded(top = window.pageYOffset) {
|
||||||
const marginTop = this.getMarginTop();
|
const marginTop = this.getMarginTop();
|
||||||
const viewportHeight = $(window).height() - marginTop;
|
const viewportHeight = $(window).height() - marginTop;
|
||||||
const viewportTop = top + marginTop;
|
const viewportTop = top + marginTop;
|
||||||
@@ -169,13 +185,6 @@ export default class PostStream extends Component {
|
|||||||
this.stream.loadNext();
|
this.stream.loadNext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Throttle calculation of our position (start/end numbers of posts in the
|
|
||||||
// viewport) to 100ms.
|
|
||||||
clearTimeout(this.calculatePositionTimeout);
|
|
||||||
this.calculatePositionTimeout = setTimeout(this.calculatePosition.bind(this, top), 100);
|
|
||||||
|
|
||||||
this.updateScrubber(top);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateScrubber(top = window.pageYOffset) {
|
updateScrubber(top = window.pageYOffset) {
|
||||||
@@ -396,6 +405,8 @@ export default class PostStream extends Component {
|
|||||||
|
|
||||||
this.calculatePosition();
|
this.calculatePosition();
|
||||||
this.stream.paused = false;
|
this.stream.paused = false;
|
||||||
|
// Check if we need to load more posts after scrolling.
|
||||||
|
this.loadPostsIfNeeded();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -112,7 +112,6 @@ export default class PostStreamScrubber extends Component {
|
|||||||
|
|
||||||
// Now we want to make the scrollbar handle draggable. Let's start by
|
// Now we want to make the scrollbar handle draggable. Let's start by
|
||||||
// preventing default browser events from messing things up.
|
// preventing default browser events from messing things up.
|
||||||
.css({ cursor: 'pointer', 'user-select': 'none' })
|
|
||||||
.bind('dragstart mousedown touchstart', (e) => e.preventDefault());
|
.bind('dragstart mousedown touchstart', (e) => e.preventDefault());
|
||||||
|
|
||||||
// When the mouse is pressed on the scrollbar handle, we capture some
|
// When the mouse is pressed on the scrollbar handle, we capture some
|
||||||
@@ -124,7 +123,6 @@ export default class PostStreamScrubber extends Component {
|
|||||||
this.indexStart = 0;
|
this.indexStart = 0;
|
||||||
|
|
||||||
this.$('.Scrubber-handle')
|
this.$('.Scrubber-handle')
|
||||||
.css('cursor', 'move')
|
|
||||||
.bind('mousedown touchstart', this.onmousedown.bind(this))
|
.bind('mousedown touchstart', this.onmousedown.bind(this))
|
||||||
|
|
||||||
// Exempt the scrollbar handle from the 'jump to' click event.
|
// Exempt the scrollbar handle from the 'jump to' click event.
|
||||||
|
@@ -121,7 +121,7 @@ export default class PostsUserPage extends UserPage {
|
|||||||
loadResults(offset) {
|
loadResults(offset) {
|
||||||
return app.store.find('posts', {
|
return app.store.find('posts', {
|
||||||
filter: {
|
filter: {
|
||||||
user: this.user.id(),
|
author: this.user.username(),
|
||||||
type: 'comment',
|
type: 'comment',
|
||||||
},
|
},
|
||||||
page: { offset, limit: this.loadLimit },
|
page: { offset, limit: this.loadLimit },
|
||||||
|
@@ -49,7 +49,7 @@ export default class RenameDiscussionModal extends Modal {
|
|||||||
|
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
|
|
||||||
const title = this.newTitle;
|
const title = this.newTitle();
|
||||||
const currentTitle = this.currentTitle;
|
const currentTitle = this.currentTitle;
|
||||||
|
|
||||||
// If the title is different to what it was before, then save it. After the
|
// If the title is different to what it was before, then save it. After the
|
||||||
|
@@ -5,6 +5,7 @@ import avatar from '../../common/helpers/avatar';
|
|||||||
import username from '../../common/helpers/username';
|
import username from '../../common/helpers/username';
|
||||||
import DiscussionControls from '../utils/DiscussionControls';
|
import DiscussionControls from '../utils/DiscussionControls';
|
||||||
import ComposerPostPreview from './ComposerPostPreview';
|
import ComposerPostPreview from './ComposerPostPreview';
|
||||||
|
import listItems from '../../common/helpers/listItems';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The `ReplyPlaceholder` component displays a placeholder for a reply, which,
|
* The `ReplyPlaceholder` component displays a placeholder for a reply, which,
|
||||||
@@ -25,6 +26,7 @@ export default class ReplyPlaceholder extends Component {
|
|||||||
{avatar(app.session.user, { className: 'PostUser-avatar' })}
|
{avatar(app.session.user, { className: 'PostUser-avatar' })}
|
||||||
{username(app.session.user)}
|
{username(app.session.user)}
|
||||||
</h3>
|
</h3>
|
||||||
|
<ul className="PostUser-badges badges">{listItems(app.session.user.badges().toArray())}</ul>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
<ComposerPostPreview className="Post-body" composer={app.composer} surround={this.anchorPreview.bind(this)} />
|
<ComposerPostPreview className="Post-body" composer={app.composer} surround={this.anchorPreview.bind(this)} />
|
||||||
|
@@ -21,6 +21,8 @@ import UsersSearchSource from './UsersSearchSource';
|
|||||||
* - state: SearchState instance.
|
* - state: SearchState instance.
|
||||||
*/
|
*/
|
||||||
export default class Search extends Component {
|
export default class Search extends Component {
|
||||||
|
static MIN_SEARCH_LEN = 3;
|
||||||
|
|
||||||
oninit(vnode) {
|
oninit(vnode) {
|
||||||
super.oninit(vnode);
|
super.oninit(vnode);
|
||||||
this.state = this.attrs.state;
|
this.state = this.attrs.state;
|
||||||
@@ -69,8 +71,11 @@ export default class Search extends Component {
|
|||||||
// Hide the search view if no sources were loaded
|
// Hide the search view if no sources were loaded
|
||||||
if (!this.sources.length) return <div></div>;
|
if (!this.sources.length) return <div></div>;
|
||||||
|
|
||||||
|
const searchLabel = extractText(app.translator.trans('core.forum.header.search_placeholder'));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
role="search"
|
||||||
className={
|
className={
|
||||||
'Search ' +
|
'Search ' +
|
||||||
classList({
|
classList({
|
||||||
@@ -83,16 +88,17 @@ export default class Search extends Component {
|
|||||||
>
|
>
|
||||||
<div className="Search-input">
|
<div className="Search-input">
|
||||||
<input
|
<input
|
||||||
|
aria-label={searchLabel}
|
||||||
className="FormControl"
|
className="FormControl"
|
||||||
type="search"
|
type="search"
|
||||||
placeholder={extractText(app.translator.trans('core.forum.header.search_placeholder'))}
|
placeholder={searchLabel}
|
||||||
value={this.state.getValue()}
|
value={this.state.getValue()}
|
||||||
oninput={(e) => this.state.setValue(e.target.value)}
|
oninput={(e) => this.state.setValue(e.target.value)}
|
||||||
onfocus={() => (this.hasFocus = true)}
|
onfocus={() => (this.hasFocus = true)}
|
||||||
onblur={() => (this.hasFocus = false)}
|
onblur={() => (this.hasFocus = false)}
|
||||||
/>
|
/>
|
||||||
{this.loadingSources ? (
|
{this.loadingSources ? (
|
||||||
LoadingIndicator.component({ size: 'tiny', className: 'Button Button--icon Button--link' })
|
<LoadingIndicator size="small" display="inline" containerClassName="Button Button--icon Button--link" />
|
||||||
) : currentSearch ? (
|
) : currentSearch ? (
|
||||||
<button className="Search-clear Button Button--icon Button--link" onclick={this.clear.bind(this)}>
|
<button className="Search-clear Button Button--icon Button--link" onclick={this.clear.bind(this)}>
|
||||||
{icon('fas fa-times-circle')}
|
{icon('fas fa-times-circle')}
|
||||||
@@ -108,9 +114,23 @@ export default class Search extends Component {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateMaxHeight() {
|
||||||
|
// Since extensions might add elements above the search box on mobile,
|
||||||
|
// we need to calculate and set the max height dynamically.
|
||||||
|
const resultsElementMargin = 14;
|
||||||
|
const maxHeight =
|
||||||
|
window.innerHeight - this.element.querySelector('.Search-input>.FormControl').getBoundingClientRect().bottom - resultsElementMargin;
|
||||||
|
this.element.querySelector('.Search-results').style['max-height'] = `${maxHeight}px`;
|
||||||
|
}
|
||||||
|
|
||||||
onupdate() {
|
onupdate() {
|
||||||
// Highlight the item that is currently selected.
|
// Highlight the item that is currently selected.
|
||||||
this.setIndex(this.getCurrentNumericIndex());
|
this.setIndex(this.getCurrentNumericIndex());
|
||||||
|
|
||||||
|
// If there are no sources, the search view is not shown.
|
||||||
|
if (!this.sources.length) return;
|
||||||
|
|
||||||
|
this.updateMaxHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
oncreate(vnode) {
|
oncreate(vnode) {
|
||||||
@@ -152,7 +172,7 @@ export default class Search extends Component {
|
|||||||
search.searchTimeout = setTimeout(() => {
|
search.searchTimeout = setTimeout(() => {
|
||||||
if (state.isCached(query)) return;
|
if (state.isCached(query)) return;
|
||||||
|
|
||||||
if (query.length >= 3) {
|
if (query.length >= Search.MIN_SEARCH_LEN) {
|
||||||
search.sources.map((source) => {
|
search.sources.map((source) => {
|
||||||
if (!source.search) return;
|
if (!source.search) return;
|
||||||
|
|
||||||
@@ -175,6 +195,13 @@ export default class Search extends Component {
|
|||||||
.one('mouseup', (e) => e.preventDefault())
|
.one('mouseup', (e) => e.preventDefault())
|
||||||
.select();
|
.select();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.updateMaxHeightHandler = this.updateMaxHeight.bind(this);
|
||||||
|
window.addEventListener('resize', this.updateMaxHeightHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
onremove() {
|
||||||
|
window.removeEventListener('resize', this.updateMaxHeightHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -17,6 +17,8 @@ export default class SessionDropdown extends Dropdown {
|
|||||||
attrs.className = 'SessionDropdown';
|
attrs.className = 'SessionDropdown';
|
||||||
attrs.buttonClassName = 'Button Button--user Button--flat';
|
attrs.buttonClassName = 'Button Button--user Button--flat';
|
||||||
attrs.menuClassName = 'Dropdown-menu--right';
|
attrs.menuClassName = 'Dropdown-menu--right';
|
||||||
|
|
||||||
|
attrs.accessibleToggleLabel = app.translator.trans('core.forum.header.session_dropdown_accessible_label');
|
||||||
}
|
}
|
||||||
|
|
||||||
view(vnode) {
|
view(vnode) {
|
||||||
|
@@ -40,6 +40,7 @@ export default class UserCard extends Component {
|
|||||||
menuClassName: 'Dropdown-menu--right',
|
menuClassName: 'Dropdown-menu--right',
|
||||||
buttonClassName: this.attrs.controlsButtonClassName,
|
buttonClassName: this.attrs.controlsButtonClassName,
|
||||||
label: app.translator.trans('core.forum.user_controls.button'),
|
label: app.translator.trans('core.forum.user_controls.button'),
|
||||||
|
accessibleToggleLabel: app.translator.trans('core.forum.user_controls.toggle_dropdown_accessible_label'),
|
||||||
icon: 'fas fa-ellipsis-v',
|
icon: 'fas fa-ellipsis-v',
|
||||||
},
|
},
|
||||||
controls
|
controls
|
||||||
|
@@ -51,7 +51,7 @@ export default class UserPage extends Page {
|
|||||||
</div>
|
</div>
|
||||||
</div>,
|
</div>,
|
||||||
]
|
]
|
||||||
: [<LoadingIndicator className="LoadingIndicator--block" />]}
|
: [<LoadingIndicator display="block" />]}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -102,7 +102,7 @@ export default class UserPage extends Page {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!this.user) {
|
if (!this.user) {
|
||||||
app.store.find('users', username).then(this.show.bind(this));
|
app.store.find('users', username, { bySlug: true }).then(this.show.bind(this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user