Permalink
Browse files

Breaking the app up a tad as things arent as discreet in the API as f…

…irst thought
  • Loading branch information...
1 parent 2af7948 commit 6ccc2bb1d7ea4c6849d6f8e61d151e7393b4f37b jb@kulor.com committed Jun 8, 2012
View
@@ -3,8 +3,9 @@
* Module dependencies.
*/
-var express = require('express')
- , routes = require('./routes');
+var express = require('express');
+var generalRoutes = require('./routes/index');
+var adminRoutes = require('./routes/admin');
var app = module.exports = express.createServer();
@@ -13,7 +14,7 @@ var app = module.exports = express.createServer();
app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
- app.use(express.bodyParser());
+ app.use(express.bodyParser({ uploadDir: '/tmp/' }));
app.use(express.cookieParser());
app.use(express.session({ secret: "Mooving target" }));
app.use(express.methodOverride());
@@ -29,14 +30,29 @@ app.configure('production', function(){
app.use(express.errorHandler());
});
-app.get('/', routes.index);
+function checkHasPack(req, res, next){
+ if(!req.session.pack){
+ return res.redirect('/pack/create');
+ }
+ next();
+}
-app.get('/pack/create', routes.createPackForm);
-app.get('/pack/:packId', routes.getPack);
-app.post('/pack/create', routes.createPack);
+app.get('/admin', adminRoutes.index);
-app.get('/card/create', routes.createCardForm);
-app.post('/card/create', routes.createCard);
+app.get('/image/import', generalRoutes.importImageForm);
+app.post('/image/import', generalRoutes.importImage);
+
+app.get('/image/upload', generalRoutes.uploadImageForm);
+app.post('/image/upload', generalRoutes.uploadImage);
+
+app.get('/', generalRoutes.index);
+
+app.get('/pack/create', generalRoutes.createPackForm);
+app.get('/pack/:packId', generalRoutes.getPack);
+app.post('/pack/create', generalRoutes.createPack);
+
+app.get('/card/create', checkHasPack, generalRoutes.createCardForm);
+app.post('/card/create', checkHasPack, generalRoutes.createCard);
app.listen(3000, function(){
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
View
@@ -0,0 +1,18 @@
+var appConfig = require('./moo.api.conf.js').conf;
+
+exports.create = function(packId, conf, callback){
+ conf = conf || {};
+ conf.method = 'moo.image.uploadImage';
+ conf.packId = packId;
+
+ console.log('Create card API call', appConfig.baseUrl, conf);
+
+ appConfig.oa.post(
+ appConfig.baseUrl,
+ "",
+ "",
+ conf,
+ function (error, data, response) {
+ callback(error, JSON.parse(data));
+ });
+}
View
@@ -0,0 +1,37 @@
+var appConfig = require('./moo.api.conf.js').conf;
+var fs = require('fs');
+
+exports.import = function(imageUrl, callback){
+ conf = {};
+ conf.method = 'moo.image.importImage';
+ conf.imageUrl = imageUrl;
+
+ console.log('Import image API call', appConfig.baseUrl, conf);
+
+ appConfig.oa.post(
+ appConfig.baseUrl,
+ "",
+ "",
+ conf,
+ function (error, data, response) {
+ callback(error, JSON.parse(data));
+ });
+}
+
+exports.upload = function(imageFile, callback){
+ conf = {};
+ conf.method = 'moo.image.uploadImage';
+ conf.imageFile = imageFile;
+
+ console.log('Upload image API call', appConfig.baseUrl, conf);
+
+ appConfig.oa.post(
+ appConfig.baseUrl,
+ "",
+ "",
+ conf,
+ 'multipart/form-data',
+ function (error, data, response) {
+ callback(error, JSON.parse(data));
+ });
+}
View
@@ -4,6 +4,60 @@ exports.create = function(conf, callback){
conf = conf || {};
conf.method = 'moo.pack.createPack';
conf.product = 'businesscard';
+ var packObj = {
+ numCards: 50,
+ productCode: 'businesscard' ,
+ sides: [
+ {
+ "templateCode" : "businesscard_full_image_landscape",
+ "type" : "image",
+ "sideNum" : 1,
+ "data" : [
+ {
+ "linkId" : "variable_image_front",
+ "imageStoreFileId" : "7a20d4a4-1518-4ca3-8171-7cb3b4171100",
+ "type" : "imageData",
+ "resourceUri" : "filestore://image_original/7a20d4a4-1518-4ca3-8171-7cb3b4171100.png",
+ "enhance" : false,
+ "imageBox" : {
+ "height" : 66,
+ "angle" : 0,
+ "width" : 88,
+ "center" : {
+ "x" : 44,
+ "y" : 29.5
+ }
+ }
+ }
+ ]
+ },
+
+ {
+ "templateCode" : "businesscard_full_image_landscape",
+ "type" : "image",
+ "sideNum" : 2,
+ "data" : [
+ {
+ "linkId" : "variable_image_front",
+ "imageStoreFileId" : "7a20d4a4-1518-4ca3-8171-7cb3b4171100",
+ "type" : "imageData",
+ "resourceUri" : "filestore://image_original/7a20d4a4-1518-4ca3-8171-7cb3b4171100.png",
+ "enhance" : false,
+ "imageBox" : {
+ "height" : 66,
+ "angle" : 0,
+ "width" : 88,
+ "center" : {
+ "x" : 44,
+ "y" : 29.5
+ }
+ }
+ }
+ ]
+ }
+ ]
+ };
+ conf.pack = JSON.stringify(packObj);
console.log('Create pack API call', appConfig.baseUrl, conf);
@@ -5,4 +5,10 @@ body {
a {
color: #00B7FF;
+}
+
+.side{
+ float:left;
+ clear:none;
+ margin-right:30px;
}
View
@@ -0,0 +1,8 @@
+var mooPackApi = require('../lib/moo.api.pack.js');
+var mooCardApi = require('../lib/moo.api.card.js');
+
+exports.index = function(req, res){
+ res.render('admin/index', {
+ title: 'Admin Panel',
+ });
+};
View
@@ -1,4 +1,6 @@
var mooPackApi = require('../lib/moo.api.pack.js');
+var mooCardApi = require('../lib/moo.api.card.js');
+var mooImageApi = require('../lib/moo.api.image.js');
var titleMap = {
businesscard : "Making Business Cards"
@@ -30,6 +32,16 @@ exports.createPack = function(req, res){
})
};
+exports.createCard = function(req, res){
+ mooCardApi.create(req.session.pack, req.body, function(err, data){
+ if(err){
+ return res.send(err, 500);
+ }
+ console.log('data', data);
+ res.redirect('/pack/' + req.session.pack);
+ })
+};
+
exports.getPack = function(req, res){
packId = req.params.packId;
mooPackApi.get(packId, function(err, data){
@@ -41,4 +53,39 @@ exports.getPack = function(req, res){
pack: data
});
})
+};
+
+exports.importImageForm = function(req, res){
+ res.render('image/import', {
+ title: "Image Importer"
+ })
+};
+
+exports.uploadImageForm = function(req, res){
+ res.render('image/upload', {
+ title: "Image Uploader"
+ });
+};
+
+exports.uploadImage = function(req, res){
+ var imageFile = req.body.imageFile;
+
+ mooImageApi.upload(imageFile, function(err, data){
+ if(err){
+ return res.send(err, 500);
+ }
+ res.send(data);
+ })
+};
+
+
+exports.importImage = function(req, res){
+ var imageUrl = req.body.imageUrl;
+ mooImageApi.import(imageUrl, function(err, data){
+ if(err){
+ return res.send(err, 500);
+ }
+ console.log('data', data);
+ res.send(data);
+ })
};
View
@@ -1,5 +1,19 @@
h1= title
-img.sample-card(src="/images/card.png")
+form(action="/card/create", method="POST")
+ .sides
+ #card-front.side
+ h2 Front
+ img.sample-card(src="/images/card.png")
+ div
+ input(type="file", name="imageFile")
-form(action="/pack/create")
- button.create-pack Create Card
+ #card-back.side
+ h2 Back
+ img.sample-card(src="/images/card.png")
+ div
+ input(type="file", name="imageFile")
+
+hr
+
+div
+ button.create-pack Generate Cards
@@ -0,0 +1,3 @@
+form(action="/image/import", method="POST")
+ input(name="imageUrl", value="http://upload.wikimedia.org/wikipedia/commons/thumb/c/ca/Niobe050905-Siamese_Cat.jpeg/220px-Niobe050905-Siamese_Cat.jpeg")
+ button(type="submit") Add this image thing
@@ -0,0 +1,3 @@
+form(action="/image/upload", method="POST", enctype="multipart/form-data")
+ input(name="imageFile", type="file")
+ button(type="submit") Add this image
View
@@ -3,4 +3,15 @@ html
head
title= title
link(rel='stylesheet', href='/stylesheets/style.css')
- body!= body
+ body
+ a(href="/admin") Admin
+ //- #nav
+ //- ul
+ //- li
+ //- a(href="/pack/create") Create Pack
+ //- li
+ //- a(href="/side/create") Create Side
+ //- li
+ //- a(href="/image/upload") Upload Image
+ #content!= body
+
View
@@ -2,8 +2,10 @@ h1= title
div#pack-detail
p
- span Pack ID:
- span#pack-id= pack.packId
+ span
+ a(href="http://uk.testing1.office.moo.com/create/design.php?uuid=" + pack.packId) Edit Pack
+ span#pack-id
+ = pack.packId
p
span Number of Cards:
View
@@ -0,0 +1,14 @@
+Feature: Admin panel
+ As a third party developer
+ I want to be able to change the settings of my widget
+
+ Scenario: Importing images
+ When I visit "image/import"
+ And I import the image "http://uk.moo.com/images/logo/logo_no_stripe_green.png"
+ And I submit the form
+ Then I should see a list of the images I have uploaded
+
+ Scenario: Uploading images
+ When I visit "image/upload"
+ And I upload a sample image "foo.gif"
+ Then I should see a list of the images I have uploaded
View
@@ -1,9 +1,14 @@
-@pending
Feature: Creating a card
As a third party developer
I want to be able to allow people to create custom cards based on my webapp
- Scenario: Adding a user
+ Scenario: Create card landing page
When I visit "card/create"
Then I should get the title "Create a card"
- And there should be a sample image of a credit card
+ And there should be a sample image of a credit card
+
+ Scenario: Adding a user
+ Given I have a sample pack
+ When I visit "card/create"
+ And I click "Create Card From Image"
+ Then I should see "50" cards
View
@@ -1,7 +1,7 @@
-@pending
Feature: Creating a pack
As a third party developer
I want to be able to allow people to create custom cards based on my webapp
+ This will allow me to add custom cards to a collection
Scenario: Creating a pack
When I visit "pack/create"
@@ -0,0 +1,4 @@
+Then /^I should see "(.*?)" cards$/ do |expected_card_count|
+ cards = page.all('.card')
+ cards.length.should == expected_card_count
+end
@@ -0,0 +1,7 @@
+When /^I import the image "(.*?)"$/ do |url|
+ fill_in 'imageUrl', :with => url
+end
+
+Then /^I should see a list of the images I have uploaded$/ do
+ p page.find('.images')
+end
@@ -21,4 +21,8 @@
Then /^I should see a button or link "(.*?)"$/ do |button_text|
page.should have_css('button,a', :text => button_text)
+end
+
+When /^I submit the form$/ do
+ page.find('button').click
end

0 comments on commit 6ccc2bb

Please sign in to comment.