hostr/web/public/src/app.js

131 lines
4.3 KiB
JavaScript
Raw Normal View History

2015-07-09 23:01:43 +01:00
import angular from 'angular';
2018-06-02 19:42:45 +00:00
import 'angular-route';
import 'angular-resource';
import 'angular-reconnecting-websocket/angular-reconnecting-websocket';
2015-08-23 22:12:32 +01:00
import 'angular-strap/dist/modules/dimensions';
import 'angular-strap/dist/modules/compiler';
import 'angular-strap/dist/modules/tooltip';
import 'angular-strap/dist/modules/tooltip.tpl';
2015-07-09 23:01:43 +01:00
import { FilesController, FileController, AccountController, ProController, BillingController } from './app/controllers';
import { appHeader, appFooter, menuDropdown, searchShortcut, stripeSubscribe } from './app/directives';
import dropzone from './app/directives/dropzone';
import lazySrc from './app/directives/lazy-src';
import { fileSize, direct } from './app/filters';
import { FileService, UserService, EventService, TransactionService, SettingService } from './app/services';
// Declare app level module which depends on filters, and services
2015-08-23 22:12:32 +01:00
const app = angular.module('hostr', [
2015-07-09 23:01:43 +01:00
'ngRoute',
'ngResource',
'reconnectingWebSocket',
2015-08-22 00:27:55 +01:00
'mgcrea.ngStrap.core',
2015-08-23 22:12:32 +01:00
'mgcrea.ngStrap.tooltip',
2015-07-09 23:01:43 +01:00
]);
app.factory('FileService', ['$resource', '$cacheFactory', FileService.factory]);
app.factory('UserService', ['$resource', UserService.factory]);
2015-08-08 20:37:49 +01:00
app.factory('EventService', ['$rootScope', 'WebSocket', EventService.factory]);
2015-07-09 23:01:43 +01:00
app.factory('TransactionService', ['$resource', '$cacheFactory', TransactionService.factory]);
app.factory('SettingService', ['$http', SettingService.factory]);
app.filter('fileSize', [fileSize]);
app.filter('direct', [direct]);
app.directive('appHeader', [appHeader]);
app.directive('appFooter', [appFooter]);
app.directive('dropzone', ['FileService', '$cacheFactory', '$window', dropzone]);
app.directive('menuDropdown', [menuDropdown]);
app.directive('lazySrc', ['$window', '$document', lazySrc]);
app.directive('searchShortcut', ['$document', searchShortcut]);
app.directive('stripeSubscribe', ['$http', stripeSubscribe]);
2015-08-23 22:12:32 +01:00
app.config(['$routeProvider', '$locationProvider', '$httpProvider', ($routeProvider, $locationProvider, $httpProvider) => {
2015-07-09 23:01:43 +01:00
if (typeof window.user !== 'undefined') {
$httpProvider.defaults.headers.common.Authorization = ':' + window.user.token;
}
$locationProvider.html5Mode(true);
2015-08-23 22:12:32 +01:00
$httpProvider.interceptors.push(['$q', ($q) => {
2015-07-09 23:01:43 +01:00
return {
2015-08-23 22:12:32 +01:00
responseError: (rejection) => {
2015-07-09 23:01:43 +01:00
if (rejection.status === 401) {
window.location = '/logout';
}
return $q.reject(rejection);
2015-08-23 22:12:32 +01:00
},
2015-07-09 23:01:43 +01:00
};
}]);
$routeProvider.when('/', {
templateUrl: '/build/partials/files.html',
controller: FilesController,
title: ' - Files',
resolve: {
2015-08-23 22:12:32 +01:00
files: ['FileService', (Files) => {
2015-07-09 23:01:43 +01:00
return Files.query();
2015-08-23 22:12:32 +01:00
}],
},
2015-07-09 23:01:43 +01:00
})
.when('/apps', {
templateUrl: '/build/partials/apps.html',
2015-08-23 22:12:32 +01:00
title: ' - Apps for Mac and Windows',
2015-07-09 23:01:43 +01:00
})
.when('/pro', {
templateUrl: '/build/partials/pro.html',
controller: ProController,
2015-08-23 22:12:32 +01:00
title: ' - Pro',
2015-07-09 23:01:43 +01:00
})
.when('/account', {
templateUrl: '/build/partials/account.html',
controller: AccountController,
2015-08-23 22:12:32 +01:00
title: ' - Account',
2015-07-09 23:01:43 +01:00
})
.when('/billing', {
templateUrl: '/build/partials/billing.html',
controller: BillingController,
2015-08-23 22:12:32 +01:00
title: ' - Billing',
2015-07-09 23:01:43 +01:00
})
.when('/terms', {
templateUrl: '/build/partials/terms.html',
2015-08-23 22:12:32 +01:00
title: ' - Terms of Service',
2015-07-09 23:01:43 +01:00
})
.when('/privacy', {
templateUrl: '/build/partials/privacy.html',
2015-08-23 22:12:32 +01:00
title: ' - Privacy Policy',
2015-07-09 23:01:43 +01:00
})
.when('/:id', {
templateUrl: '/build/partials/file.html',
controller: FileController,
resolve: {
2015-08-23 22:12:32 +01:00
file: ['$route', 'FileService', ($route, Files) => {
2015-07-09 23:01:43 +01:00
return Files.get({id: $route.current.params.id});
2015-08-23 22:12:32 +01:00
}],
},
2015-07-09 23:01:43 +01:00
});
}]);
2015-08-23 22:12:32 +01:00
app.run(['$location', '$rootScope', ($location, $rootScope) => {
$rootScope.$on('$routeChangeStart', (e, curr) => {
if (curr.$$route && curr.$$route.resolve) {
2015-07-09 23:01:43 +01:00
// Show a loading message until promises are resolved
2015-08-23 22:12:32 +01:00
$rootScope.loadingView = true;
}
});
$rootScope.$on('$routeChangeSuccess', (event, current) => {
2015-07-09 23:01:43 +01:00
$rootScope.navError = false;
$rootScope.pageTitle = current.$$route.title;
});
2015-08-23 22:12:32 +01:00
$rootScope.$on('$routeChangeError', () => {
2015-07-09 23:01:43 +01:00
$rootScope.loadingView = false;
$rootScope.navError = true;
});
2015-08-23 22:12:32 +01:00
$rootScope.$on('$locationChangeStart', (event, newUrl) => {
2015-07-09 23:01:43 +01:00
if (window.ga) {
window.ga('send', 'pageview', newUrl);
}
});
}]);
2016-03-28 16:20:50 +01:00
angular.bootstrap(document, ['hostr']);