Skip to content
This repository has been archived by the owner on Jul 26, 2022. It is now read-only.

Commit

Permalink
Fix Bug 871700 - Basic tag support for Popcorn Maker projects
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher De Cairos committed May 30, 2013
1 parent 4bf2f29 commit 65f9c98
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 37 deletions.
50 changes: 26 additions & 24 deletions lib/project.js
Expand Up @@ -7,7 +7,7 @@ function defaultDBReadyFunction( err ) {
}
}

module.exports = function( config, makeapi, utils, dbReadyFn ) {
module.exports = function( config, makeapiConfig, utils, dbReadyFn ) {
config = config || {};

dbReadyFn = dbReadyFn || defaultDBReadyFunction;
Expand All @@ -16,7 +16,7 @@ module.exports = function( config, makeapi, utils, dbReadyFn ) {
password = config.password || "",
Sequelize = require( "sequelize" ),
sequelize,
makeClient = require( "makeapi" ).makeAPI( makeapi );
makeClient = require( "makeapi" ).makeAPI( makeapiConfig );

try {
sequelize = new Sequelize( config.database, username, password, config.options );
Expand Down Expand Up @@ -139,7 +139,7 @@ module.exports = function( config, makeapi, utils, dbReadyFn ) {
return callback( err );
}

makeClient.remove( result[ 0 ]._id, function( error ) {
makeClient.remove( result[ 0 ].id, function( error ) {
if ( error ) {
return callback( error );
}
Expand Down Expand Up @@ -234,8 +234,8 @@ module.exports = function( config, makeapi, utils, dbReadyFn ) {
return;
}

var projectDataJSON = data.data;
var projectDataString = JSON.stringify( projectDataJSON );
var projectDataJSON = data.data,
projectDataString = JSON.stringify( projectDataJSON );

project.updateAttributes({
data: projectDataString,
Expand All @@ -251,30 +251,32 @@ module.exports = function( config, makeapi, utils, dbReadyFn ) {
.error( function( err ) {
callback( err );
})
.success( function( projectUpdateResult ) {
makeClient.url( utils.generatePublishUrl( projectUpdateResult.id ) ).then(function( err, result ) {
.success( function( project ) {
makeClient.url( utils.generatePublishUrl( project.id ) )
.then( function( err, result ) {
if ( err ) {
return callback( err, projectUpdateResult );
callback( err, project );
return;
}

makeClient.update( result[ 0 ]._id, {
maker: email,
make: {
title: projectUpdateResult.name,
author: projectUpdateResult.author,
email: email,
contentType: "application/x-popcorn",
url: utils.generatePublishUrl( projectUpdateResult.id ),
thumbnail: projectUpdateResult.thumbnail,
description: projectUpdateResult.description,
remixedFrom: projectUpdateResult.remixedFrom
}
}, function( error ) {
if ( error ) {
return callback( error );
var make = result[ 0 ];

make.title = project.name;
make.author = project.author;
make.url = utils.generatePublishUrl( project.id );
make.contentType = "application/x-popcorn";
make.thumbnail = project.thumbnail;
make.description = project.description;
make.email = email;
make.tags = data.tags;

make.update( email, function( err ) {
if ( err ) {
callback( err );
return;
}

callback( null, projectUpdateResult );
callback( null, project );
});
});
});
Expand Down
3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -91,9 +91,8 @@
"knox": "0.7.0",
"less-middleware": "0.1.9",
"less": "1.3.3",
"makeapi": "0.1.5",
"makeapi": "0.1.10",
"mysql": "2.0.0-alpha8",
"makeapi": "0.1.5",
"nconf": "0.6.7",
"newrelic": "0.9.20",
"node-uuid": "1.4.0",
Expand Down
22 changes: 21 additions & 1 deletion public/src/core/project.js
Expand Up @@ -13,6 +13,8 @@ define( [ "core/eventmanager", "core/media", "util/sanitizer" ],
_id, _name, _template, _author, _description, _dataObject,
_publishUrl, _iframeUrl, _remixedFrom, _remixedFromUrl,

_tags = [],

// Whether or not a save to server is required (project data has changed)
_isDirty = false,

Expand Down Expand Up @@ -124,6 +126,19 @@ define( [ "core/eventmanager", "core/media", "util/sanitizer" ],
enumerable: true
},

"tags": {
set: function( val ) {
_tags = val.split( "," ).map(function( v ) {
return v.trim();
});
invalidate();
},
get: function() {
return _tags;
},
enumerable: true
},

"data": {
get: function() {
// Memoize value, since it doesn't always change
Expand Down Expand Up @@ -209,7 +224,6 @@ define( [ "core/eventmanager", "core/media", "util/sanitizer" ],
_this.import = function( json ) {
var oldTarget, targets, targetData,
mediaData, media, m, i, l;

// If JSON, convert to Object
if ( typeof json === "string" ) {
try {
Expand Down Expand Up @@ -243,6 +257,10 @@ define( [ "core/eventmanager", "core/media", "util/sanitizer" ],
_description = json.description;
}

if ( json.tags ) {
_tags = json.tags;
}

if ( json.thumbnail ) {
_thumbnail = json.thumbnail;
}
Expand Down Expand Up @@ -322,6 +340,7 @@ define( [ "core/eventmanager", "core/media", "util/sanitizer" ],
data.template = _template;
data.author = _author;
data.description = _description;
data.tags = _tags.join( "," );
data.thumbnail = _thumbnail;
data.backupDate = Date.now();
try {
Expand Down Expand Up @@ -363,6 +382,7 @@ define( [ "core/eventmanager", "core/media", "util/sanitizer" ],
description: _description,
thumbnail: _thumbnail,
data: _this.data,
tags: _this.tags,
remixedFrom: _remixedFrom
};

Expand Down
3 changes: 3 additions & 0 deletions public/src/editor/project-editor.js
Expand Up @@ -13,6 +13,7 @@ define([ "editor/editor", "editor/base-editor",
_socialMedia = new SocialMedia(),
_projectURL = _rootElement.querySelector( ".butter-project-url" ),
_authorInput = _rootElement.querySelector( ".butter-project-author" ),
_tagInput = _rootElement.querySelector( ".butter-project-tags" ),
_descriptionInput = _rootElement.querySelector( ".butter-project-description" ),
_dropArea = _rootElement.querySelector( ".image-droparea" ),
_thumbnailInput = _rootElement.querySelector( ".butter-project-thumbnail" ),
Expand Down Expand Up @@ -131,6 +132,7 @@ define([ "editor/editor", "editor/base-editor",

applyInputListeners( _authorInput, "author" );
applyInputListeners( _thumbnailInput, "thumbnail" );
applyInputListeners( _tagInput, "tags" );

applyInputListeners( _descriptionInput, "description" );
_descriptionInput.addEventListener( "keyup", checkDescription, false );
Expand Down Expand Up @@ -171,6 +173,7 @@ define([ "editor/editor", "editor/base-editor",
_previewBtn.href = _projectURL.value = _project.publishUrl;
_viewSourceBtn.href = "view-source:" + _project.iframeUrl;
_thumbnailInput.value = _project.thumbnail;
_tagInput.value = _project.tags;
updateEmbed( _project.iframeUrl );

_previewBtn.onclick = function() {
Expand Down
2 changes: 2 additions & 0 deletions public/src/layouts/project-editor.html
Expand Up @@ -31,6 +31,8 @@
<div class="image-droparea">
<div class="droparea-text">Or drag an image here from your desktop</div>
</div>
<label>Tags</label>
<input class="butter-project-tags">
</div>

<!-- Share Container -->
Expand Down
15 changes: 11 additions & 4 deletions routes/index.js
@@ -1,12 +1,13 @@
'use strict';

module.exports = function routesCtor( app, Project, filter, sanitizer,
stores, utils, metrics ) {
stores, utils, metrics, makeapiConfig ) {

var uuid = require( "node-uuid" ),
// Keep track of whether this is production or development
deploymentType = app.settings.env === "production" ? "production" : "development",
api = require( "./api" )( metrics, utils, stores );
api = require( "./api" )( metrics, utils, stores ),
makeClient = require( "makeapi" ).makeAPI( makeapiConfig );

app.get( '/healthcheck', api.healthcheck );

Expand Down Expand Up @@ -112,15 +113,21 @@ module.exports = function routesCtor( app, Project, filter, sanitizer,
projectJSON.remixedFrom = doc.remixedFrom;
projectJSON.remixedFromUrl = utils.generateIframeUrl( doc.remixedFrom );
}
res.json( projectJSON );

makeClient.url( projectJSON.publishUrl ).then(function( err, make ) {
if ( err ) {
res.json( 500, { error: err } );
}
projectJSON.tags = make[ 0 ].tags;
res.json( projectJSON );
});
});
});

// We have a separate remix API for unsecured and sanitized access to projects
app.get( '/api/remix/:id',
filter.isStorageAvailable,
function( req, res ) {

Project.find( { id: req.params.id }, function( err, project ) {
if ( err ) {
res.json( { error: err }, 500 );
Expand Down
13 changes: 7 additions & 6 deletions server.js
Expand Up @@ -22,7 +22,11 @@ var express = require('express'),
APP_HOSTNAME = config.hostname,
WWW_ROOT = path.resolve( __dirname, config.dirs.wwwRoot ),
VALID_TEMPLATES = config.templates,
port = config.PORT;
port = config.PORT,
makeapiConfig= {
apiURL: config.MAKE_ENDPOINT,
auth: config.MAKE_USERNAME + ":" + config.MAKE_PASSWORD
};

var templateConfigs = {};

Expand Down Expand Up @@ -160,10 +164,7 @@ app.configure( function() {
EMBED_SUFFIX: '_'
}, stores );

Project = require( './lib/project' )( config.database, {
apiURL: config.MAKE_ENDPOINT,
auth: config.MAKE_USERNAME + ":" + config.MAKE_PASSWORD
}, utils );
Project = require( './lib/project' )( config.database, makeapiConfig, utils );
filter = require( './lib/filter' )( Project.isDBOnline );
});

Expand All @@ -172,7 +173,7 @@ require( 'express-persona' )( app, {
});

var routes = require('./routes');
routes( app, Project, filter, sanitizer, stores, utils, metrics );
routes( app, Project, filter, sanitizer, stores, utils, metrics, makeapiConfig );

function writeEmbedShell( embedPath, url, data, callback ) {
if( !writeEmbedShell.templateFn ) {
Expand Down

0 comments on commit 65f9c98

Please sign in to comment.