Преглед на файлове

AMBARI-7744 Admin View: include Views icon in header and link to /#/main/views in web. (Levgen Gorbachev via ababiichuk)

ababiichuk преди 10 години
родител
ревизия
ffb8e3fa01

+ 9 - 0
ambari-admin/src/main/resources/ui/admin-web/app/index.html

@@ -50,6 +50,15 @@
             <a href="#/" class="logo"><img src="/img/logo-white.png" alt="Apache Ambari" title="Apache Ambari"></a>
             <a href="#/" class="brand" title="Apache Ambari">Ambari</a>
             <ul class="nav navbar-nav navbar-right">
+              <li>
+                <div class="btn-group navbar-views-dropdown" dropdown is-open="viewsdropdown.isopen" ng-mouseover="viewsdropdown.isopen=true" ng-mouseout="viewsdropdown.isopen=false">
+                  <a href="/#/main/views" ng-click="gotoViewsDashboard()" class="dropdown-toggle"><i class="fa fa-th"></i></a>
+                  <ul class="dropdown-menu" role="menu">
+                    <li ng-repeat="instance in viewInstances"><a href="/#/main{{instance.context_path}}" ng-click="about()">{{instance.label}}</a></li>
+                    <li ng-show="!viewInstances.length" class="disabled"><a>No Views</a></li>
+                  </ul>
+                </div>
+              </li>
               <li>
                 <div class="btn-group" dropdown is-open="status.isopen">
                   <button type="button" class="btn btn-default dropdown-toggle navbar-btn" ng-disabled="disabled">

+ 10 - 1
ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/mainCtrl.js

@@ -18,7 +18,7 @@
 'use strict';
 
 angular.module('ambariAdminConsole')
