Skip to content

Commit

Permalink
Search results implemented for Dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
jflores1997 committed Jun 18, 2018
1 parent 6acb24c commit 53e1f03
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 20 deletions.
37 changes: 23 additions & 14 deletions js/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
});
Expand All @@ -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);
});
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -567,7 +557,6 @@ class Database {
}
stmt.run(type, tag);
stmt.finalize();
console.log("added favorite: " + tag + ", " + type + ", " + checked);
});
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 = ?"
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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");
Expand Down
41 changes: 38 additions & 3 deletions js/landing.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,55 @@ 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 {
alert("Please input ____ into Search Bar");
}
}

function insertSearchResults(results) {
var template = [
'<div id="" role="tablist" aria-multiselectable="true">',
'<div class="panel panel-default data-panel">',
'<div class="panel-body">',
results,
'</div>',
'</div>',
'</div>',
].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(
Expand Down
16 changes: 13 additions & 3 deletions sections/landing.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div class="inner" style="min-height: 100%; width: device-width">
<div class="input-group custom-search-form form-group-lg absolute-center" style="width: 80%">

<input id="dashSearchId" type="text" class="form-control" placeholder="Search..." style="margin-top: 10%; margin-left: 18%; width: 80% width: 80%">
<input id="dashSearchId" type="text" class="form-control" placeholder="Search for Images or Projects" style="margin-top: 10%; margin-left: 18%; width: 80% width: 80%">

<span class="input-group-btn" style="margin-left: 100%; margin-top: 5%;position: absolute;">
<button class="btn btn-default" type="button" onclick="dashSearch()">
Expand All @@ -16,8 +16,18 @@
</span>
</div>

<div id="result-wrapper"></div>

<div id="result-wrapper">
<!-- <div id="" role="tablist" aria-multiselectable="true">
<div class="panel panel-default data-panel">
<div id="display-fav{{id}}" class="panel-collapse accordian-body" role="tabpanel" aria-labelledby="trigger-fav{{id}}">
<div class="panel-body">
{asda}
</div>
</div>
</div>
</div> -->
</div>

<div class="charts" id="chart-wrapper" style="padding-top:100px">
<div class="row no-side-margins">
<div class="col-xs-6" style="padding-right: 15px">
Expand Down

0 comments on commit 53e1f03

Please sign in to comment.