Loading responses...
JSON definition · shared/definitions/dashboard.json
View on GitHub
{
"title": "Product feedback",
"elements": [
{
"type": "rating",
"name": "satisfaction",
"title": "How satisfied are you with the product?",
"rateMin": 1,
"rateMax": 5
},
{
"type": "rating",
"name": "recommend",
"title": "How likely are you to recommend us?",
"rateMin": 0,
"rateMax": 10
},
{
"type": "radiogroup",
"name": "channel",
"title": "Where did you hear about us?",
"choices": [
"Search",
"Social media",
"A colleague",
"Conference"
]
},
{
"type": "checkbox",
"name": "features",
"title": "Which features do you use?",
"choices": [
"Forms",
"Dashboard",
"Creator",
"PDF export"
]
},
{
"type": "comment",
"name": "improve",
"title": "What should we improve?"
}
]
}
Client · shared/client/dashboard.js · sjs:dashboard.client
View on GitHub
// Load answers with their submission dates for Dashboard's built-in date filter
async function loadResults(signal) {
const query = new URLSearchParams({ formId: "feedback", includeCreatedAt: "1", limit: "5000" });
const [definition, response] = await Promise.all([
loadSchema(), fetch(`/api/responses?${query}`, { signal })
]);
if (!response.ok) throw new Error("Responses load failed");
const data = await response.json();
if (!Array.isArray(data)) throw new Error("Invalid responses");
return { definition, data: data.map(row => ({ ...row.data, createdAt: row.createdAt })) };
}
function renderResults(definition, data) {
if (!dashboard) {
const survey = new Model(definition);
dashboard = new Dashboard({
questions: survey.getAllQuestions(), data,
dateFieldName: "createdAt", datePeriod: "last30days"
});
dashboard.render(container);
} else {
dashboard.updateData(data);
}
}
Server · examples/views/dashboard.py · sjs:dashboard.server
View on GitHub
# GET /api/responses?formId=&includeCreatedAt=&from=&to=&limit=&offset=
def responses(request: HttpRequest) -> HttpResponse:
query = request.GET
try: # page on the server for large volumes
limit, offset = min(max(int(query.get("limit", 500)), 1), 5000), max(int(query.get("offset", 0)), 0)
except ValueError:
return JsonResponse({"error": "limit and offset must be whole numbers"}, status=400)
rows = Response.objects.filter(form_id=query.get("formId", ""), created_at__gte=query.get("from", ""))
if to := query.get("to"): # ISO 8601 UTC strings compare as dates; `to` includes that whole day
rows = rows.annotate(day=Substr("created_at", 1, 10)).filter(day__lte=to)
rows = rows.order_by("created_at", "id").values_list("data", "created_at")[offset:offset + limit]
# Include submission dates separately when requested by Dashboard
if query.get("includeCreatedAt") in ("1", "true"):
return JsonResponse([{"data": json.loads(data), "createdAt": created_at} for data, created_at in rows], safe=False)
return HttpResponse("[" + ",".join(data for data, _ in rows) + "]", content_type="application/json") # as stored