diff --git a/js/database.js b/js/database.js index 86a9724..e8ee297 100644 --- a/js/database.js +++ b/js/database.js @@ -5,7 +5,6 @@ const sqlite3 = require('sqlite3') // Get the user data path, the directory in which the information will be stored. const userDataPath = (electron.app || electron.remote.app).getPath('userData'); const db_filename = path.join(userDataPath, 'meta.db'); - console.log(db_filename); class Database { @@ -92,8 +91,6 @@ class Database { /* Uses callback(boolean) to return if image was added successfully or not. */ add_image(img_name, img_path, proj_name, index, num_images, callback) { - console.log("adding image: " + img_name); - // Check if image has been made yet, if not create it var _this = this; var db = this.db; @@ -328,14 +325,11 @@ class Database { if (bool) { var fave_int = fave_bool ? 1 : 0; var query = "UPDATE Images SET favorited=? WHERE path=? AND proj_name=?"; - console.log(query, "query"); var stmt = db.prepare(query); stmt.run([fave_int, img_path, proj_name]); stmt.finalize(); success = true; - console.log('add_favorite_image: image', img_path, 'favorited', proj_name); } else { - console.log('add_favorite_image: image', img_path, 'does not exist in', proj_name); } callback(img_path, proj_name, fave_bool, success); }); @@ -357,13 +351,10 @@ class Database { stmt.run([new_name, old_name]); stmt.finalize(); success = true; - console.log('update_project_name: proj', old_name, 'updated', new_name); } else { - console.log("update_project_name: proj", new_name, "is already a project"); } }); } else { - console.log('update_project_name: proj', old_name, 'does not exist'); } callback(old_name, new_name, success); }); @@ -494,7 +485,6 @@ class Database { images.push(row); }, function() { - console.log('get_favorite_images_in_project:', images, 'in', proj_name); callback(proj_name, images); }); stmt.finalize(); @@ -567,7 +557,6 @@ class Database { } stmt.run(type, tag); stmt.finalize(); - console.log("added favorite: " + tag + ", " + type + ", " + checked); }); } @@ -617,6 +606,29 @@ class Database { }); } + /* Uses callback(bool, img_name, proj_names) to return list of projects containing img_name. */ + get_projects_with_image(img_name, callback) { + var _this = this; + var db = this.db; + db.serialize(function() { + var stmt = db.prepare("SELECT proj_name FROM Images WHERE img_name=?"); + stmt.all([img_name], function(err, rows) { + if (err) { + console.error(err); + } + if (rows != null && rows.length > 0) { + var proj_names = []; + for (var index in rows) { + proj_names.push(rows[index]['proj_name']); + } + callback(true, img_name, proj_names); + } else { + callback(false, img_name, rows); + } + }); + }); + } + /* Uses callback(bool, img_name, img_path, proj_name, {}) to return dict of metafields to metadata. * Ignores any fields that are not filled in. */ get_image_metadata(img_path, img_name, proj_name, callback) { @@ -664,7 +676,6 @@ class Database { if (bool) { _this.has_metadata_attr(['CreateDate'], function(attr_exists) { if (attr_exists) { - console.log("CreateDate exists"); var dates = []; var counts = []; var stmt_str = "SELECT CreateDate, COUNT(*) as Count FROM Images WHERE proj_name = ?" @@ -725,7 +736,6 @@ class Database { coords.push({'lat': JSON.parse(row['GPSLatitude']), 'lng': JSON.parse(row['GPSLongitude'])}); }, function() { - console.log('get_locations_for_images:', coords, 'in', proj_name); callback(coords); }); stmt.finalize(); @@ -830,7 +840,6 @@ class Database { db.serialize(function() { _this.has_metadata_attr(['CreateDate'], function(attr_exists) { if (attr_exists) { - console.log("CreateDate exists"); var dates = []; var counts = []; var stmt = db.prepare("SELECT CreateDate, COUNT(*) as Count FROM Images WHERE CreateDate IS NOT NULL GROUP BY CreateDate"); diff --git a/js/landing.js b/js/landing.js index c666bec..b2e030c 100644 --- a/js/landing.js +++ b/js/landing.js @@ -23,13 +23,29 @@ Chart.plugins.register({ var database = electron.remote.getGlobal('sharedObj').db; function dashSearch() { + clearSearchResults(); + + var results = []; var searchId = $("#dashSearchId").val(); if (searchId) { database.has_project(searchId, function(bool) { - if (!bool) { - alert("Search could not find any match."); + var result; + if (bool) { + result = searchId; + } else { + result = "No Projects Found: " + searchId; + } + insertSearchResults(result); + //loadDetail(searchId); + }); + + database.get_projects_with_image(searchId, function(bool, img_name, proj_names) { + if (bool) { + for (var index in proj_names) { + insertSearchResults(proj_names[index]); + }; } else { - loadDetail(searchId); + insertSearchResults("No Images Found: " + searchId); } }); } else { @@ -37,6 +53,25 @@ function dashSearch() { } } +function insertSearchResults(results) { + var template = [ + '
', + '
', + '
', + results, + '
', + '
', + '
', + ].join("\n"); + + var filler = Mustache.render(template, results); + $("#result-wrapper").append(filler); +} + +function clearSearchResults() { + document.getElementById("result-wrapper").innerHTML = ""; +} + function create_image_timeline_chart() { database.get_all_image_dates(function(dates, counts) { addLineChart( diff --git a/sections/landing.html b/sections/landing.html index 4db7379..917ffd3 100644 --- a/sections/landing.html +++ b/sections/landing.html @@ -7,7 +7,7 @@
- +
-
- +
+ +
+