diff --git a/.gitignore b/.gitignore index 64fd867a0..71909ee81 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,4 @@ gallery-dan todo node_modules npm-debug.log -resizeImages -!node_modules/expect.js/index.js \ No newline at end of file +resizeImages \ No newline at end of file diff --git a/admin/get_gallery_directories.js b/admin/get_gallery_directories.js index e3e760934..379ac97b3 100644 --- a/admin/get_gallery_directories.js +++ b/admin/get_gallery_directories.js @@ -4,7 +4,6 @@ var fs = require('fs'); exports.init = function (param) { var response = param.response, - request = param.request, files = fs.readdirSync('.'), i, len = files.length, diff --git a/app.js b/app.js index 152784360..760fe979f 100644 --- a/app.js +++ b/app.js @@ -1,13 +1,8 @@ /*global __dirname, console, require*/ -var doT = require('doT'), +var adminImageManipulation = require('./js/admin-image-manipulation.js'), express = require('express'), app = express(), expressPort = 80, - constant = { - "debug": false, - "resizeFolder": "resizeImages", - "tempThumbFolder": '_historyThumb' - }, path = require('path'), serveStaticPages = function (param) { var request = param.request, @@ -90,18 +85,18 @@ app.get(/(admin\/walk-path)/, function(request, response) { '/js/global.js', '/js/walk-path-tested.js', '/js/directory-contents.js', - '/lib/jquery-ui-1.10.3.datepicker.sortable/jquery-ui-1.10.3.custom.min.js', + '/lib/jquery-ui-1.11.2.custom/jquery-ui.min.js', '/public/views.js' ], "css": [ - '/lib/jquery-ui-1.10.3.datepicker.sortable/humanity/jquery-ui-1.10.3.custom.min.css', + '/lib/jquery-ui-1.11.2.custom/jquery-ui.min.css', '/css/directory-contents.css' ] } ); }); app.get(/(api\/walk-path)/, function(request, response) { - require('./js/admin-directory-contents-api.js').list({"constant": constant, "request": request, "response": response}); + require('./js/admin-directory-contents-api.js').list({"request": request, "response": response}); }); app.get(/(admin\/diff-album-path)/, function(request, response) { response.render( @@ -120,13 +115,16 @@ app.get(/(admin\/diff-album-path)/, function(request, response) { ); }); app.post(/(admin\/preview-generator)/, function(request, response) { - require('./js/admin-image-manipulation.js').preview({"constant": constant, "request": request, "response": response}); + adminImageManipulation.preview({"request": request, "response": response}); }); app.post(/(admin\/rename-photos)/, function(request, response) { - require('./js/admin-image-manipulation.js').rename({"constant": constant, "request": request, "response": response}); + adminImageManipulation.rename({"request": request, "response": response}); }); app.post(/(admin\/resize-photo)/, function(request, response) { - require('./js/admin-image-manipulation.js').resize({"constant": constant, "request": request, "response": response}); + adminImageManipulation.resize({"request": request, "response": response}); +}); +app.post(/(admin\/delete-path)/, function(request, response) { + adminImageManipulation.deletePath({"request": request, "response": response}); }); app.get('*', function(request, response) { diff --git a/gruntfile.js b/gruntfile.js index a729b9c62..4e838c791 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -31,14 +31,19 @@ module.exports = function (grunt) { }, jshint: { options: { - curly: true, - eqnull: true, - immed: true, - latedef: true, - loopfunc: true, - noarg: true, - sub: true, - undef: true + "curly": true, + "debug": false, + "eqeqeq": true, + "globals": { + "browser": true + }, + "immed": true, + "latedef": true, + "loopfunc": true, + "noarg": true, + "sub": true, + "undef": true, + "unused": true }, adminJs: ['gruntfile.js', 'package.json', 'app.js', 'admin/*.js', 'test/*.js', 'lib/json_to_xml.js'], viewJs: ['js/*.js', '!js/edit_admin_xml.js', '!<%= jshint.viewJsDebug.files.src %>'], diff --git a/js/admin-directory-contents-api.js b/js/admin-directory-contents-api.js index 6ef7a5644..b67a53acf 100644 --- a/js/admin-directory-contents-api.js +++ b/js/admin-directory-contents-api.js @@ -59,8 +59,6 @@ Format directory contents: files or folders as JSON function generateJson(arg) { var currentFolder, filenames, - isFolder, - isRasterFile, jsonPackage = { "items": [] }, len, path = require('path'); @@ -98,6 +96,8 @@ function generateJson(arg) { function getType (extension) { if (extension.toLowerCase().match(/\.(gif|jpg|jpeg|png)$/)) { return "image"; + } else if (extension.toLowerCase().match(/\.(arw|raw|psd)$/)) { + return "source"; } else if (extension.toLowerCase().match(/\.(avi|mov|mp4|mts|qt|webm)$/)) { return "video"; } else if (extension === "") { diff --git a/js/admin-edit-xml-tested.js b/js/admin-edit-xml-tested.js index 1db0dd664..baf6788bc 100644 --- a/js/admin-edit-xml-tested.js +++ b/js/admin-edit-xml-tested.js @@ -1,4 +1,5 @@ /*global $, album, util*/ +/*exported SaveToJson*/ var schema = { "filename": "filename", "city": "photo_city", diff --git a/js/admin-image-manipulation.js b/js/admin-image-manipulation.js index fd82452c7..e7ab7dd36 100644 --- a/js/admin-image-manipulation.js +++ b/js/admin-image-manipulation.js @@ -1,48 +1,49 @@ /*global __dirname, console, module, require*/ var _error = { - "emptyRenameFile": "Empty filename found, cannot rename file", - "missingArg": "Missing required argument", - "missingArgConstant": "Missing required argument global constant", - "missingArgConstantResizeFolder": "Missing required argument resize folder in global constant", - "missingArgCurrentFiles": "Missing required argument current files", - "missingArgFilename": "Missing required argument filename", - "missingArgFolderName": "Missing required argument folder name", - "missingArgMove": "Missing required argument move to resize boolean", - "missingArgNewFiles": "Missing required argument new files", - "missingArgResponse": "Missing required response object", - "missingArgRequest": "Missing required request object", - "missingArgRequestBodyFolder": "Missing required folder in request object", - "missingArgSourcePath": "Missing required argument source path", - "missingArgTargetPath": "Missing required argument target path" -}; + "emptyRenameFile": "Empty filename found, cannot rename file", + "missingArg": "Missing required argument", + "missingArgDestination": "Missing required argument file destination", + "missingArgAssets": "Missing required argument assets", + "missingArgFolderName": "Missing required argument folder name", + "missingArgMove": "Missing required argument move to resize boolean", + "missingArgResponse": "Missing required response object", + "missingArgRequest": "Missing required request object", + "missingArgRequestBodyFolder": "Missing required folder in request object", + "missingArgSource": "Missing required argument file source", + "missingArgTargetPath": "Missing required argument target path" + }, + constant = require("../js/global-constant.js"), + path = require('path'); module.exports.error = _error; - +/*** +* ###### +* # # ##### ###### # # # ###### # # +* # # # # # # # # # # # +* ###### # # ##### # # # ##### # # +* # ##### # # # # # # ## # +* # # # # # # # # ## ## +* # # # ###### ## # ###### # # +* +*/ /** Generate preview sized thumbnail photos for directory viewing @method preview @param {object} arg arguments -@param {object} arg.constant global variables @param {object} arg.body Express POST variables @param {string} arg.body.folder Path to directory @param {object} arg.response @param {object} arg.request -@param {boolean} [arg.isTest] @return {undefined} **/ module.exports.preview = function (arg) { - var constant, - directory = require("../js/admin-directory-contents-api.js"), - isTest, + var directory = require("../js/admin-directory-contents-api.js"), response, request; if (arg === undefined) { throw new ReferenceError(_error.missingArg); } - if (arg.constant === undefined) { - throw new ReferenceError(_error.missingArgConstant); - } if (arg.response === undefined) { throw new ReferenceError(_error.missingArgResponse); } @@ -52,8 +53,6 @@ module.exports.preview = function (arg) { if (arg.request.body === undefined || arg.request.body.folder === undefined) { throw new ReferenceError(_error.missingArgRequestBodyFolder); } - constant = arg.constant; - isTest = arg.isTest || false; response = arg.response; request = arg.request; @@ -74,7 +73,7 @@ module.exports.preview = function (arg) { count.imageLength = json.items.length; function possibleOutput(callee) { var done = false; - if (constant.debug && constant.debug === true) { + if (constant.config.debug && constant.config.debug === true) { console.log("possibleOutput: count.thumbCreated="+count.thumbCreated+"; count.imageLength="+count.imageLength+"; callee="+callee+";"); } if (count.imageLength === 0) { // no images in this directory @@ -98,15 +97,15 @@ module.exports.preview = function (arg) { } function ifImage(item) { function createThumb(item) { - var sourcePath = require('path').dirname(__dirname) + item.path.abs, + var sourcePath = path.dirname(__dirname) + item.path.abs, outputPath, filename = item.name + item.ext; - if (constant.tempThumbFolder) { - outputPath = sourcePath + constant.tempThumbFolder + "/"; + if (constant.config.tempThumbFolder) { + outputPath = sourcePath + constant.config.tempThumbFolder + "/"; } else { outputPath = sourcePath; } - if (constant.debug && constant.debug === true) { + if (constant.config.debug && constant.config.debug === true) { console.log("ifImage: filename="+filename+"; outputPath="+outputPath+";"); } @@ -116,35 +115,35 @@ module.exports.preview = function (arg) { } if (require('fs').existsSync(outputPath + filename)) { // file exists + if (constant.config.debug && constant.config.debug === true) { + console.log("createThumb: file exists:" + outputPath + filename + ";"); + } afterThumbCreated(); return; } - if (constant.debug && constant.debug === true) { + if (constant.config.debug && constant.config.debug === true) { console.log("ifImage resize image: filename="+filename+";"); } - if (isTest) { - afterThumbCreated(); - } else { - require('gm')(sourcePath + filename) - .resize(dimension.width, dimension.height + ">") - .gravity('Center') - .extent(dimension.width, dimension.height) - .write(outputPath + filename, afterThumbCreated); - } + + require('gm')(sourcePath + filename) + .resize(dimension.width, dimension.height + ">") + .gravity('Center') + .extent(dimension.width, dimension.height) + .write(outputPath + filename, afterThumbCreated); }); } if (item.content.type === "image") { - if (constant.debug && constant.debug === true) { + if (constant.config.debug && constant.config.debug === true) { console.log("ifImage; start create thumb"); } createThumb(item); - if (constant.tempThumbFolder) { - out.push(constant.tempThumbFolder + "/" + item.name + item.ext); + if (constant.config.tempThumbFolder) { + out.push(constant.config.tempThumbFolder + "/" + item.name + item.ext); } else { out.push(item.name + item.ext); } } else { - if (constant.debug && constant.debug === true) { + if (constant.config.debug && constant.config.debug === true) { console.log("ifImage; file type="+item.content.type+";"); } afterThumbCreated(); @@ -153,7 +152,7 @@ module.exports.preview = function (arg) { function addToQueue() { var item = json.items[count.imageInitiated]; if (item === undefined) { - if (constant.debug && constant.debug === true) { + if (constant.config.debug && constant.config.debug === true) { console.log("addToQueue; item="+item+";"); } return; @@ -168,7 +167,7 @@ module.exports.preview = function (arg) { } queue = require("async").queue(function (item, callback) { var filename = item.name + item.ext; - if (constant.debug && constant.debug === true) { + if (constant.config.debug && constant.config.debug === true) { console.log("Asynce queue item:"+filename+";"); } ifImage(item); @@ -177,7 +176,12 @@ module.exports.preview = function (arg) { addToQueue(); } - directory.getContents({"folder": decodeURIComponent(request.body.folder)}, ensureShrunkImages); + directory.getContents( + { + "folder": decodeURIComponent(request.body.folder) + }, + ensureShrunkImages + ); }; @@ -186,7 +190,6 @@ Create directory or use existing directory @method ensureDestinationFolder @param {object} arg arguments -@param {object} arg.constant Global variables @param {string} arg.targetFolderName Destination folder's name for this photo batch @param {string} [arg.destinationRootPath=resizeImages] Destination photo path excluding filename @return {string[]} paths to verified directories @@ -198,16 +201,10 @@ function _ensureDestinationFolder(arg) { if (arg === undefined) { throw new ReferenceError(_error.missingArg); } - if (arg.constant === undefined) { - throw new ReferenceError(_error.missingArgConstant); - } - if (arg.constant.resizeFolder === undefined) { - throw new ReferenceError(_error.missingArgConstantResizeFolder); - } if (arg.targetFolderName === undefined) { throw new ReferenceError(_error.missingArgFolderName); } - destinationPath = arg.destinationRootPath || (require('path').dirname(__dirname) + '/' + arg.constant.resizeFolder + '/'); + destinationPath = arg.destinationRootPath || (path.dirname(__dirname) + '/' + constant.config.resizeFolder + '/'); function createOrVerifyFolder(folder) { var folderPath = destinationPath + folder + '/' + arg.targetFolderName; @@ -226,50 +223,91 @@ function _ensureDestinationFolder(arg) { } module.exports.ensureDestinationFolder = _ensureDestinationFolder; +/*** +* ###### ###### +* # # ###### # ###### ##### ###### # # ## ##### # # +* # # # # # # # # # # # # # # +* # # ##### # ##### # ##### ###### # # # ###### +* # # # # # # # # ###### # # # +* # # # # # # # # # # # # # +* ###### ###### ###### ###### # ###### # # # # # # +* +*/ /** Delete path (file or folder) @method deletePath @param {object} arg arguments -@param {string} arg.path -@param {boolean} [arg.isTest] +@param {string} arg.request.body.path || arg.request.body.tempThumbFolder **/ -function _deletePath(arg) { - var isTest, +function _deletePath(arg, unitTestCallback) { + var errors = [], + response, + request, targetPath; if (arg === undefined) { throw new ReferenceError(_error.missingArg); } - if (arg.path === undefined) { + if (arg.request === undefined || arg.request.body === undefined) { throw new ReferenceError(_error.missingArgTargetPath); } - isTest = arg.isTest || false; - targetPath = arg.path; - - if (isTest) { - return "tested"; + if (arg.request.body.path === undefined) { + if (arg.request.body.tempThumbFolder === undefined) { + throw new ReferenceError(_error.missingArgTargetPath); + } else { + targetPath = path.join(arg.request.body.tempThumbFolder, constant.config.tempThumbFolder); + } + } else { + targetPath = path.join(arg.request.body.path); } + response = arg.response; + request = arg.request; + targetPath = path.join(path.dirname(__dirname), targetPath); require('rimraf')(targetPath, function(err) { if (err) { - console.log("Delete failed on this path: " + targetPath + "; with this error message:" + err + ";"); + errors.push("Delete failed on this path: " + targetPath + "; with this error message:" + err + ";"); + } + response.writeHead(200, {'Content-Type': 'application/json'}); + response.end(JSON.stringify( + { + "meta": { + "error": { + "count": errors.length, + "message": errors.join('; ') + }, + "success": { + "message": targetPath + " folder successfully deleted." + } + } + } + )); + if (unitTestCallback) { + unitTestCallback(); } }); } module.exports.deletePath = _deletePath; +/*** +* # # ###### +* ## ## #### # # ###### # # # # #### ##### #### #### +* # # # # # # # # # # # # # # # # # # # +* # # # # # # # ##### ###### ###### # # # # # #### +* # # # # # # # # # # # # # # # # +* # # # # # # # # # # # # # # # # # +* # # #### ## ###### # # # #### # #### #### +* +*/ /** Move source photo to destination originals folder @method movePhotos @param {object} arg arguments - -@param {string} arg.sourceFolderPath Original photo path excluding filename @param {string} [arg.destinationRootPath=resizeImages] Destination photo path excluding filename -@param {string} arg.targetFolderName Destination folder's name for this photo batch inside the originals, photos, or thumbs folders -@param {string[]} arg.newFiles Ordered list of new renamed files (extension excluded) -@param {string[]} arg.currentFiles Ordered list of current files (extension excluded) +@param {object} arg.assets { sort: ["2014-12-18"], "2014-12-18": { files: [ {moved: "", raw: "", renamed: "" } ] } } +@param {boolean} arg.moveToResize Change directory @return {object} arg arguments @return {string[]} arg.files Collection of before and after filename **/ @@ -277,56 +315,34 @@ function _movePhotos(arg, callback) { var afterRename, beforeRename, callbackCount = 0, - constant, destinationPath, files = [], fs = require('fs'), isMoveToResize, - targetFolderName, - queue, - sourceFolderPath; + queue; if (arg === undefined) { throw new ReferenceError(_error.missingArg); } - if (arg.sourceFolderPath === undefined) { - throw new ReferenceError(_error.missingArgSourcePath); - } - if (arg.targetFolderName === undefined) { - throw new ReferenceError(_error.missingArgFolderName); - } - if (arg.currentFiles === undefined || arg.currentFiles.length === 0) { - throw new ReferenceError(_error.missingArgCurrentFiles); + if (arg.assets === undefined) { + throw new ReferenceError(_error.missingArgAssets); } if (arg.moveToResize === undefined) { throw new ReferenceError(_error.missingArgMove); } - if (arg.constant === undefined) { - throw new ReferenceError(_error.missingArgConstant); - } - if (arg.newFiles === undefined || arg.newFiles.length === 0) { - throw new ReferenceError(_error.missingArgNewFiles); - } - constant = arg.constant; - destinationPath = arg.destinationRootPath || (require('path').dirname(__dirname) + '/resizeImages/originals/'); + + destinationPath = arg.destinationRootPath || (path.dirname(__dirname) + '/' + constant.config.resizeFolder + '/originals/'); destinationPath = decodeURIComponent(destinationPath); - isMoveToResize = (arg.moveToResize === "true"); - targetFolderName = arg.targetFolderName; - sourceFolderPath = decodeURIComponent(arg.sourceFolderPath); - - arg.currentFiles.forEach(function (filename, index) { - beforeRename = sourceFolderPath + filename; - if (isMoveToResize) { - afterRename = destinationPath; - if (targetFolderName === "") { - afterRename += "/"; - } else { - afterRename += targetFolderName + "/"; - } - } else { - afterRename = sourceFolderPath; + isMoveToResize = (arg.moveToResize === "true" || arg.moveToResize === true); + + arg.assets.sort.forEach(function (id) { + beforeRename = decodeURIComponent(arg.assets[id].files[0].raw); + afterRename = (isMoveToResize) ? destinationPath + arg.assets[id].files[0].moved : arg.assets[id].files[0].renamed; + + if (constant.config.debug === true) { + console.log("_movePhotos: beforeRename(" + beforeRename + "); afterRename(" + afterRename + ")"); } - afterRename += arg.newFiles[index]; - if (beforeRename === undefined || beforeRename === "" || afterRename === undefined || afterRename === "") { + + if (beforeRename === undefined || beforeRename === "" || afterRename === undefined || afterRename === "") { throw new TypeError(_error.emptyRenameFile); } files.push({ @@ -337,13 +353,11 @@ function _movePhotos(arg, callback) { } }, "destination": { - "filename": arg.newFiles[index], "moved": isMoveToResize, "path": { "type": "absolute", "value": afterRename - }, - "targetFolderName": targetFolderName + } } }); }); @@ -352,10 +366,8 @@ function _movePhotos(arg, callback) { callbackCount++; if (callbackCount === (files.length + 1)) { // +1 for drain - callback({"files": files}); + callback({"assets": files}); } - - _deletePath({"path": sourceFolderPath + constant.tempThumbFolder}); } queue = require("async").queue(function (file, errorCallback) { @@ -363,13 +375,13 @@ function _movePhotos(arg, callback) { if (exists) { fs.rename(file.source.path.value, file.destination.path.value, function (warningRename) { if (warningRename) { - console.log("Image renaming warning: " + warningRename + "; Before filename=" + file.destination.path.value + "; After filename=" + file.source.path.value + ";"); + console.log("Image renaming warning (_movePhotos): " + warningRename + "; Before filename=" + file.destination.path.value + "; After filename=" + file.source.path.value + ";"); } possibleCallback(); }); errorCallback(); } else { - console.log("Image does not exist: " + file.source.path.value + ";"); + console.log("Image does not exist (_movePhotos): " + file.source.path.value + ";"); } }); }, 1); @@ -383,49 +395,46 @@ function _movePhotos(arg, callback) { } module.exports.movePhotos = _movePhotos; - +/*** +* ###### +* # # ###### #### # ###### ###### +* # # # # # # # +* ###### ##### #### # # ##### +* # # # # # # # +* # # # # # # # # +* # # ###### #### # ###### ###### +* +*/ /** Resize solo photo into originals, photos, thumbs folder @method resize @param {object} arg arguments -@param {object} arg.constant Global variables @param {string} arg.targetFolderName Folder to become child of originals, photos, and thumbs **/ module.exports.resize = function (arg) { - var constant = arg.constant, - filename, - fs = require('fs'), + var filename, gm = require('gm'), - path = require('path'), photo = { width: 800, height: 600 }, response = arg.response, request = arg.request, - targetFolderName, thumb = { width: 185, height: 45 }; - targetFolderName = (request.body && request.body.targetFolderName) || arg.targetFolderName; // POST or direct variable - filename = (request.body && request.body.filename) || arg.filename; // POST or direct variable if (arg === undefined) { throw new ReferenceError(_error.missingArg); } - if (targetFolderName === undefined) { - throw new ReferenceError(_error.missingArgFolderName); - } - if (filename === undefined) { - throw new ReferenceError(_error.missingArgFilename); + if (request.body === undefined || request.body.destination === undefined) { + throw new ReferenceError(_error.missingArgDestination); } - function transformImage (originalPaths) { - gm(originalPaths.join("")) + function transformImage (originalPath) { + gm(originalPath) .autoOrient() - .stream(function (errOrient, stdout, stderr) { + .stream(function (errOrient, stdout) { // stderr is third param var callbackCount = 0, callbackTotal = 2, errors = [], - photoPaths = originalPaths.concat([]), - thumbPaths = originalPaths.concat([]); - photoPaths[2] = 'photos'; - thumbPaths[2] = 'thumbs'; + photoPath = originalPath.replace("/originals/", '/photos/'), + thumbPath = originalPath.replace("/originals/", '/thumbs/'); if (errOrient) { errors.push('Original orientation write error: ' + errOrient); @@ -441,13 +450,13 @@ module.exports.resize = function (arg) { "error": { "count": errors.length, "message": errors.join('; ') - }, + } }, "payload": { "paths": { - "original": originalPaths.join(''), - "photo": photoPaths.join(''), - "thumb": thumbPaths.join('') + "original": originalPath, + "photo": photoPath, + "thumb": thumbPath } } } @@ -457,7 +466,7 @@ module.exports.resize = function (arg) { gm(stdout) .resize(photo.width, photo.height) - .write(photoPaths.join(''), function (errResize) { + .write(photoPath, function (errResize) { if (errResize) { errors.push('Photo resize write error: ' + errResize); } @@ -468,7 +477,7 @@ module.exports.resize = function (arg) { gm(stdout) .resize(thumb.width, thumb.height, "!") .noProfile() - .write(thumbPaths.join(''), function (errResize) { + .write(thumbPath, function (errResize) { if (errResize) { errors.push('Thumbnail resize write error: ' + errResize); } @@ -479,80 +488,63 @@ module.exports.resize = function (arg) { ; } - transformImage([path.dirname(__dirname), '/' + constant.resizeFolder + '/', 'originals', '/', targetFolderName, '/', filename]); + filename = request.body.destination.path.value; + transformImage(filename); }; - +/*** +* ###### +* # # ###### # # ## # # ###### +* # # # ## # # # ## ## # +* ###### ##### # # # # # # ## # ##### +* # # # # # # ###### # # # +* # # # # ## # # # # # +* # # ###### # # # # # # ###### +* +*/ /** Rename and move images @method rename @param {object} arg arguments -@param {object} arg.constant Global variables @param {object} arg.response Express response object @param {object} arg.request Express request object @param {object} arg.request.body Express POST object -@param {string} arg.request.body.targetFolderName _ensureDestinationFolder -@param {string[]} arg.request.body.currentFiles See movePhotos -@param {string[]} arg.request.body.moveToResize See movePhotos -@param {string[]} arg.request.body.newFiles See movePhotos -@param {string} arg.request.body.sourceFolderPath See movePhotos -@param {boolean} [arg.isTest] +@param {} arg.request.body.assets See movePhotos +@param {boolean} arg.request.body.moveToResize See movePhotos **/ -module.exports.rename = function (arg) { - var constant, - isTest, - targetFolderName, - response, +module.exports.rename = function (arg, unitTestCallback) { + var response, request; if (arg === undefined) { throw new ReferenceError(_error.missingArg); } - if (arg.constant === undefined) { - throw new ReferenceError(_error.missingArgConstant); - } if (arg.response === undefined) { throw new ReferenceError(_error.missingArgResponse); } if (arg.request === undefined) { throw new ReferenceError(_error.missingArgRequest); } - if (arg.request.body === undefined || arg.request.body.targetFolderName === undefined) { - throw new ReferenceError(_error.missingArgFolderName); - } - if (arg.request.body.sourceFolderPath === undefined) { - throw new ReferenceError(_error.missingArgSourcePath); - } - if (arg.request.body.currentFiles === undefined || arg.request.body.currentFiles.length === 0) { - throw new ReferenceError(_error.missingArgCurrentFiles); + if (arg.request.body === undefined || arg.request.body.assets === undefined || arg.request.body.assets.sort === undefined) { + throw new ReferenceError(_error.missingArgAssets); } if (arg.request.body.moveToResize === undefined) { throw new ReferenceError(_error.missingArgMove); } - if (arg.request.body.newFiles === undefined || arg.request.body.newFiles === 0) { - throw new ReferenceError(_error.missingArgNewFiles); - } - constant = arg.constant; - isTest = arg.isTest || false; response = arg.response; request = arg.request; - targetFolderName = request.body.targetFolderName; - - if (isTest) { - return "tested"; - } - _ensureDestinationFolder({"constant": constant, "targetFolderName": targetFolderName}); + _movePhotos( + request.body, + function (payload) { + var out = {"files": payload.assets}; - _movePhotos({ - "constant": constant, - "currentFiles": request.body.currentFiles, - "targetFolderName": targetFolderName, - "moveToResize": request.body.moveToResize, - "newFiles": request.body.newFiles, - "sourceFolderPath": request.body.sourceFolderPath - }, function (moveArg) { - response.writeHead(200, {'Content-Type': 'application/json'}); - response.end(JSON.stringify({"files": moveArg.files})); - }); + if (unitTestCallback) { + unitTestCallback(out); + } else { + response.writeHead(200, {'Content-Type': 'application/json'}); + response.end(JSON.stringify(out)); + } + } + ); }; \ No newline at end of file diff --git a/js/album-xml.js b/js/album-xml.js index 1addb6988..587c62a69 100644 --- a/js/album-xml.js +++ b/js/album-xml.js @@ -1,4 +1,4 @@ -/*global __dirname, ajaxError, console, jQuery, require, util, window */ +/*global ajaxError, console, jQuery, util, window */ var _error = { "missingArg": "Missing required argument", "missingArgAlbum": "Missing required argument album filename", @@ -7,7 +7,6 @@ var _error = { function _getAlbumXmlAsJson(arg) { "use strict"; - var xmlJsonClass; if (arg === undefined) { throw new ReferenceError(_error.missingArg); } @@ -21,12 +20,12 @@ function _getAlbumXmlAsJson(arg) { function comparePhotoFilename (xml, file) { var idLoop = window.prompt("Starting XML photo ID?", 1), xmlOutput = []; - jQuery.each(xml, function (key, value) { + jQuery.each(xml, function (key) { if (xml[key] !== file[key]) { console.log(xml[key] + " XML filename missing from file. Delete the XML photo element"); } }); - jQuery.each(file, function (key, value) { + jQuery.each(file, function (key) { if (xml[key] !== file[key]) { xmlOutput.push('' + file[key] + ''); idLoop++; diff --git a/js/album.js b/js/album.js index 8c3f28d84..c800fbb97 100644 --- a/js/album.js +++ b/js/album.js @@ -1,5 +1,5 @@ /*global ColorThief, jQuery, Map, Xml, window*/ - +/*exported fOpenWin, fnMedium, triggerLightboxOpen*/ /* GALLERY */ jQuery.noConflict(); /* ALBUM */ @@ -66,13 +66,13 @@ function fOpenWin(sURL, iW, iH, sName, bScrollBars) { iYPos += window.screenY; } else { /* screen width (1 600) not used because I want centred in window on screen */ iXPos = (window.document.body.clientWidth - iW) / 2; /* [current browser chrome width (800) - new window width (400)] / 2 = 200 on each side */ - iBrowserHeight = (window.document.compatMode == "CSS1Compat") ? window.document.documentElement.clientHeight : window.document.body.clientHeight; + iBrowserHeight = (window.document.compatMode === "CSS1Compat") ? window.document.documentElement.clientHeight : window.document.body.clientHeight; iYPos = (iBrowserHeight - iH) / 2; iXPos += window.screenLeft; iYPos += window.screenTop; /* current position of window (400) + iXPos (200) = 600 is left pos */ } /* left space (600) + new width (400) + right space (600) = screen res (1 600) */ - if (typeof bScrollBars == 'boolean') { + if (typeof bScrollBars === 'boolean') { bScrollBars = (bScrollBars === true) ? 'yes' : 'no'; } else { bScrollBars = 'yes'; /* not defined set to default */ @@ -84,8 +84,8 @@ function fOpenWin(sURL, iW, iH, sName, bScrollBars) { } oWin = window.open(sURL, sName, sArgs); - if (oWin != null) { - if (oWin.opener == null) { /* give orphan child window this parent */ + if (oWin !== null && oWin !== undefined) { + if (oWin.opener === null || oWin.opener === undefined) { /* give orphan child window this parent */ oWin.opener = window.self; } oWin.focus(); @@ -112,7 +112,7 @@ function triggerLightboxOpen(objMapLink, strPhotoId) { .trigger('click'); } function displayAlbum (response) { - var intZoom = parseInt(response.json.album.album_meta.geo.google_zoom, 10); + //var intZoom = parseInt(response.json.album.album_meta.geo.google_zoom, 10); map = new Map({ "album": meta.album, diff --git a/js/credentials.js b/js/credentials.js index 374eca827..aa2ab1b47 100644 --- a/js/credentials.js +++ b/js/credentials.js @@ -1,3 +1,4 @@ +/*exported credentials*/ var credentials = { "flickr": { "apiKey": '671aab1520e2cb69e08dd36a5f40213b', diff --git a/js/directory-contents.js b/js/directory-contents.js index d1964d640..cfb839cd1 100644 --- a/js/directory-contents.js +++ b/js/directory-contents.js @@ -1,4 +1,4 @@ -/*global $, ajaxError, console, doT, util, window */ +/*global $, ajaxError, doT, util, window */ (function () { var qs = util.queryObj(), parent = window.walkPath.setParentFolderLink({"querystring": qs}); @@ -58,75 +58,112 @@ function bindEvents() { $("#btnRename, #btnResize").click(function ($event) { var $datepicker, - isMoveToResize = this.id === "btnResize"; + isMoveToResize = (this.id === "btnResize"), + generateFilenames, + xmlOutput = ""; $event.preventDefault(); - function getSelectedDate (formattedDate) { - var currentFiles = [], - newFiles = window.walkPath.getRenamedFiles({ - "filePrefix": formattedDate, - "photosInDay": $(".js-directory-list").children('li[data-type=image]').length, - "xmlStartPhotoId": (isMoveToResize === true) ? window.prompt("Starting XML photo ID?", 1) : 1 - }), - year = formattedDate.substring(0, 4); + + $datepicker = $('
') + .insertAfter(this) + .datepicker({ + "changeMonth": true, + "changeYear": true, + "dateFormat": 'yy-mm-dd', + "onSelect": function (formattedDate) { + $datepicker.datepicker( "destroy" ); - // list of ordered filenames - $('.js-directory-list').each(function (i, dom) { - var $element = $(dom), - filenames = []; - if ($element.children().length !== 0) { - filenames = $element.sortable( "toArray", {"attribute": 'data-filename'}); - currentFiles = currentFiles.concat(filenames); - } - }); + $.ajax({ + "url": '/admin/rename-photos', + "method": 'post', + "data": { + "mediaType": "image", + "moveToResize": isMoveToResize, + "assets": generateFilenames(formattedDate) + }, + "success": function (response) { + var deleteTempThumb = function () { + $.ajax({ + "url": '/admin/delete-path', + "method": 'post', + "data": { + "tempThumbFolder": qs.folder + }, + "error": ajaxError + }); + }, + output = "", + resizeImage = function (postData) { + $.ajax({ + "url": '/admin/resize-photo', + "method": 'post', + "data": postData, + "error": ajaxError + }); + }; - $datepicker.datepicker( "destroy" ); + if (isMoveToResize === true) { + $.each(response.files, function (x, file) { + resizeImage(file); + }); + deleteTempThumb(); + output = xmlOutput; + } else { + output = "Rename successfull"; + } + + $("