Exemple #1
0
          entity.find.call({ req: opts.req, res: opts.res }, query, function (err, results) {
            if (err) {
              return opts.res.end(err.message);
            }

            results = results.filter(function (item) {
              if (item.key_type === "internal") {
                return false;
              }
              return true;
            });

            if (opts.req.jsonResponse) {
              return opts.res.json(results);
            }
            if (results && results.length === 0) {
              cb(null, $.html());
            } else {
              mschemaForms.generate({
                 type: "grid",
                 form: opts.form.grid,
                 schema: opts.schema,
                 data: results
                }, function (err, re) {
                  if (err) {
                    res.end(err.message);
                  }
                  $('.grid').append(re);
                  cb(null, $.html());
               });
            }
          });
Exemple #2
0
  function showForm (cb) {
    var formSchema = service.mschema || {};

    for (var p in formSchema) {
      if(typeof params[p] !== 'undefined') {
        formSchema[p].default = params[p];
      }
    }

    formSchema.run = {
      "type": "string",
      "default": "true",
      "format": "hidden"
    };

    formSchema.format = {
      "type": "string",
      "default": "friendly",
      "enum": ["raw", "friendly"]
    };

    formSchema.theme = {
      "type": "string",
      "format": "hidden",
      "default": params.theme
    };


    var themeSelect = '<form class="themeForm" action="" method="GET">\
    Switch Theme: <select class="themeSelector" name="theme">\
      <option value="simple-form">simple-form</option>\
      <option value="">custom</option>\
      <option value="debug">debug</option>\
      <option value="form">form</option>\
      <option value="none">none</option>\
    </select></form>';
    

    forms.generate({
      type: "generic",
      form: {
        legend: service.name + ' form',
        submit: "Submit",
        action: ""
      },
      schema: formSchema,
      }, function (err, result){
        $('.testForm').html(result);
        cb(null, $.html());
    });
    
  }
