Skip to content

Commit

Permalink
Merge pull request #88 from alexnoox/master
Browse files Browse the repository at this point in the history
[MNOE-215] Fix company creation & Impac config refactor
  • Loading branch information
alexnoox authored Oct 26, 2016
2 parents ace8412 + 0bf3e7d commit a0fa100
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#============================================
#
#============================================
DashboardCompanySelectboxCtrl = ($scope, $location, $stateParams, $cookies, $sce, $uibModal, MnoeCurrentUser, MnoeOrganizations, MnoeAppInstances) ->
DashboardCompanySelectboxCtrl = ($scope, $location, $state, $stateParams, $cookies, $sce, $uibModal, MnoeCurrentUser, MnoeOrganizations, MnoeAppInstances) ->
'ngInject'

#====================================
Expand Down Expand Up @@ -31,10 +31,6 @@ DashboardCompanySelectboxCtrl = ($scope, $location, $stateParams, $cookies, $sce
selectBox.close = ->
selectBox.isClosed = true

selectBox.createNewOrga = ->
newOrgModal.open()
selectBox.close()

#====================================
# Create Company Modal
#====================================
Expand All @@ -48,6 +44,7 @@ DashboardCompanySelectboxCtrl = ($scope, $location, $stateParams, $cookies, $sce
modalInstance.result.then(
(selectedItem) ->
selectBox.changeTo(selectedItem)
$state.go('home.impac')
)

#====================================
Expand Down
11 changes: 6 additions & 5 deletions src/app/components/mnoe-api/organizations.svc.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,18 @@ angular.module 'mnoEnterpriseAngular'
@create = (organization) ->
MnoeApiSvc.all('/organizations').post(organization).then(
(response) ->
# Add the new org in the menu
_self.selectedId = _self.selected.organization.id
MnoeCurrentUser.user.organizations.push(response.plain().organization)

# Reload the permissions
# Reload the permissions and save organization id in a cookie
MnoeCurrentUser.refresh().then(
->
_self.selected = response.plain()
_self.selectedId = _self.selected.organization.id
$cookies.put("#{MnoeCurrentUser.user.id}_dhb_ref_id", _self.selectedId)
)

# Add the new org in the menu
_self.selectedId = _self.selected.organization.id
MnoeCurrentUser.user.organizations.push(response.plain().organization)

response
)

Expand Down
65 changes: 65 additions & 0 deletions src/app/impac.config.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
angular.module 'mnoEnterpriseAngular'

#======================================================================================
# IMPAC-ROUTES: Configuring routes
#======================================================================================
.config((ImpacRoutesProvider, IMPAC_CONFIG) ->
mnoHub = IMPAC_CONFIG.paths.mnohub_api
impacPrefix = "/impac"

data =
mnoHub: mnoHub
impacPrefix: impacPrefix
impacApi: "#{IMPAC_CONFIG.protocol}://#{IMPAC_CONFIG.host}/api"
dashboards:
index: "#{mnoHub}#{impacPrefix}/dashboards"
widgets:
index: "#{mnoHub}#{impacPrefix}/widgets"
create: "#{mnoHub}#{impacPrefix}/dashboards/:dashboard_id/widgets"
kpis:
index: "#{mnoHub}#{impacPrefix}/kpis"
create: "#{mnoHub}#{impacPrefix}/dashboards/:dashboard_id/kpis"
update: "#{mnoHub}#{impacPrefix}/kpis/:id"
del: "#{mnoHub}#{impacPrefix}/kpis/:id"
alerts:
index: "#{mnoHub}#{impacPrefix}/alerts"
create: "#{mnoHub}#{impacPrefix}/kpis/:kpi_id/alerts"
del: "#{mnoHub}#{impacPrefix}/alerts/:id"

ImpacRoutesProvider.configureRoutes(data)
)

#======================================================================================
# IMPAC-THEMING: Configuring colour theme, layout, labels, descriptions, and features
#======================================================================================
.config((ImpacThemingProvider) ->
options =
dataNotFoundConfig:
linkUrl: '#/marketplace'
dhbErrorsConfig:
firstTimeCreated:
note: ''

ImpacThemingProvider.configure(options)
)

#======================================================================================
# IMPAC-ASSETS: Configuring assets
#======================================================================================
.config((ImpacAssetsProvider) ->
options =
defaultImagesPath: '/dashboard/images'

ImpacAssetsProvider.configure(options)
)

#======================================================================================
# IMPAC-LINKING: Configuring linking
#======================================================================================
.run((ImpacLinking, ImpacConfigSvc) ->
data =
user: ImpacConfigSvc.getUserData
organizations: ImpacConfigSvc.getOrganizations

ImpacLinking.linkData(data)
)
52 changes: 0 additions & 52 deletions src/app/index.config.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -59,55 +59,3 @@ angular.module 'mnoEnterpriseAngular'
$translateProvider.useSanitizeValueStrategy('sanitizeParameters')
$translateProvider.useMissingTranslationHandlerLog()
)

#======================================================================================
# IMPAC-ROUTES: Configuring routes
#======================================================================================
.config (ImpacRoutesProvider, IMPAC_CONFIG) ->
mnoHub = IMPAC_CONFIG.paths.mnohub_api
impacPrefix = "/impac"

data =
mnoHub: mnoHub
impacPrefix: impacPrefix
impacApi: "#{IMPAC_CONFIG.protocol}://#{IMPAC_CONFIG.host}/api"
dashboards:
index: "#{mnoHub}#{impacPrefix}/dashboards"
widgets:
index: "#{mnoHub}#{impacPrefix}/widgets"
create: "#{mnoHub}#{impacPrefix}/dashboards/:dashboard_id/widgets"
kpis:
index: "#{mnoHub}#{impacPrefix}/kpis"
create: "#{mnoHub}#{impacPrefix}/dashboards/:dashboard_id/kpis"
update: "#{mnoHub}#{impacPrefix}/kpis/:id"
del: "#{mnoHub}#{impacPrefix}/kpis/:id"
alerts:
index: "#{mnoHub}#{impacPrefix}/alerts"
create: "#{mnoHub}#{impacPrefix}/kpis/:kpi_id/alerts"
del: "#{mnoHub}#{impacPrefix}/alerts/:id"

ImpacRoutesProvider.configureRoutes(data)


#======================================================================================
# IMPAC-THEMING: Configuring colour theme, layout, labels, descriptions, and features
#======================================================================================
.config (ImpacThemingProvider) ->
options =
dataNotFoundConfig:
linkUrl: '#/marketplace'
dhbErrorsConfig:
firstTimeCreated:
note: ''

ImpacThemingProvider.configure(options)

#======================================================================================
# IMPAC-ASSETS: Configuring assests
#======================================================================================
.config (ImpacAssetsProvider) ->
options =
defaultImagesPath: '/dashboard/images'

ImpacAssetsProvider.configure(options)

8 changes: 0 additions & 8 deletions src/app/index.run.coffee
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
angular.module 'mnoEnterpriseAngular'
# Impac configuration
.run((ImpacLinking, ImpacConfigSvc) ->
data =
user: ImpacConfigSvc.getUserData
organizations: ImpacConfigSvc.getOrganizations

ImpacLinking.linkData(data)
)

# xeditable-anugular configuration
.run((editableOptions) ->
Expand Down
2 changes: 1 addition & 1 deletion src/app/views/impac/impac.controller.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ angular.module 'mnoEnterpriseAngular'
if MnoeOrganizations.role.atLeastAdmin(selectedOrg.current_user_role)
# Display impac! and force it to reload if necessary
vm.isImpacShown = true
ImpacDashboardsSvc.reload(true) if newValue? && oldValue? && newValue != oldValue
ImpacDashboardsSvc.reload(true) if newValue? && oldValue? && parseInt(newValue) != parseInt(oldValue)
else
$state.go('home.apps')
) if newValue?
Expand Down
12 changes: 7 additions & 5 deletions src/app/views/layout.controller.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ angular.module 'mnoEnterpriseAngular'
$scope.$watch(MnoeOrganizations.getSelectedId, (newValue) ->
MnoeCurrentUser.get().then(
(response) ->
selectedOrg = _.find(response.organizations, {id: parseInt(newValue)})
if MnoeOrganizations.role.atLeastAdmin(selectedOrg.current_user_role)
$state.go('home.impac')
else
$state.go('home.apps')
# We only check the role for those states
if $state.is('home.impac') || $state.is('home.apps')
selectedOrg = _.find(response.organizations, {id: parseInt(newValue)})
if MnoeOrganizations.role.atLeastAdmin(selectedOrg.current_user_role)
$state.go('home.impac')
else
$state.go('home.apps')
) if newValue?
)

Expand Down

0 comments on commit a0fa100

Please sign in to comment.