Skip to content

Commit

Permalink
group gallery works
Browse files Browse the repository at this point in the history
  • Loading branch information
theresa-cy-ngo committed Mar 26, 2016
1 parent a217196 commit 1eea042
Show file tree
Hide file tree
Showing 3 changed files with 196 additions and 128 deletions.
4 changes: 2 additions & 2 deletions app/display/display.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ <h3>My Pictures</h3>

<div class="groupPictures" style="margin-left: 20px; padding-top:10px;">
<h3>Group Pictures</h3>
<!-- <ng-gallery images="groupPictures">
</ng-gallery> -->
<ng-gallery images="groupPictures">
</ng-gallery>
</div>

<div class="popularPictures" style="margin-left: 20px; padding-top:10px;">
Expand Down
48 changes: 33 additions & 15 deletions app/display/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,43 @@ angular.module("myApp.display", ["ngRoute", "LocalStorageModule", "myApp.display
return thumb;
};

// Gets the gallery for the user's uploaded images
displayHandler.getPictures(usernameFromStorage, function(result){
var index = 0;
for (index; index < result.data.data.length; index++){
var image = new Image(),
photoString = result.data.data[index][8],
photo = parseImageResult(photoString);
var imageThumb = new Image(),
thumbString = result.data.data[index][7],
thumb = parseThumbResult(thumbString);

image.src = "data:image/png;base64," + photo;
imageThumb.src = "data:image/png;base64," + thumb;
$scope.myPictures.push({thumb: imageThumb.src, img: image.src, description: result.data.data[index][3]})
}
//document.body.appendChild(image);
if (result.data.data) {
for (index; index < result.data.data.length; index++){
var image = new Image(),
photoString = result.data.data[index][8],
photo = parseImageResult(photoString);
var imageThumb = new Image(),
thumbString = result.data.data[index][7],
thumb = parseThumbResult(thumbString);

image.src = "data:image/png;base64," + photo;
imageThumb.src = "data:image/png;base64," + thumb;
$scope.myPictures.push({thumb: imageThumb.src, img: image.src, description: result.data.data[index][3]})
}
};
});



// Retrieves the gallery for the user's group and public images
displayHandler.getGroupPictures(usernameFromStorage, function(result){
var index = 0;
if (result.data.data) {
for (index; index < result.data.data.length; index++){
var image = new Image(),
photoString = result.data.data[index][8],
photo = parseImageResult(photoString);
var imageThumb = new Image(),
thumbString = result.data.data[index][7],
thumb = parseThumbResult(thumbString);

image.src = "data:image/png;base64," + photo;
imageThumb.src = "data:image/png;base64," + thumb;
$scope.groupPictures.push({thumb: imageThumb.src, img: image.src, description: result.data.data[index][3]})
}
};
});

// $scope.myPictures = [
// {thumb: 'images/thumbs/1.jpg', img: 'images/1.jpg', description: 'Subject: fkdsj;afljdlka, Location: jfklsajklf;jdsaljdflkas, Description: fdksl;ajlfdjslajfdklsj;'},
Expand Down
272 changes: 161 additions & 111 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -503,117 +503,95 @@ app.post("/getMyPictures", function(req, res){
"FROM images " +
"WHERE images.owner_name = :userName" ,
DBQueryParam = {userName: req.query.userName};
oracledb.getConnection(dbConfig, function (err, connection) {
if (err) {
connectionError(err, res);
return;
}
connection.execute(DBQueryString, DBQueryParam,
function (err, result) {
var lob, buffer, bufferLength;
// Array of promises
var lobLoading = [];
var lobPromises = [];
if (err) {
executeError(err, res);
} else {
result.rows.forEach(function (row, index, array) {
console.log(row);
lob = row[row.length-1];
thumbnailLob = row[row.length-2];
buffer = new Buffer(0);
bufferLength = 0;
thumbnailBuffer = new Buffer(0);
thumbnailBufferLength = 0;
if (lob) {
// Add promise at index
// Have to use index*2 because each row has two blobs
// Q sucks, so we have to make an array of the deferreds and the promises...
lobLoading[index*2] = Q.defer();
lobPromises[index*2] = lobLoading[index*2].promise;
// When data comes in from the stream, add it to the buffer
lob.on("data", function (chunk) {
bufferLength = bufferLength + chunk.length;
buffer = Buffer.concat([buffer, chunk], bufferLength);
});
//When the data is finished coming in, change it to base 64 and add to result
lob.on("end", function () {
result.rows[index][row.length-1] = buffer.toString("base64");
//doRelease(connection);
});
// When the stream closes, resolce the promsie
lob.on("close", function (chunk) {
// Fulfill promise
lobLoading[index*2].resolve();
});
// Make sure we reject the promise when the stream fails so that we don't have a memory leak
lob.on("error", function () {
executeError(err, res);
// Reject promise
lobLoading[index*2].reject();
});
}
if (thumbnailLob) {
// Add promise at index
lobLoading[index*2+1] = Q.defer();
lobPromises[index*2+1] = lobLoading[index*2+1].promise;
// When data comes in from the stream, add it to the buffer
thumbnailLob.on("data", function (chunk) {
thumbnailBufferLength = thumbnailBufferLength + chunk.length;
thumbnailBuffer = Buffer.concat([thumbnailBuffer, chunk], thumbnailBufferLength);
});
//When the data is finished coming in, change it to base 64 and add to result
thumbnailLob.on("end", function () {
result.rows[index][row.length-2] = thumbnailBuffer.toString("base64");
//doRelease(connection);
});
// When the stream closes, resolve the promsie
thumbnailLob.on("close", function (chunk) {
// Fulfill promise
lobLoading[index*2+1].resolve();
});
// Make sure we reject the promise when the stream fails so that we don't have a memory leak
thumbnailLob.on("error", function () {
executeError(err, res);
// Reject promise
lobLoading[index*2+1].reject();
});
}
});
// When all promises complete, return the results
Q.allSettled(lobPromises).then(function () {
doRelease(connection);
res.send({
success: true,
data: result.rows
oracledb.getConnection(dbConfig, function (err, connection) {
if (err) {
connectionError(err, res);
return;
}
connection.execute(DBQueryString, DBQueryParam,
function (err, result) {
var lob, buffer, bufferLength;
// Array of promises
var lobLoading = [];
var lobPromises = [];
if (err) {
executeError(err, res);
} else {
result.rows.forEach(function (row, index, array) {
lob = row[row.length-1];
thumbnailLob = row[row.length-2];
buffer = new Buffer(0);
bufferLength = 0;
thumbnailBuffer = new Buffer(0);
thumbnailBufferLength = 0;
if (lob) {
// Add promise at index
// Have to use index*2 because each row has two blobs
// Q sucks, so we have to make an array of the deferreds and the promises...
lobLoading[index*2] = Q.defer();
lobPromises[index*2] = lobLoading[index*2].promise;
// When data comes in from the stream, add it to the buffer
lob.on("data", function (chunk) {
bufferLength = bufferLength + chunk.length;
buffer = Buffer.concat([buffer, chunk], bufferLength);
});
//When the data is finished coming in, change it to base 64 and add to result
lob.on("end", function () {
result.rows[index][row.length-1] = buffer.toString("base64");
//doRelease(connection);
});
// When the stream closes, resolce the promsie
lob.on("close", function (chunk) {
// Fulfill promise
lobLoading[index*2].resolve();
});
// Make sure we reject the promise when the stream fails so that we don't have a memory leak
lob.on("error", function () {
executeError(err, res);
// Reject promise
lobLoading[index*2].reject();
});
}
if (thumbnailLob) {
// Add promise at index
lobLoading[index*2+1] = Q.defer();
lobPromises[index*2+1] = lobLoading[index*2+1].promise;
// When data comes in from the stream, add it to the buffer
thumbnailLob.on("data", function (chunk) {
thumbnailBufferLength = thumbnailBufferLength + chunk.length;
thumbnailBuffer = Buffer.concat([thumbnailBuffer, chunk], thumbnailBufferLength);
});
//When the data is finished coming in, change it to base 64 and add to result
thumbnailLob.on("end", function () {
result.rows[index][row.length-2] = thumbnailBuffer.toString("base64");
//doRelease(connection);
});
// When the stream closes, resolve the promsie
thumbnailLob.on("close", function (chunk) {
// Fulfill promise
lobLoading[index*2+1].resolve();
});
// Make sure we reject the promise when the stream fails so that we don't have a memory leak
thumbnailLob.on("error", function () {
executeError(err, res);
// Reject promise
lobLoading[index*2+1].reject();
});
}
});
// When all promises complete, return the results
Q.allSettled(lobPromises).then(function () {
doRelease(connection);
res.send({
success: true,
data: result.rows
});
}
});
}

// doRelease(connection);

);
});
}
);
});
});
// oracledb.getConnection(dbConfig, function (err, connection) {
// if (err) {
// connectionError(err, res);
// return;
// }
// connection.execute(DBQueryString, DBQueryParam,
// {autoCommit: true},
// function (err, result) {
// if (err) {
// executeError(err, res);
// } else {
// res.send({success: true, results: result.rows});
// }
// doRelease(connection);
// }
// );
// });


// Retrieves pictures that others uploaded onto the database
app.post("/getGroupPictures", function(req, res){
Expand All @@ -630,14 +608,86 @@ app.post("/getGroupPictures", function(req, res){
return;
}
connection.execute(DBQueryString, DBQueryParam,
{autoCommit: true},
function (err, result) {
var lob, buffer, bufferLength;
// Array of promises
var lobLoading = [];
var lobPromises = [];
if (err) {
executeError(err, res);
} else {
res.send({success: true, results: result.rows});
}
doRelease(connection);
result.rows.forEach(function (row, index, array) {
lob = row[row.length-1];
thumbnailLob = row[row.length-2];
buffer = new Buffer(0);
bufferLength = 0;
thumbnailBuffer = new Buffer(0);
thumbnailBufferLength = 0;
if (lob) {
// Add promise at index
// Have to use index*2 because each row has two blobs
// Q sucks, so we have to make an array of the deferreds and the promises...
lobLoading[index*2] = Q.defer();
lobPromises[index*2] = lobLoading[index*2].promise;
// When data comes in from the stream, add it to the buffer
lob.on("data", function (chunk) {
bufferLength = bufferLength + chunk.length;
buffer = Buffer.concat([buffer, chunk], bufferLength);
});
//When the data is finished coming in, change it to base 64 and add to result
lob.on("end", function () {
result.rows[index][row.length-1] = buffer.toString("base64");
//doRelease(connection);
});
// When the stream closes, resolce the promsie
lob.on("close", function (chunk) {
// Fulfill promise
lobLoading[index*2].resolve();
});
// Make sure we reject the promise when the stream fails so that we don't have a memory leak
lob.on("error", function () {
executeError(err, res);
// Reject promise
lobLoading[index*2].reject();
});
}
if (thumbnailLob) {
// Add promise at index
lobLoading[index*2+1] = Q.defer();
lobPromises[index*2+1] = lobLoading[index*2+1].promise;
// When data comes in from the stream, add it to the buffer
thumbnailLob.on("data", function (chunk) {
thumbnailBufferLength = thumbnailBufferLength + chunk.length;
thumbnailBuffer = Buffer.concat([thumbnailBuffer, chunk], thumbnailBufferLength);
});
//When the data is finished coming in, change it to base 64 and add to result
thumbnailLob.on("end", function () {
result.rows[index][row.length-2] = thumbnailBuffer.toString("base64");
//doRelease(connection);
});
// When the stream closes, resolve the promsie
thumbnailLob.on("close", function (chunk) {
// Fulfill promise
lobLoading[index*2+1].resolve();
});
// Make sure we reject the promise when the stream fails so that we don't have a memory leak
thumbnailLob.on("error", function () {
executeError(err, res);
// Reject promise
lobLoading[index*2+1].reject();
});
}
});
// When all promises complete, return the results
Q.allSettled(lobPromises).then(function () {
doRelease(connection);
console.log(result.rows);
res.send({
success: true,
data: result.rows
});
});
}
}
);
});
Expand Down

0 comments on commit 1eea042

Please sign in to comment.