photo context menu: reset coordinates
Signed-off-by: Julien Veyssier <eneiluj@posteo.net>
This commit is contained in:
Родитель
0945319535
Коммит
18a9eb43c3
|
@ -22,6 +22,7 @@ return [
|
|||
['name' => 'photos#getPhotosFromDb', 'url' => '/photos', 'verb' => 'GET'],
|
||||
['name' => 'photos#getNonLocalizedPhotosFromDb', 'url' => '/photos/nonlocalized', 'verb' => 'GET'],
|
||||
['name' => 'photos#placePhotos', 'url' => '/photos', 'verb' => 'POST'],
|
||||
['name' => 'photos#resetPhotosCoords', 'url' => '/photos', 'verb' => 'DELETE'],
|
||||
|
||||
// contacts
|
||||
['name' => 'contacts#getContacts', 'url' => '/contacts', 'verb' => 'GET'],
|
||||
|
|
|
@ -60,6 +60,12 @@ PhotosController.prototype = {
|
|||
that.enterMovePhotoMode();
|
||||
that.map.closePopup();
|
||||
});
|
||||
$('body').on('click', '.resetphoto', function(e) {
|
||||
var ul = $(this).parent().parent();
|
||||
var filePath = ul.attr('filepath');
|
||||
that.resetPhotoCoords([filePath]);
|
||||
that.map.closePopup();
|
||||
});
|
||||
},
|
||||
|
||||
updateMyFirstLastDates: function() {
|
||||
|
@ -423,5 +429,43 @@ PhotosController.prototype = {
|
|||
});
|
||||
},
|
||||
|
||||
resetPhotoCoords: function(paths) {
|
||||
var that = this;
|
||||
$('#navigation-photos').addClass('icon-loading-small');
|
||||
$('.leaflet-container').css('cursor', 'wait');
|
||||
var req = {
|
||||
paths: paths
|
||||
};
|
||||
var url = OC.generateUrl('/apps/maps/photos');
|
||||
$.ajax({
|
||||
type: 'DELETE',
|
||||
url: url,
|
||||
data: req,
|
||||
async: true
|
||||
}).done(function (response) {
|
||||
OC.Notification.showTemporary(t('maps', '{nb} photos reset', {nb: response}));
|
||||
if (response > 0) {
|
||||
that.photosDataLoaded = false;
|
||||
for (var i=0; i < that.photoMarkers.length; i++) {
|
||||
that.photoLayer.removeLayer(that.photoMarkers[i]);
|
||||
}
|
||||
that.photoMarkers = [];
|
||||
that.photoMarkersOldest = null;
|
||||
that.photoMarkersNewest = null;
|
||||
that.photoMarkersFirstVisible = 0;
|
||||
that.photoMarkersLastVisible = -1;
|
||||
that.timeFilterBegin = 0;
|
||||
that.timeFilterEnd = Date.now();
|
||||
|
||||
that.showLayer();
|
||||
}
|
||||
}).always(function (response) {
|
||||
$('#navigation-photos').removeClass('icon-loading-small');
|
||||
$('.leaflet-container').css('cursor', 'grab');
|
||||
}).fail(function(response) {
|
||||
OC.Notification.showTemporary(t('maps', 'Failed to reset photos coordinates') + ': ' + response.responseText);
|
||||
});
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -62,4 +62,12 @@ class PhotosController extends Controller {
|
|||
return new DataResponse($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function resetPhotosCoords($paths) {
|
||||
$result = $this->photofilesService->resetPhotosFilesCoords($this->userId, $paths);
|
||||
return new DataResponse($result);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -236,6 +236,24 @@ class PhotofilesService {
|
|||
return $nbDone;
|
||||
}
|
||||
|
||||
public function resetPhotosFilesCoords($userId, $paths) {
|
||||
$userFolder = $this->root->getUserFolder($userId);
|
||||
$nbDone = 0;
|
||||
|
||||
foreach ($paths as $i => $path) {
|
||||
$cleanpath = str_replace(array('../', '..\\'), '', $path);
|
||||
if ($userFolder->nodeExists($cleanpath)) {
|
||||
$file = $userFolder->get($cleanpath);
|
||||
if ($this->isPhoto($file) and $file->isUpdateable()) {
|
||||
$this->resetExifCoords($file);
|
||||
$this->photoMapper->updateByFileId($file->getId(), null, null);
|
||||
$nbDone++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $nbDone;
|
||||
}
|
||||
|
||||
private function addPhoto($photo, $userId) {
|
||||
$exif = $this->getExif($photo);
|
||||
if (!is_null($exif)) {
|
||||
|
@ -387,9 +405,38 @@ class PhotofilesService {
|
|||
}
|
||||
}
|
||||
|
||||
private function setExifCoords($file, $lat, $lng) {
|
||||
private function resetExifCoords($file) {
|
||||
$path = $file->getStorage()->getLocalFile($file->getInternalPath());
|
||||
|
||||
$data = new PelDataWindow($file->getContent());
|
||||
$pelJpeg = new PelJpeg($data);
|
||||
|
||||
$pelExif = $pelJpeg->getExif();
|
||||
if ($pelExif == null) {
|
||||
$pelExif = new PelExif();
|
||||
$pelJpeg->setExif($pelExif);
|
||||
}
|
||||
|
||||
$pelTiff = $pelExif->getTiff();
|
||||
if ($pelTiff == null) {
|
||||
$pelTiff = new PelTiff();
|
||||
$pelExif->setTiff($pelTiff);
|
||||
}
|
||||
|
||||
$pelIfd0 = $pelTiff->getIfd();
|
||||
if ($pelIfd0 == null) {
|
||||
$pelIfd0 = new PelIfd(PelIfd::IFD0);
|
||||
$pelTiff->setIfd($pelIfd0);
|
||||
}
|
||||
|
||||
$pelSubIfdGps = new PelIfd(PelIfd::GPS);
|
||||
$pelIfd0->addSubIfd($pelSubIfdGps);
|
||||
|
||||
$file->putContent($pelJpeg->getBytes());
|
||||
}
|
||||
|
||||
private function setExifCoords($file, $lat, $lng) {
|
||||
$path = $file->getStorage()->getLocalFile($file->getInternalPath());
|
||||
|
||||
$data = new PelDataWindow($file->getContent());
|
||||
$pelJpeg = new PelJpeg($data);
|
||||
|
|
Загрузка…
Ссылка в новой задаче