ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alejan...@apache.org
Subject git commit: AMBARI-7707. Admin View: Unable to create view instance on installer stage (alejandro)
Date Sat, 11 Oct 2014 03:15:40 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk effc64c1e -> b86e49abe


AMBARI-7707. Admin View: Unable to create view instance on installer stage (alejandro)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/b86e49ab
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/b86e49ab
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/b86e49ab

Branch: refs/heads/trunk
Commit: b86e49abe39fc8509c71913a830c420a77df181b
Parents: effc64c
Author: Alejandro Fernandez <afernandez@hortonworks.com>
Authored: Wed Oct 8 16:25:51 2014 -0700
Committer: Alejandro Fernandez <afernandez@hortonworks.com>
Committed: Fri Oct 10 20:14:18 2014 -0700

----------------------------------------------------------------------
 .../ambariViews/CreateViewInstanceCtrl.js       | 30 ++++-------
 .../admin-web/app/views/ambariViews/create.html | 22 ++++----
 .../app/views/ambariViews/modals/create.html    | 18 +++----
 .../unit/controllers/CreateViewInstanceCtrl.js  | 57 ++++++++++++++++++++
 4 files changed, 87 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/b86e49ab/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/ambariViews/CreateViewInstanceCtrl.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/ambariViews/CreateViewInstanceCtrl.js
b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/ambariViews/CreateViewInstanceCtrl.js
index bfabd59..a9c3268 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/ambariViews/CreateViewInstanceCtrl.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/ambariViews/CreateViewInstanceCtrl.js
@@ -73,26 +73,16 @@ angular.module('ambariAdminConsole')
   $scope.nameValidationPattern = /^\s*\w*\s*$/;
 
   $scope.save = function() {
-    $scope.form.isntanceCreateForm.submitted = true;
-    if($scope.form.isntanceCreateForm.$valid){
-      View.getInstance($scope.instance.view_name, $scope.instance.version, $scope.instance.instance_name)
-      .then(function(data) {
-        if (data.ViewInstanceInfo) {
-          $scope.instanceExists = true;
-        } else {
-          View.createInstance($scope.instance)
-          .then(function(data) {
-            Alert.success('Created View Instance ' + $scope.instance.instance_name);
-            $location.path('/views/' + $scope.instance.view_name + '/versions/' + $scope.instance.version
+ '/instances/' + $scope.instance.instance_name + '/edit');
-          })
-          .catch(function(data) {
-            Alert.error('Cannot create instance', data.data.message);
-          });
-        }
-      })
-      .catch(function(data) {
-        Alert.error('Cannot create instance', data.data.message);
-      });
+    $scope.form.instanceCreateForm.submitted = true;
+    if($scope.form.instanceCreateForm.$valid){
+      View.createInstance($scope.instance)
+        .then(function(data) {
+          Alert.success('Created View Instance ' + $scope.instance.instance_name);
+          $location.path('/views/' + $scope.instance.view_name + '/versions/' + $scope.instance.version
+ '/instances/' + $scope.instance.instance_name + '/edit');
+        })
+        .catch(function(data) {
+          Alert.error('Cannot create instance', data.data.message);
+        });
     }
   };
 }]);

http://git-wip-us.apache.org/repos/asf/ambari/blob/b86e49ab/ambari-admin/src/main/resources/ui/admin-web/app/views/ambariViews/create.html
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/views/ambariViews/create.html
b/ambari-admin/src/main/resources/ui/admin-web/app/views/ambariViews/create.html
index 4bf51ac..eafd7d0 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/views/ambariViews/create.html
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/views/ambariViews/create.html
@@ -20,7 +20,7 @@
   <li class="active">Create Instance</li>
 </ol>
 <hr>
-<form class="form-horizontal create-view-form" role="form" name="form.isntanceCreateForm"
novalidate>
+<form class="form-horizontal create-view-form" role="form" name="form.instanceCreateForm"
novalidate>
   <div class="view-header">
     <div class="form-group">
       <div class="col-sm-2">
@@ -42,16 +42,16 @@
     </div>
     <div class="panel-body">
       <div class="form-group" 