-.controller('MainCtrl',['$scope', '$window','Auth', 'Alert', '$modal', 'Cluster', function($scope, $window, Auth, Alert, $modal, Cluster) {
+.controller('MainCtrl',['$scope', '$window','Auth', 'Alert', '$modal', 'Cluster', 'View', function($scope, $window, Auth, Alert, $modal, Cluster, View) {
   $scope.signOut = function() {
     var data = JSON.parse(localStorage.ambari);
     delete data.app.authenticated;
@@ -53,4 +53,13 @@ angular.module('ambariAdminConsole')
     Alert.error('Check cluster status error', data.data.message);
   });
 
+  $scope.viewInstances = [];
+  View.getAllVisibleInstance().then(function(instances) {
+    $scope.viewInstances = instances;
+  });
+
+  $scope.gotoViewsDashboard =function() {
+    window.location = '/#/main/views';
+  };
+
 }]);

+ 25 - 0
ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/View.js

@@ -251,6 +251,31 @@ angular.module('ambariAdminConsole')
     return deferred;
   };
 
+  View.getAllVisibleInstance = function() {
+    var deferred = $q.defer();
+    $http({
+      method: 'GET',
+      url: Settings.baseUrl + '/views',
+      params:{
+        'fields': 'versions/instances/ViewInstanceInfo',
+        'versions/ViewVersionInfo/system': false,
+        'versions/instances/ViewInstanceInfo/visible': true
+      }
+    }).then(function(data) {
+      var instances = [];
+      data.data.items.forEach(function(view) {
+        view.versions.forEach(function(version) {
+          version.instances.forEach(function(instance) {
+            instances.push(instance.ViewInstanceInfo);
+          });
+        })
+      });
+      deferred.resolve(instances);
+    });
+
+    return deferred.promise;
+  };
+
   View.all = function() {
     var deferred = $q.defer();
     var fields = [

+ 29 - 0
ambari-admin/src/main/resources/ui/admin-web/app/styles/main.css

@@ -395,6 +395,35 @@ a.gotoinstance{
 /*
   Style topnav menu
 */
+.navbar-views-dropdown > a{
+  color: #c3c3c3;
+  font-size: 1.3em;
+  padding: 10px 25px 18px;
+  display: block;
+  box-shadow: none!important;
+  background: none!important;
+  text-decoration: none;
+}
+.navbar-views-dropdown > a:hover{
+  color: #fff;
+}
+.navbar-views-dropdown > a > i{
+  display: block;
+  margin-top: 1px;
+  margin-bottom: -12px;
+}
+.navbar-views-dropdown .dropdown-menu{
+  margin-top: -2px;
+}
+
+.navbar-views-dropdown .dropdown-menu a:hover{
+  background: #666;
+  color: #fff;
+}
+.navbar-views-dropdown .dropdown-menu .disabled a:hover{
+  background: none;
+  color: #999;
+}
 #top-nav .navbar.navbar-static-top{
   min-height: 40px;
 }

+ 56 - 1
ambari-admin/src/main/resources/ui/admin-web/test/unit/controllers/mainCtrl_test.js

@@ -36,6 +36,54 @@ describe('#Auth', function () {
       $window = _$window_;
       $httpBackend = _$httpBackend_;
       $httpBackend.whenGET('/api/v1/logout').respond(200,{message: "successfully logged out"});
+      $httpBackend.whenGET('/api/v1/views?fields=versions%2Finstances%2FViewInstanceInfo&versions%2FViewVersionInfo%2Fsystem=false&versions%2Finstances%2FViewInstanceInfo%2Fvisible=true')
+        .respond(200,{
+          "href": "http://c6401.ambari.apache.org:8080/api/v1/views?fields=versions/instances/ViewInstanceInfo&versions/ViewVersionInfo/system=false&versions/instances/ViewInstanceInfo/visible=true",
+          "items": [
+            {
+              "ViewInfo": {
+                "view_name": "SLIDER"
+              },
+              "href": "http://c6401.ambari.apache.org:8080/api/v1/views/SLIDER",
+              "versions": [
+                {
+                  "ViewVersionInfo": {
+                    "system": false,
+                    "version": "1.0.0",
+                    "view_name": "SLIDER"
+                  },
+                  "href": "http://c6401.ambari.apache.org:8080/api/v1/views/SLIDER/versions/1.0.0",
+                  "instances": [
+                    {
+                      "ViewInstanceInfo": {
+                        "context_path": "/views/SLIDER/1.0.0/VisibleInstance",
+                        "description": "VisibleInstance",
+                        "icon64_path": null,
+                        "icon_path": null,
+                        "instance_data": {},
+                        "instance_name": "VisibleInstance",
+                        "label": "VisibleInstance",
+                        "properties": {
+                          "ambari.server.password": "123",
+                          "ambari.server.url": "123",
+                          "ambari.server.username": "123",
+                          "slider.user": null,
+                          "view.kerberos.principal": null,
+                          "view.kerberos.principal.keytab": null
+                        },
+                        "static": false,
+                        "version": "1.0.0",
+                        "view_name": "SLIDER",
+                        "visible": true
+                      },
+                      "href": "http://c6401.ambari.apache.org:8080/api/v1/views/SLIDER/versions/1.0.0/instances/VisibleInstance"
+                    }
+                  ]
+                }
+              ]
+            }
+          ]
+        });
       scope = $rootScope.$new();
       scope.$apply();
       ctrl = $controller('MainCtrl', {$scope: scope});
@@ -43,12 +91,19 @@ describe('#Auth', function () {
 
     it('should reset window.location and ambari localstorage', function () {
       scope.signOut();
-      $httpBackend.flush();
       chai.expect($window.location.pathname).to.be.empty;
       var data = JSON.parse(localStorage.ambari);
       chai.expect(data.app.authenticated).to.equal(undefined);
       chai.expect(data.app.loginName).to.equal(undefined);
       chai.expect(data.app.user).to.equal(undefined);
+      $httpBackend.flush();
+    });
+
+    it('should get visible view instances and show them in top nav menu', function() {
+      $httpBackend.flush();
+
+      chai.expect(scope.viewInstances.length).to.equal(1);
+      chai.expect(scope.viewInstances[0].instance_name).to.equal('VisibleInstance');
     });
   });
 });