Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/jwoo12/CMPUT391_W16
Browse files Browse the repository at this point in the history
  • Loading branch information
theresa-cy-ngo committed Mar 29, 2016
2 parents 854297c + 4046621 commit 0a08604
Show file tree
Hide file tree
Showing 8 changed files with 253 additions and 77 deletions.
25 changes: 23 additions & 2 deletions app/display/display.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,34 @@
<script type="text/javascript" src="bower_components/ngGallery/src/js/ngGallery.js"></script>
<link rel="stylesheet" type="text/css" href="bower_components/ngGallery/src/css/ngGallery.css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">

<style>
.ng-scope{
text-align: center;
}


</style>


</head>
<body>
<h1 style="text-align: center;">Display</h1>

<div class="selectedPic">
<image class="photoGallery" style="max-height:400px; max-width:400px; margin-right:5px; border:1px solid black;" ng-src={{selected.src}}></image>
<div class="photo" style="width: 50%; display: inline-block;">
<image class="selectedPhoto" style="max-height:400px; max-width:400px; margin-right:5px; border:1px solid black; margin-left:50px;" ng-src={{selected.src}}></image>
</div>
<div class="photoInfo" style="width: 45%; display: inline-block;">
<p ng-show="selected">Owner: {{selected.owner}}</p>
<p ng-show="selected">Subject: {{selected.subject}}</p>
<p ng-show="selected">Group ID: {{selected.permit}}</p>
<p ng-show="selected">Location: {{selected.place}}</p>
<p ng-show="selected">Date Taken: {{selected.timing}}</p>
<p ng-show="selected">Photo ID: {{selected.id}}</p>
</div>

<button type="button" class="btn btn-primary" style="margin-bottom:100px;" ng-click="editPhoto(photo)" ng-show="selected">Edit Photo</button>
</div>

<div class="myPictures" style="margin-left: 20px; padding-top:10px;">
Expand All @@ -34,7 +55,7 @@ <h3>My Pictures</h3>

<div class="groupPictures" style="margin-left: 20px; padding-top:10px;">
<h3>Group Pictures</h3>
<image class="thumbGallery" style="max-height:100px; max-width:100px; margin-right:5px; border:1px solid black;" ng-repeat="image in groupPictures" ng-src={{image.src}}></image>
<image class="thumbGallery" style="max-height:100px; max-width:100px; margin-right:5px; border:1px solid black;" ng-repeat="image in groupPictures" ng-src={{image.src}} ng-click="showImageDetails(image)"></image>

</div>

