forked from meanjs/mean
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): Modify core module to implement style guidelines.
Update the core module to implement the style guidelines. Reduce size of init.js - moved filter logic out to it's own config. Rename Menus to menuService
- Loading branch information
1 parent
59e6daa
commit b2462ec
Showing
28 changed files
with
610 additions
and
533 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,22 @@ | ||
'use strict'; | ||
(function (window) { | ||
'use strict'; | ||
|
||
// Init the application configuration module for AngularJS application | ||
var ApplicationConfiguration = (function () { | ||
// Init module configuration options | ||
var applicationModuleName = 'mean'; | ||
var applicationModuleVendorDependencies = ['ngResource', 'ngAnimate', 'ngMessages', 'ui.router', 'ui.bootstrap', 'angularFileUpload']; | ||
|
||
var service = { | ||
applicationModuleName: applicationModuleName, | ||
applicationModuleVendorDependencies: ['ngResource', 'ngAnimate', 'ngMessages', 'ui.router', 'ui.bootstrap', 'angularFileUpload'], | ||
registerModule: registerModule | ||
}; | ||
|
||
window.ApplicationConfiguration = service; | ||
|
||
// Add a new vertical module | ||
var registerModule = function (moduleName, dependencies) { | ||
function registerModule(moduleName, dependencies) { | ||
// Create angular module | ||
angular.module(moduleName, dependencies || []); | ||
|
||
// Add the module to the AngularJS configuration file | ||
angular.module(applicationModuleName).requires.push(moduleName); | ||
}; | ||
|
||
return { | ||
applicationModuleName: applicationModuleName, | ||
applicationModuleVendorDependencies: applicationModuleVendorDependencies, | ||
registerModule: registerModule | ||
}; | ||
}()); | ||
} | ||
}(window)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,45 @@ | ||
'use strict'; | ||
(function (app) { | ||
'use strict'; | ||
|
||
// Start by defining the main module and adding the module dependencies | ||
angular.module(ApplicationConfiguration.applicationModuleName, ApplicationConfiguration.applicationModuleVendorDependencies); | ||
// Start by defining the main module and adding the module dependencies | ||
angular | ||
.module(app.applicationModuleName, app.applicationModuleVendorDependencies); | ||
|
||
// Setting HTML5 Location Mode | ||
angular.module(ApplicationConfiguration.applicationModuleName).config(['$locationProvider', '$httpProvider', | ||
function ($locationProvider, $httpProvider) { | ||
// Setting HTML5 Location Mode | ||
angular | ||
.module(app.applicationModuleName) | ||
.config(bootstrapConfig); | ||
|
||
function bootstrapConfig($locationProvider, $httpProvider) { | ||
$locationProvider.html5Mode(true).hashPrefix('!'); | ||
|
||
$httpProvider.interceptors.push('authInterceptor'); | ||
} | ||
]); | ||
|
||
angular.module(ApplicationConfiguration.applicationModuleName).run(function ($rootScope, $state, Authentication) { | ||
|
||
// Check authentication before changing state | ||
$rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) { | ||
if (toState.data && toState.data.roles && toState.data.roles.length > 0) { | ||
var allowed = false; | ||
toState.data.roles.forEach(function (role) { | ||
if ((role === 'guest') || (Authentication.user && Authentication.user.roles !== undefined && Authentication.user.roles.indexOf(role) !== -1)) { | ||
allowed = true; | ||
return true; | ||
} | ||
}); | ||
|
||
if (!allowed) { | ||
event.preventDefault(); | ||
if (Authentication.user !== undefined && typeof Authentication.user === 'object') { | ||
$state.go('forbidden'); | ||
} else { | ||
$state.go('authentication.signin').then(function () { | ||
storePreviousState(toState, toParams); | ||
}); | ||
} | ||
bootstrapConfig.$inject = ['$locationProvider', '$httpProvider']; | ||
|
||
// Then define the init function for starting up the application | ||
angular.element(document).ready(init); | ||
|
||
function init() { | ||
// Fixing facebook bug with redirect | ||
if (window.location.hash && window.location.hash === '#_=_') { | ||
if (window.history && history.pushState) { | ||
window.history.pushState('', document.title, window.location.pathname); | ||
} else { | ||
// Prevent scrolling by storing the page's current scroll offset | ||
var scroll = { | ||
top: document.body.scrollTop, | ||
left: document.body.scrollLeft | ||
}; | ||
window.location.hash = ''; | ||
// Restore the scroll offset, should be flicker free | ||
document.body.scrollTop = scroll.top; | ||
document.body.scrollLeft = scroll.left; | ||
} | ||
} | ||
}); | ||
|
||
// Record previous state | ||
$rootScope.$on('$stateChangeSuccess', function (event, toState, toParams, fromState, fromParams) { | ||
storePreviousState(fromState, fromParams); | ||
}); | ||
|
||
// Store previous state | ||
function storePreviousState(state, params) { | ||
// only store this state if it shouldn't be ignored | ||
if (!state.data || !state.data.ignoreState) { | ||
$state.previous = { | ||
state: state, | ||
params: params, | ||
href: $state.href(state, params) | ||
}; | ||
} | ||
// Then init the app | ||
angular.bootstrap(document, [app.applicationModuleName]); | ||
} | ||
}); | ||
|
||
// Then define the init function for starting up the application | ||
angular.element(document).ready(function () { | ||
// Fixing facebook bug with redirect | ||
if (window.location.hash && window.location.hash === '#_=_') { | ||
if (window.history && history.pushState) { | ||
window.history.pushState('', document.title, window.location.pathname); | ||
} else { | ||
// Prevent scrolling by storing the page's current scroll offset | ||
var scroll = { | ||
top: document.body.scrollTop, | ||
left: document.body.scrollLeft | ||
}; | ||
window.location.hash = ''; | ||
// Restore the scroll offset, should be flicker free | ||
document.body.scrollTop = scroll.top; | ||
document.body.scrollLeft = scroll.left; | ||
} | ||
} | ||
|
||
// Then init the app | ||
angular.bootstrap(document, [ApplicationConfiguration.applicationModuleName]); | ||
}); | ||
}(ApplicationConfiguration)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,18 @@ | ||
'use strict'; | ||
(function () { | ||
'use strict'; | ||
|
||
angular.module('core.admin').run(['Menus', | ||
function (Menus) { | ||
Menus.addMenuItem('topbar', { | ||
angular | ||
.module('core.admin') | ||
.run(menuConfig); | ||
|
||
menuConfig.$inject = ['menuService']; | ||
|
||
function menuConfig(menuService) { | ||
menuService.addMenuItem('topbar', { | ||
title: 'Admin', | ||
state: 'admin', | ||
type: 'dropdown', | ||
roles: ['admin'] | ||
}); | ||
} | ||
]); | ||
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
(function () { | ||
'use strict'; | ||
|
||
angular | ||
.module('core') | ||
.run(routeFilter); | ||
|
||
routeFilter.$inject = ['$rootScope', '$state', 'Authentication']; | ||
|
||
function routeFilter($rootScope, $state, Authentication) { | ||
$rootScope.$on('$stateChangeStart', stateChangeStart); | ||
$rootScope.$on('$stateChangeSuccess', stateChangeSuccess); | ||
|
||
function stateChangeStart(event, toState, toParams, fromState, fromParams) { | ||
// Check authentication before changing state | ||
if (toState.data && toState.data.roles && toState.data.roles.length > 0) { | ||
var allowed = false; | ||
|
||
for (var i = 0, roles = toState.data.roles; i < roles.length; i++) { | ||
if ((roles[i] === 'guest') || (Authentication.user && Authentication.user.roles !== undefined && Authentication.user.roles.indexOf(roles[i]) !== -1)) { | ||
allowed = true; | ||
break; | ||
} | ||
} | ||
|
||
if (!allowed) { | ||
event.preventDefault(); | ||
if (Authentication.user !== undefined && typeof Authentication.user === 'object') { | ||
$state.transitionTo('forbidden'); | ||
} else { | ||
$state.go('authentication.signin').then(function () { | ||
// Record previous state | ||
storePreviousState(toState, toParams); | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
|
||
function stateChangeSuccess(event, toState, toParams, fromState, fromParams) { | ||
// Record previous state | ||
storePreviousState(fromState, fromParams); | ||
} | ||
|
||
// Store previous state | ||
function storePreviousState(state, params) { | ||
// only store this state if it shouldn't be ignored | ||
if (!state.data || !state.data.ignoreState) { | ||
$state.previous = { | ||
state: state, | ||
params: params, | ||
href: $state.href(state, params) | ||
}; | ||
} | ||
} | ||
} | ||
}()); |
Oops, something went wrong.