Пример #1
0
  self.on('attached', function () {
    // define routes
    self.defineRoute('index', '/');
    self.defineRoute('show', '/:componentId');
    self.defineRoute('child-component', '/:componentId/child-component');

    // index
    self.get(self.lookupRoute('index'), function(req, res, next) {
      res.locals.next = req.routeToPath('show', { componentId: 1 });
      res.render('index', {
        title: 'Component Index'
      });
    });

    // load
    self.get(self.lookupRoute('show') + '*', function (req, res, next) {
      var param = req.params.componentId;
      if (/^\d+$/.test(param)) {
        req.component = Number(param);
          res.locals.back = req.routeToPath('show');
        if (req.component < 3) {
          res.locals.next = req.routeToPath('show', { componentId: req.component + 1 });
        }
      };
      next();
    })

    // show
    self.get(self.lookupRoute('show'), function (req, res, next) {
      if (!req.component) {
        next(new Error('Route Not Found'));
        return;
      }
      if (req.component <= 1) {
        res.locals.back = req.routeToPath('index');
      } else {
        res.locals.back = req.routeToPath('child-component.show', { componentId: req.component - 1, childComponentId: 3 });
      }
      res.locals.next = req.routeToPath('child-component.index');
      res.render('index', {
        title: 'Component ' + req.component
      })
    });

    self.attach('child-component', childComponent);

    // there is a bug in the router that causes a range error if this
    // is not here. It has something to do with the load route.
    self.get('*', function (req, res, next) {
      next('route');
    })
  })
Пример #2
0
  function attach() {

    var controller = Controller(shared.model('User'));

    // Define Named Routes
    self.defineRoute('new', '/');
    self.defineRoute('create', '/');

    // Attach controllers
    // These should be restricited to un authenticated users.
    self.get(self.lookupRoute('new'), controller.new);
    self.post(self.lookupRoute('create'), controller.create);

    self.emit('ready', self);

  };
Пример #3
0
  self.on('attached', function () {
    // Define Routes
    self.defineRoute('index', '/');
    self.defineRoute('show', '/:childComponentId');

    // index
    self.get(self.lookupRoute('index'), function(req, res, next) {
      // test getting a parent route from inside an attached component.
      console.log(req.routeToPath('signup'));// should not throw!
      res.locals.next = req.routeToPath('show', { childComponentId: 1 });
      res.render('index', {
        title: 'Child Component Index'
      });
    });

    // load
    self.get(self.lookupRoute('show'), function (req, res, next) {
      var param = req.params.childComponentId;
      if (/^\d+$/.test(param)) {
        req.childComponent = Number(param);
      };
      next();
    })

    self.get(self.lookupRoute('show'), function (req, res, next) {
      if (!req.childComponent) {
        next(new Error('Route Not Found'));
        return;
      };
      if (req.childComponent <= 1) {
        res.locals.back = req.routeToPath('index');
      } else {
        res.locals.back = req.routeToPath('show', { childComponentId: req.childComponent - 1 });
      };
      if (req.childComponent < 3) {
        res.locals.next = req.routeToPath('show', { childComponentId: req.childComponent + 1 });
      }
      res.render('index', {
        title: 'Child Component ' + req.childComponent
      });
    });

    console.log('Child Component - Ready');
    self.emit('ready', self);

  })
  function attach() {

    // instantiate controller
    var controller = Controller(shared.model('User'));

    // Define Routes
    self.defineRoute('index', '/');
    self.defineRoute('new', '/');
    self.defineRoute('create', '/');
    self.defineRoute('edit', '/edit');
    self.defineRoute('update', '/update');

    // Attach Routes to Controller
    self.get(self.lookupRoute('new'), controller.new);
    self.post(self.lookupRoute('create'), controller.create);
    self.get(self.lookupRoute('edit'), controller.edit);
    self.post(self.lookupRoute('update'), controller.update);

    self.emit('ready', self);

  };
Пример #5
0
  function attach() {

    // instantiate controller
    var controller = Controller(shared.model('User'));

    // Define Named Routes
    // index is rewritten to be base route + /signin, because
    // this is normally mounted to the app index ('/')
    self.defineRoute('index', '/signin');
    self.defineRoute('signin', '/signin');
    self.defineRoute('signout', '/signout');

    // Define Routes
    // Should these only be available to anonymous users?
    self.get(self.lookupRoute('signin'), controller.new);
    self.post(self.lookupRoute('signin'), controller.create);
    // should restrict this to signed in users
    self.get(self.lookupRoute('signout'), controller.destroy);

    self.emit('ready', self);

  };