1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-23 19:53:43 +00:00

shortcuts and modal fixes

This commit is contained in:
Kyle Spearrin
2018-02-09 12:12:41 -05:00
parent f80ae40b1a
commit 481d04b2b9
6 changed files with 126 additions and 58 deletions

View File

@@ -57,12 +57,12 @@
<div class="box-content condensed">
<div class="box-content-row box-content-row-input" appBoxRow>
<label for="min-number">{{'minNumbers' | i18n}}</label>
<input id="min-number" type="number" min="0" max="5" (change)="saveOptions()"
<input id="min-number" type="number" min="0" max="9" (change)="saveOptions()"
[(ngModel)]="options.minNumber">
</div>
<div class="box-content-row box-content-row-input" appBoxRow>
<label for="min-special">{{'minSpecial' | i18n}}</label>
<input id="min-special" type="number" min="0" max="5" (change)="saveOptions()"
<input id="min-special" type="number" min="0" max="9" (change)="saveOptions()"
[(ngModel)]="options.minSpecial">
</div>
<div class="box-content-row box-content-row-checkbox" appBoxRow>

View File

@@ -84,6 +84,9 @@ export class PasswordGeneratorComponent implements OnInit {
}
private normalizeOptions() {
this.options.minLowercase = 0;
this.options.minUppercase = 0;
if (!this.options.uppercase && !this.options.lowercase && !this.options.number && !this.options.special) {
this.options.lowercase = true;
const lowercase = document.querySelector('#lowercase') as HTMLInputElement;
@@ -91,22 +94,31 @@ export class PasswordGeneratorComponent implements OnInit {
lowercase.checked = true;
}
}
if (!this.options.minNumber) {
this.options.minNumber = 0;
} else if (this.options.minNumber > 5) {
this.options.minNumber = 5;
}
if (!this.options.minSpecial) {
this.options.minSpecial = 0;
} else if (this.options.minSpecial > 5) {
this.options.minSpecial = 5;
}
if (!this.options.length) {
this.options.length = 5;
} else if (this.options.length > 128) {
this.options.length = 128;
}
if (!this.options.minNumber) {
this.options.minNumber = 0;
} else if (this.options.minNumber > this.options.length) {
this.options.minNumber = this.options.length;
} else if (this.options.minNumber > 9) {
this.options.minNumber = 9;
}
if (!this.options.minSpecial) {
this.options.minSpecial = 0;
} else if (this.options.minSpecial > this.options.length) {
this.options.minSpecial = this.options.length;
} else if (this.options.minSpecial > 9) {
this.options.minSpecial = 9;
}
if (this.options.minSpecial + this.options.minNumber > this.options.length) {
this.options.minSpecial = this.options.length - this.options.minNumber;
}
}
}

View File

@@ -27,7 +27,7 @@
(onDeletedCipher)="deletedCipher($event)"
(onEditAttachments)="editCipherAttachments($event)"
(onCancelled)="cancelledAddEdit($event)"
(onGeneratePassword)="openPasswordGenerator()">
(onGeneratePassword)="openPasswordGenerator(true)">
</app-vault-add-edit>
<div id="logo" *ngIf="action !== 'add' && action !== 'edit' && action !== 'view'">
<div class="content">

View File

