(function() {
'use strict'
function queryLink() {
return {
restrict: 'E',
scope: {
'query': '=',
'visualization': '=?'
},
template: '{{query.name}}',
link: function(scope, element) {
scope.link = '/queries/' + scope.query.id;
if (scope.visualization) {
if (scope.visualization.type === 'TABLE') {
// link to hard-coded table tab instead of the (hidden) visualization tab
scope.link += '#table';
} else {
scope.link += '#' + scope.visualization.id;
}
}
// element.find('a').attr('href', link);
}
}
}
function querySourceLink() {
return {
restrict: 'E',
template: '\
Show Source\
\
Hide Source\
\
'
}
}
function queryResultCSVLink() {
return {
restrict: 'A',
link: function (scope, element) {
scope.$watch('queryResult && queryResult.getData()', function(data) {
if (!data) {
return;
}
if (scope.queryResult.getId() == null) {
element.attr('href', '');
} else {
element.attr('href', '/api/queries/' + scope.query.id + '/results/' + scope.queryResult.getId() + '.csv');
element.attr('download', scope.query.name.replace(" ", "_") + moment(scope.queryResult.getUpdatedAt()).format("_YYYY_MM_DD") + ".csv");
}
});
}
}
}
function queryEditor() {
return {
restrict: 'E',
scope: {
'query': '=',
'lock': '='
},
template: '