1
0
mirror of https://github.com/bitwarden/directory-connector synced 2025-12-05 23:53:21 +00:00

reduce menu. added gsuite file picker

This commit is contained in:
Kyle Spearrin
2018-05-02 14:01:44 -04:00
parent d53c1211cf
commit f8ae050556
7 changed files with 42 additions and 75 deletions

View File

@@ -65,20 +65,9 @@ export class AppComponent implements OnInit {
private componentFactoryResolver: ComponentFactoryResolver, private messagingService: MessagingService) { }
ngOnInit() {
this.ngZone.runOutsideAngular(() => {
window.setTimeout(async () => {
await this.updateAppMenu();
}, 1000);
});
this.broadcasterService.subscribe(BroadcasterSubscriptionId, async (message: any) => {
this.ngZone.run(async () => {
switch (message.command) {
case 'loggedIn':
case 'unlocked':
case 'loggedOut':
this.updateAppMenu();
break;
case 'logout':
this.logOut(!!message.expired);
break;
@@ -92,12 +81,6 @@ export class AppComponent implements OnInit {
this.broadcasterService.unsubscribe(BroadcasterSubscriptionId);
}
private async updateAppMenu() {
this.messagingService.send('updateAppMenu', {
isAuthenticated: await this.userService.isAuthenticated(),
});
}
private async logOut(expired: boolean) {
const userId = await this.userService.getUserId();

View File

@@ -87,10 +87,15 @@
<small class="text-muted form-text">{{'ex' | i18n}} 39204722352</small>
</div>
<div class="form-group">
<label for="keyFile">{{'jsonKeyFile' | i18n}}</label>
<input type="file" class="form-control-file" id="keyFile" accept=".json" (change)="parseKeyFile()">
<small class="text-muted form-text">{{'ex' | i18n}} My Project-jksd3jd223.json</small>
</div>
<div class="form-group" [hidden]="!gsuite.clientEmail">
<label for="clientEmail">{{'clientEmail' | i18n}}</label>
<input type="text" class="form-control" id="clientEmail" name="ClientEmail" [(ngModel)]="gsuite.clientEmail">
</div>
<div class="form-group">
<div class="form-group" [hidden]="!gsuite.privateKey">
<label for="privateKey">{{'privateKey' | i18n}}</label>
<textarea class="form-control text-monospace" id="privateKey" name="PrivateKey" [(ngModel)]="gsuite.privateKey">
</textarea>

View File

@@ -1,5 +1,7 @@
import {
ChangeDetectorRef,
Component,
NgZone,
OnDestroy,
OnInit,
} from '@angular/core';
@@ -28,7 +30,8 @@ export class SettingsComponent implements OnInit, OnDestroy {
sync = new SyncConfiguration();
directoryOptions: any[];
constructor(private i18nService: I18nService, private configurationService: ConfigurationService) {
constructor(private i18nService: I18nService, private configurationService: ConfigurationService,
private changeDetectorRef: ChangeDetectorRef, private ngZone: NgZone) {
this.directoryOptions = [
{ name: i18nService.t('select'), value: null },
{ name: 'Active Directory / LDAP', value: DirectoryType.Ldap },
@@ -72,4 +75,32 @@ export class SettingsComponent implements OnInit, OnDestroy {
await this.configurationService.saveDirectory(DirectoryType.AzureActiveDirectory, this.azure);
await this.configurationService.saveSync(this.sync);
}
async parseKeyFile() {
const filePicker = (document.getElementById('keyFile') as HTMLInputElement);
if (filePicker.files == null || filePicker.files.length < 0) {
return;
}
const reader = new FileReader();
reader.readAsText(filePicker.files[0], 'utf-8');
reader.onload = (evt) => {
this.ngZone.run(async () => {
try {
const result = JSON.parse((evt.target as FileReader).result);
if (result.client_email != null && result.private_key != null) {
this.gsuite.clientEmail = result.client_email;
this.gsuite.privateKey = result.private_key;
}
} catch { }
this.changeDetectorRef.detectChanges();
});
// reset file input
// ref: https://stackoverflow.com/a/20552042
filePicker.type = '';
filePicker.type = 'file';
filePicker.value = '';
};
}
}

View File

@@ -231,8 +231,8 @@
"view": {
"message": "View"
},
"file": {
"message": "File"
"jsonKeyFile": {
"message": "JSON Key File"
},
"edit": {
"message": "Edit"

View File

@@ -10,7 +10,6 @@ import { BaseMenu } from 'jslib/electron/baseMenu';
export class MenuMain extends BaseMenu {
menu: Menu;
logOut: MenuItem;
constructor(main: Main) {
super(main.i18nService, main.windowMain, main.i18nService.t('bitwardenDirectoryConnector'),
@@ -21,21 +20,10 @@ export class MenuMain extends BaseMenu {
this.initProperties();
this.initContextMenu();
this.initApplicationMenu();
this.logOut = this.menu.getMenuItemById('logOut');
this.updateApplicationMenuState(false);
}
updateApplicationMenuState(isAuthenticated: boolean) {
this.logOut.enabled = isAuthenticated;
}
private initApplicationMenu() {
const template: MenuItemConstructorOptions[] = [
{
label: this.i18nService.t('file'),
submenu: [this.logOutMenuItemOptions],
},
this.editMenuItemOptions,
{
label: this.i18nService.t('view'),
@@ -44,54 +32,21 @@ export class MenuMain extends BaseMenu {
this.windowMenuItemOptions,
];
const firstMenuOptions: MenuItemConstructorOptions[] = [
{ type: 'separator' },
{
label: this.i18nService.t('settings'),
id: 'settings',
click: () => { /* Something */ },
},
];
const updateMenuItem = {
label: this.i18nService.t('checkForUpdates'),
click: () => { /* Something */ },
id: 'checkForUpdates',
};
if (process.platform === 'darwin') {
const firstMenuPart: MenuItemConstructorOptions[] = [
{
label: this.i18nService.t('aboutBitwarden'),
role: 'about',
},
updateMenuItem,
];
template.unshift({
label: this.appName,
submenu: firstMenuPart.concat(firstMenuOptions, [
{ type: 'separator' },
], this.macAppMenuItemOptions),
submenu: firstMenuPart.concat(this.macAppMenuItemOptions),
});
// Window menu
template[template.length - 1].submenu = this.macWindowSubmenuOptions;
} else {
// File menu
template[0].submenu = (template[0].submenu as MenuItemConstructorOptions[]).concat(
firstMenuOptions);
// About menu
const aboutMenuAdditions: MenuItemConstructorOptions[] = [
{ type: 'separator' },
updateMenuItem,
];
aboutMenuAdditions.push(this.aboutMenuItemOptions);
template[template.length - 1].submenu =
(template[template.length - 1].submenu as MenuItemConstructorOptions[]).concat(aboutMenuAdditions);
}
this.menu = Menu.buildFromTemplate(template);

View File

@@ -24,9 +24,6 @@ export class MessagingMain {
case 'scheduleNextSync':
this.scheduleNextSync();
break;
case 'updateAppMenu':
this.menuMain.updateApplicationMenuState(message.isAuthenticated);
break;
default:
break;
}

View File

@@ -43,11 +43,7 @@ h4 {
}
app-root > #loading {
display: flex;
text-align: center;
justify-content: center;
align-items: center;
height: 100%;
width: 100%;
margin-top: 20px;
color: $text-muted;
}