(function () { 'use strict'; var serviceId = 'datacontext'; angular.module('app').factory(serviceId, ['common', '$http', 'config', 'DSCacheFactory', datacontext]); function datacontext(common, $http, config, DSCacheFactory) { var $q = common.$q; var service = { getEmails: getEmails, clearAllCachedData: clearAllCachedData, getNotifications: getNotifications, linkOrganisationInviteWithUser: linkOrganisationInviteWithUser, markNotificationAsSeen: markNotificationAsSeen, deleteNotificationByInviteId: deleteNotificationByInviteId, rejectNotification: rejectNotification, sendNotification: sendNotification, changePassword: changePassword, forgotPassword: forgotPassword, isUsernameAvailable: isUsernameAvailable, getCompetencySummary: getCompetencySummary, getUserItemSummary: getUserItemSummary, getUserSummary: getUserSummary, getUsers: getUsers, getShowcaseReviewersForUserByStatus: getShowcaseReviewersForUserByStatus, changeShowcaseReviewerstatus: changeShowcaseReviewerstatus, archiveShowcaseReviewers: archiveShowcaseReviewers, getTotalGraphicsForOrg: getTotalGraphicsForOrg, getTotalBadgesForOrg: getTotalBadgesForOrg, getTotalIssuedForOrg: getTotalIssuedForOrg, getTemplatesByOrgs: getTemplatesByOrgs, getGraphicsByOrg: getGraphicsByOrg, getIssuedByTemplate: getIssuedByTemplate, getTotalBadgesForDateRange: getTotalBadgesForDateRange, getTotalBadgesForTemplateInDateRange: getTotalBadgesForTemplateInDateRange, getTotalGraphicsInDateRange: getTotalGraphicsInDateRange, getTotalBadgeTemplatesInDateRange: getTotalBadgeTemplatesInDateRange, getTotalRecipientsForDateRange: getTotalRecipientsForDateRange, getTotalRecipientsForDateRangeByOrg: getTotalRecipientsForDateRangeByOrg, deleteInvite: deleteInvite, getMyProgressIntegrations: getMyProgressIntegrations, getCanvasIntegrations: getCanvasIntegrations, createMyProgressIntegration: createMyProgressIntegration, deleteMyProgressIntegration: deleteMyProgressIntegration, updateMyProgressIntegration: updateMyProgressIntegration, createCanvasIntegration: createCanvasIntegration, deleteCanvasIntegration: deleteCanvasIntegration, updateCanvasIntegration: updateCanvasIntegration, getTotalBadgesForClaimInDateRange: getTotalBadgesForClaimInDateRange, setRoles: setRoles, setRolesIndividual: setRolesIndividual, getOrgUsers: getOrgUsers, createDefaultCustomRoles: createDefaultCustomRoles, configureCanvasForUser: configureCanvasForUser, getCompetencySummaryForUser: getCompetencySummaryForUser, getIndividualFramework: getIndividualFramework, getDeployedFrameworkAssignment: getDeployedFrameworkAssignment, getIntegrations: getIntegrations, getAllIntegrations: getAllIntegrations, createIntegration: createIntegration, updateIntegration: updateIntegration, deleteIntegration: deleteIntegration, getAuthenticationToken: getAuthenticationToken, getCalendars: getCalendars, getCalendarByOrgId: getCalendarByOrgId, getOrgsUsers: getOrgsUsers, isEmailAvailable: isEmailAvailable, getUserIndividualFramework: getUserIndividualFramework, getUserDetails: getUserDetails, getAllocatedFrameworkOrg: getAllocatedFrameworkOrg, deleteIntegrationById: deleteIntegrationById, getTotalClicksForBadge: getTotalClicksForBadge }; return service; function clearAllCachedData() { DSCacheFactory.destroyAll(); } function linkOrganisationInviteWithUser(organisationInviteId) { var request = $http({ method: "get", url: config.notificationsRemoteServiceUrl + 'organisationinvitelink/' + organisationInviteId }); return (request.then(function (response) { return; }, handleError)); } //get users by their unique ids function getUsers(userIds) { var request = $http({ method: "post", url: config.usersRemoteServiceUrl + 'details', data: { userIds: userIds } }); return (request.then(function (response) { return response.data; }, handleError)); } function getCompetencySummary(userIds) { var request = $http({ method: "post", url: config.competencyRemoteServiceUrl + 'summary', data: userIds }); return (request.then(handleSuccess, handleError)); } //get a summary of the competencies and numbers of associated tags for current user function getCompetencySummaryForUser(requestModel) { var request = $http({ method: "post", url: config.userRemoteServiceUrl + 'itemsummary', data: requestModel }); return (request.then(handleSuccess, handleError)); } function getUserItemSummary(query) { var request = $http({ method: "post", url: config.usersRemoteServiceUrl + 'itemsummary', data: query }); return (request.then(handleSuccess, handleError)); } function getUserSummary(userIds) { var request = $http({ method: "post", url: config.usersRemoteServiceUrl + 'usersummary', data: userIds }); return (request.then(handleSuccess, handleError)); } function handleError(response) { // The API response from the server should be returned in a // nomralized format. However, if the request was not handled by the // server (or what not handles properly - ex. server error), then we // may have to normalize it on our end, as best we can. if ( !angular.isObject(response.data) || !response.data.message ) { return ($q.reject("An unknown error occurred.")); } // Otherwise, use expected error message. return ($q.reject(response.data.message)); } // I transform the successful response, unwrapping the application data // from the API response payload. function handleSuccess(response) { return (response.data); } function getEmails(query) { var request = $http({ method: "get", url: config.userRemoteServiceUrl + 'myemails/' + query }); return (request.then(handleSuccess, handleError)); } function getNotifications() { var request = $http({ method: "get", url: apigatewayUrl + 'notifications/api/notifications/appcode/' + config.appCode }); return (request.then(function (response) { return response.data; }, handleError)); } function markNotificationAsSeen(notificationId) { var request = $http({ method: "put", url: apigatewayUrl + 'notifications/api/notifications/' + notificationId }); return (request.then(handleSuccess, handleError)); } //delete a notification by invite id function deleteNotificationByInviteId(inviteId) { var request = $http({ method: "delete", url: config.notificationsRemoteServiceUrl + "invite/" + inviteId }); return (request.then(handleSuccess, handleError)); } function rejectNotification(notificationId) { var request = $http({ method: "delete", url: config.notificationsRemoteServiceUrl + notificationId + '/reject' }); return (request.then(handleSuccess, handleError)); } function deleteInvite(inviteId, orgId) { var request = $http({ method: "delete", url: config.myusersUrl + "api/organisationadministration/" + orgId + "/invites/" + inviteId }); return (request.then(handleSuccess, handleError)); } function getOrgsUsers(orgIds) { var request = $http({ method: "post", url: config.myusersUrl + "api/organisationadministration/organisation/users", data: orgIds }); return (request.then(function (response) { return response.data; }, handleError)); } function sendNotification(data) { var request = $http({ method: "post", url: config.notificationsRemoteServiceUrl + '/send', data: data }); return (request.then(handleSuccess, handleError)); } function changePassword(model) { var request = $http({ method: "post", url: config.myusersUrl + 'api/account/changepassword', data: model }); return (request.then(handleSuccess, handleError)); } function forgotPassword(model) { var request = $http({ method: "post", url: config.myusersUrl + 'api/account/forgottenpassword', data: model }); return (request.then(handleSuccess, handleError)); } function isUsernameAvailable(username) { var request = $http({ method: "get", url: config.myusersUrl + 'api/Account/usernameavailable?username=' + username }); return (request.then(handleSuccess, handleError)); } function isEmailAvailable(email) { var request = $http({ method: "get", url: config.userProfileServiceUrl + 'emailavailable?email=' + email }); return (request.then(handleSuccess, handleError)); } function getShowcaseReviewersForUserByStatus(userId, statuses) { var request = $http({ method: "post", url: 'api/showcasereviews/userstatus', data: { userId: userId, statuses: statuses } }); return (request.then(handleSuccess, handleError)); } function changeShowcaseReviewerstatus(showcaseReviews) { var request = $http({ method: "post", url: 'api/showcasereviews/status', data: showcaseReviews }); return (request.then(handleSuccess, handleError)); } function archiveShowcaseReviewers(showcaseReviews) { var request = $http({ method: "post", url: 'api/showcasereviews/archive', data: showcaseReviews }); return (request.then(handleSuccess, handleError)); } // Badge reporting services function getTotalGraphicsForOrg(orgIds) { var request = $http({ method: "post", url: config.mybadgesUrl + 'mybadgereports/graphics/total', data: orgIds }); return (request.then(handleSuccess, handleError)); } function getTotalBadgesForOrg(orgIds) { var request = $http({ method: "post", url: config.mybadgesUrl + 'mybadgereports/templates/total', data: orgIds }); return (request.then(handleSuccess, handleError)); } function getTotalIssuedForOrg(orgIds) { var request = $http({ method: "post", url: config.mybadgesUrl + 'mybadgereports/issued/total', data: orgIds }); return (request.then(handleSuccess, handleError)); } // Get badge templates for a list of org ids function getTemplatesByOrgs(orgIds) { var request = $http({ method: "post", url: config.mybadgesUrl + 'organisation/badgetemplates', data: orgIds }); return (request.then(handleSuccess, handleError)); } // Get the graphics that are associated with the users organisation ID function getGraphicsByOrg(orgIds) { var request = $http({ method: "post", url: config.mybadgesUrl + 'organisation/graphics', data: orgIds }); return (request.then(handleSuccess, handleError)); } // Get the issued badges by badge template id function getIssuedByTemplate(templateId, status) { var request = $http({ method: "get", url: config.mybadgesUrl + 'badgetemplates/' + templateId + '/issuedbadges/' + status }); return (request.then(handleSuccess, handleError)); } // Get total number of badges issued by an issuer in a given date range and grouping function getTotalBadgesForDateRange(dateModel) { var request = $http({ method: "post", url: config.mybadgesUrl + 'mybadgereports/issuer/issued/datesummary' + '?cache=' + Date.now(), data: dateModel }); return (request.then(handleSuccess, handleError)); } // Get total number of badges issued for a badge template in a given date range and grouping function getTotalBadgesForTemplateInDateRange(dateModel) { var request = $http({ method: "post", url: config.mybadgesUrl + 'mybadgereports/badgetemplates/issued/datesummary' + '?cache=' + Date.now(), data: dateModel }); return (request.then(handleSuccess, handleError)); } function getTotalBadgesForClaimInDateRange(dateModel) { var request = $http({ method: "post", url: config.mybadgesUrl + 'mybadgereports/claims/issued/datesummary' + '?cache=' + Date.now(), data: dateModel }); return (request.then(handleSuccess, handleError)); } // Get total number of badges issued for a badge template in a given date range and grouping function getTotalGraphicsInDateRange(dateModel) { var request = $http({ method: "post", url: config.mybadgesUrl + 'mybadgereports/issuer/badgegraphics/datesummary' + '?cache=' + Date.now(), data: dateModel }); return (request.then(handleSuccess, handleError)); } // Get total number of badges issued for a badge template in a given date range and grouping function getTotalBadgeTemplatesInDateRange(dateModel) { var request = $http({ method: "post", url: config.mybadgesUrl + 'mybadgereports/issuer/badgetemplates/datesummary' + '?cache=' + Date.now(), data: dateModel }); return (request.then(handleSuccess, handleError)); } // Get total number of badges issued for a badge template in a given date range and grouping function getTotalRecipientsForDateRange(dateModel) { var request = $http({ method: "get", url: config.mybadgesUrl + 'mybadgereports/recipients/' + dateModel.startDate + '/' + dateModel.endDate + '?cache=' + Date.now() }); return (request.then(handleSuccess, handleError)); } function getTotalRecipientsForDateRangeByOrg(dateModel) { var request = $http({ method: "get", url: config.mybadgesUrl + 'mybadgereports/recipientsbyorg/' + dateModel.startDate + '/' + dateModel.endDate + '?cache=' + Date.now() }); return (request.then(handleSuccess, handleError)); } function getMyProgressIntegrations(orgId) { var request = $http({ method: "get", url: config.myShowcaseSiteUrl + 'api/organisationconnections/organisation/' + orgId }); return (request.then(handleSuccess, handleError)); } function getCanvasIntegrations(orgId) { var request = $http({ method: "get", url: config.myusersUrl + 'api/lti/organisationconnections/' + orgId }); return (request.then(handleSuccess, handleError)); } function createMyProgressIntegration(integration) { var request = $http({ method: "post", url: config.myShowcaseSiteUrl + 'api/organisationconnections/organisation/', data: integration }); return (request.then(handleSuccess, handleError)); } function createCanvasIntegration(integration) { var request = $http({ method: "post", url: config.myusersUrl + 'api/lti/organisationconnections/', data: integration }); return (request.then(handleSuccess, handleError)); } function updateMyProgressIntegration(integration) { var request = $http({ method: "put", url: config.myShowcaseSiteUrl + 'api/organisationconnections/organisation/', data: integration }); return (request.then(handleSuccess, handleError)); } function updateCanvasIntegration(integration) { var request = $http({ method: "put", url: config.myusersUrl + 'api/lti/organisationconnections/', data: integration }); return (request.then(handleSuccess, handleError)); } function deleteMyProgressIntegration(integration) { var request = $http({ method: "delete", url: config.myShowcaseSiteUrl + 'api/organisationconnections/organisation/' + integration.id, }); return (request.then(handleSuccess, handleError)); } function deleteCanvasIntegration(integration) { var request = $http({ method: "delete", url: config.myusersUrl + 'api/lti/organisationconnections/' + integration.id, }); return (request.then(handleSuccess, handleError)); } function setRolesIndividual(userId, roles) { var request = $http({ method: "post", url: config.myusersUrl + 'api/account/roles/admin', data: { userIds: [userId], roles: ["myshowcase", "mybadges"], orgAdmin: false } }); return (request.then(handleSuccess, handleError)); } function setRoles(userId, roles) { var request = $http({ method: "post", url: config.myusersUrl + 'api/account/roles/admin', data: { userIds: [userId], roles: ["myshowcase", "mybadges"], orgAdmin: true } }); return (request.then(handleSuccess, handleError)); } // Get total number of badges issued for a badge template in a given date range and grouping function getOrgUsers(orgId) { var request = $http({ method: "get", url: config.myusersUrl + 'api/organisationadministration/' + orgId + '/groupsandusers' }); return (request.then(handleSuccess, handleError)); } /* * Create the system default roles and optionally set the given user as a 'SystemAdmin' and 'User' */ function createDefaultCustomRoles(orgId, systemAdminId) { var request = $http({ method: "get", url: config.myusersUrl + 'api/organisationadministration/' + orgId + '/groupsandusers' }); return (request.then(handleSuccess, handleError)); } // Get total number of badges issued for a badge template in a given date range and grouping function configureCanvasForUser(code, connectionId) { var request = $http({ method: "post", url: config.myusersUrl + 'api/lti/userconnections/token', data: { connectionId: connectionId, redirectUri: config.myShowcaseAdminSiteUrl + '%2F%23!%2Fcanvas', code: code, oAuthEndPoint: "login/oauth2/token" } }); return (request.then(handleSuccess, handleError)); } // get individual framework function getIndividualFramework(frameworkId, groupAllocated, selfAllocated) { var request = $http({ method: "get", url: config.myShowcaseSiteUrl + 'api/individualframeworks/' + frameworkId + "?groupallocated=" + groupAllocated + "&selfallocated=" + selfAllocated }); return (request.then(handleSuccess, handleError)); }; function getDeployedFrameworkAssignment(deployedAssignmentId) { var request = $http({ method: "get", url: config.apigatewayUrl + 'deployedassignment/forme/' + deployedAssignmentId }); return (request.then(handleSuccess, handleError)); } function getAllIntegrations(orgId) { var request = $http({ method: "get", url: config.myusersUrl + 'api/lti/organisationconnections/' + orgId, }); return (request.then(handleSuccess, handleError)); } function getIntegrations(orgId, connectiontype) { var request = $http({ method: "get", url: config.myusersUrl + 'api/lti/organisationconnections/' + orgId + '/' + connectiontype, }); return (request.then(handleSuccess, handleError)); } function createIntegration(integration) { var request = $http({ method: "post", url: config.myusersUrl + 'api/lti/organisationconnections/', data: integration }); return (request.then(handleSuccess, handleError)); } function updateIntegration(integration) { var request = $http({ method: "put", url: config.myusersUrl + 'api/lti/organisationconnections/', data: integration }); return (request.then(handleSuccess, handleError)); } function deleteIntegration(integration) { var request = $http({ method: "delete", url: config.myusersUrl + 'api/lti/organisationconnections/' + integration.id, data: integration }); return (request.then(handleSuccess, handleError)); } function deleteIntegrationById(integrationid) { var request = $http({ method: "delete", url: config.myusersUrl + 'api/lti/organisationconnections/' + integrationid, data: integrationid }); return (request.then(handleSuccess, handleError)); } function getAuthenticationToken(developerKey, organisationId) { var request = $http({ method: "get", url: config.myusersUrl + 'api/Account/AuthKey/' + developerKey + '/' + organisationId }); return (request.then(handleSuccess, handleError)); } function getCalendars() { var request = $http({ method: "get", url: config.calendarUrl + "api/calendarsmanager" }); return (request.then(handleSuccess, handleError)); } function getCalendarByOrgId(orgId) { var request = $http({ method: "get", url: config.calendarUrl + "api/calendarsmanager/org/" + orgId }); return (request.then(handleSuccess, handleError)); } function getUserIndividualFramework(frameworkId, userId) { var request = $http({ method: "get", url: config.myShowcaseSiteUrl + 'api/myshowcaseframeworks/' + frameworkId + '/individualframeworks/' + userId }); return (request.then(handleSuccess, handleError)); } function getUserDetails(userId) { var request = $http({ method: "post", url: config.myShowcaseSiteUrl + 'api/users/details', data: { UserIds: [userId] } }); return (request.then(handleSuccess, handleError)); } function getAllocatedFrameworkOrg(frameworkId, userId) { var request = $http({ method: "get", url: config.myusersUrl + 'api/frameworks/' + frameworkId + '/allocated/organisations/user/' + userId }); return (request.then(handleSuccess, handleError)); } function getTotalClicksForBadge(badgeId) { var request = $http({ method: "get", url: config.mybadgesUrl + 'reports/socialtrackings/badges/' + badgeId }); return (request.then(handleSuccess, handleError)); } } })();