- '$http',
- 'Sdc.Services.CacheService',
- 'Sdc.Services.CookieService',
- 'Sdc.Services.ConfigurationUiService',
- 'Sdc.Services.UserResourceService',
- 'Sdc.Services.CategoryResourceService',
- 'Sdc.Services.SdcVersionService',
- '$state',
- '$rootScope',
- '$location',
- 'sdcMenu',
- 'ModalsHandler',
- 'Sdc.Services.EcompHeaderService',
- 'LeftPaletteLoaderService',
- 'Sdc.Services.DataTypesService',
- 'AngularJSBridge',
- ($http:ng.IHttpService,
- cacheService:CacheService,
- cookieService:CookieService,
- ConfigurationUi:ConfigurationUiService,
- UserResourceClass:IUserResourceClass,
- categoryResourceService:ICategoryResourceClass,
- sdcVersionService:SdcVersionService,
- $state:ng.ui.IStateService,
- $rootScope:ng.IRootScopeService,
- $location:ng.ILocationService,
- sdcMenu:IAppMenu,
- ModalsHandler:ModalsHandler,
- ecompHeaderService:EcompHeaderService,
- LeftPaletteLoaderService:LeftPaletteLoaderService,
- DataTypesService:DataTypesService,
- AngularJSBridge):void => {
-
- //handle cache data - version
- let initAsdcVersion:Function = ():void => {
-
- let onFailed = (response) => {
- console.info('onFailed initAsdcVersion', response);
- cacheService.set('version', 'N/A');
- };
-
- let onSuccess = (version:any) => {
- let tmpVerArray = version.version.split(".");
- let ver = tmpVerArray[0] + "." + tmpVerArray[1] + "." + tmpVerArray[2];
- cacheService.set('version', ver);
- };
-
- sdcVersionService.getVersion().then(onSuccess, onFailed);
-
- };
-
- let initEcompMenu:Function = (user):void => {
- ecompHeaderService.getMenuItems(user.userId).then((data)=> {
- $rootScope['menuItems'] = data;
- });
- };
-
- let initConfigurationUi:Function = ():void => {
- ConfigurationUi
- .getConfigurationUi()
- .then((configurationUi:any) => {
- cacheService.set('UIConfiguration', configurationUi);
- });
- };
-
- let initCategories:Function = ():void => {
- let onError = ():void => {
- console.log('Failed to init categories');
- };
-
- categoryResourceService.getAllCategories((categories: Categories):void => {
- cacheService.set('serviceCategories', categories.serviceCategories);
- cacheService.set('resourceCategories', categories.resourceCategories);
- cacheService.set('productCategories', categories.productCategories);
- }, onError);
- };
-
- // Add hosted applications to sdcConfig
- sdcConfig.hostedApplications = hostedApplications;
-
- //handle http config
- $http.defaults.withCredentials = true;
- $http.defaults.headers.common.Authorization = 'Basic YmVlcDpib29w';
- $http.defaults.headers.common[cookieService.getUserIdSuffix()] = cookieService.getUserId();
-
- initAsdcVersion();
- initConfigurationUi();
- // initLeftPalette();
- DataTypesService.initDataTypes();
-
- //handle stateChangeStart
- let internalDeregisterStateChangeStartWatcher:Function = ():void => {
- if (deregisterStateChangeStartWatcher) {
- deregisterStateChangeStartWatcher();
- deregisterStateChangeStartWatcher = null;
- }
- };
-
- let removeLoader:Function = ():void => {
- $(".sdc-loading-page .main-loader").addClass("animated fadeOut");
- $(".sdc-loading-page .caption1").addClass("animated fadeOut");
- $(".sdc-loading-page .caption2").addClass("animated fadeOut");
- window.setTimeout(():void=> {
- $(".sdc-loading-page .main-loader").css("display", "none");
- $(".sdc-loading-page .caption1").css("display", "none");
- $(".sdc-loading-page .caption2").css("display", "none");
- $(".sdc-loading-page").addClass("animated fadeOut");
- }, 1000);
- };
-
- let onNavigateOut:Function = (toState, toParams):void => {
- let onOk = ():void => {
- $state.current.data.unsavedChanges = false;
+ '$http',
+ 'Sdc.Services.CacheService',
+ 'Sdc.Services.CookieService',
+ 'AuthenticationServiceNg2',
+ '$state',
+ '$rootScope',
+ '$location',
+ 'sdcMenu',
+ 'Sdc.Services.EcompHeaderService',
+ 'LeftPaletteLoaderService',
+ 'Sdc.Services.DataTypesService',
+ 'AngularJSBridge',
+ '$templateCache',
+ 'ModalServiceSdcUI',
+ ($http: ng.IHttpService,
+ cacheService: CacheService,
+ cookieService: CookieService,
+ authService: AuthenticationService,
+ $state: ng.ui.IStateService,
+ $rootScope: ng.IRootScopeService,
+ $location: ng.ILocationService,
+ sdcMenu: IAppMenu,
+ ecompHeaderService: EcompHeaderService,
+ LeftPaletteLoaderService: LeftPaletteLoaderService,
+ DataTypesService: DataTypesService,
+ AngularJSBridge,
+ $templateCache: ng.ITemplateCacheService,
+ ModalServiceSdcUI: SdcUiServices.ModalService): void => {
+ $templateCache.put('notification-custom-template.html', require('./view-models/shared/notification-custom-template.html'));
+ $templateCache.put('notification-custom-template.html', require('./view-models/shared/notification-custom-template.html'));
+
+ // Add hosted applications to sdcConfig
+ sdcConfig.hostedApplications = hostedApplications;
+
+ // handle http config
+ $http.defaults.withCredentials = true;
+ $http.defaults.headers.common[cookieService.getUserIdSuffix()] = cookieService.getUserId();
+
+ DataTypesService.loadDataTypesCache(null);
+
+ // handle stateChangeStart
+ const internalDeregisterStateChangeStartWatcher: Function = (): void => {
+ if (deregisterStateChangeStartWatcher) {
+ deregisterStateChangeStartWatcher();
+ deregisterStateChangeStartWatcher = null;
+ }
+ if (deregisterStateChangeSuccessWatcher) {
+ deregisterStateChangeSuccessWatcher();
+ deregisterStateChangeSuccessWatcher = null;
+ }
+ };
+
+ const removeLoader: Function = (): void => {
+ $('.sdc-loading-page .main-loader').addClass('animated fadeOut');
+ $('.sdc-loading-page .caption1').addClass('animated fadeOut');
+ $('.sdc-loading-page .caption2').addClass('animated fadeOut');
+ window.setTimeout((): void => {
+ $('.sdc-loading-page .main-loader').css('display', 'none');
+ $('.sdc-loading-page .caption1').css('display', 'none');
+ $('.sdc-loading-page .caption2').css('display', 'none');
+ $('.sdc-loading-page').addClass('animated fadeOut');
+ }, 1000);
+ };
+
+ const onNavigateOut: Function = (toState, toParams): void => {
+ const onOk: Function = (): void => {
+ $state.current.data.unsavedChanges = false;
+ $state.go(toState.name, toParams);
+ };
+
+ const data = sdcMenu.alertMessages.exitWithoutSaving;
+ const okButton = {
+ testId: 'OK',
+ text: sdcMenu.alertMessages.okButton,
+ type: SdcUiCommon.ButtonType.warning,
+ callback: onOk,
+ closeModal: true
+ } as SdcUiComponents.ModalButtonComponent;
+ // open notify to user if changes are not saved
+ ModalServiceSdcUI.openWarningModal(data.title,
+ data.message,
+ 'navigate-modal',
+ [okButton]);
+ };
+
+ const onStateChangeStart: Function = (event, toState, toParams, fromState, fromParams): void => {
+ console.debug((new Date()).getTime());
+ console.debug('$stateChangeStart', toState.name);
+ if (toState.name !== 'error-403' && !authService.getLoggedinUser()) {
+
+ authService.authenticate().subscribe((userInfo: IUserProperties) => {
+ if (!doesUserHasAccess(toState, userInfo)) {
+ $state.go('error-403');
+ console.debug('User has no permissions');
+ return;
+ }
+ authService.setLoggedinUser(userInfo);
+ setTimeout(function() {
+
+ removeLoader();
+
+ if (authService.getLoggedinUser().role === 'ADMIN') {
+ $state.go('adminDashboard', toParams);
+ return;
+ }
+
+ // After user authorized init categories
+ window.setTimeout((): void => {
+ if ($state.current.name === '') {