diff --git a/CHANGELOG.md b/CHANGELOG.md index 04c6461..9052e70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Strava Sync Changelog +## 1.0.6 - 2019-05-31 +### Added +- Table attribute to the users table view to see if user is connected/disconnected from Strava +- Pane inside a user to see if user is connected/disconnected from Strava and output Athlete ID + ## 1.0.5 - 2019-04-26 ### Fixed - Fixed issue where new Strava users produced an error when trying to save profile photos (Because they didn't exist) diff --git a/README.md b/README.md index f389042..426a40e 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,9 @@ https://plugins.craftcms.com/strava-sync - Automatically fills profile data (First Name, Last Name, Profile Photo etc) - Map additional athlete data to user fields (City, Country, Sex etc) - Get data from the Strava API (Athletes, activities, segments etc) -- Sync data directly in to Craft CMS via Webhooks [Soon] +- Sync data directly in to Craft CMS via Webhooks +- Pane inside a user to show athlete data and if connected/disconnected to Strava +- Table attribute column on 'Users' table, to show if user is connected/disconnected to Strava ## Requirements @@ -173,6 +175,10 @@ Depending on your scope type when you authorised the account, the supported requ - getStreamsSegment - getStreamsRoute +## Webhooks + +@TODO Documentation on this feature. Open issue if any questions. + ## Support If you have any issues (Surely not!) then I'll aim to reply to these as soon as possible. If it's a site-breaking-oh-no-what-has-happened moment, then hit me up on the Craft CMS Slack / Discord - @bymayo diff --git a/composer.json b/composer.json index 584fe8d..de3cbc0 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "bymayo/strava-sync", "description": "Connect to Strava with oAuth and sync activities etc to Craft CMS ", "type": "craft-plugin", - "version": "1.0.5", + "version": "1.0.6", "keywords": [ "craft", "cms", diff --git a/src/StravaSync.php b/src/StravaSync.php index d9de912..db7e901 100755 --- a/src/StravaSync.php +++ b/src/StravaSync.php @@ -4,6 +4,7 @@ use bymayo\stravasync\variables\StravaSyncVariable; use bymayo\stravasync\models\Settings; +use bymayo\stravasync\assetbundles\stravasync\StravaSyncAsset; use Craft; use craft\base\Plugin; @@ -12,6 +13,8 @@ use craft\web\UrlManager; use craft\web\twig\variables\CraftVariable; use craft\events\RegisterUrlRulesEvent; +use craft\events\RegisterElementTableAttributesEvent; +use craft\events\SetElementTableAttributeHtmlEvent; use craft\helpers\FileHelper; use craft\services\Elements; use craft\elements\User as UserElement; @@ -111,6 +114,43 @@ function (Event $event) { ), __METHOD__ ); + + Event::on( + UserElement::class, + UserElement::EVENT_REGISTER_TABLE_ATTRIBUTES, + function(RegisterElementTableAttributesEvent $event) { + $event->tableAttributes['stravaSync'] = 'Strava'; + } + ); + + Event::on( + UserElement::class, + UserElement::EVENT_SET_TABLE_ATTRIBUTE_HTML, + function(SetElementTableAttributeHtmlEvent $event) { + if ($event->attribute === 'stravaSync') { + Craft::$app->getView()->registerAssetBundle(StravaSyncAsset::class); + $user = $event->sender; + $userConnected = StravaSync::getInstance()->userService->checkUserLinkExists($user->id); + $event->html = Craft::$app->getView()->renderTemplate( + 'strava-sync/table-attribute', + [ + 'status' => $userConnected, + ] + ); + } + } + ); + + Craft::$app->getView()->hook( + 'cp.users.edit.details', + function(&$context) { + if ($context['user'] && $context['user']->id) { + Craft::$app->getView()->registerAssetBundle(StravaSyncAsset::class); + return Craft::$app->getView()->renderTemplate('strava-sync/user-pane', $context); + } + } + ); + } // Protected Methods diff --git a/src/assetbundles/stravasync/dist/css/StravaSync.css b/src/assetbundles/stravasync/dist/css/StravaSync.css index 0b811f8..8de3f9d 100755 --- a/src/assetbundles/stravasync/dist/css/StravaSync.css +++ b/src/assetbundles/stravasync/dist/css/StravaSync.css @@ -1,11 +1,27 @@ -/** - * Strava Sync plugin for Craft CMS - * - * Strava Sync CSS - * - * @author bymayo - * @copyright Copyright (c) 2019 bymayo - * @link http://bymayo.co.uk - * @package StravaSync - * @since 1.0.0 - */ +.rounded { + border-radius: .25rem; +} + +.font-medium { + font-weight: 500; +} + +.text-sm { + font-size: .75rem; +} + +.p-2 { + padding: 0.3rem 0.5rem; +} + +.text-white { + color: #fff; +} + +.bg-strava { + background-color: #fc4c02; +} + +.bg-gray-300 { + background-color: #e2e8f0; +} diff --git a/src/assetbundles/stravasync/dist/img/StravaSync-icon.svg b/src/assetbundles/stravasync/dist/img/StravaSync-icon.svg deleted file mode 100755 index c8afbcd..0000000 --- a/src/assetbundles/stravasync/dist/img/StravaSync-icon.svg +++ /dev/null @@ -1,52 +0,0 @@ - - - - diff --git a/src/assetbundles/stravasync/dist/js/StravaSync.js b/src/assetbundles/stravasync/dist/js/StravaSync.js index 19e7001..e69de29 100755 --- a/src/assetbundles/stravasync/dist/js/StravaSync.js +++ b/src/assetbundles/stravasync/dist/js/StravaSync.js @@ -1,11 +0,0 @@ -/** - * Strava Sync plugin for Craft CMS - * - * Strava Sync JS - * - * @author bymayo - * @copyright Copyright (c) 2019 bymayo - * @link http://bymayo.co.uk - * @package StravaSync - * @since 1.0.0 - */ diff --git a/src/services/UserService.php b/src/services/UserService.php index f150462..faa5e0c 100755 --- a/src/services/UserService.php +++ b/src/services/UserService.php @@ -23,11 +23,16 @@ class UserService extends Component // Public Methods // ========================================================================= - public function checkUserLinkExists() + public function checkUserLinkExists($userId) { - $user = Craft::$app->getUser()->getIdentity(); - $userRecord = UsersRecord::findOne(['userId' => $user->id]); + if (!$userId) + { + $user = Craft::$app->getUser()->getIdentity(); + $userId = $user->id; + } + + $userRecord = UsersRecord::findOne(['userId' => $userId]); if ($userRecord) { return $userRecord; diff --git a/src/templates/table-attribute.twig b/src/templates/table-attribute.twig new file mode 100644 index 0000000..553a37e --- /dev/null +++ b/src/templates/table-attribute.twig @@ -0,0 +1,5 @@ +{% if status %} + Connected +{% else %} + Disconnected +{% endif %} diff --git a/src/templates/user-pane.twig b/src/templates/user-pane.twig new file mode 100644 index 0000000..2552a27 --- /dev/null +++ b/src/templates/user-pane.twig @@ -0,0 +1,39 @@ +{% if user.id == currentUser.id or currentUser.admin %} + +
+ +{% endif %} diff --git a/src/variables/StravaSyncVariable.php b/src/variables/StravaSyncVariable.php index 375a796..ffb9dce 100755 --- a/src/variables/StravaSyncVariable.php +++ b/src/variables/StravaSyncVariable.php @@ -18,9 +18,9 @@ public function request($method, $params = null, $userId = null) return $connect = StravaSync::getInstance()->oauthService->request($method, $params, $userId); } - public function connected() + public function connected($userId) { - return StravaSync::getInstance()->userService->checkUserLinkExists(); + return StravaSync::getInstance()->userService->checkUserLinkExists($userId); } public function connectUrl()