Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MNOE-406] Added logic to request for unscoped data when showing dashboard apps #425

Open
wants to merge 3 commits into
base: 1.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ DashboardAppsDockCtrl = ($scope, $cookies, $uibModal, $window, $timeout, MnoeOrg
$scope.$watch MnoeOrganizations.getSelectedId, (val) ->
if val?
$scope.isLoading = true
MnoeAppInstances.getAppInstances().then(
MnoeAppInstances.getAppInstances(true).then(
(response) ->
$scope.apps = response
).finally(-> $scope.isLoading = false)
Expand Down
14 changes: 9 additions & 5 deletions src/app/components/mnoe-api/app-instances.svc.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ angular.module 'mnoEnterpriseAngular'
@appInstances = []

appInstancesPromise = null
@getAppInstances = ->

# If unscoped and no cache, retrieve app instances irrespective of tenant
@getAppInstances = (unscoped = false) ->
return appInstancesPromise if appInstancesPromise?

deferred = $q.defer()
Expand All @@ -15,14 +17,14 @@ angular.module 'mnoEnterpriseAngular'
cache = MnoLocalStorage.getObject(MnoeCurrentUser.user.id + "_" + LOCALSTORAGE.appInstancesKey)
if cache?
# Refresh the cache content asynchronously
fetchAppInstances()
fetchAppInstances(unscoped)
# Append response array to service array
_self.appInstances = cache
# Return the promised cache
deferred.resolve(cache)
else
# If the cache is empty return the call promise
fetchAppInstances().then((response) -> deferred.resolve(response))
fetchAppInstances(unscoped).then((response) -> deferred.resolve(response))

return appInstancesPromise = deferred.promise

Expand All @@ -33,14 +35,16 @@ angular.module 'mnoEnterpriseAngular'
fetchAppInstances()

# Retrieve app instances from the backend
fetchAppInstances = ->
# If unscoped, retrieve app instances irrespective of tenant
fetchAppInstances = (unscoped) ->
# Workaround as the API is not standard (return a hash map not an array)
# (Prefix operation by '/' to avoid data extraction)
# TODO: Standard API
defer = $q.defer()
MnoeOrganizations.get().then(
->
_self.appInstancesPromise = MnoeApiSvc.one('organizations', MnoeOrganizations.selectedId).one('/app_instances').get().then(
params = if unscoped then {unscoped: true} else {}
_self.appInstancesPromise = MnoeApiSvc.one('organizations', MnoeOrganizations.selectedId).one('/app_instances').get(params).then(
(response) ->
response = response.plain()
# Save the app instances in the local storage
Expand Down