-      ng-class="{'has-error' : ( (form.isntanceCreateForm.instanceNameInput.$error.required
|| form.isntanceCreateForm.instanceNameInput.$error.pattern) && form.isntanceCreateForm.submitted)
|| instanceExists }"
+      ng-class="{'has-error' : ( (form.instanceCreateForm.instanceNameInput.$error.required
|| form.instanceCreateForm.instanceNameInput.$error.pattern) && form.instanceCreateForm.submitted)
|| instanceExists }"
       >
         <label for="" class="control-label col-sm-2">Instance Name</label>
         <div class="col-sm-10">
           <input type="text" class="form-control instancename-input" name="instanceNameInput"
ng-pattern="nameValidationPattern" required ng-model="instance.instance_name" autocomplete="off">
 
-          <div class="alert alert-danger no-margin-bottom top-margin" ng-show='form.isntanceCreateForm.instanceNameInput.$error.required
&& form.isntanceCreateForm.submitted'>
+          <div class="alert alert-danger no-margin-bottom top-margin" ng-show='form.instanceCreateForm.instanceNameInput.$error.required
&& form.instanceCreateForm.submitted'>
             This field is required.
           </div>
-          <div class="alert alert-danger no-margin-bottom top-margin" ng-show='form.isntanceCreateForm.instanceNameInput.$error.pattern
&& form.isntanceCreateForm.submitted'>
+          <div class="alert alert-danger no-margin-bottom top-margin" ng-show='form.instanceCreateForm.instanceNameInput.$error.pattern
&& form.instanceCreateForm.submitted'>
             Must not contain any special characters or spaces.
           </div>
           <div class="alert alert-danger no-margin-bottom top-margin" ng-show='instanceExists'>
@@ -60,24 +60,24 @@
         </div>
       </div>
       <div class="form-group"
-      ng-class="{'has-error' : ( (form.isntanceCreateForm.displayLabel.$error.required ||
form.isntanceCreateForm.displayLabel.$error.pattern) && form.isntanceCreateForm.submitted)}">
+      ng-class="{'has-error' : ( (form.instanceCreateForm.displayLabel.$error.required ||
form.instanceCreateForm.displayLabel.$error.pattern) && form.instanceCreateForm.submitted)}">
         <label for="" class="control-label col-sm-2">Display Name</label>
         <div class="col-sm-10">
           <input type="text" class="form-control instancelabel-input" name="displayLabel"
ng-model="instance.label" required ng-pattern="/^([a-zA-Z0-9._\s]+)$/" autocomplete="off">
 
-          <div class="alert alert-danger no-margin-bottom top-margin" ng-show='form.isntanceCreateForm.displayLabel.$error.required
&& form.isntanceCreateForm.submitted'>
+          <div class="alert alert-danger no-margin-bottom top-margin" ng-show='form.instanceCreateForm.displayLabel.$error.required
&& form.instanceCreateForm.submitted'>
             This field is required.
           </div>
-          <div class="alert alert-danger no-margin-bottom top-margin" ng-show='form.isntanceCreateForm.displayLabel.$error.pattern
&& form.isntanceCreateForm.submitted'>
+          <div class="alert alert-danger no-margin-bottom top-margin" ng-show='form.instanceCreateForm.displayLabel.$error.pattern
&& form.instanceCreateForm.submitted'>
             Must not contain any special characters.
           </div>
         </div>
       </div>
-      <div class="form-group" ng-class="{'has-error' : form.isntanceCreateForm.description.$error.required
&& form.isntanceCreateForm.submitted }">
+      <div class="form-group" ng-class="{'has-error' : form.instanceCreateForm.description.$error.required
&& form.instanceCreateForm.submitted }">
         <label for="" class="control-label col-sm-2">Description</label>
         <div class="col-sm-10">
           <input type="text" class="form-control" name="description" ng-model="instance.description"
maxlength="140" required>
-          <div class="alert alert-danger no-margin-bottom top-margin" ng-show='form.isntanceCreateForm.description.$error.required
&& form.isntanceCreateForm.submitted'>
+          <div class="alert alert-danger no-margin-bottom top-margin" ng-show='form.instanceCreateForm.description.$error.required
&& form.instanceCreateForm.submitted'>
             This field is required.
           </div>
         </div>
@@ -99,11 +99,11 @@
     </div>
     <div class="panel-body property-form">
       <div class="form-group" ng-repeat="parameter in instance.properties"
