1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-27 12:36:14 +01:00

cleanup and formatting

This commit is contained in:
Kyle Spearrin 2017-11-27 23:46:03 -05:00
parent 78c4ea7ecb
commit 8332e52a7b
19 changed files with 104 additions and 146 deletions

View File

@ -53,7 +53,7 @@ angular
.state('privateMode', { .state('privateMode', {
url: '/private-mode', url: '/private-mode',
controller: 'privateModeController', controller: 'privateModeController',
template: require('./global/privateMode.html'), template: require('./global/private-mode.html'),
data: { authorize: false }, data: { authorize: false },
params: { animation: null } params: { animation: null }
}) })

View File

@ -6,7 +6,7 @@ export class MainController implements ng.IController {
animation: string; animation: string;
constructor($scope: any, $transitions: any, $state: any, authService: any, toastr: any, constructor($scope: any, $transitions: any, $state: any, authService: any, toastr: any,
i18nService: any, $analytics: any, utilsService: UtilsService, $window: any) { i18nService: any, $analytics: any, utilsService: UtilsService, $window: any) {
this.animation = ''; this.animation = '';
this.xsBody = $window.screen.availHeight < 600; this.xsBody = $window.screen.availHeight < 600;
this.smBody = !this.xsBody && $window.screen.availHeight <= 800; this.smBody = !this.xsBody && $window.screen.availHeight <= 800;

View File

@ -1,4 +1,4 @@
export class PrivateModeController implements ng.IController { export class PrivateModeController implements ng.IController {
constructor($scope: any) { constructor($scope: any) {
$scope.privateModeMessage = chrome.i18n.getMessage('privateModeMessage'); $scope.privateModeMessage = chrome.i18n.getMessage('privateModeMessage');
$scope.learnMoreMessage = chrome.i18n.getMessage('learnMore'); $scope.learnMoreMessage = chrome.i18n.getMessage('learnMore');

View File

@ -1,4 +1,4 @@
export class TabsController implements ng.IController { export class TabsController implements ng.IController {
constructor($scope: any, $state: any, i18nService: any) { constructor($scope: any, $state: any, i18nService: any) {
$scope.$state = $state; $scope.$state = $state;
$scope.i18n = i18nService; $scope.i18n = i18nService;

View File

@ -1,4 +1,4 @@
import * as template from './about.component.html'; import * as template from './about.component.html';
class AboutController { class AboutController {
version: string; version: string;

View File

@ -27,7 +27,7 @@
</div> </div>
</div> </div>
<div class="list-section-footer"> <div class="list-section-footer">
{{$ctrl.i18n.contribute}} <a href="" ng-click="learnMore()">{{$ctrl.i18n.learnMore}}</a> {{$ctrl.i18n.contribute}} <a href="" ng-click="$ctrl.learnMore()">{{$ctrl.i18n.learnMore}}</a>
</div> </div>
</div> </div>
</div> </div>

View File

@ -1,4 +1,4 @@
import * as template from './credits.component.html'; import * as template from './credits.component.html';
class CreditsController { class CreditsController {
i18n: any; i18n: any;

View File

@ -26,15 +26,13 @@ class EnvironmentController {
} }
save() { save() {
this.environmentService this.environmentService.setUrls({
.setUrls({
base: this.baseUrl, base: this.baseUrl,
api: this.apiUrl, api: this.apiUrl,
identity: this.identityUrl, identity: this.identityUrl,
webVault: this.webVaultUrl, webVault: this.webVaultUrl,
icons: this.iconsUrl, icons: this.iconsUrl,
}) }).then((resUrls: any) => {
.then((resUrls: any) => {
this.$timeout(() => { this.$timeout(() => {
// re-set urls since service can change them, ex: prefixing https:// // re-set urls since service can change them, ex: prefixing https://
this.baseUrl = resUrls.base; this.baseUrl = resUrls.base;

View File

@ -13,8 +13,8 @@ class FeaturesController {
i18n: any; i18n: any;
constructor(private i18nService: any, private $analytics: any, private constantsService: any, constructor(private i18nService: any, private $analytics: any, private constantsService: any,
private utilsService: UtilsService, private totpService: any, private stateService: StateService, private utilsService: UtilsService, private totpService: any, private stateService: StateService,
private $timeout: ng.ITimeoutService) { private $timeout: ng.ITimeoutService) {
this.i18n = i18nService; this.i18n = i18nService;
$timeout(() => { $timeout(() => {
@ -25,22 +25,23 @@ class FeaturesController {
} }
async loadSettings() { async loadSettings() {
this.enableAutoFillOnPageLoad = await this.utilsService this.enableAutoFillOnPageLoad = await this.utilsService.getObjFromStorage<boolean>(
.getObjFromStorage<boolean>(this.constantsService.enableAutoFillOnPageLoadKey); this.constantsService.enableAutoFillOnPageLoadKey);
const disableGa = await this.utilsService.getObjFromStorage<boolean>(this.constantsService.disableGaKey); const disableGa = await this.utilsService.getObjFromStorage<boolean>(
this.constantsService.disableGaKey);
this.disableGa = disableGa || (this.utilsService.isFirefox() && disableGa === undefined); this.disableGa = disableGa || (this.utilsService.isFirefox() && disableGa === undefined);
this.disableAddLoginNotification = await this.utilsService this.disableAddLoginNotification = await this.utilsService.getObjFromStorage<boolean>(
.getObjFromStorage<boolean>(this.constantsService.disableAddLoginNotificationKey); this.constantsService.disableAddLoginNotificationKey);
this.disableContextMenuItem = await this.utilsService this.disableContextMenuItem = await this.utilsService.getObjFromStorage<boolean>(
.getObjFromStorage<boolean>(this.constantsService.disableContextMenuItemKey); this.constantsService.disableContextMenuItemKey);
this.disableAutoTotpCopy = !await this.totpService.isAutoCopyEnabled(); this.disableAutoTotpCopy = !await this.totpService.isAutoCopyEnabled();
this.disableFavicon = await this.utilsService this.disableFavicon = await this.utilsService.getObjFromStorage<boolean>(
.getObjFromStorage<boolean>(this.constantsService.disableFaviconKey); this.constantsService.disableFaviconKey);
} }
callAnalytics(name: string, enabled: boolean) { callAnalytics(name: string, enabled: boolean) {
@ -49,28 +50,19 @@ class FeaturesController {
} }
updateGa() { updateGa() {
this.utilsService.saveObjToStorage( this.utilsService.saveObjToStorage(this.constantsService.disableGaKey, this.disableGa);
this.constantsService.disableGaKey,
this.disableGa,
);
this.callAnalytics('Analytics', !this.disableGa); this.callAnalytics('Analytics', !this.disableGa);
} }
updateAddLoginNotification() { updateAddLoginNotification() {
this.utilsService.saveObjToStorage( this.utilsService.saveObjToStorage(this.constantsService.disableAddLoginNotificationKey,
this.constantsService.disableAddLoginNotificationKey, this.disableAddLoginNotification);
this.disableAddLoginNotification,
);
this.callAnalytics('Add Login Notification', !this.disableAddLoginNotification); this.callAnalytics('Add Login Notification', !this.disableAddLoginNotification);
} }
updateDisableContextMenuItem() { updateDisableContextMenuItem() {
this.utilsService this.utilsService.saveObjToStorage(this.constantsService.disableContextMenuItemKey,
.saveObjToStorage( this.disableContextMenuItem).then(() => {
this.constantsService.disableContextMenuItemKey,
this.disableContextMenuItem,
)
.then(() => {
chrome.runtime.sendMessage({ chrome.runtime.sendMessage({
command: 'bgUpdateContextMenu', command: 'bgUpdateContextMenu',
}); });
@ -79,26 +71,18 @@ class FeaturesController {
} }
updateAutoTotpCopy() { updateAutoTotpCopy() {
this.utilsService.saveObjToStorage( this.utilsService.saveObjToStorage(this.constantsService.disableAutoTotpCopyKey, this.disableAutoTotpCopy);
this.constantsService.disableAutoTotpCopyKey,
this.disableAutoTotpCopy,
);
this.callAnalytics('Auto Copy TOTP', !this.disableAutoTotpCopy); this.callAnalytics('Auto Copy TOTP', !this.disableAutoTotpCopy);
} }
updateAutoFillOnPageLoad() { updateAutoFillOnPageLoad() {
this.utilsService.saveObjToStorage( this.utilsService.saveObjToStorage(this.constantsService.enableAutoFillOnPageLoadKey,
this.constantsService.enableAutoFillOnPageLoadKey, this.enableAutoFillOnPageLoad);
this.enableAutoFillOnPageLoad,
);
this.callAnalytics('Auto-fill Page Load', this.enableAutoFillOnPageLoad); this.callAnalytics('Auto-fill Page Load', this.enableAutoFillOnPageLoad);
} }
updateDisableFavicon() { updateDisableFavicon() {
this.utilsService.saveObjToStorage( this.utilsService.saveObjToStorage(this.constantsService.disableFaviconKey, this.disableFavicon);
this.constantsService.disableFaviconKey,
this.disableFavicon,
);
this.stateService.saveState('faviconEnabled', !this.disableFavicon); this.stateService.saveState('faviconEnabled', !this.disableFavicon);
this.callAnalytics('Favicon', !this.disableFavicon); this.callAnalytics('Favicon', !this.disableFavicon);
} }

View File

@ -9,7 +9,7 @@ class AddFolderController {
i18n: any; i18n: any;
constructor(private folderService: any, private $state: any, private toastr: any, utilsService: UtilsService, constructor(private folderService: any, private $state: any, private toastr: any, utilsService: UtilsService,
private $analytics: any, private i18nService: any, $timeout: any) { private $analytics: any, private i18nService: any, $timeout: any) {
$timeout(() => { $timeout(() => {
utilsService.initListSectionItemListeners(document, angular); utilsService.initListSectionItemListeners(document, angular);
document.getElementById('name').focus(); document.getElementById('name').focus();
@ -26,17 +26,14 @@ class AddFolderController {
return; return;
} }
this.savePromise = this.folderService this.savePromise = this.folderService.encrypt(model).then((folderModel: any) => {
.encrypt(model) const folder = new Folder(folderModel, true);
.then((folderModel: any) => { return this.folderService.saveWithServer(folder);
const folder = new Folder(folderModel, true); }).then((folder: any) => {
return this.folderService.saveWithServer(folder); this.$analytics.eventTrack('Added Folder');
}) this.toastr.success(this.i18nService.addedFolder);
.then((folder: any) => { this.$state.go('^.list', { animation: 'out-slide-down' });
this.$analytics.eventTrack('Added Folder'); });
this.toastr.success(this.i18nService.addedFolder);
this.$state.go('^.list', { animation: 'out-slide-down' });
});
} }
} }

View File

@ -11,8 +11,8 @@ class EditFolderController {
folder: Folder; folder: Folder;
constructor($scope: any, $stateParams: any, private folderService: any, private toastr: any, private $state: any, constructor($scope: any, $stateParams: any, private folderService: any, private toastr: any, private $state: any,
private SweetAlert: any, utilsService: UtilsService, private $analytics: any, private i18nService: any, private SweetAlert: any, utilsService: UtilsService, private $analytics: any, private i18nService: any,
$timeout: any) { $timeout: any) {
this.i18n = i18nService; this.i18n = i18nService;
$timeout(() => { $timeout(() => {
@ -25,14 +25,11 @@ class EditFolderController {
$onInit() { $onInit() {
this.folderId = this.$transition$.params('to').folderId; this.folderId = this.$transition$.params('to').folderId;
this.folderService.get(this.folderId).then((folder: any) => {
this.folderService return folder.decrypt();
.get(this.folderId) }).then((model: Folder) => {
.then((folder: any) => { this.folder = model;
return folder.decrypt(); });
}).then((model: Folder) => {
this.folder = model;
});
} }
save(model: any) { save(model: any) {
@ -41,17 +38,14 @@ class EditFolderController {
return; return;
} }
this.savePromise = this.folderService this.savePromise = this.folderService.encrypt(model).then((folderModel: any) => {
.encrypt(model) const folder = new Folder(folderModel, true);
.then((folderModel: any) => { return this.folderService.saveWithServer(folder);
const folder = new Folder(folderModel, true); }).then((folder: any) => {
return this.folderService.saveWithServer(folder); this.$analytics.eventTrack('Edited Folder');
}) this.toastr.success(this.i18nService.editedFolder);
.then((folder: any) => { this.$state.go('^.list', { animation: 'out-slide-down' });
this.$analytics.eventTrack('Edited Folder'); });
this.toastr.success(this.i18nService.editedFolder);
this.$state.go('^.list', { animation: 'out-slide-down' });
});
} }
delete() { delete() {
@ -63,15 +57,13 @@ class EditFolderController {
cancelButtonText: this.i18nService.no, cancelButtonText: this.i18nService.no,
}, (confirmed: boolean) => { }, (confirmed: boolean) => {
if (confirmed) { if (confirmed) {
this.folderService this.folderService.deleteWithServer(this.folderId).then(() => {
.deleteWithServer(this.folderId) this.$analytics.eventTrack('Deleted Folder');
.then(() => { this.toastr.success(this.i18nService.deletedFolder);
this.$analytics.eventTrack('Deleted Folder'); this.$state.go('^.list', {
this.toastr.success(this.i18nService.deletedFolder); animation: 'out-slide-down',
this.$state.go('^.list', {
animation: 'out-slide-down',
});
}); });
});
} }
}); });
} }

View File

@ -1,4 +1,4 @@
import { Folder } from '../../../../models/domain/folder'; import { Folder } from '../../../../models/domain/folder';
import * as template from './folders.component.html'; import * as template from './folders.component.html';
class FoldersController { class FoldersController {
@ -8,23 +8,20 @@ class FoldersController {
constructor(private folderService: any, private $state: any, i18nService: any) { constructor(private folderService: any, private $state: any, i18nService: any) {
this.i18n = i18nService; this.i18n = i18nService;
this.load(); this.load();
} }
load() { load() {
this.folderService this.folderService.getAllDecrypted().then((folders: any) => {
.getAllDecrypted() if (folders.length > 0 && folders[0].id === null) {
.then((folders: any) => { // remove the "none" folder
if (folders.length > 0 && folders[0].id === null) { this.folders = folders.slice(1);
// remove the "none" folder } else {
this.folders = folders.slice(1); this.folders = folders;
} else { }
this.folders = folders;
}
this.loaded = true; this.loaded = true;
}); });
} }
editFolder(folder: any) { editFolder(folder: any) {

View File

@ -1,4 +1,4 @@
import * as template from './help.component.html'; import * as template from './help.component.html';
class HelpController { class HelpController {
i18n: any; i18n: any;

View File

@ -41,7 +41,7 @@
</a> </a>
</div> </div>
</div> </div>
<div ng-if="isPremium"> <div ng-if="$ctrl.isPremium">
<p class="text-center lead">{{$ctrl.i18n.premiumCurrentMember}}</p> <p class="text-center lead">{{$ctrl.i18n.premiumCurrentMember}}</p>
<p class="text-center">{{$ctrl.i18n.premiumCurrentMemberThanks}}</p> <p class="text-center">{{$ctrl.i18n.premiumCurrentMemberThanks}}</p>
<div class="bottom-buttons"> <div class="bottom-buttons">

View File

@ -6,22 +6,20 @@ class PremiumController {
price = '$10'; price = '$10';
constructor(private i18nService: any, private tokenService: any, private apiService: any, private toastr: any, constructor(private i18nService: any, private tokenService: any, private apiService: any, private toastr: any,
private SweetAlert: any, private $analytics: any, private $timeout: any) { private SweetAlert: any, private $analytics: any, private $timeout: any) {
this.i18n = i18nService; this.i18n = i18nService;
this.isPremium = tokenService.getPremium(); this.isPremium = tokenService.getPremium();
} }
refresh() { refresh() {
this.apiService this.apiService.refreshIdentityToken().then(() => {
.refreshIdentityToken() this.toastr.success(this.i18nService.refreshComplete);
.then(() => { this.$timeout(() => {
this.toastr.success(this.i18nService.refreshComplete); this.isPremium = this.tokenService.getPremium();
this.$timeout(() => {
this.isPremium = this.tokenService.getPremium();
});
}, (err: any) => {
this.toastr.error(this.i18nService.errorsOccurred);
}); });
}, (err: any) => {
this.toastr.error(this.i18nService.errorsOccurred);
});
} }
purchase() { purchase() {

View File

@ -23,8 +23,8 @@ class SettingsController {
showOnLocked: boolean; showOnLocked: boolean;
constructor(private $state: any, private SweetAlert: any, private utilsService: UtilsService, constructor(private $state: any, private SweetAlert: any, private utilsService: UtilsService,
private $analytics: any, private i18nService: any, private constantsService: ConstantsService, private $analytics: any, private i18nService: any, private constantsService: ConstantsService,
private cryptoService: CryptoService, private lockService: any, private $timeout: ng.ITimeoutService) { private cryptoService: CryptoService, private lockService: any, private $timeout: ng.ITimeoutService) {
this.i18n = i18nService; this.i18n = i18nService;
$timeout(() => { $timeout(() => {
@ -77,13 +77,11 @@ class SettingsController {
lock() { lock() {
this.$analytics.eventTrack('Lock Now'); this.$analytics.eventTrack('Lock Now');
this.lockService this.lockService.lock().then(() => {
.lock() return this.$state.go('lock', {
.then(() => { animation: 'in-slide-down',
return this.$state.go('lock', {
animation: 'in-slide-down',
});
}); });
});
} }
logOut() { logOut() {
@ -147,7 +145,6 @@ class SettingsController {
rate() { rate() {
this.$analytics.eventTrack('Rate Extension'); this.$analytics.eventTrack('Rate Extension');
chrome.tabs.create({ chrome.tabs.create({
url: RateUrls[this.utilsService.getBrowser()], url: RateUrls[this.utilsService.getBrowser()],
}); });

View File

@ -1,4 +1,4 @@
import * as angular from 'angular'; import * as angular from 'angular';
import { AboutComponent } from './about.component'; import { AboutComponent } from './about.component';
import { CreditsComponent } from './credits.component'; import { CreditsComponent } from './credits.component';
import { EnvironmentComponent } from './environment.component'; import { EnvironmentComponent } from './environment.component';

View File

@ -7,36 +7,31 @@ class SyncController {
constructor(private syncService: any, private toastr: any, private $analytics: any, private i18nService: any) { constructor(private syncService: any, private toastr: any, private $analytics: any, private i18nService: any) {
this.i18n = i18nService; this.i18n = i18nService;
this.setLastSync(); this.setLastSync();
} }
sync() { sync() {
this.loading = true; this.loading = true;
this.syncService this.syncService.fullSync(true).then((success: boolean) => {
.fullSync(true) this.loading = false;
.then((success: boolean) => { if (success) {
this.loading = false; this.setLastSync();
if (success) { this.$analytics.eventTrack('Synced Full');
this.setLastSync(); this.toastr.success(this.i18nService.syncingComplete);
this.$analytics.eventTrack('Synced Full'); } else {
this.toastr.success(this.i18nService.syncingComplete); this.toastr.error(this.i18nService.syncingFailed);
} else { }
this.toastr.error(this.i18nService.syncingFailed); });
}
});
} }
setLastSync() { setLastSync() {
this.syncService this.syncService.getLastSync().then((lastSync: any) => {
.getLastSync() if (lastSync) {
.then((lastSync: any) => { this.lastSync = lastSync.toLocaleDateString() + ' ' + lastSync.toLocaleTimeString();
if (lastSync) { } else {
this.lastSync = lastSync.toLocaleDateString() + ' ' + lastSync.toLocaleTimeString(); this.lastSync = this.i18nService.never;
} else { }
this.lastSync = this.i18nService.never; });
}
});
} }
} }