analytics/assets/js/dashboard/api.js
Uku Taht a2ed7514d7
Improve datepicker (#41)
* Update datepicker dropdown style

* Add custom range for datepicker
2020-03-04 17:24:18 +02:00

27 lines
767 B
JavaScript

import {formatISO} from './date'
function serialize(obj) {
var str = [];
for (var p in obj)
if (obj.hasOwnProperty(p)) {
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
}
return str.join("&");
}
export function serializeQuery(query, extraQuery=[]) {
query = Object.assign({}, query, {
date: query.date ? formatISO(query.date) : undefined,
from: query.from ? formatISO(query.from) : undefined,
to: query.to ? formatISO(query.to) : undefined,
filters: query.filters ? JSON.stringify(query.filters) : undefined
}, ...extraQuery)
return '?' + serialize(query)
}
export function get(url, query, ...extraQuery) {
url = url + serializeQuery(query, extraQuery)
return fetch(url).then(res => res.json())
}