-        ng-class="{'has-error' : (form.isntanceCreateForm[parameter.name].$error.required
&& form.isntanceCreateForm.submitted)}" >
+        ng-class="{'has-error' : (form.instanceCreateForm[parameter.name].$error.required
&& form.instanceCreateForm.submitted)}" >
         <label for="" class="col-sm-3 control-label" ng-class="{'not-required': !parameter.required}"
tooltip="{{parameter.description}}">{{parameter.name}}{{parameter.required ? '*' : ''}}</label>
         <div class="col-sm-9">
           <input type="{{parameter.masked ? 'password' : 'text'}}" class="form-control
viewproperty-input"  name="{{parameter.name}}" ng-required="parameter.required" ng-model="parameter.value"
autocomplete="off" tooltip="{{parameter.description}}">
-          <div class="alert alert-danger no-margin-bottom top-margin" ng-show='form.isntanceCreateForm[parameter.name].$error.required
&& form.isntanceCreateForm.submitted'>
+          <div class="alert alert-danger no-margin-bottom top-margin" ng-show='form.instanceCreateForm[parameter.name].$error.required
&& form.instanceCreateForm.submitted'>
             This field is required.
           </div>
         </div>

http://git-wip-us.apache.org/repos/asf/ambari/blob/b86e49ab/ambari-admin/src/main/resources/ui/admin-web/app/views/ambariViews/modals/create.html
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/views/ambariViews/modals/create.html
b/ambari-admin/src/main/resources/ui/admin-web/app/views/ambariViews/modals/create.html
index 9b15f44..cd4e958 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/views/ambariViews/modals/create.html
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/views/ambariViews/modals/create.html
@@ -15,7 +15,7 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 -->
-<form class="form-horizontal" role="form" name="form.isntanceCreateForm" novalidate>
+<form class="form-horizontal" role="form" name="form.instanceCreateForm" novalidate>
 <div class="modal-header">
   <h3 class="modal-title">Create View Instance</h3>
 </div>
@@ -35,16 +35,16 @@
       </div>
       <div class="panel-body">
         <div class="form-group" 
-        ng-class="{'has-error' : ( (form.isntanceCreateForm.instanceNameInput.$error.required
|| form.isntanceCreateForm.instanceNameInput.$error.pattern) && form.isntanceCreateForm.submitted)
|| instanceExists }"
+        ng-class="{'has-error' : ( (form.instanceCreateForm.instanceNameInput.$error.required
|| form.instanceCreateForm.instanceNameInput.$error.pattern) && form.instanceCreateForm.submitted)
|| instanceExists }"
         >
           <label for="" class="control-labe col-sm-2">Instance name</label>
           <div class="col-sm-10">
             <input type="text" class="form-control" name="instanceNameInput" ng-pattern="nameValidationPattern"
required ng-model="instance.instance_name">
 
-            <div class="alert alert-danger no-margin-bottom top-margin" ng-show='form.isntanceCreateForm.instanceNameInput.$error.required
&& form.isntanceCreateForm.submitted'>
+            <div class="alert alert-danger no-margin-bottom top-margin" ng-show='form.instanceCreateForm.instanceNameInput.$error.required
&& form.instanceCreateForm.submitted'>
               Field requried!
             </div>
-            <div class="alert alert-danger no-margin-bottom top-margin" ng-show='form.isntanceCreateForm.instanceNameInput.$error.pattern
&& form.isntanceCreateForm.submitted'>
+            <div class="alert alert-danger no-margin-bottom top-margin" ng-show='form.instanceCreateForm.instanceNameInput.$error.pattern
&& form.instanceCreateForm.submitted'>
               Must no contain special characters!
             </div>
             <div class="alert alert-danger no-margin-bottom top-margin" ng-show='instanceExists'>
@@ -53,15 +53,15 @@
           </div>
         </div>
         <div class="form-group"
-        ng-class="{'has-error' : ( (form.isntanceCreateForm.displayLabel.$error.required
|| form.isntanceCreateForm.displayLabel.$error.pattern) && form.isntanceCreateForm.submitted)}">
+        ng-class="{'has-error' : ( (form.instanceCreateForm.displayLabel.$error.required
|| form.instanceCreateForm.displayLabel.$error.pattern) && form.instanceCreateForm.submitted)}">
           <label for="" class="control-labe col-sm-2">Display label</label>
           <div class="col-sm-10">
             <input type="text" class="form-control" name="displayLabel" ng-model="instance.label"
