]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/dashboard_v2: Add cdPasswordButton directive
authorVolker Theile <vtheile@suse.com>
Tue, 6 Feb 2018 11:02:50 +0000 (12:02 +0100)
committerRicardo Dias <rdias@suse.com>
Mon, 5 Mar 2018 13:07:08 +0000 (13:07 +0000)
Signed-off-by: Volker Theile <vtheile@suse.com>
src/pybind/mgr/dashboard_v2/frontend/src/app/core/auth/auth.module.ts
src/pybind/mgr/dashboard_v2/frontend/src/app/core/auth/login/login.component.html
src/pybind/mgr/dashboard_v2/frontend/src/app/core/auth/login/login.component.scss
src/pybind/mgr/dashboard_v2/frontend/src/app/shared/directives/password-button.directive.spec.ts [new file with mode: 0644]
src/pybind/mgr/dashboard_v2/frontend/src/app/shared/directives/password-button.directive.ts [new file with mode: 0644]
src/pybind/mgr/dashboard_v2/frontend/src/app/shared/shared.module.ts

index 924f164a3d70b1ee2c4c21793274a7aa1c780c14..e96b1b30b8f84546d3641fcb7edd77726fab8b91 100644 (file)
@@ -1,6 +1,7 @@
 import { CommonModule } from '@angular/common';
 import { NgModule } from '@angular/core';
 import { FormsModule } from '@angular/forms';
+import { SharedModule } from '../../shared/shared.module';
 
 import { LoginComponent } from './login/login.component';
 import { LogoutComponent } from './logout/logout.component';
@@ -8,7 +9,8 @@ import { LogoutComponent } from './logout/logout.component';
 @NgModule({
   imports: [
     CommonModule,
-    FormsModule
+    FormsModule,
+    SharedModule
   ],
   declarations: [LoginComponent, LogoutComponent],
   exports: [LogoutComponent]
index 96554e0b55a327db10692e6c634b0c3ab8349302..a535cd9fde42b4bfe9fbca9612d7f9f1da8dedea 100644 (file)
         <!-- Password -->
         <div class="form-group has-feedback"
              [ngClass]="{'has-error': (loginForm.submitted || password.dirty) && password.invalid}">
-          <input id="password"
-                 name="password"
-                 [(ngModel)]="model.password"
-                 #password="ngModel"
-                 type="password"
-                 placeholder="Enter your password..."
-                 class="form-control"
-                 required>
+          <div class="input-group">
+            <input id="password"
+                   name="password"
+                   [(ngModel)]="model.password"
+                   #password="ngModel"
+                   type="password"
+                   placeholder="Enter your password..."
+                   class="form-control"
+                   required>
+            <span class="input-group-btn">
+              <button type="button"
+                      class="btn btn-default btn-password"
+                      cdPasswordButton="password">
+              </button>
+            </span>
+          </div>
           <div class="help-block"
-               *ngIf="(loginForm.submitted || password.dirty) && password.invalid">Password is required</div>
+               *ngIf="(loginForm.submitted || password.dirty) && password.invalid">Password is required
+          </div>
         </div>
 
         <!-- Stay signed in -->
index d017d87f09a99e4ef685b235766ca2dda64471d4..1f77356d29670ffc1260ebae0d4c02f9f480d45b 100644 (file)
     margin-bottom: 30px;
   }
 
+  .btn-password,
   .form-control {
     color: #ececec;
     background-color: #555555;
   }
 
+  .btn-password:focus {
+    outline-color: #66afe9;
+  }
+
   .checkbox-primary input[type="checkbox"]:checked + label::before,
   .checkbox-primary input[type="radio"]:checked + label::before {
     background-color: $oa-color-blue;
diff --git a/src/pybind/mgr/dashboard_v2/frontend/src/app/shared/directives/password-button.directive.spec.ts b/src/pybind/mgr/dashboard_v2/frontend/src/app/shared/directives/password-button.directive.spec.ts
new file mode 100644 (file)
index 0000000..1fc8f9c
--- /dev/null
@@ -0,0 +1,8 @@
+import { PasswordButtonDirective } from './password-button.directive';
+
+describe('PasswordButtonDirective', () => {
+  it('should create an instance', () => {
+    const directive = new PasswordButtonDirective(null, null);
+    expect(directive).toBeTruthy();
+  });
+});
diff --git a/src/pybind/mgr/dashboard_v2/frontend/src/app/shared/directives/password-button.directive.ts b/src/pybind/mgr/dashboard_v2/frontend/src/app/shared/directives/password-button.directive.ts
new file mode 100644 (file)
index 0000000..b375ba2
--- /dev/null
@@ -0,0 +1,40 @@
+import { Directive, ElementRef, HostListener, Input, OnInit, Renderer2 } from '@angular/core';
+
+@Directive({
+  selector: '[cdPasswordButton]'
+})
+export class PasswordButtonDirective implements OnInit {
+  private inputElement: any;
+  private iElement: any;
+
+  @Input('cdPasswordButton') private cdPasswordButton: string;
+
+  constructor(private el: ElementRef, private renderer: Renderer2) { }
+
+  ngOnInit() {
+    this.inputElement = document.getElementById(this.cdPasswordButton);
+    this.iElement = this.renderer.createElement('i');
+    this.renderer.addClass(this.iElement, 'icon-prepend');
+    this.renderer.addClass(this.iElement, 'fa');
+    this.renderer.appendChild(this.el.nativeElement, this.iElement);
+    this.update();
+  }
+
+  private update() {
+    if (this.inputElement.type === 'text') {
+      this.renderer.removeClass(this.iElement, 'fa-eye');
+      this.renderer.addClass(this.iElement, 'fa-eye-slash');
+    } else {
+      this.renderer.removeClass(this.iElement, 'fa-eye-slash');
+      this.renderer.addClass(this.iElement, 'fa-eye');
+    }
+  }
+
+  @HostListener('click')
+  onClick() {
+    // Modify the type of the input field.
+    this.inputElement.type = (this.inputElement.type === 'password') ? 'text' : 'password';
+    // Update the button icon/tooltip.
+    this.update();
+  }
+}
index 766db6401d0aa1542f8ffa9c9ab4ed6dbcdb4356..e4cbc3b344da7c822121a13d1233b38af245fb55 100644 (file)
@@ -2,6 +2,7 @@ import { CommonModule } from '@angular/common';
 import { NgModule } from '@angular/core';
 
 import { ComponentsModule } from './components/components.module';
+import { PasswordButtonDirective } from './directives/password-button.directive';
 import { PipesModule } from './pipes/pipes.module';
 import { AuthGuardService } from './services/auth-guard.service';
 import { AuthStorageService } from './services/auth-storage.service';
@@ -18,8 +19,14 @@ import { ServicesModule } from './services/services.module';
     ComponentsModule,
     ServicesModule
   ],
-  exports: [PipesModule, ServicesModule],
-  declarations: [],
+  exports: [
+    PipesModule,
+    ServicesModule,
+    PasswordButtonDirective
+  ],
+  declarations: [
+    PasswordButtonDirective
+  ],
   providers: [
     AuthService,
     AuthStorageService,