Skip to content

Commit

Permalink
rename thumbnail in api and js code #238
Browse files Browse the repository at this point in the history
  • Loading branch information
nadar committed Nov 21, 2018
1 parent eac7482 commit 1ce9cff
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 173 deletions.
13 changes: 6 additions & 7 deletions src/apis/StorageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,22 +164,21 @@ public function actionImage($id)
*/
public function actionImageInfo($id)
{
$model = StorageImage::find()->where(['id' => $id])->with(['file', 'thumbnail.file'])->one();
$model = StorageImage::find()->where(['id' => $id])->with(['file', 'tinyCropImage.file'])->one();

if (!$model) {
throw new NotFoundHttpException("Unable to find the given storage image.");
}

// try to create thumbnail on view if not done
// @TODO rename to given filters: tinyCropImage and mediumThumbnailImage
if (empty($model->thumbnail)) {
// try to create thumbnail on view if not done
if (empty($model->tinyCropImage)) {
// there are very rare cases where the thumbnail does not exists, therefore generate the thumbnail and reload the model.
Yii::$app->storage->createImage($model->file_id, Yii::$app->storage->getFiltersArrayItem(TinyCrop::identifier())['id']);
// refresh model internal (as $model->refresh() wont load the relations data we have to call the same model with relations again)
$model = StorageImage::find()->where(['id' => $id])->with(['file', 'thumbnail.file'])->one();
$model = StorageImage::find()->where(['id' => $id])->with(['file', 'tinyCropImage.file'])->one();
}

return $model->toArray(['id', 'source', 'file_id', 'filter_id', 'resolution_width', 'resolution_height', 'file'], ['source', 'thumbnail.file']);
return $model->toArray(['id', 'source', 'file_id', 'filter_id', 'resolution_width', 'resolution_height', 'file'], ['source', 'tinyCropImage.file']);
}

/**
Expand All @@ -193,7 +192,7 @@ public function actionImagesInfo()
$ids = Yii::$app->request->getBodyParam('ids', []);
$ids = array_unique($ids);
return new ActiveDataProvider([
'query' => StorageImage::find()->where(['in', 'id', $ids])->with(['file', 'thumbnail.file']),
'query' => StorageImage::find()->where(['in', 'id', $ids])->with(['file', 'tinyCropImage.file']),
'pagination' => false,
]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/resources/dist/js/main.uglified.js

Large diffs are not rendered by default.

169 changes: 5 additions & 164 deletions src/resources/js/directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -2483,13 +2483,13 @@
// now access trough getImage of images service
if ($scope.imageId != 0) {
ServiceImagesData.getImage($scope.imageId).then(function(response) {
if (response.thumbnail) {
$scope.imageSrc = response.thumbnail.source;
if (response.tinyCropImage) {
$scope.imageSrc = response.tinyCropImage.source;
} else {
// the thumbnail does not exists, try to force a new xhr request which should generate the thumbnail:
ServiceImagesData.getImage($scope.imageId, true).then(function(r) {
if (r.thumbnail) {
$scope.imageSrc = r.thumbnail.source;
if (r.tinyCropImage) {
$scope.imageSrc = r.tinyCropImage.source;
}
});
}
Expand All @@ -2511,26 +2511,6 @@
},
controller: ['$scope', '$filter', 'ServiceImagesData', 'ServiceFilesData', function($scope, $filter, ServiceImagesData, ServiceFilesData) {

// ServiceFilesData inheritance

/*
$scope.filesData = ServiceFilesData.data;
$scope.$on('service:FilesData', function(event, data) {
$scope.filesData = data;
});
*/

// ServiceImagesData inheritance

/*
$scope.imagesData = ServiceImagesData.data;
$scope.$on('service:ImagesData', function(event, data) {
$scope.imagesData = data;
});
*/

$scope.$watch('imageId', function(n, o) {
if (n != o) {
$scope.imageSrc = null;
Expand All @@ -2542,7 +2522,7 @@
$scope.$watch(function() { return $scope.imageId }, function(n, o) {
if (n != undefined || n != null) {
ServiceImagesData.getImage(n).then(function(response) {
$scope.imageSrc = response.thumbnail.source;
$scope.imageSrc = response.tinyCropImage.source;
}, function() {
$scope.imageSrc = null;
});
Expand All @@ -2564,20 +2544,6 @@
ngModel : '='
},
controller: ['$scope', '$filter', 'ServiceFilesData', function($scope, $filter, ServiceFilesData) {

// ServiceFilesData inhertiance

/*
$scope.filesData = ServiceFilesData.data;
$scope.$on('service:FilesData', function(event, data) {
$scope.filesData = data;
});
*/

// controller logic

//$scope.ngModel = 0;

$scope.modal = {state: 1};

Expand Down Expand Up @@ -2636,20 +2602,6 @@
},
controller : ['$scope', '$http', '$filter', 'ServiceFiltersData', 'ServiceImagesData', 'AdminToastService', 'ServiceFilesData', function($scope, $http, $filter, ServiceFiltersData, ServiceImagesData, AdminToastService, ServiceFilesData) {

// ServiceImagesData inheritance

/*
$scope.imagesData = ServiceImagesData.data;
$scope.$on('service:ImagesData', function(event, data) {
$scope.imagesData = data;
});
$scope.imagesDataReload = function() {
return ServiceImagesData.load(true);
}
*/

// ServiceFiltesrData inheritance

//$scope.ngModel = 0;
Expand Down Expand Up @@ -2705,44 +2657,8 @@
$scope.thumb = false;
$scope.ngModel = 0;
});

/*
var items = $filter('filter')($scope.imagesData, {fileId: $scope.fileId, filterId: $scope.filterId}, true);
if (items && items.length == 0) {
$scope.imageLoading = true;
// image does not exists make request.
$http.post('admin/api-admin-storage/image-upload', $.param({ fileId : $scope.fileId, filterId : $scope.filterId }), {
headers : {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}
}).then(function(transport) {
if (!transport.data.error) {
$scope.imagesDataReload().then(function(r) {
$scope.ngModel = transport.data.id;
AdminToastService.success(i18n['js_dir_image_upload_ok']);
$scope.imageLoading = false;
});
}
}, function(error) {
AdminToastService.error(i18n['js_dir_image_filter_error']);
$scope.imageLoading = false;
});
} else {
var item = items[0];
$scope.ngModel = item.id
$scope.imageinfo = item;
}
*/
};

/*
$scope.$watch(function() { return $scope.filterId }, function(n, o) {
if (n == null || n == undefined || $scope.fileId == 0 || n == 0) {
return;
}
$scope.filterApply();
});
*/

$scope.changeFilter = function() {
$scope.filterApply();
};
Expand All @@ -2752,21 +2668,6 @@
if (n != null && n != undefined) {
$scope.filterApply();
}


/*
console.log('==> image fileId watch', n, o);
if (n !== undefined && n != null && n != o) {
if (n == 0) {
$scope.filterId = 0;
$scope.imageinfo = null;
$scope.ngModel = 0;
} else {
console.log('[!!!!!!!!!!!!!!]from fileid watcher', n);
$scope.filterApply();
}
}
*/
});

$scope.$watch(function() { return $scope.ngModel }, function(n, o) {
Expand All @@ -2782,73 +2683,13 @@
$scope.thumb = false;
});
}



/*
if (n != 0 && n != null && n !== undefined) {
//var filtering = $filter('findidfilter')($scope.imagesData, n, true);
ServiceImagesData.getImage(n).then(function(response) {
$scope.imageinfo = response;
$scope.fileId = response.file_id;
$scope.filterId = response.filter_id;
});
}
if (n == undefined || n == 0) {
$scope.fileId = 0;
$scope.filterId = 0;
$scope.imageinfo = null;
$scope.thumb = false;
}
*/
});

$scope.applyImageDetails = function(imageInfo) {
$scope.imageinfo = imageInfo;
$scope.thumb = imageInfo;
/*
if (imageInfo.filterId == 0) {
// the original image is usual to bug, therefor we use a thumbnail size instaed
var thumbnail = $filter('findthumbnail')($scope.imagesData, n.fileId, $scope.getThumbnailFilter().id);
} else {
$scope.thumb = imageInfo;
}
*/
};


/*
$scope.getThumbnailFilter = function() {
if ($scope.thumbnailfilter === null) {
if ('medium-thumbnail' in $scope.filtersData) {
$scope.thumbnailfilter = $scope.filtersData['medium-thumbnail'];
}
}
return $scope.thumbnailfilter;
};
*/



/*
$scope.$watch('imageinfo', function(n, o) {
if (n != 0 && n != null && n !== undefined) {
if (n.filterId != 0) {
$scope.thumb = n;
} else {
var result = $filter('findthumbnail')($scope.imagesData, n.fileId, $scope.getThumbnailFilter().id);
if (!result) {
$scope.thumb = n;
} else {
$scope.thumb = result;
}
}
}
})
*/
}],
templateUrl : 'storageImageUpload'
}
Expand Down
2 changes: 1 addition & 1 deletion src/resources/js/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ zaa.factory("ServiceImagesData", ['$http', '$q', '$rootScope', '$log', function(

service.loadImages = function(imagesArray) {
return $q(function(resolve, reject) {
$http.post('admin/api-admin-storage/images-info?expand=source,thumbnail', {ids: imagesArray}).then(function(response) {
$http.post('admin/api-admin-storage/images-info?expand=source,tinyCropImage', {ids: imagesArray}).then(function(response) {
angular.forEach(response.data, function(value) {
service.data[value.id] = value;
});
Expand Down

0 comments on commit 1ce9cff

Please sign in to comment.