diff --git a/src/app/components/dashboard-company-selectbox/dashboard-company-selectbox.coffee b/src/app/components/dashboard-company-selectbox/dashboard-company-selectbox.coffee index 388c936c..7c5bec95 100644 --- a/src/app/components/dashboard-company-selectbox/dashboard-company-selectbox.coffee +++ b/src/app/components/dashboard-company-selectbox/dashboard-company-selectbox.coffee @@ -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' #==================================== @@ -31,10 +31,6 @@ DashboardCompanySelectboxCtrl = ($scope, $location, $stateParams, $cookies, $sce selectBox.close = -> selectBox.isClosed = true - selectBox.createNewOrga = -> - newOrgModal.open() - selectBox.close() - #==================================== # Create Company Modal #==================================== @@ -48,6 +44,7 @@ DashboardCompanySelectboxCtrl = ($scope, $location, $stateParams, $cookies, $sce modalInstance.result.then( (selectedItem) -> selectBox.changeTo(selectedItem) + $state.go('home.impac') ) #==================================== diff --git a/src/app/components/mnoe-api/organizations.svc.coffee b/src/app/components/mnoe-api/organizations.svc.coffee index 7116f219..d5b9ee9f 100644 --- a/src/app/components/mnoe-api/organizations.svc.coffee +++ b/src/app/components/mnoe-api/organizations.svc.coffee @@ -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 ) diff --git a/src/app/impac.config.coffee b/src/app/impac.config.coffee new file mode 100644 index 00000000..6be3ed6e --- /dev/null +++ b/src/app/impac.config.coffee @@ -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) +) diff --git a/src/app/index.config.coffee b/src/app/index.config.coffee index 9315c74c..ef41675c 100644 --- a/src/app/index.config.coffee +++ b/src/app/index.config.coffee @@ -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) - diff --git a/src/app/index.run.coffee b/src/app/index.run.coffee index 17d4d711..7366c140 100644 --- a/src/app/index.run.coffee +++ b/src/app/index.run.coffee @@ -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) -> diff --git a/src/app/views/impac/impac.controller.coffee b/src/app/views/impac/impac.controller.coffee index 653eaeff..06be25d4 100644 --- a/src/app/views/impac/impac.controller.coffee +++ b/src/app/views/impac/impac.controller.coffee @@ -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? diff --git a/src/app/views/layout.controller.coffee b/src/app/views/layout.controller.coffee index e9136771..5bab3679 100644 --- a/src/app/views/layout.controller.coffee +++ b/src/app/views/layout.controller.coffee @@ -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? )