required ng-pattern="nameValidationPattern">
 
-            <div class="alert alert-danger no-margin-bottom top-margin" ng-show='form.isntanceCreateForm.displayLabel.$error.required
&& form.isntanceCreateForm.submitted'>
+            <div class="alert alert-danger no-margin-bottom top-margin" ng-show='form.instanceCreateForm.displayLabel.$error.required
&& form.instanceCreateForm.submitted'>
               Field requried!
             </div>
-            <div class="alert alert-danger no-margin-bottom top-margin" ng-show='form.isntanceCreateForm.displayLabel.$error.pattern
&& form.isntanceCreateForm.submitted'>
+            <div class="alert alert-danger no-margin-bottom top-margin" ng-show='form.instanceCreateForm.displayLabel.$error.pattern
&& form.instanceCreateForm.submitted'>
               Must no contain special characters!
             </div>
           </div>
@@ -107,11 +107,11 @@
       </div>
       <div class="panel-body">
       <div class="form-group" ng-repeat="parameter in instance.properties"
-        ng-class="{'has-error' : (form.isntanceCreateForm[parameter.name].$error.required
&& form.isntanceCreateForm.submitted)}" >
+        ng-class="{'has-error' : (form.instanceCreateForm[parameter.name].$error.required
&& form.instanceCreateForm.submitted)}" >
         <label for="" class="col-sm-3 control-label">{{parameter.description}}</label>
         <div class="col-sm-9">
           <input type="text" class="form-control"  name="{{parameter.name}}" ng-required="parameter.required"
ng-model="parameter.value">
-          <div class="alert alert-danger no-margin-bottom top-margin" ng-show='form.isntanceCreateForm[parameter.name].$error.required
&& form.isntanceCreateForm.submitted'>
+          <div class="alert alert-danger no-margin-bottom top-margin" ng-show='form.instanceCreateForm[parameter.name].$error.required
&& form.instanceCreateForm.submitted'>
             Field requried!
           </div>
         </div>

http://git-wip-us.apache.org/repos/asf/ambari/blob/b86e49ab/ambari-admin/src/main/resources/ui/admin-web/test/unit/controllers/CreateViewInstanceCtrl.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/test/unit/controllers/CreateViewInstanceCtrl.js
b/ambari-admin/src/main/resources/ui/admin-web/test/unit/controllers/CreateViewInstanceCtrl.js
new file mode 100644
index 0000000..c5a7d67
--- /dev/null
+++ b/ambari-admin/src/main/resources/ui/admin-web/test/unit/controllers/CreateViewInstanceCtrl.js
@@ -0,0 +1,57 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     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.
+ */
+
+describe('#CreateViewInstanceCtrl', function () {
+  var scope, ctrl, $httpBackend, View;
+  
+  beforeEach(module('ambariAdminConsole', function($provide){
+    $provide.value('$routeParams', {viewId: 'TestView'});
+  }));
+
+  afterEach(function() {
+    $httpBackend.verifyNoOutstandingExpectation();
+    $httpBackend.verifyNoOutstandingRequest();
+  });
+
+  beforeEach(inject(function (_$httpBackend_, $rootScope, $controller, _View_, $q) {
+    View = _View_;
+    spyOn(View, 'createInstance').andReturn($q.defer().promise);
+
+    $httpBackend = _$httpBackend_;
+    $httpBackend.whenGET('/api/v1/views/TestView?versions/ViewVersionInfo/status=DEPLOYED').respond(200,
{
+      "versions": [{"ViewVersionInfo": {}}]
+    });
+    $httpBackend.whenGET('/api/v1/views/TestView/versions/1.0.0').respond(200, {
+      "ViewVersionInfo": {}
+    });
+    scope = $rootScope.$new();
+    ctrl = $controller('CreateViewInstanceCtrl', {$scope: scope});
+  }));
+
+  it('it should invoke View.createInstance on save', function () {
+    scope.form = {
+      instanceCreateForm: {
+        submitted: false,
+        $valid: true
+      }
+    };
+    $httpBackend.flush();
+    scope.save();
+    expect(View.createInstance).toHaveBeenCalled();
+  });  
+});
\ No newline at end of file


Mime
View raw message