1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-10-01 04:37:40 +02:00

Convert global module to TypeScript. (#397)

This commit is contained in:
Oscar Hinton 2017-11-25 16:04:31 +01:00 committed by Kyle Spearrin
parent f5ccc22076
commit 7c525d3f3a
11 changed files with 83 additions and 77 deletions

View File

@ -26,6 +26,7 @@ import ToolsModule from './tools/tools.module';
import ServicesModule from './services/services.module';
import LockModule from './lock/lock.module';
import CurrentModule from './current/current.module';
import GlobalModule from './global/global.module';
// Model imports
import { Attachment } from '../../models/domain/attachment';
@ -83,7 +84,7 @@ angular
ComponentsModule,
ServicesModule,
'bit.global',
GlobalModule,
'bit.accounts',
CurrentModule,
'bit.vault',
@ -93,11 +94,6 @@ angular
]);
require('./config');
require('./global/globalModule.js');
require('./global/mainController.js');
require('./global/tabsController.js');
require('./global/baseController.js');
require('./global/privateModeController.js');
require('./accounts/accountsModule.js');
require('./accounts/accountsLoginController.js');
require('./accounts/accountsLoginTwoFactorController.js');

View File

@ -0,0 +1,5 @@
export class BaseController implements ng.IController {
constructor($scope: any, i18nService: any) {
$scope.i18n = i18nService;
}
}

View File

@ -1,6 +0,0 @@
angular
.module('bit.global')
.controller('baseController', function ($scope, i18nService) {
$scope.i18n = i18nService;
});

View File

@ -0,0 +1,15 @@
import * as angular from 'angular';
import { BaseController } from './base.controller';
import { MainController } from './main.controller';
import { PrivateModeController } from './private-mode.controller';
import { TabsController } from './tabs.controller';
export default angular
.module('bit.global', ['ngAnimate'])
.controller('mainController', MainController)
.controller('baseController', BaseController)
.controller('tabsController', TabsController)
.controller('privateModeController', PrivateModeController)
.name;

View File

@ -1,2 +0,0 @@
angular
.module('bit.global', ['ngAnimate']);

View File

@ -0,0 +1,46 @@
import { UtilsService } from '../../../services/abstractions/utils.service';
export class MainController implements ng.IController {
smBody: boolean;
xsBody: boolean;
animation: string;
constructor($scope: any, $transitions: any, $state: any, authService: any, toastr: any,
i18nService: any, $analytics: any, utilsService: UtilsService, $window: any) {
this.animation = '';
this.xsBody = $window.screen.availHeight < 600;
this.smBody = !this.xsBody && $window.screen.availHeight <= 800;
$transitions.onSuccess({}, (transition: any) => {
const toParams = transition.params('to');
if (toParams.animation) {
this.animation = toParams.animation;
} else {
this.animation = '';
}
});
chrome.runtime.onMessage.addListener((msg: any, sender: any, sendResponse: any) => {
if (msg.command === 'syncCompleted') {
$scope.$broadcast('syncCompleted', msg.successfully);
} else if (msg.command === 'syncStarted') {
$scope.$broadcast('syncStarted');
} else if (msg.command === 'doneLoggingOut') {
authService.logOut(() => {
$analytics.eventTrack('Logged Out');
if (msg.expired) {
toastr.warning(i18nService.loginExpired, i18nService.loggedOut);
}
$state.go('home');
});
} else if (msg.command === 'collectPageDetailsResponse' && msg.sender === 'currentController') {
$scope.$broadcast('collectPageDetailsResponse', {
frameId: sender.frameId,
tab: msg.tab,
details: msg.details,
});
}
});
}
}

View File

@ -1,46 +0,0 @@
angular
.module('bit.global')
.controller('mainController', function ($scope, $transitions, $state, authService, toastr, i18nService, $analytics, utilsService,
$window) {
var self = this;
self.animation = '';
self.xsBody = $window.screen.availHeight < 600;
self.smBody = !self.xsBody && $window.screen.availHeight <= 800;
$transitions.onSuccess({}, function(transition) {
const toParams = transition.params("to");
if (toParams.animation) {
self.animation = toParams.animation;
return;
} else {
self.animation = '';
}
});
chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
if (msg.command === 'syncCompleted') {
$scope.$broadcast('syncCompleted', msg.successfully);
}
else if (msg.command === 'syncStarted') {
$scope.$broadcast('syncStarted');
}
else if (msg.command === 'doneLoggingOut') {
authService.logOut(function () {
$analytics.eventTrack('Logged Out');
if (msg.expired) {
toastr.warning(i18nService.loginExpired, i18nService.loggedOut);
}
$state.go('home');
});
}
else if (msg.command === 'collectPageDetailsResponse' && msg.sender === 'currentController') {
$scope.$broadcast('collectPageDetailsResponse', {
frameId: sender.frameId,
tab: msg.tab,
details: msg.details
});
}
});
});

View File

@ -0,0 +1,9 @@
export class PrivateModeController implements ng.IController {
constructor($scope: any) {
$scope.privateModeMessage = chrome.i18n.getMessage('privateModeMessage');
$scope.learnMoreMessage = chrome.i18n.getMessage('learnMore');
$scope.learnMore = () => {
chrome.tabs.create({ url: 'https://help.bitwarden.com/article/extension-wont-load-in-private-mode/' });
};
}
}

View File

@ -1,10 +0,0 @@
angular
.module('bit.global')
.controller('privateModeController', function ($scope) {
$scope.privateModeMessage = chrome.i18n.getMessage("privateModeMessage");
$scope.learnMoreMessage = chrome.i18n.getMessage("learnMore");
$scope.learnMore = function () {
chrome.tabs.create({ url: 'https://help.bitwarden.com/article/extension-wont-load-in-private-mode/' });
};
});

View File

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

View File

@ -1,7 +0,0 @@
angular
.module('bit.global')
.controller('tabsController', function ($scope, $state, i18nService) {
$scope.$state = $state;
$scope.i18n = i18nService;
});