Exemple #3
0
function showUserForm (user, cb) {
  var formSchema = userSchema || {};

  formSchema.name = {
    default: user.name,
    disabled: true
  };

  formSchema.email.default = user.email || "";
  // formSchema.email.disabled = true;

  /*
  formSchema.run = {
    "type": "string",
    "default": "true",
    "format": "hidden"
  };
  */
  formSchema.paidStatus = {
    "type": "string",
    "label": "account paid status",
    "disabled": true,
    "default": user.paidStatus
  };

  formSchema.password = {
    "type": "string",
    "format": "password"
  };
  formSchema.confirmPassword = {
    "type": "string",
    "format": "password"
  };

  formSchema.previousName = {
    default: user.name,
    format: "hidden"
  };

  /*
  formSchema.githubOAuth = {
    "type": "string",
    "disabled": true,
    "enum": ["true", "false"],
    "default": "false",
    "label": "Account Linked To Github"
  };
  */
  if (typeof user.hostingCredits !== "number") {
    user.hostingCredits = 0;
  }

  if (user.hostingCredits > 0) {
    formSchema.hostingCredits = {
      "type": "number",
      "label": "hosting credits",
      "disabled": true,
      "default": user.hostingCredits
    }
  }

  forms.generate({
    type: "generic",
    form: {
      legend: "Account Information",
      submit: "Save",
      action: ""
    },
    schema: formSchema,
    }, function (err, result){
      cb(null, result);
  });

}
Exemple #4
0
module['exports'] = function view (opts, callback) {
  var params = opts.request.resource.params;
  var req = opts.request,
      service = opts.service,
      res = opts.response
      result = opts;
  var $ = this.$;
  var run = params.run;
  $('title').html(req.params.owner + "/" + req.params.hook);
  var gist = opts.gist || params.gist;
  $('.gistEmbed').html('<script src="' + gist + '.js"></script>');
  $('.gist').html('<a href="' + gist + '">' + gist + '</a>');

  // $('.hookDocs').html(docs);
  $('.hookDocs .docsHeader').remove();

  if (params.theme) {
    $('.theme').attr('value', params.theme);
  }
  if (params.edit) {
    return res.redirect(301, config.app.url + "/admin?owner=" + req.params.owner + "&hook=" + req.params.hook);
  }

  if (true) {
    // check result.headers for content type
    // if the content type is not text, display binary file message
   if (result.headers && result.headers.headers && typeof result.headers.headers['Content-Type'] !== "undefined") {
     var types = result.headers.headers['Content-Type'].split(',');
     if (types.indexOf('text/html') === -1) {
       $('.viewRaw').remove();
       $('.binaryFileLink .contentType').html(types[0]);
     } else {
       $('.binaryFileLink').remove();
     }
   } else {
     $('.binaryFileLink').remove();
   }

   if (result.headers && result.headers.code === 500) {
     $('.hookResult .message').html('Error executing Hook!');
     $('.hookResult .message').addClass('error');
     $('.hookResult .message').removeClass('success');
   }

   // $('.sourceCode').remove();
   // $('.hookOptions').remove();
   $('.hookParams').html(JSON.stringify(result.params, true, 2));

   var Datauri = require('datauri'),
       dUri    = new Datauri();

   var isVideo = false;
   if (types && types.indexOf('video/mp4') !== -1) {
     isVideo = true;
     var uri = dUri.format('.mp4', result.output);
     $('.hookOutput').html('<video controls><source type="video/mp4" src="' + uri.content + '"></video>');
     $('.binaryFileLink').remove();
   }

   var mime = require('mime');

   var imageTypes = ['image/bmp', 'image/gif', 'image/jpeg', 'image/png', 'image/tiff'];

   var isImage = false, _type;
   if (types) {
     imageTypes.forEach(function(t){
       if(types.indexOf(t) !== -1) {
         _type = t;
         isImage = true;
       }
     });
   }

   if (isImage) {
     var uri = dUri.format('.' + mime.extension(_type), result.output);
     $('.hookOutput').html('<img src="' + uri.content + '"/>');
     $('.binaryFileLink').remove();
   }

   // TODO: add audio
   if (!isVideo && !isImage) {
     $('.binaryFileLink').remove();
     $('.hookOutput').html('<textarea cols="80" rows="10" class="hookOutput">' + result.output + '</textarea>');
   }

   $('.hookHeaders').html(JSON.stringify(result.headers, true, 2));
   $('.hookDebugOutput').html(JSON.stringify(result.debug, true, 2));    
   //return callback(null, $.html());

   $('.hookName').html(service.name);
   // $('.httpMethod').html(req.method.toUpperCase());

  }

 var strParams = '';
 var ignoreParams = ['hook', 'subhook', 'username', 'format', 'run'];
 for (var p in params) {
   if (ignoreParams.indexOf(p) === -1) {
     strParams += ("&" + p + "=" + encodeURI(params[p]));
   }
 }

 //$('.forkButton').attr('data-url', 'https://hook.io/' + req.hook.owner + "/" + req.hook.name + "?fork=true");
 //$('.editButton').attr('data-url', 'https://hook.io/' + req.hook.owner + "/" + req.hook.name + "?admin=true");

  // $('.counter').html('<em>' + req.hook.name + ' has run ' + numberWithCommas(req.hook.ran.toString()) + ' times since ' + dateFormat(new Date(req.hook.ctime), "mmmm dS, yyyy, h:MM:ss TT") + '</em>');
  $('.gistEmbed').html('<script src="' + gist + '.js"></script>');
  
  //$('.hookResult').remove();
  if(typeof params.forked !== "undefined") {
    $('.notice').html('<strong>You just forked a Hook!</strong> <br/> <a href="' + gist + '">Click here to view the Gist</a>');
  }

  if (typeof params.created !== "undefined") {
    $('.notice').html('<strong class="success">Hook created!</strong>');
  }

  if (typeof params.alreadyExists !== "undefined") {
    $('.notice').html('<strong class="success">Hook already exists! Here it is.</strong>');
  }

  var formSchema = service.mschema || {};

  for (var p in formSchema) {
    if(typeof params[p] !== 'undefined') {
      formSchema[p].default = params[p];
    }
  }

  formSchema.run = {
    "type": "string",
    "default": "true",
    "format": "hidden"
  };

  formSchema.format = {
    type: "string",
    enum: ["friendly", "raw"],
    default: "friendly"
  };

  formSchema.theme = {
    "type": "string",
    "format": "hidden",
    "default": params.theme
  };

  forms.generate({
    type: "generic",
    form: {
      legend: service.name + ' test form',
      submit: "Test Hook",
      action: "/" + service.owner + "/" + service.name
    },
    schema: formSchema,
    }, function (err, result){
      $('.testForm').html(result);
      $('form legend').append('&nbsp;&nbsp;&nbsp;<button title="Run This Hook" class="run-icon mega-octicon octicon-playback-play"/>')
      
      // $('form legend').append('<div class="counter"><em>Ran ' + req.hook.ran.toString() + ' times since ' + dateFormat(new Date(req.hook.ctime), "mmmm dS, yyyy, h:MM:ss TT") + '</em></div>');
      
      // load gist embed based on incoming gist url parameter
      $('#gistUrl').attr('value', gist);
      callback(null, $.html());
  });

};
Exemple #5
0
function showUserForm (user, cb) {

  var formSchema = userSchema || {};
  formSchema.name = {
    default: user.name,
    disabled: true
  };

  formSchema.email.default = user.email || "";
  formSchema.timezone = {
    type: 'string',
    format: 'select',
    value: user.timezone,
    enum: timezone.listTimeZones()
  };

  formSchema.servicePlan = {
    "type": "string",
    "label": "service plan",
    "disabled": true,
    "default": user.servicePlan
  };

  formSchema.password = {
    "type": "string",
    "format": "password"
  };
  formSchema.confirmPassword = {
    "type": "string",
    "format": "password",
    "label": "confirm password"
  };

  formSchema.previousName = {
    default: user.name,
    format: "hidden"
  };

  /*
  formSchema.githubOAuth = {
    "type": "string",
    "disabled": true,
    "enum": ["true", "false"],
    "default": "false",
    "label": "Account Linked To Github"
  };
  */
  if (typeof user.hostingCredits !== "number") {
    user.hostingCredits = 0;
  }

  if (user.hostingCredits > 0) {
    formSchema.hostingCredits = {
      "type": "number",
      "label": "hosting credits",
      "disabled": true,
      "default": user.hostingCredits
    }
  }

  forms.generate({
    type: "generic",
    form: {
      legend: "Account Information",
      submit: "Save",
      action: ""
    },
    schema: formSchema,
    }, function (err, result){
      cb(null, result);
  });

}
Exemple #6
0
module['exports'] = function billingForm (data, cb) {

  var billingSchema = billingSchema || {};

/*
  billingSchema.name = {
    type: "string",
    default: data.name,
    disabled: true
  };

*/
  billingSchema.method = {
    type: "string",
    default: data.type,
    disabled: true
  };

  var amt = (data.amount / 100).toString() + ".00";
  billingSchema.amount = {
    type: "number",
    default: amt,
    disabled: true
  };

  billingSchema.plan = {
    type: "string",
    default: data.plan,
    disabled: true
  };

 /*
  billingSchema.card_number = {
    type: "string",
    default: data.card_number,
    disabled: true
  };

  billingSchema.card_exp = {
    type: "string",
    default: data.card_exp,
    disabled: true
  };

  billingSchema.card_ccv = {
    type: "string",
    default: data.card_ccv,
    disabled: true
   };
 */
  console.log('using billingSchema', data, billingSchema);

  billingSchema.run = {
    "type": "string",
    "default": "true",
    "format": "hidden"
  };

  forms.generate({
    type: "read-only",
    form: {
      legend: "Billing Information",
      submit: "Update",
      action: ""
    },
    schema: billingSchema,
    }, function (err, result){
      console.log('generated', err, result)
      cb(null, result);
  });

};
Exemple #7
0
module['exports'] = function (opts, cb) {

  var r = opts.resource;
  var html = '';
  var $ = this.$,
    self = this,
    output = '',
    params = opts.params || {},
    query = opts.query || {},
    entity = opts.resource || 'unknown';
     mschemaForms.generate({
       type: "generic",
       form: {
         submit: opts.form.create.submit,
         legend: opts.form.create.legend,
         action: opts.action
       },
       schema: opts.schema
      }, function (err, result) {

        $('.grid').append(result);

        if (params.destroy) {
          // TODO: add role check
          return entity.destroy(params.id, function (err) {
            if (err) {
              return cb(err);
            }
            finish();
          });
        }
        if (typeof params.submitted !== 'undefined') {
          // process posted form data
          entity.create(params, function (err, result){
            if (err) {
              return cb(err);
            }
            finish();
          });
        } else {
          // do nothing
          finish();
        }

        function finish () {

          // why is there a databind happening here? did we need this scope somewhere else for another feature?
          entity.find.call({ req: opts.req, res: opts.res }, query, function (err, results) {
            if (err) {
              return opts.res.end(err.message);
            }

            results = results.filter(function (item) {
              if (item.key_type === "internal") {
                return false;
              }
              return true;
            });

            if (opts.req.jsonResponse) {
              return opts.res.json(results);
            }
            if (results && results.length === 0) {
              cb(null, $.html());
            } else {
              mschemaForms.generate({
                 type: "grid",
                 form: opts.form.grid,
                 schema: opts.schema,
                 data: results
                }, function (err, re) {
                  if (err) {
                    res.end(err.message);
                  }
                  $('.grid').append(re);
                  cb(null, $.html());
               });
            }
          });
        }

     });

}