Skip to content

Commit

Permalink
Merge pull request #125 from clpetersonucf/issue/1340-lti-preview-emb…
Browse files Browse the repository at this point in the history
…ed-ownership-options

Access Request option for LTI previews
  • Loading branch information
clpetersonucf authored Nov 10, 2021
2 parents 5053470 + 4daa62e commit 4c7d5b8
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/css/core.scss
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,12 @@ h3 {
}
}
}

button.action_button {
margin-top: 10px;
padding: 5px 8px;
font-size: 15px;
}
}

#notifications_link {
Expand Down
47 changes: 44 additions & 3 deletions src/css/partials/_lti_embed_preview.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
margin-bottom: 2em;
}

.button {
}

.widget_info {
display: flex;
align-items: center;
Expand All @@ -48,4 +45,48 @@
}
}
}

.container.not_an_owner {
width: 85%;

.widget_icon img {
width: 46px;
height: 46px;
margin: 5px;
}

h3 {
margin: 5px 0;
}

ul {
padding: 0;
text-align: left;
list-style-type: none;
}

.instance_owner {
position: relative;
padding: 15px;
margin-bottom: 2px;

background: #fcfcfc;
font-weight: bold;
}

.button {
position: absolute;
font-size: 15px;
padding: 4px 6px;
top: 10px;
right: 15px;
}

.button.disabled {
background: #a8a8a8;
color: #000;
border: solid 1px #6d6d6d;
cursor: default;
}
}
}
13 changes: 13 additions & 0 deletions src/css/partials/_widget_share_modal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,19 @@
padding: 15px 0 0 0;
}

.user_perm.highlight {
animation: pulse 1s alternate infinite;
}

@keyframes pulse {
0% {
background-color: none;
}
100% {
background-color: #ffffff;
}
}

