From a0cab889c70fa2a70cee0840f0b64faa8844eebc Mon Sep 17 00:00:00 2001 From: Michael V Date: Sat, 22 Sep 2018 22:40:49 +0200 Subject: [PATCH 01/37] Test latest profile viewers list on front-end --- js/forum/dist/extension.js | 36 ++++++++++++++++++++++++++++++++++-- js/forum/src/main.js | 27 +++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/js/forum/dist/extension.js b/js/forum/dist/extension.js index eb21d6d..c27cac6 100644 --- a/js/forum/dist/extension.js +++ b/js/forum/dist/extension.js @@ -1,9 +1,9 @@ 'use strict'; -System.register('michaelbelgium/flarum-profile-views/main', ['flarum/app', 'flarum/models/User', 'flarum/components/UserCard', 'flarum/helpers/icon', 'flarum/Model', 'flarum/extend'], function (_export, _context) { +System.register('michaelbelgium/flarum-profile-views/main', ['flarum/app', 'flarum/models/User', 'flarum/components/UserCard', 'flarum/components/UserPage', 'flarum/components/FieldSet', 'flarum/helpers/icon', 'flarum/Model', 'flarum/utils/ItemList', 'flarum/helpers/avatar', 'flarum/helpers/username', 'flarum/extend'], function (_export, _context) { "use strict"; - var app, User, UserCard, icon, Model, extend; + var app, User, UserCard, UserPage, FieldSet, icon, Model, ItemList, avatar, username, extend; return { setters: [function (_flarumApp) { app = _flarumApp.default; @@ -11,10 +11,20 @@ System.register('michaelbelgium/flarum-profile-views/main', ['flarum/app', 'flar User = _flarumModelsUser.default; }, function (_flarumComponentsUserCard) { UserCard = _flarumComponentsUserCard.default; + }, function (_flarumComponentsUserPage) { + UserPage = _flarumComponentsUserPage.default; + }, function (_flarumComponentsFieldSet) { + FieldSet = _flarumComponentsFieldSet.default; }, function (_flarumHelpersIcon) { icon = _flarumHelpersIcon.default; }, function (_flarumModel) { Model = _flarumModel.default; + }, function (_flarumUtilsItemList) { + ItemList = _flarumUtilsItemList.default; + }, function (_flarumHelpersAvatar) { + avatar = _flarumHelpersAvatar.default; + }, function (_flarumHelpersUsername) { + username = _flarumHelpersUsername.default; }, function (_flarumExtend) { extend = _flarumExtend.extend; }], @@ -34,6 +44,28 @@ System.register('michaelbelgium/flarum-profile-views/main', ['flarum/app', 'flar app.translator.trans('flarum_profile_views.forum.user.views_count_text', { viewcount: user.views() }) )); }); + + extend(UserPage.prototype, 'sidebarItems', function (items) { + var lastViewed = new ItemList(); + var testUser = app.store.all('users').filter(function (user) { + return user.id() == 1; + })[0]; + console.log(testUser); + + lastViewed.add('lastUser', m( + 'a', + { href: app.forum.attribute('baseUrl') + '/u/' + testUser.id() }, + avatar(testUser, { className: 'lastUser-avatar' }), + username(testUser, { className: 'lastUser-name' }) + )); + + items.add('lastViewedUsers', FieldSet.component({ + label: 'Last viewed:', + className: 'LastUsers', + children: lastViewed.toArray() + })); + console.log(items); + }); }); } }; diff --git a/js/forum/src/main.js b/js/forum/src/main.js index afc2a10..6e4075c 100644 --- a/js/forum/src/main.js +++ b/js/forum/src/main.js @@ -1,8 +1,13 @@ import app from 'flarum/app'; import User from 'flarum/models/User'; import UserCard from 'flarum/components/UserCard'; +import UserPage from 'flarum/components/UserPage'; +import FieldSet from 'flarum/components/FieldSet'; import icon from 'flarum/helpers/icon'; import Model from 'flarum/Model'; +import ItemList from 'flarum/utils/ItemList'; +import avatar from 'flarum/helpers/avatar'; +import username from 'flarum/helpers/username'; import { extend } from 'flarum/extend'; app.initializers.add('michaelbelgium-flarum-profile-views', function() { @@ -19,4 +24,26 @@ app.initializers.add('michaelbelgium-flarum-profile-views', function() { )); }); + + extend(UserPage.prototype, 'sidebarItems', function(items) { + const lastViewed = new ItemList(); + const testUser = app.store.all('users').filter(user => user.id() == 1)[0]; + console.log(testUser); + + lastViewed.add('lastUser', + + {avatar(testUser, {className: 'lastUser-avatar'})} + {username(testUser, {className: 'lastUser-name'})} + + ); + + items.add('lastViewedUsers', + FieldSet.component({ + label: 'Last viewed:', + className: 'LastUsers', + children: lastViewed.toArray() + }) + ); + console.log(items); + }); }); \ No newline at end of file From 0f5ce48def9f9b864c709633ca268078a242a478 Mon Sep 17 00:00:00 2001 From: Michael V Date: Sat, 22 Sep 2018 22:41:02 +0200 Subject: [PATCH 02/37] Add styling --- less/extension.less | 15 +++++++++++++++ src/listeners/AddAssets.php | 5 ++++- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 less/extension.less diff --git a/less/extension.less b/less/extension.less new file mode 100644 index 0000000..470c937 --- /dev/null +++ b/less/extension.less @@ -0,0 +1,15 @@ +fieldset.LastUsers { + ul { + list-style-type: none; + padding: 0; + + .lastUser-avatar { + width: 24px; + height: 24px; + line-height: 24px; + font-size: 12px; + margin-right: 6px; + vertical-align: middle; + } + } +} \ No newline at end of file diff --git a/src/listeners/AddAssets.php b/src/listeners/AddAssets.php index eebfc10..a440dc3 100644 --- a/src/listeners/AddAssets.php +++ b/src/listeners/AddAssets.php @@ -26,7 +26,10 @@ public function configAssets(ConfigureWebApp $event) { if($event->isForum()) { - $event->addAssets(__DIR__.'/../../js/forum/dist/extension.js'); + $event->addAssets([ + __DIR__.'/../../js/forum/dist/extension.js', + __DIR__.'/../../less/extension.less' + ]); $event->addBootstrapper('michaelbelgium/flarum-profile-views/main'); } } From db8c2b87d21ae65027037987b4b4e425fb965ca1 Mon Sep 17 00:00:00 2001 From: Michael V Date: Sun, 23 Sep 2018 20:07:04 +0200 Subject: [PATCH 03/37] Use translation for label --- js/forum/dist/extension.js | 3 +-- js/forum/src/main.js | 3 +-- locale/en.yml | 3 ++- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/js/forum/dist/extension.js b/js/forum/dist/extension.js index c27cac6..6bf0cdb 100644 --- a/js/forum/dist/extension.js +++ b/js/forum/dist/extension.js @@ -60,11 +60,10 @@ System.register('michaelbelgium/flarum-profile-views/main', ['flarum/app', 'flar )); items.add('lastViewedUsers', FieldSet.component({ - label: 'Last viewed:', + label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'), className: 'LastUsers', children: lastViewed.toArray() })); - console.log(items); }); }); } diff --git a/js/forum/src/main.js b/js/forum/src/main.js index 6e4075c..6e0ab86 100644 --- a/js/forum/src/main.js +++ b/js/forum/src/main.js @@ -39,11 +39,10 @@ app.initializers.add('michaelbelgium-flarum-profile-views', function() { items.add('lastViewedUsers', FieldSet.component({ - label: 'Last viewed:', + label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'), className: 'LastUsers', children: lastViewed.toArray() }) ); - console.log(items); }); }); \ No newline at end of file diff --git a/locale/en.yml b/locale/en.yml index b137e95..756040c 100644 --- a/locale/en.yml +++ b/locale/en.yml @@ -1,4 +1,5 @@ flarum_profile_views: forum: user: - views_count_text: viewed {viewcount} times \ No newline at end of file + views_count_text: viewed {viewcount} times + title_last_viewers: Last profile viewers \ No newline at end of file From 1debfeed7066debc8fbe9391430d3c1df075240f Mon Sep 17 00:00:00 2001 From: Michael V Date: Mon, 24 Sep 2018 18:23:41 +0200 Subject: [PATCH 04/37] Add viewed_id to users_profile_views --- .../2018_09_22_210131_add_viewed_id.php | 22 +++++++++++++++++++ src/listeners/AddProfileViewHandler.php | 18 +++++++++------ 2 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 migrations/2018_09_22_210131_add_viewed_id.php diff --git a/migrations/2018_09_22_210131_add_viewed_id.php b/migrations/2018_09_22_210131_add_viewed_id.php new file mode 100644 index 0000000..decb4cf --- /dev/null +++ b/migrations/2018_09_22_210131_add_viewed_id.php @@ -0,0 +1,22 @@ + function (Builder $schema) { + $schema->table('users_profile_views', function (Blueprint $table) { + $table->string('ip', 16)->change(); + $table->integer('viewed_id')->unsigned(); + + $table->foreign("viewed_id")->references("id")->on("users")->onDelete("CASCADE")->onUpdate("CASCADE"); + }); + }, + + 'down' => function (Builder $schema) { + $schema->table('users_profile_views', function (Blueprint $table) { + $table->dropForeign(['viewed_id']); + $table->dropColumn('viewed_id'); + }); + } +]; diff --git a/src/listeners/AddProfileViewHandler.php b/src/listeners/AddProfileViewHandler.php index b8e91e3..5db49fb 100644 --- a/src/listeners/AddProfileViewHandler.php +++ b/src/listeners/AddProfileViewHandler.php @@ -28,21 +28,25 @@ public function confViews(PrepareApiData $event) $ip = $serverParams["HTTP_CF_CONNECTING_IP"]; /** @var User $profile */ - $user = $event->data; + $user = $event->actor; + $user_viewing = $event->data; $resultCount = app('flarum.db') ->table("users_profile_views") ->where("ip", $ip) - ->where("user_id", $user->id) - ->count() - ; + ->where("viewed_id", $user_viewing->id) + ->count(); if($resultCount > 0) return; - $user->views++; - $user->save(); + $user_viewing->views++; + $user_viewing->save(); - app('flarum.db')->table("users_profile_views")->insert(array("ip" => $ip, "user_id" => $user->id)); + app('flarum.db')->table("users_profile_views")->insert(array( + "ip" => $ip, + "user_id" => $user->id, + "viewed_id" => $user_viewing->id + )); } } } From 4c59f7f2fc664464f0e247e1f402823e61abf4c3 Mon Sep 17 00:00:00 2001 From: Michael V Date: Thu, 18 Oct 2018 20:04:51 +0200 Subject: [PATCH 05/37] Create profileview model eloquent/js --- js/lib/models/ProfileView.js | 10 ++++++++++ src/ProfileView.php | 12 ++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 js/lib/models/ProfileView.js create mode 100644 src/ProfileView.php diff --git a/js/lib/models/ProfileView.js b/js/lib/models/ProfileView.js new file mode 100644 index 0000000..7fe8cef --- /dev/null +++ b/js/lib/models/ProfileView.js @@ -0,0 +1,10 @@ +import Model from 'flarum/Model'; +import mixin from 'flarum/utils/mixin'; + +export default class ProfileView extends mixin(Model, { + identifier: Model.attribute('id'), + ip: Model.attribute('ip'), + viewer_id: Model.attribute('user_id'), + viewed_id: Model.attribute('viewed_id') +}) { +} \ No newline at end of file diff --git a/src/ProfileView.php b/src/ProfileView.php new file mode 100644 index 0000000..922ab69 --- /dev/null +++ b/src/ProfileView.php @@ -0,0 +1,12 @@ + Date: Thu, 18 Oct 2018 20:35:01 +0200 Subject: [PATCH 06/37] Rename column user_id to viewer_id --- js/lib/models/ProfileView.js | 2 +- migrations/2018_09_22_210131_add_viewed_id.php | 1 + src/listeners/AddProfileViewHandler.php | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/js/lib/models/ProfileView.js b/js/lib/models/ProfileView.js index 7fe8cef..1505814 100644 --- a/js/lib/models/ProfileView.js +++ b/js/lib/models/ProfileView.js @@ -4,7 +4,7 @@ import mixin from 'flarum/utils/mixin'; export default class ProfileView extends mixin(Model, { identifier: Model.attribute('id'), ip: Model.attribute('ip'), - viewer_id: Model.attribute('user_id'), + viewer_id: Model.attribute('viewer_id'), viewed_id: Model.attribute('viewed_id') }) { } \ No newline at end of file diff --git a/migrations/2018_09_22_210131_add_viewed_id.php b/migrations/2018_09_22_210131_add_viewed_id.php index decb4cf..eedcfe5 100644 --- a/migrations/2018_09_22_210131_add_viewed_id.php +++ b/migrations/2018_09_22_210131_add_viewed_id.php @@ -8,6 +8,7 @@ $schema->table('users_profile_views', function (Blueprint $table) { $table->string('ip', 16)->change(); $table->integer('viewed_id')->unsigned(); + $table->renameColumn('user_id', 'viewer_id'); $table->foreign("viewed_id")->references("id")->on("users")->onDelete("CASCADE")->onUpdate("CASCADE"); }); diff --git a/src/listeners/AddProfileViewHandler.php b/src/listeners/AddProfileViewHandler.php index 5db49fb..ffa6908 100644 --- a/src/listeners/AddProfileViewHandler.php +++ b/src/listeners/AddProfileViewHandler.php @@ -44,7 +44,7 @@ public function confViews(PrepareApiData $event) app('flarum.db')->table("users_profile_views")->insert(array( "ip" => $ip, - "user_id" => $user->id, + "viewer_id" => $user->id, "viewed_id" => $user_viewing->id )); } From ae1b428440f0567d115443253b9da1a9a9c268e7 Mon Sep 17 00:00:00 2001 From: Michael V Date: Thu, 18 Oct 2018 20:56:18 +0200 Subject: [PATCH 07/37] Add user relationship with profile views --- src/ProfileView.php | 1 + src/listeners/AddProfileViewHandler.php | 14 +++------ src/listeners/AddRelationship.php | 42 +++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 10 deletions(-) create mode 100644 src/listeners/AddRelationship.php diff --git a/src/ProfileView.php b/src/ProfileView.php index 922ab69..8f486cf 100644 --- a/src/ProfileView.php +++ b/src/ProfileView.php @@ -9,4 +9,5 @@ class ProfileView extends AbstractModel { protected $table = "users_profile_views"; + protected $fillable = ["ip", "viewer_id", "viewed_id"]; } diff --git a/src/listeners/AddProfileViewHandler.php b/src/listeners/AddProfileViewHandler.php index ffa6908..d54b575 100644 --- a/src/listeners/AddProfileViewHandler.php +++ b/src/listeners/AddProfileViewHandler.php @@ -6,6 +6,7 @@ use Illuminate\Contracts\Events\Dispatcher; use Flarum\Core\User; use Illuminate\Support\Facades\DB; +use michaelbelgium\profileviews\ProfileView; class AddProfileViewHandler { @@ -31,22 +32,15 @@ public function confViews(PrepareApiData $event) $user = $event->actor; $user_viewing = $event->data; - $resultCount = app('flarum.db') - ->table("users_profile_views") - ->where("ip", $ip) - ->where("viewed_id", $user_viewing->id) - ->count(); + $resultCount = $user_viewing->userViewers()->where("ip" , $ip)->count(); if($resultCount > 0) return; - $user_viewing->views++; - $user_viewing->save(); - - app('flarum.db')->table("users_profile_views")->insert(array( + $user_viewing->userViewers()->save(ProfileView::create([ "ip" => $ip, "viewer_id" => $user->id, "viewed_id" => $user_viewing->id - )); + ])); } } } diff --git a/src/listeners/AddRelationship.php b/src/listeners/AddRelationship.php new file mode 100644 index 0000000..41655a7 --- /dev/null +++ b/src/listeners/AddRelationship.php @@ -0,0 +1,42 @@ +listen(GetModelRelationship::class, [$this, 'getModelRelationship']); + } + + /** + * @param GetModelRelationship $event + * + * @return \Illuminate\Database\Eloquent\Relations\HasMany|null + */ + public function getModelRelationship(GetModelRelationship $event) + { + if($event->isRelationship(User::class, self::RELATIONSHIP_NAME)) + { + return $event->model->hasMany(ProfileView::class, 'viewed_id', 'id'); + } + } +} \ No newline at end of file From 9110bac6c6d543db04e4578920139ffc86e362b7 Mon Sep 17 00:00:00 2001 From: Michael V Date: Thu, 18 Oct 2018 21:02:31 +0200 Subject: [PATCH 08/37] Pass count of the hasmany relationship in stead of "views" column + removes views column --- .../2018_10_18_185757_remove_views_column.php | 18 ++++++++++++++++++ src/listeners/AddUserApiAttributes.php | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 migrations/2018_10_18_185757_remove_views_column.php diff --git a/migrations/2018_10_18_185757_remove_views_column.php b/migrations/2018_10_18_185757_remove_views_column.php new file mode 100644 index 0000000..dff5e3d --- /dev/null +++ b/migrations/2018_10_18_185757_remove_views_column.php @@ -0,0 +1,18 @@ + function (Builder $schema) { + $schema->table('users', function (Blueprint $table) { + $table->dropColumn('views'); + }); + }, + + 'down' => function (Builder $schema) { + $schema->table('users', function (Blueprint $table) { + $table->integer('views')->default(0); + }); + } +]; diff --git a/src/listeners/AddUserApiAttributes.php b/src/listeners/AddUserApiAttributes.php index 83bbd03..6fbdf2b 100644 --- a/src/listeners/AddUserApiAttributes.php +++ b/src/listeners/AddUserApiAttributes.php @@ -21,6 +21,6 @@ public function subscribe(Dispatcher $events) public function addApiAttributes(PrepareApiAttributes $event) { if ($event->isSerializer(UserSerializer::class)) - $event->attributes['views'] = $event->model->views; + $event->attributes['views'] = $event->model->userViewers()->count(); } } \ No newline at end of file From 0d663362a895a46adb66b93e899ba411d2321a4d Mon Sep 17 00:00:00 2001 From: Michael V Date: Thu, 18 Oct 2018 21:03:54 +0200 Subject: [PATCH 09/37] Subscribe to Addrelationship --- bootstrap.php | 1 + 1 file changed, 1 insertion(+) diff --git a/bootstrap.php b/bootstrap.php index a845607..164e939 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -7,4 +7,5 @@ $events->subscribe(listeners\AddProfileViewHandler::class); $events->subscribe(listeners\AddUserApiAttributes::class); $events->subscribe(listeners\AddAssets::class); + $events->subscribe(listeners\AddRelationship::class); }; \ No newline at end of file From f79e4a2b9b2f65a6ab9b638dc27a936338299ccc Mon Sep 17 00:00:00 2001 From: Michael V Date: Thu, 18 Oct 2018 21:34:53 +0200 Subject: [PATCH 10/37] Move model and serializer to a directory --- src/listeners/AddProfileViewHandler.php | 2 +- src/listeners/AddRelationship.php | 4 ++-- src/{ => models}/ProfileView.php | 4 ++-- src/serializers/ProfileViewSerializer.php | 21 +++++++++++++++++++++ 4 files changed, 26 insertions(+), 5 deletions(-) rename src/{ => models}/ProfileView.php (56%) create mode 100644 src/serializers/ProfileViewSerializer.php diff --git a/src/listeners/AddProfileViewHandler.php b/src/listeners/AddProfileViewHandler.php index d54b575..a1f8f57 100644 --- a/src/listeners/AddProfileViewHandler.php +++ b/src/listeners/AddProfileViewHandler.php @@ -6,7 +6,7 @@ use Illuminate\Contracts\Events\Dispatcher; use Flarum\Core\User; use Illuminate\Support\Facades\DB; -use michaelbelgium\profileviews\ProfileView; +use michaelbelgium\profileviews\models\ProfileView; class AddProfileViewHandler { diff --git a/src/listeners/AddRelationship.php b/src/listeners/AddRelationship.php index 41655a7..93d1a1d 100644 --- a/src/listeners/AddRelationship.php +++ b/src/listeners/AddRelationship.php @@ -7,13 +7,13 @@ use DirectoryIterator; use Flarum\Event\GetModelRelationship; use Flarum\Core\User; -use michaelbelgium\profileviews\ProfileView; +use michaelbelgium\profileviews\models\ProfileView; use Flarum\Event\GetApiRelationship; use Flarum\Api\Serializer\UserBasicSerializer; use Flarum\Event\ConfigureApiController; use Illuminate\Routing\Controller; use Flarum\Api\Controller\ShowUserController; -use michaelbelgium\profileviews\ProfileViewSerializer; +use michaelbelgium\profileviews\serializers\ProfileViewSerializer; class AddRelationship { diff --git a/src/ProfileView.php b/src/models/ProfileView.php similarity index 56% rename from src/ProfileView.php rename to src/models/ProfileView.php index 8f486cf..01bd5b0 100644 --- a/src/ProfileView.php +++ b/src/models/ProfileView.php @@ -1,6 +1,6 @@ $model->id, + 'ip' => $model->ip, + 'viewer_id' => $model->viewer_id, + 'viewed_id' => $model->viewed_id + ]; + } +} From 99534583e8c178eb40ddd56981865c4cbfa9b91c Mon Sep 17 00:00:00 2001 From: Michael V Date: Thu, 18 Oct 2018 21:50:49 +0200 Subject: [PATCH 11/37] Dont add view if the viewer equals the viewed user or if guest --- src/listeners/AddProfileViewHandler.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/listeners/AddProfileViewHandler.php b/src/listeners/AddProfileViewHandler.php index a1f8f57..929f896 100644 --- a/src/listeners/AddProfileViewHandler.php +++ b/src/listeners/AddProfileViewHandler.php @@ -7,6 +7,7 @@ use Flarum\Core\User; use Illuminate\Support\Facades\DB; use michaelbelgium\profileviews\models\ProfileView; +use Flarum\Core\Guest; class AddProfileViewHandler { @@ -28,13 +29,11 @@ public function confViews(PrepareApiData $event) if (isset($serverParams["HTTP_CF_CONNECTING_IP"])) $ip = $serverParams["HTTP_CF_CONNECTING_IP"]; - /** @var User $profile */ $user = $event->actor; $user_viewing = $event->data; - $resultCount = $user_viewing->userViewers()->where("ip" , $ip)->count(); - if($resultCount > 0) return; + if($resultCount > 0 || $user->id == $user_viewing->id || $user->isGuest()) return; $user_viewing->userViewers()->save(ProfileView::create([ "ip" => $ip, From 59be7862d322b6a83ca94848c10bd0ab25ddecc6 Mon Sep 17 00:00:00 2001 From: Michael V Date: Fri, 19 Oct 2018 11:14:29 +0200 Subject: [PATCH 12/37] Add js model in gulpfile --- js/forum/Gulpfile.js | 5 ++++- js/lib/models/ProfileView.js | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/js/forum/Gulpfile.js b/js/forum/Gulpfile.js index f264b65..546614d 100644 --- a/js/forum/Gulpfile.js +++ b/js/forum/Gulpfile.js @@ -2,6 +2,9 @@ var flarum = require('flarum-gulp'); flarum({ modules: { - 'michaelbelgium/flarum-profile-views': 'src/**/*.js' + 'michaelbelgium/flarum-profile-views': [ + 'src/**/*.js', + '../lib/**/*.js' + ] } }); \ No newline at end of file diff --git a/js/lib/models/ProfileView.js b/js/lib/models/ProfileView.js index 1505814..1f2adc5 100644 --- a/js/lib/models/ProfileView.js +++ b/js/lib/models/ProfileView.js @@ -2,7 +2,7 @@ import Model from 'flarum/Model'; import mixin from 'flarum/utils/mixin'; export default class ProfileView extends mixin(Model, { - identifier: Model.attribute('id'), + id: Model.attribute('id'), ip: Model.attribute('ip'), viewer_id: Model.attribute('viewer_id'), viewed_id: Model.attribute('viewed_id') From cf2cd1dd83c93c83f4445eac4bda80b232f3a017 Mon Sep 17 00:00:00 2001 From: Michael V Date: Fri, 19 Oct 2018 11:15:49 +0200 Subject: [PATCH 13/37] Attempt to get relationship working in js --- js/forum/dist/extension.js | 77 +++++++++++++++++++++++-------- js/forum/src/main.js | 39 +++++++++------- src/listeners/AddRelationship.php | 21 +++++++++ 3 files changed, 103 insertions(+), 34 deletions(-) diff --git a/js/forum/dist/extension.js b/js/forum/dist/extension.js index 6bf0cdb..fce7b1f 100644 --- a/js/forum/dist/extension.js +++ b/js/forum/dist/extension.js @@ -1,9 +1,9 @@ 'use strict'; -System.register('michaelbelgium/flarum-profile-views/main', ['flarum/app', 'flarum/models/User', 'flarum/components/UserCard', 'flarum/components/UserPage', 'flarum/components/FieldSet', 'flarum/helpers/icon', 'flarum/Model', 'flarum/utils/ItemList', 'flarum/helpers/avatar', 'flarum/helpers/username', 'flarum/extend'], function (_export, _context) { +System.register('michaelbelgium/flarum-profile-views/main', ['flarum/app', 'flarum/models/User', 'flarum/components/UserCard', 'flarum/components/UserPage', 'flarum/components/FieldSet', 'flarum/helpers/icon', 'flarum/Model', 'flarum/utils/ItemList', 'flarum/helpers/avatar', 'flarum/helpers/username', 'michaelbelgium/flarum-profile-views/models/ProfileView', 'flarum/extend'], function (_export, _context) { "use strict"; - var app, User, UserCard, UserPage, FieldSet, icon, Model, ItemList, avatar, username, extend; + var app, User, UserCard, UserPage, FieldSet, icon, Model, ItemList, avatar, username, ProfileView, extend; return { setters: [function (_flarumApp) { app = _flarumApp.default; @@ -25,13 +25,18 @@ System.register('michaelbelgium/flarum-profile-views/main', ['flarum/app', 'flar avatar = _flarumHelpersAvatar.default; }, function (_flarumHelpersUsername) { username = _flarumHelpersUsername.default; + }, function (_michaelbelgiumFlarumProfileViewsModelsProfileView) { + ProfileView = _michaelbelgiumFlarumProfileViewsModelsProfileView.default; }, function (_flarumExtend) { extend = _flarumExtend.extend; }], execute: function () { app.initializers.add('michaelbelgium-flarum-profile-views', function () { + app.store.models.userViews = ProfileView; + User.prototype.views = Model.attribute('views'); + User.prototype.userviews = Model.hasMany('userViewers'); extend(UserCard.prototype, 'infoItems', function (items) { var user = this.props.user; @@ -46,26 +51,62 @@ System.register('michaelbelgium/flarum-profile-views/main', ['flarum/app', 'flar }); extend(UserPage.prototype, 'sidebarItems', function (items) { - var lastViewed = new ItemList(); - var testUser = app.store.all('users').filter(function (user) { - return user.id() == 1; - })[0]; - console.log(testUser); + $.each(this.user.userviews(), function (index, element) { + console.log(index + ': ' + element); + }); + // const lastViewed = new ItemList(); + // const testUser = app.store.all('users').filter(user => user.id() == 1)[0]; + // console.log(testUser); - lastViewed.add('lastUser', m( - 'a', - { href: app.forum.attribute('baseUrl') + '/u/' + testUser.id() }, - avatar(testUser, { className: 'lastUser-avatar' }), - username(testUser, { className: 'lastUser-name' }) - )); + // lastViewed.add('lastUser', + // + // {avatar(testUser, {className: 'lastUser-avatar'})} + // {username(testUser, {className: 'lastUser-name'})} + // + // ); - items.add('lastViewedUsers', FieldSet.component({ - label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'), - className: 'LastUsers', - children: lastViewed.toArray() - })); + // items.add('lastViewedUsers', + // FieldSet.component({ + // label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'), + // className: 'LastUsers', + // children: lastViewed.toArray() + // }) + // ); }); }); } }; +});; +'use strict'; + +System.register('michaelbelgium/flarum-profile-views/models/ProfileView', ['flarum/Model', 'flarum/utils/mixin'], function (_export, _context) { + "use strict"; + + var Model, mixin, ProfileView; + return { + setters: [function (_flarumModel) { + Model = _flarumModel.default; + }, function (_flarumUtilsMixin) { + mixin = _flarumUtilsMixin.default; + }], + execute: function () { + ProfileView = function (_mixin) { + babelHelpers.inherits(ProfileView, _mixin); + + function ProfileView() { + babelHelpers.classCallCheck(this, ProfileView); + return babelHelpers.possibleConstructorReturn(this, (ProfileView.__proto__ || Object.getPrototypeOf(ProfileView)).apply(this, arguments)); + } + + return ProfileView; + }(mixin(Model, { + id: Model.attribute('id'), + ip: Model.attribute('ip'), + viewer_id: Model.attribute('viewer_id'), + viewed_id: Model.attribute('viewed_id') + })); + + _export('default', ProfileView); + } + }; }); \ No newline at end of file diff --git a/js/forum/src/main.js b/js/forum/src/main.js index 6e0ab86..5bf89df 100644 --- a/js/forum/src/main.js +++ b/js/forum/src/main.js @@ -8,10 +8,14 @@ import Model from 'flarum/Model'; import ItemList from 'flarum/utils/ItemList'; import avatar from 'flarum/helpers/avatar'; import username from 'flarum/helpers/username'; +import ProfileView from 'michaelbelgium/flarum-profile-views/models/ProfileView'; import { extend } from 'flarum/extend'; app.initializers.add('michaelbelgium-flarum-profile-views', function() { + app.store.models.userViews = ProfileView; + User.prototype.views = Model.attribute('views'); + User.prototype.userviews = Model.hasMany('userViewers'); extend(UserCard.prototype, 'infoItems', function(items) { const user = this.props.user; @@ -26,23 +30,26 @@ app.initializers.add('michaelbelgium-flarum-profile-views', function() { }); extend(UserPage.prototype, 'sidebarItems', function(items) { - const lastViewed = new ItemList(); - const testUser = app.store.all('users').filter(user => user.id() == 1)[0]; - console.log(testUser); + $.each(this.user.userviews(), function(index, element) { + console.log(index + ': ' + element); + }); + // const lastViewed = new ItemList(); + // const testUser = app.store.all('users').filter(user => user.id() == 1)[0]; + // console.log(testUser); - lastViewed.add('lastUser', - - {avatar(testUser, {className: 'lastUser-avatar'})} - {username(testUser, {className: 'lastUser-name'})} - - ); + // lastViewed.add('lastUser', + // + // {avatar(testUser, {className: 'lastUser-avatar'})} + // {username(testUser, {className: 'lastUser-name'})} + // + // ); - items.add('lastViewedUsers', - FieldSet.component({ - label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'), - className: 'LastUsers', - children: lastViewed.toArray() - }) - ); + // items.add('lastViewedUsers', + // FieldSet.component({ + // label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'), + // className: 'LastUsers', + // children: lastViewed.toArray() + // }) + // ); }); }); \ No newline at end of file diff --git a/src/listeners/AddRelationship.php b/src/listeners/AddRelationship.php index 93d1a1d..82c31ee 100644 --- a/src/listeners/AddRelationship.php +++ b/src/listeners/AddRelationship.php @@ -25,6 +25,8 @@ class AddRelationship public function subscribe(Dispatcher $events) { $events->listen(GetModelRelationship::class, [$this, 'getModelRelationship']); + $events->listen(GetApiRelationship::class, [$this, 'getApiRelationship']); + $events->listen(ConfigureApiController::class, [$this, 'configureApiController']); } /** @@ -39,4 +41,23 @@ public function getModelRelationship(GetModelRelationship $event) return $event->model->hasMany(ProfileView::class, 'viewed_id', 'id'); } } + + /** + * @param GetApiRelationship $event + */ + public function getApiRelationship(GetApiRelationship $event) + { + if($event->isRelationship(UserBasicSerializer::class, self::RELATIONSHIP_NAME)) + { + return $event->serializer->hasMany($event->model, ProfileViewSerializer::class, self::RELATIONSHIP_NAME); + } + } + + public function configureApiController(ConfigureApiController $event) + { + if($event->isController(ShowUserController::class)) + { + $event->addInclude(self::RELATIONSHIP_NAME); + } + } } \ No newline at end of file From ac282de95fc3611b5685eff5bf91c69ac856361b Mon Sep 17 00:00:00 2001 From: Michael V Date: Fri, 19 Oct 2018 15:33:05 +0200 Subject: [PATCH 14/37] Remove 'views' attribute from js, use relationship to count views --- bootstrap.php | 1 - js/forum/dist/extension.js | 4 ++-- js/forum/src/main.js | 6 +++--- src/listeners/AddUserApiAttributes.php | 26 -------------------------- 4 files changed, 5 insertions(+), 32 deletions(-) delete mode 100644 src/listeners/AddUserApiAttributes.php diff --git a/bootstrap.php b/bootstrap.php index 164e939..278b866 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -5,7 +5,6 @@ return function (Dispatcher $events) { $events->subscribe(listeners\AddProfileViewHandler::class); - $events->subscribe(listeners\AddUserApiAttributes::class); $events->subscribe(listeners\AddAssets::class); $events->subscribe(listeners\AddRelationship::class); }; \ No newline at end of file diff --git a/js/forum/dist/extension.js b/js/forum/dist/extension.js index fce7b1f..c8e85e9 100644 --- a/js/forum/dist/extension.js +++ b/js/forum/dist/extension.js @@ -35,18 +35,18 @@ System.register('michaelbelgium/flarum-profile-views/main', ['flarum/app', 'flar app.initializers.add('michaelbelgium-flarum-profile-views', function () { app.store.models.userViews = ProfileView; - User.prototype.views = Model.attribute('views'); User.prototype.userviews = Model.hasMany('userViewers'); extend(UserCard.prototype, 'infoItems', function (items) { var user = this.props.user; + var views = user.userviews() === false ? 0 : user.userviews().length; items.add('profile-views', m( 'span', null, icon('eye'), ' ', - app.translator.trans('flarum_profile_views.forum.user.views_count_text', { viewcount: user.views() }) + app.translator.trans('flarum_profile_views.forum.user.views_count_text', { viewcount: views }) )); }); diff --git a/js/forum/src/main.js b/js/forum/src/main.js index 5bf89df..e25dcc7 100644 --- a/js/forum/src/main.js +++ b/js/forum/src/main.js @@ -14,17 +14,17 @@ import { extend } from 'flarum/extend'; app.initializers.add('michaelbelgium-flarum-profile-views', function() { app.store.models.userViews = ProfileView; - User.prototype.views = Model.attribute('views'); User.prototype.userviews = Model.hasMany('userViewers'); extend(UserCard.prototype, 'infoItems', function(items) { - const user = this.props.user; + var user = this.props.user; + var views = user.userviews() === false ? 0 : user.userviews().length; items.add('profile-views',( {icon('eye')} {' '} - {app.translator.trans('flarum_profile_views.forum.user.views_count_text', {viewcount: user.views()})} + {app.translator.trans('flarum_profile_views.forum.user.views_count_text', {viewcount: views})} )); }); diff --git a/src/listeners/AddUserApiAttributes.php b/src/listeners/AddUserApiAttributes.php deleted file mode 100644 index 6fbdf2b..0000000 --- a/src/listeners/AddUserApiAttributes.php +++ /dev/null @@ -1,26 +0,0 @@ -listen(PrepareApiAttributes::class, [$this, 'addApiAttributes']); - } - - /** - * @param PrepareApiAttributes $event - */ - public function addApiAttributes(PrepareApiAttributes $event) - { - if ($event->isSerializer(UserSerializer::class)) - $event->attributes['views'] = $event->model->userViewers()->count(); - } -} \ No newline at end of file From 7f60afc55032a43428fa6c5868086cae07069acb Mon Sep 17 00:00:00 2001 From: Michael V Date: Fri, 19 Oct 2018 15:56:40 +0200 Subject: [PATCH 15/37] Fixes undefined js models --- js/forum/dist/extension.js | 11 +++++++---- js/forum/src/main.js | 12 ++++++++---- src/listeners/AddRelationship.php | 16 ++++++++++------ 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/js/forum/dist/extension.js b/js/forum/dist/extension.js index c8e85e9..ca0b427 100644 --- a/js/forum/dist/extension.js +++ b/js/forum/dist/extension.js @@ -33,7 +33,7 @@ System.register('michaelbelgium/flarum-profile-views/main', ['flarum/app', 'flar execute: function () { app.initializers.add('michaelbelgium-flarum-profile-views', function () { - app.store.models.userViews = ProfileView; + app.store.models.userViewers = ProfileView; User.prototype.userviews = Model.hasMany('userViewers'); @@ -51,9 +51,12 @@ System.register('michaelbelgium/flarum-profile-views/main', ['flarum/app', 'flar }); extend(UserPage.prototype, 'sidebarItems', function (items) { - $.each(this.user.userviews(), function (index, element) { - console.log(index + ': ' + element); - }); + if (this.user.userviews() !== false) { + $.each(this.user.userviews(), function (index, element) { + console.log(element); + }); + } + // const lastViewed = new ItemList(); // const testUser = app.store.all('users').filter(user => user.id() == 1)[0]; // console.log(testUser); diff --git a/js/forum/src/main.js b/js/forum/src/main.js index e25dcc7..7f33b5e 100644 --- a/js/forum/src/main.js +++ b/js/forum/src/main.js @@ -12,7 +12,7 @@ import ProfileView from 'michaelbelgium/flarum-profile-views/models/ProfileView' import { extend } from 'flarum/extend'; app.initializers.add('michaelbelgium-flarum-profile-views', function() { - app.store.models.userViews = ProfileView; + app.store.models.userViewers = ProfileView; User.prototype.userviews = Model.hasMany('userViewers'); @@ -30,9 +30,13 @@ app.initializers.add('michaelbelgium-flarum-profile-views', function() { }); extend(UserPage.prototype, 'sidebarItems', function(items) { - $.each(this.user.userviews(), function(index, element) { - console.log(index + ': ' + element); - }); + if(this.user.userviews() !== false) + { + $.each(this.user.userviews(), function(index, element) { + console.log(element); + }); + } + // const lastViewed = new ItemList(); // const testUser = app.store.all('users').filter(user => user.id() == 1)[0]; // console.log(testUser); diff --git a/src/listeners/AddRelationship.php b/src/listeners/AddRelationship.php index 82c31ee..00cc7e5 100644 --- a/src/listeners/AddRelationship.php +++ b/src/listeners/AddRelationship.php @@ -3,17 +3,18 @@ namespace michaelbelgium\profileviews\listeners; +use Illuminate\Routing\Controller; use Illuminate\Contracts\Events\Dispatcher; -use DirectoryIterator; -use Flarum\Event\GetModelRelationship; +use Flarum\Api\Controller\ShowUserController; +use Flarum\Api\Serializer\UserBasicSerializer; use Flarum\Core\User; -use michaelbelgium\profileviews\models\ProfileView; +use Flarum\Event\GetModelRelationship; use Flarum\Event\GetApiRelationship; -use Flarum\Api\Serializer\UserBasicSerializer; use Flarum\Event\ConfigureApiController; -use Illuminate\Routing\Controller; -use Flarum\Api\Controller\ShowUserController; +use Flarum\Event\PrepareApiData; + use michaelbelgium\profileviews\serializers\ProfileViewSerializer; +use michaelbelgium\profileviews\models\ProfileView; class AddRelationship { @@ -53,6 +54,9 @@ public function getApiRelationship(GetApiRelationship $event) } } + /** + * @param ConfigureApiController $event + */ public function configureApiController(ConfigureApiController $event) { if($event->isController(ShowUserController::class)) From 24cc30dba1b3f6de91553ba408430dd8ceb08dcb Mon Sep 17 00:00:00 2001 From: Michael V Date: Fri, 19 Oct 2018 20:33:07 +0200 Subject: [PATCH 16/37] Add relationships in ProfileView model (php) --- src/models/ProfileView.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/models/ProfileView.php b/src/models/ProfileView.php index 01bd5b0..a944d9d 100644 --- a/src/models/ProfileView.php +++ b/src/models/ProfileView.php @@ -3,6 +3,7 @@ namespace michaelbelgium\profileviews\models; use Flarum\Database\AbstractModel; +use Flarum\Core\User; class ProfileView extends AbstractModel @@ -10,4 +11,14 @@ class ProfileView extends AbstractModel protected $table = "users_profile_views"; protected $fillable = ["ip", "viewer_id", "viewed_id"]; + + public function viewer() + { + return $this->hasOne(User::class, 'id', 'viewer_id'); + } + + public function viewedUser() + { + return $this->hasOne(User::class, 'id', 'viewed_id'); + } } From 665d7de9a7224f2129dac7cc830c32d7553bbe7d Mon Sep 17 00:00:00 2001 From: Michael V Date: Fri, 19 Oct 2018 20:34:25 +0200 Subject: [PATCH 17/37] Working attempt of displaying last viewed users --- js/forum/dist/extension.js | 42 +++++++++++------------ js/forum/src/main.js | 36 +++++++++---------- js/lib/models/ProfileView.js | 4 +-- src/serializers/ProfileViewSerializer.php | 7 +--- 4 files changed, 39 insertions(+), 50 deletions(-) diff --git a/js/forum/dist/extension.js b/js/forum/dist/extension.js index ca0b427..596f80d 100644 --- a/js/forum/dist/extension.js +++ b/js/forum/dist/extension.js @@ -52,29 +52,27 @@ System.register('michaelbelgium/flarum-profile-views/main', ['flarum/app', 'flar extend(UserPage.prototype, 'sidebarItems', function (items) { if (this.user.userviews() !== false) { - $.each(this.user.userviews(), function (index, element) { - console.log(element); - }); - } + var lastViewed = new ItemList(); - // const lastViewed = new ItemList(); - // const testUser = app.store.all('users').filter(user => user.id() == 1)[0]; - // console.log(testUser); + $.each(this.user.userviews(), function (index, element) { + var viewer = app.store.all('users').filter(function (u) { + return u.id() == element.viewer(); + })[0]; - // lastViewed.add('lastUser', - // - // {avatar(testUser, {className: 'lastUser-avatar'})} - // {username(testUser, {className: 'lastUser-name'})} - // - // ); + lastViewed.add('lastUser', m( + 'a', + { href: app.forum.attribute('baseUrl') + '/u/' + viewer.id() }, + avatar(viewer, { className: 'lastUser-avatar' }), + username(viewer, { className: 'lastUser-name' }) + )); + }); - // items.add('lastViewedUsers', - // FieldSet.component({ - // label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'), - // className: 'LastUsers', - // children: lastViewed.toArray() - // }) - // ); + items.add('lastViewedUsers', FieldSet.component({ + label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'), + className: 'LastUsers', + children: lastViewed.toArray() + })); + } }); }); } @@ -105,8 +103,8 @@ System.register('michaelbelgium/flarum-profile-views/models/ProfileView', ['flar }(mixin(Model, { id: Model.attribute('id'), ip: Model.attribute('ip'), - viewer_id: Model.attribute('viewer_id'), - viewed_id: Model.attribute('viewed_id') + viewer: Model.attribute('viewer_id'), + viewed: Model.attribute('viewed_id') })); _export('default', ProfileView); diff --git a/js/forum/src/main.js b/js/forum/src/main.js index 7f33b5e..1e9b30c 100644 --- a/js/forum/src/main.js +++ b/js/forum/src/main.js @@ -32,28 +32,24 @@ app.initializers.add('michaelbelgium-flarum-profile-views', function() { extend(UserPage.prototype, 'sidebarItems', function(items) { if(this.user.userviews() !== false) { + const lastViewed = new ItemList(); + $.each(this.user.userviews(), function(index, element) { - console.log(element); + var viewer = app.store.all('users').filter(u => u.id() == element.viewer())[0]; + + lastViewed.add('lastUser', + + {avatar(viewer, {className: 'lastUser-avatar'})} + {username(viewer, {className: 'lastUser-name'})} + + ); }); - } - // const lastViewed = new ItemList(); - // const testUser = app.store.all('users').filter(user => user.id() == 1)[0]; - // console.log(testUser); - - // lastViewed.add('lastUser', - // - // {avatar(testUser, {className: 'lastUser-avatar'})} - // {username(testUser, {className: 'lastUser-name'})} - // - // ); - - // items.add('lastViewedUsers', - // FieldSet.component({ - // label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'), - // className: 'LastUsers', - // children: lastViewed.toArray() - // }) - // ); + items.add('lastViewedUsers', FieldSet.component({ + label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'), + className: 'LastUsers', + children: lastViewed.toArray() + })); + } }); }); \ No newline at end of file diff --git a/js/lib/models/ProfileView.js b/js/lib/models/ProfileView.js index 1f2adc5..f39dc62 100644 --- a/js/lib/models/ProfileView.js +++ b/js/lib/models/ProfileView.js @@ -4,7 +4,7 @@ import mixin from 'flarum/utils/mixin'; export default class ProfileView extends mixin(Model, { id: Model.attribute('id'), ip: Model.attribute('ip'), - viewer_id: Model.attribute('viewer_id'), - viewed_id: Model.attribute('viewed_id') + viewer: Model.attribute('viewer_id'), + viewed: Model.attribute('viewed_id') }) { } \ No newline at end of file diff --git a/src/serializers/ProfileViewSerializer.php b/src/serializers/ProfileViewSerializer.php index 2e21bff..863c891 100644 --- a/src/serializers/ProfileViewSerializer.php +++ b/src/serializers/ProfileViewSerializer.php @@ -11,11 +11,6 @@ class ProfileViewSerializer extends AbstractSerializer protected function getDefaultAttributes($model) { - return [ - 'id' => $model->id, - 'ip' => $model->ip, - 'viewer_id' => $model->viewer_id, - 'viewed_id' => $model->viewed_id - ]; + return $model->toArray(); } } From c39288d80a766fb2683676d242a6c20598634496 Mon Sep 17 00:00:00 2001 From: Michael V Date: Fri, 19 Oct 2018 21:00:22 +0200 Subject: [PATCH 18/37] Link with username and not id --- js/forum/dist/extension.js | 2 +- js/forum/src/main.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/js/forum/dist/extension.js b/js/forum/dist/extension.js index 596f80d..57143e3 100644 --- a/js/forum/dist/extension.js +++ b/js/forum/dist/extension.js @@ -61,7 +61,7 @@ System.register('michaelbelgium/flarum-profile-views/main', ['flarum/app', 'flar lastViewed.add('lastUser', m( 'a', - { href: app.forum.attribute('baseUrl') + '/u/' + viewer.id() }, + { href: app.forum.attribute('baseUrl') + '/u/' + viewer.username() }, avatar(viewer, { className: 'lastUser-avatar' }), username(viewer, { className: 'lastUser-name' }) )); diff --git a/js/forum/src/main.js b/js/forum/src/main.js index 1e9b30c..36d66b0 100644 --- a/js/forum/src/main.js +++ b/js/forum/src/main.js @@ -38,7 +38,7 @@ app.initializers.add('michaelbelgium-flarum-profile-views', function() { var viewer = app.store.all('users').filter(u => u.id() == element.viewer())[0]; lastViewed.add('lastUser', - + {avatar(viewer, {className: 'lastUser-avatar'})} {username(viewer, {className: 'lastUser-name'})} From 1d07a63293169c1a457772916bdb55a0f28c83f7 Mon Sep 17 00:00:00 2001 From: Michael V Date: Sat, 20 Oct 2018 16:02:22 +0200 Subject: [PATCH 19/37] Fix/add hasOne relationship in js too --- js/forum/dist/extension.js | 10 +++------- js/forum/src/main.js | 2 +- js/lib/models/ProfileView.js | 6 ++---- src/listeners/AddRelationship.php | 2 +- src/serializers/ProfileViewSerializer.php | 19 ++++++++++++++++++- 5 files changed, 25 insertions(+), 14 deletions(-) diff --git a/js/forum/dist/extension.js b/js/forum/dist/extension.js index 57143e3..8b32398 100644 --- a/js/forum/dist/extension.js +++ b/js/forum/dist/extension.js @@ -55,9 +55,7 @@ System.register('michaelbelgium/flarum-profile-views/main', ['flarum/app', 'flar var lastViewed = new ItemList(); $.each(this.user.userviews(), function (index, element) { - var viewer = app.store.all('users').filter(function (u) { - return u.id() == element.viewer(); - })[0]; + var viewer = element.viewer(); lastViewed.add('lastUser', m( 'a', @@ -101,10 +99,8 @@ System.register('michaelbelgium/flarum-profile-views/models/ProfileView', ['flar return ProfileView; }(mixin(Model, { - id: Model.attribute('id'), - ip: Model.attribute('ip'), - viewer: Model.attribute('viewer_id'), - viewed: Model.attribute('viewed_id') + viewer: Model.hasOne('userviewer'), + viewed: Model.hasOne('userviewed') })); _export('default', ProfileView); diff --git a/js/forum/src/main.js b/js/forum/src/main.js index 36d66b0..d168956 100644 --- a/js/forum/src/main.js +++ b/js/forum/src/main.js @@ -35,7 +35,7 @@ app.initializers.add('michaelbelgium-flarum-profile-views', function() { const lastViewed = new ItemList(); $.each(this.user.userviews(), function(index, element) { - var viewer = app.store.all('users').filter(u => u.id() == element.viewer())[0]; + var viewer = element.viewer(); lastViewed.add('lastUser', diff --git a/js/lib/models/ProfileView.js b/js/lib/models/ProfileView.js index f39dc62..bade5be 100644 --- a/js/lib/models/ProfileView.js +++ b/js/lib/models/ProfileView.js @@ -2,9 +2,7 @@ import Model from 'flarum/Model'; import mixin from 'flarum/utils/mixin'; export default class ProfileView extends mixin(Model, { - id: Model.attribute('id'), - ip: Model.attribute('ip'), - viewer: Model.attribute('viewer_id'), - viewed: Model.attribute('viewed_id') + viewer: Model.hasOne('userviewer'), + viewed: Model.hasOne('userviewed') }) { } \ No newline at end of file diff --git a/src/listeners/AddRelationship.php b/src/listeners/AddRelationship.php index 00cc7e5..a8468ad 100644 --- a/src/listeners/AddRelationship.php +++ b/src/listeners/AddRelationship.php @@ -61,7 +61,7 @@ public function configureApiController(ConfigureApiController $event) { if($event->isController(ShowUserController::class)) { - $event->addInclude(self::RELATIONSHIP_NAME); + $event->addInclude([self::RELATIONSHIP_NAME, self::RELATIONSHIP_NAME.'.userviewer', self::RELATIONSHIP_NAME.'.userviewed']); } } } \ No newline at end of file diff --git a/src/serializers/ProfileViewSerializer.php b/src/serializers/ProfileViewSerializer.php index 863c891..2bcd857 100644 --- a/src/serializers/ProfileViewSerializer.php +++ b/src/serializers/ProfileViewSerializer.php @@ -4,6 +4,7 @@ use Flarum\Api\Serializer\AbstractSerializer; use michaelbelgium\profileviews\listeners\AddRelationship; +use Flarum\Api\Serializer\UserSerializer; class ProfileViewSerializer extends AbstractSerializer { @@ -11,6 +12,22 @@ class ProfileViewSerializer extends AbstractSerializer protected function getDefaultAttributes($model) { - return $model->toArray(); + return []; + } + + /** + * Needs to be added in AddRelationship.php > configureApiController too + */ + protected function userviewer($profileview) + { + return $this->hasOne($profileview, UserSerializer::class, 'viewer_id'); + } + + /** + * Needs to be added in AddRelationship.php > configureApiController too + */ + protected function userviewed($profileview) + { + return $this->hasOne($profileview, UserSerializer::class, 'viewed_id'); } } From 48b4d0a7403f5dfdebbe4a29861918f5140399ad Mon Sep 17 00:00:00 2001 From: Michael V Date: Sun, 2 Dec 2018 17:28:38 +0100 Subject: [PATCH 20/37] Add relationship on frontend --- extend.php | 6 ----- js/src/forum/index.js | 4 +-- .../AddUserProfileViewsRelationship.php | 26 +++++++++++++++++++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/extend.php b/extend.php index 35766f4..dfe4c8a 100644 --- a/extend.php +++ b/extend.php @@ -16,11 +16,5 @@ function (Dispatcher $events) { $events->subscribe(listeners\AddProfileViewHandler::class); $events->subscribe(listeners\AddUserProfileViewsRelationship::class); - - $events->listen(Serializing::class, function (Serializing $event) { - if ($event->isSerializer(UserSerializer::class)) { - $event->attributes['views'] = $event->model->profileViews()->count(); - } - }); } ]; \ No newline at end of file diff --git a/js/src/forum/index.js b/js/src/forum/index.js index eb2f3ce..b711cee 100644 --- a/js/src/forum/index.js +++ b/js/src/forum/index.js @@ -7,7 +7,7 @@ import Model from 'flarum/Model'; import { extend } from 'flarum/extend'; app.initializers.add('michaelbelgium-flarum-profile-views', function() { - User.prototype.views = Model.attribute('views'); + User.prototype.profileViews = Model.hasMany('profileViews'); extend(UserCard.prototype, 'infoItems', function(items) { const user = this.props.user; @@ -16,7 +16,7 @@ app.initializers.add('michaelbelgium-flarum-profile-views', function() { {icon('far fa-eye')} {' '} - {app.translator.trans('flarum_profile_views.forum.user.views_count_text', {viewcount: user.views() == 0 ? '0' : user.views()})} + {app.translator.trans('flarum_profile_views.forum.user.views_count_text', {viewcount: '' + user.profileViews().length})} )); }); diff --git a/src/listeners/AddUserProfileViewsRelationship.php b/src/listeners/AddUserProfileViewsRelationship.php index c211386..1bb9351 100644 --- a/src/listeners/AddUserProfileViewsRelationship.php +++ b/src/listeners/AddUserProfileViewsRelationship.php @@ -2,8 +2,12 @@ namespace michaelbelgium\profileviews\listeners; use Illuminate\Contracts\Events\Dispatcher; +use Flarum\Event\GetApiRelationship; use Flarum\Event\GetModelRelationship; use Flarum\User\User; +use Flarum\Api\Event\WillGetData; +use Flarum\Api\Serializer\UserSerializer; +use Flarum\Api\Controller\ShowUserController; class AddUserProfileViewsRelationship { @@ -15,7 +19,9 @@ class AddUserProfileViewsRelationship */ public function subscribe(Dispatcher $events) { + $events->listen(WillGetData::class, [$this, 'includeTagsRelationship']); $events->listen(GetModelRelationship::class, [$this, 'getModelRelationship']); + $events->listen(GetApiRelationship::class, [$this, 'GetApiRelationship']); } public function getModelRelationship(GetModelRelationship $event) @@ -30,4 +36,24 @@ public function getModelRelationship(GetModelRelationship $event) return $event->model->belongsToMany(User::class, 'user_profile_views', 'viewer_id', 'viewed_user_id')->withPivot('ip'); } } + + /** + * @param GetApiRelationship $event + * @return \Tobscure\JsonApi\Relationship|null + */ + public function getApiRelationship(GetApiRelationship $event) + { + if ($event->isRelationship(UserSerializer::class, self::RELATIONSHIP)) { + return $event->serializer->hasMany($event->model, UserSerializer::class, self::RELATIONSHIP); + } + } + + /** + * @param WillGetData $event + */ + public function includeTagsRelationship(WillGetData $event) + { + if ($event->isController(ShowUserController::class)) + $event->addInclude([self::RELATIONSHIP, self::RELATIONSHIP_OTHER]); + } } \ No newline at end of file From 817156da96549a7d027b396b5a2b381097ca751d Mon Sep 17 00:00:00 2001 From: Michael V Date: Sun, 2 Dec 2018 17:55:44 +0100 Subject: [PATCH 21/37] Display latest viewers --- extend.php | 5 ++--- js/dist/forum.js | 2 +- js/dist/forum.js.map | 2 +- js/src/forum/index.js | 36 ++++++++++++++++++------------------ 4 files changed, 22 insertions(+), 23 deletions(-) diff --git a/extend.php b/extend.php index dfe4c8a..f55f40d 100644 --- a/extend.php +++ b/extend.php @@ -2,14 +2,13 @@ use michaelbelgium\profileviews\listeners; use Illuminate\Contracts\Events\Dispatcher; -use Flarum\Api\Serializer\UserSerializer; -use Flarum\Api\Event\Serializing; use Flarum\Extend\Locales; use Flarum\Extend\Frontend; return [ (new Frontend('forum')) - ->js(__DIR__. '/js/dist/forum.js'), + ->js(__DIR__. '/js/dist/forum.js') + ->css(__DIR__. '/less/extension.less'), new Locales(__DIR__ . '/locale'), diff --git a/js/dist/forum.js b/js/dist/forum.js index 2a275a3..0eb4e7a 100644 --- a/js/dist/forum.js +++ b/js/dist/forum.js @@ -1,2 +1,2 @@ -module.exports=function(e){var t={};function r(o){if(t[o])return t[o].exports;var n=t[o]={i:o,l:!1,exports:{}};return e[o].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.m=e,r.c=t,r.d=function(e,t,o){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(r.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)r.d(o,n,function(t){return e[t]}.bind(null,n));return o},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=7)}([function(e,t){e.exports=flarum.core.compat.app},function(e,t){e.exports=flarum.core.compat.extend},function(e,t){e.exports=flarum.core.compat["models/User"]},function(e,t){e.exports=flarum.core.compat["components/UserPage"]},function(e,t){e.exports=flarum.core.compat["components/UserCard"]},function(e,t){e.exports=flarum.core.compat["helpers/icon"]},function(e,t){e.exports=flarum.core.compat.Model},function(e,t,r){"use strict";r.r(t);var o=r(0),n=r.n(o),u=r(2),i=r.n(u),a=r(3),c=r.n(a),f=r(4),p=r.n(f),s=r(5),l=r.n(s),d=r(6),v=r.n(d),b=r(1);n.a.initializers.add("michaelbelgium-flarum-profile-views",function(){i.a.prototype.views=v.a.attribute("views"),Object(b.extend)(p.a.prototype,"infoItems",function(e){var t=this.props.user;e.add("profile-views",m("span",null,l()("far fa-eye")," ",n.a.translator.trans("flarum_profile_views.forum.user.views_count_text",{viewcount:0==t.views()?"0":t.views()})))}),Object(b.extend)(c.a.prototype,"sidebarItems",function(e){})})}]); +module.exports=function(e){var r={};function t(o){if(r[o])return r[o].exports;var n=r[o]={i:o,l:!1,exports:{}};return e[o].call(n.exports,n,n.exports,t),n.l=!0,n.exports}return t.m=e,t.c=r,t.d=function(e,r,o){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:o})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(t.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)t.d(o,n,function(r){return e[r]}.bind(null,n));return o},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=11)}([function(e,r){e.exports=flarum.core.compat.app},function(e,r){e.exports=flarum.core.compat.extend},function(e,r){e.exports=flarum.core.compat["models/User"]},function(e,r){e.exports=flarum.core.compat["components/UserPage"]},function(e,r){e.exports=flarum.core.compat["components/UserCard"]},function(e,r){e.exports=flarum.core.compat["components/FieldSet"]},function(e,r){e.exports=flarum.core.compat["helpers/icon"]},function(e,r){e.exports=flarum.core.compat["helpers/avatar"]},function(e,r){e.exports=flarum.core.compat["helpers/username"]},function(e,r){e.exports=flarum.core.compat.Model},function(e,r){e.exports=flarum.core.compat["utils/ItemList"]},function(e,r,t){"use strict";t.r(r);var o=t(0),n=t.n(o),a=t(2),s=t.n(a),u=t(3),i=t.n(u),c=t(4),l=t.n(c),f=t(5),p=t.n(f),d=t(6),x=t.n(d),b=t(7),v=t.n(b),y=t(8),w=t.n(y),_=t(9),h=t.n(_),g=t(10),j=t.n(g),O=t(1);n.a.initializers.add("michaelbelgium-flarum-profile-views",function(){s.a.prototype.profileViews=h.a.hasMany("profileViews"),Object(O.extend)(l.a.prototype,"infoItems",function(e){var r=this.props.user;e.add("profile-views",m("span",null,x()("far fa-eye")," ",n.a.translator.trans("flarum_profile_views.forum.user.views_count_text",{viewcount:""+r.profileViews().length})))}),Object(O.extend)(i.a.prototype,"sidebarItems",function(e){var r=new j.a;$.each(this.user.profileViews(),function(e,t){r.add("lastUser-"+t.id(),m("a",{href:n.a.forum.attribute("baseUrl")+"/u/"+t.username()},v()(t,{className:"lastUser-avatar"}),w()(t,{className:"lastUser-name"})))}),e.add("lastViewedUsers",p.a.component({label:n.a.translator.trans("flarum_profile_views.forum.user.title_last_viewers"),className:"LastUsers",children:r.toArray()}))})})}]); //# sourceMappingURL=forum.js.map \ No newline at end of file diff --git a/js/dist/forum.js.map b/js/dist/forum.js.map index af11657..ec7a3ae 100644 --- a/js/dist/forum.js.map +++ b/js/dist/forum.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack://@michaelbelgium/flarum-profile-views/webpack/bootstrap","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['app']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['extend']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['models/User']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/UserPage']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/UserCard']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/icon']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['Model']\"","webpack://@michaelbelgium/flarum-profile-views/./src/forum/index.js"],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","flarum","core","compat","app","initializers","add","User","views","Model","attribute","extend","UserCard","items","user","this","props","icon","translator","trans","viewcount","UserPage"],"mappings":"2BACA,IAAAA,EAAA,GAGA,SAAAC,EAAAC,GAGA,GAAAF,EAAAE,GACA,OAAAF,EAAAE,GAAAC,QAGA,IAAAC,EAAAJ,EAAAE,GAAA,CACAG,EAAAH,EACAI,GAAA,EACAH,QAAA,IAUA,OANAI,EAAAL,GAAAM,KAAAJ,EAAAD,QAAAC,IAAAD,QAAAF,GAGAG,EAAAE,GAAA,EAGAF,EAAAD,QA0DA,OArDAF,EAAAQ,EAAAF,EAGAN,EAAAS,EAAAV,EAGAC,EAAAU,EAAA,SA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C,OAAA,+BCAAnC,EAAAD,QAAAkC,OAAAC,KAAAC,OAAA,sJCQAC,IAAIC,aAAaC,IAAI,sCAAuC,WACxDC,IAAKV,UAAUW,MAAQC,IAAMC,UAAU,SAEvCC,iBAAOC,IAASf,UAAW,YAAa,SAASgB,GAC7C,IAAMC,EAAOC,KAAKC,MAAMF,KAExBD,EAAMP,IAAI,gBACNjC,EAAA,YACK4C,IAAK,cACL,IACAb,IAAIc,WAAWC,MAAM,mDAAoD,CAACC,UAA2B,GAAhBN,EAAKN,QAAe,IAAMM,EAAKN,cAKjIG,iBAAOU,IAASxB,UAAW,eAAgB,SAASgB","file":"forum.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 7);\n","module.exports = flarum.core.compat['app'];","module.exports = flarum.core.compat['extend'];","module.exports = flarum.core.compat['models/User'];","module.exports = flarum.core.compat['components/UserPage'];","module.exports = flarum.core.compat['components/UserCard'];","module.exports = flarum.core.compat['helpers/icon'];","module.exports = flarum.core.compat['Model'];","import app from 'flarum/app';\nimport User from 'flarum/models/User';\nimport UserPage from 'flarum/components/UserPage';\nimport UserCard from 'flarum/components/UserCard';\nimport icon from 'flarum/helpers/icon';\nimport Model from 'flarum/Model';\nimport { extend } from 'flarum/extend';\n\napp.initializers.add('michaelbelgium-flarum-profile-views', function() {\n User.prototype.views = Model.attribute('views');\n\n extend(UserCard.prototype, 'infoItems', function(items) {\n const user = this.props.user;\n\n items.add('profile-views',(\n \n {icon('far fa-eye')}\n {' '}\n {app.translator.trans('flarum_profile_views.forum.user.views_count_text', {viewcount: user.views() == 0 ? '0' : user.views()})}\n \n ));\n });\n\n extend(UserPage.prototype, 'sidebarItems', function(items) {\n // if(this.user.userviews() !== false)\n // {\n // const lastViewed = new ItemList();\n\n // $.each(this.user.userviews(), function(index, element) {\n // var viewer = element.viewer();\n\n // lastViewed.add('lastUser', \n // \n // {avatar(viewer, {className: 'lastUser-avatar'})}\n // {username(viewer, {className: 'lastUser-name'})}\n // \n // );\n // });\n\n // items.add('lastViewedUsers', FieldSet.component({\n // label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'),\n // className: 'LastUsers',\n // children: lastViewed.toArray()\n // }));\n // }\n });\n});"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack://@michaelbelgium/flarum-profile-views/webpack/bootstrap","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['app']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['extend']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['models/User']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/UserPage']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/UserCard']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/FieldSet']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/icon']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/avatar']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/username']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['Model']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['utils/ItemList']\"","webpack://@michaelbelgium/flarum-profile-views/./src/forum/index.js"],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","flarum","core","compat","app","initializers","add","User","profileViews","Model","hasMany","extend","UserCard","items","user","this","props","icon","translator","trans","viewcount","length","UserPage","lastViewed","ItemList","$","each","index","viewer","id","href","forum","attribute","username","avatar","className","FieldSet","component","label","children","toArray"],"mappings":"2BACA,IAAAA,EAAA,GAGA,SAAAC,EAAAC,GAGA,GAAAF,EAAAE,GACA,OAAAF,EAAAE,GAAAC,QAGA,IAAAC,EAAAJ,EAAAE,GAAA,CACAG,EAAAH,EACAI,GAAA,EACAH,QAAA,IAUA,OANAI,EAAAL,GAAAM,KAAAJ,EAAAD,QAAAC,IAAAD,QAAAF,GAGAG,EAAAE,GAAA,EAGAF,EAAAD,QA0DA,OArDAF,EAAAQ,EAAAF,EAGAN,EAAAS,EAAAV,EAGAC,EAAAU,EAAA,SAAAR,EAAAS,EAAAC,GACAZ,EAAAa,EAAAX,EAAAS,IACAG,OAAAC,eAAAb,EAAAS,EAAA,CAA0CK,YAAA,EAAAC,IAAAL,KAK1CZ,EAAAkB,EAAA,SAAAhB,GACA,oBAAAiB,eAAAC,aACAN,OAAAC,eAAAb,EAAAiB,OAAAC,YAAA,CAAwDC,MAAA,WAExDP,OAAAC,eAAAb,EAAA,cAAiDmB,OAAA,KAQjDrB,EAAAsB,EAAA,SAAAD,EAAAE,GAEA,GADA,EAAAA,IAAAF,EAAArB,EAAAqB,IACA,EAAAE,EAAA,OAAAF,EACA,KAAAE,GAAA,iBAAAF,QAAAG,WAAA,OAAAH,EACA,IAAAI,EAAAX,OAAAY,OAAA,MAGA,GAFA1B,EAAAkB,EAAAO,GACAX,OAAAC,eAAAU,EAAA,WAAyCT,YAAA,EAAAK,UACzC,EAAAE,GAAA,iBAAAF,EAAA,QAAAM,KAAAN,EAAArB,EAAAU,EAAAe,EAAAE,EAAA,SAAAA,GAAgH,OAAAN,EAAAM,IAAqBC,KAAA,KAAAD,IACrI,OAAAF,GAIAzB,EAAA6B,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xD,EAAA,KAAGyD,KAAM1B,IAAI2B,MAAMC,UAAU,WAAa,MAAQJ,EAAOK,YACpDC,IAAON,EAAQ,CAACO,UAAW,oBAC3BF,IAASL,EAAQ,CAACO,UAAW,sBAK1CtB,EAAMP,IAAI,kBAAmB8B,IAASC,UAAU,CAC5CC,MAAOlC,IAAIc,WAAWC,MAAM,sDAC5BgB,UAAW,YACXI,SAAUhB,EAAWiB","file":"forum.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 11);\n","module.exports = flarum.core.compat['app'];","module.exports = flarum.core.compat['extend'];","module.exports = flarum.core.compat['models/User'];","module.exports = flarum.core.compat['components/UserPage'];","module.exports = flarum.core.compat['components/UserCard'];","module.exports = flarum.core.compat['components/FieldSet'];","module.exports = flarum.core.compat['helpers/icon'];","module.exports = flarum.core.compat['helpers/avatar'];","module.exports = flarum.core.compat['helpers/username'];","module.exports = flarum.core.compat['Model'];","module.exports = flarum.core.compat['utils/ItemList'];","import app from 'flarum/app';\nimport User from 'flarum/models/User';\nimport UserPage from 'flarum/components/UserPage';\nimport UserCard from 'flarum/components/UserCard';\nimport FieldSet from 'flarum/components/FieldSet';\nimport icon from 'flarum/helpers/icon';\nimport avatar from 'flarum/helpers/avatar';\nimport username from 'flarum/helpers/username';\nimport Model from 'flarum/Model';\nimport ItemList from 'flarum/utils/ItemList';\nimport { extend } from 'flarum/extend';\n\napp.initializers.add('michaelbelgium-flarum-profile-views', function() {\n User.prototype.profileViews = Model.hasMany('profileViews');\n\n extend(UserCard.prototype, 'infoItems', function(items) {\n const user = this.props.user;\n\n items.add('profile-views',(\n \n {icon('far fa-eye')}\n {' '}\n {app.translator.trans('flarum_profile_views.forum.user.views_count_text', {viewcount: '' + user.profileViews().length})}\n \n ));\n });\n\n extend(UserPage.prototype, 'sidebarItems', function(items) {\n const lastViewed = new ItemList();\n\n $.each(this.user.profileViews(), function(index, viewer) {\n\n lastViewed.add('lastUser-' + viewer.id(),\n \n {avatar(viewer, {className: 'lastUser-avatar'})}\n {username(viewer, {className: 'lastUser-name'})}\n \n );\n });\n\n items.add('lastViewedUsers', FieldSet.component({\n label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'),\n className: 'LastUsers',\n children: lastViewed.toArray()\n }));\n });\n});"],"sourceRoot":""} \ No newline at end of file diff --git a/js/src/forum/index.js b/js/src/forum/index.js index b711cee..18ca13e 100644 --- a/js/src/forum/index.js +++ b/js/src/forum/index.js @@ -2,8 +2,12 @@ import app from 'flarum/app'; import User from 'flarum/models/User'; import UserPage from 'flarum/components/UserPage'; import UserCard from 'flarum/components/UserCard'; +import FieldSet from 'flarum/components/FieldSet'; import icon from 'flarum/helpers/icon'; +import avatar from 'flarum/helpers/avatar'; +import username from 'flarum/helpers/username'; import Model from 'flarum/Model'; +import ItemList from 'flarum/utils/ItemList'; import { extend } from 'flarum/extend'; app.initializers.add('michaelbelgium-flarum-profile-views', function() { @@ -22,26 +26,22 @@ app.initializers.add('michaelbelgium-flarum-profile-views', function() { }); extend(UserPage.prototype, 'sidebarItems', function(items) { - // if(this.user.userviews() !== false) - // { - // const lastViewed = new ItemList(); + const lastViewed = new ItemList(); - // $.each(this.user.userviews(), function(index, element) { - // var viewer = element.viewer(); + $.each(this.user.profileViews(), function(index, viewer) { - // lastViewed.add('lastUser', - // - // {avatar(viewer, {className: 'lastUser-avatar'})} - // {username(viewer, {className: 'lastUser-name'})} - // - // ); - // }); + lastViewed.add('lastUser-' + viewer.id(), + + {avatar(viewer, {className: 'lastUser-avatar'})} + {username(viewer, {className: 'lastUser-name'})} + + ); + }); - // items.add('lastViewedUsers', FieldSet.component({ - // label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'), - // className: 'LastUsers', - // children: lastViewed.toArray() - // })); - // } + items.add('lastViewedUsers', FieldSet.component({ + label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'), + className: 'LastUsers', + children: lastViewed.toArray() + })); }); }); \ No newline at end of file From 3350771156941554978c4692e3eef54b0adbda38 Mon Sep 17 00:00:00 2001 From: Michael V Date: Mon, 3 Dec 2018 18:15:29 +0100 Subject: [PATCH 22/37] Add feature --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3b4d404..ff6347b 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,8 @@ php flarum cache:clear # Features * Tracks and displays **unique** profileviews in the usercard +* Displays a list of last viewers on a user profile # Media -![image](http://puu.sh/yxd7o.png) +![image](http://puu.sh/yxd7o.png) \ No newline at end of file From 8c41bb74e88694450297cb67e0fc666a498ed610 Mon Sep 17 00:00:00 2001 From: Michael V Date: Thu, 6 Dec 2018 23:26:32 +0100 Subject: [PATCH 23/37] Add profile view via javascript Detecting client side is more accurate. Extending the show method of a UserPage, then making a post request and handle the request in the controller. --- extend.php | 11 ++++-- js/dist/forum.js | 2 +- js/dist/forum.js.map | 2 +- js/src/forum/index.js | 13 ++++++- .../CreateUserProfileViewController.php | 31 +++++++++++++++ src/listeners/AddProfileViewHandler.php | 38 ------------------- 6 files changed, 52 insertions(+), 45 deletions(-) create mode 100644 src/controllers/CreateUserProfileViewController.php delete mode 100644 src/listeners/AddProfileViewHandler.php diff --git a/extend.php b/extend.php index f55f40d..f3e1682 100644 --- a/extend.php +++ b/extend.php @@ -1,9 +1,10 @@ post('/profileview/{id}', 'profileview.add', CreateUserProfileViewController::class), + function (Dispatcher $events) { - $events->subscribe(listeners\AddProfileViewHandler::class); - $events->subscribe(listeners\AddUserProfileViewsRelationship::class); + $events->subscribe(AddUserProfileViewsRelationship::class); } ]; \ No newline at end of file diff --git a/js/dist/forum.js b/js/dist/forum.js index 0eb4e7a..3c75d63 100644 --- a/js/dist/forum.js +++ b/js/dist/forum.js @@ -1,2 +1,2 @@ -module.exports=function(e){var r={};function t(o){if(r[o])return r[o].exports;var n=r[o]={i:o,l:!1,exports:{}};return e[o].call(n.exports,n,n.exports,t),n.l=!0,n.exports}return t.m=e,t.c=r,t.d=function(e,r,o){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:o})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(t.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)t.d(o,n,function(r){return e[r]}.bind(null,n));return o},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=11)}([function(e,r){e.exports=flarum.core.compat.app},function(e,r){e.exports=flarum.core.compat.extend},function(e,r){e.exports=flarum.core.compat["models/User"]},function(e,r){e.exports=flarum.core.compat["components/UserPage"]},function(e,r){e.exports=flarum.core.compat["components/UserCard"]},function(e,r){e.exports=flarum.core.compat["components/FieldSet"]},function(e,r){e.exports=flarum.core.compat["helpers/icon"]},function(e,r){e.exports=flarum.core.compat["helpers/avatar"]},function(e,r){e.exports=flarum.core.compat["helpers/username"]},function(e,r){e.exports=flarum.core.compat.Model},function(e,r){e.exports=flarum.core.compat["utils/ItemList"]},function(e,r,t){"use strict";t.r(r);var o=t(0),n=t.n(o),a=t(2),s=t.n(a),u=t(3),i=t.n(u),c=t(4),l=t.n(c),f=t(5),p=t.n(f),d=t(6),x=t.n(d),b=t(7),v=t.n(b),y=t(8),w=t.n(y),_=t(9),h=t.n(_),g=t(10),j=t.n(g),O=t(1);n.a.initializers.add("michaelbelgium-flarum-profile-views",function(){s.a.prototype.profileViews=h.a.hasMany("profileViews"),Object(O.extend)(l.a.prototype,"infoItems",function(e){var r=this.props.user;e.add("profile-views",m("span",null,x()("far fa-eye")," ",n.a.translator.trans("flarum_profile_views.forum.user.views_count_text",{viewcount:""+r.profileViews().length})))}),Object(O.extend)(i.a.prototype,"sidebarItems",function(e){var r=new j.a;$.each(this.user.profileViews(),function(e,t){r.add("lastUser-"+t.id(),m("a",{href:n.a.forum.attribute("baseUrl")+"/u/"+t.username()},v()(t,{className:"lastUser-avatar"}),w()(t,{className:"lastUser-name"})))}),e.add("lastViewedUsers",p.a.component({label:n.a.translator.trans("flarum_profile_views.forum.user.title_last_viewers"),className:"LastUsers",children:r.toArray()}))})})}]); +module.exports=function(e){var r={};function t(o){if(r[o])return r[o].exports;var n=r[o]={i:o,l:!1,exports:{}};return e[o].call(n.exports,n,n.exports,t),n.l=!0,n.exports}return t.m=e,t.c=r,t.d=function(e,r,o){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:o})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(t.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)t.d(o,n,function(r){return e[r]}.bind(null,n));return o},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=11)}([function(e,r){e.exports=flarum.core.compat.app},function(e,r){e.exports=flarum.core.compat.extend},function(e,r){e.exports=flarum.core.compat["components/UserPage"]},function(e,r){e.exports=flarum.core.compat["models/User"]},function(e,r){e.exports=flarum.core.compat["components/UserCard"]},function(e,r){e.exports=flarum.core.compat["components/FieldSet"]},function(e,r){e.exports=flarum.core.compat["helpers/icon"]},function(e,r){e.exports=flarum.core.compat["helpers/avatar"]},function(e,r){e.exports=flarum.core.compat["helpers/username"]},function(e,r){e.exports=flarum.core.compat.Model},function(e,r){e.exports=flarum.core.compat["utils/ItemList"]},function(e,r,t){"use strict";t.r(r);var o=t(0),n=t.n(o),a=t(3),s=t.n(a),i=t(2),u=t.n(i),l=t(4),c=t.n(l),f=t(5),p=t.n(f),d=t(6),v=t.n(d),b=t(7),x=t.n(b),y=t(8),w=t.n(y),h=t(9),_=t.n(h),O=t(10),j=t.n(O),U=t(1);n.a.initializers.add("michaelbelgium-flarum-profile-views",function(){s.a.prototype.profileViews=_.a.hasMany("profileViews"),Object(U.extend)(c.a.prototype,"infoItems",function(e){var r=this.props.user;e.add("profile-views",m("span",null,v()("far fa-eye")," ",n.a.translator.trans("flarum_profile_views.forum.user.views_count_text",{viewcount:""+(!1===r.profileViews()?"0":r.profileViews().length)})))}),Object(U.extend)(u.a.prototype,"sidebarItems",function(e){var r=new j.a;$.each(this.user.profileViews(),function(e,t){r.add("lastUser-"+t.id(),m("a",{href:n.a.forum.attribute("baseUrl")+"/u/"+t.username()},x()(t,{className:"lastUser-avatar"}),w()(t,{className:"lastUser-name"})))}),e.add("lastViewedUsers",p.a.component({label:n.a.translator.trans("flarum_profile_views.forum.user.title_last_viewers"),className:"LastUsers",children:r.toArray()}))}),Object(U.extend)(u.a.prototype,"show",function(){void 0!==n.a.session.user&&n.a.session.user.id()!==this.user.id()&&n.a.request({method:"POST",url:n.a.forum.attribute("apiUrl")+"/profileview/"+this.user.id(),data:{viewer:n.a.session.user.id()}})})})}]); //# sourceMappingURL=forum.js.map \ No newline at end of file diff --git a/js/dist/forum.js.map b/js/dist/forum.js.map index ec7a3ae..cffb320 100644 --- a/js/dist/forum.js.map +++ b/js/dist/forum.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack://@michaelbelgium/flarum-profile-views/webpack/bootstrap","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['app']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['extend']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['models/User']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/UserPage']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/UserCard']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/FieldSet']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/icon']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/avatar']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/username']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['Model']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['utils/ItemList']\"","webpack://@michaelbelgium/flarum-profile-views/./src/forum/index.js"],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","flarum","core","compat","app","initializers","add","User","profileViews","Model","hasMany","extend","UserCard","items","user","this","props","icon","translator","trans","viewcount","length","UserPage","lastViewed","ItemList","$","each","index","viewer","id","href","forum","attribute","username","avatar","className","FieldSet","component","label","children","toArray"],"mappings":"2BACA,IAAAA,EAAA,GAGA,SAAAC,EAAAC,GAGA,GAAAF,EAAAE,GACA,OAAAF,EAAAE,GAAAC,QAGA,IAAAC,EAAAJ,EAAAE,GAAA,CACAG,EAAAH,EACAI,GAAA,EACAH,QAAA,IAUA,OANAI,EAAAL,GAAAM,KAAAJ,EAAAD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AA,8BCAAnC,EAAAD,QAAAkC,OAAAC,KAAAC,OAAA,sCCAAnC,EAAAD,QAAAkC,OAAAC,KAAAC,OAAA,sCCAAnC,EAAAD,QAAAkC,OAAAC,KAAAC,OAAA,sCCAAnC,EAAAD,QAAAkC,OAAAC,KAAAC,OAAA,+BCAAnC,EAAAD,QAAAkC,OAAAC,KAAAC,OAAA,iCCAAnC,EAAAD,QAAAkC,OAAAC,KAAAC,OAAA,mCCAAnC,EAAAD,QAAAkC,OAAAC,KAAAC,OAAA,qBCAAnC,EAAAD,QAAAkC,OAAAC,KAAAC,OAAA,mOCYAC,IAAIC,aAAaC,IAAI,sCAAuC,WACxDC,IAAKV,UAAUW,aAAeC,IAAMC,QAAQ,gBAE5CC,iBAAOC,IAASf,UAAW,YAAa,SAASgB,GAC7C,IAAMC,EAAOC,KAAKC,MAAMF,KAExBD,EAAMP,IAAI,gBACNjC,EAAA,YACK4C,IAAK,cACL,IACAb,IAAIc,WAAWC,MAAM,mDAAoD,CAACC,UAAW,GAAKN,EAAKN,eAAea,aAK3HV,iBAAOW,IAASzB,UAAW,eAAgB,SAASgB,GAChD,IAAMU,EAAa,IAAIC,IAEvBC,EAAEC,KAAKX,KAAKD,KAAKN,eAAgB,SAASmB,EAAOC,GAE7CL,EAAWjB,IAAI,YAAcsB,EAAOC,KAChCxD,EAAA,KAAGyD,KAAM1B,IAAI2B,MAAMC,UAAU,WAAa,MAAQJ,EAAOK,YACpDC,IAAON,EAAQ,CAACO,UAAW,oBAC3BF,IAASL,EAAQ,CAACO,UAAW,sBAK1CtB,EAAMP,IAAI,kBAAmB8B,IAASC,UAAU,CAC5CC,MAAOlC,IAAIc,WAAWC,MAAM,sDAC5BgB,UAAW,YACXI,SAAUhB,EAAWiB","file":"forum.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 11);\n","module.exports = flarum.core.compat['app'];","module.exports = flarum.core.compat['extend'];","module.exports = flarum.core.compat['models/User'];","module.exports = flarum.core.compat['components/UserPage'];","module.exports = flarum.core.compat['components/UserCard'];","module.exports = flarum.core.compat['components/FieldSet'];","module.exports = flarum.core.compat['helpers/icon'];","module.exports = flarum.core.compat['helpers/avatar'];","module.exports = flarum.core.compat['helpers/username'];","module.exports = flarum.core.compat['Model'];","module.exports = flarum.core.compat['utils/ItemList'];","import app from 'flarum/app';\nimport User from 'flarum/models/User';\nimport UserPage from 'flarum/components/UserPage';\nimport UserCard from 'flarum/components/UserCard';\nimport FieldSet from 'flarum/components/FieldSet';\nimport icon from 'flarum/helpers/icon';\nimport avatar from 'flarum/helpers/avatar';\nimport username from 'flarum/helpers/username';\nimport Model from 'flarum/Model';\nimport ItemList from 'flarum/utils/ItemList';\nimport { extend } from 'flarum/extend';\n\napp.initializers.add('michaelbelgium-flarum-profile-views', function() {\n User.prototype.profileViews = Model.hasMany('profileViews');\n\n extend(UserCard.prototype, 'infoItems', function(items) {\n const user = this.props.user;\n\n items.add('profile-views',(\n \n {icon('far fa-eye')}\n {' '}\n {app.translator.trans('flarum_profile_views.forum.user.views_count_text', {viewcount: '' + user.profileViews().length})}\n \n ));\n });\n\n extend(UserPage.prototype, 'sidebarItems', function(items) {\n const lastViewed = new ItemList();\n\n $.each(this.user.profileViews(), function(index, viewer) {\n\n lastViewed.add('lastUser-' + viewer.id(),\n \n {avatar(viewer, {className: 'lastUser-avatar'})}\n {username(viewer, {className: 'lastUser-name'})}\n \n );\n });\n\n items.add('lastViewedUsers', FieldSet.component({\n label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'),\n className: 'LastUsers',\n children: lastViewed.toArray()\n }));\n });\n});"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack://@michaelbelgium/flarum-profile-views/webpack/bootstrap","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['app']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['extend']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/UserPage']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['models/User']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/UserCard']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/FieldSet']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/icon']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/avatar']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/username']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['Model']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['utils/ItemList']\"","webpack://@michaelbelgium/flarum-profile-views/./src/forum/index.js"],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","flarum","core","compat","app","initializers","add","User","profileViews","Model","hasMany","extend","UserCard","items","user","this","props","icon","translator","trans","viewcount","length","UserPage","lastViewed","ItemList","$","each","index","viewer","id","href","forum","attribute","username","avatar","className","FieldSet","component","label","children","toArray","session","request","method","url","data"],"mappings":"2BACA,IAAAA,EAAA,GAGA,SAAAC,EAAAC,GAGA,GAAAF,EAAAE,GACA,OAAAF,EAAAE,GAAAC,QAGA,IAAAC,EAAAJ,EAAAE,GAAA,CACAG,EAAAH,EACAI,GAAA,EACAH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MAAwBV,IAAIqC,QAAQ3B,KAAKe,OAASd,KAAKD,KAAKe,MAE9EzB,IAAIsC,QAAQ,CACRC,OAAQ,OACRC,IAAKxC,IAAI2B,MAAMC,UAAU,UAAY,gBAAkBjB,KAAKD,KAAKe,KACjEgB,KAAM,CAAEjB,OAAQxB,IAAIqC,QAAQ3B,KAAKe","file":"forum.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 11);\n","module.exports = flarum.core.compat['app'];","module.exports = flarum.core.compat['extend'];","module.exports = flarum.core.compat['components/UserPage'];","module.exports = flarum.core.compat['models/User'];","module.exports = flarum.core.compat['components/UserCard'];","module.exports = flarum.core.compat['components/FieldSet'];","module.exports = flarum.core.compat['helpers/icon'];","module.exports = flarum.core.compat['helpers/avatar'];","module.exports = flarum.core.compat['helpers/username'];","module.exports = flarum.core.compat['Model'];","module.exports = flarum.core.compat['utils/ItemList'];","import app from 'flarum/app';\r\nimport User from 'flarum/models/User';\r\nimport UserPage from 'flarum/components/UserPage';\r\nimport UserCard from 'flarum/components/UserCard';\r\nimport FieldSet from 'flarum/components/FieldSet';\r\nimport icon from 'flarum/helpers/icon';\r\nimport avatar from 'flarum/helpers/avatar';\r\nimport username from 'flarum/helpers/username';\r\nimport Model from 'flarum/Model';\r\nimport ItemList from 'flarum/utils/ItemList';\r\nimport { extend } from 'flarum/extend';\r\n\r\napp.initializers.add('michaelbelgium-flarum-profile-views', function() {\r\n User.prototype.profileViews = Model.hasMany('profileViews');\r\n\r\n extend(UserCard.prototype, 'infoItems', function(items) {\r\n const user = this.props.user;\r\n\r\n items.add('profile-views',(\r\n \r\n {icon('far fa-eye')}\r\n {' '}\r\n {app.translator.trans('flarum_profile_views.forum.user.views_count_text', {viewcount: '' + (user.profileViews() === false ? '0' : user.profileViews().length)})}\r\n \r\n ));\r\n });\r\n\r\n extend(UserPage.prototype, 'sidebarItems', function(items) {\r\n const lastViewed = new ItemList();\r\n\r\n $.each(this.user.profileViews(), function(index, viewer) {\r\n\r\n lastViewed.add('lastUser-' + viewer.id(),\r\n \r\n {avatar(viewer, {className: 'lastUser-avatar'})}\r\n {username(viewer, {className: 'lastUser-name'})}\r\n \r\n );\r\n });\r\n\r\n items.add('lastViewedUsers', FieldSet.component({\r\n label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'),\r\n className: 'LastUsers',\r\n children: lastViewed.toArray()\r\n }));\r\n });\r\n\r\n extend(UserPage.prototype, 'show', function() {\r\n if(typeof app.session.user !== 'undefined' && app.session.user.id() !== this.user.id())\r\n {\r\n app.request({\r\n method: 'POST',\r\n url: app.forum.attribute('apiUrl') + '/profileview/' + this.user.id(),\r\n data: { viewer: app.session.user.id() }\r\n });\r\n }\r\n });\r\n});"],"sourceRoot":""} \ No newline at end of file diff --git a/js/src/forum/index.js b/js/src/forum/index.js index 18ca13e..aa187d5 100644 --- a/js/src/forum/index.js +++ b/js/src/forum/index.js @@ -20,7 +20,7 @@ app.initializers.add('michaelbelgium-flarum-profile-views', function() { {icon('far fa-eye')} {' '} - {app.translator.trans('flarum_profile_views.forum.user.views_count_text', {viewcount: '' + user.profileViews().length})} + {app.translator.trans('flarum_profile_views.forum.user.views_count_text', {viewcount: '' + (user.profileViews() === false ? '0' : user.profileViews().length)})} )); }); @@ -44,4 +44,15 @@ app.initializers.add('michaelbelgium-flarum-profile-views', function() { children: lastViewed.toArray() })); }); + + extend(UserPage.prototype, 'show', function() { + if(typeof app.session.user !== 'undefined' && app.session.user.id() !== this.user.id()) + { + app.request({ + method: 'POST', + url: app.forum.attribute('apiUrl') + '/profileview/' + this.user.id(), + data: { viewer: app.session.user.id() } + }); + } + }); }); \ No newline at end of file diff --git a/src/controllers/CreateUserProfileViewController.php b/src/controllers/CreateUserProfileViewController.php new file mode 100644 index 0000000..a38aa4a --- /dev/null +++ b/src/controllers/CreateUserProfileViewController.php @@ -0,0 +1,31 @@ +getQueryParams(), 'id'); + $viewerId = array_get($request->getParsedBody(), 'viewer'); + $user = User::find($userId); + $serverParams = $request->getServerParams(); + $ip = $serverParams['REMOTE_ADDR']; + + if (isset($serverParams["HTTP_CF_CONNECTING_IP"])) + $ip = $serverParams["HTTP_CF_CONNECTING_IP"]; + + $resultCount = $user->profileViews()->wherePivot('ip', '=', $ip)->count(); + + if($resultCount == 0) + $user->profileViews()->attach(User::find($viewerId), ["ip" => $ip]); + + return new EmptyResponse(); + } +} \ No newline at end of file diff --git a/src/listeners/AddProfileViewHandler.php b/src/listeners/AddProfileViewHandler.php deleted file mode 100644 index 5733328..0000000 --- a/src/listeners/AddProfileViewHandler.php +++ /dev/null @@ -1,38 +0,0 @@ -listen(WillSerializeData::class, [$this, "confViews"]); - } - - public function confViews(WillSerializeData $event) - { - if($event->isController(ShowUserController::class)) - { - $id = $event->request->getQueryParams()["id"]; - if(is_numeric($id)) return; - - $serverParams = $event->request->getServerParams(); - $ip = $serverParams['REMOTE_ADDR']; - - if (isset($serverParams["HTTP_CF_CONNECTING_IP"])) - $ip = $serverParams["HTTP_CF_CONNECTING_IP"]; - - $visited_user = $event->data; - $user = $event->actor; - - $resultCount = $visited_user->profileViews()->wherePivot('ip', '=', $ip)->count(); - - if($resultCount > 0 || $user->isGuest()) return; - - $visited_user->profileViews()->attach($user, ["ip" => $ip]); - } - } -} From f23eea89efef43990487a88b17a50bc3058697c8 Mon Sep 17 00:00:00 2001 From: Michael V Date: Sat, 12 Jan 2019 11:34:10 +0100 Subject: [PATCH 24/37] PSR-4 --- composer.json | 2 +- extend.php | 4 ++-- src/controllers/CreateUserProfileViewController.php | 2 +- src/listeners/AddUserProfileViewsRelationship.php | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index b42ed12..3acda6d 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ }, "autoload": { "psr-4": { - "michaelbelgium\\profileviews\\": "src/" + "Michaelbelgium\\Profileviews\\": "src/" } }, "extra": { diff --git a/extend.php b/extend.php index f3e1682..6841b92 100644 --- a/extend.php +++ b/extend.php @@ -1,6 +1,6 @@ Date: Sat, 12 Jan 2019 12:14:23 +0100 Subject: [PATCH 25/37] Remove column ip, add column visited_at --- migrations/2019_01_12_103741_drop_ip_views.php | 7 +++++++ .../2019_01_12_104853_add_visited_at_views.php | 7 +++++++ src/controllers/CreateUserProfileViewController.php | 12 ++++++------ src/listeners/AddUserProfileViewsRelationship.php | 4 ++-- 4 files changed, 22 insertions(+), 8 deletions(-) create mode 100644 migrations/2019_01_12_103741_drop_ip_views.php create mode 100644 migrations/2019_01_12_104853_add_visited_at_views.php diff --git a/migrations/2019_01_12_103741_drop_ip_views.php b/migrations/2019_01_12_103741_drop_ip_views.php new file mode 100644 index 0000000..ea3ebaa --- /dev/null +++ b/migrations/2019_01_12_103741_drop_ip_views.php @@ -0,0 +1,7 @@ + ["string"] +]); \ No newline at end of file diff --git a/migrations/2019_01_12_104853_add_visited_at_views.php b/migrations/2019_01_12_104853_add_visited_at_views.php new file mode 100644 index 0000000..15d056d --- /dev/null +++ b/migrations/2019_01_12_104853_add_visited_at_views.php @@ -0,0 +1,7 @@ + ["datetime"] +]); \ No newline at end of file diff --git a/src/controllers/CreateUserProfileViewController.php b/src/controllers/CreateUserProfileViewController.php index 709ceef..16e7321 100644 --- a/src/controllers/CreateUserProfileViewController.php +++ b/src/controllers/CreateUserProfileViewController.php @@ -16,15 +16,15 @@ public function handle(Request $request): Response $viewerId = array_get($request->getParsedBody(), 'viewer'); $user = User::find($userId); $serverParams = $request->getServerParams(); - $ip = $serverParams['REMOTE_ADDR']; - if (isset($serverParams["HTTP_CF_CONNECTING_IP"])) - $ip = $serverParams["HTTP_CF_CONNECTING_IP"]; + $profileView = $user->profileViews()->where('viewer_id', $viewerId); - $resultCount = $user->profileViews()->wherePivot('ip', '=', $ip)->count(); + $count = $profileView->count(); - if($resultCount == 0) - $user->profileViews()->attach(User::find($viewerId), ["ip" => $ip]); + if($count == 0) + $user->profileViews()->attach(User::find($viewerId), ["visited_at" => date('Y-m-d H:i:s')]); + else + $profileView->update(["visited_at" => date('Y-m-d H:i:s')]); return new EmptyResponse(); } diff --git a/src/listeners/AddUserProfileViewsRelationship.php b/src/listeners/AddUserProfileViewsRelationship.php index 83a3c90..23126b9 100644 --- a/src/listeners/AddUserProfileViewsRelationship.php +++ b/src/listeners/AddUserProfileViewsRelationship.php @@ -28,12 +28,12 @@ public function getModelRelationship(GetModelRelationship $event) { if($event->isRelationship(User::class, self::RELATIONSHIP)) { - return $event->model->belongsToMany(User::class, 'user_profile_views', 'viewed_user_id', 'viewer_id')->withPivot('ip'); + return $event->model->belongsToMany(User::class, 'user_profile_views', 'viewed_user_id', 'viewer_id')->withPivot('visited_at'); } if($event->isRelationship(User::class, self::RELATIONSHIP_OTHER)) { - return $event->model->belongsToMany(User::class, 'user_profile_views', 'viewer_id', 'viewed_user_id')->withPivot('ip'); + return $event->model->belongsToMany(User::class, 'user_profile_views', 'viewer_id', 'viewed_user_id')->withPivot('visited_at'); } } From 141f032966d108f07e774c5239fed373860149cf Mon Sep 17 00:00:00 2001 From: Michael V Date: Wed, 16 Jan 2019 21:38:44 +0100 Subject: [PATCH 26/37] Different approach, not working yet fully Doesn't display on the userpage? --- extend.php | 9 +-- js/dist/forum.js | 2 +- js/dist/forum.js.map | 2 +- js/src/ProfileView.js | 7 +++ js/src/forum/index.js | 41 ++++++++----- src/Models/UserProfileView.php | 23 ++++++++ src/Serializers/UserProfileViewSerializer.php | 28 +++++++++ .../CreateUserProfileViewController.php | 23 ++++---- .../ListProfileViewsController.php | 32 ++++++++++ .../AddUserProfileViewsRelationship.php | 59 ------------------- 10 files changed, 134 insertions(+), 92 deletions(-) create mode 100644 js/src/ProfileView.js create mode 100644 src/Models/UserProfileView.php create mode 100644 src/Serializers/UserProfileViewSerializer.php create mode 100644 src/controllers/ListProfileViewsController.php delete mode 100644 src/listeners/AddUserProfileViewsRelationship.php diff --git a/extend.php b/extend.php index 6841b92..a54583c 100644 --- a/extend.php +++ b/extend.php @@ -1,5 +1,5 @@ post('/profileview/{id}', 'profileview.add', CreateUserProfileViewController::class), - - function (Dispatcher $events) { - $events->subscribe(AddUserProfileViewsRelationship::class); - } + ->post('/profileview/{id}', 'profileview.add', CreateUserProfileViewController::class) + ->get('/profileview', 'profileview.index', ListProfileViewsController::class), ]; \ No newline at end of file diff --git a/js/dist/forum.js b/js/dist/forum.js index 3c75d63..33ea436 100644 --- a/js/dist/forum.js +++ b/js/dist/forum.js @@ -1,2 +1,2 @@ -module.exports=function(e){var r={};function t(o){if(r[o])return r[o].exports;var n=r[o]={i:o,l:!1,exports:{}};return e[o].call(n.exports,n,n.exports,t),n.l=!0,n.exports}return t.m=e,t.c=r,t.d=function(e,r,o){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:o})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(t.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)t.d(o,n,function(r){return e[r]}.bind(null,n));return o},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=11)}([function(e,r){e.exports=flarum.core.compat.app},function(e,r){e.exports=flarum.core.compat.extend},function(e,r){e.exports=flarum.core.compat["components/UserPage"]},function(e,r){e.exports=flarum.core.compat["models/User"]},function(e,r){e.exports=flarum.core.compat["components/UserCard"]},function(e,r){e.exports=flarum.core.compat["components/FieldSet"]},function(e,r){e.exports=flarum.core.compat["helpers/icon"]},function(e,r){e.exports=flarum.core.compat["helpers/avatar"]},function(e,r){e.exports=flarum.core.compat["helpers/username"]},function(e,r){e.exports=flarum.core.compat.Model},function(e,r){e.exports=flarum.core.compat["utils/ItemList"]},function(e,r,t){"use strict";t.r(r);var o=t(0),n=t.n(o),a=t(3),s=t.n(a),i=t(2),u=t.n(i),l=t(4),c=t.n(l),f=t(5),p=t.n(f),d=t(6),v=t.n(d),b=t(7),x=t.n(b),y=t(8),w=t.n(y),h=t(9),_=t.n(h),O=t(10),j=t.n(O),U=t(1);n.a.initializers.add("michaelbelgium-flarum-profile-views",function(){s.a.prototype.profileViews=_.a.hasMany("profileViews"),Object(U.extend)(c.a.prototype,"infoItems",function(e){var r=this.props.user;e.add("profile-views",m("span",null,v()("far fa-eye")," ",n.a.translator.trans("flarum_profile_views.forum.user.views_count_text",{viewcount:""+(!1===r.profileViews()?"0":r.profileViews().length)})))}),Object(U.extend)(u.a.prototype,"sidebarItems",function(e){var r=new j.a;$.each(this.user.profileViews(),function(e,t){r.add("lastUser-"+t.id(),m("a",{href:n.a.forum.attribute("baseUrl")+"/u/"+t.username()},x()(t,{className:"lastUser-avatar"}),w()(t,{className:"lastUser-name"})))}),e.add("lastViewedUsers",p.a.component({label:n.a.translator.trans("flarum_profile_views.forum.user.title_last_viewers"),className:"LastUsers",children:r.toArray()}))}),Object(U.extend)(u.a.prototype,"show",function(){void 0!==n.a.session.user&&n.a.session.user.id()!==this.user.id()&&n.a.request({method:"POST",url:n.a.forum.attribute("apiUrl")+"/profileview/"+this.user.id(),data:{viewer:n.a.session.user.id()}})})})}]); +module.exports=function(e){var t={};function r(o){if(t[o])return t[o].exports;var n=t[o]={i:o,l:!1,exports:{}};return e[o].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.m=e,r.c=t,r.d=function(e,t,o){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(r.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)r.d(o,n,function(t){return e[t]}.bind(null,n));return o},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=12)}([function(e,t){e.exports=flarum.core.compat.app},function(e,t){e.exports=flarum.core.compat.Model},function(e,t){e.exports=flarum.core.compat.extend},function(e,t){e.exports=flarum.core.compat["components/UserPage"]},function(e,t){e.exports=flarum.core.compat["models/User"]},function(e,t){e.exports=flarum.core.compat["components/UserCard"]},function(e,t){e.exports=flarum.core.compat["components/FieldSet"]},function(e,t){e.exports=flarum.core.compat["helpers/icon"]},function(e,t){e.exports=flarum.core.compat["helpers/avatar"]},function(e,t){e.exports=flarum.core.compat["helpers/username"]},function(e,t){e.exports=flarum.core.compat["utils/ItemList"]},function(e,t){e.exports=flarum.core.compat["utils/humanTime"]},function(e,t,r){"use strict";r.r(t);var o=r(0),n=r.n(o),a=r(4),i=r.n(a),s=r(3),u=r.n(s),c=r(5),l=r.n(c),f=r(6),p=r.n(f),d=r(7),v=r.n(d),b=r(8),w=r.n(b),h=r(9),y=r.n(h),x=r(1),_=r.n(x),O=r(10),U=r.n(O),j=r(2);function g(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function P(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var S=function(e){var t,r;function o(){for(var t,r=arguments.length,o=new Array(r),n=0;n\r\n {icon('far fa-eye')}\r\n {' '}\r\n {app.translator.trans('flarum_profile_views.forum.user.views_count_text', {viewcount: '' + (user.profileViews() === false ? '0' : user.profileViews().length)})}\r\n \r\n ));\r\n });\r\n\r\n extend(UserPage.prototype, 'sidebarItems', function(items) {\r\n const lastViewed = new ItemList();\r\n\r\n $.each(this.user.profileViews(), function(index, viewer) {\r\n\r\n lastViewed.add('lastUser-' + viewer.id(),\r\n \r\n {avatar(viewer, {className: 'lastUser-avatar'})}\r\n {username(viewer, {className: 'lastUser-name'})}\r\n \r\n );\r\n });\r\n\r\n items.add('lastViewedUsers', FieldSet.component({\r\n label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'),\r\n className: 'LastUsers',\r\n children: lastViewed.toArray()\r\n }));\r\n });\r\n\r\n extend(UserPage.prototype, 'show', function() {\r\n if(typeof app.session.user !== 'undefined' && app.session.user.id() !== this.user.id())\r\n {\r\n app.request({\r\n method: 'POST',\r\n url: app.forum.attribute('apiUrl') + '/profileview/' + this.user.id(),\r\n data: { viewer: app.session.user.id() }\r\n });\r\n }\r\n });\r\n});"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack://@michaelbelgium/flarum-profile-views/webpack/bootstrap","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['app']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['Model']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['extend']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/UserPage']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['models/User']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/UserCard']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/FieldSet']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/icon']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/avatar']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/username']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['utils/ItemList']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['utils/humanTime']\"","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/defineProperty.js","webpack://@michaelbelgium/flarum-profile-views/./src/ProfileView.js","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/inheritsLoose.js","webpack://@michaelbelgium/flarum-profile-views/./src/forum/index.js"],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","flarum","core","compat","_assertThisInitialized","self","ReferenceError","_defineProperty","obj","configurable","writable","ProfileView","subClass","superClass","Model","attribute","transformDate","hasOne","constructor","__proto__","app","initializers","add","User","profileViews","hasMany","extend","UserCard","items","this","props","user","icon","translator","trans","viewcount","UserPage","_this","request","method","url","forum","then","data","views","map","filter","viewedUser","lastViewed","ItemList","forEach","element","viewer","id","href","username","avatar","className","humanTime","Date","visitedAt","FieldSet","component","label","children","toArray","console","log","session"],"mappings":"2BACA,IAAAA,EAAA,GAGA,SAAAC,EAAAC,GAGA,GAAAF,EAAAE,GACA,OAAAF,EAAAE,GAAAC,QAGA,IAAAC,EAAAJ,EAAAE,GAAA,CACAG,EAAAH,EACAI,GAAA,EACAH,QAAA,IAUA,OANAI,EAAAL,GAAAM,KAAAJ,EAAAD,QAAAC,IAAAD,QAAAF,GAGAG,EAAAE,GAAA,EAGAF,EAAAD,QA0DA,OArDAF,EAAAQ,EAA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KAAKE,IAAI,SAAArC,GAAG,OAAI,IAAIG,EAAYH,KAC/BsC,OAAO,SAAAtC,GAAG,OAAIA,EAAIuC,cAAgBV,EAAKN,OAC5DiB,EAAa,IAAIC,IAErBL,EAAMM,QAAQ,SAAAC,GACVH,EAAW1B,IAAI,YAAc6B,EAAQC,SAASC,KAC1ChF,EAAA,KAAGiF,KAAMlC,IAAIqB,MAAM1B,UAAU,WAAa,MAAQoC,EAAQC,SAASG,YAC9DC,IAAOL,EAAQC,SAAU,CAACK,UAAW,oBACrCF,IAASJ,EAAQC,SAAU,CAACK,UAAW,kBACxCpF,EAAA,QAAMoF,UAAU,oBAAoBC,IAAU,IAAIC,KAAKR,EAAQS,mBAK3EhC,EAAMN,IAAI,kBAAmBuC,IAASC,UAAU,CAC5CC,MAAO3C,IAAIa,WAAWC,MAAM,sDAC5BuB,UAAW,YACXO,SAAUhB,EAAWiB,aAGzBC,QAAQC,IAAInB,EAAWiB,eAI/BvC,iBAAOU,IAASvC,UAAW,OAAQ,gBACA,IAArBuB,IAAIgD,QAAQrC,MAAwBX,IAAIgD,QAAQrC,KAAKsB,OAASxB,KAAKE,KAAKsB,MAE9EjC,IAAIkB,QAAQ,CACRC,OAAQ,OACRC,IAAKpB,IAAIqB,MAAM1B,UAAU,UAAY,gBAAkBc,KAAKE,KAAKsB,KACjEV,KAAM,CAAES,OAAQhC,IAAIgD,QAAQrC,KAAKsB","file":"forum.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 12);\n","module.exports = flarum.core.compat['app'];","module.exports = flarum.core.compat['Model'];","module.exports = flarum.core.compat['extend'];","module.exports = flarum.core.compat['components/UserPage'];","module.exports = flarum.core.compat['models/User'];","module.exports = flarum.core.compat['components/UserCard'];","module.exports = flarum.core.compat['components/FieldSet'];","module.exports = flarum.core.compat['helpers/icon'];","module.exports = flarum.core.compat['helpers/avatar'];","module.exports = flarum.core.compat['helpers/username'];","module.exports = flarum.core.compat['utils/ItemList'];","module.exports = flarum.core.compat['utils/humanTime'];","export default function _assertThisInitialized(self) {\n if (self === void 0) {\n throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\");\n }\n\n return self;\n}","export default function _defineProperty(obj, key, value) {\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n\n return obj;\n}","import Model from 'flarum/Model';\r\n\r\nexport default class ProfileView extends Model {\r\n visitedAt = Model.attribute('visited_at', Model.transformDate);\r\n viewer = Model.hasOne('viewer');\r\n viewedUser = Model.hasOne('viewedUser');\r\n}","export default function _inheritsLoose(subClass, superClass) {\n subClass.prototype = Object.create(superClass.prototype);\n subClass.prototype.constructor = subClass;\n subClass.__proto__ = superClass;\n}","import app from 'flarum/app';\r\nimport User from 'flarum/models/User';\r\nimport UserPage from 'flarum/components/UserPage';\r\nimport UserCard from 'flarum/components/UserCard';\r\nimport FieldSet from 'flarum/components/FieldSet';\r\nimport icon from 'flarum/helpers/icon';\r\nimport avatar from 'flarum/helpers/avatar';\r\nimport username from 'flarum/helpers/username';\r\nimport Model from 'flarum/Model';\r\nimport ItemList from 'flarum/utils/ItemList';\r\nimport { extend } from 'flarum/extend';\r\nimport ProfileView from '../ProfileView';\r\nimport humanTime from 'flarum/utils/humanTime';\r\n\r\napp.initializers.add('michaelbelgium-flarum-profile-views', function() {\r\n User.prototype.profileViews = Model.hasMany('profileViews');\r\n\r\n extend(UserCard.prototype, 'infoItems', function(items) {\r\n const user = this.props.user;\r\n\r\n items.add('profile-views',(\r\n \r\n {icon('far fa-eye')}\r\n {' '}\r\n {app.translator.trans('flarum_profile_views.forum.user.views_count_text', {viewcount: 'todo'})}\r\n \r\n ));\r\n });\r\n\r\n extend(UserPage.prototype, 'sidebarItems', function(items) {\r\n app.request({\r\n method: 'GET',\r\n url: app.forum.attribute('apiUrl') + '/profileview',\r\n }).then(data => {\r\n var profileViews = data.data.map(obj => new ProfileView(obj));\r\n var views = profileViews.filter(obj => obj.viewedUser() == this.user);\r\n var lastViewed = new ItemList();\r\n\r\n views.forEach(element => {\r\n lastViewed.add('lastUser-' + element.viewer().id(),\r\n \r\n {avatar(element.viewer(), {className: 'lastUser-avatar'})}\r\n {username(element.viewer(), {className: 'lastUser-name'})}\r\n {humanTime(new Date(element.visitedAt()))}\r\n \r\n );\r\n });\r\n\r\n items.add('lastViewedUsers', FieldSet.component({\r\n label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'),\r\n className: 'LastUsers',\r\n children: lastViewed.toArray()\r\n }));\r\n\r\n console.log(lastViewed.toArray());\r\n });\r\n });\r\n\r\n extend(UserPage.prototype, 'show', function() {\r\n if(typeof app.session.user !== 'undefined' && app.session.user.id() !== this.user.id())\r\n {\r\n app.request({\r\n method: 'POST',\r\n url: app.forum.attribute('apiUrl') + '/profileview/' + this.user.id(),\r\n data: { viewer: app.session.user.id() }\r\n });\r\n }\r\n });\r\n});"],"sourceRoot":""} \ No newline at end of file diff --git a/js/src/ProfileView.js b/js/src/ProfileView.js new file mode 100644 index 0000000..b50cffc --- /dev/null +++ b/js/src/ProfileView.js @@ -0,0 +1,7 @@ +import Model from 'flarum/Model'; + +export default class ProfileView extends Model { + visitedAt = Model.attribute('visited_at', Model.transformDate); + viewer = Model.hasOne('viewer'); + viewedUser = Model.hasOne('viewedUser'); +} \ No newline at end of file diff --git a/js/src/forum/index.js b/js/src/forum/index.js index aa187d5..e6b0718 100644 --- a/js/src/forum/index.js +++ b/js/src/forum/index.js @@ -9,6 +9,8 @@ import username from 'flarum/helpers/username'; import Model from 'flarum/Model'; import ItemList from 'flarum/utils/ItemList'; import { extend } from 'flarum/extend'; +import ProfileView from '../ProfileView'; +import humanTime from 'flarum/utils/humanTime'; app.initializers.add('michaelbelgium-flarum-profile-views', function() { User.prototype.profileViews = Model.hasMany('profileViews'); @@ -20,29 +22,38 @@ app.initializers.add('michaelbelgium-flarum-profile-views', function() { {icon('far fa-eye')} {' '} - {app.translator.trans('flarum_profile_views.forum.user.views_count_text', {viewcount: '' + (user.profileViews() === false ? '0' : user.profileViews().length)})} + {app.translator.trans('flarum_profile_views.forum.user.views_count_text', {viewcount: 'todo'})} )); }); extend(UserPage.prototype, 'sidebarItems', function(items) { - const lastViewed = new ItemList(); + app.request({ + method: 'GET', + url: app.forum.attribute('apiUrl') + '/profileview', + }).then(data => { + var profileViews = data.data.map(obj => new ProfileView(obj)); + var views = profileViews.filter(obj => obj.viewedUser() == this.user); + var lastViewed = new ItemList(); - $.each(this.user.profileViews(), function(index, viewer) { + views.forEach(element => { + lastViewed.add('lastUser-' + element.viewer().id(), + + {avatar(element.viewer(), {className: 'lastUser-avatar'})} + {username(element.viewer(), {className: 'lastUser-name'})} + {humanTime(new Date(element.visitedAt()))} + + ); + }); - lastViewed.add('lastUser-' + viewer.id(), - - {avatar(viewer, {className: 'lastUser-avatar'})} - {username(viewer, {className: 'lastUser-name'})} - - ); - }); + items.add('lastViewedUsers', FieldSet.component({ + label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'), + className: 'LastUsers', + children: lastViewed.toArray() + })); - items.add('lastViewedUsers', FieldSet.component({ - label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'), - className: 'LastUsers', - children: lastViewed.toArray() - })); + console.log(lastViewed.toArray()); + }); }); extend(UserPage.prototype, 'show', function() { diff --git a/src/Models/UserProfileView.php b/src/Models/UserProfileView.php new file mode 100644 index 0000000..fa4f4ce --- /dev/null +++ b/src/Models/UserProfileView.php @@ -0,0 +1,23 @@ +belongsTo(User::class, 'viewed_user_id'); + } + + public function viewer() + { + return $this->belongsTo(User::class, 'viewer_id'); + } +} diff --git a/src/Serializers/UserProfileViewSerializer.php b/src/Serializers/UserProfileViewSerializer.php new file mode 100644 index 0000000..1e3befa --- /dev/null +++ b/src/Serializers/UserProfileViewSerializer.php @@ -0,0 +1,28 @@ + $this->formatDate($profileview->visited_at) + ]; + } + + protected function viewedUser($profileview) + { + return $this->hasOne($profileview, UserSerializer::class); + } + + protected function viewer($profileview) + { + return $this->hasOne($profileview, UserSerializer::class); + } +} diff --git a/src/controllers/CreateUserProfileViewController.php b/src/controllers/CreateUserProfileViewController.php index 16e7321..dc6756f 100644 --- a/src/controllers/CreateUserProfileViewController.php +++ b/src/controllers/CreateUserProfileViewController.php @@ -6,7 +6,9 @@ use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Server\RequestHandlerInterface; use Zend\Diactoros\Response\EmptyResponse; -use Flarum\User\User; +use Flarum\User\User; +use Carbon\Carbon; +use Michaelbelgium\Profileviews\Models\UserProfileView; class CreateUserProfileViewController implements RequestHandlerInterface { @@ -14,18 +16,19 @@ public function handle(Request $request): Response { $userId = array_get($request->getQueryParams(), 'id'); $viewerId = array_get($request->getParsedBody(), 'viewer'); - $user = User::find($userId); - $serverParams = $request->getServerParams(); - $profileView = $user->profileViews()->where('viewer_id', $viewerId); + $profileView = UserProfileView::where('viewer_id', $viewerId)->where('viewed_user_id', $userId)->first(); - $count = $profileView->count(); + if(is_null($profileView)) + { + $profileView = new UserProfileView(); + $profileView->viewer()->associate(User::find($viewerId)); + $profileView->viewedUser()->associate(User::find($userId)); + } + + $profileView->visited_at = Carbon::now(); + $profileView->save(); - if($count == 0) - $user->profileViews()->attach(User::find($viewerId), ["visited_at" => date('Y-m-d H:i:s')]); - else - $profileView->update(["visited_at" => date('Y-m-d H:i:s')]); - return new EmptyResponse(); } } \ No newline at end of file diff --git a/src/controllers/ListProfileViewsController.php b/src/controllers/ListProfileViewsController.php new file mode 100644 index 0000000..4799fd7 --- /dev/null +++ b/src/controllers/ListProfileViewsController.php @@ -0,0 +1,32 @@ + 'desc']; + + protected function data(ServerRequestInterface $request, Document $document) + { + // $this->extractInclude($request); + + $sort = $this->extractSort($request); + + $query = UserProfileView::query(); + + foreach ($sort as $field => $order) { + $query->orderBy(snake_case($field), $order); + } + + return $query->get(); + } +} \ No newline at end of file diff --git a/src/listeners/AddUserProfileViewsRelationship.php b/src/listeners/AddUserProfileViewsRelationship.php deleted file mode 100644 index 23126b9..0000000 --- a/src/listeners/AddUserProfileViewsRelationship.php +++ /dev/null @@ -1,59 +0,0 @@ -listen(WillGetData::class, [$this, 'includeTagsRelationship']); - $events->listen(GetModelRelationship::class, [$this, 'getModelRelationship']); - $events->listen(GetApiRelationship::class, [$this, 'GetApiRelationship']); - } - - public function getModelRelationship(GetModelRelationship $event) - { - if($event->isRelationship(User::class, self::RELATIONSHIP)) - { - return $event->model->belongsToMany(User::class, 'user_profile_views', 'viewed_user_id', 'viewer_id')->withPivot('visited_at'); - } - - if($event->isRelationship(User::class, self::RELATIONSHIP_OTHER)) - { - return $event->model->belongsToMany(User::class, 'user_profile_views', 'viewer_id', 'viewed_user_id')->withPivot('visited_at'); - } - } - - /** - * @param GetApiRelationship $event - * @return \Tobscure\JsonApi\Relationship|null - */ - public function getApiRelationship(GetApiRelationship $event) - { - if ($event->isRelationship(UserSerializer::class, self::RELATIONSHIP)) { - return $event->serializer->hasMany($event->model, UserSerializer::class, self::RELATIONSHIP); - } - } - - /** - * @param WillGetData $event - */ - public function includeTagsRelationship(WillGetData $event) - { - if ($event->isController(ShowUserController::class)) - $event->addInclude([self::RELATIONSHIP, self::RELATIONSHIP_OTHER]); - } -} \ No newline at end of file From 5f487f53aab663829f9ad41e26fb972c66633192 Mon Sep 17 00:00:00 2001 From: Michael V Date: Sat, 19 Jan 2019 15:56:08 +0100 Subject: [PATCH 27/37] Try with relationships again, but with hasMany and not belongsToMany --- extend.php | 9 +- js/dist/forum.js | 429 +++++++++++++++++- js/dist/forum.js.map | 2 +- js/src/ProfileView.js | 1 + js/src/forum/index.js | 48 +- .../AddUserProfileViewsRelationship.php | 66 +++ .../CreateUserProfileViewController.php | 15 +- .../ListProfileViewsController.php | 32 -- 8 files changed, 533 insertions(+), 69 deletions(-) create mode 100644 src/Listeners/AddUserProfileViewsRelationship.php delete mode 100644 src/controllers/ListProfileViewsController.php diff --git a/extend.php b/extend.php index a54583c..6841b92 100644 --- a/extend.php +++ b/extend.php @@ -1,5 +1,5 @@ post('/profileview/{id}', 'profileview.add', CreateUserProfileViewController::class) - ->get('/profileview', 'profileview.index', ListProfileViewsController::class), + ->post('/profileview/{id}', 'profileview.add', CreateUserProfileViewController::class), + + function (Dispatcher $events) { + $events->subscribe(AddUserProfileViewsRelationship::class); + } ]; \ No newline at end of file diff --git a/js/dist/forum.js b/js/dist/forum.js index 33ea436..be8c214 100644 --- a/js/dist/forum.js +++ b/js/dist/forum.js @@ -1,2 +1,429 @@ -module.exports=function(e){var t={};function r(o){if(t[o])return t[o].exports;var n=t[o]={i:o,l:!1,exports:{}};return e[o].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.m=e,r.c=t,r.d=function(e,t,o){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(r.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)r.d(o,n,function(t){return e[t]}.bind(null,n));return o},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=12)}([function(e,t){e.exports=flarum.core.compat.app},function(e,t){e.exports=flarum.core.compat.Model},function(e,t){e.exports=flarum.core.compat.extend},function(e,t){e.exports=flarum.core.compat["components/UserPage"]},function(e,t){e.exports=flarum.core.compat["models/User"]},function(e,t){e.exports=flarum.core.compat["components/UserCard"]},function(e,t){e.exports=flarum.core.compat["components/FieldSet"]},function(e,t){e.exports=flarum.core.compat["helpers/icon"]},function(e,t){e.exports=flarum.core.compat["helpers/avatar"]},function(e,t){e.exports=flarum.core.compat["helpers/username"]},function(e,t){e.exports=flarum.core.compat["utils/ItemList"]},function(e,t){e.exports=flarum.core.compat["utils/humanTime"]},function(e,t,r){"use strict";r.r(t);var o=r(0),n=r.n(o),a=r(4),i=r.n(a),s=r(3),u=r.n(s),c=r(5),l=r.n(c),f=r(6),p=r.n(f),d=r(7),v=r.n(d),b=r(8),w=r.n(b),h=r(9),y=r.n(h),x=r(1),_=r.n(x),O=r(10),U=r.n(O),j=r(2);function g(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function P(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var S=function(e){var t,r;function o(){for(var t,r=arguments.length,o=new Array(r),n=0;n + // {avatar(viewer, {className: 'lastUser-avatar'})} + // {username(viewer, {className: 'lastUser-name'})} + // + // ); + }); // items.add('lastViewedUsers', FieldSet.component({ + // label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'), + // className: 'LastUsers', + // children: lastViewed.toArray() + // })); + }); + Object(flarum_extend__WEBPACK_IMPORTED_MODULE_10__["extend"])(flarum_components_UserPage__WEBPACK_IMPORTED_MODULE_2___default.a.prototype, 'show', function () { + if (typeof flarum_app__WEBPACK_IMPORTED_MODULE_0___default.a.session.user !== 'undefined' && flarum_app__WEBPACK_IMPORTED_MODULE_0___default.a.session.user.id() !== this.user.id()) { + flarum_app__WEBPACK_IMPORTED_MODULE_0___default.a.request({ + method: 'POST', + url: flarum_app__WEBPACK_IMPORTED_MODULE_0___default.a.forum.attribute('apiUrl') + '/profileview/' + this.user.id(), + data: { + viewer: flarum_app__WEBPACK_IMPORTED_MODULE_0___default.a.session.user.id() + } + }); + } + }); +}); + +/***/ }), + +/***/ "flarum/Model": +/*!**********************************************!*\ + !*** external "flarum.core.compat['Model']" ***! + \**********************************************/ +/*! no static exports found */ +/***/ (function(module, exports) { + +module.exports = flarum.core.compat['Model']; + +/***/ }), + +/***/ "flarum/app": +/*!********************************************!*\ + !*** external "flarum.core.compat['app']" ***! + \********************************************/ +/*! no static exports found */ +/***/ (function(module, exports) { + +module.exports = flarum.core.compat['app']; + +/***/ }), + +/***/ "flarum/components/FieldSet": +/*!************************************************************!*\ + !*** external "flarum.core.compat['components/FieldSet']" ***! + \************************************************************/ +/*! no static exports found */ +/***/ (function(module, exports) { + +module.exports = flarum.core.compat['components/FieldSet']; + +/***/ }), + +/***/ "flarum/components/UserCard": +/*!************************************************************!*\ + !*** external "flarum.core.compat['components/UserCard']" ***! + \************************************************************/ +/*! no static exports found */ +/***/ (function(module, exports) { + +module.exports = flarum.core.compat['components/UserCard']; + +/***/ }), + +/***/ "flarum/components/UserPage": +/*!************************************************************!*\ + !*** external "flarum.core.compat['components/UserPage']" ***! + \************************************************************/ +/*! no static exports found */ +/***/ (function(module, exports) { + +module.exports = flarum.core.compat['components/UserPage']; + +/***/ }), + +/***/ "flarum/extend": +/*!***********************************************!*\ + !*** external "flarum.core.compat['extend']" ***! + \***********************************************/ +/*! no static exports found */ +/***/ (function(module, exports) { + +module.exports = flarum.core.compat['extend']; + +/***/ }), + +/***/ "flarum/helpers/avatar": +/*!*******************************************************!*\ + !*** external "flarum.core.compat['helpers/avatar']" ***! + \*******************************************************/ +/*! no static exports found */ +/***/ (function(module, exports) { + +module.exports = flarum.core.compat['helpers/avatar']; + +/***/ }), + +/***/ "flarum/helpers/icon": +/*!*****************************************************!*\ + !*** external "flarum.core.compat['helpers/icon']" ***! + \*****************************************************/ +/*! no static exports found */ +/***/ (function(module, exports) { + +module.exports = flarum.core.compat['helpers/icon']; + +/***/ }), + +/***/ "flarum/helpers/username": +/*!*********************************************************!*\ + !*** external "flarum.core.compat['helpers/username']" ***! + \*********************************************************/ +/*! no static exports found */ +/***/ (function(module, exports) { + +module.exports = flarum.core.compat['helpers/username']; + +/***/ }), + +/***/ "flarum/models/User": +/*!****************************************************!*\ + !*** external "flarum.core.compat['models/User']" ***! + \****************************************************/ +/*! no static exports found */ +/***/ (function(module, exports) { + +module.exports = flarum.core.compat['models/User']; + +/***/ }), + +/***/ "flarum/utils/ItemList": +/*!*******************************************************!*\ + !*** external "flarum.core.compat['utils/ItemList']" ***! + \*******************************************************/ +/*! no static exports found */ +/***/ (function(module, exports) { + +module.exports = flarum.core.compat['utils/ItemList']; + +/***/ }) + +/******/ }); //# sourceMappingURL=forum.js.map \ No newline at end of file diff --git a/js/dist/forum.js.map b/js/dist/forum.js.map index f0e18bb..6f587f9 100644 --- a/js/dist/forum.js.map +++ b/js/dist/forum.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack://@michaelbelgium/flarum-profile-views/webpack/bootstrap","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['app']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['Model']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['extend']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/UserPage']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['models/User']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/UserCard']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/FieldSet']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/icon']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/avatar']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/username']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['utils/ItemList']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['utils/humanTime']\"","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/defineProperty.js","webpack://@michaelbelgium/flarum-profile-views/./src/ProfileView.js","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/inheritsLoose.js","webpack://@michaelbelgium/flarum-profile-views/./src/forum/index.js"],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","flarum","core","compat","_assertThisInitialized","self","ReferenceError","_defineProperty","obj","configurable","writable","ProfileView","subClass","superClass","Model","attribute","transformDate","hasOne","constructor","__proto__","app","initializers","add","User","profileViews","hasMany","extend","UserCard","items","this","props","user","icon","translator","trans","viewcount","UserPage","_this","request","method","url","forum","then","data","views","map","filter","viewedUser","lastViewed","ItemList","forEach","element","viewer","id","href","username","avatar","className","humanTime","Date","visitedAt","FieldSet","component","label","children","toArray","console","log","session"],"mappings":"2BACA,IAAAA,EAAA,GAGA,SAAAC,EAAAC,GAGA,GAAAF,EAAAE,GACA,OAAAF,EAAAE,GAAAC,QAGA,IAAAC,EAAAJ,EAAAE,GAAA,CACAG,EAAAH,EACAI,GAAA,EACAH,QAAA,IAUA,OANAI,EAAAL,GAAAM,KAAAJ,EAAAD,QAAAC,IAAAD,QAAAF,GAGAG,EAAAE,GAAA,EAGAF,EAAAD,QA0DA,OArDAF,EAAAQ,EAAAF,EAGAN,EAAAS,EAAAV,EAGAC,EAAAU,EAAA,SAAAR,EAAAS,EAAAC,GACAZ,EAAAa,EAAAX,EAAAS,IACAG,OAAAC,eAAAb,EAAAS,EAAA,CAA0CK,YAA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MM,QAAQ,SAAAC,GACVH,EAAW1B,IAAI,YAAc6B,EAAQC,SAASC,KAC1ChF,EAAA,KAAGiF,KAAMlC,IAAIqB,MAAM1B,UAAU,WAAa,MAAQoC,EAAQC,SAASG,YAC9DC,IAAOL,EAAQC,SAAU,CAACK,UAAW,oBACrCF,IAASJ,EAAQC,SAAU,CAACK,UAAW,kBACxCpF,EAAA,QAAMoF,UAAU,oBAAoBC,IAAU,IAAIC,KAAKR,EAAQS,mBAK3EhC,EAAMN,IAAI,kBAAmBuC,IAASC,UAAU,CAC5CC,MAAO3C,IAAIa,WAAWC,MAAM,sDAC5BuB,UAAW,YACXO,SAAUhB,EAAWiB,aAGzBC,QAAQC,IAAInB,EAAWiB,eAI/BvC,iBAAOU,IAASvC,UAAW,OAAQ,gBACA,IAArBuB,IAAIgD,QAAQrC,MAAwBX,IAAIgD,QAAQrC,KAAKsB,OAASxB,KAAKE,KAAKsB,MAE9EjC,IAAIkB,QAAQ,CACRC,OAAQ,OACRC,IAAKpB,IAAIqB,MAAM1B,UAAU,UAAY,gBAAkBc,KAAKE,KAAKsB,KACjEV,KAAM,CAAES,OAAQhC,IAAIgD,QAAQrC,KAAKsB","file":"forum.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 12);\n","module.exports = flarum.core.compat['app'];","module.exports = flarum.core.compat['Model'];","module.exports = flarum.core.compat['extend'];","module.exports = flarum.core.compat['components/UserPage'];","module.exports = flarum.core.compat['models/User'];","module.exports = flarum.core.compat['components/UserCard'];","module.exports = flarum.core.compat['components/FieldSet'];","module.exports = flarum.core.compat['helpers/icon'];","module.exports = flarum.core.compat['helpers/avatar'];","module.exports = flarum.core.compat['helpers/username'];","module.exports = flarum.core.compat['utils/ItemList'];","module.exports = flarum.core.compat['utils/humanTime'];","export default function _assertThisInitialized(self) {\n if (self === void 0) {\n throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\");\n }\n\n return self;\n}","export default function _defineProperty(obj, key, value) {\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n\n return obj;\n}","import Model from 'flarum/Model';\r\n\r\nexport default class ProfileView extends Model {\r\n visitedAt = Model.attribute('visited_at', Model.transformDate);\r\n viewer = Model.hasOne('viewer');\r\n viewedUser = Model.hasOne('viewedUser');\r\n}","export default function _inheritsLoose(subClass, superClass) {\n subClass.prototype = Object.create(superClass.prototype);\n subClass.prototype.constructor = subClass;\n subClass.__proto__ = superClass;\n}","import app from 'flarum/app';\r\nimport User from 'flarum/models/User';\r\nimport UserPage from 'flarum/components/UserPage';\r\nimport UserCard from 'flarum/components/UserCard';\r\nimport FieldSet from 'flarum/components/FieldSet';\r\nimport icon from 'flarum/helpers/icon';\r\nimport avatar from 'flarum/helpers/avatar';\r\nimport username from 'flarum/helpers/username';\r\nimport Model from 'flarum/Model';\r\nimport ItemList from 'flarum/utils/ItemList';\r\nimport { extend } from 'flarum/extend';\r\nimport ProfileView from '../ProfileView';\r\nimport humanTime from 'flarum/utils/humanTime';\r\n\r\napp.initializers.add('michaelbelgium-flarum-profile-views', function() {\r\n User.prototype.profileViews = Model.hasMany('profileViews');\r\n\r\n extend(UserCard.prototype, 'infoItems', function(items) {\r\n const user = this.props.user;\r\n\r\n items.add('profile-views',(\r\n \r\n {icon('far fa-eye')}\r\n {' '}\r\n {app.translator.trans('flarum_profile_views.forum.user.views_count_text', {viewcount: 'todo'})}\r\n \r\n ));\r\n });\r\n\r\n extend(UserPage.prototype, 'sidebarItems', function(items) {\r\n app.request({\r\n method: 'GET',\r\n url: app.forum.attribute('apiUrl') + '/profileview',\r\n }).then(data => {\r\n var profileViews = data.data.map(obj => new ProfileView(obj));\r\n var views = profileViews.filter(obj => obj.viewedUser() == this.user);\r\n var lastViewed = new ItemList();\r\n\r\n views.forEach(element => {\r\n lastViewed.add('lastUser-' + element.viewer().id(),\r\n \r\n {avatar(element.viewer(), {className: 'lastUser-avatar'})}\r\n {username(element.viewer(), {className: 'lastUser-name'})}\r\n {humanTime(new Date(element.visitedAt()))}\r\n \r\n );\r\n });\r\n\r\n items.add('lastViewedUsers', FieldSet.component({\r\n label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'),\r\n className: 'LastUsers',\r\n children: lastViewed.toArray()\r\n }));\r\n\r\n console.log(lastViewed.toArray());\r\n });\r\n });\r\n\r\n extend(UserPage.prototype, 'show', function() {\r\n if(typeof app.session.user !== 'undefined' && app.session.user.id() !== this.user.id())\r\n {\r\n app.request({\r\n method: 'POST',\r\n url: app.forum.attribute('apiUrl') + '/profileview/' + this.user.id(),\r\n data: { viewer: app.session.user.id() }\r\n });\r\n }\r\n });\r\n});"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack://@michaelbelgium/flarum-profile-views/webpack/bootstrap","webpack://@michaelbelgium/flarum-profile-views/./forum.js","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/defineProperty.js","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/inheritsLoose.js","webpack://@michaelbelgium/flarum-profile-views/./src/ProfileView.js","webpack://@michaelbelgium/flarum-profile-views/./src/forum/index.js","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['Model']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['app']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/FieldSet']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/UserCard']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/UserPage']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['extend']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/avatar']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/icon']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/username']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['models/User']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['utils/ItemList']\""],"names":["ProfileView","Model","attribute","transformDate","hasOne","app","initializers","add","store","models","profileviews","User","prototype","profileViews","hasMany","console","log","all","extend","UserCard","items","user","props","icon","translator","trans","viewcount","length","UserPage","lastViewed","ItemList","$","each","index","view","session","id","request","method","url","forum","data","viewer"],"mappings":";;AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA,kDAA0C,gCAAgC;AAC1E;AACA;;AAEA;AACA;AACA;AACA,gEAAwD,kBAAkB;AAC1E;AACA,yDAAiD,cAAc;AAC/D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iDAAyC,iCAAiC;AAC1E,wHAAgH,mBAAmB,EAAE;AACrI;AACA;;AAEA;AACA;AACA;AACA,mCAA2B,0BAA0B,EAAE;AACvD,yCAAiC,eAAe;AAChD;AACA;AACA;;AAEA;AACA,8DAAsD,+DAA+D;;AAErH;AACA;;;AAGA;AACA;;;;;;;;;;;;;AClFA;AAAA;AAAA,wC;;;;;;;;;;;;ACAA;AAAA;AAAe;A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;AACJ,GATK,CAAN;AAUH,CAnDD,E;;;;;;;;;;;ACbA,6C;;;;;;;;;;;ACAA,2C;;;;;;;;;;;ACAA,2D;;;;;;;;;;;ACAA,2D;;;;;;;;;;;ACAA,2D;;;;;;;;;;;ACAA,8C;;;;;;;;;;;ACAA,sD;;;;;;;;;;;ACAA,oD;;;;;;;;;;;ACAA,wD;;;;;;;;;;;ACAA,mD;;;;;;;;;;;ACAA,sD","file":"forum.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = \"./forum.js\");\n","export * from './src/forum';","export default function _assertThisInitialized(self) {\n if (self === void 0) {\n throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\");\n }\n\n return self;\n}","export default function _defineProperty(obj, key, value) {\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n\n return obj;\n}","export default function _inheritsLoose(subClass, superClass) {\n subClass.prototype = Object.create(superClass.prototype);\n subClass.prototype.constructor = subClass;\n subClass.__proto__ = superClass;\n}","import Model from 'flarum/Model';\r\n\r\nexport default class ProfileView extends Model {\r\n //comes from ProfileViewSerializer (viewer(), viewedUser(), visited_at)\r\n visitedAt = Model.attribute('visited_at', Model.transformDate);\r\n viewer = Model.hasOne('viewer');\r\n viewedUser = Model.hasOne('viewedUser');\r\n}","import app from 'flarum/app';\r\nimport User from 'flarum/models/User';\r\nimport UserPage from 'flarum/components/UserPage';\r\nimport UserCard from 'flarum/components/UserCard';\r\nimport FieldSet from 'flarum/components/FieldSet';\r\nimport icon from 'flarum/helpers/icon';\r\nimport avatar from 'flarum/helpers/avatar';\r\nimport username from 'flarum/helpers/username';\r\nimport Model from 'flarum/Model';\r\nimport ItemList from 'flarum/utils/ItemList';\r\nimport { extend } from 'flarum/extend';\r\nimport ProfileView from '../ProfileView';\r\n\r\napp.initializers.add('michaelbelgium-flarum-profile-views', function() {\r\n app.store.models.profileviews = ProfileView;\r\n User.prototype.profileViews = Model.hasMany('profileviews');//comes from the line above: \"app.store.models.\"profileviews\"\r\n\r\n // app.store.find('profileviews').then(console.log);\r\n console.log(app.store.all('profileviews'));\r\n extend(UserCard.prototype, 'infoItems', function(items) {\r\n const user = this.props.user;\r\n\r\n items.add('profile-views',(\r\n \r\n {icon('far fa-eye')}\r\n {' '}\r\n {app.translator.trans('flarum_profile_views.forum.user.views_count_text', {viewcount: '' + (user.profileViews() === false ? '0' : user.profileViews().length)})}\r\n \r\n ));\r\n });\r\n\r\n extend(UserPage.prototype, 'sidebarItems', function(items) {\r\n const lastViewed = new ItemList();\r\n\r\n console.log(this.user);\r\n console.log(this.user.profileViews());\r\n $.each(this.user.profileViews(), function(index, view) {\r\n\r\n console.log(view);\r\n // lastViewed.add('lastUser-' + viewer.id(),\r\n // \r\n // {avatar(viewer, {className: 'lastUser-avatar'})}\r\n // {username(viewer, {className: 'lastUser-name'})}\r\n // \r\n // );\r\n });\r\n\r\n // items.add('lastViewedUsers', FieldSet.component({\r\n // label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'),\r\n // className: 'LastUsers',\r\n // children: lastViewed.toArray()\r\n // }));\r\n });\r\n\r\n extend(UserPage.prototype, 'show', function() {\r\n if(typeof app.session.user !== 'undefined' && app.session.user.id() !== this.user.id())\r\n {\r\n app.request({\r\n method: 'POST',\r\n url: app.forum.attribute('apiUrl') + '/profileview/' + this.user.id(),\r\n data: { viewer: app.session.user.id() }\r\n });\r\n }\r\n });\r\n});","module.exports = flarum.core.compat['Model'];","module.exports = flarum.core.compat['app'];","module.exports = flarum.core.compat['components/FieldSet'];","module.exports = flarum.core.compat['components/UserCard'];","module.exports = flarum.core.compat['components/UserPage'];","module.exports = flarum.core.compat['extend'];","module.exports = flarum.core.compat['helpers/avatar'];","module.exports = flarum.core.compat['helpers/icon'];","module.exports = flarum.core.compat['helpers/username'];","module.exports = flarum.core.compat['models/User'];","module.exports = flarum.core.compat['utils/ItemList'];"],"sourceRoot":""} \ No newline at end of file diff --git a/js/src/ProfileView.js b/js/src/ProfileView.js index b50cffc..a20b234 100644 --- a/js/src/ProfileView.js +++ b/js/src/ProfileView.js @@ -1,6 +1,7 @@ import Model from 'flarum/Model'; export default class ProfileView extends Model { + //comes from ProfileViewSerializer (viewer(), viewedUser(), visited_at) visitedAt = Model.attribute('visited_at', Model.transformDate); viewer = Model.hasOne('viewer'); viewedUser = Model.hasOne('viewedUser'); diff --git a/js/src/forum/index.js b/js/src/forum/index.js index e6b0718..bd6c0d8 100644 --- a/js/src/forum/index.js +++ b/js/src/forum/index.js @@ -10,11 +10,13 @@ import Model from 'flarum/Model'; import ItemList from 'flarum/utils/ItemList'; import { extend } from 'flarum/extend'; import ProfileView from '../ProfileView'; -import humanTime from 'flarum/utils/humanTime'; app.initializers.add('michaelbelgium-flarum-profile-views', function() { - User.prototype.profileViews = Model.hasMany('profileViews'); + app.store.models.profileviews = ProfileView; + User.prototype.profileViews = Model.hasMany('profileviews');//comes from the line above: "app.store.models."profileviews" + // app.store.find('profileviews').then(console.log); + console.log(app.store.all('profileviews')); extend(UserCard.prototype, 'infoItems', function(items) { const user = this.props.user; @@ -22,38 +24,32 @@ app.initializers.add('michaelbelgium-flarum-profile-views', function() { {icon('far fa-eye')} {' '} - {app.translator.trans('flarum_profile_views.forum.user.views_count_text', {viewcount: 'todo'})} + {app.translator.trans('flarum_profile_views.forum.user.views_count_text', {viewcount: '' + (user.profileViews() === false ? '0' : user.profileViews().length)})} )); }); extend(UserPage.prototype, 'sidebarItems', function(items) { - app.request({ - method: 'GET', - url: app.forum.attribute('apiUrl') + '/profileview', - }).then(data => { - var profileViews = data.data.map(obj => new ProfileView(obj)); - var views = profileViews.filter(obj => obj.viewedUser() == this.user); - var lastViewed = new ItemList(); + const lastViewed = new ItemList(); - views.forEach(element => { - lastViewed.add('lastUser-' + element.viewer().id(), - - {avatar(element.viewer(), {className: 'lastUser-avatar'})} - {username(element.viewer(), {className: 'lastUser-name'})} - {humanTime(new Date(element.visitedAt()))} - - ); - }); - - items.add('lastViewedUsers', FieldSet.component({ - label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'), - className: 'LastUsers', - children: lastViewed.toArray() - })); + console.log(this.user); + console.log(this.user.profileViews()); + $.each(this.user.profileViews(), function(index, view) { - console.log(lastViewed.toArray()); + console.log(view); + // lastViewed.add('lastUser-' + viewer.id(), + // + // {avatar(viewer, {className: 'lastUser-avatar'})} + // {username(viewer, {className: 'lastUser-name'})} + // + // ); }); + + // items.add('lastViewedUsers', FieldSet.component({ + // label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'), + // className: 'LastUsers', + // children: lastViewed.toArray() + // })); }); extend(UserPage.prototype, 'show', function() { diff --git a/src/Listeners/AddUserProfileViewsRelationship.php b/src/Listeners/AddUserProfileViewsRelationship.php new file mode 100644 index 0000000..775435f --- /dev/null +++ b/src/Listeners/AddUserProfileViewsRelationship.php @@ -0,0 +1,66 @@ +profileViews() + const RELATIONSHIP_OTHER = "viewedProfiles"; //$user->viewedProfiles() + + /** + * @param Dispatcher $events + */ + public function subscribe(Dispatcher $events) + { + $events->listen(WillGetData::class, [$this, 'includeTagsRelationship']); + $events->listen(GetModelRelationship::class, [$this, 'getModelRelationship']); + $events->listen(GetApiRelationship::class, [$this, 'GetApiRelationship']); + } + + public function getModelRelationship(GetModelRelationship $event) + { + if($event->isRelationship(User::class, self::RELATIONSHIP)) + { + return $event->model->hasMany(UserProfileView::class, 'viewed_user_id'); + } + + if($event->isRelationship(User::class, self::RELATIONSHIP_OTHER)) + { + return $event->model->hasMany(UserProfileView::class, 'viewer_id'); + } + } + + /** + * @param GetApiRelationship $event + * @return \Tobscure\JsonApi\Relationship|null + */ + public function getApiRelationship(GetApiRelationship $event) + { + if ($event->isRelationship(UserSerializer::class, self::RELATIONSHIP)) { + return $event->serializer->hasMany($event->model, UserProfileViewSerializer::class, self::RELATIONSHIP); + } + + //todo test: + if ($event->isRelationship(UserSerializer::class, self::RELATIONSHIP_OTHER)) { + return $event->serializer->hasMany($event->model, UserProfileViewSerializer::class, self::RELATIONSHIP_OTHER); + } + } + + /** + * @param WillGetData $event + */ + public function includeTagsRelationship(WillGetData $event) + { + if($event->controller->serializer == UserSerializer::class) + $event->addInclude([self::RELATIONSHIP, self::RELATIONSHIP.'.viewer', self::RELATIONSHIP.'.viewedUser']);//".x" comes from model relationship UserProfileView + } +} \ No newline at end of file diff --git a/src/controllers/CreateUserProfileViewController.php b/src/controllers/CreateUserProfileViewController.php index dc6756f..d7a4b47 100644 --- a/src/controllers/CreateUserProfileViewController.php +++ b/src/controllers/CreateUserProfileViewController.php @@ -16,19 +16,22 @@ public function handle(Request $request): Response { $userId = array_get($request->getQueryParams(), 'id'); $viewerId = array_get($request->getParsedBody(), 'viewer'); + $user = User::find($userId); - $profileView = UserProfileView::where('viewer_id', $viewerId)->where('viewed_user_id', $userId)->first(); + $test = $user->profileViews; + $testOther = $user->viewedProfiles; - if(is_null($profileView)) - { + $profileView = $user->profileViews()->where('viewer_id', $viewerId)->first(); + + if(is_null($profileView)) { $profileView = new UserProfileView(); + $profileView->viewedUser()->associate($user); $profileView->viewer()->associate(User::find($viewerId)); - $profileView->viewedUser()->associate(User::find($userId)); } - $profileView->visited_at = Carbon::now(); + $profileView->visited_at = Carbon::now(); $profileView->save(); - + return new EmptyResponse(); } } \ No newline at end of file diff --git a/src/controllers/ListProfileViewsController.php b/src/controllers/ListProfileViewsController.php deleted file mode 100644 index 4799fd7..0000000 --- a/src/controllers/ListProfileViewsController.php +++ /dev/null @@ -1,32 +0,0 @@ - 'desc']; - - protected function data(ServerRequestInterface $request, Document $document) - { - // $this->extractInclude($request); - - $sort = $this->extractSort($request); - - $query = UserProfileView::query(); - - foreach ($sort as $field => $order) { - $query->orderBy(snake_case($field), $order); - } - - return $query->get(); - } -} \ No newline at end of file From c6bb92d2e2993de1247f572868cf0a8053688a6b Mon Sep 17 00:00:00 2001 From: Michael V Date: Sat, 19 Jan 2019 16:22:59 +0100 Subject: [PATCH 28/37] npm build --- js/dist/forum.js | 429 +----------------- js/dist/forum.js.map | 2 +- js/src/forum/index.js | 3 - src/Models/UserProfileView.php | 1 - src/Serializers/UserProfileViewSerializer.php | 2 +- 5 files changed, 3 insertions(+), 434 deletions(-) diff --git a/js/dist/forum.js b/js/dist/forum.js index be8c214..42318fb 100644 --- a/js/dist/forum.js +++ b/js/dist/forum.js @@ -1,429 +1,2 @@ -module.exports = -/******/ (function(modules) { // webpackBootstrap -/******/ // The module cache -/******/ var installedModules = {}; -/******/ -/******/ // The require function -/******/ function __webpack_require__(moduleId) { -/******/ -/******/ // Check if module is in cache -/******/ if(installedModules[moduleId]) { -/******/ return installedModules[moduleId].exports; -/******/ } -/******/ // Create a new module (and put it into the cache) -/******/ var module = installedModules[moduleId] = { -/******/ i: moduleId, -/******/ l: false, -/******/ exports: {} -/******/ }; -/******/ -/******/ // Execute the module function -/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); -/******/ -/******/ // Flag the module as loaded -/******/ module.l = true; -/******/ -/******/ // Return the exports of the module -/******/ return module.exports; -/******/ } -/******/ -/******/ -/******/ // expose the modules object (__webpack_modules__) -/******/ __webpack_require__.m = modules; -/******/ -/******/ // expose the module cache -/******/ __webpack_require__.c = installedModules; -/******/ -/******/ // define getter function for harmony exports -/******/ __webpack_require__.d = function(exports, name, getter) { -/******/ if(!__webpack_require__.o(exports, name)) { -/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); -/******/ } -/******/ }; -/******/ -/******/ // define __esModule on exports -/******/ __webpack_require__.r = function(exports) { -/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { -/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); -/******/ } -/******/ Object.defineProperty(exports, '__esModule', { value: true }); -/******/ }; -/******/ -/******/ // create a fake namespace object -/******/ // mode & 1: value is a module id, require it -/******/ // mode & 2: merge all properties of value into the ns -/******/ // mode & 4: return value when already ns object -/******/ // mode & 8|1: behave like require -/******/ __webpack_require__.t = function(value, mode) { -/******/ if(mode & 1) value = __webpack_require__(value); -/******/ if(mode & 8) return value; -/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; -/******/ var ns = Object.create(null); -/******/ __webpack_require__.r(ns); -/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); -/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); -/******/ return ns; -/******/ }; -/******/ -/******/ // getDefaultExport function for compatibility with non-harmony modules -/******/ __webpack_require__.n = function(module) { -/******/ var getter = module && module.__esModule ? -/******/ function getDefault() { return module['default']; } : -/******/ function getModuleExports() { return module; }; -/******/ __webpack_require__.d(getter, 'a', getter); -/******/ return getter; -/******/ }; -/******/ -/******/ // Object.prototype.hasOwnProperty.call -/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; -/******/ -/******/ // __webpack_public_path__ -/******/ __webpack_require__.p = ""; -/******/ -/******/ -/******/ // Load entry module and return exports -/******/ return __webpack_require__(__webpack_require__.s = "./forum.js"); -/******/ }) -/************************************************************************/ -/******/ ({ - -/***/ "./forum.js": -/*!******************!*\ - !*** ./forum.js ***! - \******************/ -/*! no exports provided */ -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */ var _src_forum__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./src/forum */ "./src/forum/index.js"); -/* empty/unused harmony star reexport */ - -/***/ }), - -/***/ "./node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js": -/*!**************************************************************************!*\ - !*** ./node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js ***! - \**************************************************************************/ -/*! exports provided: default */ -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return _assertThisInitialized; }); -function _assertThisInitialized(self) { - if (self === void 0) { - throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - } - - return self; -} - -/***/ }), - -/***/ "./node_modules/@babel/runtime/helpers/esm/defineProperty.js": -/*!*******************************************************************!*\ - !*** ./node_modules/@babel/runtime/helpers/esm/defineProperty.js ***! - \*******************************************************************/ -/*! exports provided: default */ -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return _defineProperty; }); -function _defineProperty(obj, key, value) { - if (key in obj) { - Object.defineProperty(obj, key, { - value: value, - enumerable: true, - configurable: true, - writable: true - }); - } else { - obj[key] = value; - } - - return obj; -} - -/***/ }), - -/***/ "./node_modules/@babel/runtime/helpers/esm/inheritsLoose.js": -/*!******************************************************************!*\ - !*** ./node_modules/@babel/runtime/helpers/esm/inheritsLoose.js ***! - \******************************************************************/ -/*! exports provided: default */ -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return _inheritsLoose; }); -function _inheritsLoose(subClass, superClass) { - subClass.prototype = Object.create(superClass.prototype); - subClass.prototype.constructor = subClass; - subClass.__proto__ = superClass; -} - -/***/ }), - -/***/ "./src/ProfileView.js": -/*!****************************!*\ - !*** ./src/ProfileView.js ***! - \****************************/ -/*! exports provided: default */ -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return ProfileView; }); -/* harmony import */ var _babel_runtime_helpers_esm_inheritsLoose__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/esm/inheritsLoose */ "./node_modules/@babel/runtime/helpers/esm/inheritsLoose.js"); -/* harmony import */ var _babel_runtime_helpers_esm_assertThisInitialized__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/esm/assertThisInitialized */ "./node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js"); -/* harmony import */ var _babel_runtime_helpers_esm_defineProperty__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/esm/defineProperty */ "./node_modules/@babel/runtime/helpers/esm/defineProperty.js"); -/* harmony import */ var flarum_Model__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! flarum/Model */ "flarum/Model"); -/* harmony import */ var flarum_Model__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(flarum_Model__WEBPACK_IMPORTED_MODULE_3__); - - - - - -var ProfileView = -/*#__PURE__*/ -function (_Model) { - Object(_babel_runtime_helpers_esm_inheritsLoose__WEBPACK_IMPORTED_MODULE_0__["default"])(ProfileView, _Model); - - function ProfileView() { - var _this; - - for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { - args[_key] = arguments[_key]; - } - - _this = _Model.call.apply(_Model, [this].concat(args)) || this; - - Object(_babel_runtime_helpers_esm_defineProperty__WEBPACK_IMPORTED_MODULE_2__["default"])(Object(_babel_runtime_helpers_esm_assertThisInitialized__WEBPACK_IMPORTED_MODULE_1__["default"])(Object(_babel_runtime_helpers_esm_assertThisInitialized__WEBPACK_IMPORTED_MODULE_1__["default"])(_this)), "visitedAt", flarum_Model__WEBPACK_IMPORTED_MODULE_3___default.a.attribute('visited_at', flarum_Model__WEBPACK_IMPORTED_MODULE_3___default.a.transformDate)); - - Object(_babel_runtime_helpers_esm_defineProperty__WEBPACK_IMPORTED_MODULE_2__["default"])(Object(_babel_runtime_helpers_esm_assertThisInitialized__WEBPACK_IMPORTED_MODULE_1__["default"])(Object(_babel_runtime_helpers_esm_assertThisInitialized__WEBPACK_IMPORTED_MODULE_1__["default"])(_this)), "viewer", flarum_Model__WEBPACK_IMPORTED_MODULE_3___default.a.hasOne('viewer')); - - Object(_babel_runtime_helpers_esm_defineProperty__WEBPACK_IMPORTED_MODULE_2__["default"])(Object(_babel_runtime_helpers_esm_assertThisInitialized__WEBPACK_IMPORTED_MODULE_1__["default"])(Object(_babel_runtime_helpers_esm_assertThisInitialized__WEBPACK_IMPORTED_MODULE_1__["default"])(_this)), "viewedUser", flarum_Model__WEBPACK_IMPORTED_MODULE_3___default.a.hasOne('viewedUser')); - - return _this; - } - - return ProfileView; -}(flarum_Model__WEBPACK_IMPORTED_MODULE_3___default.a); - - - -/***/ }), - -/***/ "./src/forum/index.js": -/*!****************************!*\ - !*** ./src/forum/index.js ***! - \****************************/ -/*! no exports provided */ -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */ var flarum_app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! flarum/app */ "flarum/app"); -/* harmony import */ var flarum_app__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(flarum_app__WEBPACK_IMPORTED_MODULE_0__); -/* harmony import */ var flarum_models_User__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! flarum/models/User */ "flarum/models/User"); -/* harmony import */ var flarum_models_User__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(flarum_models_User__WEBPACK_IMPORTED_MODULE_1__); -/* harmony import */ var flarum_components_UserPage__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! flarum/components/UserPage */ "flarum/components/UserPage"); -/* harmony import */ var flarum_components_UserPage__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(flarum_components_UserPage__WEBPACK_IMPORTED_MODULE_2__); -/* harmony import */ var flarum_components_UserCard__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! flarum/components/UserCard */ "flarum/components/UserCard"); -/* harmony import */ var flarum_components_UserCard__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(flarum_components_UserCard__WEBPACK_IMPORTED_MODULE_3__); -/* harmony import */ var flarum_components_FieldSet__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! flarum/components/FieldSet */ "flarum/components/FieldSet"); -/* harmony import */ var flarum_components_FieldSet__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(flarum_components_FieldSet__WEBPACK_IMPORTED_MODULE_4__); -/* harmony import */ var flarum_helpers_icon__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! flarum/helpers/icon */ "flarum/helpers/icon"); -/* harmony import */ var flarum_helpers_icon__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(flarum_helpers_icon__WEBPACK_IMPORTED_MODULE_5__); -/* harmony import */ var flarum_helpers_avatar__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! flarum/helpers/avatar */ "flarum/helpers/avatar"); -/* harmony import */ var flarum_helpers_avatar__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(flarum_helpers_avatar__WEBPACK_IMPORTED_MODULE_6__); -/* harmony import */ var flarum_helpers_username__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! flarum/helpers/username */ "flarum/helpers/username"); -/* harmony import */ var flarum_helpers_username__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(flarum_helpers_username__WEBPACK_IMPORTED_MODULE_7__); -/* harmony import */ var flarum_Model__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! flarum/Model */ "flarum/Model"); -/* harmony import */ var flarum_Model__WEBPACK_IMPORTED_MODULE_8___default = /*#__PURE__*/__webpack_require__.n(flarum_Model__WEBPACK_IMPORTED_MODULE_8__); -/* harmony import */ var flarum_utils_ItemList__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! flarum/utils/ItemList */ "flarum/utils/ItemList"); -/* harmony import */ var flarum_utils_ItemList__WEBPACK_IMPORTED_MODULE_9___default = /*#__PURE__*/__webpack_require__.n(flarum_utils_ItemList__WEBPACK_IMPORTED_MODULE_9__); -/* harmony import */ var flarum_extend__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! flarum/extend */ "flarum/extend"); -/* harmony import */ var flarum_extend__WEBPACK_IMPORTED_MODULE_10___default = /*#__PURE__*/__webpack_require__.n(flarum_extend__WEBPACK_IMPORTED_MODULE_10__); -/* harmony import */ var _ProfileView__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ../ProfileView */ "./src/ProfileView.js"); - - - - - - - - - - - - -flarum_app__WEBPACK_IMPORTED_MODULE_0___default.a.initializers.add('michaelbelgium-flarum-profile-views', function () { - flarum_app__WEBPACK_IMPORTED_MODULE_0___default.a.store.models.profileviews = _ProfileView__WEBPACK_IMPORTED_MODULE_11__["default"]; - flarum_models_User__WEBPACK_IMPORTED_MODULE_1___default.a.prototype.profileViews = flarum_Model__WEBPACK_IMPORTED_MODULE_8___default.a.hasMany('profileviews'); //comes from the line above: "app.store.models."profileviews" - // app.store.find('profileviews').then(console.log); - - console.log(flarum_app__WEBPACK_IMPORTED_MODULE_0___default.a.store.all('profileviews')); - Object(flarum_extend__WEBPACK_IMPORTED_MODULE_10__["extend"])(flarum_components_UserCard__WEBPACK_IMPORTED_MODULE_3___default.a.prototype, 'infoItems', function (items) { - var user = this.props.user; - items.add('profile-views', m("span", null, flarum_helpers_icon__WEBPACK_IMPORTED_MODULE_5___default()('far fa-eye'), ' ', flarum_app__WEBPACK_IMPORTED_MODULE_0___default.a.translator.trans('flarum_profile_views.forum.user.views_count_text', { - viewcount: '' + (user.profileViews() === false ? '0' : user.profileViews().length) - }))); - }); - Object(flarum_extend__WEBPACK_IMPORTED_MODULE_10__["extend"])(flarum_components_UserPage__WEBPACK_IMPORTED_MODULE_2___default.a.prototype, 'sidebarItems', function (items) { - var lastViewed = new flarum_utils_ItemList__WEBPACK_IMPORTED_MODULE_9___default.a(); - console.log(this.user); - console.log(this.user.profileViews()); - $.each(this.user.profileViews(), function (index, view) { - console.log(view); // lastViewed.add('lastUser-' + viewer.id(), - // - // {avatar(viewer, {className: 'lastUser-avatar'})} - // {username(viewer, {className: 'lastUser-name'})} - // - // ); - }); // items.add('lastViewedUsers', FieldSet.component({ - // label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'), - // className: 'LastUsers', - // children: lastViewed.toArray() - // })); - }); - Object(flarum_extend__WEBPACK_IMPORTED_MODULE_10__["extend"])(flarum_components_UserPage__WEBPACK_IMPORTED_MODULE_2___default.a.prototype, 'show', function () { - if (typeof flarum_app__WEBPACK_IMPORTED_MODULE_0___default.a.session.user !== 'undefined' && flarum_app__WEBPACK_IMPORTED_MODULE_0___default.a.session.user.id() !== this.user.id()) { - flarum_app__WEBPACK_IMPORTED_MODULE_0___default.a.request({ - method: 'POST', - url: flarum_app__WEBPACK_IMPORTED_MODULE_0___default.a.forum.attribute('apiUrl') + '/profileview/' + this.user.id(), - data: { - viewer: flarum_app__WEBPACK_IMPORTED_MODULE_0___default.a.session.user.id() - } - }); - } - }); -}); - -/***/ }), - -/***/ "flarum/Model": -/*!**********************************************!*\ - !*** external "flarum.core.compat['Model']" ***! - \**********************************************/ -/*! no static exports found */ -/***/ (function(module, exports) { - -module.exports = flarum.core.compat['Model']; - -/***/ }), - -/***/ "flarum/app": -/*!********************************************!*\ - !*** external "flarum.core.compat['app']" ***! - \********************************************/ -/*! no static exports found */ -/***/ (function(module, exports) { - -module.exports = flarum.core.compat['app']; - -/***/ }), - -/***/ "flarum/components/FieldSet": -/*!************************************************************!*\ - !*** external "flarum.core.compat['components/FieldSet']" ***! - \************************************************************/ -/*! no static exports found */ -/***/ (function(module, exports) { - -module.exports = flarum.core.compat['components/FieldSet']; - -/***/ }), - -/***/ "flarum/components/UserCard": -/*!************************************************************!*\ - !*** external "flarum.core.compat['components/UserCard']" ***! - \************************************************************/ -/*! no static exports found */ -/***/ (function(module, exports) { - -module.exports = flarum.core.compat['components/UserCard']; - -/***/ }), - -/***/ "flarum/components/UserPage": -/*!************************************************************!*\ - !*** external "flarum.core.compat['components/UserPage']" ***! - \************************************************************/ -/*! no static exports found */ -/***/ (function(module, exports) { - -module.exports = flarum.core.compat['components/UserPage']; - -/***/ }), - -/***/ "flarum/extend": -/*!***********************************************!*\ - !*** external "flarum.core.compat['extend']" ***! - \***********************************************/ -/*! no static exports found */ -/***/ (function(module, exports) { - -module.exports = flarum.core.compat['extend']; - -/***/ }), - -/***/ "flarum/helpers/avatar": -/*!*******************************************************!*\ - !*** external "flarum.core.compat['helpers/avatar']" ***! - \*******************************************************/ -/*! no static exports found */ -/***/ (function(module, exports) { - -module.exports = flarum.core.compat['helpers/avatar']; - -/***/ }), - -/***/ "flarum/helpers/icon": -/*!*****************************************************!*\ - !*** external "flarum.core.compat['helpers/icon']" ***! - \*****************************************************/ -/*! no static exports found */ -/***/ (function(module, exports) { - -module.exports = flarum.core.compat['helpers/icon']; - -/***/ }), - -/***/ "flarum/helpers/username": -/*!*********************************************************!*\ - !*** external "flarum.core.compat['helpers/username']" ***! - \*********************************************************/ -/*! no static exports found */ -/***/ (function(module, exports) { - -module.exports = flarum.core.compat['helpers/username']; - -/***/ }), - -/***/ "flarum/models/User": -/*!****************************************************!*\ - !*** external "flarum.core.compat['models/User']" ***! - \****************************************************/ -/*! no static exports found */ -/***/ (function(module, exports) { - -module.exports = flarum.core.compat['models/User']; - -/***/ }), - -/***/ "flarum/utils/ItemList": -/*!*******************************************************!*\ - !*** external "flarum.core.compat['utils/ItemList']" ***! - \*******************************************************/ -/*! no static exports found */ -/***/ (function(module, exports) { - -module.exports = flarum.core.compat['utils/ItemList']; - -/***/ }) - -/******/ }); +module.exports=function(e){var t={};function r(o){if(t[o])return t[o].exports;var n=t[o]={i:o,l:!1,exports:{}};return e[o].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.m=e,r.c=t,r.d=function(e,t,o){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(r.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)r.d(o,n,function(t){return e[t]}.bind(null,n));return o},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=11)}([function(e,t){e.exports=flarum.core.compat.app},function(e,t){e.exports=flarum.core.compat.Model},function(e,t){e.exports=flarum.core.compat.extend},function(e,t){e.exports=flarum.core.compat["components/UserPage"]},function(e,t){e.exports=flarum.core.compat["models/User"]},function(e,t){e.exports=flarum.core.compat["components/UserCard"]},function(e,t){e.exports=flarum.core.compat["helpers/icon"]},function(e,t){e.exports=flarum.core.compat["utils/ItemList"]},function(e,t){e.exports=flarum.core.compat["components/FieldSet"]},function(e,t){e.exports=flarum.core.compat["helpers/avatar"]},function(e,t){e.exports=flarum.core.compat["helpers/username"]},function(e,t,r){"use strict";r.r(t);var o=r(0),n=r.n(o),i=r(4),a=r.n(i),s=r(3),u=r.n(s),c=r(5),f=r.n(c),l=(r(8),r(6)),p=r.n(l),d=(r(9),r(10),r(1)),v=r.n(d),b=r(7),w=r.n(b),h=r(2);function y(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function x(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var O=function(e){var t,r;function o(){for(var t,r=arguments.length,o=new Array(r),n=0;n\r\n {icon('far fa-eye')}\r\n {' '}\r\n {app.translator.trans('flarum_profile_views.forum.user.views_count_text', {viewcount: '' + (user.profileViews() === false ? '0' : user.profileViews().length)})}\r\n \r\n ));\r\n });\r\n\r\n extend(UserPage.prototype, 'sidebarItems', function(items) {\r\n const lastViewed = new ItemList();\r\n\r\n console.log(this.user);\r\n console.log(this.user.profileViews());\r\n $.each(this.user.profileViews(), function(index, view) {\r\n\r\n console.log(view);\r\n // lastViewed.add('lastUser-' + viewer.id(),\r\n // \r\n // {avatar(viewer, {className: 'lastUser-avatar'})}\r\n // {username(viewer, {className: 'lastUser-name'})}\r\n // \r\n // );\r\n });\r\n\r\n // items.add('lastViewedUsers', FieldSet.component({\r\n // label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'),\r\n // className: 'LastUsers',\r\n // children: lastViewed.toArray()\r\n // }));\r\n });\r\n\r\n extend(UserPage.prototype, 'show', function() {\r\n if(typeof app.session.user !== 'undefined' && app.session.user.id() !== this.user.id())\r\n {\r\n app.request({\r\n method: 'POST',\r\n url: app.forum.attribute('apiUrl') + '/profileview/' + this.user.id(),\r\n data: { viewer: app.session.user.id() }\r\n });\r\n }\r\n });\r\n});","module.exports = flarum.core.compat['Model'];","module.exports = flarum.core.compat['app'];","module.exports = flarum.core.compat['components/FieldSet'];","module.exports = flarum.core.compat['components/UserCard'];","module.exports = flarum.core.compat['components/UserPage'];","module.exports = flarum.core.compat['extend'];","module.exports = flarum.core.compat['helpers/avatar'];","module.exports = flarum.core.compat['helpers/icon'];","module.exports = flarum.core.compat['helpers/username'];","module.exports = flarum.core.compat['models/User'];","module.exports = flarum.core.compat['utils/ItemList'];"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack://@michaelbelgium/flarum-profile-views/webpack/bootstrap","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['app']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['Model']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['extend']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/UserPage']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['models/User']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/UserCard']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/icon']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['utils/ItemList']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/FieldSet']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/avatar']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/username']\"","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/defineProperty.js","webpack://@michaelbelgium/flarum-profile-views/./src/ProfileView.js","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/inheritsLoose.js","webpack://@michaelbelgium/flarum-profile-views/./src/forum/index.js"],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","flarum","core","compat","_assertThisInitialized","self","ReferenceError","_defineProperty","obj","configurable","writable","ProfileView","subClass","superClass","Model","attribute","transformDate","hasOne","constructor","__proto__","app","initializers","add","store","models","profileviews","User","profileViews","hasMany","extend","UserCard","items","user","this","props","icon","translator","trans","viewcount","length","UserPage","ItemList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GAC7C,IAAMC,EAAOC,KAAKC,MAAMF,KAExBD,EAAMT,IAAI,gBACNjD,EAAA,YACK8D,IAAK,cACL,IACAf,IAAIgB,WAAWC,MAAM,mDAAoD,CAACC,UAAW,KAA8B,IAAxBN,EAAKL,eAA2B,IAAMK,EAAKL,eAAeY,cAKlKV,iBAAOW,IAAS3C,UAAW,eAAgB,SAASkC,GAC7B,IAAIU,IAEvBC,QAAQC,IAAIV,KAAKD,KAAKL,gBACtBiB,EAAEC,KAAKZ,KAAKD,KAAKL,eAAgB,SAASmB,EAAOC,GAE7CL,QAAQC,IAAII,OAgBpBlB,iBAAOW,IAAS3C,UAAW,OAAQ,gBACA,IAArBuB,IAAI4B,QAAQhB,MAAwBZ,IAAI4B,QAAQhB,KAAKiB,OAAShB,KAAKD,KAAKiB,MAE9E7B,IAAI8B,QAAQ,CACRC,OAAQ,OACRC,IAAKhC,IAAIiC,MAAMtC,UAAU,UAAY,gBAAkBkB,KAAKD,KAAKiB,KACjEK,KAAM,CAAEC,OAAQnC,IAAI4B,QAAQhB,KAAKiB","file":"forum.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 11);\n","module.exports = flarum.core.compat['app'];","module.exports = flarum.core.compat['Model'];","module.exports = flarum.core.compat['extend'];","module.exports = flarum.core.compat['components/UserPage'];","module.exports = flarum.core.compat['models/User'];","module.exports = flarum.core.compat['components/UserCard'];","module.exports = flarum.core.compat['helpers/icon'];","module.exports = flarum.core.compat['utils/ItemList'];","module.exports = flarum.core.compat['components/FieldSet'];","module.exports = flarum.core.compat['helpers/avatar'];","module.exports = flarum.core.compat['helpers/username'];","export default function _assertThisInitialized(self) {\n if (self === void 0) {\n throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\");\n }\n\n return self;\n}","export default function _defineProperty(obj, key, value) {\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n\n return obj;\n}","import Model from 'flarum/Model';\r\n\r\nexport default class ProfileView extends Model {\r\n //comes from ProfileViewSerializer (viewer(), viewedUser(), visited_at)\r\n visitedAt = Model.attribute('visited_at', Model.transformDate);\r\n viewer = Model.hasOne('viewer');\r\n viewedUser = Model.hasOne('viewedUser');\r\n}","export default function _inheritsLoose(subClass, superClass) {\n subClass.prototype = Object.create(superClass.prototype);\n subClass.prototype.constructor = subClass;\n subClass.__proto__ = superClass;\n}","import app from 'flarum/app';\r\nimport User from 'flarum/models/User';\r\nimport UserPage from 'flarum/components/UserPage';\r\nimport UserCard from 'flarum/components/UserCard';\r\nimport FieldSet from 'flarum/components/FieldSet';\r\nimport icon from 'flarum/helpers/icon';\r\nimport avatar from 'flarum/helpers/avatar';\r\nimport username from 'flarum/helpers/username';\r\nimport Model from 'flarum/Model';\r\nimport ItemList from 'flarum/utils/ItemList';\r\nimport { extend } from 'flarum/extend';\r\nimport ProfileView from '../ProfileView';\r\n\r\napp.initializers.add('michaelbelgium-flarum-profile-views', function() {\r\n app.store.models.profileviews = ProfileView;\r\n User.prototype.profileViews = Model.hasMany('profileviews');//comes from the line above: \"app.store.models.\"profileviews\"\r\n\r\n extend(UserCard.prototype, 'infoItems', function(items) {\r\n const user = this.props.user;\r\n\r\n items.add('profile-views',(\r\n \r\n {icon('far fa-eye')}\r\n {' '}\r\n {app.translator.trans('flarum_profile_views.forum.user.views_count_text', {viewcount: '' + (user.profileViews() === false ? '0' : user.profileViews().length)})}\r\n \r\n ));\r\n });\r\n\r\n extend(UserPage.prototype, 'sidebarItems', function(items) {\r\n const lastViewed = new ItemList();\r\n\r\n console.log(this.user.profileViews());\r\n $.each(this.user.profileViews(), function(index, view) {\r\n\r\n console.log(view);\r\n // lastViewed.add('lastUser-' + viewer.id(),\r\n // \r\n // {avatar(viewer, {className: 'lastUser-avatar'})}\r\n // {username(viewer, {className: 'lastUser-name'})}\r\n // \r\n // );\r\n });\r\n\r\n // items.add('lastViewedUsers', FieldSet.component({\r\n // label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'),\r\n // className: 'LastUsers',\r\n // children: lastViewed.toArray()\r\n // }));\r\n });\r\n\r\n extend(UserPage.prototype, 'show', function() {\r\n if(typeof app.session.user !== 'undefined' && app.session.user.id() !== this.user.id())\r\n {\r\n app.request({\r\n method: 'POST',\r\n url: app.forum.attribute('apiUrl') + '/profileview/' + this.user.id(),\r\n data: { viewer: app.session.user.id() }\r\n });\r\n }\r\n });\r\n});"],"sourceRoot":""} \ No newline at end of file diff --git a/js/src/forum/index.js b/js/src/forum/index.js index bd6c0d8..39e2ae2 100644 --- a/js/src/forum/index.js +++ b/js/src/forum/index.js @@ -15,8 +15,6 @@ app.initializers.add('michaelbelgium-flarum-profile-views', function() { app.store.models.profileviews = ProfileView; User.prototype.profileViews = Model.hasMany('profileviews');//comes from the line above: "app.store.models."profileviews" - // app.store.find('profileviews').then(console.log); - console.log(app.store.all('profileviews')); extend(UserCard.prototype, 'infoItems', function(items) { const user = this.props.user; @@ -32,7 +30,6 @@ app.initializers.add('michaelbelgium-flarum-profile-views', function() { extend(UserPage.prototype, 'sidebarItems', function(items) { const lastViewed = new ItemList(); - console.log(this.user); console.log(this.user.profileViews()); $.each(this.user.profileViews(), function(index, view) { diff --git a/src/Models/UserProfileView.php b/src/Models/UserProfileView.php index fa4f4ce..d21ae42 100644 --- a/src/Models/UserProfileView.php +++ b/src/Models/UserProfileView.php @@ -4,7 +4,6 @@ use Flarum\Database\AbstractModel; use Flarum\User\User; -use Carbon\Carbon; class UserProfileView extends AbstractModel { diff --git a/src/Serializers/UserProfileViewSerializer.php b/src/Serializers/UserProfileViewSerializer.php index 1e3befa..d5703a5 100644 --- a/src/Serializers/UserProfileViewSerializer.php +++ b/src/Serializers/UserProfileViewSerializer.php @@ -25,4 +25,4 @@ protected function viewer($profileview) { return $this->hasOne($profileview, UserSerializer::class); } -} +} \ No newline at end of file From b10a7108db1ab97acb227d480637cb636b1fede7 Mon Sep 17 00:00:00 2001 From: Michael V Date: Sun, 20 Jan 2019 14:58:19 +0100 Subject: [PATCH 29/37] Use right relationship in js --- js/dist/forum.js | 2 +- js/dist/forum.js.map | 2 +- js/src/forum/index.js | 28 +++++++++---------- .../AddUserProfileViewsRelationship.php | 2 +- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/js/dist/forum.js b/js/dist/forum.js index 42318fb..d845f8d 100644 --- a/js/dist/forum.js +++ b/js/dist/forum.js @@ -1,2 +1,2 @@ -module.exports=function(e){var t={};function r(o){if(t[o])return t[o].exports;var n=t[o]={i:o,l:!1,exports:{}};return e[o].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.m=e,r.c=t,r.d=function(e,t,o){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(r.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)r.d(o,n,function(t){return e[t]}.bind(null,n));return o},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=11)}([function(e,t){e.exports=flarum.core.compat.app},function(e,t){e.exports=flarum.core.compat.Model},function(e,t){e.exports=flarum.core.compat.extend},function(e,t){e.exports=flarum.core.compat["components/UserPage"]},function(e,t){e.exports=flarum.core.compat["models/User"]},function(e,t){e.exports=flarum.core.compat["components/UserCard"]},function(e,t){e.exports=flarum.core.compat["helpers/icon"]},function(e,t){e.exports=flarum.core.compat["utils/ItemList"]},function(e,t){e.exports=flarum.core.compat["components/FieldSet"]},function(e,t){e.exports=flarum.core.compat["helpers/avatar"]},function(e,t){e.exports=flarum.core.compat["helpers/username"]},function(e,t,r){"use strict";r.r(t);var o=r(0),n=r.n(o),i=r(4),a=r.n(i),s=r(3),u=r.n(s),c=r(5),f=r.n(c),l=(r(8),r(6)),p=r.n(l),d=(r(9),r(10),r(1)),v=r.n(d),b=r(7),w=r.n(b),h=r(2);function y(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function x(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var O=function(e){var t,r;function o(){for(var t,r=arguments.length,o=new Array(r),n=0;n\r\n {icon('far fa-eye')}\r\n {' '}\r\n {app.translator.trans('flarum_profile_views.forum.user.views_count_text', {viewcount: '' + (user.profileViews() === false ? '0' : user.profileViews().length)})}\r\n \r\n ));\r\n });\r\n\r\n extend(UserPage.prototype, 'sidebarItems', function(items) {\r\n const lastViewed = new ItemList();\r\n\r\n console.log(this.user.profileViews());\r\n $.each(this.user.profileViews(), function(index, view) {\r\n\r\n console.log(view);\r\n // lastViewed.add('lastUser-' + viewer.id(),\r\n // \r\n // {avatar(viewer, {className: 'lastUser-avatar'})}\r\n // {username(viewer, {className: 'lastUser-name'})}\r\n // \r\n // );\r\n });\r\n\r\n // items.add('lastViewedUsers', FieldSet.component({\r\n // label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'),\r\n // className: 'LastUsers',\r\n // children: lastViewed.toArray()\r\n // }));\r\n });\r\n\r\n extend(UserPage.prototype, 'show', function() {\r\n if(typeof app.session.user !== 'undefined' && app.session.user.id() !== this.user.id())\r\n {\r\n app.request({\r\n method: 'POST',\r\n url: app.forum.attribute('apiUrl') + '/profileview/' + this.user.id(),\r\n data: { viewer: app.session.user.id() }\r\n });\r\n }\r\n });\r\n});"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack://@michaelbelgium/flarum-profile-views/webpack/bootstrap","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['Model']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['extend']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/UserPage']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['models/User']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/UserCard']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['utils/ItemList']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/FieldSet']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/icon']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/avatar']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/username']\"","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/defineProperty.js","webpack://@michaelbelgium/flarum-profile-views/./src/ProfileView.js","webpack://@michaelbelgium/flarum-profile-views/./src/forum/index.js"],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","flarum","core","compat","_assertThisInitialized","self","ReferenceError","_defineProperty","obj","configurable","writable","Model","app","initializers","add","User","profileViews","hasMany","extend","UserCard","items","this","props","user","UserPage","Item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,CACRC,OAAQ,OACRC,IAAKpB,IAAIqB,MAAMC,UAAU,UAAY,gBAAkBb,KAAKE,KAAKM,KACjEM,KAAM,CAAEC,OAAQxB,IAAIgB,QAAQL,KAAKM","file":"forum.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 10);\n","module.exports = flarum.core.compat['Model'];","module.exports = flarum.core.compat['extend'];","module.exports = flarum.core.compat['components/UserPage'];","module.exports = flarum.core.compat['models/User'];","module.exports = flarum.core.compat['components/UserCard'];","module.exports = flarum.core.compat['utils/ItemList'];","module.exports = flarum.core.compat['components/FieldSet'];","module.exports = flarum.core.compat['helpers/icon'];","module.exports = flarum.core.compat['helpers/avatar'];","module.exports = flarum.core.compat['helpers/username'];","export default function _assertThisInitialized(self) {\n if (self === void 0) {\n throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\");\n }\n\n return self;\n}","export default function _defineProperty(obj, key, value) {\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n\n return obj;\n}","import Model from 'flarum/Model';\r\n\r\nexport default class ProfileView extends Model {\r\n //comes from ProfileViewSerializer (viewer(), viewedUser(), visited_at)\r\n visitedAt = Model.attribute('visited_at', Model.transformDate);\r\n viewer = Model.hasOne('viewer');\r\n viewedUser = Model.hasOne('viewedUser');\r\n}","import User from 'flarum/models/User';\r\nimport UserPage from 'flarum/components/UserPage';\r\nimport UserCard from 'flarum/components/UserCard';\r\nimport FieldSet from 'flarum/components/FieldSet';\r\nimport icon from 'flarum/helpers/icon';\r\nimport avatar from 'flarum/helpers/avatar';\r\nimport username from 'flarum/helpers/username';\r\nimport Model from 'flarum/Model';\r\nimport ItemList from 'flarum/utils/ItemList';\r\nimport { extend } from 'flarum/extend';\r\nimport ProfileView from '../ProfileView';\r\n\r\napp.initializers.add('michaelbelgium-flarum-profile-views', function() {\r\n // app.store.models.profileViews = ProfileView;\r\n User.prototype.profileViews = Model.hasMany('profileViews');//comes from the extended user serializer relationship self::RELATIONSHIP\r\n\r\n extend(UserCard.prototype, 'infoItems', function(items) {\r\n const user = this.props.user;\r\n\r\n // items.add('profile-views',(\r\n // \r\n // {icon('far fa-eye')}\r\n // {' '}\r\n // {app.translator.trans('flarum_profile_views.forum.user.views_count_text', {viewcount: '' + (user.profileViews() === false ? '0' : user.profileViews().length)})}\r\n // \r\n // ));\r\n });\r\n\r\n extend(UserPage.prototype, 'sidebarItems', function(items) {\r\n const lastViewed = new ItemList();\r\n\r\n console.log(this.user);\r\n console.log(this.user.profileViews());//from User prototype\r\n // $.each(this.user.profileViews(), function(index, view) {\r\n\r\n // console.log(view);\r\n // lastViewed.add('lastUser-' + viewer.id(),\r\n // \r\n // {avatar(viewer, {className: 'lastUser-avatar'})}\r\n // {username(viewer, {className: 'lastUser-name'})}\r\n // \r\n // );\r\n // });\r\n\r\n // items.add('lastViewedUsers', FieldSet.component({\r\n // label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'),\r\n // className: 'LastUsers',\r\n // children: lastViewed.toArray()\r\n // }));\r\n });\r\n\r\n extend(UserPage.prototype, 'show', function() {\r\n if(typeof app.session.user !== 'undefined' && app.session.user.id() !== this.user.id())\r\n {\r\n app.request({\r\n method: 'POST',\r\n url: app.forum.attribute('apiUrl') + '/profileview/' + this.user.id(),\r\n data: { viewer: app.session.user.id() }\r\n });\r\n }\r\n });\r\n});"],"sourceRoot":""} \ No newline at end of file diff --git a/js/src/forum/index.js b/js/src/forum/index.js index 39e2ae2..d7889c6 100644 --- a/js/src/forum/index.js +++ b/js/src/forum/index.js @@ -1,4 +1,3 @@ -import app from 'flarum/app'; import User from 'flarum/models/User'; import UserPage from 'flarum/components/UserPage'; import UserCard from 'flarum/components/UserCard'; @@ -12,35 +11,36 @@ import { extend } from 'flarum/extend'; import ProfileView from '../ProfileView'; app.initializers.add('michaelbelgium-flarum-profile-views', function() { - app.store.models.profileviews = ProfileView; - User.prototype.profileViews = Model.hasMany('profileviews');//comes from the line above: "app.store.models."profileviews" + // app.store.models.profileViews = ProfileView; + User.prototype.profileViews = Model.hasMany('profileViews');//comes from the extended user serializer relationship self::RELATIONSHIP extend(UserCard.prototype, 'infoItems', function(items) { const user = this.props.user; - items.add('profile-views',( - - {icon('far fa-eye')} - {' '} - {app.translator.trans('flarum_profile_views.forum.user.views_count_text', {viewcount: '' + (user.profileViews() === false ? '0' : user.profileViews().length)})} - - )); + // items.add('profile-views',( + // + // {icon('far fa-eye')} + // {' '} + // {app.translator.trans('flarum_profile_views.forum.user.views_count_text', {viewcount: '' + (user.profileViews() === false ? '0' : user.profileViews().length)})} + // + // )); }); extend(UserPage.prototype, 'sidebarItems', function(items) { const lastViewed = new ItemList(); - console.log(this.user.profileViews()); - $.each(this.user.profileViews(), function(index, view) { + console.log(this.user); + console.log(this.user.profileViews());//from User prototype + // $.each(this.user.profileViews(), function(index, view) { - console.log(view); + // console.log(view); // lastViewed.add('lastUser-' + viewer.id(), // // {avatar(viewer, {className: 'lastUser-avatar'})} // {username(viewer, {className: 'lastUser-name'})} // // ); - }); + // }); // items.add('lastViewedUsers', FieldSet.component({ // label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'), diff --git a/src/Listeners/AddUserProfileViewsRelationship.php b/src/Listeners/AddUserProfileViewsRelationship.php index 775435f..758bb30 100644 --- a/src/Listeners/AddUserProfileViewsRelationship.php +++ b/src/Listeners/AddUserProfileViewsRelationship.php @@ -23,7 +23,7 @@ public function subscribe(Dispatcher $events) { $events->listen(WillGetData::class, [$this, 'includeTagsRelationship']); $events->listen(GetModelRelationship::class, [$this, 'getModelRelationship']); - $events->listen(GetApiRelationship::class, [$this, 'GetApiRelationship']); + $events->listen(GetApiRelationship::class, [$this, 'getApiRelationship']); } public function getModelRelationship(GetModelRelationship $event) From ffee9c20847388cf9a616ace1cff2fd8faae1693 Mon Sep 17 00:00:00 2001 From: Michael V Date: Sat, 26 Jan 2019 18:20:43 +0100 Subject: [PATCH 30/37] Improve profileview api handling --- extend.php | 2 +- js/dist/forum.js | 2 +- js/dist/forum.js.map | 2 +- js/src/forum/index.js | 11 +++++++---- .../CreateUserProfileViewController.php | 15 ++++++--------- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/extend.php b/extend.php index 6841b92..b598c4e 100644 --- a/extend.php +++ b/extend.php @@ -14,7 +14,7 @@ new Locales(__DIR__ . '/locale'), (new Routes('api')) - ->post('/profileview/{id}', 'profileview.add', CreateUserProfileViewController::class), + ->post('/profileview', 'profileview.create', CreateUserProfileViewController::class), function (Dispatcher $events) { $events->subscribe(AddUserProfileViewsRelationship::class); diff --git a/js/dist/forum.js b/js/dist/forum.js index d845f8d..a0e59b1 100644 --- a/js/dist/forum.js +++ b/js/dist/forum.js @@ -1,2 +1,2 @@ -module.exports=function(e){var t={};function r(o){if(t[o])return t[o].exports;var n=t[o]={i:o,l:!1,exports:{}};return e[o].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.m=e,r.c=t,r.d=function(e,t,o){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(r.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)r.d(o,n,function(t){return e[t]}.bind(null,n));return o},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=10)}([function(e,t){e.exports=flarum.core.compat.Model},function(e,t){e.exports=flarum.core.compat.extend},function(e,t){e.exports=flarum.core.compat["components/UserPage"]},function(e,t){e.exports=flarum.core.compat["models/User"]},function(e,t){e.exports=flarum.core.compat["components/UserCard"]},function(e,t){e.exports=flarum.core.compat["utils/ItemList"]},function(e,t){e.exports=flarum.core.compat["components/FieldSet"]},function(e,t){e.exports=flarum.core.compat["helpers/icon"]},function(e,t){e.exports=flarum.core.compat["helpers/avatar"]},function(e,t){e.exports=flarum.core.compat["helpers/username"]},function(e,t,r){"use strict";r.r(t);var o=r(3),n=r.n(o),i=r(2),u=r.n(i),a=r(4),s=r.n(a),c=(r(6),r(7),r(8),r(9),r(0)),p=r.n(c),f=r(5),l=r.n(f),m=r(1);function d(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function b(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}p.a;app.initializers.add("michaelbelgium-flarum-profile-views",function(){n.a.prototype.profileViews=p.a.hasMany("profileViews"),Object(m.extend)(s.a.prototype,"infoItems",function(e){this.props.user}),Object(m.extend)(u.a.prototype,"sidebarItems",function(e){new l.a;console.log(this.user),console.log(this.user.profileViews())}),Object(m.extend)(u.a.prototype,"show",function(){void 0!==app.session.user&&app.session.user.id()!==this.user.id()&&app.request({method:"POST",url:app.forum.attribute("apiUrl")+"/profileview/"+this.user.id(),data:{viewer:app.session.user.id()}})})})}]); +module.exports=function(e){var t={};function r(o){if(t[o])return t[o].exports;var n=t[o]={i:o,l:!1,exports:{}};return e[o].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.m=e,r.c=t,r.d=function(e,t,o){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(r.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)r.d(o,n,function(t){return e[t]}.bind(null,n));return o},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=10)}([function(e,t){e.exports=flarum.core.compat.Model},function(e,t){e.exports=flarum.core.compat.extend},function(e,t){e.exports=flarum.core.compat["components/UserPage"]},function(e,t){e.exports=flarum.core.compat["models/User"]},function(e,t){e.exports=flarum.core.compat["components/UserCard"]},function(e,t){e.exports=flarum.core.compat["utils/ItemList"]},function(e,t){e.exports=flarum.core.compat["components/FieldSet"]},function(e,t){e.exports=flarum.core.compat["helpers/icon"]},function(e,t){e.exports=flarum.core.compat["helpers/avatar"]},function(e,t){e.exports=flarum.core.compat["helpers/username"]},function(e,t,r){"use strict";r.r(t);var o=r(3),n=r.n(o),i=r(2),a=r.n(i),u=r(4),s=r.n(u),p=(r(6),r(7),r(8),r(9),r(0)),c=r.n(p),l=r(5),f=r.n(l),d=r(1);function m(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function v(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var b=function(e){var t,r;function o(){for(var t,r=arguments.length,o=new Array(r),n=0;n\r\n // {icon('far fa-eye')}\r\n // {' '}\r\n // {app.translator.trans('flarum_profile_views.forum.user.views_count_text', {viewcount: '' + (user.profileViews() === false ? '0' : user.profileViews().length)})}\r\n // \r\n // ));\r\n });\r\n\r\n extend(UserPage.prototype, 'sidebarItems', function(items) {\r\n const lastViewed = new ItemList();\r\n\r\n console.log(this.user);\r\n console.log(this.user.profileViews());//from User prototype\r\n // $.each(this.user.profileViews(), function(index, view) {\r\n\r\n // console.log(view);\r\n // lastViewed.add('lastUser-' + viewer.id(),\r\n // \r\n // {avatar(viewer, {className: 'lastUser-avatar'})}\r\n // {username(viewer, {className: 'lastUser-name'})}\r\n // \r\n // );\r\n // });\r\n\r\n // items.add('lastViewedUsers', FieldSet.component({\r\n // label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'),\r\n // className: 'LastUsers',\r\n // children: lastViewed.toArray()\r\n // }));\r\n });\r\n\r\n extend(UserPage.prototype, 'show', function() {\r\n if(typeof app.session.user !== 'undefined' && app.session.user.id() !== this.user.id())\r\n {\r\n app.request({\r\n method: 'POST',\r\n url: app.forum.attribute('apiUrl') + '/profileview/' + this.user.id(),\r\n data: { viewer: app.session.user.id() }\r\n });\r\n }\r\n });\r\n});"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack://@michaelbelgium/flarum-profile-views/webpack/bootstrap","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['Model']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['extend']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/UserPage']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['models/User']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/UserCard']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['utils/ItemList']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/FieldSet']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/icon']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/avatar']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/username']\"","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/defineProperty.js","webpack://@michaelbelgium/flarum-profile-views/./src/ProfileView.js","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/inheritsLoose.js","webpack://@michaelbelgium/flarum-profile-views/./src/forum/index.js"],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","flarum","core","compat","_assertThisInitialized","self","ReferenceError","_defineProperty","obj","configurable","writable","ProfileView","subClass","superClass","Model","attribute","transformDate","hasOne","constructor","__proto__","app","initializers","add","store","models","profileview","User","profileViews","hasMany","extend","UserCard","items","this","props","user","UserPage","ItemList","console","log","session","id","request","method","url","forum","data","viewer","viewedUser"],"mappings":"2BACA,IAAAA,EAAA,GAGA,SAAAC,EAAAC,GAGA,GAAAF,EAAAE,GACA,OAAAF,EAAAE,GAAAC,QAGA,IAAAC,EAAAJ,EAAAE,GAAA,CACAG,EAAAH,EACAI,GAAA,EACAH,QAAA,IAUA,OANAI,EAAAL,GAAAM,KAAAJ,EAAAD,QAAAC,IAAAD,QAAAF,GAGAG,EAAAE,GAAA,EAGAF,EAAAD,QA0DA,OArDAF,EAAAQ,EAAAF,EAGAN,EAAAS,EAAAV,EAGAC,EAAAU,EAAA,SAAAR,EAAAS,EAAAC,GACAZ,EAAAa,EAAAX,EAAAS,IACAG,OAAAC,eAAAb,EAAAS,EAAA,CAA0CK,YAAA,EAAAC,IAAAL,KAK1CZ,EAAAkB,EAAA,SAAAhB,GACA,oBAAAiB,eAAAC,aACAN,OAAAC,eAAAb,EAAAiB,OAAAC,YAAA,CAAwDC,MAAA,WAExDP,OAAAC,eAAAb,EAAA,cAAiDmB,OAAA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SAAAE,EAAAC,EAAAhB,EAAAN,GAYf,OAXAM,KAAAgB,EACA7B,OAAAC,eAAA4B,EAAAhB,EAAA,CACAN,QACAL,YAAA,EACA4B,cAAA,EACAC,UAAA,IAGAF,EAAAhB,GAAAN,EAGAsB,MCVqBG,cCFN,IAAAC,EAAAC,6JDIDC,IAAMC,UAAU,aAAcD,IAAME,mCACvCF,IAAMG,OAAO,kCACTH,IAAMG,OAAO,wBCNbJ,KAAAD,KACff,UAAAlB,OAAAY,OAAAsB,EAAAhB,WACAe,EAAAf,UAAAqB,YAAAN,EACAA,EAAAO,UAAAN,KDDyCC,KEUzCM,IAAIC,aAAaC,IAAI,sCAAuC,WACxDF,IAAIG,MAAMC,OAAOC,YAAcd,EAC/Be,IAAK7B,UAAU8B,aAAeb,IAAMc,QAAQ,eAE5CC,iBAAOC,IAASjC,UAAW,YAAa,SAASkC,GAChCC,KAAKC,MAAMC,OAW5BL,iBAAOM,IAAStC,UAAW,eAAgB,SAASkC,GAC7B,IAAIK,IAEvBC,QAAQC,IAAIN,KAAKE,MACjBG,QAAQC,IAAIN,KAAKE,KAAKP,kBAmB1BE,iBAAOM,IAAStC,UAAW,OAAQ,gBACA,IAArBuB,IAAImB,QAAQL,MAAwBd,IAAImB,QAAQL,KAAKM,OAASR,KAAKE,KAAKM,MAE9EpB,IAAIqB,QAAQ,CACRC,OAAQ,OACRC,IAAKvB,IAAIwB,MAAM7B,UAAU,UAAY,eACrC8B,KAAM,CACFC,OAAQ1B,IAAImB,QAAQL,KAAKM,KACzBO,WAAYf,KAAKE,KAAKM","file":"forum.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 10);\n","module.exports = flarum.core.compat['Model'];","module.exports = flarum.core.compat['extend'];","module.exports = flarum.core.compat['components/UserPage'];","module.exports = flarum.core.compat['models/User'];","module.exports = flarum.core.compat['components/UserCard'];","module.exports = flarum.core.compat['utils/ItemList'];","module.exports = flarum.core.compat['components/FieldSet'];","module.exports = flarum.core.compat['helpers/icon'];","module.exports = flarum.core.compat['helpers/avatar'];","module.exports = flarum.core.compat['helpers/username'];","export default function _assertThisInitialized(self) {\n if (self === void 0) {\n throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\");\n }\n\n return self;\n}","export default function _defineProperty(obj, key, value) {\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n\n return obj;\n}","import Model from 'flarum/Model';\r\n\r\nexport default class ProfileView extends Model {\r\n //comes from ProfileViewSerializer (viewer(), viewedUser(), visited_at)\r\n visitedAt = Model.attribute('visited_at', Model.transformDate);\r\n viewer = Model.hasOne('viewer');\r\n viewedUser = Model.hasOne('viewedUser');\r\n}","export default function _inheritsLoose(subClass, superClass) {\n subClass.prototype = Object.create(superClass.prototype);\n subClass.prototype.constructor = subClass;\n subClass.__proto__ = superClass;\n}","import User from 'flarum/models/User';\r\nimport UserPage from 'flarum/components/UserPage';\r\nimport UserCard from 'flarum/components/UserCard';\r\nimport FieldSet from 'flarum/components/FieldSet';\r\nimport icon from 'flarum/helpers/icon';\r\nimport avatar from 'flarum/helpers/avatar';\r\nimport username from 'flarum/helpers/username';\r\nimport Model from 'flarum/Model';\r\nimport ItemList from 'flarum/utils/ItemList';\r\nimport { extend } from 'flarum/extend';\r\nimport ProfileView from '../ProfileView';\r\n\r\napp.initializers.add('michaelbelgium-flarum-profile-views', function() {\r\n app.store.models.profileview = ProfileView;\r\n User.prototype.profileViews = Model.hasMany('profileview');//comes from the extended user serializer relationship self::RELATIONSHIP\r\n\r\n extend(UserCard.prototype, 'infoItems', function(items) {\r\n const user = this.props.user;\r\n\r\n // items.add('profile-views',(\r\n // \r\n // {icon('far fa-eye')}\r\n // {' '}\r\n // {app.translator.trans('flarum_profile_views.forum.user.views_count_text', {viewcount: '' + (user.profileViews() === false ? '0' : user.profileViews().length)})}\r\n // \r\n // ));\r\n });\r\n\r\n extend(UserPage.prototype, 'sidebarItems', function(items) {\r\n const lastViewed = new ItemList();\r\n\r\n console.log(this.user);\r\n console.log(this.user.profileViews());//from User prototype\r\n // $.each(this.user.profileViews(), function(index, view) {\r\n\r\n // console.log(view);\r\n // lastViewed.add('lastUser-' + viewer.id(),\r\n // \r\n // {avatar(viewer, {className: 'lastUser-avatar'})}\r\n // {username(viewer, {className: 'lastUser-name'})}\r\n // \r\n // );\r\n // });\r\n\r\n // items.add('lastViewedUsers', FieldSet.component({\r\n // label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'),\r\n // className: 'LastUsers',\r\n // children: lastViewed.toArray()\r\n // }));\r\n });\r\n\r\n extend(UserPage.prototype, 'show', function() {\r\n if(typeof app.session.user !== 'undefined' && app.session.user.id() !== this.user.id())\r\n {\r\n app.request({\r\n method: 'POST',\r\n url: app.forum.attribute('apiUrl') + '/profileview',\r\n data: { \r\n viewer: app.session.user.id(),\r\n viewedUser: this.user.id()\r\n }\r\n });\r\n }\r\n });\r\n});"],"sourceRoot":""} \ No newline at end of file diff --git a/js/src/forum/index.js b/js/src/forum/index.js index d7889c6..7077c03 100644 --- a/js/src/forum/index.js +++ b/js/src/forum/index.js @@ -11,8 +11,8 @@ import { extend } from 'flarum/extend'; import ProfileView from '../ProfileView'; app.initializers.add('michaelbelgium-flarum-profile-views', function() { - // app.store.models.profileViews = ProfileView; - User.prototype.profileViews = Model.hasMany('profileViews');//comes from the extended user serializer relationship self::RELATIONSHIP + app.store.models.profileview = ProfileView; + User.prototype.profileViews = Model.hasMany('profileview');//comes from the extended user serializer relationship self::RELATIONSHIP extend(UserCard.prototype, 'infoItems', function(items) { const user = this.props.user; @@ -54,8 +54,11 @@ app.initializers.add('michaelbelgium-flarum-profile-views', function() { { app.request({ method: 'POST', - url: app.forum.attribute('apiUrl') + '/profileview/' + this.user.id(), - data: { viewer: app.session.user.id() } + url: app.forum.attribute('apiUrl') + '/profileview', + data: { + viewer: app.session.user.id(), + viewedUser: this.user.id() + } }); } }); diff --git a/src/controllers/CreateUserProfileViewController.php b/src/controllers/CreateUserProfileViewController.php index d7a4b47..c4941e7 100644 --- a/src/controllers/CreateUserProfileViewController.php +++ b/src/controllers/CreateUserProfileViewController.php @@ -5,7 +5,7 @@ use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Server\RequestHandlerInterface; -use Zend\Diactoros\Response\EmptyResponse; +use Zend\Diactoros\Response\JsonResponse; use Flarum\User\User; use Carbon\Carbon; use Michaelbelgium\Profileviews\Models\UserProfileView; @@ -14,24 +14,21 @@ class CreateUserProfileViewController implements RequestHandlerInterface { public function handle(Request $request): Response { - $userId = array_get($request->getQueryParams(), 'id'); + $viewedUserId = array_get($request->getParsedBody(), 'viewedUser'); $viewerId = array_get($request->getParsedBody(), 'viewer'); - $user = User::find($userId); + $viewedUser = User::find($viewedUserId); - $test = $user->profileViews; - $testOther = $user->viewedProfiles; - - $profileView = $user->profileViews()->where('viewer_id', $viewerId)->first(); + $profileView = $viewedUser->profileViews()->where('viewer_id', $viewerId)->first(); if(is_null($profileView)) { $profileView = new UserProfileView(); - $profileView->viewedUser()->associate($user); + $profileView->viewedUser()->associate($viewedUser); $profileView->viewer()->associate(User::find($viewerId)); } $profileView->visited_at = Carbon::now(); $profileView->save(); - return new EmptyResponse(); + return new JsonResponse($profileView->toArray()); } } \ No newline at end of file From a4a02e36bf911f8c48e4e4c396c87f4274233912 Mon Sep 17 00:00:00 2001 From: Michael V Date: Sat, 26 Jan 2019 18:20:57 +0100 Subject: [PATCH 31/37] Fix indendation --- src/Listeners/AddUserProfileViewsRelationship.php | 6 +++--- src/Serializers/UserProfileViewSerializer.php | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Listeners/AddUserProfileViewsRelationship.php b/src/Listeners/AddUserProfileViewsRelationship.php index 758bb30..a26f71f 100644 --- a/src/Listeners/AddUserProfileViewsRelationship.php +++ b/src/Listeners/AddUserProfileViewsRelationship.php @@ -58,9 +58,9 @@ public function getApiRelationship(GetApiRelationship $event) /** * @param WillGetData $event */ - public function includeTagsRelationship(WillGetData $event) - { + public function includeTagsRelationship(WillGetData $event) + { if($event->controller->serializer == UserSerializer::class) $event->addInclude([self::RELATIONSHIP, self::RELATIONSHIP.'.viewer', self::RELATIONSHIP.'.viewedUser']);//".x" comes from model relationship UserProfileView - } + } } \ No newline at end of file diff --git a/src/Serializers/UserProfileViewSerializer.php b/src/Serializers/UserProfileViewSerializer.php index d5703a5..3061142 100644 --- a/src/Serializers/UserProfileViewSerializer.php +++ b/src/Serializers/UserProfileViewSerializer.php @@ -9,20 +9,20 @@ class UserProfileViewSerializer extends AbstractSerializer { protected $type = 'userprofileview'; - protected function getDefaultAttributes($profileview) + protected function getDefaultAttributes($profileview) { return [ 'visited_at' => $this->formatDate($profileview->visited_at) ]; - } + } - protected function viewedUser($profileview) + protected function viewedUser($profileview) { return $this->hasOne($profileview, UserSerializer::class); - } + } - protected function viewer($profileview) + protected function viewer($profileview) { - return $this->hasOne($profileview, UserSerializer::class); - } + return $this->hasOne($profileview, UserSerializer::class); + } } \ No newline at end of file From 9f1e8a0a81ff5c7fdc6b3a7816c3af10a03940f3 Mon Sep 17 00:00:00 2001 From: Michael V Date: Sat, 26 Jan 2019 20:24:37 +0100 Subject: [PATCH 32/37] FIXES **** RELATIONSHIP FINALLY --- js/dist/forum.js | 2 +- js/dist/forum.js.map | 2 +- js/src/forum/index.js | 51 ++++++++++++++++++++----------------------- less/extension.less | 17 +++++++++------ 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/js/dist/forum.js b/js/dist/forum.js index a0e59b1..4bc805c 100644 --- a/js/dist/forum.js +++ b/js/dist/forum.js @@ -1,2 +1,2 @@ -module.exports=function(e){var t={};function r(o){if(t[o])return t[o].exports;var n=t[o]={i:o,l:!1,exports:{}};return e[o].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.m=e,r.c=t,r.d=function(e,t,o){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(r.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)r.d(o,n,function(t){return e[t]}.bind(null,n));return o},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=10)}([function(e,t){e.exports=flarum.core.compat.Model},function(e,t){e.exports=flarum.core.compat.extend},function(e,t){e.exports=flarum.core.compat["components/UserPage"]},function(e,t){e.exports=flarum.core.compat["models/User"]},function(e,t){e.exports=flarum.core.compat["components/UserCard"]},function(e,t){e.exports=flarum.core.compat["utils/ItemList"]},function(e,t){e.exports=flarum.core.compat["components/FieldSet"]},function(e,t){e.exports=flarum.core.compat["helpers/icon"]},function(e,t){e.exports=flarum.core.compat["helpers/avatar"]},function(e,t){e.exports=flarum.core.compat["helpers/username"]},function(e,t,r){"use strict";r.r(t);var o=r(3),n=r.n(o),i=r(2),a=r.n(i),u=r(4),s=r.n(u),p=(r(6),r(7),r(8),r(9),r(0)),c=r.n(p),l=r(5),f=r.n(l),d=r(1);function m(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function v(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var b=function(e){var t,r;function o(){for(var t,r=arguments.length,o=new Array(r),n=0;n\r\n // {icon('far fa-eye')}\r\n // {' '}\r\n // {app.translator.trans('flarum_profile_views.forum.user.views_count_text', {viewcount: '' + (user.profileViews() === false ? '0' : user.profileViews().length)})}\r\n // \r\n // ));\r\n });\r\n\r\n extend(UserPage.prototype, 'sidebarItems', function(items) {\r\n const lastViewed = new ItemList();\r\n\r\n console.log(this.user);\r\n console.log(this.user.profileViews());//from User prototype\r\n // $.each(this.user.profileViews(), function(index, view) {\r\n\r\n // console.log(view);\r\n // lastViewed.add('lastUser-' + viewer.id(),\r\n // \r\n // {avatar(viewer, {className: 'lastUser-avatar'})}\r\n // {username(viewer, {className: 'lastUser-name'})}\r\n // \r\n // );\r\n // });\r\n\r\n // items.add('lastViewedUsers', FieldSet.component({\r\n // label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'),\r\n // className: 'LastUsers',\r\n // children: lastViewed.toArray()\r\n // }));\r\n });\r\n\r\n extend(UserPage.prototype, 'show', function() {\r\n if(typeof app.session.user !== 'undefined' && app.session.user.id() !== this.user.id())\r\n {\r\n app.request({\r\n method: 'POST',\r\n url: app.forum.attribute('apiUrl') + '/profileview',\r\n data: { \r\n viewer: app.session.user.id(),\r\n viewedUser: this.user.id()\r\n }\r\n });\r\n }\r\n });\r\n});"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack://@michaelbelgium/flarum-profile-views/webpack/bootstrap","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['Model']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['extend']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/UserPage']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['models/User']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/UserCard']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/FieldSet']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/icon']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/avatar']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/username']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['utils/ItemList']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['utils/humanTime']\"","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/defineProperty.js","webpack://@michaelbelgium/flarum-profile-views/./src/ProfileView.js","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/inheritsLoose.js","webpack://@michaelbelgium/flarum-profile-views/./src/forum/index.js"],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","flarum","core","compat","_assertThisInitialized","self","ReferenceError","_defineProperty","obj","configurable","writable","ProfileView","subClass","superClass","Model","attribute","transformDate","hasOne","constructor","__proto__","app","initializers","add","store","models","userprofileview","User","profileViews","hasMany","extend","UserCard","items","user","this","props","icon","translator","trans","viewcount","length","UserPage","lastViewed","ItemList","$","each","index","pv","viewer","id","href","forum","username","avatar","className","FieldSet","component","label","children","toArray","session","request","method","url","data","viewedUser"],"mappings":"2BACA,IAAAA,EAAA,GAGA,SAAAC,EAAAC,GAGA,GAAAF,EAAAE,GACA,OAAAF,EAAAE,GAAAC,QAGA,IAAAC,EAAAJ,EAAAE,GAAA,CACAG,EAAAH,EACAI,GAAA,EACAH,QAAA,IAUA,OANAI,EAAAL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Aa,IAAIC,IAEvBC,EAAEC,KAAKX,KAAKD,KAAKL,eAAgB,SAASkB,EAAOC,GAC7CL,EAAWnB,IAAI,YAAcwB,EAAGC,SAASC,KACrC3E,EAAA,KAAG4E,KAAM7B,IAAI8B,MAAMnC,UAAU,WAAa,MAAQ+B,EAAGC,SAASI,YACzDC,IAAON,EAAGC,SAAU,CAACM,UAAW,oBAChCF,IAASL,EAAGC,cAKzBhB,EAAMT,IAAI,kBAAmBgC,IAASC,UAAU,CAC5CC,MAAOpC,IAAIgB,WAAWC,MAAM,sDAC5BgB,UAAW,YACXI,SAAUhB,EAAWiB,eAI7B7B,iBAAOW,IAAS3C,UAAW,OAAQ,gBACA,IAArBuB,IAAIuC,QAAQ3B,MAAwBZ,IAAIuC,QAAQ3B,KAAKgB,OAASf,KAAKD,KAAKgB,MAE9E5B,IAAIwC,QAAQ,CACRC,OAAQ,OACRC,IAAK1C,IAAI8B,MAAMnC,UAAU,UAAY,eACrCgD,KAAM,CACFhB,OAAQ3B,IAAIuC,QAAQ3B,KAAKgB,KACzBgB,WAAY/B,KAAKD,KAAKgB","file":"forum.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 11);\n","module.exports = flarum.core.compat['Model'];","module.exports = flarum.core.compat['extend'];","module.exports = flarum.core.compat['components/UserPage'];","module.exports = flarum.core.compat['models/User'];","module.exports = flarum.core.compat['components/UserCard'];","module.exports = flarum.core.compat['components/FieldSet'];","module.exports = flarum.core.compat['helpers/icon'];","module.exports = flarum.core.compat['helpers/avatar'];","module.exports = flarum.core.compat['helpers/username'];","module.exports = flarum.core.compat['utils/ItemList'];","module.exports = flarum.core.compat['utils/humanTime'];","export default function _assertThisInitialized(self) {\n if (self === void 0) {\n throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\");\n }\n\n return self;\n}","export default function _defineProperty(obj, key, value) {\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n\n return obj;\n}","import Model from 'flarum/Model';\r\n\r\nexport default class ProfileView extends Model {\r\n //comes from ProfileViewSerializer (viewer(), viewedUser(), visited_at)\r\n visitedAt = Model.attribute('visited_at', Model.transformDate);\r\n viewer = Model.hasOne('viewer');\r\n viewedUser = Model.hasOne('viewedUser');\r\n}","export default function _inheritsLoose(subClass, superClass) {\n subClass.prototype = Object.create(superClass.prototype);\n subClass.prototype.constructor = subClass;\n subClass.__proto__ = superClass;\n}","import User from 'flarum/models/User';\r\nimport UserPage from 'flarum/components/UserPage';\r\nimport UserCard from 'flarum/components/UserCard';\r\nimport FieldSet from 'flarum/components/FieldSet';\r\nimport icon from 'flarum/helpers/icon';\r\nimport avatar from 'flarum/helpers/avatar';\r\nimport username from 'flarum/helpers/username';\r\nimport Model from 'flarum/Model';\r\nimport ItemList from 'flarum/utils/ItemList';\r\nimport { extend } from 'flarum/extend';\r\nimport humanTime from 'flarum/utils/humanTime';\r\nimport ProfileView from '../ProfileView';\r\n\r\napp.initializers.add('michaelbelgium-flarum-profile-views', function() {\r\n app.store.models.userprofileview = ProfileView;//\".userprofileview\" = serializer type \"userprofileview\"\r\n User.prototype.profileViews = Model.hasMany('profileViews');//comes from AddUserProfileViewsRelationship::RELATIONSHIP = php model relationship method\r\n\r\n extend(UserCard.prototype, 'infoItems', function(items) {\r\n const user = this.props.user;\r\n\r\n items.add('profile-views',(\r\n \r\n {icon('far fa-eye')}\r\n {' '}\r\n {app.translator.trans('flarum_profile_views.forum.user.views_count_text', {viewcount: '' + user.profileViews().length})}\r\n \r\n ));\r\n });\r\n\r\n extend(UserPage.prototype, 'sidebarItems', function(items) {\r\n const lastViewed = new ItemList();\r\n\r\n $.each(this.user.profileViews(), function(index, pv) {\r\n lastViewed.add('lastUser-' + pv.viewer().id(),\r\n \r\n {avatar(pv.viewer(), {className: 'lastUser-avatar'})}\r\n {username(pv.viewer())}\r\n \r\n );\r\n });\r\n\r\n items.add('lastViewedUsers', FieldSet.component({\r\n label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'),\r\n className: 'LastUsers',\r\n children: lastViewed.toArray()\r\n }));\r\n });\r\n\r\n extend(UserPage.prototype, 'show', function() {\r\n if(typeof app.session.user !== 'undefined' && app.session.user.id() !== this.user.id())\r\n {\r\n app.request({\r\n method: 'POST',\r\n url: app.forum.attribute('apiUrl') + '/profileview',\r\n data: { \r\n viewer: app.session.user.id(),\r\n viewedUser: this.user.id()\r\n }\r\n });\r\n }\r\n });\r\n});"],"sourceRoot":""} \ No newline at end of file diff --git a/js/src/forum/index.js b/js/src/forum/index.js index 7077c03..84459bc 100644 --- a/js/src/forum/index.js +++ b/js/src/forum/index.js @@ -8,45 +8,42 @@ import username from 'flarum/helpers/username'; import Model from 'flarum/Model'; import ItemList from 'flarum/utils/ItemList'; import { extend } from 'flarum/extend'; +import humanTime from 'flarum/utils/humanTime'; import ProfileView from '../ProfileView'; app.initializers.add('michaelbelgium-flarum-profile-views', function() { - app.store.models.profileview = ProfileView; - User.prototype.profileViews = Model.hasMany('profileview');//comes from the extended user serializer relationship self::RELATIONSHIP + app.store.models.userprofileview = ProfileView;//".userprofileview" = serializer type "userprofileview" + User.prototype.profileViews = Model.hasMany('profileViews');//comes from AddUserProfileViewsRelationship::RELATIONSHIP = php model relationship method extend(UserCard.prototype, 'infoItems', function(items) { const user = this.props.user; - // items.add('profile-views',( - // - // {icon('far fa-eye')} - // {' '} - // {app.translator.trans('flarum_profile_views.forum.user.views_count_text', {viewcount: '' + (user.profileViews() === false ? '0' : user.profileViews().length)})} - // - // )); + items.add('profile-views',( + + {icon('far fa-eye')} + {' '} + {app.translator.trans('flarum_profile_views.forum.user.views_count_text', {viewcount: '' + user.profileViews().length})} + + )); }); extend(UserPage.prototype, 'sidebarItems', function(items) { const lastViewed = new ItemList(); - console.log(this.user); - console.log(this.user.profileViews());//from User prototype - // $.each(this.user.profileViews(), function(index, view) { - - // console.log(view); - // lastViewed.add('lastUser-' + viewer.id(), - // - // {avatar(viewer, {className: 'lastUser-avatar'})} - // {username(viewer, {className: 'lastUser-name'})} - // - // ); - // }); - - // items.add('lastViewedUsers', FieldSet.component({ - // label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'), - // className: 'LastUsers', - // children: lastViewed.toArray() - // })); + $.each(this.user.profileViews(), function(index, pv) { + lastViewed.add('lastUser-' + pv.viewer().id(), + + {avatar(pv.viewer(), {className: 'lastUser-avatar'})} + {username(pv.viewer())} + + ); + }); + + items.add('lastViewedUsers', FieldSet.component({ + label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'), + className: 'LastUsers', + children: lastViewed.toArray() + })); }); extend(UserPage.prototype, 'show', function() { diff --git a/less/extension.less b/less/extension.less index 470c937..98b269a 100644 --- a/less/extension.less +++ b/less/extension.less @@ -3,13 +3,16 @@ fieldset.LastUsers { list-style-type: none; padding: 0; - .lastUser-avatar { - width: 24px; - height: 24px; - line-height: 24px; - font-size: 12px; - margin-right: 6px; - vertical-align: middle; + li a { + display: block; + + span.lastUser-avatar { + width: 35px; + height: 35px; + line-height: 35px; + vertical-align: middle; + margin-right: 6px; + } } } } \ No newline at end of file From f31a0f814a2cd21a8d8de2f5088d4f9218fb29e4 Mon Sep 17 00:00:00 2001 From: Michael V Date: Sat, 26 Jan 2019 20:52:34 +0100 Subject: [PATCH 33/37] Add vistedAt in list --- js/dist/forum.js | 2 +- js/dist/forum.js.map | 2 +- js/src/forum/index.js | 5 ++++- less/extension.less | 25 ++++++++++++++++++++++--- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/js/dist/forum.js b/js/dist/forum.js index 4bc805c..4a7970b 100644 --- a/js/dist/forum.js +++ b/js/dist/forum.js @@ -1,2 +1,2 @@ -module.exports=function(e){var r={};function t(o){if(r[o])return r[o].exports;var n=r[o]={i:o,l:!1,exports:{}};return e[o].call(n.exports,n,n.exports,t),n.l=!0,n.exports}return t.m=e,t.c=r,t.d=function(e,r,o){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:o})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(t.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)t.d(o,n,function(r){return e[r]}.bind(null,n));return o},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=11)}([function(e,r){e.exports=flarum.core.compat.Model},function(e,r){e.exports=flarum.core.compat.extend},function(e,r){e.exports=flarum.core.compat["components/UserPage"]},function(e,r){e.exports=flarum.core.compat["models/User"]},function(e,r){e.exports=flarum.core.compat["components/UserCard"]},function(e,r){e.exports=flarum.core.compat["components/FieldSet"]},function(e,r){e.exports=flarum.core.compat["helpers/icon"]},function(e,r){e.exports=flarum.core.compat["helpers/avatar"]},function(e,r){e.exports=flarum.core.compat["helpers/username"]},function(e,r){e.exports=flarum.core.compat["utils/ItemList"]},function(e,r){e.exports=flarum.core.compat["utils/humanTime"]},function(e,r,t){"use strict";t.r(r);var o=t(3),n=t.n(o),a=t(2),i=t.n(a),s=t(4),u=t.n(s),p=t(5),c=t.n(p),l=t(6),f=t.n(l),d=t(7),v=t.n(d),w=t(8),b=t.n(w),h=t(0),y=t.n(h),x=t(9),_=t.n(x),O=t(1);t(10);function j(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function U(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}var g=function(e){var r,t;function o(){for(var r,t=arguments.length,o=new Array(t),n=0;n\r\n {icon('far fa-eye')}\r\n {' '}\r\n {app.translator.trans('flarum_profile_views.forum.user.views_count_text', {viewcount: '' + user.profileViews().length})}\r\n \r\n ));\r\n });\r\n\r\n extend(UserPage.prototype, 'sidebarItems', function(items) {\r\n const lastViewed = new ItemList();\r\n\r\n $.each(this.user.profileViews(), function(index, pv) {\r\n lastViewed.add('lastUser-' + pv.viewer().id(),\r\n \r\n {avatar(pv.viewer(), {className: 'lastUser-avatar'})}\r\n {username(pv.viewer())}\r\n \r\n );\r\n });\r\n\r\n items.add('lastViewedUsers', FieldSet.component({\r\n label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'),\r\n className: 'LastUsers',\r\n children: lastViewed.toArray()\r\n }));\r\n });\r\n\r\n extend(UserPage.prototype, 'show', function() {\r\n if(typeof app.session.user !== 'undefined' && app.session.user.id() !== this.user.id())\r\n {\r\n app.request({\r\n method: 'POST',\r\n url: app.forum.attribute('apiUrl') + '/profileview',\r\n data: { \r\n viewer: app.session.user.id(),\r\n viewedUser: this.user.id()\r\n }\r\n });\r\n }\r\n });\r\n});"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack://@michaelbelgium/flarum-profile-views/webpack/bootstrap","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['Model']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['extend']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/UserPage']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['models/User']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/UserCard']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/FieldSet']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/icon']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/avatar']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/username']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['utils/ItemList']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['utils/humanTime']\"","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/defineProperty.js","webpack://@michaelbelgium/flarum-profile-views/./src/ProfileView.js","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/inheritsLoose.js","webpack://@michaelbelgium/flarum-profile-views/./src/forum/index.js"],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","flarum","core","compat","_assertThisInitialized","self","ReferenceError","_defineProperty","obj","configurable","writable","ProfileView","subClass","superClass","Model","attribute","transformDate","hasOne","constructor","__proto__","app","initializers","add","store","models","userprofileview","User","profileViews","hasMany","extend","UserCard","items","user","this","props","icon","translator","trans","viewcount","length","UserPage","lastViewed","ItemList","$","each","index","pv","viewer","id","href","forum","username","avatar","className","humanTime","visitedAt","FieldSet","component","label","children","toArray","session","request","method","url","data","viewedUser"],"mappings":"2BACA,IAAAA,EAAA,GAGA,SAAAC,EAAAC,GAGA,GAAAF,EAAAE,GACA,OAAAF,EAAAE,GAAAC,QAGA,IAAAC,EAAAJ,EAAAE,GAAA,CACAG,EAAAH,EACAI,GAAA,EACAH,QAAA,IAUA,OANAI,EAAAL,GAAA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AIC,IAEvBC,EAAEC,KAAKX,KAAKD,KAAKL,eAAgB,SAASkB,EAAOC,GAC7CL,EAAWnB,IAAI,YAAcwB,EAAGC,SAASC,KACrC3E,EAAA,KAAG4E,KAAM7B,IAAI8B,MAAMnC,UAAU,WAAa,MAAQ+B,EAAGC,SAASI,YACzDC,IAAON,EAAGC,SAAU,CAACM,UAAW,oBACjChF,EAAA,WACK8E,IAASL,EAAGC,UACb1E,EAAA,QAAMgF,UAAU,oBAAoBC,IAAUR,EAAGS,mBAMjExB,EAAMT,IAAI,kBAAmBkC,IAASC,UAAU,CAC5CC,MAAOtC,IAAIgB,WAAWC,MAAM,sDAC5BgB,UAAW,YACXM,SAAUlB,EAAWmB,eAI7B/B,iBAAOW,IAAS3C,UAAW,OAAQ,gBACA,IAArBuB,IAAIyC,QAAQ7B,MAAwBZ,IAAIyC,QAAQ7B,KAAKgB,OAASf,KAAKD,KAAKgB,MAE9E5B,IAAI0C,QAAQ,CACRC,OAAQ,OACRC,IAAK5C,IAAI8B,MAAMnC,UAAU,UAAY,eACrCkD,KAAM,CACFlB,OAAQ3B,IAAIyC,QAAQ7B,KAAKgB,KACzBkB,WAAYjC,KAAKD,KAAKgB","file":"forum.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 11);\n","module.exports = flarum.core.compat['Model'];","module.exports = flarum.core.compat['extend'];","module.exports = flarum.core.compat['components/UserPage'];","module.exports = flarum.core.compat['models/User'];","module.exports = flarum.core.compat['components/UserCard'];","module.exports = flarum.core.compat['components/FieldSet'];","module.exports = flarum.core.compat['helpers/icon'];","module.exports = flarum.core.compat['helpers/avatar'];","module.exports = flarum.core.compat['helpers/username'];","module.exports = flarum.core.compat['utils/ItemList'];","module.exports = flarum.core.compat['utils/humanTime'];","export default function _assertThisInitialized(self) {\n if (self === void 0) {\n throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\");\n }\n\n return self;\n}","export default function _defineProperty(obj, key, value) {\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n\n return obj;\n}","import Model from 'flarum/Model';\r\n\r\nexport default class ProfileView extends Model {\r\n //comes from ProfileViewSerializer (viewer(), viewedUser(), visited_at)\r\n visitedAt = Model.attribute('visited_at', Model.transformDate);\r\n viewer = Model.hasOne('viewer');\r\n viewedUser = Model.hasOne('viewedUser');\r\n}","export default function _inheritsLoose(subClass, superClass) {\n subClass.prototype = Object.create(superClass.prototype);\n subClass.prototype.constructor = subClass;\n subClass.__proto__ = superClass;\n}","import User from 'flarum/models/User';\r\nimport UserPage from 'flarum/components/UserPage';\r\nimport UserCard from 'flarum/components/UserCard';\r\nimport FieldSet from 'flarum/components/FieldSet';\r\nimport icon from 'flarum/helpers/icon';\r\nimport avatar from 'flarum/helpers/avatar';\r\nimport username from 'flarum/helpers/username';\r\nimport Model from 'flarum/Model';\r\nimport ItemList from 'flarum/utils/ItemList';\r\nimport { extend } from 'flarum/extend';\r\nimport humanTime from 'flarum/utils/humanTime';\r\nimport ProfileView from '../ProfileView';\r\n\r\napp.initializers.add('michaelbelgium-flarum-profile-views', function() {\r\n app.store.models.userprofileview = ProfileView;//\".userprofileview\" = serializer type \"userprofileview\"\r\n User.prototype.profileViews = Model.hasMany('profileViews');//comes from AddUserProfileViewsRelationship::RELATIONSHIP = php model relationship method\r\n\r\n extend(UserCard.prototype, 'infoItems', function(items) {\r\n const user = this.props.user;\r\n\r\n items.add('profile-views',(\r\n \r\n {icon('far fa-eye')}\r\n {' '}\r\n {app.translator.trans('flarum_profile_views.forum.user.views_count_text', {viewcount: '' + user.profileViews().length})}\r\n \r\n ));\r\n });\r\n\r\n extend(UserPage.prototype, 'sidebarItems', function(items) {\r\n const lastViewed = new ItemList();\r\n\r\n $.each(this.user.profileViews(), function(index, pv) {\r\n lastViewed.add('lastUser-' + pv.viewer().id(),\r\n \r\n {avatar(pv.viewer(), {className: 'lastUser-avatar'})}\r\n
\r\n {username(pv.viewer())}\r\n {humanTime(pv.visitedAt())}\r\n
\r\n
\r\n );\r\n });\r\n\r\n items.add('lastViewedUsers', FieldSet.component({\r\n label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'),\r\n className: 'LastUsers',\r\n children: lastViewed.toArray()\r\n }));\r\n });\r\n\r\n extend(UserPage.prototype, 'show', function() {\r\n if(typeof app.session.user !== 'undefined' && app.session.user.id() !== this.user.id())\r\n {\r\n app.request({\r\n method: 'POST',\r\n url: app.forum.attribute('apiUrl') + '/profileview',\r\n data: { \r\n viewer: app.session.user.id(),\r\n viewedUser: this.user.id()\r\n }\r\n });\r\n }\r\n });\r\n});"],"sourceRoot":""} \ No newline at end of file diff --git a/js/src/forum/index.js b/js/src/forum/index.js index 84459bc..3bd8bb9 100644 --- a/js/src/forum/index.js +++ b/js/src/forum/index.js @@ -34,7 +34,10 @@ app.initializers.add('michaelbelgium-flarum-profile-views', function() { lastViewed.add('lastUser-' + pv.viewer().id(), {avatar(pv.viewer(), {className: 'lastUser-avatar'})} - {username(pv.viewer())} +
+ {username(pv.viewer())} + {humanTime(pv.visitedAt())} +
); }); diff --git a/less/extension.less b/less/extension.less index 98b269a..8f27ef0 100644 --- a/less/extension.less +++ b/less/extension.less @@ -7,11 +7,30 @@ fieldset.LastUsers { display: block; span.lastUser-avatar { - width: 35px; + width: 20%; + display: inline-block; height: 35px; line-height: 35px; - vertical-align: middle; - margin-right: 6px; + } + + div { + display: inline-block; + width: 80%; + + span.username { + margin-left: 6px; + } + + span.lastUser-visited { + float: right; + font-size: .8em; + } + } + } + + li a:hover { + div > span { + text-decoration: underline; } } } From 131d0bacc770518af9b069c50feec59e3fea9e43 Mon Sep 17 00:00:00 2001 From: Michael V Date: Sat, 26 Jan 2019 20:58:49 +0100 Subject: [PATCH 34/37] Add screenshot in readme --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ff6347b..9dcf1f0 100644 --- a/README.md +++ b/README.md @@ -21,4 +21,6 @@ php flarum cache:clear # Media -![image](http://puu.sh/yxd7o.png) \ No newline at end of file +![image](http://puu.sh/yxd7o.png) + +![image](http://puu.sh/CCJvo.png) \ No newline at end of file From 50d639b78a89b6bb1587cb6bd9877e0fec626f6d Mon Sep 17 00:00:00 2001 From: Michael V Date: Sat, 2 Feb 2019 21:48:36 +0100 Subject: [PATCH 35/37] Show only last 5 viewers --- js/dist/forum.js | 2 +- js/dist/forum.js.map | 2 +- js/src/forum/index.js | 31 ++++++++++++++++++++----------- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/js/dist/forum.js b/js/dist/forum.js index 4a7970b..9a5475c 100644 --- a/js/dist/forum.js +++ b/js/dist/forum.js @@ -1,2 +1,2 @@ -module.exports=function(e){var r={};function t(o){if(r[o])return r[o].exports;var n=r[o]={i:o,l:!1,exports:{}};return e[o].call(n.exports,n,n.exports,t),n.l=!0,n.exports}return t.m=e,t.c=r,t.d=function(e,r,o){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:o})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(t.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)t.d(o,n,function(r){return e[r]}.bind(null,n));return o},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=11)}([function(e,r){e.exports=flarum.core.compat.Model},function(e,r){e.exports=flarum.core.compat.extend},function(e,r){e.exports=flarum.core.compat["components/UserPage"]},function(e,r){e.exports=flarum.core.compat["models/User"]},function(e,r){e.exports=flarum.core.compat["components/UserCard"]},function(e,r){e.exports=flarum.core.compat["components/FieldSet"]},function(e,r){e.exports=flarum.core.compat["helpers/icon"]},function(e,r){e.exports=flarum.core.compat["helpers/avatar"]},function(e,r){e.exports=flarum.core.compat["helpers/username"]},function(e,r){e.exports=flarum.core.compat["utils/ItemList"]},function(e,r){e.exports=flarum.core.compat["utils/humanTime"]},function(e,r,t){"use strict";t.r(r);var o=t(3),n=t.n(o),a=t(2),i=t.n(a),s=t(4),u=t.n(s),p=t(5),l=t.n(p),c=t(6),f=t.n(c),d=t(7),v=t.n(d),w=t(8),b=t.n(w),h=t(0),y=t.n(h),x=t(9),_=t.n(x),O=t(1),U=t(10),j=t.n(U);function g(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function P(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}var S=function(e){var r,t;function o(){for(var r,t=arguments.length,o=new Array(t),n=0;n=5&&(t=t.slice(0,5)),t.forEach(function(e){r.add("lastUser-"+e.viewer().id(),m("a",{href:app.forum.attribute("baseUrl")+"/u/"+e.viewer().username()},v()(e.viewer(),{className:"lastUser-avatar"}),m("div",null,b()(e.viewer()),m("span",{className:"lastUser-visited"},g()(e.visitedAt())))))})),e.add("lastViewedUsers",l.a.component({label:app.translator.trans("flarum_profile_views.forum.user.title_last_viewers"),className:"LastUsers",children:r.toArray()}))}),Object(O.extend)(i.a.prototype,"show",function(){void 0!==app.session.user&&app.session.user.id()!==this.user.id()&&app.request({method:"POST",url:app.forum.attribute("apiUrl")+"/profileview",data:{viewer:app.session.user.id(),viewedUser:this.user.id()}})})})}]); //# sourceMappingURL=forum.js.map \ No newline at end of file diff --git a/js/dist/forum.js.map b/js/dist/forum.js.map index 1c0e95a..8b6751d 100644 --- a/js/dist/forum.js.map +++ b/js/dist/forum.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack://@michaelbelgium/flarum-profile-views/webpack/bootstrap","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['Model']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['extend']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/UserPage']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['models/User']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/UserCard']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/FieldSet']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/icon']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/avatar']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/username']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['utils/ItemList']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['utils/humanTime']\"","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/defineProperty.js","webpack://@michaelbelgium/flarum-profile-views/./src/ProfileView.js","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/inheritsLoose.js","webpack://@michaelbelgium/flarum-profile-views/./src/forum/index.js"],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","flarum","core","compat","_assertThisInitialized","self","ReferenceError","_defineProperty","obj","configurable","writable","ProfileView","subClass","superClass","Model","attribute","transformDate","hasOne","constructor","__proto__","app","initializers","add","store","models","userprofileview","User","profileViews","hasMany","extend","UserCard","items","user","this","props","icon","translator","trans","viewcount","length","UserPage","lastViewed","ItemList","$","each","index","pv","viewer","id","href","forum","username","avatar","className","humanTime","visitedAt","FieldSet","component","label","children","toArray","session","request","method","url","data","viewedUser"],"mappings":"2BACA,IAAAA,EAAA,GAGA,SAAAC,EAAAC,GAGA,GAAAF,EAAAE,GACA,OAAAF,EAAAE,GAAAC,QAGA,IAAAC,EAAAJ,EAAAE,GAAA,CACAG,EAAAH,EACAI,GAAA,EACAH,QAAA,IAUA,OANAI,EAAAL,GAAAM,KAAAJ,EAAAD,QAAAC,IAAAD,QAAAF,GAGAG,EAAAE,GAAA,EAGAF,EAAAD,QA0DA,OArDAF,EAAAQ,EAAAF,EAGAN,EAAAS,EAAAV,EAGAC,EAAAU,EAAA,SAAAR,EAAAS,EAAAC,GACAZ,EAAAa,EAAAX,EAAAS,IACAG,OAAAC,eAAAb,EAAAS,EAAA,CAA0CK,YAAA,EAAAC,IAAAL,KAK1CZ,EAAAkB,EAAA,SAAAhB,GACA,oBAAAiB,eAAAC,aACAN,OAAAC,eAAAb,EAAAiB,OAAAC,YAAA,CAAwDC,MAAA,WAExDP,OAAAC,eAAAb,EAAA,cAAiDmB,OAAA,KAQjDrB,EAAAsB,EAAA,SAAAD,EAAAE,GAEA,GADA,EAAAA,IAAAF,EAAArB,EAAAqB,IACA,EAAAE,EAAA,OAAAF,EACA,KAAAE,GAAA,iBAAAF,QAAAG,WAAA,OAAAH,EACA,IAAAI,EAAAX,OAAAY,OAAA,MAGA,GAFA1B,EAAAkB,EAAAO,GACAX,OAAAC,eAAAU,EAAA,WAAyCT,YAAA,EAAAK,UACzC,EAAAE,GAAA,iBAAAF,EAAA,QAAAM,K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WAAYjC,KAAKD,KAAKgB","file":"forum.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 11);\n","module.exports = flarum.core.compat['Model'];","module.exports = flarum.core.compat['extend'];","module.exports = flarum.core.compat['components/UserPage'];","module.exports = flarum.core.compat['models/User'];","module.exports = flarum.core.compat['components/UserCard'];","module.exports = flarum.core.compat['components/FieldSet'];","module.exports = flarum.core.compat['helpers/icon'];","module.exports = flarum.core.compat['helpers/avatar'];","module.exports = flarum.core.compat['helpers/username'];","module.exports = flarum.core.compat['utils/ItemList'];","module.exports = flarum.core.compat['utils/humanTime'];","export default function _assertThisInitialized(self) {\n if (self === void 0) {\n throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\");\n }\n\n return self;\n}","export default function _defineProperty(obj, key, value) {\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n\n return obj;\n}","import Model from 'flarum/Model';\r\n\r\nexport default class ProfileView extends Model {\r\n //comes from ProfileViewSerializer (viewer(), viewedUser(), visited_at)\r\n visitedAt = Model.attribute('visited_at', Model.transformDate);\r\n viewer = Model.hasOne('viewer');\r\n viewedUser = Model.hasOne('viewedUser');\r\n}","export default function _inheritsLoose(subClass, superClass) {\n subClass.prototype = Object.create(superClass.prototype);\n subClass.prototype.constructor = subClass;\n subClass.__proto__ = superClass;\n}","import User from 'flarum/models/User';\r\nimport UserPage from 'flarum/components/UserPage';\r\nimport UserCard from 'flarum/components/UserCard';\r\nimport FieldSet from 'flarum/components/FieldSet';\r\nimport icon from 'flarum/helpers/icon';\r\nimport avatar from 'flarum/helpers/avatar';\r\nimport username from 'flarum/helpers/username';\r\nimport Model from 'flarum/Model';\r\nimport ItemList from 'flarum/utils/ItemList';\r\nimport { extend } from 'flarum/extend';\r\nimport humanTime from 'flarum/utils/humanTime';\r\nimport ProfileView from '../ProfileView';\r\n\r\napp.initializers.add('michaelbelgium-flarum-profile-views', function() {\r\n app.store.models.userprofileview = ProfileView;//\".userprofileview\" = serializer type \"userprofileview\"\r\n User.prototype.profileViews = Model.hasMany('profileViews');//comes from AddUserProfileViewsRelationship::RELATIONSHIP = php model relationship method\r\n\r\n extend(UserCard.prototype, 'infoItems', function(items) {\r\n const user = this.props.user;\r\n\r\n items.add('profile-views',(\r\n \r\n {icon('far fa-eye')}\r\n {' '}\r\n {app.translator.trans('flarum_profile_views.forum.user.views_count_text', {viewcount: '' + user.profileViews().length})}\r\n \r\n ));\r\n });\r\n\r\n extend(UserPage.prototype, 'sidebarItems', function(items) {\r\n const lastViewed = new ItemList();\r\n\r\n $.each(this.user.profileViews(), function(index, pv) {\r\n lastViewed.add('lastUser-' + pv.viewer().id(),\r\n \r\n {avatar(pv.viewer(), {className: 'lastUser-avatar'})}\r\n
\r\n {username(pv.viewer())}\r\n {humanTime(pv.visitedAt())}\r\n
\r\n
\r\n );\r\n });\r\n\r\n items.add('lastViewedUsers', FieldSet.component({\r\n label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'),\r\n className: 'LastUsers',\r\n children: lastViewed.toArray()\r\n }));\r\n });\r\n\r\n extend(UserPage.prototype, 'show', function() {\r\n if(typeof app.session.user !== 'undefined' && app.session.user.id() !== this.user.id())\r\n {\r\n app.request({\r\n method: 'POST',\r\n url: app.forum.attribute('apiUrl') + '/profileview',\r\n data: { \r\n viewer: app.session.user.id(),\r\n viewedUser: this.user.id()\r\n }\r\n });\r\n }\r\n });\r\n});"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack://@michaelbelgium/flarum-profile-views/webpack/bootstrap","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['Model']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['extend']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/UserPage']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['models/User']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/UserCard']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/FieldSet']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/icon']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/avatar']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/username']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['utils/ItemList']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['utils/humanTime']\"","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/defineProperty.js","webpack://@michaelbelgium/flarum-profile-views/./src/ProfileView.js","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/inheritsLoose.js","webpack://@michaelbelgium/flarum-profile-views/./src/forum/index.js"],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","flarum","core","compat","_assertThisInitialized","self","ReferenceError","_defineProperty","obj","configurable","writable","ProfileView","subClass","superClass","Model","attribute","transformDate","hasOne","constructor","__proto__","app","initializers","add","store","models","userprofileview","User","profileViews","hasMany","extend","UserCard","items","user","this","props","icon","translator","trans","viewcount","length","UserPage","lastViewed","ItemList","views","slice","forEach","pv","viewer","id","href","forum","username","avatar","className","humanTime","visitedAt","FieldSet","component","label","children","toArray","session","request","method","url","data","viewedUser"],"mappings":"2BACA,IAAAA,EAAA,GAGA,SAAAC,EAAAC,GAGA,GAAAF,EAAAE,GACA,OAAAF,EAAAE,GAAAC,QAGA,IAAAC,EAAAJ,EAAAE,GAAA,CACAG,EAAAH,EACAI,GAAA,EACAH,QAAA,IAUA,OANAI,EAAAL,GAAAM,KAAAJ,EAAAD,QAAAC,IAAAD,QAAAF,GAGAG,EAAAE,GAAA,EAGAF,EAAAD,QA0DA,OArDAF,EAAAQ,EAAAF,EAGAN,EAAAS,EAAAV,EAGAC,EAAAU,EAAA,SAAAR,EAAAS,EAAAC,GACAZ,EAAAa,EAAAX,EAAAS,IACAG,OAAAC,eAAAb,EAAAS,EAAA,CAA0CK,YAAA,EAAAC,IAAAL,KAK1CZ,EAAAkB,EAAA,SAAAhB,GACA,oBAAAiB,eAAAC,aACAN,OAAAC,eAAAb,EAAAiB,OAAAC,YAAA,CAAwDC,MAAA,WAExDP,OAAAC,eAAAb,EAAA,cAAiDmB,OAAA,KAQjDrB,EAAAsB,EAAA,SAAAD,EAAAE,GAEA,GADA,EAAAA,IAAAF,EAAArB,EAAAqB,IACA,EAAAE,EAAA,OAAAF,EACA,KAAAE,GAAA,iBAAAF,QAAAG,WAAA,OAAAH,EACA,IAAAI,EAAAX,OAAAY,OAAA,MAGA,GAFA1B,EAAAkB,EAAAO,GACAX,OAAAC,eAAAU,EAAA,WAAyCT,YAAA,EAAAK,UACzC,EAAAE,GAAA,iBAAAF,EAAA,QAAAM,KAAAN,EAAArB,EAAAU,EAAAe,EAAAE,EAAA,SAAAA,GAAgH,OAAAN,EAAAM,IAAqBC,KAAA,KAAAD,IACrI,OAAAF,GAIAzB,EAAA6B,EAAA,SAAA1B,GACA,IAAAS,EAAAT,KAAAqB,WACA,WAA2B,OAAArB,EAAA,SA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AkBd,EACnCe,IAAK7B,UAAU8B,aAAeb,IAAMc,QAAQ,gBAE5CC,iBAAOC,IAASjC,UAAW,YAAa,SAASkC,GAC7C,IAAMC,EAAOC,KAAKC,MAAMF,KAExBD,EAAMT,IAAI,gBACNjD,EAAA,YACK8D,IAAK,cACL,IACAf,IAAIgB,WAAWC,MAAM,mDAAoD,CAACC,UAAW,GAAKN,EAAKL,eAAeY,aAK3HV,iBAAOW,IAAS3C,UAAW,eAAgB,SAASkC,GAChD,IAAMU,EAAa,IAAIC,IAEnBC,EAAQV,KAAKD,KAAKL,gBAET,IAAVgB,IAEIA,EAAMJ,QAAU,IACfI,EAAQA,EAAMC,MAAM,EAAG,IAG3BD,EAAME,QAAQ,SAAAC,GACVL,EAAWnB,IAAI,YAAcwB,EAAGC,SAASC,KACrC3E,EAAA,KAAG4E,KAAM7B,IAAI8B,MAAMnC,UAAU,WAAa,MAAQ+B,EAAGC,SAASI,YACzDC,IAAON,EAAGC,SAAU,CAACM,UAAW,oBACjChF,EAAA,WACK8E,IAASL,EAAGC,UACb1E,EAAA,QAAMgF,UAAU,oBAAoBC,IAAUR,EAAGS,oBAOrExB,EAAMT,IAAI,kBAAmBkC,IAASC,UAAU,CAC5CC,MAAOtC,IAAIgB,WAAWC,MAAM,sDAC5BgB,UAAW,YACXM,SAAUlB,EAAWmB,eAI7B/B,iBAAOW,IAAS3C,UAAW,OAAQ,gBACA,IAArBuB,IAAIyC,QAAQ7B,MAAwBZ,IAAIyC,QAAQ7B,KAAKgB,OAASf,KAAKD,KAAKgB,MAE9E5B,IAAI0C,QAAQ,CACRC,OAAQ,OACRC,IAAK5C,IAAI8B,MAAMnC,UAAU,UAAY,eACrCkD,KAAM,CACFlB,OAAQ3B,IAAIyC,QAAQ7B,KAAKgB,KACzBkB,WAAYjC,KAAKD,KAAKgB","file":"forum.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 11);\n","module.exports = flarum.core.compat['Model'];","module.exports = flarum.core.compat['extend'];","module.exports = flarum.core.compat['components/UserPage'];","module.exports = flarum.core.compat['models/User'];","module.exports = flarum.core.compat['components/UserCard'];","module.exports = flarum.core.compat['components/FieldSet'];","module.exports = flarum.core.compat['helpers/icon'];","module.exports = flarum.core.compat['helpers/avatar'];","module.exports = flarum.core.compat['helpers/username'];","module.exports = flarum.core.compat['utils/ItemList'];","module.exports = flarum.core.compat['utils/humanTime'];","export default function _assertThisInitialized(self) {\n if (self === void 0) {\n throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\");\n }\n\n return self;\n}","export default function _defineProperty(obj, key, value) {\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n\n return obj;\n}","import Model from 'flarum/Model';\r\n\r\nexport default class ProfileView extends Model {\r\n //comes from ProfileViewSerializer (viewer(), viewedUser(), visited_at)\r\n visitedAt = Model.attribute('visited_at', Model.transformDate);\r\n viewer = Model.hasOne('viewer');\r\n viewedUser = Model.hasOne('viewedUser');\r\n}","export default function _inheritsLoose(subClass, superClass) {\n subClass.prototype = Object.create(superClass.prototype);\n subClass.prototype.constructor = subClass;\n subClass.__proto__ = superClass;\n}","import User from 'flarum/models/User';\r\nimport UserPage from 'flarum/components/UserPage';\r\nimport UserCard from 'flarum/components/UserCard';\r\nimport FieldSet from 'flarum/components/FieldSet';\r\nimport icon from 'flarum/helpers/icon';\r\nimport avatar from 'flarum/helpers/avatar';\r\nimport username from 'flarum/helpers/username';\r\nimport Model from 'flarum/Model';\r\nimport ItemList from 'flarum/utils/ItemList';\r\nimport { extend } from 'flarum/extend';\r\nimport humanTime from 'flarum/utils/humanTime';\r\nimport ProfileView from '../ProfileView';\r\n\r\napp.initializers.add('michaelbelgium-flarum-profile-views', function() {\r\n app.store.models.userprofileview = ProfileView;//\".userprofileview\" = serializer type \"userprofileview\"\r\n User.prototype.profileViews = Model.hasMany('profileViews');//comes from AddUserProfileViewsRelationship::RELATIONSHIP = php model relationship method\r\n\r\n extend(UserCard.prototype, 'infoItems', function(items) {\r\n const user = this.props.user;\r\n\r\n items.add('profile-views',(\r\n \r\n {icon('far fa-eye')}\r\n {' '}\r\n {app.translator.trans('flarum_profile_views.forum.user.views_count_text', {viewcount: '' + user.profileViews().length})}\r\n \r\n ));\r\n });\r\n\r\n extend(UserPage.prototype, 'sidebarItems', function(items) {\r\n const lastViewed = new ItemList();\r\n\r\n var views = this.user.profileViews();\r\n\r\n if(views !== false)\r\n {\r\n if(views.length >= 5) {\r\n views = views.slice(0, 5);\r\n }\r\n \r\n views.forEach(pv => {\r\n lastViewed.add('lastUser-' + pv.viewer().id(),\r\n \r\n {avatar(pv.viewer(), {className: 'lastUser-avatar'})}\r\n
\r\n {username(pv.viewer())}\r\n {humanTime(pv.visitedAt())}\r\n
\r\n
\r\n );\r\n });\r\n }\r\n\r\n items.add('lastViewedUsers', FieldSet.component({\r\n label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'),\r\n className: 'LastUsers',\r\n children: lastViewed.toArray()\r\n }));\r\n });\r\n\r\n extend(UserPage.prototype, 'show', function() {\r\n if(typeof app.session.user !== 'undefined' && app.session.user.id() !== this.user.id())\r\n {\r\n app.request({\r\n method: 'POST',\r\n url: app.forum.attribute('apiUrl') + '/profileview',\r\n data: { \r\n viewer: app.session.user.id(),\r\n viewedUser: this.user.id()\r\n }\r\n });\r\n }\r\n });\r\n});"],"sourceRoot":""} \ No newline at end of file diff --git a/js/src/forum/index.js b/js/src/forum/index.js index 3bd8bb9..e8c525f 100644 --- a/js/src/forum/index.js +++ b/js/src/forum/index.js @@ -30,17 +30,26 @@ app.initializers.add('michaelbelgium-flarum-profile-views', function() { extend(UserPage.prototype, 'sidebarItems', function(items) { const lastViewed = new ItemList(); - $.each(this.user.profileViews(), function(index, pv) { - lastViewed.add('lastUser-' + pv.viewer().id(), - - {avatar(pv.viewer(), {className: 'lastUser-avatar'})} -
- {username(pv.viewer())} - {humanTime(pv.visitedAt())} -
-
- ); - }); + var views = this.user.profileViews(); + + if(views !== false) + { + if(views.length >= 5) { + views = views.slice(0, 5); + } + + views.forEach(pv => { + lastViewed.add('lastUser-' + pv.viewer().id(), + + {avatar(pv.viewer(), {className: 'lastUser-avatar'})} +
+ {username(pv.viewer())} + {humanTime(pv.visitedAt())} +
+
+ ); + }); + } items.add('lastViewedUsers', FieldSet.component({ label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'), From f0b9f16598a9c53832646b3b7e705a454bbf77e2 Mon Sep 17 00:00:00 2001 From: Michael V Date: Sat, 2 Feb 2019 22:00:03 +0100 Subject: [PATCH 36/37] Show exact date on hover --- js/dist/forum.js | 2 +- js/dist/forum.js.map | 2 +- js/src/forum/index.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/js/dist/forum.js b/js/dist/forum.js index 9a5475c..4068d83 100644 --- a/js/dist/forum.js +++ b/js/dist/forum.js @@ -1,2 +1,2 @@ -module.exports=function(e){var r={};function t(o){if(r[o])return r[o].exports;var n=r[o]={i:o,l:!1,exports:{}};return e[o].call(n.exports,n,n.exports,t),n.l=!0,n.exports}return t.m=e,t.c=r,t.d=function(e,r,o){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:o})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(t.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)t.d(o,n,function(r){return e[r]}.bind(null,n));return o},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=11)}([function(e,r){e.exports=flarum.core.compat.Model},function(e,r){e.exports=flarum.core.compat.extend},function(e,r){e.exports=flarum.core.compat["components/UserPage"]},function(e,r){e.exports=flarum.core.compat["models/User"]},function(e,r){e.exports=flarum.core.compat["components/UserCard"]},function(e,r){e.exports=flarum.core.compat["components/FieldSet"]},function(e,r){e.exports=flarum.core.compat["helpers/icon"]},function(e,r){e.exports=flarum.core.compat["helpers/avatar"]},function(e,r){e.exports=flarum.core.compat["helpers/username"]},function(e,r){e.exports=flarum.core.compat["utils/ItemList"]},function(e,r){e.exports=flarum.core.compat["utils/humanTime"]},function(e,r,t){"use strict";t.r(r);var o=t(3),n=t.n(o),a=t(2),i=t.n(a),s=t(4),u=t.n(s),p=t(5),l=t.n(p),c=t(6),f=t.n(c),d=t(7),v=t.n(d),w=t(8),b=t.n(w),h=t(0),y=t.n(h),x=t(9),_=t.n(x),O=t(1),U=t(10),g=t.n(U);function j(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function P(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}var S=function(e){var r,t;function o(){for(var r,t=arguments.length,o=new Array(t),n=0;n=5&&(t=t.slice(0,5)),t.forEach(function(e){r.add("lastUser-"+e.viewer().id(),m("a",{href:app.forum.attribute("baseUrl")+"/u/"+e.viewer().username()},v()(e.viewer(),{className:"lastUser-avatar"}),m("div",null,b()(e.viewer()),m("span",{className:"lastUser-visited"},g()(e.visitedAt())))))})),e.add("lastViewedUsers",l.a.component({label:app.translator.trans("flarum_profile_views.forum.user.title_last_viewers"),className:"LastUsers",children:r.toArray()}))}),Object(O.extend)(i.a.prototype,"show",function(){void 0!==app.session.user&&app.session.user.id()!==this.user.id()&&app.request({method:"POST",url:app.forum.attribute("apiUrl")+"/profileview",data:{viewer:app.session.user.id(),viewedUser:this.user.id()}})})})}]); +module.exports=function(e){var t={};function r(o){if(t[o])return t[o].exports;var n=t[o]={i:o,l:!1,exports:{}};return e[o].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.m=e,r.c=t,r.d=function(e,t,o){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(r.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)r.d(o,n,function(t){return e[t]}.bind(null,n));return o},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=11)}([function(e,t){e.exports=flarum.core.compat.Model},function(e,t){e.exports=flarum.core.compat.extend},function(e,t){e.exports=flarum.core.compat["components/UserPage"]},function(e,t){e.exports=flarum.core.compat["models/User"]},function(e,t){e.exports=flarum.core.compat["components/UserCard"]},function(e,t){e.exports=flarum.core.compat["components/FieldSet"]},function(e,t){e.exports=flarum.core.compat["helpers/icon"]},function(e,t){e.exports=flarum.core.compat["helpers/avatar"]},function(e,t){e.exports=flarum.core.compat["helpers/username"]},function(e,t){e.exports=flarum.core.compat["utils/ItemList"]},function(e,t){e.exports=flarum.core.compat["utils/humanTime"]},function(e,t,r){"use strict";r.r(t);var o=r(3),n=r.n(o),a=r(2),i=r.n(a),s=r(4),u=r.n(s),p=r(5),l=r.n(p),c=r(6),f=r.n(c),d=r(7),v=r.n(d),w=r(8),b=r.n(w),h=r(0),y=r.n(h),x=r(9),_=r.n(x),O=r(1),g=r(10),U=r.n(g);function j(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function P(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var S=function(e){var t,r;function o(){for(var t,r=arguments.length,o=new Array(r),n=0;n=5&&(r=r.slice(0,5)),r.forEach(function(e){t.add("lastUser-"+e.viewer().id(),m("a",{href:app.forum.attribute("baseUrl")+"/u/"+e.viewer().username()},v()(e.viewer(),{className:"lastUser-avatar"}),m("div",null,b()(e.viewer()),m("span",{className:"lastUser-visited",title:e.visitedAt().toLocaleString()},U()(e.visitedAt())))))})),e.add("lastViewedUsers",l.a.component({label:app.translator.trans("flarum_profile_views.forum.user.title_last_viewers"),className:"LastUsers",children:t.toArray()}))}),Object(O.extend)(i.a.prototype,"show",function(){void 0!==app.session.user&&app.session.user.id()!==this.user.id()&&app.request({method:"POST",url:app.forum.attribute("apiUrl")+"/profileview",data:{viewer:app.session.user.id(),viewedUser:this.user.id()}})})})}]); //# sourceMappingURL=forum.js.map \ No newline at end of file diff --git a/js/dist/forum.js.map b/js/dist/forum.js.map index 8b6751d..e014060 100644 --- a/js/dist/forum.js.map +++ b/js/dist/forum.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack://@michaelbelgium/flarum-profile-views/webpack/bootstrap","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['Model']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['extend']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/UserPage']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['models/User']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/UserCard']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/FieldSet']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/icon']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/avatar']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/username']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['utils/ItemList']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['utils/humanTime']\"","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/defineProperty.js","webpack://@michaelbelgium/flarum-profile-views/./src/ProfileView.js","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/inheritsLoose.js","webpack://@michaelbelgium/flarum-profile-views/./src/forum/index.js"],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","flarum","core","compat","_assertThisInitialized","self","ReferenceError","_defineProperty","obj","configurable","writable","ProfileView","subClass","superClass","Model","attribute","transformDate","hasOne","constructor","__proto__","app","initializers","add","store","models","userprofileview","User","profileViews","hasMany","extend","UserCard","items","user","this","props","icon","translator","trans","viewcount","length","UserPage","lastViewed","ItemList","views","slice","forEach","pv","viewer","id","href","forum","username","avatar","className","humanTime","visitedAt","FieldSet","component","label","children","toArray","session","request","method","url","data","viewedUser"],"mappings":"2BACA,IAAAA,EAAA,GAGA,SAAAC,EAAAC,GAGA,GAAAF,EAAAE,GACA,OAAAF,EAAAE,GAAAC,QAGA,IAAAC,EAAAJ,EAAAE,GAAA,CACAG,EAAAH,EACAI,GAAA,EACAH,QAAA,IAUA,OANAI,EAAAL,GAAAM,KAAAJ,EAAAD,QAA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AAKD,KAAKL,gBAET,IAAVgB,IAEIA,EAAMJ,QAAU,IACfI,EAAQA,EAAMC,MAAM,EAAG,IAG3BD,EAAME,QAAQ,SAAAC,GACVL,EAAWnB,IAAI,YAAcwB,EAAGC,SAASC,KACrC3E,EAAA,KAAG4E,KAAM7B,IAAI8B,MAAMnC,UAAU,WAAa,MAAQ+B,EAAGC,SAASI,YACzDC,IAAON,EAAGC,SAAU,CAACM,UAAW,oBACjChF,EAAA,WACK8E,IAASL,EAAGC,UACb1E,EAAA,QAAMgF,UAAU,oBAAoBC,IAAUR,EAAGS,oBAOrExB,EAAMT,IAAI,kBAAmBkC,IAASC,UAAU,CAC5CC,MAAOtC,IAAIgB,WAAWC,MAAM,sDAC5BgB,UAAW,YACXM,SAAUlB,EAAWmB,eAI7B/B,iBAAOW,IAAS3C,UAAW,OAAQ,gBACA,IAArBuB,IAAIyC,QAAQ7B,MAAwBZ,IAAIyC,QAAQ7B,KAAKgB,OAASf,KAAKD,KAAKgB,MAE9E5B,IAAI0C,QAAQ,CACRC,OAAQ,OACRC,IAAK5C,IAAI8B,MAAMnC,UAAU,UAAY,eACrCkD,KAAM,CACFlB,OAAQ3B,IAAIyC,QAAQ7B,KAAKgB,KACzBkB,WAAYjC,KAAKD,KAAKgB","file":"forum.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 11);\n","module.exports = flarum.core.compat['Model'];","module.exports = flarum.core.compat['extend'];","module.exports = flarum.core.compat['components/UserPage'];","module.exports = flarum.core.compat['models/User'];","module.exports = flarum.core.compat['components/UserCard'];","module.exports = flarum.core.compat['components/FieldSet'];","module.exports = flarum.core.compat['helpers/icon'];","module.exports = flarum.core.compat['helpers/avatar'];","module.exports = flarum.core.compat['helpers/username'];","module.exports = flarum.core.compat['utils/ItemList'];","module.exports = flarum.core.compat['utils/humanTime'];","export default function _assertThisInitialized(self) {\n if (self === void 0) {\n throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\");\n }\n\n return self;\n}","export default function _defineProperty(obj, key, value) {\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n\n return obj;\n}","import Model from 'flarum/Model';\r\n\r\nexport default class ProfileView extends Model {\r\n //comes from ProfileViewSerializer (viewer(), viewedUser(), visited_at)\r\n visitedAt = Model.attribute('visited_at', Model.transformDate);\r\n viewer = Model.hasOne('viewer');\r\n viewedUser = Model.hasOne('viewedUser');\r\n}","export default function _inheritsLoose(subClass, superClass) {\n subClass.prototype = Object.create(superClass.prototype);\n subClass.prototype.constructor = subClass;\n subClass.__proto__ = superClass;\n}","import User from 'flarum/models/User';\r\nimport UserPage from 'flarum/components/UserPage';\r\nimport UserCard from 'flarum/components/UserCard';\r\nimport FieldSet from 'flarum/components/FieldSet';\r\nimport icon from 'flarum/helpers/icon';\r\nimport avatar from 'flarum/helpers/avatar';\r\nimport username from 'flarum/helpers/username';\r\nimport Model from 'flarum/Model';\r\nimport ItemList from 'flarum/utils/ItemList';\r\nimport { extend } from 'flarum/extend';\r\nimport humanTime from 'flarum/utils/humanTime';\r\nimport ProfileView from '../ProfileView';\r\n\r\napp.initializers.add('michaelbelgium-flarum-profile-views', function() {\r\n app.store.models.userprofileview = ProfileView;//\".userprofileview\" = serializer type \"userprofileview\"\r\n User.prototype.profileViews = Model.hasMany('profileViews');//comes from AddUserProfileViewsRelationship::RELATIONSHIP = php model relationship method\r\n\r\n extend(UserCard.prototype, 'infoItems', function(items) {\r\n const user = this.props.user;\r\n\r\n items.add('profile-views',(\r\n \r\n {icon('far fa-eye')}\r\n {' '}\r\n {app.translator.trans('flarum_profile_views.forum.user.views_count_text', {viewcount: '' + user.profileViews().length})}\r\n \r\n ));\r\n });\r\n\r\n extend(UserPage.prototype, 'sidebarItems', function(items) {\r\n const lastViewed = new ItemList();\r\n\r\n var views = this.user.profileViews();\r\n\r\n if(views !== false)\r\n {\r\n if(views.length >= 5) {\r\n views = views.slice(0, 5);\r\n }\r\n \r\n views.forEach(pv => {\r\n lastViewed.add('lastUser-' + pv.viewer().id(),\r\n \r\n {avatar(pv.viewer(), {className: 'lastUser-avatar'})}\r\n
\r\n {username(pv.viewer())}\r\n {humanTime(pv.visitedAt())}\r\n
\r\n
\r\n );\r\n });\r\n }\r\n\r\n items.add('lastViewedUsers', FieldSet.component({\r\n label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'),\r\n className: 'LastUsers',\r\n children: lastViewed.toArray()\r\n }));\r\n });\r\n\r\n extend(UserPage.prototype, 'show', function() {\r\n if(typeof app.session.user !== 'undefined' && app.session.user.id() !== this.user.id())\r\n {\r\n app.request({\r\n method: 'POST',\r\n url: app.forum.attribute('apiUrl') + '/profileview',\r\n data: { \r\n viewer: app.session.user.id(),\r\n viewedUser: this.user.id()\r\n }\r\n });\r\n }\r\n });\r\n});"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack://@michaelbelgium/flarum-profile-views/webpack/bootstrap","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['Model']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['extend']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/UserPage']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['models/User']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/UserCard']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/FieldSet']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/icon']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/avatar']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/username']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['utils/ItemList']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['utils/humanTime']\"","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/defineProperty.js","webpack://@michaelbelgium/flarum-profile-views/./src/ProfileView.js","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/inheritsLoose.js","webpack://@michaelbelgium/flarum-profile-views/./src/forum/index.js"],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","flarum","core","compat","_assertThisInitialized","self","ReferenceError","_defineProperty","obj","configurable","writable","ProfileView","subClass","superClass","Model","attribute","transformDate","hasOne","constructor","__proto__","app","initializers","add","store","models","userprofileview","User","profileViews","hasMany","extend","UserCard","items","user","this","props","icon","translator","trans","viewcount","length","UserPage","lastViewed","ItemList","views","slice","forEach","pv","viewer","id","href","forum","username","avatar","className","title","visitedAt","toLocaleString","humanTime","FieldSet","component","label","children","toArray","session","request","method","url","data","viewedUser"],"mappings":"2BACA,IAAAA,EAAA,GAGA,SAAAC,EAAAC,GAGA,GAAAF,EAAAE,GACA,OAAAF,EAAAE,GAAAC,QAGA,IAAAC,EAAAJ,EAAAE,GAAA,CACAG,EAAAH,EACAI,GAAA,EACAH,QAAA,IAUA,OANAI,EAAAL,GAAAM,KAAAJ,EAAAD,QAAAC,IAAAD,QAAAF,GAGAG,EAAAE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IA,EAAMJ,QAAU,IACfI,EAAQA,EAAMC,MAAM,EAAG,IAG3BD,EAAME,QAAQ,SAAAC,GACVL,EAAWnB,IAAI,YAAcwB,EAAGC,SAASC,KACrC3E,EAAA,KAAG4E,KAAM7B,IAAI8B,MAAMnC,UAAU,WAAa,MAAQ+B,EAAGC,SAASI,YACzDC,IAAON,EAAGC,SAAU,CAACM,UAAW,oBACjChF,EAAA,WACK8E,IAASL,EAAGC,UACb1E,EAAA,QAAMgF,UAAU,mBAAmBC,MAAOR,EAAGS,YAAYC,kBAAmBC,IAAUX,EAAGS,oBAO7GxB,EAAMT,IAAI,kBAAmBoC,IAASC,UAAU,CAC5CC,MAAOxC,IAAIgB,WAAWC,MAAM,sDAC5BgB,UAAW,YACXQ,SAAUpB,EAAWqB,eAI7BjC,iBAAOW,IAAS3C,UAAW,OAAQ,gBACA,IAArBuB,IAAI2C,QAAQ/B,MAAwBZ,IAAI2C,QAAQ/B,KAAKgB,OAASf,KAAKD,KAAKgB,MAE9E5B,IAAI4C,QAAQ,CACRC,OAAQ,OACRC,IAAK9C,IAAI8B,MAAMnC,UAAU,UAAY,eACrCoD,KAAM,CACFpB,OAAQ3B,IAAI2C,QAAQ/B,KAAKgB,KACzBoB,WAAYnC,KAAKD,KAAKgB","file":"forum.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 11);\n","module.exports = flarum.core.compat['Model'];","module.exports = flarum.core.compat['extend'];","module.exports = flarum.core.compat['components/UserPage'];","module.exports = flarum.core.compat['models/User'];","module.exports = flarum.core.compat['components/UserCard'];","module.exports = flarum.core.compat['components/FieldSet'];","module.exports = flarum.core.compat['helpers/icon'];","module.exports = flarum.core.compat['helpers/avatar'];","module.exports = flarum.core.compat['helpers/username'];","module.exports = flarum.core.compat['utils/ItemList'];","module.exports = flarum.core.compat['utils/humanTime'];","export default function _assertThisInitialized(self) {\n if (self === void 0) {\n throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\");\n }\n\n return self;\n}","export default function _defineProperty(obj, key, value) {\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n\n return obj;\n}","import Model from 'flarum/Model';\r\n\r\nexport default class ProfileView extends Model {\r\n //comes from ProfileViewSerializer (viewer(), viewedUser(), visited_at)\r\n visitedAt = Model.attribute('visited_at', Model.transformDate);\r\n viewer = Model.hasOne('viewer');\r\n viewedUser = Model.hasOne('viewedUser');\r\n}","export default function _inheritsLoose(subClass, superClass) {\n subClass.prototype = Object.create(superClass.prototype);\n subClass.prototype.constructor = subClass;\n subClass.__proto__ = superClass;\n}","import User from 'flarum/models/User';\r\nimport UserPage from 'flarum/components/UserPage';\r\nimport UserCard from 'flarum/components/UserCard';\r\nimport FieldSet from 'flarum/components/FieldSet';\r\nimport icon from 'flarum/helpers/icon';\r\nimport avatar from 'flarum/helpers/avatar';\r\nimport username from 'flarum/helpers/username';\r\nimport Model from 'flarum/Model';\r\nimport ItemList from 'flarum/utils/ItemList';\r\nimport { extend } from 'flarum/extend';\r\nimport humanTime from 'flarum/utils/humanTime';\r\nimport ProfileView from '../ProfileView';\r\n\r\napp.initializers.add('michaelbelgium-flarum-profile-views', function() {\r\n app.store.models.userprofileview = ProfileView;//\".userprofileview\" = serializer type \"userprofileview\"\r\n User.prototype.profileViews = Model.hasMany('profileViews');//comes from AddUserProfileViewsRelationship::RELATIONSHIP = php model relationship method\r\n\r\n extend(UserCard.prototype, 'infoItems', function(items) {\r\n const user = this.props.user;\r\n\r\n items.add('profile-views',(\r\n \r\n {icon('far fa-eye')}\r\n {' '}\r\n {app.translator.trans('flarum_profile_views.forum.user.views_count_text', {viewcount: '' + user.profileViews().length})}\r\n \r\n ));\r\n });\r\n\r\n extend(UserPage.prototype, 'sidebarItems', function(items) {\r\n const lastViewed = new ItemList();\r\n\r\n var views = this.user.profileViews();\r\n\r\n if(views !== false)\r\n {\r\n if(views.length >= 5) {\r\n views = views.slice(0, 5);\r\n }\r\n \r\n views.forEach(pv => {\r\n lastViewed.add('lastUser-' + pv.viewer().id(),\r\n \r\n {avatar(pv.viewer(), {className: 'lastUser-avatar'})}\r\n
\r\n {username(pv.viewer())}\r\n {humanTime(pv.visitedAt())}\r\n
\r\n
\r\n );\r\n });\r\n }\r\n\r\n items.add('lastViewedUsers', FieldSet.component({\r\n label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'),\r\n className: 'LastUsers',\r\n children: lastViewed.toArray()\r\n }));\r\n });\r\n\r\n extend(UserPage.prototype, 'show', function() {\r\n if(typeof app.session.user !== 'undefined' && app.session.user.id() !== this.user.id())\r\n {\r\n app.request({\r\n method: 'POST',\r\n url: app.forum.attribute('apiUrl') + '/profileview',\r\n data: { \r\n viewer: app.session.user.id(),\r\n viewedUser: this.user.id()\r\n }\r\n });\r\n }\r\n });\r\n});"],"sourceRoot":""} \ No newline at end of file diff --git a/js/src/forum/index.js b/js/src/forum/index.js index e8c525f..ab811a7 100644 --- a/js/src/forum/index.js +++ b/js/src/forum/index.js @@ -44,7 +44,7 @@ app.initializers.add('michaelbelgium-flarum-profile-views', function() { {avatar(pv.viewer(), {className: 'lastUser-avatar'})}
{username(pv.viewer())} - {humanTime(pv.visitedAt())} + {humanTime(pv.visitedAt())}
); From f66610434090ea8df5ded6506db04c557f168eaa Mon Sep 17 00:00:00 2001 From: Michael V Date: Sat, 2 Feb 2019 22:04:11 +0100 Subject: [PATCH 37/37] Check if relationship returns false --- js/dist/forum.js | 2 +- js/dist/forum.js.map | 2 +- js/src/forum/index.js | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/js/dist/forum.js b/js/dist/forum.js index 4068d83..1c8a55f 100644 --- a/js/dist/forum.js +++ b/js/dist/forum.js @@ -1,2 +1,2 @@ -module.exports=function(e){var t={};function r(o){if(t[o])return t[o].exports;var n=t[o]={i:o,l:!1,exports:{}};return e[o].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.m=e,r.c=t,r.d=function(e,t,o){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(r.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)r.d(o,n,function(t){return e[t]}.bind(null,n));return o},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=11)}([function(e,t){e.exports=flarum.core.compat.Model},function(e,t){e.exports=flarum.core.compat.extend},function(e,t){e.exports=flarum.core.compat["components/UserPage"]},function(e,t){e.exports=flarum.core.compat["models/User"]},function(e,t){e.exports=flarum.core.compat["components/UserCard"]},function(e,t){e.exports=flarum.core.compat["components/FieldSet"]},function(e,t){e.exports=flarum.core.compat["helpers/icon"]},function(e,t){e.exports=flarum.core.compat["helpers/avatar"]},function(e,t){e.exports=flarum.core.compat["helpers/username"]},function(e,t){e.exports=flarum.core.compat["utils/ItemList"]},function(e,t){e.exports=flarum.core.compat["utils/humanTime"]},function(e,t,r){"use strict";r.r(t);var o=r(3),n=r.n(o),a=r(2),i=r.n(a),s=r(4),u=r.n(s),p=r(5),l=r.n(p),c=r(6),f=r.n(c),d=r(7),v=r.n(d),w=r(8),b=r.n(w),h=r(0),y=r.n(h),x=r(9),_=r.n(x),O=r(1),g=r(10),U=r.n(g);function j(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function P(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var S=function(e){var t,r;function o(){for(var t,r=arguments.length,o=new Array(r),n=0;n=5&&(r=r.slice(0,5)),r.forEach(function(e){t.add("lastUser-"+e.viewer().id(),m("a",{href:app.forum.attribute("baseUrl")+"/u/"+e.viewer().username()},v()(e.viewer(),{className:"lastUser-avatar"}),m("div",null,b()(e.viewer()),m("span",{className:"lastUser-visited",title:e.visitedAt().toLocaleString()},U()(e.visitedAt())))))})),e.add("lastViewedUsers",l.a.component({label:app.translator.trans("flarum_profile_views.forum.user.title_last_viewers"),className:"LastUsers",children:t.toArray()}))}),Object(O.extend)(i.a.prototype,"show",function(){void 0!==app.session.user&&app.session.user.id()!==this.user.id()&&app.request({method:"POST",url:app.forum.attribute("apiUrl")+"/profileview",data:{viewer:app.session.user.id(),viewedUser:this.user.id()}})})})}]); +module.exports=function(e){var r={};function t(o){if(r[o])return r[o].exports;var n=r[o]={i:o,l:!1,exports:{}};return e[o].call(n.exports,n,n.exports,t),n.l=!0,n.exports}return t.m=e,t.c=r,t.d=function(e,r,o){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:o})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(t.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)t.d(o,n,function(r){return e[r]}.bind(null,n));return o},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=11)}([function(e,r){e.exports=flarum.core.compat.Model},function(e,r){e.exports=flarum.core.compat.extend},function(e,r){e.exports=flarum.core.compat["components/UserPage"]},function(e,r){e.exports=flarum.core.compat["models/User"]},function(e,r){e.exports=flarum.core.compat["components/UserCard"]},function(e,r){e.exports=flarum.core.compat["components/FieldSet"]},function(e,r){e.exports=flarum.core.compat["helpers/icon"]},function(e,r){e.exports=flarum.core.compat["helpers/avatar"]},function(e,r){e.exports=flarum.core.compat["helpers/username"]},function(e,r){e.exports=flarum.core.compat["utils/ItemList"]},function(e,r){e.exports=flarum.core.compat["utils/humanTime"]},function(e,r,t){"use strict";t.r(r);var o=t(3),n=t.n(o),a=t(2),i=t.n(a),s=t(4),u=t.n(s),p=t(5),l=t.n(p),c=t(6),f=t.n(c),d=t(7),v=t.n(d),w=t(8),b=t.n(w),h=t(0),y=t.n(h),x=t(9),_=t.n(x),O=t(1),g=t(10),U=t.n(g);function j(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function P(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}var S=function(e){var r,t;function o(){for(var r,t=arguments.length,o=new Array(t),n=0;n=5&&(t=t.slice(0,5)),t.forEach(function(e){r.add("lastUser-"+e.viewer().id(),m("a",{href:app.forum.attribute("baseUrl")+"/u/"+e.viewer().username()},v()(e.viewer(),{className:"lastUser-avatar"}),m("div",null,b()(e.viewer()),m("span",{className:"lastUser-visited",title:e.visitedAt().toLocaleString()},U()(e.visitedAt())))))})),e.add("lastViewedUsers",l.a.component({label:app.translator.trans("flarum_profile_views.forum.user.title_last_viewers"),className:"LastUsers",children:r.toArray()}))}),Object(O.extend)(i.a.prototype,"show",function(){void 0!==app.session.user&&app.session.user.id()!==this.user.id()&&app.request({method:"POST",url:app.forum.attribute("apiUrl")+"/profileview",data:{viewer:app.session.user.id(),viewedUser:this.user.id()}})})})}]); //# sourceMappingURL=forum.js.map \ No newline at end of file diff --git a/js/dist/forum.js.map b/js/dist/forum.js.map index e014060..b0a3888 100644 --- a/js/dist/forum.js.map +++ b/js/dist/forum.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack://@michaelbelgium/flarum-profile-views/webpack/bootstrap","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['Model']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['extend']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/UserPage']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['models/User']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/UserCard']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/FieldSet']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/icon']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/avatar']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/username']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['utils/ItemList']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['utils/humanTime']\"","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/defineProperty.js","webpack://@michaelbelgium/flarum-profile-views/./src/ProfileView.js","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/inheritsLoose.js","webpack://@michaelbelgium/flarum-profile-views/./src/forum/index.js"],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","flarum","core","compat","_assertThisInitialized","self","ReferenceError","_defineProperty","obj","configurable","writable","ProfileView","subClass","superClass","Model","attribute","transformDate","hasOne","constructor","__proto__","app","initializers","add","store","models","userprofileview","User","profileViews","hasMany","extend","UserCard","items","user","this","props","icon","translator","trans","viewcount","length","UserPage","lastViewed","ItemList","views","slice","forEach","pv","viewer","id","href","forum","username","avatar","className","title","visitedAt","toLocaleString","humanTime","FieldSet","component","label","children","toArray","session","request","method","url","data","viewedUser"],"mappings":"2BACA,IAAAA,EAAA,GAGA,SAAAC,EAAAC,GAGA,GAAAF,EAAAE,GACA,OAAAF,EAAAE,GAAAC,QAGA,IAAAC,EAAAJ,EAAAE,GAAA,CACAG,EAAAH,EACAI,GAAA,EACAH,QAAA,IAUA,OANAI,EAAAL,GAAAM,KAAAJ,EAAAD,QAAAC,IAAAD,QAAAF,GAGAG,EAAAE,GAAA,EAGAF,EAAAD,QA0DA,OArDAF,EAAAQ,EAAAF,EAGAN,EAAAS,EAAAV,EAGAC,EAAAU,EAAA,SAAAR,EAAAS,EAAAC,GACAZ,EAAAa,EAAAX,EAAAS,IACAG,OAAAC,eAAAb,EAAAS,EAAA,CAA0CK,YAAA,EAAAC,IAAAL,KAK1CZ,EAAAkB,EAAA,SAAAhB,GACA,oBAAAiB,eAAAC,aACAN,OAAAC,eAAAb,EAAAiB,OAAAC,YAAA,CAAwDC,MAAA,WAExDP,OAAAC,eAAAb,EAAA,cAAiDmB,OAAA,KAQjDrB,EAAAsB,EAAA,SAAAD,EAAAE,GAEA,GADA,EAAAA,IAAAF,EAAArB,EAAAqB,IACA,EAAAE,EAAA,OAAAF,EACA,KAAAE,GAAA,iBAAAF,QAAAG,WAAA,OAAAH,EACA,IAAAI,EAAAX,OAAAY,OAAA,MAGA,GAFA1B,EAAAkB,EAAAO,GACAX,OAAAC,eAAAU,EAAA,WAAyCT,YAAA,EAAAK,UACzC,EAAAE,GAAA,iBAAAF,EA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,OACRC,IAAK9C,IAAI8B,MAAMnC,UAAU,UAAY,eACrCoD,KAAM,CACFpB,OAAQ3B,IAAI2C,QAAQ/B,KAAKgB,KACzBoB,WAAYnC,KAAKD,KAAKgB","file":"forum.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 11);\n","module.exports = flarum.core.compat['Model'];","module.exports = flarum.core.compat['extend'];","module.exports = flarum.core.compat['components/UserPage'];","module.exports = flarum.core.compat['models/User'];","module.exports = flarum.core.compat['components/UserCard'];","module.exports = flarum.core.compat['components/FieldSet'];","module.exports = flarum.core.compat['helpers/icon'];","module.exports = flarum.core.compat['helpers/avatar'];","module.exports = flarum.core.compat['helpers/username'];","module.exports = flarum.core.compat['utils/ItemList'];","module.exports = flarum.core.compat['utils/humanTime'];","export default function _assertThisInitialized(self) {\n if (self === void 0) {\n throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\");\n }\n\n return self;\n}","export default function _defineProperty(obj, key, value) {\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n\n return obj;\n}","import Model from 'flarum/Model';\r\n\r\nexport default class ProfileView extends Model {\r\n //comes from ProfileViewSerializer (viewer(), viewedUser(), visited_at)\r\n visitedAt = Model.attribute('visited_at', Model.transformDate);\r\n viewer = Model.hasOne('viewer');\r\n viewedUser = Model.hasOne('viewedUser');\r\n}","export default function _inheritsLoose(subClass, superClass) {\n subClass.prototype = Object.create(superClass.prototype);\n subClass.prototype.constructor = subClass;\n subClass.__proto__ = superClass;\n}","import User from 'flarum/models/User';\r\nimport UserPage from 'flarum/components/UserPage';\r\nimport UserCard from 'flarum/components/UserCard';\r\nimport FieldSet from 'flarum/components/FieldSet';\r\nimport icon from 'flarum/helpers/icon';\r\nimport avatar from 'flarum/helpers/avatar';\r\nimport username from 'flarum/helpers/username';\r\nimport Model from 'flarum/Model';\r\nimport ItemList from 'flarum/utils/ItemList';\r\nimport { extend } from 'flarum/extend';\r\nimport humanTime from 'flarum/utils/humanTime';\r\nimport ProfileView from '../ProfileView';\r\n\r\napp.initializers.add('michaelbelgium-flarum-profile-views', function() {\r\n app.store.models.userprofileview = ProfileView;//\".userprofileview\" = serializer type \"userprofileview\"\r\n User.prototype.profileViews = Model.hasMany('profileViews');//comes from AddUserProfileViewsRelationship::RELATIONSHIP = php model relationship method\r\n\r\n extend(UserCard.prototype, 'infoItems', function(items) {\r\n const user = this.props.user;\r\n\r\n items.add('profile-views',(\r\n \r\n {icon('far fa-eye')}\r\n {' '}\r\n {app.translator.trans('flarum_profile_views.forum.user.views_count_text', {viewcount: '' + user.profileViews().length})}\r\n \r\n ));\r\n });\r\n\r\n extend(UserPage.prototype, 'sidebarItems', function(items) {\r\n const lastViewed = new ItemList();\r\n\r\n var views = this.user.profileViews();\r\n\r\n if(views !== false)\r\n {\r\n if(views.length >= 5) {\r\n views = views.slice(0, 5);\r\n }\r\n \r\n views.forEach(pv => {\r\n lastViewed.add('lastUser-' + pv.viewer().id(),\r\n \r\n {avatar(pv.viewer(), {className: 'lastUser-avatar'})}\r\n
\r\n {username(pv.viewer())}\r\n {humanTime(pv.visitedAt())}\r\n
\r\n
\r\n );\r\n });\r\n }\r\n\r\n items.add('lastViewedUsers', FieldSet.component({\r\n label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'),\r\n className: 'LastUsers',\r\n children: lastViewed.toArray()\r\n }));\r\n });\r\n\r\n extend(UserPage.prototype, 'show', function() {\r\n if(typeof app.session.user !== 'undefined' && app.session.user.id() !== this.user.id())\r\n {\r\n app.request({\r\n method: 'POST',\r\n url: app.forum.attribute('apiUrl') + '/profileview',\r\n data: { \r\n viewer: app.session.user.id(),\r\n viewedUser: this.user.id()\r\n }\r\n });\r\n }\r\n });\r\n});"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack://@michaelbelgium/flarum-profile-views/webpack/bootstrap","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['Model']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['extend']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/UserPage']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['models/User']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/UserCard']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['components/FieldSet']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/icon']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/avatar']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['helpers/username']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['utils/ItemList']\"","webpack://@michaelbelgium/flarum-profile-views/external \"flarum.core.compat['utils/humanTime']\"","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/defineProperty.js","webpack://@michaelbelgium/flarum-profile-views/./src/ProfileView.js","webpack://@michaelbelgium/flarum-profile-views/./node_modules/@babel/runtime/helpers/esm/inheritsLoose.js","webpack://@michaelbelgium/flarum-profile-views/./src/forum/index.js"],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","flarum","core","compat","_assertThisInitialized","self","ReferenceError","_defineProperty","obj","configurable","writable","ProfileView","subClass","superClass","Model","attribute","transformDate","hasOne","constructor","__proto__","app","initializers","add","store","models","userprofileview","User","profileViews","hasMany","extend","UserCard","items","user","this","props","count","length","icon","translator","trans","viewcount","UserPage","lastViewed","ItemList","views","slice","forEach","pv","viewer","id","href","forum","username","avatar","className","title","visitedAt","toLocaleString","humanTime","FieldSet","component","label","children","toArray","session","request","method","url","data","viewedUser"],"mappings":"2BACA,IAAAA,EAAA,GAGA,SAAAC,EAAAC,GAGA,GAAAF,EAAAE,GACA,OAAAF,EAAAE,GAAAC,QAGA,IAAAC,EAAAJ,EAAAE,GAAA,CACAG,EAAAH,EACAI,GAAA,EACAH,QAAA,IAUA,OANAI,EAAAL,GAAAM,KAAAJ,EAAAD,QAAAC,IAAAD,QAAAF,GAGAG,EAAAE,GAAA,EAGAF,EAAAD,QA0DA,OArDAF,EAAAQ,EAAAF,EAGAN,EAAAS,EAAAV,EAGAC,EAAAU,EAAA,SAAAR,EAAAS,EAAAC,GACAZ,EAAAa,EAAAX,EAAAS,IACAG,OAAAC,eAAAb,EAAAS,EAAA,CAA0CK,YAAA,EAAAC,IAAAL,KAK1CZ,EAAAkB,EAAA,SAAAhB,GACA,oBAAAiB,eAAAC,aACAN,OAAAC,eAAAb,EAAAiB,OAAAC,YAAA,CAAwDC,MAAA,WAExDP,OAAAC,eAAAb,EAAA,cAAiDmB,OAAA,KAQjDrB,EAAAsB,EAAA,SAAAD,EAAAE,GAEA,GADA,EAAAA,IAAAF,EAAArB,EAAAqB,IACA,EAAAE,EAAA,OAAAF,EACA,KAAAE,GAAA,iBAAAF,QAAAG,WAAA,OAAAH,EACA,IAAAI,EAAAX,OAAAY,OAAA,MAGA,GAFA1B,EAAAkB,EAAAO,GACAX,OAAAC,eAAAU,EAAA,WAAyCT,YAAA,EAAAK,UACzC,EAAAE,GAAA,iBAAA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KD,KAAKiB,MAE9E7B,IAAI6C,QAAQ,CACRC,OAAQ,OACRC,IAAK/C,IAAI+B,MAAMpC,UAAU,UAAY,eACrCqD,KAAM,CACFpB,OAAQ5B,IAAI4C,QAAQhC,KAAKiB,KACzBoB,WAAYpC,KAAKD,KAAKiB","file":"forum.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 11);\n","module.exports = flarum.core.compat['Model'];","module.exports = flarum.core.compat['extend'];","module.exports = flarum.core.compat['components/UserPage'];","module.exports = flarum.core.compat['models/User'];","module.exports = flarum.core.compat['components/UserCard'];","module.exports = flarum.core.compat['components/FieldSet'];","module.exports = flarum.core.compat['helpers/icon'];","module.exports = flarum.core.compat['helpers/avatar'];","module.exports = flarum.core.compat['helpers/username'];","module.exports = flarum.core.compat['utils/ItemList'];","module.exports = flarum.core.compat['utils/humanTime'];","export default function _assertThisInitialized(self) {\n if (self === void 0) {\n throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\");\n }\n\n return self;\n}","export default function _defineProperty(obj, key, value) {\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n\n return obj;\n}","import Model from 'flarum/Model';\r\n\r\nexport default class ProfileView extends Model {\r\n //comes from ProfileViewSerializer (viewer(), viewedUser(), visited_at)\r\n visitedAt = Model.attribute('visited_at', Model.transformDate);\r\n viewer = Model.hasOne('viewer');\r\n viewedUser = Model.hasOne('viewedUser');\r\n}","export default function _inheritsLoose(subClass, superClass) {\n subClass.prototype = Object.create(superClass.prototype);\n subClass.prototype.constructor = subClass;\n subClass.__proto__ = superClass;\n}","import User from 'flarum/models/User';\r\nimport UserPage from 'flarum/components/UserPage';\r\nimport UserCard from 'flarum/components/UserCard';\r\nimport FieldSet from 'flarum/components/FieldSet';\r\nimport icon from 'flarum/helpers/icon';\r\nimport avatar from 'flarum/helpers/avatar';\r\nimport username from 'flarum/helpers/username';\r\nimport Model from 'flarum/Model';\r\nimport ItemList from 'flarum/utils/ItemList';\r\nimport { extend } from 'flarum/extend';\r\nimport humanTime from 'flarum/utils/humanTime';\r\nimport ProfileView from '../ProfileView';\r\n\r\napp.initializers.add('michaelbelgium-flarum-profile-views', function() {\r\n app.store.models.userprofileview = ProfileView;//\".userprofileview\" = serializer type \"userprofileview\"\r\n User.prototype.profileViews = Model.hasMany('profileViews');//comes from AddUserProfileViewsRelationship::RELATIONSHIP = php model relationship method\r\n\r\n extend(UserCard.prototype, 'infoItems', function(items) {\r\n const user = this.props.user;\r\n\r\n const count = user.profileViews() === false ? 0 : user.profileViews().length;\r\n\r\n items.add('profile-views',(\r\n \r\n {icon('far fa-eye')}\r\n {' '}\r\n {app.translator.trans('flarum_profile_views.forum.user.views_count_text', {viewcount: '' + count})}\r\n \r\n ));\r\n });\r\n\r\n extend(UserPage.prototype, 'sidebarItems', function(items) {\r\n const lastViewed = new ItemList();\r\n\r\n var views = this.user.profileViews();\r\n\r\n if(views !== false)\r\n {\r\n if(views.length >= 5) {\r\n views = views.slice(0, 5);\r\n }\r\n \r\n views.forEach(pv => {\r\n lastViewed.add('lastUser-' + pv.viewer().id(),\r\n \r\n {avatar(pv.viewer(), {className: 'lastUser-avatar'})}\r\n
\r\n {username(pv.viewer())}\r\n {humanTime(pv.visitedAt())}\r\n
\r\n
\r\n );\r\n });\r\n }\r\n\r\n items.add('lastViewedUsers', FieldSet.component({\r\n label: app.translator.trans('flarum_profile_views.forum.user.title_last_viewers'),\r\n className: 'LastUsers',\r\n children: lastViewed.toArray()\r\n }));\r\n });\r\n\r\n extend(UserPage.prototype, 'show', function() {\r\n if(typeof app.session.user !== 'undefined' && app.session.user.id() !== this.user.id())\r\n {\r\n app.request({\r\n method: 'POST',\r\n url: app.forum.attribute('apiUrl') + '/profileview',\r\n data: { \r\n viewer: app.session.user.id(),\r\n viewedUser: this.user.id()\r\n }\r\n });\r\n }\r\n });\r\n});"],"sourceRoot":""} \ No newline at end of file diff --git a/js/src/forum/index.js b/js/src/forum/index.js index ab811a7..5950063 100644 --- a/js/src/forum/index.js +++ b/js/src/forum/index.js @@ -18,11 +18,13 @@ app.initializers.add('michaelbelgium-flarum-profile-views', function() { extend(UserCard.prototype, 'infoItems', function(items) { const user = this.props.user; + const count = user.profileViews() === false ? 0 : user.profileViews().length; + items.add('profile-views',( {icon('far fa-eye')} {' '} - {app.translator.trans('flarum_profile_views.forum.user.views_count_text', {viewcount: '' + user.profileViews().length})} + {app.translator.trans('flarum_profile_views.forum.user.views_count_text', {viewcount: '' + count})} )); });