now able to sort tracks by name or date, order saved in options

Signed-off-by: Julien Veyssier <eneiluj@posteo.net>
This commit is contained in:
Julien Veyssier 2019-07-02 13:09:32 +02:00
Родитель 29889e0777
Коммит 66040fc7bf
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4141FEE162030638
4 изменённых файлов: 79 добавлений и 12 удалений

Просмотреть файл

@ -233,6 +233,12 @@
return parseInt(x);
});
}
if (optionsValues.hasOwnProperty('tracksSortOrder') && optionsValues.tracksSortOrder !== '') {
tracksController.sortOrder = optionsValues.tracksSortOrder;
}
else {
tracksController.sortOrder = 'name';
}
if (getUrlParameter('track') || !optionsValues.hasOwnProperty('tracksEnabled') || optionsValues.tracksEnabled === 'true') {
tracksController.toggleTracks();
}

Просмотреть файл

@ -24,6 +24,7 @@ function TracksController(optionsController, timeFilterController) {
this.changingColorOf = null;
this.lastZIndex = 1000;
this.sortOrder = 'name';
}
TracksController.prototype = {
@ -45,6 +46,17 @@ TracksController.prototype = {
var id = $(this).parent().parent().parent().parent().attr('track');
that.zoomOnTrack(id);
});
// sort
$('body').on('click', '#sort-name-tracks', function(e) {
that.sortOrder = 'name';
that.sortTracks();
that.optionsController.saveOptionValues({tracksSortOrder: 'name'});
});
$('body').on('click', '#sort-date-tracks', function(e) {
that.sortOrder = 'date';
that.sortTracks();
that.optionsController.saveOptionValues({tracksSortOrder: 'date'});
});
// show/hide all tracks
$('body').on('click', '#select-all-tracks', function(e) {
that.showAllTracks();
@ -318,6 +330,15 @@ TracksController.prototype = {
this.trackLayers[track.id].loaded = false;
this.mapTrackLayers[track.id].addLayer(this.trackLayers[track.id]);
this.addMenuEntry(track, color);
// enable if in saved options or if it should be enabled for another reason
if (show || this.optionsController.enabledTracks.indexOf(track.id) !== -1) {
this.toggleTrack(track.id, false, pageLoad, zoom);
}
},
addMenuEntry: function(track, color) {
var name = track.file_name;
var path = track.file_path;
@ -357,25 +378,52 @@ TracksController.prototype = {
'</li>';
var beforeThis = null;
var nameLower = name.toLowerCase();
var trackName;
$('#track-list > li').each(function() {
trackName = $(this).attr('name');
if (nameLower.localeCompare(trackName) < 0) {
beforeThis = $(this);
return false;
}
});
var that = this;
if (this.sortOrder === 'name') {
var nameLower = name.toLowerCase();
var trackName;
$('#track-list > li').each(function() {
trackName = $(this).attr('name');
if (nameLower.localeCompare(trackName) < 0) {
beforeThis = $(this);
return false;
}
});
}
else if (this.sortOrder === 'date') {
var mtime = parseInt(track.mtime);
var tmpMtime;
$('#track-list > li').each(function() {
tmpMtime = parseInt(that.tracks[$(this).attr('track')].mtime);
if (mtime > tmpMtime) {
beforeThis = $(this);
return false;
}
});
}
if (beforeThis !== null) {
$(li).insertBefore(beforeThis);
}
else {
$('#track-list').append(li);
}
},
// enable if in saved options or if it should be enabled for another reason
if (show || this.optionsController.enabledTracks.indexOf(track.id) !== -1) {
this.toggleTrack(track.id, false, pageLoad, zoom);
// wipe track list, then add items again
// take care of enabling selected tracks
sortTracks: function() {
$('#track-list').html('');
var color;
for (var id in this.tracks) {
color = this.trackColors[id];
this.addMenuEntry(this.tracks[id], color);
// select if necessary
var mapTrackLayer = this.mapTrackLayers[id];
var trackLine = $('#track-list > li[track="' + id + '"]');
var trackName = trackLine.find('.track-name');
if (this.mainLayer.hasLayer(mapTrackLayer)) {
trackName.addClass('active');
}
}
},

Просмотреть файл

@ -95,6 +95,7 @@ class TracksController extends Controller {
if (is_array($res) and count($res) > 0) {
$trackFile = $res[0];
if ($trackFile->getType() === \OCP\Files\FileInfo::TYPE_FILE) {
$track['mtime'] = $trackFile->getMTime();
$track['file_name'] = $trackFile->getName();
$track['file_path'] = \preg_replace("/^\/".$this->userId."\/files/", '', $trackFile->getPath());
array_push($existingTracks, $track);

Просмотреть файл

@ -169,6 +169,18 @@
<span><?php p($l->t('Hide all')); ?></span>
</a>
</li>
<li>
<a href="#" id="sort-name-tracks">
<span class="icon-tag"></span>
<span><?php p($l->t('Sort by name')); ?></span>
</a>
</li>
<li>
<a href="#" id="sort-date-tracks">
<span class="icon-calendar-dark"></span>
<span><?php p($l->t('Sort by date')); ?></span>
</a>
</li>
</ul>
</div>
<ul id="track-list">