1
0
Fork 0
satnogs-network/network/static/js/observation_view.js

124 lines
4.0 KiB
JavaScript
Raw Normal View History

/* global WaveSurfer URI */
2017-02-11 06:59:02 -07:00
2015-07-01 10:01:20 -06:00
$(document).ready(function() {
'use strict';
// Format time for the player
function formatTime(timeSeconds) {
var minute = Math.floor(timeSeconds / 60);
var tmp = Math.round(timeSeconds - (minute * 60));
var second = (tmp < 10 ? '0' : '') + tmp;
return String(minute + ':' + second);
}
2015-07-01 10:01:20 -06:00
2017-03-27 13:05:24 -06:00
// Set width for not selected tabs
var panelWidth = $('.tab-content').first().width();
2017-03-27 13:05:24 -06:00
$('.tab-pane').css('width', panelWidth);
2015-07-01 10:01:20 -06:00
// Waveform loading
2017-02-11 06:59:02 -07:00
$('.wave').each(function(){
var $this = $(this);
var wid = $this.data('id');
2015-07-01 10:01:20 -06:00
var wavesurfer = Object.create(WaveSurfer);
var data_audio_url = $this.data('audio');
2015-07-06 06:12:33 -06:00
var container_el = '#data-' + wid;
$(container_el).css('opacity', '0');
var loading = '#loading-' + wid;
var $playbackTime = $('#playback-time-' + wid);
var progressDiv = $('#progress-bar-' + wid);
var progressBar = $('.progress-bar', progressDiv);
var showProgress = function (percent) {
if (percent == 100) {
$(loading).text('Analyzing data...');
}
progressDiv.css('display', 'block');
progressBar.css('width', percent + '%');
progressBar.text(percent + '%');
};
var hideProgress = function () {
progressDiv.css('display', 'none');
};
2015-07-01 10:01:20 -06:00
wavesurfer.init({
2017-02-11 06:59:02 -07:00
container: container_el,
waveColor: '#bf7fbf',
progressColor: 'purple'
2015-07-01 10:01:20 -06:00
});
wavesurfer.on('destroy', hideProgress);
wavesurfer.on('error', hideProgress);
wavesurfer.on('loading', function(percent) {
showProgress(percent);
2015-07-06 06:12:33 -06:00
$(loading).show();
});
$this.parents('.observation-data').find('.playpause').click( function(){
2015-07-01 10:01:20 -06:00
wavesurfer.playPause();
});
$('a[href="#tab-audio"]').on('shown.bs.tab', function () {
wavesurfer.load(data_audio_url);
$('a[href="#tab-audio"]').off('shown.bs.tab');
});
2015-07-06 06:12:33 -06:00
wavesurfer.on('ready', function() {
hideProgress();
var spectrogram = Object.create(WaveSurfer.Spectrogram);
spectrogram.init({
wavesurfer: wavesurfer,
container: '#wave-spectrogram',
fftSamples: 256,
windowFunc: 'hann'
});
//$playbackTime.text(formatTime(wavesurfer.getCurrentTime()));
$playbackTime.text(formatTime(wavesurfer.getCurrentTime()));
wavesurfer.on('audioprocess', function(evt) {
$playbackTime.text(formatTime(evt));
});
wavesurfer.on('seek', function(evt) {
$playbackTime.text(formatTime(wavesurfer.getDuration() * evt));
});
2015-07-06 06:12:33 -06:00
$(loading).hide();
$(container_el).css('opacity', '1');
2015-07-06 06:12:33 -06:00
});
2015-04-07 10:00:57 -06:00
});
2016-03-26 08:46:50 -06:00
2017-09-30 08:32:10 -06:00
// Handle Observation tabs
2017-02-11 06:59:02 -07:00
var uri = new URI(location.href);
2017-09-30 08:32:10 -06:00
var tab = uri.hash();
$('.observation-tabs li a[href="' + tab + '"]').tab('show');
// Delete confirmation
2017-02-11 06:59:02 -07:00
var message = 'Do you really want to delete this Observation?';
var actions = $('#obs-delete');
if (actions.length) {
2017-02-11 06:59:02 -07:00
actions[0].addEventListener('click', function(e) {
if (! confirm(message)) {
e.preventDefault();
}
});
}
2017-10-29 04:47:49 -06:00
// Hotkeys bindings
$(document).bind('keyup', function(event){
if (event.which == 88) {
var link_delete = $('#obs-delete');
link_delete[0].click();
} else if (event.which == 68) {
var link_discuss = $('#obs-discuss');
link_discuss[0].click();
} else if (event.which == 71) {
2017-11-18 12:16:21 -07:00
var link_good = $('#good-data');
2017-10-29 04:47:49 -06:00
link_good[0].click();
} else if (event.which == 66) {
var link_bad = $('#bad-data');
link_bad[0].click();
}
});
2014-10-07 12:23:29 -06:00
});