Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Getting to a stage where the dummy app actually works

  • Loading branch information...
commit f9c5815480632d33a49851e9a4fe9e58aa1ca133 1 parent 6ccc2bb
jb@kulor.com authored
View
1  app/app.js
@@ -39,6 +39,7 @@ function checkHasPack(req, res, next){
app.get('/admin', adminRoutes.index);
+app.get('/image/imported', generalRoutes.imported);
app.get('/image/import', generalRoutes.importImageForm);
app.post('/image/import', generalRoutes.importImage);
View
18 app/lib/moo.api.card.js
@@ -1,18 +0,0 @@
-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
1  app/lib/moo.api.image.js
@@ -14,6 +14,7 @@ exports.import = function(imageUrl, callback){
"",
conf,
function (error, data, response) {
+ console.log('Image response', data);
callback(error, JSON.parse(data));
});
}
View
70 app/lib/moo.api.pack.js
@@ -4,62 +4,26 @@ 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
- }
- }
- }
- ]
- }
- ]
- };
+ console.log('Create pack API call', appConfig.baseUrl, conf);
+
+ appConfig.oa.post(
+ appConfig.baseUrl,
+ "",
+ "",
+ conf,
+ function (error, data, response) {
+ callback(error, JSON.parse(data));
+ });
+}
+
+exports.update = function(packId, packObj, callback){
+ conf = {};
+ conf.method = 'moo.pack.updatePack';
+ conf.packId = packId;
conf.pack = JSON.stringify(packObj);
- console.log('Create pack API call', appConfig.baseUrl, conf);
+ console.log('Update pack API call', appConfig.baseUrl, conf);
appConfig.oa.post(
appConfig.baseUrl,
View
1  app/package.json
@@ -7,5 +7,6 @@
, "express": "2.5.8"
, "jade": ">= 0.0.1"
, "oauth": ">= 0.0.1"
+ , "clone": ">= 0.0.1"
}
}
View
1  app/routes/admin.js
@@ -1,5 +1,4 @@
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', {
View
90 app/routes/index.js
@@ -1,7 +1,8 @@
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 clone = require('clone');
+
var titleMap = {
businesscard : "Making Business Cards"
};
@@ -14,7 +15,10 @@ exports.index = function(req, res){
};
exports.createCardForm = function(req, res){
- res.render('create_card', { title: 'Create a card' });
+ res.render('create_card', {
+ title: 'Create a card',
+ images: req.session.images || []
+ });
};
exports.createPackForm = function(req, res){
@@ -33,10 +37,77 @@ exports.createPack = function(req, res){
};
exports.createCard = function(req, res){
- mooCardApi.create(req.session.pack, req.body, function(err, data){
+ var frontImageResource = req.session.images[req.body.frontImage];
+ var backImageResource = clone(req.session.images[req.body.backImage]);
+ backImageResource.imageBasketItem.type = 'back';
+ var frontImageData = [
+ {
+ "linkId" : "variable_image_front",
+ "type" : "imageData",
+ "resourceUri" : frontImageResource.imageBasketItem.resourceUri,
+ "enhance" : false,
+ "imageBox" : {
+ "height" : 66,
+ "angle" : 0,
+ "width" : 88,
+ "center" : {
+ "x" : 44,
+ "y" : 29.5
+ }
+ },
+ }
+ ];
+
+ var backImageData = [
+ {
+ "linkId" : "variable_image_details",
+ "type" : "imageData",
+ "resourceUri" : backImageResource.imageBasketItem.resourceUri,
+ "enhance" : false,
+ "imageBox" : {
+ "height" : 66,
+ "angle" : 0,
+ "width" : 88,
+ "center" : {
+ "x" : 44,
+ "y" : 29.5
+ }
+ },
+ }
+ ];
+
+ var packObj = {
+ productVersion: 1,
+ numCards: 50,
+ productCode: 'businesscard' ,
+ sides: [
+ {
+ "templateCode" : "businesscard_full_image_landscape",
+ "type" : "image",
+ "sideNum" : 1,
+ "data" : frontImageData
+ },
+ {
+ "templateCode" : "businesscard_full_image_landscape",
+ "type" : "details",
+ "sideNum" : 2,
+ "data" : backImageData
+ }
+ ],
+ imageBasket : {
+ items : [req.session.images[0].imageBasketItem]
+ }
+ };
+
+ console.log('frontImageResource', frontImageResource);
+ console.log('backImageResource', backImageResource);
+ console.log('packObj', packObj);
+
+ mooPackApi.update(req.session.pack, packObj, function(err, data){
if(err){
return res.send(err, 500);
}
+ console.error('err', err);
console.log('data', data);
res.redirect('/pack/' + req.session.pack);
})
@@ -85,7 +156,16 @@ exports.importImage = function(req, res){
if(err){
return res.send(err, 500);
}
- console.log('data', data);
- res.send(data);
+ req.session.images = req.session.images || [];
+ req.session.images.push(data);
+ res.redirect('/image/imported');
+ })
+};
+
+exports.imported = function(req, res){
+ var imageUrl = req.body.imageUrl;
+ res.render('image/imported', {
+ title: "Imported Images",
+ images: req.session.images
})
};
View
25 app/views/create_card.jade
@@ -3,17 +3,24 @@ form(action="/card/create", method="POST")
.sides
#card-front.side
h2 Front
- img.sample-card(src="/images/card.png")
+ if typeof images !== 'undefined' && images.length
+ each image, key in images
+ li.image
+ input(type="radio", name="frontImage", value=key, checked="checked")
+ img(src=image.imageBasketItem.imageItems[2].resourceUri)
div
- input(type="file", name="imageFile")
+ a(href="/image/import") Import image
#card-back.side
h2 Back
- img.sample-card(src="/images/card.png")
- div
- input(type="file", name="imageFile")
-
-hr
+ if typeof images !== 'undefined' && images.length
+ each image, key in images
+ li.image
+ input(type="radio", name="backImage", value=key, checked="checked")
+ img(src=image.imageBasketItem.imageItems[2].resourceUri)
+ else
+ div
+ a(href="/image/import") Import image
-div
- button.create-pack Generate Cards
+ div
+ button.create-pack(type="submit") Generate Cards
View
2  app/views/image/import.jade
@@ -1,3 +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")
+ input(name="imageUrl", value="http://dribbble.com/system/assets/15/10470/screenshots/588264/credit_card.png?1338747350")
button(type="submit") Add this image thing
View
7 app/views/image/imported.jade
@@ -0,0 +1,7 @@
+h1= title
+a(href="/card/create") Create Card with this image
+ul.images
+ each image in images
+ li.image
+ div=image.imageBasketItem.resourceUri
+ img(src=image.imageBasketItem.imageItems[2].resourceUri)
View
9 app/views/layout.jade
@@ -4,14 +4,5 @@ html
title= title
link(rel='stylesheet', href='/stylesheets/style.css')
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  app/views/pack.jade
@@ -14,5 +14,7 @@ div#pack-detail
#actions
a(href="/card/create") Create Card
+textarea(style="width:100%;height:500px")= JSON.stringify(pack, null, 4)
+
-console.log(pack)
View
8 features/admin.feature
@@ -8,7 +8,7 @@ Feature: Admin panel
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
+ # 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
16 features/card.feature
@@ -3,12 +3,20 @@ Feature: Creating a card
I want to be able to allow people to create custom cards based on my webapp
Scenario: Create card landing page
+ Given I have a sample pack
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
- Scenario: Adding a user
+ @javascript
+ Scenario: Submitting the card to the moo service
Given I have a sample pack
- When I visit "card/create"
- And I click "Create Card From Image"
- Then I should see "50" cards
+ When I visit "/card/create"
+
+ And I click "Import image"
+ And I click "Add this image thing"
+ And I click "Create Card with this image"
+
+ And I click "Generate Cards"
+ And I click "Edit Pack"
+ Then I should see the moo canvas with my cards preloaded
View
5 features/step_definitions/card.rb
@@ -1,4 +1,9 @@
Then /^I should see "(.*?)" cards$/ do |expected_card_count|
cards = page.all('.card')
cards.length.should == expected_card_count
+end
+
+Then /^I should see the moo canvas with my cards preloaded$/ do
+ page.should have_css('#BCDesignImageUI.current', :text => 'Crop your images')
+ sleep 10
end
View
2  features/step_definitions/image.rb
@@ -3,5 +3,5 @@
end
Then /^I should see a list of the images I have uploaded$/ do
- p page.find('.images')
+ page.all('.image img').length.should >= 0
end
Please sign in to comment.
Something went wrong with that request. Please try again.