-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f0ffacc
commit 8d166fd
Showing
8 changed files
with
283 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
const libs = { | ||
fullcalendarCore: { | ||
js: 'https://cdn.jsdelivr.net/npm/@fullcalendar/core@6.1.8/index.global.min.js', | ||
loaded: () => typeof FullCalendar !== 'undefined', | ||
}, | ||
fullcalendarLocales: { | ||
js: 'https://cdn.jsdelivr.net/npm/@fullcalendar/core@6.1.8/locales-all.global.min.js', | ||
loaded: () => typeof FullCalendar !== 'undefined' && FullCalendar.globalLocales.length > 2, | ||
}, | ||
fullcalendarDayGrid: { | ||
js: 'https://cdn.jsdelivr.net/npm/@fullcalendar/daygrid@6.1.8/index.global.min.js', | ||
loaded: () => typeof FullCalendar !== 'undefined' && FullCalendar.globalPlugins.find((p) => p.name === '@fullcalendar/daygrid'), | ||
}, | ||
fullcalendarInteraction: { | ||
js: 'https://cdn.jsdelivr.net/npm/@fullcalendar/interaction@6.1.8/index.global.min.js', | ||
loaded: () => typeof FullCalendar !== 'undefined' && FullCalendar.globalPlugins.find((p) => p.name === '@fullcalendar/interaction'), | ||
}, | ||
fullcalendarList: { | ||
js: 'https://cdn.jsdelivr.net/npm/@fullcalendar/list@6.1.8/index.global.min.js', | ||
loaded: () => typeof FullCalendar !== 'undefined' && FullCalendar.globalPlugins.find((p) => p.name === '@fullcalendar/list'), | ||
}, | ||
|
||
flatpickr: { | ||
css: 'https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css', | ||
js: 'https://cdn.jsdelivr.net/npm/flatpickr', | ||
loaded: () => typeof window.flatpickr !== 'undefined', | ||
}, | ||
flatpickrLocale: { | ||
js: (locale) => `https://cdn.jsdelivr.net/npm/flatpickr/dist/l10n/${locale}.js`, | ||
loaded: (locale) => typeof window.flatpickr.l10ns[locale] !== 'undefined', | ||
}, | ||
}; | ||
|
||
export default function dynamicallyLoadLib(lib, ...moreArgs) { | ||
if (Array.isArray(lib)) { | ||
return Promise.all(lib.map((l) => dynamicallyLoadLib(l))); | ||
} | ||
|
||
let libConf = {}; | ||
|
||
// If the lib is an object | ||
if (typeof lib === 'object') { | ||
libConf = { ...lib }; | ||
|
||
if (!libConf.loaded) { | ||
console.warn('dynamicallyLoadLib: No loaded function defined for lib', lib); | ||
return Promise.resolve(); | ||
} | ||
} | ||
|
||
if (typeof lib === 'string') { | ||
// If lib is not in the libs object log a warning and return a resolved promise | ||
if (!libs[lib]) { | ||
console.warn('dynamicallyLoadLib: lib not found', lib); | ||
return Promise.resolve(); | ||
} | ||
|
||
libConf = { ...libs[lib] }; | ||
} | ||
|
||
if (Object.keys(libConf).length === 0) { | ||
console.warn('dynamicallyLoadLib: lib is not a string nor an valid object', lib); | ||
return Promise.resolve(); | ||
} | ||
|
||
let loadPromises = []; | ||
|
||
if (libConf.loaded(...moreArgs)) { | ||
loadPromises.push(Promise.resolve()); | ||
} else { | ||
if (libConf.css) { | ||
const css = Array.isArray(libConf.css) ? libConf.css : [libConf.css]; | ||
css.forEach((href) => { | ||
const css = document.createElement('link'); | ||
css.rel = 'stylesheet'; | ||
css.href = href; | ||
document.head.appendChild(css); | ||
}); | ||
} | ||
|
||
if (libConf.js) { | ||
if (typeof libConf.js === 'function') { | ||
libConf.js = libConf.js(...moreArgs); | ||
} | ||
|
||
const js = Array.isArray(libConf.js) ? libConf.js : [libConf.js]; | ||
js.forEach((src) => { | ||
const script = document.createElement('script'); | ||
script.src = src; | ||
document.head.appendChild(script); | ||
}); | ||
} | ||
|
||
loadPromises.push( | ||
new Promise((resolve, reject) => { | ||
const interval = setInterval(() => { | ||
if (libConf.loaded(...moreArgs)) { | ||
clearInterval(interval); | ||
resolve(); | ||
} | ||
}, 5); | ||
}) | ||
); | ||
} | ||
|
||
return Promise.all(loadPromises); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of askvortsov/flarum-moderator-warnings | ||
* | ||
* Copyright (c) 2021 Alexander Skvortsov. | ||
* | ||
* For detailed copyright and license information, please view the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Mattoid\CheckinHistory\Api\Controller; | ||
|
||
use Flarum\Api\Controller\AbstractListController; | ||
use Flarum\Http\RequestUtil; | ||
use Flarum\User\Exception\PermissionDeniedException; | ||
use Mattoid\CheckinHistory\Api\Serializer\CheckinHistorySerializer; | ||
use Mattoid\CheckinHistory\Model\UserCheckinHistory; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Tobscure\JsonApi\Document; | ||
|
||
class ListCheckinHistoryController extends AbstractListController | ||
{ | ||
public $serializer = CheckinHistorySerializer::class; | ||
|
||
public $include = ['warnedUser', 'addedByUser', 'hiddenByUser', 'post', 'post.discussion', 'post.user']; | ||
|
||
/** | ||
* Get the data to be serialized and assigned to the response document. | ||
* | ||
* @param ServerRequestInterface $request | ||
* @param Document $document | ||
* | ||
* @throws PermissionDeniedException | ||
* | ||
* @return mixed | ||
*/ | ||
protected function data(ServerRequestInterface $request, Document $document) | ||
{ | ||
|
||
$actor = RequestUtil::getActor($request); | ||
|
||
if (!$actor->can('event.view')) { | ||
return array(); | ||
} | ||
|
||
$userId = $request->getAttributes()['actor']['id']; | ||
|
||
return UserCheckinHistory::where('user_id', $userId)->where('last_checkin_date', ">=", $request->getQueryParams()['start']) | ||
->where('last_checkin_date', "<=", $request->getQueryParams()['end'])->get(); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of askvortsov/flarum-moderator-warnings | ||
* | ||
* Copyright (c) 2021 Alexander Skvortsov. | ||
* | ||
* For detailed copyright and license information, please view the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Mattoid\CheckinHistory\Api\Serializer; | ||
|
||
use Mattoid\CheckinHistory\Model\UserCheckinHistory; | ||
use Flarum\Api\Serializer\AbstractSerializer; | ||
use Flarum\Api\Serializer\PostSerializer; | ||
use Flarum\Post\Post; | ||
|
||
class CheckinHistorySerializer extends AbstractSerializer | ||
{ | ||
protected $type = 'checkin.history'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getDefaultAttributes($history) | ||
{ | ||
$attributes = [ | ||
'id' => $history->id, | ||
'userId' => $history->user_id, | ||
'name' => $history->type ? '签到' : '补签', | ||
'totalCheckinCount' => $history->total_checkin_count, | ||
'totalContinuousCheckinCount' => $history->total_continuous_checkin_count, | ||
'start' => $history->last_checkin_date, | ||
'time' => $history->last_checkin_time, | ||
]; | ||
|
||
return $attributes; | ||
} | ||
|
||
protected function format($text) | ||
{ | ||
return UserCheckinHistory::getFormatter()->render($text, new Post()); | ||
} | ||
|
||
protected function post($history) | ||
{ | ||
return $this->hasOne($history, PostSerializer::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters