(function () { 'use strict'; //datacontext service provides functionality to interact with remote RESTful endpoints / local cache var serviceId = 'datacontext'; angular.module('app').factory(serviceId, ['common', '$http', 'config', 'DSCacheFactory', datacontext]); function datacontext(common, $http, config, DSCacheFactory) { //cache names var myStuffCache = 'myStuffCache'; var itemsCache = 'itemsCache'; var allShowcasesCache = 'allShowcasesCache'; var feedsCache = 'feedsCache'; var currentShowcaseCache = 'currentShowcaseCache'; var tagSummaryCache = 'tagSummaryCache'; var showcaseSummaryCache = 'showcaseSummaryCache'; var showcasesCache = 'showcasesCache'; var showcaseItemsCache = 'showcaseItemsCache'; var themesCache = 'themesCache'; var allItemsCacheName = 'allitems'; var allShowcasesCacheName = 'allshowcases'; var allFeedsCacheName = 'allfeeds'; var allThemesCacheName = 'allthemes'; var tagSummaryCacheName = 'tagsummary'; var showcaseSummaryCacheName = 'showcasesummary'; var currentShowcaseCacheName = 'currentshowcase'; var showcases; var $q = common.$q; //create the local caches we need createAllShowcasesCache(); createMyItemsCache(); createItemsCache(); createShowcasesCache(); createShowcaseItemsCache(); createThemesCache(); createMyItemsCache createTagSummaryCache(); createShowcaseSummaryCache(); createCurrentShowcaseCache(); createFeedsCache(); //define the functions available on this service var service = { getShowcases: getShowcases, getShowcase: getShowcase, publishShowcase: publishShowcase, createStatusItem: createStatusItem, getMyItems: getMyItems, getItemDetailBySource: getItemDetailBySource, setMyItems:setMyItems, getMyItemsExtra:getMyItemsExtra, getItem: getItem, editStatusItem: editStatusItem, editWeblinkItem: editWeblinkItem, createWeblinkItem: createWeblinkItem, showcaseItem: showcaseItem, showcaseAddInItem:showcaseAddInItem, getShowcasesAvailableForItem: getShowcasesAvailableForItem, getShowcasesLinkedToItem:getShowcasesLinkedToItem, recycleBinItem: recycleBinItem, createShowcase: createShowcase, getItemsForShowcase: getItemsForShowcase, manageShowcase: manageShowcase, createImageItem: createImageItem, createVideoItem: createVideoItem, editImageItem: editImageItem, editVideoItem: editVideoItem, editBadgeItem:editBadgeItem, getTags: getTags, getTagSummary: getTagSummary, getShowcaseSummary: getShowcaseSummary, createFileItem: createFileItem, editFileItem: editFileItem, editAssessmentItem: editAssessmentItem, editEvernoteItem:editEvernoteItem, deleteShowcase: deleteShowcase, setShowcaseArchived: setShowcaseArchived, sendShowcase: sendShowcase, cloneShowcase: cloneShowcase, getEmails: getEmails, getReviewerNames:getReviewerNames, createEmbedItem: createEmbedItem, editEmbedItem: editEmbedItem, getThemes: getThemes, removeItemFromShowcaseByShowcaseItemId: removeItemFromShowcaseByShowcaseItemId, removeItemFromShowcaseByShowcaseIdAndItemId: removeItemFromShowcaseByShowcaseIdAndItemId, clearAllCachedData: clearAllCachedData, setShowcaseSummary: setShowcaseSummary, getCurrentShowcase: getCurrentShowcase, setCurrentShowcase: setCurrentShowcase, checkShouldResetCachesWithItems: checkShouldResetCachesWithItems, clearCachesForItemAdded: clearCachesForItemAdded, clearCachesForItemUpdated: clearCachesForItemUpdated, getFeeds: getFeeds, createFeed: createFeed, deleteFeed: deleteFeed, editFeed: editFeed, getNotifications: getNotifications, linkOrganisationInviteWithUser: linkOrganisationInviteWithUser, deleteNotification: deleteNotification, deleteNotificationByInviteId: deleteNotificationByInviteId, rejectNotification: rejectNotification, sendNotification: sendNotification, getCompetencySummaryForMe: getCompetencySummaryForMe, changePassword: changePassword, forgotPassword: forgotPassword, isUsernameAvailable: isUsernameAvailable, manageShowcaseItems: manageShowcaseItems, commitTemporaryShowcases:commitTemporaryShowcases, deleteTemporaryShowcases: deleteTemporaryShowcases, sendShowcaseReviewMessage: sendShowcaseReviewMessage, toggleShowcasePublicPrivate: toggleShowcasePublicPrivate, editFormItem: editFormItem, createFormItem: createFormItem, getShowcaseVersions: getShowcaseVersions, getSpecificShowcaseVersion: getSpecificShowcaseVersion, toggleShowcasePublicPrivateVersion: toggleShowcasePublicPrivateVersion, isValidOpenbadge: isValidOpenbadge, parseOpenbadge: parseOpenbadge, deleteInvite: deleteInvite, sendVerificationEmail: sendVerificationEmail, saveBadgeUser: saveBadgeUser, updateEmails: updateEmails, saveBadgeUserTheme: saveBadgeUserTheme, resendVerification: resendVerification, getBadgeAccount: getBadgeAccount, getAllBadgesForUser: getAllBadgesForUser, getBadgesCountForUser: getBadgesCountForUser, createBadgeItem: createBadgeItem, updateBadgeItem: updateBadgeItem, deleteBadgeItem: deleteBadgeItem, getCollectionsForUser: getCollectionsForUser, createCollection: createCollection, updateCollection: updateCollection, deleteCollection: deleteCollection, resendAlternativeEmailVerification: resendAlternativeEmailVerification, getBadgesForEmail: getBadgesForEmail, setToRetrieved: setToRetrieved, createBadgeAccount: createBadgeAccount, makeEmailPrimary: makeEmailPrimary, addItemsToCollection: addItemsToCollection, removeItemsFromCollection: removeItemsFromCollection, getCollectionById: getCollectionById, publishCollectionContent: publishCollectionContent, createBackpackItem: createBackpackItem, editBadgeCollectionItem: editBadgeCollectionItem, createBadgeCollectionItem: createBadgeCollectionItem, createConversation: createConversation, getConversations: getConversations, getUserDetails: getUserDetails, markConversationAsReadForMessageRecipient: markConversationAsReadForMessageRecipient, replyToConversation: replyToConversation, addTagsToConversation: addTagsToConversation, showcaseItems: showcaseItems, getShowcaseByFrameworkId: getShowcaseByFrameworkId, getIndividualFramework: getIndividualFramework, getDeployedFrameworkAssignment: getDeployedFrameworkAssignment, getDeployedFrameworkAssignmentForMeWithEvidenceSummary: getDeployedFrameworkAssignmentForMeWithEvidenceSummary, getUserSummary: getUserSummary, publishIndividualFramework: publishIndividualFramework, setFrameworkStatus: setFrameworkStatus, setFrameworkChanged: setFrameworkChanged, getFrameworkChanged: getFrameworkChanged, getAllIndividualFramework: getAllIndividualFramework, getUsers: getUsers, createReflectionItem: createReflectionItem, editReflectionItem: editReflectionItem, generateLtiPairing: generateLtiPairing, validateConnection: validateConnection, linkExistingAccount: linkExistingAccount, createAccountIfNotExist: createAccountIfNotExist, signInWithAuthData: signInWithAuthData, mergeAccounts: mergeAccounts, getCanvasConnections: getCanvasConnections, disconnectCanvasConnection: disconnectCanvasConnection, getCalendars: getCalendars, getCalendarByOrgId: getCalendarByOrgId, createCalendar: createCalendar, createCalendarEvent: createCalendarEvent, updateCalendarEvent: updateCalendarEvent, deleteCalendarEvent: deleteCalendarEvent, getOrgUsers: getOrgUsers, isEmailAvailable: isEmailAvailable, getShowcasesForAssignments: getShowcasesForAssignments, getCanvasIntegrationByDomain: getCanvasIntegrationByDomain, getCanvasIntegrationByConnection: getCanvasIntegrationByConnection, configureCanvasForUser: configureCanvasForUser, createEvidence: createEvidence, deleteEvidence: deleteEvidence }; return service; //implement the functions for the service //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 the currently active showcase for the user by storing it in a local cache (its then present if the user refreshes the page etc) function getCurrentShowcase() { var cache = DSCacheFactory.get(currentShowcaseCache); if (cache) { var cacheShowcase = cache.get(currentShowcaseCacheName); if (cacheShowcase) return cacheShowcase; return {}; } } //set the current showcase in the local cache function setCurrentShowcase(theShowcase) { var cache = DSCacheFactory.get(currentShowcaseCache); if (cache) cache.put(currentShowcaseCacheName, theShowcase); else createCurrentShowcaseCache(); } //destroy all cached data e.g. when a user signs out function clearAllCachedData() { DSCacheFactory.destroyAll(); } //set the showcase summary (basically a list of showcases) in the local cache function setShowcaseSummary(summary) { var cache = DSCacheFactory.get(showcaseSummaryCache); if (cache) cache.put(showcaseSummaryCacheName, summary); else createShowcaseSummaryCache(); } //create a local cache to store the current showcase function createCurrentShowcaseCache() { var cache = DSCacheFactory(currentShowcaseCache, { storageMode: 'localStorage' }); cache.setOptions({ maxAge: 3600000, deleteOnExpire: 'aggressive' }); return cache; } //create a local cache to store the 'all showcases' list function createAllShowcasesCache() { var cache = DSCacheFactory(allShowcasesCache, { storageMode: 'localStorage' }); cache.setOptions({ maxAge: 300000, deleteOnExpire: 'aggressive' }); return cache; } //create a local cache to store the linked feeds function createFeedsCache() { var cache = DSCacheFactory(feedsCache, { storageMode: 'localStorage' }); cache.setOptions({ maxAge: 300000, deleteOnExpire: 'aggressive' }); return cache; } //create a local cache to store data about the user function createMeCache() { var cache = DSCacheFactory(meCache, { storageMode: 'localStorage' }); cache.setOptions({ maxAge: 300000, deleteOnExpire: 'aggressive' }); return cache; } //create a local cache to store all the items for the user function createMyItemsCache() { var cache = DSCacheFactory(myStuffCache, { storageMode: 'localStorage' }); cache.setOptions({ maxAge: 300000, deleteOnExpire: 'aggressive' }); return cache; } //create a local cache to store individual items for the user function createItemsCache() { var cache = DSCacheFactory(itemsCache, { storageMode: 'localStorage' }); cache.setOptions({ maxAge: 300000, deleteOnExpire: 'aggressive' }); return cache; } //create a local cache to store showcases function createShowcasesCache() { var cache = DSCacheFactory(showcasesCache, { storageMode: 'localStorage' }); cache.setOptions({ maxAge: 300000, deleteOnExpire: 'aggressive' }); return cache; } //create a local cache to store showcase items (items that are in showcases) function createShowcaseItemsCache() { var cache = DSCacheFactory(showcaseItemsCache, { storageMode: 'localStorage' }); cache.setOptions({ maxAge: 300000, deleteOnExpire: 'aggressive' }); return cache; } //create a local cache to store showcase themes function createThemesCache() { return DSCacheFactory(themesCache, { storageMode: 'localStorage', maxAge: 3600000, deleteOnExpire: 'aggressive' }); } //create a local cache to store the showcase suumary function createShowcaseSummaryCache() { return DSCacheFactory(showcaseSummaryCache, { storageMode: 'localStorage', maxAge: 300000, deleteOnExpire: 'aggressive' }); } //create a local cache to store item tags function createTagSummaryCache() { return DSCacheFactory(tagSummaryCache, { storageMode: 'localStorage', maxAge: 300000, deleteOnExpire: 'aggressive' }); } //clear the relevant item related caches when an item is added - we want to get fresh data from the server in this case function clearCachesForItemAdded() { var msCache = DSCacheFactory.get(myStuffCache); if(msCache) msCache.removeAll(); var tsCache = DSCacheFactory.get(tagSummaryCache); if (tsCache) tsCache.removeAll(); } //clear relevant caches when an item is updated function clearCachesForItemUpdated(itemIds) { if (itemIds) { for (var i = 0; i < itemIds.length; i++) { DSCacheFactory.get(itemsCache).remove(itemIds[i]); } } DSCacheFactory.get(myStuffCache).removeAll(); DSCacheFactory.get(showcasesCache).removeAll(); DSCacheFactory.get(showcaseItemsCache).removeAll(); DSCacheFactory.get(tagSummaryCache).removeAll(); DSCacheFactory.get(showcaseSummaryCache).removeAll(); } //items can change when the user isn't using the web application (e.g. items can be added from external feeds or mobile app) //when the user goes back to the web app they want to see the latest data so work out if anything has changed by calling the server and if it has clear the relevant caches function checkShouldResetCachesWithItems() { var request = $http({ method: "get", url: config.userRemoteServiceUrl + 'itemcacheclear' }); return (request.then(function (response) { if (response.data.action == 'itemsadded') clearCachesForItemAdded(); else if (response.data.action == 'itemsupdated') clearCachesForItemUpdated(response.data.itemIds); return response.data.action != 'nowt'; }, handleError)); } //get the showcase summary (list of showcases) function getShowcaseSummary() { //check if its already cached locally, if it is return it in a promise var cache = DSCacheFactory.get(showcaseSummaryCache); if (cache) { var cacheShowcaseSummary = cache.get(showcaseSummaryCacheName); if (cacheShowcaseSummary) { var deferred = $q.defer(); deferred.resolve(cacheShowcaseSummary); return deferred.promise; } }//its not in the local cache so create the cache (if its not already there) else cache = createShowcaseSummaryCache(); //get the data from the server var request = $http({ method: "get", url: config.showcaseRemoteServiceUrl+"summary" }); return (request.then(function (response) { //add the data to the cache ready for next time and return the data cache.put(showcaseSummaryCacheName, response.data); return response.data; }, handleError)); } //publish a showcase function publishShowcase(showcaseId) { //clear down the showcase caches DSCacheFactory.get(allShowcasesCache).removeAll(); DSCacheFactory.get(showcaseSummaryCache).removeAll(); DSCacheFactory.get(showcasesCache).remove(showcaseId); //call the serverside REST endpoint to publish var request = $http({ method: "get", url: config.showcaseRemoteServiceUrl + showcaseId + "/publish" }); return (request.then(handleSuccess, handleError)); } //a user has been editing a showcase, that process creates a temporary showcase (we don't want to change the original showcase because the user may not commit) //this function is called when a user commits the showcase changes function commitTemporaryShowcases(showcaseId) { DSCacheFactory.get(showcasesCache).remove(showcaseId); DSCacheFactory.get(showcaseItemsCache).remove(showcaseId); DSCacheFactory.get(allShowcasesCache).removeAll(); DSCacheFactory.get(showcaseSummaryCache).removeAll(); var request = $http({ method: "get", url: config.showcaseRemoteServiceUrl + showcaseId + "/committemporary" }); return (request.then(handleSuccess, handleError)); } //delete a temp showcase (e.g. when a user cancels from an edit) function deleteTemporaryShowcases(showcaseId) { var request = $http({ method: "delete", url: config.showcaseRemoteServiceUrl + showcaseId + "/temporary" }); return (request.then(handleSuccess, handleError)); } //get showcase by framework id function getShowcaseByFrameworkId(frameworkId) { var request = $http({ method: "get", url: config.showcaseRemoteServiceUrl + 'showcasebyframework/' + frameworkId }); return (request.then(handleSuccess, handleError)); } //clone / copy a showcase function cloneShowcase(showcaseId) { DSCacheFactory.get(allShowcasesCache).removeAll(); DSCacheFactory.get(showcaseSummaryCache).removeAll(); var request = $http({ method: "get", url: config.showcaseRemoteServiceUrl + showcaseId + "/clone" }); return (request.then(handleSuccess, handleError)); } //users are invited to join organisations and a unique organisationInviteId is sent in a message to them //when the user accepts the invite this function is called function linkOrganisationInviteWithUser(organisationInviteId) { var request = $http({ method: "get", url: config.notificationsRemoteServiceUrl + 'organisationinvitelink/' + organisationInviteId }); return (request.then(function (response) { return; }, handleError)); } //get feeds (a feed is a link from another tool to MyShowcase e.g. Evernote) that the user has set up function getFeeds() { //try to get from the local cache, if not create the cache, get from the server, add to the cache and return var cache = DSCacheFactory.get(feedsCache); if (cache) { var cacheFeeds = cache.get(allFeedsCacheName); if (cacheFeeds) { var deferred = $q.defer(); deferred.resolve(cacheFeeds); return deferred.promise; } } else cache = createFeedsCache(); var request = $http({ method: "get", url: config.feedRemoteServiceUrl }); return (request.then(function (response) { cache.put(allFeedsCacheName, response.data); return response.data; }, handleError)); } //create a new feed for the user function createFeed(feed) { DSCacheFactory.get(feedsCache).removeAll(); var request = $http({ method: "post", url: config.feedRemoteServiceUrl, data:feed }); return (request.then(function (response) { return response.data; }, handleError)); } //chnage a feed for the user function editFeed(feed) { DSCacheFactory.get(feedsCache).removeAll(); var request = $http({ method: "put", url: config.feedRemoteServiceUrl + feed.id, data:feed }); return (request.then(function (response) { return response.data; }, handleError)); } //remove a feed function deleteFeed(feedId) { DSCacheFactory.get(feedsCache).removeAll(); var request = $http({ method: "delete", url: config.feedRemoteServiceUrl + feedId }); return (request.then(function (response) { return response.data; }, handleError)); } //get a specific item using its unique ID function getItem(itemId) { //is it in the local cache? If so use it var cache = DSCacheFactory.get(itemsCache); if (cache) { var cacheItem = cache.get(itemId); if (cacheItem) { var deferred = $q.defer(); deferred.resolve(cacheItem); return deferred.promise; } } else createItemsCache(); //it ain't so get from server var request = $http({ method: "get", url: config.myItemRemoteServiceUrl + itemId }); return (request.then(function (response) { //add to cache and return the item cache.put(itemId, response.data); return response.data; }, handleError)); } //put an item into the recycle bin using its unique id //the item is 'soft deleted' function recycleBinItem(itemId) { //clear the caches DSCacheFactory.get(myStuffCache).removeAll(); DSCacheFactory.get(itemsCache).remove(itemId); DSCacheFactory.get(tagSummaryCache).removeAll(); DSCacheFactory.get(showcaseSummaryCache).removeAll(); DSCacheFactory.get(showcaseItemsCache).removeAll(); var request = $http({ method: "get", url: config.myItemRemoteServiceUrl + itemId + "/movetorecyclebin" }); return (request.then(handleSuccess, handleError)); } //get possible showcase themes function getThemes() { //try to get from local cache var cache = DSCacheFactory.get(themesCache); if (cache) { var cacheThemes = cache.get(allThemesCacheName); if (cacheThemes) { var deferred = $q.defer(); deferred.resolve(cacheThemes); return deferred.promise; } } //its not in the cache so get from server and add to the cache else createThemesCache(); var request = $http({ method: "get", url: config.themesRemoteServiceUrl }); return (request.then(function (response) { cache.put(allThemesCacheName, response.data); return response.data; }, handleError)); } //get all showcases for the user function getShowcases(getCached) { if (getCached) { if (showcases) { var deferred = $q.defer(); deferred.resolve(showcases); return deferred.promise; } else { var request = $http({ method: "get", url: config.showcaseRemoteServiceUrl }); } } else { //if not get from server and add to cache var request = $http({ method: "get", url: config.showcaseRemoteServiceUrl }); } return (request.then(function (response) { showcases = response.data return response.data; }, handleError)); } //get a specific showcase using its unique ID function getShowcase(showcaseId) { //try to get from cache var cache = DSCacheFactory.get(showcasesCache); if (cache) { var cacheShowcase = cache.get(showcaseId); if (cacheShowcase) { var deferred = $q.defer(); deferred.resolve(cacheShowcase); return deferred.promise; } } else createShowcasesCache(); //its not in the cache so get from server, add to cache and return var request = $http({ method: "get", url: config.showcaseRemoteServiceUrl + showcaseId }); return (request.then(function (response) { cache.put(showcaseId, response.data); return response.data; }, handleError)); } //get the showcases that are available to add an item to (showcases that don't already have that item) //this could possibly be refactored to calculate this client side rather than hitting the server function getShowcasesAvailableForItem(itemId) { var request = $http({ method: "get", url: config.showcaseRemoteServiceUrl + "availableforitem/" + itemId }); return (request.then(handleSuccess, handleError)); } //get the showcases that are linked to an item function getShowcasesLinkedToItem(itemId) { var request = $http({ method: "get", url: config.showcaseRemoteServiceUrl + "linkedtoitem/" + itemId }); return (request.then(handleSuccess, handleError)); } //get all items in a showcase function getItemsForShowcase(showcaseId) { //try to get from the local cache //var cache = DSCacheFactory.get(showcaseItemsCache); //if (cache) { // var cacheShowcaseItems = cache.get(showcaseId); // if (cacheShowcaseItems) { // var deferred = $q.defer(); // deferred.resolve(cacheShowcaseItems); // return deferred.promise; // } //} // //its not there so get from server and add to cache //else // cache=createShowcaseItemsCache(); var request = $http({ method: "get", url: config.showcaseRemoteServiceUrl + showcaseId + "/items" }); return (request.then(function (response) { //cache.put(showcaseId, response.data); return response.data; }, handleError)); } //stick all my items in the local cache function setMyItems(data) { var cache = DSCacheFactory.get(myStuffCache); cache.put(allItemsCacheName, data); } //get all users items function getMyItems() { //try to get from the local cache var cache = DSCacheFactory.get(myStuffCache); if (cache) { var cacheData = cache.get(allItemsCacheName); if (cacheData) { var deferred = $q.defer(); deferred.resolve(cacheData); return deferred.promise; } } else cache = createMyItemsCache(); //its not there so get from server, add to cache var request = $http({ method: "get", url: config.myItemRemoteServiceUrl }); return (request.then(function(response) { cache.put(allItemsCacheName, response.data); return { allDataPresent:false, items:response.data }; }, handleError)); } //get extra data for all users items function getMyItemsExtra() { var request = $http({ method: "get", url: config.myItemRemoteServiceUrl + 'extra' }); return (request.then(function (response) { return response.data; }, handleError)); } function getItemDetailBySource(source) { var request = $http({ method: "get", url: source }); return (request.then(function (response) { return response.data; }, handleError)); } //handle an error response (HTTP 500 etc) from the server 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, value) { if (value) return (response.data, value); return (response.data); } function createEvidence(evidence, deployedAssignmentId) { var request = $http({ data: evidence, method: "post", url: config.apigatewayUrl + 'deployedassignment/EvidenceForMe/' + deployedAssignmentId }); return (request.then(handleSuccess, handleError)); } function deleteEvidence(evidenceId, deployedAssignmentId) { var request = $http({ method: "delete", url: config.apigatewayUrl + 'deployedassignment/EvidenceForMe/' + deployedAssignmentId + '/evidence/' + evidenceId }); return (request.then(handleSuccess, handleError)); } //create a new status (AKA text note) item function createStatusItem(statusItem) { //clear the cache so the app updates clearCachesForItemAdded(); var request = $http({ data:statusItem, method: "post", url: config.statusItemRemoteServiceUrl }); return (request.then(handleSuccess, handleError)); } //create a new reflection item function createReflectionItem(reflectionItem) { //clear the cache so the app updates clearCachesForItemAdded(); var request = $http({ data: reflectionItem, method: "post", url: config.reflectionItemRemoteServiceUrl }); return (request.then(handleSuccess, handleError)); } //create a new embed item (vimeo, prezzi etc.) function createEmbedItem(item) { clearCachesForItemAdded(); var request = $http({ data: item, method: "post", url: config.embedItemRemoteServiceUrl }); return (request.then(handleSuccess, handleError)); } //create a new image item function createImageItem(imageItem) { clearCachesForItemAdded(); var request = $http({ data: imageItem, method: "post", url: config.imageItemRemoteServiceUrl }); return (request.then(handleSuccess, handleError)); } //create a new video item function createVideoItem(videoItem) { clearCachesForItemAdded(); var request = $http({ data: videoItem, method: "post", url: config.videoItemRemoteServiceUrl }); return (request.then(handleSuccess, handleError)); } //create a new badge (open badges) item function createBadgeItem(badgeItem) { clearCachesForItemAdded(); var request = $http({ data: badgeItem, method: "post", url: config.badgeItemRemoteServiceUrl }); return (request.then(handleSuccess, handleError)); } //create a new file item function createFileItem(fileItem) { clearCachesForItemAdded(); var request = $http({ data: fileItem, method: "post", url: config.fileItemRemoteServiceUrl }); return (request.then(handleSuccess, handleError)); } //edit a status item function editStatusItem(statusItem) { clearCachesForItemUpdated([statusItem.itemId]); var request = $http({ data: statusItem, method: "put", url: config.statusItemRemoteServiceUrl + statusItem.itemId }); return (request.then(handleSuccess, handleError)); } //edit a reflection item function editReflectionItem(reflectionItem) { clearCachesForItemUpdated([reflectionItem.itemId]); var request = $http({ data: reflectionItem, method: "put", url: config.reflectionItemRemoteServiceUrl + reflectionItem.itemId }); return (request.then(handleSuccess, handleError)); } //edit a weblink (like a webclipping) item function editWeblinkItem(weblinkItem) { clearCachesForItemUpdated([weblinkItem.itemId]); var request = $http({ data: weblinkItem, method: "put", url: config.weblinkItemRemoteServiceUrl + weblinkItem.itemId }); return (request.then(handleSuccess, handleError)); } //create a new weblink item function createWeblinkItem(weblinkItem) { clearCachesForItemAdded(); var request = $http({ data: weblinkItem, method: "post", url: config.weblinkItemRemoteServiceUrl }); return (request.then(handleSuccess, handleError)); } //edit a BadgeCollection item function editBadgeCollectionItem(BadgeCollectionItem) { clearCachesForItemUpdated([BadgeCollectionItem.itemId]); var request = $http({ data: BadgeCollectionItem, method: "put", url: config.badgeCollectionItemRemoteServiceUrl + BadgeCollectionItem.itemId }); return (request.then(handleSuccess, handleError)); } //create a new BadgeCollection item function createBadgeCollectionItem(BadgeCollectionItem) { clearCachesForItemAdded(); var request = $http({ data: BadgeCollectionItem, method: "post", url: config.badgeCollectionItemRemoteServiceUrl }); return (request.then(handleSuccess, handleError)); } //edit a weblink item function editEvernoteItem(evernoteItem) { clearCachesForItemUpdated([evernoteItem.itemId]); var request = $http({ data: evernoteItem, method: "put", url: config.evernoteItemRemoteServiceUrl + evernoteItem.itemId }); return (request.then(handleSuccess, handleError)); } //edit an image item function editImageItem(imageItem) { clearCachesForItemUpdated([imageItem.itemId]); var request = $http({ data: imageItem, method: "put", url: config.imageItemRemoteServiceUrl + imageItem.itemId }); return (request.then(handleSuccess, handleError)); } //edit a video item function editVideoItem(videoItem) { clearCachesForItemUpdated([videoItem.itemId]); var request = $http({ data: videoItem, method: "put", url: config.videoItemRemoteServiceUrl + videoItem.itemId }); return (request.then(handleSuccess, handleError)); } //edit a badge item function editBadgeItem(badgeItem) { clearCachesForItemUpdated([badgeItem.itemId]); var request = $http({ data: badgeItem, method: "put", url: config.badgeItemRemoteServiceUrl + badgeItem.itemId }); return (request.then(handleSuccess, handleError)); } //edit a file item function editFileItem(fileItem) { clearCachesForItemUpdated([fileItem.itemId]); var request = $http({ data: fileItem, method: "put", url: config.fileItemRemoteServiceUrl + fileItem.itemId }); return (request.then(handleSuccess, handleError)); } //edit an assessment item function editAssessmentItem(assessmentItem) { clearCachesForItemUpdated([assessmentItem.itemId]); var request = $http({ data: assessmentItem, method: "put", url: config.assessmentItemRemoteServiceUrl + assessmentItem.itemId }); return (request.then(handleSuccess, handleError)); } //edit an embed item function editEmbedItem(embedtem) { clearCachesForItemUpdated([embedtem.itemId]); var request = $http({ data: embedtem, method: "put", url: config.embedItemRemoteServiceUrl + embedtem.itemId }); return (request.then(handleSuccess, handleError)); } //showcase an item (add an item to a showcase(s)) //the showcase ids to add it to //the id of the item to be added //the position in the showcase to add to function showcaseItem(showcaseIds, itemId, index) { //clear all the relevant caches DSCacheFactory.get(itemsCache).remove(itemId); DSCacheFactory.get(myStuffCache).removeAll(); DSCacheFactory.get(allShowcasesCache).removeAll(); DSCacheFactory.get(showcasesCache).removeAll(); DSCacheFactory.get(showcaseItemsCache).removeAll(); DSCacheFactory.get(showcaseSummaryCache).removeAll(); var request = $http({ method: "post", data: { showcaseIds: showcaseIds, }, url: config.myItemRemoteServiceUrl + itemId + "/showcase/" + index }); return (request.then(handleSuccess, handleError)); } function showcaseItems(showcaseId, itemIds, parentId) { //clear all the relevant caches var request = $http({ method: "post", data: itemIds, url: config.myItemRemoteServiceUrl + showcaseId + "/showcaseitems/" + parentId }); return (request.then(handleSuccess, handleError)); } //showcase an 'add in' (a heading or piece of descriptive text) function showcaseAddInItem(showcaseIds, index, addInType, name, level, isGroup, children, childrenWithData, details) { DSCacheFactory.get(allShowcasesCache).removeAll(); DSCacheFactory.get(showcasesCache).removeAll(); DSCacheFactory.get(showcaseItemsCache).removeAll(); DSCacheFactory.get(showcaseSummaryCache).removeAll(); if (!name) { var request = $http({ method: "post", data: { showcaseIds: showcaseIds, }, url: config.myItemRemoteServiceUrl + "showcaseaddin/" + addInType + "/" + index }); } else { // We provided a title so we create the item with this value var request = $http({ method: "post", data: { showcaseIds: showcaseIds, title: name, details: details, level: level, isGroup: isGroup, children: children, childrenWithData: childrenWithData }, url: config.myItemRemoteServiceUrl + "showcaseaddin/" + addInType + "/" + index }); } return (request.then(handleSuccess, handleError)); } //remove an item from a showcase using its showcaseitemid function removeItemFromShowcaseByShowcaseItemId(showcaseItemId) { DSCacheFactory.get(myStuffCache).removeAll(); DSCacheFactory.get(allShowcasesCache).removeAll(); DSCacheFactory.get(showcaseItemsCache).removeAll(); DSCacheFactory.get(showcaseSummaryCache).removeAll(); var request = $http({ method: "delete", url: config.myItemRemoteServiceUrl + showcaseItemId + "/showcaseitem" }); return (request.then(handleSuccess, handleError)); } //remove an item from a showcase using its showcaseid and itemid function removeItemFromShowcaseByShowcaseIdAndItemId(showcaseId, itemId) { DSCacheFactory.get(itemsCache).remove(itemId); DSCacheFactory.get(myStuffCache).removeAll(); DSCacheFactory.get(allShowcasesCache).removeAll(); DSCacheFactory.get(showcasesCache).remove(showcaseId); DSCacheFactory.get(showcaseItemsCache).removeAll(); DSCacheFactory.get(showcaseSummaryCache).removeAll(); var request = $http({ method: "delete", url: config.myItemRemoteServiceUrl + itemId + "/showcase/" + showcaseId }); return (request.then(handleSuccess, handleError)); } //send a message to people to review a showcase function sendShowcase(showcaseId, shortcode, emails) { DSCacheFactory.get(showcasesCache).remove(showcaseId); var request = $http({ method: "post", data: emails, url: config.showcaseRemoteServiceUrl + showcaseId + "/send/"+shortcode }); return (request.then(handleSuccess, handleError)); } //manage / edit items in a showcase e.g. move items around function manageShowcaseItems(showcaseId, showcaseItems) { DSCacheFactory.get(showcasesCache).remove(showcaseId); DSCacheFactory.get(showcaseItemsCache).removeAll(); var request = $http({ method: "post", data: showcaseItems, url: config.showcaseRemoteServiceUrl + showcaseId + "/manageitems/" }); return (request.then(handleSuccess, handleError)); } //create a new showcase function createShowcase(showcase) { DSCacheFactory.get(allShowcasesCache).removeAll(); DSCacheFactory.get(showcaseSummaryCache).removeAll(); var request = $http({ method: "post", data: showcase, url: config.showcaseRemoteServiceUrl }); return (request.then(handleSuccess, handleError)); } //delete a showcase using its unique id function deleteShowcase(showcaseId) { DSCacheFactory.get(allShowcasesCache).removeAll(); DSCacheFactory.get(showcasesCache).remove(showcaseId); DSCacheFactory.get(showcaseItemsCache).remove(showcaseId); DSCacheFactory.get(showcaseSummaryCache).removeAll(); var request = $http({ method: "delete", url: config.showcaseRemoteServiceUrl + showcaseId }); return (request.then(handleSuccess, handleError)); } //mark a showcase as archived function setShowcaseArchived(showcaseId, shouldArchive) { DSCacheFactory.get(allShowcasesCache).removeAll(); DSCacheFactory.get(showcasesCache).remove(showcaseId); DSCacheFactory.get(showcaseItemsCache).remove(showcaseId); DSCacheFactory.get(showcaseSummaryCache).removeAll(); var request = $http({ method: "get", url: config.showcaseRemoteServiceUrl + showcaseId + '/setarchived/' + shouldArchive }); return (request.then(handleSuccess, handleError)); } function sendShowcaseReviewMessage(showcase,shortcode) { DSCacheFactory.get(showcasesCache).remove(showcase.showcaseId); var request = $http({ method: "post", data: showcase, url: config.showcaseRemoteServiceUrl + "send/" + shortcode }); return (request.then(handleSuccess, handleError)); } //edit / manage a showcase (chnage its name etc.) function manageShowcase(showcase) { DSCacheFactory.get(showcasesCache).remove(showcase.showcaseId); DSCacheFactory.get(showcaseItemsCache).remove(showcase.showcaseId); DSCacheFactory.get(allShowcasesCache).removeAll(); DSCacheFactory.get(showcaseSummaryCache).removeAll(); DSCacheFactory.get(myStuffCache).removeAll(); var request = $http({ method: "post", data: showcase, url: config.showcaseRemoteServiceUrl+ "manage" }); return (request.then(handleSuccess, handleError)); } //get item tags that match a query function getTags(query) { var request = $http({ method: "get", url: config.tagsRemoteServiceUrl +query }); return (request.then(handleSuccess, handleError)); } //get email addresses that match a query function getEmails(query) { var request = $http({ method: "get", url: config.userRemoteServiceUrl + 'myemails/'+ query }); return (request.then(handleSuccess, handleError)); } //get email reviewer names that match a query function getReviewerNames(query) { var request = $http({ method: "get", url: config.userRemoteServiceUrl + 'myreviewernames/' + query }); return (request.then(handleSuccess, handleError)); } //get the item tags along with the number of items against each tag function getTagSummary() { //try to get from cache var cache = DSCacheFactory.get(tagSummaryCache); if (cache) { var cacheTags = cache.get(tagSummaryCacheName); if (cacheTags) { var deferred = $q.defer(); deferred.resolve(cacheTags); return deferred.promise; } } else //get from server and add to cache cache = createTagSummaryCache(); var request = $http({ method: "get", url: config.tagsRemoteServiceUrl }); return (request.then(function (response) { cache.put(tagSummaryCacheName, response.data); return response.data; }, handleError)); } //get notifications for the user function getNotifications() { var request = $http({ method: "get", url: apigatewayUrl + 'notifications/api/notifications/appcode/' + config.appCode }); return (request.then(function (response) { return response.data; }, handleError)); } //delete a notification (e.g. user has read it) function deleteNotification(notificationId) { var request = $http({ method: "delete", url: config.notificationsRemoteServiceUrl + 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)); } //reject a notification function rejectNotification(notificationId) { var request = $http({ method: "delete", url: config.notificationsRemoteServiceUrl + notificationId+'/reject' }); return (request.then(handleSuccess, handleError)); } //send a notification (to another user) function sendNotification(data) { var request = $http({ method: "post", url: config.notificationsRemoteServiceUrl + '/send', data:data }); return (request.then(handleSuccess, handleError)); } function deleteInvite(inviteId, orgId) { var request = $http({ method: "delete", url: config.myusersUrl + "organisationadministration/" + orgId + "/invites/" + inviteId }); return (request.then(handleSuccess, handleError)); } //get a summary of the competencies and numbers of associated tags for current user function getCompetencySummaryForMe(requestModel) { var request = $http({ method: "post", url: config.userRemoteServiceUrl + 'itemsummary', data: requestModel }); return (request.then(handleSuccess, handleError)); } //change the password function changePassword(model) { var request = $http({ method: "post", url: config.myusersUrl + 'api/account/changepassword', data: model }); return (request.then(handleSuccess, handleError)); } //request that you have forgotten your password function forgotPassword(model) { var request = $http({ method: "post", url: config.myusersUrl + 'api/account/forgottenpassword', data: model }); return (request.then(handleSuccess, handleError)); } //set a showcase as private / public function toggleShowcasePublicPrivate(showcaseId) { DSCacheFactory.get(allShowcasesCache).removeAll(); DSCacheFactory.get(showcasesCache).remove(showcaseId); var request = $http({ method: "get", url: config.showcaseRemoteServiceUrl + showcaseId + "/togglepublicprivate" }); return (request.then(handleSuccess, handleError)); } //set a showcase as private / public function toggleShowcasePublicPrivateVersion(showcaseId ,showcaseVersion) { var request = $http({ method: "put", url: config.siteUrl + 'api/showcaseversions/' + showcaseId + '/' + showcaseVersion.version + '/publicity', data: showcaseVersion }); return (request.then(handleSuccess, handleError)); } //create a form based item (an item from a MyForms form) function createFormItem(formItem) { clearCachesForItemAdded(); var request = $http({ data: formItem, method: "post", url: config.formItemRemoteServiceUrl }); return (request.then(handleSuccess, handleError)); } //edit a MyForms item function editFormItem(formItem) { clearCachesForItemUpdated([formItem.itemId]); var request = $http({ data: formItem, method: "put", url: config.formItemRemoteServiceUrl + formItem.itemId }); return (request.then(handleSuccess, handleError)); } //set a showcase as private / public function getShowcaseVersions(showcaseId) { var request = $http({ method: "get", url: config.siteUrl + "api/showcaseversions/" + showcaseId }); return (request.then(handleSuccess, handleError)); } //set a showcase as private / public function getSpecificShowcaseVersion(showcaseId, version) { var request = $http({ method: "get", url: config.siteUrl + "api/showcaseversions/" + showcaseId + "/" + version }); return (request.then(handleSuccess, handleError)); } //use a service to check if an openbadge is a valid openbadge function isValidOpenbadge(badgeString) { var request = $http({ method: "post", url: config.mybadgesUrl + "openbadges/validator" }); return (request.then(handleSuccess, handleError)); } //use a service to upload and strip out data from an openbadge function parseOpenbadge(badgeString, emails) { var request = $http({ data: { fileString: badgeString, emails: emails }, method: "post", url: config.mybadgesUrl + "openbadges/upload/parser" }); return (request.then(handleSuccess, handleError)); } // get backpack account function getBadgeAccount() { var request = $http({ method: "get", url: config.mybadgesUrl + 'account/', }); return (request.then(handleSuccess, handleError)); } // create backpack account function createBadgeAccount(accountModel) { var request = $http({ method: "post", url: config.mybadgesUrl + 'account/', }); return (request.then(handleSuccess, handleError)); } // send verification email function sendVerificationEmail(userId) { var request = $http({ method: "post", url: config.mybadgesUrl + 'account/verification', data: { userId: userId } }); return (request.then(handleSuccess, handleError)); } // send verification email function saveBadgeUser(user) { var request = $http({ method: "put", url: config.mybadgesUrl + 'user', data: user }); return (request.then(handleSuccess, handleError)); } // send users theme function saveBadgeUserTheme(userTheme) { var request = $http({ method: "put", url: config.mybadgesUrl + 'user/theme', data: userTheme }); return (request.then(handleSuccess, handleError)); } // update alternative emails function updateEmails(emails) { var request = $http({ method: "put", url: config.mybadgesUrl + 'user/alternativeemails', data: emails }); return (request.then(handleSuccess, handleError)); } function makeEmailPrimary(email) { var request = $http({ method: "put", url: config.mybadgesUrl + 'user/primaryemail', data: email }); return (request.then(handleSuccess, handleError)); } // send verification to alternative email function resendAlternativeEmailVerification(alternativeEmail) { var request = $http({ method: "post", url: config.mybadgesUrl + 'user/alternativeemails/verifications', data: alternativeEmail }); return (request.then(handleSuccess, handleError)); } // resend verification email function resendVerification(applicationUrl) { var request = $http({ method: "post", url: config.mybadgesUrl + 'account/verification', data: applicationUrl }); return (request.then(handleSuccess, handleError)); } // getAllBadgesForUser function getAllBadgesForUser() { var request = $http({ method: "get", url: config.mybadgesUrl + 'backpack', }); return (request.then(handleSuccess, handleError)); } // getAllBadgesForUser function getBadgesCountForUser() { var request = $http({ method: "get", url: config.mybadgesUrl + 'backpack/items/count', }); return (request.then(handleSuccess, handleError)); } // create badge backpack function createBackpackItem(badge) { var request = $http({ method: "post", url: config.mybadgesUrl + 'backpack/items', data: badge }); return (request.then(handleSuccess, handleError)); } // update a badge function updateBadgeItem(badge) { var request = $http({ method: "put", url: config.mybadgesUrl + 'backpackitems', data: badge }); return (request.then(handleSuccess, handleError)); } // delete a badge function deleteBadgeItem(badgeId) { var request = $http({ method: "delete", url: config.mybadgesUrl + 'backpackitems/' + badgeId, }); return (request.then(handleSuccess, handleError)); } // create a collection function getCollectionsForUser() { var request = $http({ method: "get", url: config.mybadgesUrl + 'backpackcollections/stages', }); return (request.then(handleSuccess, handleError)); } // create a collection function createCollection(collection) { var request = $http({ method: "post", url: config.mybadgesUrl + 'backpackcollections/stages', data: collection }); return (request.then(handleSuccess, handleError)); } // update a collection function updateCollection(collection) { var request = $http({ method: "put", url: config.mybadgesUrl + 'backpackcollections', data: collection }); return (request.then(handleSuccess, handleError)); } // delete a collection function deleteCollection(collection) { var request = $http({ method: "delete", url: config.mybadgesUrl + 'backpackcollections/stages/' + collection.id, }); return (request.then(handleSuccess, handleError)); } // get collection by id function getCollectionById(collectionId) { var request = $http({ method: "get", url: config.mybadgesUrl + 'backpackcollections/stages/' + collectionId, }); return (request.then(handleSuccess, handleError)); } // publisCollection function publishCollectionContent(collectionId) { var request = $http({ method: "get", url: config.mybadgesUrl + 'backpackcollections/stages/' + collectionId + '/publisher', }); return (request.then(handleSuccess, handleError)); } // add items to a collection function addItemsToCollection(collection) { var request = $http({ method: "post", url: config.mybadgesUrl + 'backpackcollections/items', data: collection }); return (request.then(handleSuccess, handleError)); } // remove items from a collection function removeItemsFromCollection(collection) { var request = $http({ method: "post", url: config.mybadgesUrl + 'backpackcollections/items/remover', data: collection }); return (request.then(handleSuccess, handleError)); } // fetch all badges for a given email address function getBadgesForEmail(backpackModel) { var request = $http({ method: "post", url: config.mybadgesUrl + 'backpack/associatedemails/items', data: backpackModel }); return (request.then(handleSuccess, handleError)); } // set badges to retrieved function setToRetrieved(model) { var request = $http({ method: "put", url: config.mybadgesUrl + 'user/badgesretrieved', data: model }); return (request.then(handleSuccess, handleError)); } // create a conversation function createConversation(model) { var request = $http({ method: "post", url: config.mymessagesUrl + 'conversations', data: model, headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' } }); return (request.then(handleSuccess, handleError)); } // get conversations function getConversations() { var request = $http({ method: "get", url: config.mymessagesUrl + 'conversations' }); return (request.then(handleSuccess, handleError)); } // get users details (names, avatar etc) by a list of their ids function getUserDetails(userIds) { var request = $http({ method: "post", url: 'api/users/details', data: userIds, }); return (request.then(handleSuccess, handleError)); } // marks entire conversation as read for the message recipient function markConversationAsReadForMessageRecipient(conversation) { var request = $http({ method: "put", url: config.mymessagesUrl + 'conversations/messages/read', data: conversation, }); return (request.then(handleSuccess, handleError)); } // updates conversation when reply has been made function replyToConversation(conversation) { var request = $http({ method: "post", url: config.mymessagesUrl + 'conversations/messages/reply', data: conversation, }); return (request.then(handleSuccess, handleError)); } // adds tags to conversation for participant function addTagsToConversation(participant) { var request = $http({ method: "post", url: config.mymessagesUrl + 'conversations/participant/tag', data: participant, }); return (request.then(handleSuccess, handleError)); } // get individual framework function getAllIndividualFramework(userId) { var request = $http({ method: "get", url: 'api/individualframeworks/user/' + userId }); 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)); } //config.apigatewayUrl + 'deployedassignment/evidenceforme/' + deployedAssignmentId + '/evidencesummary' // url: "https://192.168.2.112:59400/" + 'deployedassignment/evidenceforme/' + deployedAssignmentId + '/evidencesummary' // url: "https://192.168.2.112:59400/" + 'deployedassignment/evidenceforme/' + deployedAssignmentId + '/evidence/' + deployedAssignmentId function getDeployedFrameworkAssignmentForMeWithEvidenceSummary(deployedAssignmentId) { var request = $http({ method: "get", url: config.apigatewayUrl + 'deployedassignment/evidenceforme/' + deployedAssignmentId + '/evidencesummary' }); return (request.then(handleSuccess, handleError)); } // get individual framework function publishIndividualFramework(framework) { var request = $http({ method: "post", url: 'api/individualframeworks/publisher', data: framework }); return (request.then(handleSuccess, handleError)); } // marks entire conversation as read for the message recipient function setFrameworkStatus(model) { var request = $http({ method: "put", url: 'api/individualframeworks/useronlystatus', data: model, }); return (request.then(handleSuccess, handleError)); } function setFrameworkChanged(model) { var request = $http({ method: "put", url: 'api/individualframeworks/haschangesstatus', data: model, }); return (request.then(handleSuccess, handleError)); } function getFrameworkChanged(model) { var request = $http({ method: "get", url: 'api/individualframeworks/' + model.frameworkId + '/haschangesstatus', }); return (request.then(handleSuccess, handleError)); } // gets user summary function getUserSummary(userIds) { var request = $http({ method: "post", url: config.usersRemoteServiceUrl + 'usersummary', data: userIds }); return (request.then(handleSuccess, handleError)); } function generateLtiPairing(url) { var request = $http({ method: "post", url: config.ltiRemoteServiceUrl + 'pairings', data: { hostUrl : url } }); return (request.then(handleSuccess, handleError)); } function validateConnection(ltiConnection) { var request = $http({ method: "post", url: config.myusersUrl + 'api/canvas/launch/connectexisting', data: ltiConnection }); return (request.then(handleSuccess, function (error) { return error.data; })); } function linkExistingAccount(ltiConnection) { var request = $http({ method: "post", url: config.myusersUrl + 'api/canvas/launch/linkexisting', data: ltiConnection }); return (request.then(handleSuccess, function(error) { return error.data; })); } function createAccountIfNotExist(ltiConnection) { var request = $http({ method: "post", url: config.myusersUrl + 'api/canvas/launch/createifnotexist', data: ltiConnection }); return (request.then(handleSuccess, function (error) { return error.data; })); } function signInWithAuthData(authData) { var request = $http({ method: "post", url: config.myusersUrl + 'api/canvas/launch/signinwithautdata', data: authData }); return (request.then(handleSuccess, function (error) { return error.data; })); } function mergeAccounts(connection) { var request = $http({ method: "post", url: config.myusersUrl + 'api/canvas/launch/mergeaccounts', data: connection }); return (request.then(handleSuccess, function(error) { return error.data; })); } function getCanvasConnections(userId) { var request = $http({ method: "get", url: config.myusersUrl + 'api/canvas/user/' + userId + '/connections' }); return (request.then(handleSuccess, function (error) { return error.data; })); } function getCanvasIntegrationByDomain(url){ var request = $http({ method: "post", data: {'systemUrl': url}, url: config.myusersUrl + 'api/lti/organisationconnections/domains' }); return (request.then(handleSuccess, handleError)); } function getCanvasIntegrationByConnection(connectionId){ var request = $http({ method: "get", url: config.myusersUrl + 'api/lti/organisationconnections/connectionids/' + connectionId }); return (request.then(handleSuccess, handleError)); } function configureCanvasForUser(code, connectionId, canvasUserId) { var request = $http({ method: "post", url: config.myusersUrl + 'api/lti/userconnections/token', data: { connectionId: connectionId, redirectUri: 'https://dev.myshowcase.me/' + '%2F%23!%2Fcanvas', code: code, ltiUserId: canvasUserId, oAuthEndPoint: "login/oauth2/token" } }); return (request.then(handleSuccess, handleError)); } function disconnectCanvasConnection(connection) { var request = $http({ method: "delete", url: config.myusersUrl + 'api/canvas/user/' + connection.userId + '/disconnect/' + connection.url }); return (request.then(handleSuccess, function (error) { return error.data; })); } 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 createCalendar(calendar) { var request = $http({ method: "post", url: config.calendarUrl + "api/calendarsmanager", data: calendar }); return (request.then(handleSuccess, handleError)); } function createCalendarEvent(event) { var request = $http({ method: "post", url: config.calendarUrl + "api/calendarevents", data: event }); return (request.then(handleSuccess, handleError)); } function updateCalendarEvent(event) { var request = $http({ method: "put", url: config.calendarUrl + "api/calendarevents/" + event.id, data: event }); return (request.then(handleSuccess, handleError)); } function deleteCalendarEvent(event) { var request = $http({ method: "delete", url: config.calendarUrl + "api/calendarevents/" + event.id, data: event }); 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)); } 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)); } //get all showcases for the user function getShowcasesForAssignments(connectionId) { var request = $http({ method: "get", url: config.apigatewayUrl + "MyShowcaseApi?connectionId=" + connectionId }); return (request.then(function (response) { return response.data; }, handleError)); } } })();