mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-05 22:26:07 +00:00
Add hash navigation to admin Enterprise edit view
This commit is contained in:
@@ -22,7 +22,7 @@ angular.module("admin.enterprises")
|
||||
{ name: 'users', label: t('users'), icon_class: "icon-user" }
|
||||
]
|
||||
|
||||
$scope.select(0)
|
||||
SideMenu.init()
|
||||
|
||||
$scope.showItem = (item) ->
|
||||
if item.show?
|
||||
|
||||
@@ -1,9 +1,21 @@
|
||||
angular.module("admin.side_menu")
|
||||
.factory "SideMenu", ->
|
||||
.factory "SideMenu", ($location) ->
|
||||
new class SideMenu
|
||||
items: []
|
||||
selected: null
|
||||
|
||||
|
||||
# Checks for path and uses it to set the view
|
||||
# If no path, loads first view
|
||||
init: =>
|
||||
path = $location.path()?.match(/^\/\w+$/)?[0]
|
||||
index = if path
|
||||
name = path[1..]
|
||||
@items.indexOf(@find_by_name(name))
|
||||
else
|
||||
0
|
||||
@select(index)
|
||||
|
||||
setItems: (items) =>
|
||||
@items = items
|
||||
item.visible = true for item in @items
|
||||
@@ -13,6 +25,7 @@ angular.module("admin.side_menu")
|
||||
@selected.selected = false if @selected
|
||||
@selected = @items[index]
|
||||
@selected.selected = true
|
||||
$location.path(@selected.name)
|
||||
|
||||
find_by_name: (name) =>
|
||||
for item in @items when item.name is name
|
||||
|
||||
@@ -17,6 +17,7 @@ describe "menuCtrl", ->
|
||||
inject ($rootScope, $controller, _SideMenu_) ->
|
||||
scope = $rootScope
|
||||
SideMenu = _SideMenu_
|
||||
spyOn(SideMenu, "init").and.callThrough()
|
||||
spyOn(SideMenu, "select").and.callThrough()
|
||||
spyOn(SideMenu, "setItems").and.callThrough()
|
||||
ctrl = $controller 'sideMenuCtrl', {$scope: scope, enterprise: enterprise, SideMenu: SideMenu, enterprisePermissions: {}}
|
||||
@@ -30,7 +31,7 @@ describe "menuCtrl", ->
|
||||
expect(scope.menu.items).toBe SideMenu.items
|
||||
|
||||
it "sets the initally selected value", ->
|
||||
expect(SideMenu.select).toHaveBeenCalledWith 0
|
||||
expect(SideMenu.init).toHaveBeenCalled()
|
||||
|
||||
|
||||
describe "selecting an item", ->
|
||||
|
||||
Reference in New Issue
Block a user