Modify html label to support multi-language
[portal.git] / ecomp-portal-FE-common / client / app / views / header / header.controller.js
index f0a3117..e464048 100644 (file)
@@ -1,39 +1,83 @@
 /*-
- * ================================================================================
- * ECOMP Portal
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software except in compliance with the License.
  * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
+ *             http://www.apache.org/licenses/LICENSE-2.0
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- * ================================================================================
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *             https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ * 
  */
 'use strict';
 (function () {
        class HeaderCtrl {
-        constructor($log, $window, userProfileService, menusService, $scope, ECOMP_URL_REGEX, $cookies, $state,auditLogService,notificationService,ngDialog,$modal) {
-            this.firstName = '';
-            this.lastName = '';
-            this.$log = $log;
-            this.menusService = menusService;
-            this.$scope = $scope;
-            this.favoritesMenuItems = '';
-            $scope.favoriteItemsCount = 0;
-            $scope.favoritesMenuItems = '';
-            $scope.showFavorites = false;
-            $scope.emptyFavorites = false;
-            $scope.favoritesWindow = false;
-            $scope.notificationCount=0;
-            $scope.showNotification = true;
+    constructor($log, $window, $translate, translateService,userProfileService, menusService, $scope, ECOMP_URL_REGEX, $cookies, $state,auditLogService,notificationService,ngDialog,$modal) {
+      this.firstName = '';
+      this.lastName = '';
+      this.$log = $log;
+      this.menusService = menusService;
+      this.$scope = $scope;
+      this.favoritesMenuItems = '';
+      $scope.cur_lang = '';
+      $scope.langList = []
+      $scope.favoriteItemsCount = 0;
+      $scope.favoritesMenuItems = '';
+      $scope.showFavorites = false;
+      $scope.emptyFavorites = false;
+      $scope.favoritesWindow = false;
+      $scope.notificationCount=0;
+      $scope.showNotification = true;
+      // get all languages
+      var loginId = sessionStorage.getItem('userId')
+      translateService.getCurrentLang(loginId).then(res => {
+        $scope.cur_lang = res.languageAlias
+        $translate.use($scope.cur_lang);
+      })
+      translateService.getLangList().then(res => {
+        $scope.langList = res.languageList
+      })
+      // switch language
+      $scope.switching = function(lang) {
+        $translate.use(lang);
+        var langs = $scope.langList
+        var langId = ''
+        var selectedLang = langs.find(function(item) {
+          return item.languageAlias === lang;
+        });
+        langId = selectedLang.languageId
+        var loginId = sessionStorage.getItem('userId')
+        translateService.saveSelectedLang(loginId, {'languageId': langId}).then(res => {
+          window.location.reload();
+        })
+      }
+      $scope.cur_lang = $translate.use();
 
             $scope.hideMenus = false;
 
                  $scope.lastName = res.lastName;
                  $scope.loginSnippetEmail = res.email;
                  $scope.loginSnippetUserid = res.userId;
-                 $scope.lastLogin = res.last_login;
+                 $scope.lastLogin = Date.parse(res.last_login);
                 }).catch(err=> {
                  $log.error('HeaderCtrl::LoginSnippetCtrl: failed in getFunctionalMenuStaticInfo: ' + err);
                 });
     
     NotificationCtrl.$inject = ['$log', '$scope', '$cookies', '$timeout', 'sessionService','notificationService','$interval','ngDialog','$modal'];
     LoginSnippetCtrl.$inject = ['$log', '$scope', '$cookies', '$timeout','userProfileService', 'sessionService'];
-    HeaderCtrl.$inject = ['$log', '$window', 'userProfileService', 'menusService', '$scope', 'ECOMP_URL_REGEX','$cookies','$state','auditLogService','notificationService','ngDialog','$modal'];
+    HeaderCtrl.$inject = ['$log', '$window', '$translate', 'translateService', 'userProfileService', 'menusService', '$scope', 'ECOMP_URL_REGEX','$cookies','$state','auditLogService','notificationService','ngDialog','$modal'];
     angular.module('ecompApp').controller('HeaderCtrl', HeaderCtrl);
     angular.module('ecompApp').controller('loginSnippetCtrl', LoginSnippetCtrl);
     angular.module('ecompApp').controller('notificationCtrl', NotificationCtrl);