refs #3 add button to load all compatible files in a folder

merge-requests/1/head
Julien Veyssier 2017-03-27 14:46:04 -03:00
parent 2cefac0323
commit 3b0093cd9b
6 changed files with 134 additions and 5 deletions

View File

@ -21,6 +21,7 @@ return [
'routes' => [ 'routes' => [
['name' => 'page#index', 'url' => '/', 'verb' => 'GET'], ['name' => 'page#index', 'url' => '/', 'verb' => 'GET'],
['name' => 'page#getgpx', 'url' => '/getgpx', 'verb' => 'POST'], ['name' => 'page#getgpx', 'url' => '/getgpx', 'verb' => 'POST'],
['name' => 'page#getfoldergpxs', 'url' => '/getfoldergpxs', 'verb' => 'POST'],
['name' => 'page#savegpx', 'url' => '/savegpx', 'verb' => 'POST'], ['name' => 'page#savegpx', 'url' => '/savegpx', 'verb' => 'POST'],
['name' => 'utils#addTileServer', 'url' => '/addTileServer', 'verb' => 'POST'], ['name' => 'utils#addTileServer', 'url' => '/addTileServer', 'verb' => 'POST'],
['name' => 'utils#deleteTileServer', 'url' => '/deleteTileServer', 'verb' => 'POST'], ['name' => 'utils#deleteTileServer', 'url' => '/deleteTileServer', 'verb' => 'POST'],

View File

@ -176,7 +176,7 @@ class PageController extends Controller {
/** /**
* convert the given file (csv or kml) to gpx and return its content * convert the given file (csv or kml) to gpx and return its content
*/ */
public function toGpx($file){ private function toGpx($file){
$gpsbabel_path = getProgramPath('gpsbabel'); $gpsbabel_path = getProgramPath('gpsbabel');
$data_folder = $this->userAbsoluteDataPath; $data_folder = $this->userAbsoluteDataPath;
$tempdir = $data_folder.'/../cache/'.rand(); $tempdir = $data_folder.'/../cache/'.rand();
@ -263,6 +263,50 @@ class PageController extends Controller {
return $response; return $response;
} }
/**
*
* @NoAdminRequired
* @NoCSRFRequired
*/
public function getfoldergpxs($path) {
$userFolder = \OC::$server->getUserFolder();
$cleanpath = str_replace(array('../', '..\\'), '', $path);
$gpxs = Array();
if ($userFolder->nodeExists($cleanpath)){
$folder = $userFolder->get($cleanpath);
if ($folder->getType() === \OCP\Files\FileInfo::TYPE_FOLDER){
foreach ($folder->getDirectoryListing() as $file) {
if ($file->getType() === \OCP\Files\FileInfo::TYPE_FILE) {
if (endswith($file->getName(), '.GPX') or endswith($file->getName(), '.gpx')){
$gpxContent = $file->getContent();
array_push($gpxs, $gpxContent);
}
else if (getProgramPath('gpsbabel') !== null and
(endswith($file->getName(), '.KML') or endswith($file->getName(), '.kml') or
endswith($file->getName(), '.JPG') or endswith($file->getName(), '.jpg') or
endswith($file->getName(), '.CSV') or endswith($file->getName(), '.csv'))
){
$gpxContent = $this->toGpx($file);
array_push($gpxs, $gpxContent);
}
}
}
}
}
$response = new DataResponse(
[
'gpxs'=>$gpxs
]
);
$csp = new ContentSecurityPolicy();
$csp->addAllowedImageDomain('*')
->addAllowedMediaDomain('*')
->addAllowedConnectDomain('*');
$response->setContentSecurityPolicy($csp);
return $response;
}
/** /**
* *
* @NoAdminRequired * @NoAdminRequired

View File

@ -798,12 +798,12 @@ h2.popupTitle{
#clearButton i{ #clearButton i{
color: red; color: red;
} }
#saveButton, #loadButton{ #saveButton, #loadButton, #loadFolderButton{
display:block; display:block;
margin-left: auto; margin-left: auto;
margin-right: auto; margin-right: auto;
} }
#loadButton i{ #loadButton i, #loadFolderButton i{
color: blue; color: blue;
} }
#saveNameLabel, #savePathLabel{ #saveNameLabel, #savePathLabel{

View File

@ -953,6 +953,74 @@
$('#saving').hide(); $('#saving').hide();
} }
function loadFolderAction(folder) {
loadFolder(folder);
// set save name
var spl = folder.split('/');
var basename = spl[spl.length - 1];
$('input#saveName').val(basename);
}
function loadFolder(folder) {
var req = {
path: folder
};
var url = OC.generateUrl('/apps/gpxedit/getfoldergpxs');
$('#loadingpc').text('0');
showLoadingAnimation();
gpxedit.currentAjax = $.ajax({
type: 'POST',
async: true,
url: url,
data: req,
xhr: function() {
var xhr = new window.XMLHttpRequest();
xhr.addEventListener('progress', function(evt) {
if (evt.lengthComputable) {
var percentComplete = evt.loaded / evt.total * 100;
$('#loadingpc').text(parseInt(percentComplete));
}
}, false);
return xhr;
}
}).done(function (response) {
var i;
if ($('#clearbeforeload').is(':checked')) {
clear();
}
console.log(Object.keys(response));
console.log('len : '+response.gpxs.length);
if (response.gpxs.length === 0) {
OC.dialogs.alert('The folder does not exist or does not contain any compatible file',
'Load folder error');
}
else {
for (i = 0; i < response.gpxs.length; i++) {
parseGpx(response.gpxs[i]);
}
try {
var bounds = gpxedit.editableLayers.getBounds();
gpxedit.map.fitBounds(
bounds,
{
animate: true,
paddingTopLeft: [parseInt($('#sidebar').css('width')), 0]
}
);
}
catch (err) {
console.log('Impossible to fit to bounds \n'+err);
}
}
hideLoadingAnimation();
}).fail(function (){
OC.dialogs.alert('Failed to communicate with the server',
'Load folder error');
hideLoadingAnimation();
});
}
function loadAction(file) { function loadAction(file) {
if ( !endsWith(file, '.gpx') if ( !endsWith(file, '.gpx')
&& !endsWith(file, '.kml') && !endsWith(file, '.kml')
@ -1441,6 +1509,20 @@
); );
}); });
$('button#loadFolderButton').click(function(e) {
if (gpxedit.currentAjax !== null) {
gpxedit.currentAjax.abort();
hideLoadingAnimation();
}
OC.dialogs.filepicker(
t('gpxedit', 'Load folder (all compatible file inside)'),
function(targetPath) {
loadFolderAction(targetPath);
},
false, "httpd/unix-directory", true
);
});
$('button#saveButton').click(function(e) { $('button#saveButton').click(function(e) {
if (gpxedit.editableLayers.getLayers().length === 0) { if (gpxedit.editableLayers.getLayers().length === 0) {
showFailAnimation(t('gpxedit', 'There is nothing to save')); showFailAnimation(t('gpxedit', 'There is nothing to save'));

View File

@ -3,7 +3,8 @@
"loading file" : "chargement du fichier", "loading file" : "chargement du fichier",
"Choose directory and save" : "Choisir un dossier et sauver", "Choose directory and save" : "Choisir un dossier et sauver",
"About GpxEdit" : "À propos de GpxEdit", "About GpxEdit" : "À propos de GpxEdit",
"Load" : "Charger", "Load file" : "Charger un fichier",
"Load directory" : "Charger un dossier",
"Save" : "Enregistrer", "Save" : "Enregistrer",
"Select a file to load it on the map" : "Sélectionner un fichier pour le charger sur la carte", "Select a file to load it on the map" : "Sélectionner un fichier pour le charger sur la carte",
"Select a folder, set a name and click \"Save\" button" : "Sélectionner un dossier, entrer un nom et cliquer sur le bouton \"Enregistrer\"", "Select a folder, set a name and click \"Save\" button" : "Sélectionner un dossier, entrer un nom et cliquer sur le bouton \"Enregistrer\"",

View File

@ -24,7 +24,8 @@ p($_['gpxedit_version']);
<div style="clear:both"></div> <div style="clear:both"></div>
</form> </form>
<hr/> <hr/>
<button id="loadButton"><i class="fa fa-file-o"></i> <?php p($l->t('Load'));?></button> <button id="loadButton"><i class="fa fa-file-o"></i> <?php p($l->t('Load file'));?></button>
<button id="loadFolderButton"><i class="fa fa-folder-open-o"></i> <?php p($l->t('Load directory'));?></button>
<hr/> <hr/>
<h2 id="savetitle"><?php p($l->t('Save'));?></h2> <h2 id="savetitle"><?php p($l->t('Save'));?></h2>
<div> <div>