@@ -43,9 +43,9 @@ export class VaultComponent implements OnInit {
@ViewChild(AddEditComponent) addEditComponent: AddEditComponent;
@ViewChild(CiphersComponent) ciphersComponent: CiphersComponent;
@ViewChild(GroupingsComponent) groupingsComponent: GroupingsComponent;
@ViewChild('passwordGenerator', { read: ViewContainerRef }) passwordGeneratorModal: ViewContainerRef;
@ViewChild('attachments', { read: ViewContainerRef }) attachmentsModal: ViewContainerRef;
@ViewChild('folderAddEdit', { read: ViewContainerRef }) folderAddEditModal: ViewContainerRef;
@ViewChild('passwordGenerator', { read: ViewContainerRef }) passwordGeneratorModalRef: ViewContainerRef;
@ViewChild('attachments', { read: ViewContainerRef }) attachmentsModalRef: ViewContainerRef;
@ViewChild('folderAddEdit', { read: ViewContainerRef }) folderAddEditModalRef: ViewContainerRef;
action: string;
cipherId: string = null;
@@ -55,6 +55,10 @@ export class VaultComponent implements OnInit {
collectionId: string = null;
addType: CipherType = null;
private passwordGeneratorModal: ModalComponent = null;
private folderAddEditModal: ModalComponent = null;
private attachmentsModal: ModalComponent = null;
constructor(private route: ActivatedRoute, private router: Router, private location: Location,
private componentFactoryResolver: ComponentFactoryResolver, private i18nService: I18nService,
private broadcasterService: BroadcasterService, private changeDetectorRef: ChangeDetectorRef,
@@ -82,6 +86,13 @@ export class VaultComponent implements OnInit {
case 'newFolder':
await this.addFolder();
break;
case 'focusSearch':
(document.querySelector('#search') as HTMLInputElement).focus();
detectChanges = false;
break;
case 'openPasswordGenerator':
await this.openPasswordGenerator(false);
break;
default:
detectChanges = false;
break;
@@ -103,9 +114,10 @@ export class VaultComponent implements OnInit {
}
async load(params?: { [key: string]: any }) {
await this.groupingsComponent.load();
if (params == null) {
this.groupingsComponent.selectedAll = true;
await this.groupingsComponent.load();
await this.ciphersComponent.load();
return;
}
@@ -138,7 +150,6 @@ export class VaultComponent implements OnInit {
await this.filterCollection(params.collectionId);
} else {
this.groupingsComponent.selectedAll = true;
await this.groupingsComponent.load();
await this.ciphersComponent.load();
}
}
@@ -189,11 +200,20 @@ export class VaultComponent implements OnInit {
}
editCipherAttachments(cipher: CipherView) {
if (this.attachmentsModal != null) {
this.attachmentsModal.close();
}
const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent);
const modal = this.attachmentsModal.createComponent(factory).instance;
const childComponent = modal.show<AttachmentsComponent>(AttachmentsComponent, this.attachmentsModal);
this.attachmentsModal = this.attachmentsModalRef.createComponent(factory).instance;
const childComponent = this.attachmentsModal.show<AttachmentsComponent>(
AttachmentsComponent, this.attachmentsModalRef);
childComponent.cipherId = cipher.id;
this.attachmentsModal.onClosed.subscribe(() => {
this.attachmentsModal = null;
});
}
cancelledAddEdit(cipher: CipherView) {
@@ -242,48 +262,66 @@ export class VaultComponent implements OnInit {
this.go();
}
async openPasswordGenerator() {
const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent);
const modal = this.passwordGeneratorModal.createComponent(factory).instance;
const childComponent = modal.show<PasswordGeneratorComponent>(PasswordGeneratorComponent,
this.passwordGeneratorModal);
async openPasswordGenerator(showSelect: boolean) {
if (this.passwordGeneratorModal != null) {
this.passwordGeneratorModal.close();
}
childComponent.showSelect = true;
const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent);
this.passwordGeneratorModal = this.passwordGeneratorModalRef.createComponent(factory).instance;
const childComponent = this.passwordGeneratorModal.show<PasswordGeneratorComponent>(PasswordGeneratorComponent,
this.passwordGeneratorModalRef);
childComponent.showSelect = showSelect;
childComponent.onSelected.subscribe((password: string) => {
modal.close();
this.passwordGeneratorModal.close();
if (this.addEditComponent != null && this.addEditComponent.cipher != null &&
this.addEditComponent.cipher.login != null) {
this.addEditComponent.cipher.login.password = password;
}
});
this.passwordGeneratorModal.onClosed.subscribe(() => {
this.passwordGeneratorModal = null;
});
}
async addFolder() {
const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent);
const modal = this.folderAddEditModal.createComponent(factory).instance;
const childComponent = modal.show<FolderAddEditComponent>(FolderAddEditComponent, this.folderAddEditModal);
this.folderAddEditModal = this.folderAddEditModalRef.createComponent(factory).instance;
const childComponent = this.folderAddEditModal.show<FolderAddEditComponent>(
FolderAddEditComponent, this.folderAddEditModalRef);
childComponent.folderId = null;
childComponent.onSavedFolder.subscribe(async (folder: FolderView) => {
modal.close();
this.folderAddEditModal.close();
await this.groupingsComponent.loadFolders();
});
this.folderAddEditModal.onClosed.subscribe(() => {
this.folderAddEditModal = null;
});
}
async editFolder(folderId: string) {
const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent);
const modal = this.folderAddEditModal.createComponent(factory).instance;
const childComponent = modal.show<FolderAddEditComponent>(FolderAddEditComponent, this.folderAddEditModal);
this.folderAddEditModal = this.folderAddEditModalRef.createComponent(factory).instance;
const childComponent = this.folderAddEditModal.show<FolderAddEditComponent>(
FolderAddEditComponent, this.folderAddEditModalRef);
childComponent.folderId = folderId;
childComponent.onSavedFolder.subscribe(async (folder: FolderView) => {
modal.close();
this.folderAddEditModal.close();
await this.groupingsComponent.loadFolders();
});
childComponent.onDeletedFolder.subscribe(async (folder: FolderView) => {
modal.close();
this.folderAddEditModal.close();
await this.groupingsComponent.loadFolders();
});
this.folderAddEditModal.onClosed.subscribe(() => {
this.folderAddEditModal = null;
});
}
private clearFilters() {