Skip to content

Commit

Permalink
Fixed bug with image upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Fredrik Jonsén committed Oct 16, 2015
1 parent 66257cf commit c10066e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
23 changes: 11 additions & 12 deletions project/static/js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,22 +236,21 @@ function($scope, $rootScope, ChatService) {
}])
.controller('ImageController', ['$scope', 'Upload', 'ImageService', '$modal',
function($scope, Upload, ImageService, $modal) {

ImageService.getImages($scope.id)
.then(function(res) {
$scope.images = res.data;
});
$scope.$watch('file', function() {
if($scope.file && !$scope.file.$error) {
console.dir($scope.file);
Upload.upload({
url: '/addImage',
file: $scope.file
})
.success(function(data) {
$scope.images.push(data);
});
}
});

$scope.upload = function(file) {
Upload.upload({
url: '/addImage',
file: file
})
.success(function(data) {
$scope.images.push(data);
});
};

$scope.open = function(name) {
$scope.activeImage = name;
Expand Down
2 changes: 1 addition & 1 deletion project/static/js/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ function($rootScope, $http, $q, UserService) {
}])
.service('ImageService', ['$http', function($http) {
return {
getImages: (id) => http({
getImages: (id) => $http({
method: 'GET',
url: '/getImages',
params: { id: id }
Expand Down
6 changes: 2 additions & 4 deletions project/static/partials/images.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<section ng-controller="ImageController" class="col-xs-12">
<!--<div ngf-select ngf-drop id="imageUpload" ngf-multiple="false" accept="image/*" ng-model="file" class="imageContainer">Click or drag image here to upload</div>-->
<div ng-if="ownProfile" ngf-drop ngf-select ng-model="file" name="image" class="imageContainer" id="imageUpload"
<div ng-if="ownProfile" ngf-drop ngf-select ng-model="file" ngf-change="upload($file)" name="file" class="imageContainer" id="imageUpload"
ngf-drag-over-class="dragover" ngf-multiple="false" ngf-allow-dir="true"
accept="image/*,application/pdf"
ngf-pattern="'image/*,application/pdf'">Click or drag image here to upload</div>
accept="image/*" ngf-pattern="'image/*'">Click or drag image here to upload</div>
<div ng-repeat="item in images|orderBy:'time':reverse" class="imageContainer" style="background-color:blue;">
<img class="thumbnail" ng-src="images/{{item.name}}" ng-click="open(item.name)"></img>
</div>
Expand Down

0 comments on commit c10066e

Please sign in to comment.