Skip to content

Instantly share code, notes, and snippets.

@doron2402
Created November 21, 2015 00:13
Show Gist options
  • Save doron2402/9a4a6c0ddf9dfb8071fe to your computer and use it in GitHub Desktop.
Save doron2402/9a4a6c0ddf9dfb8071fe to your computer and use it in GitHub Desktop.

Revisions

  1. doron2402 created this gist Nov 21, 2015.
    86 changes: 86 additions & 0 deletions navBarStep.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,86 @@
    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 mapFunc = function(val){
    if (steps[val].isEnabled) {
    steps[val].name = val;
    return steps[val];
    }
    return null;
    };
    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 filterNull = function(val) { return val !== null; };

    var mapPrevNextOrder = function(val, index, arr){
    if (index === 0) {
    val.prev = 'welcome';
    } else {
    val.prev = arr[index-1].name;
    }

    if (index === arr.length-1) {
    val.next = 'welcome';
    } else {
    val.next = arr[index+1].name;
    }
    return val;
    };

    var newSteps = Object.keys(steps)
    .sort(SortByPosition)
    .map(mapFunc)
    .filter(filterNull)
    .map(mapPrevNextOrder);
    console.log(newSteps);