Skip to content

Instantly share code, notes, and snippets.

@doron2402
Created November 23, 2015 17:33
Show Gist options
  • Save doron2402/b65b49adb90aefaf503f to your computer and use it in GitHub Desktop.
Save doron2402/b65b49adb90aefaf503f to your computer and use it in GitHub Desktop.
var steps = {
floorplan: {
display: 'ResourceService.FloorPlan',
url: "/floorplan",
icon: "floorplan",
isEnabled: true,
position: 6
},
combinations: {
display: 'ResourceService.TableCombinations',
url: "/combinations",
icon: "combinations",
isEnabled: true,
position: 2
},
'reservation-availability': {
display: "Reservation",
url: "/reservation-availability",
icon: "reservation",
isEnabled: false,
position: 3
},
shift: {
display: 'ResourceService.Schedule',
url: "/shift",
icon: "schedule",
isEnabled: true,
position: 1
},
calendar: {
display: 'ResourceService.SpecialDays',
//TODO: Need to rename URL endpoint to something like SpecialDays
url: "/calendar",
icon: "specialdays",
isEnabled: true,
position: 5
},
publish: {
display: 'ResourceService.Publish',
url: "/publish",
icon: "publish",
isEnabled: true,
position: 4
}
};
var SortByPosition = function(prev, current) {
if (steps[prev].position < steps[current].position) {
return -1;
} else if (steps[prev].position > steps[current].position) {
return 1;
}
return 0;
};
var reducePrevNext = function(prev, curr, index, arr){
if (!!steps[curr].isEnabled) {
prev.push(
{
name: curr,
display: steps[curr].display,
url: steps[curr].url,
icon: steps[curr].icon,
prev: arr[index-1] ? arr[index-1] : 'welcome',
next: arr[index+1] ? arr[index+1] : 'welcome',
}
);
}
return prev;
};
var a = Object.keys(steps).sort(SortByPosition).reduce(reducePrevNext,[]);
console.log(a);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment