refs #3 add ability to choose file type to load when loading folder

merge-requests/1/head
Julien Veyssier 2017-03-27 15:36:25 -03:00
parent 3b0093cd9b
commit 9b8b9aa44c
4 changed files with 45 additions and 10 deletions

View File

@ -268,7 +268,7 @@ class PageController extends Controller {
* @NoAdminRequired
* @NoCSRFRequired
*/
public function getfoldergpxs($path) {
public function getfoldergpxs($path, $type) {
$userFolder = \OC::$server->getUserFolder();
$cleanpath = str_replace(array('../', '..\\'), '', $path);
$gpxs = Array();
@ -277,14 +277,26 @@ class PageController extends Controller {
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')){
if ( ($type === 'all' or $type === '.gpx')
and (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'))
(
( ($type === 'all' or $type === '.kml')
and (endswith($file->getName(), '.KML') or endswith($file->getName(), '.kml'))
)
or
( ($type === 'all' or $type === '.jpg')
and (endswith($file->getName(), '.JPG') or endswith($file->getName(), '.jpg'))
)
or
( ($type === 'all' or $type === '.csv')
and (endswith($file->getName(), '.CSV') or endswith($file->getName(), '.csv'))
)
)
){
$gpxContent = $this->toGpx($file);
array_push($gpxs, $gpxContent);

View File

@ -798,7 +798,19 @@ h2.popupTitle{
#clearButton i{
color: red;
}
#saveButton, #loadButton, #loadFolderButton{
#divloadfolder{
width: 80%;
margin: 0 auto;
}
select#loadtypeselect{
float: right;
}
#loadFolderButton{
float: left;
}
#saveButton, #loadButton{
display:block;
margin-left: auto;
margin-right: auto;

View File

@ -962,8 +962,10 @@
}
function loadFolder(folder) {
var type = $('select#loadtypeselect').val();
var req = {
path: folder
path: folder,
type: type
};
var url = OC.generateUrl('/apps/gpxedit/getfoldergpxs');
$('#loadingpc').text('0');
@ -989,8 +991,6 @@
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');
@ -1514,8 +1514,9 @@
gpxedit.currentAjax.abort();
hideLoadingAnimation();
}
var type = $('select#loadtypeselect').val();
OC.dialogs.filepicker(
t('gpxedit', 'Load folder (all compatible file inside)'),
t('gpxedit', 'Load folder ('+type+')'),
function(targetPath) {
loadFolderAction(targetPath);
},

View File

@ -25,7 +25,17 @@ p($_['gpxedit_version']);
</form>
<hr/>
<button id="loadButton"><i class="fa fa-file-o"></i> <?php p($l->t('Load file'));?></button>
<div id="divloadfolder">
<button id="loadFolderButton"><i class="fa fa-folder-open-o"></i> <?php p($l->t('Load directory'));?></button>
<select id="loadtypeselect">
<option value="all">all</option>
<option value=".jpg">jpg</option>
<option value=".gpx">gpx</option>
<option value=".kml">kml</option>
<option value=".csv">csv</option>
</select>
</div>
<div style="clear:both"></div>
<hr/>
<h2 id="savetitle"><?php p($l->t('Save'));?></h2>
<div>