1
0
mirror of https://github.com/bitwarden/desktop.git synced 2024-11-30 12:54:31 +01:00

set generated password from add/edit

This commit is contained in:
Kyle Spearrin 2018-01-29 16:33:38 -05:00
parent ce84e8e428
commit 40c5cfa10b
5 changed files with 30 additions and 2 deletions

View File

@ -4,7 +4,6 @@ import {
Component, Component,
ComponentFactoryResolver, ComponentFactoryResolver,
EventEmitter, EventEmitter,
Input,
OnDestroy, OnDestroy,
Output, Output,
Type, Type,
@ -17,6 +16,10 @@ import {
template: `<ng-template #container></ng-template>`, template: `<ng-template #container></ng-template>`,
}) })
export class ModalComponent implements OnDestroy { export class ModalComponent implements OnDestroy {
@Output() onClose = new EventEmitter();
@Output() onClosed = new EventEmitter();
@Output() onShow = new EventEmitter();
@Output() onShown = new EventEmitter();
@ViewChild('container', { read: ViewContainerRef }) container: ViewContainerRef; @ViewChild('container', { read: ViewContainerRef }) container: ViewContainerRef;
parentContainer: ViewContainerRef = null; parentContainer: ViewContainerRef = null;
fade: boolean = true; fade: boolean = true;
@ -29,6 +32,7 @@ export class ModalComponent implements OnDestroy {
} }
show<T>(type: Type<T>, parentContainer: ViewContainerRef, fade: boolean = true): T { show<T>(type: Type<T>, parentContainer: ViewContainerRef, fade: boolean = true): T {
this.onShow.emit();
this.parentContainer = parentContainer; this.parentContainer = parentContainer;
this.fade = fade; this.fade = fade;
@ -50,10 +54,13 @@ export class ModalComponent implements OnDestroy {
}); });
} }
this.onShown.emit();
return componentRef.instance; return componentRef.instance;
} }
close() { close() {
this.onClose.emit();
this.onClosed.emit();
if (this.parentContainer != null) { if (this.parentContainer != null) {
this.parentContainer.clear(); this.parentContainer.clear();
} }

View File

@ -175,6 +175,11 @@ export class AddEditComponent implements OnChanges {
} }
generatePassword() { generatePassword() {
if (this.cipher.login != null && this.cipher.login.password != null && this.cipher.login.password.length &&
!confirm(this.i18nService.t('overwritePasswordConfirmation'))) {
return;
}
this.onGeneratePassword.emit(); this.onGeneratePassword.emit();
} }
} }

View File

@ -68,7 +68,7 @@
</div> </div>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="primary" appBlurClick *ngIf="showSelect"> <button type="button" class="primary" appBlurClick *ngIf="showSelect" (click)="select()">
<i class="fa fa-lg fa-check"></i> {{'select' | i18n}} <i class="fa fa-lg fa-check"></i> {{'select' | i18n}}
</button> </button>
<button type="button" data-dismiss="modal">{{'close' | i18n}}</button> <button type="button" data-dismiss="modal">{{'close' | i18n}}</button>

View File

@ -20,6 +20,7 @@ import { UtilsService } from 'jslib/abstractions/utils.service';
}) })
export class PasswordGeneratorComponent implements OnInit { export class PasswordGeneratorComponent implements OnInit {
@Input() showSelect: boolean = false; @Input() showSelect: boolean = false;
@Output() onSelected = new EventEmitter<string>();
options: any = {}; options: any = {};
password: string = '-'; password: string = '-';
@ -83,4 +84,9 @@ export class PasswordGeneratorComponent implements OnInit {
this.analytics.eventTrack.next({ action: 'Copied Generated Password' }); this.analytics.eventTrack.next({ action: 'Copied Generated Password' });
this.utilsService.copyToClipboard(this.password, window.document); this.utilsService.copyToClipboard(this.password, window.document);
} }
select() {
this.analytics.eventTrack.next({ action: 'Selected Generated Password' });
this.onSelected.emit(this.password);
}
} }

View File

@ -15,6 +15,7 @@ import {
import { Location } from '@angular/common'; import { Location } from '@angular/common';
import { AddEditComponent } from './add-edit.component';
import { CiphersComponent } from './ciphers.component'; import { CiphersComponent } from './ciphers.component';
import { GroupingsComponent } from './groupings.component'; import { GroupingsComponent } from './groupings.component';
import { PasswordGeneratorComponent } from './password-generator.component'; import { PasswordGeneratorComponent } from './password-generator.component';
@ -31,6 +32,7 @@ import { FolderView } from 'jslib/models/view/folderView';
template: template, template: template,
}) })
export class VaultComponent implements OnInit { export class VaultComponent implements OnInit {
@ViewChild(AddEditComponent) addEditComponent: AddEditComponent;
@ViewChild(CiphersComponent) ciphersComponent: CiphersComponent; @ViewChild(CiphersComponent) ciphersComponent: CiphersComponent;
@ViewChild(GroupingsComponent) groupingsComponent: GroupingsComponent; @ViewChild(GroupingsComponent) groupingsComponent: GroupingsComponent;
@ViewChild('passwordGenerator', { read: ViewContainerRef }) passwordGeneratorModal: ViewContainerRef; @ViewChild('passwordGenerator', { read: ViewContainerRef }) passwordGeneratorModal: ViewContainerRef;
@ -176,7 +178,15 @@ export class VaultComponent implements OnInit {
let modal = componentRef.instance as ModalComponent; let modal = componentRef.instance as ModalComponent;
let childComponent = modal.show<PasswordGeneratorComponent>(PasswordGeneratorComponent, let childComponent = modal.show<PasswordGeneratorComponent>(PasswordGeneratorComponent,
this.passwordGeneratorModal); this.passwordGeneratorModal);
childComponent.showSelect = true; childComponent.showSelect = true;
childComponent.onSelected.subscribe((password: string) => {
modal.close();
if (this.addEditComponent != null && this.addEditComponent.cipher != null &&
this.addEditComponent.cipher.login != null) {
this.addEditComponent.cipher.login.password = password;
}
});
} }
private clearFilters() { private clearFilters() {