menu service ES6 refactoring
This commit is contained in:
1 parent
7594a14ad6
commit
24f596abae
3 files changed
+34
-37
No files matched your search
+2
-1
@@ -11,6 +11,7 @@ import HomeController from './controllers/HomeController';
|
|||||||
import TeamController from './controllers/TeamController';
|
import TeamController from './controllers/TeamController';
|
||||||
import DocumentsController from './controllers/DocumentsController';
|
import DocumentsController from './controllers/DocumentsController';
|
||||||
import IOService from './services/io';
|
import IOService from './services/io';
|
||||||
|
import MenuService from './services/menu';
|
||||||
import api from './api/api';
|
import api from './api/api';
|
||||||
|
|
||||||
let deps = [
|
let deps = [
|
||||||
@@ -89,9 +90,9 @@ app.run(($location, $rootScope, $http) => {
|
|||||||
[
|
[
|
||||||
api,
|
api,
|
||||||
IOService,
|
IOService,
|
||||||
|
MenuService,
|
||||||
require('./directives/mainMenu'),
|
require('./directives/mainMenu'),
|
||||||
require('./directives/backgroundPicture'),
|
require('./directives/backgroundPicture'),
|
||||||
require('./ui/menu'),
|
|
||||||
require('./ui/breadcrumbs'),
|
require('./ui/breadcrumbs'),
|
||||||
require('./ui/timeline'),
|
require('./ui/timeline'),
|
||||||
require('./filters/strip'),
|
require('./filters/strip'),
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import menuItems from '../../models/menu';
|
||||||
|
|
||||||
|
class Menu {
|
||||||
|
constructor() {
|
||||||
|
this.items = menuItems;
|
||||||
|
this.current = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
activate(path) {
|
||||||
|
let filteredItems = this.items.filter(i => i.url === path);
|
||||||
|
|
||||||
|
if (filteredItems.length) {
|
||||||
|
this.current = filteredItems[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function (app) {
|
||||||
|
app.factory('menu', ($route, $rootScope) => {
|
||||||
|
const menu = new Menu();
|
||||||
|
$rootScope.$on('$routeChangeSuccess', (event, current) => {
|
||||||
|
try {
|
||||||
|
let path = current['$$route'].originalPath;
|
||||||
|
menu.activate(path);
|
||||||
|
} catch (e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return menu;
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
/**
|
|
||||||
* Created by tmshv on 05/11/14.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import menuItems from '../../models/menu';
|
|
||||||
|
|
||||||
module.exports = function (app) {
|
|
||||||
app.factory("menu", function ($route, $rootScope) {
|
|
||||||
function Menu() {
|
|
||||||
this.items = menuItems;
|
|
||||||
this.current = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
Menu.prototype.activate = function (path) {
|
|
||||||
var f = this.items.filter(function (i) {
|
|
||||||
return i.url === path;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (f.length) {
|
|
||||||
this.current = f[0];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var menu = new Menu();
|
|
||||||
$rootScope.$on('$routeChangeSuccess', function (event, current) {
|
|
||||||
try {
|
|
||||||
var path = current['$$route'].originalPath;
|
|
||||||
menu.activate(path);
|
|
||||||
} catch (e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return menu;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
Reference in new issue
Block a user