Skip to content

Commit

Permalink
[MNOE-406] commenting and param refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
MAhsenArif committed Feb 22, 2018
1 parent c60b3e3 commit 1891748
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 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 = (force = false) ->

# 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(force)
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(force).then((response) -> deferred.resolve(response))
fetchAppInstances(unscoped).then((response) -> deferred.resolve(response))

return appInstancesPromise = deferred.promise

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

# Retrieve app instances from the backend
fetchAppInstances = (force) ->
# 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(
->
query = if force == true then '?unscoped=true' else ''
query = if unscoped == true then '?unscoped=true' else ''
_self.appInstancesPromise = MnoeApiSvc.one('organizations', MnoeOrganizations.selectedId).one('/app_instances' + query).get().then(
(response) ->
response = response.plain()
Expand Down

0 comments on commit 1891748

Please sign in to comment.