.user_perm .options {
position: absolute;
right: 0;
Expand Down
21 changes: 20 additions & 1 deletion src/js/controllers/ctrl-my-widgets-collaboration.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ app.controller('MyWidgetsCollaborationController', function (
last: user.last,
gravatar: user.gravatar,
access: String(ACCESS.VISIBLE),
highlight: $scope.pending_collaborator ? true : false,
})

$timeout(() => {
Expand Down Expand Up @@ -224,7 +225,7 @@ app.controller('MyWidgetsCollaborationController', function (
]).then((returnData) => {
if (returnData === true) {
$scope.$emit('collaborators.update', '')
$scope.show.collaborationModal = false
$scope.hideModal()
if (remove_widget) {
WidgetSrv.removeWidget(widget_id)
}
Expand All @@ -241,6 +242,8 @@ app.controller('MyWidgetsCollaborationController', function (
}
}

if ($scope.pending_collaborator != undefined) $scope.pending_collaborator = null

Please.$apply()
})
}
Expand Down Expand Up @@ -283,4 +286,20 @@ app.controller('MyWidgetsCollaborationController', function (
// Initialize

$scope.$watch('inputs.userSearchInput', (input) => _searchFor(input))

// once initilization is complete - check to see if a pending collaborator exists
// if so, grab info about collaborator and add them to the list via manually calling _searchMatchClick
$timeout(() => {
if ($scope.pending_collaborator && $scope.pending_collaborator != null) {
Materia.Coms.Json.send('user_get', [[$scope.pending_collaborator]]).then((result) => {
if (result) {
result[0].gravatar = UserServ.getAvatar(result[0], 50)

$scope.searchResults.matches.push(result[0])

_searchMatchClick(result[0])
}
})
}
})
})
18 changes: 18 additions & 0 deletions src/js/controllers/ctrl-my-widgets-selected.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ app.controller('MyWidgetsSelectedController', function (
this.$parent.hideModal()
}

$scope.handleDialogClose = () => {
if ($scope.pending_collaborator != undefined) $scope.pending_collaborator = null
}

const _exportPopup = () => {
// Do not show modal disabled
$scope.show.exportModal = true
Expand Down Expand Up @@ -217,6 +221,20 @@ app.controller('MyWidgetsSelectedController', function (
Please.$apply()
})

// is widget done loading? check to see if there's a pending collaborator
$scope.$on('widget.loadingCompleted', () => {
if ($scope.pending_collaborator) _showCollaboration()
})

// notification has announced that we should add a collaborator, but we're already on the my widgets page
$scope.$on('notification.directAddPendingCollaborator', (event, broadcast) => {
$scope.pending_collaborator = broadcast.from_id

if (!$scope.selected.widget || $scope.selected.widget.id != broadcast.item_id)
$scope.setSelected(broadcast.item_id)
else _showCollaboration()
})

$scope.removeExpires = _removeExpires
$scope.setupPickers = _setupPickers
$scope.showCollaboration = _showCollaboration
Expand Down
12 changes: 12 additions & 0 deletions src/js/controllers/ctrl-my-widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ app.controller('MyWidgetsController', function (
$scope,
$q,
$window,
$location,
$timeout,
WidgetSrv,
UserServ,
Expand Down Expand Up @@ -52,6 +53,14 @@ app.controller('MyWidgetsController', function (
WidgetSrv.selectWidgetFromHashUrl()
firstRun = false
$window.addEventListener('hashchange', WidgetSrv.selectWidgetFromHashUrl, false)

if ($location.search()?.pending_collaborator) {
$scope.pending_collaborator = $location.search().pending_collaborator
var pattern = /\/([A-Za-z0-9]{5})/
var widgetId = $location.path().match(pattern) ? $location.path().match(pattern)[1] : null
if (widgetId) $scope.setSelected(widgetId)
$location.search('pending_collaborator', null).replace()
}
}
}

Expand Down Expand Up @@ -189,6 +198,9 @@ app.controller('MyWidgetsController', function (

populateAvailability(sel.widget.open_at, sel.widget.close_at)
populateAttempts(sel.widget.attempts)

// announce that widget is done loading, in case a hook requires it
$rootScope.$broadcast('widget.loadingCompleted')
}

// count up the number of other users collaborating
Expand Down
37 changes: 35 additions & 2 deletions src/js/controllers/ctrl-user-notification.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const app = angular.module('materia')
app.controller('UserNotificationCtrl', function (Please, $scope, $sce) {
app.controller('UserNotificationCtrl', function (Please, $scope, $sce, $rootScope) {
let $notices = document.querySelector('#notices')
const _toggleOpen = () => {
$scope.isOpen = !$scope.isOpen
Expand All @@ -26,7 +26,40 @@ app.controller('UserNotificationCtrl', function (Please, $scope, $sce) {
$scope.toggleOpen = _toggleOpen

Materia.Coms.Json.send('notifications_get').then((notifications) => {
$scope.notifications = notifications
if (!notifications && !notifications.length) return
$scope.notifications = notifications.map((notification) => {
// does a notification include an action? Perform some additional setup based on the action performed. This is intended to be extensible.
if (notification.action) {
// someone is requesting access to the widget, enable the "add a collaborator" button and callback behavior
switch (notification.action) {
case 'access_request':
notification.button_action_text = 'Add as Collaborator'
notification.button_action_callback = () => {
var url = new URL(window.location.href)
var pattern = /^(\/my-widgets)/
// already on the my-widgets page; don't need to redirect, just send a broadcast with relevant info
if (url.pathname.match(pattern) && url.pathname.match(pattern).length) {
$rootScope.$broadcast('notification.directAddPendingCollaborator', {
from_id: notification.from_id,
item_id: notification.item_id,
})
}
// not on my-widgets page; update url with widget hash and collaborator id, then redirect
else {
url.pathname = '/my-widgets'
url.hash = `/${notification.item_id}?pending_collaborator=${notification.from_id}`
location.assign(url)
}
}
break

default:
break
}
}
return notification
})

Please.$apply()
})
})

0 comments on commit 4c7d5b8

Please sign in to comment.