Expand Down
32 changes: 26 additions & 6 deletions app/display/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ angular.module("myApp.display", ["ngRoute", "LocalStorageModule", "myApp.display

.controller("displayController", function($scope, $location, localStorageService, displayHandler) {
var usernameFromStorage,
storageKey = "user";
storageKey = "user",
currentImage;

// Initializes array of pictures
$scope.myPictures = [];
$scope.groupPictures = [];
$scope.popularPictures = [];
$scope.selected;

function getItem(key) {
return localStorageService.get(key);
Expand All @@ -28,19 +30,27 @@ angular.module("myApp.display", ["ngRoute", "LocalStorageModule", "myApp.display
}

function parseImageResult (result){
var photo = result.slice(7, result.length-2);
// var photo = result.slice(8, result.length-2);
var photo = result.slice(7, result.length-2);

//console.log(photo);
return photo;
};

function parseThumbResult (result){
var thumb = result.slice(8, result.length-2);
//console.log(thumb);
return thumb;
};

$scope.editPhoto = function(){
displayHandler.curr_image = currentImage;
$location.url("/edit");
}

$scope.showImageDetails = function (selectedImage){
console.log(selectedImage);
//UPDATE IMAGE TRACKING HERE
$scope.selected = selectedImage;
currentImage = selectedImage;
};

// Gets the gallery for the user's uploaded images
Expand All @@ -55,7 +65,9 @@ angular.module("myApp.display", ["ngRoute", "LocalStorageModule", "myApp.display
thumbString = result.data.thumbs[index],
thumb = parseThumbResult(thumbString);

image.src = "data:image/jpeg;base64," + photo;
// image.src = "data:image/jpeg;base64," + photo;
image.src = "data:image/png;base64," + photo;

imageThumb.src = "data:image/png;base64," + thumb;
$scope.myPictures.push({src: image.src,
id: result.data.rows[index][0],
Expand Down Expand Up @@ -85,7 +97,15 @@ angular.module("myApp.display", ["ngRoute", "LocalStorageModule", "myApp.display
image.src = "data:image/png;base64," + photo;
imageThumb.src = "data:image/png;base64," + thumb;
// $scope.groupPictures.push({thumb: image.src, img: image.src, description: result.data.rows[index][3]})
$scope.groupPictures.push({src: image.src});
$scope.groupPictures.push({src: image.src,
id: result.data.rows[index][0],
owner: result.data.rows[index][1],
permit: result.data.rows[index][2],
subject: result.data.rows[index][3],
place: result.data.rows[index][4],
timing: result.data.rows[index][5],
desc: result.data.rows[index][6]
});

}
};
Expand Down
10 changes: 6 additions & 4 deletions app/display/displayHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ angular.module("myApp.display.displayHandler", [])
$http({
url: SERVICE_BASE_URL + "getPopularPictures",
method: "POST",
params: {userName: username}
data: {userName: username}
})
.then(function(result) {
return callback(result);
Expand All @@ -44,11 +44,13 @@ angular.module("myApp.display.displayHandler", [])
});
};

this.editImage = function (photo_id, permitted, subject, loc, date, desc, callback) {
this.editImage = function (requestBody, callback) {
console.log(requestBody);
$http({
url: SERVICE_BASE_URL + "editImage",
url: SERVICE_BASE_URL + "updatePhoto",
method: "POST",
params: {photo_id: photo_id, permitted: permitted, subject: subject, loc: loc, timing: date, desc: desc}
data: requestBody
// {photoid: requestBody.photo_id, permit: requestBody.permitted, subject: requestBody.subject, place: requestBody.loc, timing: requestBody.date, desc: requestBody.desc}
})
.then(function(result) {
return callback(result);
Expand Down
10 changes: 8 additions & 2 deletions app/edit/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
</style>
</head>
<body>

<h1 style="text-align:center;"> Edit an Image </h1>

<div class="photo" style="width: 50%; display: inline-block;">
<image class="selectedPhoto" style="max-height:400px; max-width:400px; margin-right:5px; border:1px solid black; margin-left:50px; margin-top:20px; margin-bottom:30px;" ng-src={{selected.src}}></image>
</div>

<div class="editContainer" style="margin-left:20px;">
<form name="photoForm">

Expand All @@ -46,9 +53,8 @@
<input class="form-control input-lg" ng-model="imgDesc" type="text" required="" style="width: 50%">
</label>

<button class="btn btn-default" ng-click="editImage()" ng-disabled="photoForm.$invalid">EDIT</button>
<button class="btn btn-default" ng-click="editImage()" ng-disabled="photoForm.$invalid" style="margin-bottom:50px;">EDIT</button>
</form>
<!-- ng-disabled="photoForm.$invalid" -->

</div>

Expand Down
53 changes: 30 additions & 23 deletions app/edit/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,8 @@ angular.module("myApp.edit", ["ngRoute", "LocalStorageModule", "ngFileUpload", "
var usernameFromStorage,
storageKey = "user",
selected_image = displayHandler.curr_image;
// ** Need to make sure that the image passed through is actually called curr_image **

// Initialize the page with the pre-existing values
// May need to reformat this to format "yyyy/mm/dd" if original format doesn't work
var imageDate = new Date(selected_image.timing);
$scope.imgPerm = selected_image.permitted;
$scope.imgSubject = selected_image.subject;
$scope.imgLocation = selected_image.place;
$scope.imgWhen = imageDate;
$scope.imgDesc = selected_image.desc;

$scope.selected;

function getItem(key) {
return localStorageService.get(key);
Expand All @@ -34,6 +25,19 @@ angular.module("myApp.edit", ["ngRoute", "LocalStorageModule", "ngFileUpload", "
usernameFromStorage = getItem(storageKey);
}

if(!selected_image){
$location.url("/display");
}else {
var imageDate = new Date(selected_image.timing);
$scope.imgPerm = selected_image.permit;
$scope.imgSubject = selected_image.subject;
$scope.imgLocation = selected_image.place;
$scope.imgWhen = imageDate;
$scope.imgDesc = selected_image.desc;

$scope.selected = selected_image;
}

// Formats the date to be put into the database
function formatDate(date) {
var dd = date.getDate(),
Expand All @@ -48,22 +52,25 @@ angular.module("myApp.edit", ["ngRoute", "LocalStorageModule", "ngFileUpload", "
}
dateString = yyyy + "/" + mm + "/" + dd
return dateString
}

$scope.editImage = function() {
console.log("Editing image")
};

var id = selected_image.id,
permitted = $scope.imgPerm,
subject = $scope.imgSubject,
location = $scope.imgLocation,
date = $scope.imgWhen,
desc = $scope.imgDesc;

date = formatDate(date);
$scope.editImage = function() {
var requestBody = {
photoid : selected_image.id,
permit : $scope.imgPerm,
subject : $scope.imgSubject,
place : $scope.imgLocation,
desc : $scope.imgDesc,
timing : formatDate($scope.imgWhen)
};

uploadHandler.uploadFile(id, permitted, subject, location, date, desc, function(result){
alert("Edited Image");
displayHandler.editImage(requestBody, function(result){
if(result.status !== 200){
alert("Error trying to update. Please try again.")
}else{
alert("Edited Image");
}
});

};
Expand Down
14 changes: 3 additions & 11 deletions app/search/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,12 @@ <h1 style="text-align: center;">Search</h1>
</div>

</div>
</div>

<!-- <form name="searchForm">
<label class="searchLabel" for="keywordInput"> Keywords
<input class="form-control input-sm" ng-model="searchKey" type="text" required="" style="width: 50%">
</label>
<div class="searchResults">

<label class="searchLabel" for="subjectInput"> Timeframe
<input class="form-control input-sm" ng-model="searchTime" type="text" required="" style="width: 50%">
</label>
<image class="resultGallery" style="max-height:100px; max-width:100px; margin:5px 5px 5px 5px; border:1px solid black;" ng-repeat="image in searchResults" ng-src={{image.src}}></image>

<button class="btn btn-default" ng-click="search()">SEARCH</button>
</form>
<! ng-disabled="photoForm.$invalid" -->

</div>

Expand Down
51 changes: 47 additions & 4 deletions app/search/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ angular.module("myApp.search", ["ngRoute", "LocalStorageModule", "myApp.search.s
var usernameFromStorage,
storageKey = "user";

$scope.searchResults = [];

function getItem(key) {
return localStorageService.get(key);
};
Expand Down Expand Up @@ -39,18 +41,57 @@ angular.module("myApp.search", ["ngRoute", "LocalStorageModule", "myApp.search.s
}
dateString = yyyy + "/" + mm + "/" + dd
return dateString
}
};

function parseImageResult (result){
// var photo = result.slice(8, result.length-2);
var photo = result.slice(7, result.length-2);

//console.log(photo);
return photo;
};

displayResults = function (photoResults, rowResults) {
var image = new Image(),
photoString,
photo;


for(var i = 0; i < photoResults.length; i++){
photoString = photoResults[i];
photo = parseImageResult(photoString);

image.src = "data:image/png;base64," + photo;
$scope.searchResults.push({src: image.src,
id: rowResults[i][0],
owner: rowResults[i][1],
permit: rowResults[i][2],
subject: rowResults[i][3],
place: rowResults[i][4],
timing: rowResults[i][5],
desc: rowResults[i][6]
});
}


};



// Search function after the SEARCH button is pressed
$scope.search = function() {
//clear results from previous searches
$scope.searchResults = [];

// Only uses keyword
var keywords = $scope.searchKey,
keyArray = [];
if ($scope.searchKey && !$scope.searchTimeBegin && !$scope.searchTimeEnd){
keyArray = $.map(keywords.split(","), $.trim);
console.log(keyArray);
searchHandler.getKeyResults(usernameFromStorage, keyArray, function(result){
console.log(result.data);
console.log(result.data);
displayResults(result.data.images, result.data.rows);
});

// Only uses time
Expand All @@ -60,7 +101,8 @@ angular.module("myApp.search", ["ngRoute", "LocalStorageModule", "myApp.search.s
timeBegin = formatDate(timeBegin, 0);
timeEnd = formatDate(timeEnd, 1);
searchHandler.getTimeResults(usernameFromStorage, timeBegin, timeEnd, function(result){
console.log(result.data);
console.log(result.data);
displayResults(result.data.images, result.data.rows);
});

// Uses all fields
Expand All @@ -71,7 +113,8 @@ angular.module("myApp.search", ["ngRoute", "LocalStorageModule", "myApp.search.s
timeBegin = formatDate(timeBegin, 0);
timeEnd = formatDate(timeEnd, 1);
searchHandler.getKeyTimeResults(usernameFromStorage, keyArray, timeBegin, timeEnd, function(result){
console.log(result.data);
console.log(result.data);
displayResults(result.data.images, result.data.rows);
});

// All other inputs
Expand Down
Loading

0 comments on commit 0a08604

Please sign in to comment.