menu service ES6 refactoring

This commit is contained in:
tmshv committed 2016-02-22 01:46:36 +03:00
1 parent 7594a14ad6
commit 24f596abae
3 files changed
+34 -37

No files matched your search

+2 -1
View File
@@ -11,6 +11,7 @@ import HomeController from './controllers/HomeController';
import TeamController from './controllers/TeamController';
import DocumentsController from './controllers/DocumentsController';
import IOService from './services/io';
import MenuService from './services/menu';
import api from './api/api';
let deps = [
@@ -89,9 +90,9 @@ app.run(($location, $rootScope, $http) => {
[
api,
IOService,
MenuService,
require('./directives/mainMenu'),
require('./directives/backgroundPicture'),
require('./ui/menu'),
require('./ui/breadcrumbs'),
require('./ui/timeline'),
require('./filters/strip'),
+32
View File
@@ -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;
});
};
-36
View File
@@ -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;
});
};