Closed VyachL05 closed 8 months ago
@VyachL05 it's interesting. Could you please provide more details? Such as panel settings, ideally is a dashboard json
@VyachL05 The problem with setting number to date element. Please update your initial request code to
elements[0].value = new Date().toISOString();
and then it should be working
Please let us know if there is anything else
@asimonok , thank you for answer. But this is not fixed my problem.
@asimonok , you can review my dashboard here: http://213.219.215.242:32444/ with credentials: user: Somebody passw: Somebody1
@VyachL05 updated the dashboard json, now it should be working. The problem was in failing static data source empty query so the initial request was not called
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": {
"type": "grafana",
"uid": "-- Grafana --"
},
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 0,
"id": 7,
"links": [],
"liveNow": false,
"panels": [
{
"datasource": {
"type": "marcusolsson-static-datasource",
"uid": "P1D2C73DC01F2359B"
},
"gridPos": {
"h": 10,
"w": 19,
"x": 0,
"y": 0
},
"id": 2,
"options": {
"buttonGroup": {
"orientation": "center",
"size": "md"
},
"confirmModal": {
"body": "Вы уверены, что хотите внести новую запись в оперативный журнал?",
"cancel": "Отменить",
"columns": {
"name": "Название",
"newValue": "Новое значение",
"oldValue": "Старое значение"
},
"confirm": "Да",
"title": "Подтверждение новой записи"
},
"elementValueChanged": "",
"elements": [
{
"disableIf": "",
"id": "ts",
"labelWidth": 20,
"max": "",
"min": "",
"section": "",
"showIf": "",
"title": "Время",
"tooltip": "Время, к которому относится значение:",
"type": "datetime",
"uid": "84724314-0221-428c-8bc4-86b050aae6b6",
"unit": "",
"value": ""
},
{
"hidden": false,
"id": "id",
"labelWidth": 20,
"section": "",
"title": "Объект",
"tooltip": "guid род.объекта модели",
"type": "string",
"uid": "e899f01c-3dcb-4e06-a16e-b05807295dd5",
"unit": "",
"value": ""
},
{
"hidden": false,
"id": "value",
"labelWidth": 20,
"section": "",
"title": "Параметр",
"tooltip": "например, Power",
"type": "string",
"uid": "6f6b8bab-0ec1-402b-86e9-39d8b05297e4",
"unit": "",
"value": ""
},
{
"id": "param_val",
"labelWidth": 20,
"section": "",
"title": "Значение",
"tooltip": "",
"type": "number",
"uid": "6e39148e-750b-496c-9010-072c9961f169",
"unit": "",
"value": 0
}
],
"initial": {
"code": "context.panel.onChangeElements(context.panel.elements.map((element) => {\n if (element.id === 'ts') {\n return {\n ...element,\n value: element.value || new Date().toISOString(),\n }\n }\n return element;\n}))\n\n// console.log(data, response, initial, elements);\nconsole.log(elements);\nreturn;\n\n/**\n * Data Source\n * Requires form elements to be defined\n */\nconst dataQuery = toDataQueryResponse(response);\nconsole.log(dataQuery);",
"contentType": "application/json",
"getPayload": "return {\n rawSql: '',\n format: 'table',\n}",
"highlight": false,
"highlightColor": "red",
"method": "-"
},
"layout": {
"orientation": "horizontal",
"padding": 10,
"variant": "single"
},
"reset": {
"backgroundColor": "purple",
"foregroundColor": "yellow",
"icon": "process",
"text": "Reset",
"variant": "hidden"
},
"resetAction": {
"code": "if (response && response.ok) {\n notifySuccess(['Update', 'Values updated successfully.']);\n locationService.reload();\n} else {\n notifyError(['Update', 'An error occured updating values.']);\n}",
"confirm": false,
"getPayload": "return {\n rawSql: '',\n format: 'table',\n}",
"mode": "initial"
},
"saveDefault": {
"icon": "save",
"text": "Save Default",
"variant": "hidden"
},
"submit": {
"backgroundColor": "purple",
"foregroundColor": "yellow",
"icon": "check",
"text": "Внести запись",
"variant": "primary"
},
"sync": false,
"update": {
"code": "if (response && response.ok) {\n notifySuccess(['Update', 'Values updated successfully.']);\n locationService.reload();\n} else {\n notifyError(['Update', 'An error occured updating values.']);\n}",
"confirm": true,
"contentType": "application/json",
"getPayload": "const payload = {};\n\n// elements.forEach((element) => {\n// if (!element.value) {\n// return;\n// }\n\n// payload[element.id] = element.value;\n// })\n// let Date = new Date(elements[0].value);\n// payload[\"ts\"] = Date.getTime();\n// payload[\"ts\"] = elements[0].value;\npayload[\"ts\"] = Math.floor(new Date(elements[0].value).getTime());\n// payload[\"ts\"] = 1706789116000;\npayload[\"id\"] = elements[1].value;\npayload[\"dateFrom\"] = 0;\npayload[\"dateTo\"] = 0;\npayload[\"value\"] = {};\npayload[\"value\"][elements[2].value] = elements[3].value;\n\nreturn [payload];\n\n/**\n * Data Source payload\n */\nreturn {\n rawSql: '',\n format: 'table',\n};",
"method": "POST",
"payloadMode": "custom",
"url": "http://213.219.215.242:30200/raw?type=raw"
},
"updateEnabled": "auto"
},
"pluginVersion": "3.6.0",
"targets": [
{
"datasource": {
"type": "marcusolsson-static-datasource",
"uid": "P1D2C73DC01F2359B"
},
"frame": {
"fields": [
{
"config": {},
"name": "Field 1",
"type": "string",
"values": []
}
],
"meta": {}
},
"refId": "A"
}
],
"title": "Внесение новой записи в журнал",
"transparent": true,
"type": "volkovlabs-form-panel"
},
{
"datasource": {
"type": "postgres",
"uid": "PCC52D03280B7034C"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"custom": {
"align": "auto",
"cellOptions": {
"type": "auto"
},
"filterable": true,
"inspect": true
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
},
"unitScale": true
},
"overrides": [
{
"matcher": {
"id": "byRegexp",
"options": "/Время*/"
},
"properties": [
{
"id": "custom.filterable",
"value": false
}
]
},
{
"matcher": {
"id": "byName",
"options": "Категория события"
},
"properties": [
{
"id": "custom.width",
"value": 300
}
]
},
{
"matcher": {
"id": "byName",
"options": "Содержание"
},
"properties": [
{
"id": "custom.width",
"value": 300
}
]
}
]
},
"gridPos": {
"h": 9,
"w": 24,
"x": 0,
"y": 10
},
"id": 1,
"options": {
"cellHeight": "md",
"footer": {
"countRows": false,
"fields": "",
"reducer": [
"sum"
],
"show": false
},
"showHeader": true
},
"pluginVersion": "10.3.1",
"targets": [
{
"datasource": {
"type": "postgres",
"uid": "PCC52D03280B7034C"
},
"editorMode": "builder",
"format": "table",
"rawQuery": true,
"rawSql": "SELECT ts AS \"Время записи\", eventtime AS \"Время события\", category AS \"Категория события\", object AS \"Объект\", message AS \"Содержание\", who AS \"Запись внес\" FROM operjournal LIMIT 50 ",
"refId": "A",
"sql": {
"columns": [
{
"alias": "\"Время записи\"",
"parameters": [
{
"name": "ts",
"type": "functionParameter"
}
],
"type": "function"
},
{
"alias": "\"Время события\"",
"parameters": [
{
"name": "eventtime",
"type": "functionParameter"
}
],
"type": "function"
},
{
"alias": "\"Категория события\"",
"parameters": [
{
"name": "category",
"type": "functionParameter"
}
],
"type": "function"
},
{
"alias": "\"Объект\"",
"parameters": [
{
"name": "object",
"type": "functionParameter"
}
],
"type": "function"
},
{
"alias": "\"Содержание\"",
"parameters": [
{
"name": "message",
"type": "functionParameter"
}
],
"type": "function"
},
{
"alias": "\"Запись внес\"",
"parameters": [
{
"name": "who",
"type": "functionParameter"
}
],
"type": "function"
}
],
"groupBy": [
{
"property": {
"type": "string"
},
"type": "groupBy"
}
],
"limit": 50
},
"table": "operjournal"
}
],
"title": "Оперативный журнал",
"transparent": true,
"type": "table"
}
],
"refresh": "",
"schemaVersion": 39,
"tags": [],
"templating": {
"list": []
},
"time": {
"from": "now-12h",
"to": "now"
},
"timepicker": {},
"timezone": "",
"title": "Ввод данных",
"uid": "cfd215f9-fe72-498c-b4ff-b30fdd5e3a55",
"version": 8,
"weekStart": ""
}
@asimonok , I change my "empty query" to the grafana RandomWalk, but the problem is still here.
@VyachL05 updated the dashboard json, now it should be working. The problem was in failing static data source empty query so the initial request was not called
{ "annotations": { "list": [ { "builtIn": 1, "datasource": { "type": "grafana", "uid": "-- Grafana --" }, "enable": true, "hide": true, "iconColor": "rgba(0, 211, 255, 1)", "name": "Annotations & Alerts", "type": "dashboard" } ] }, "editable": true, "fiscalYearStartMonth": 0, "graphTooltip": 0, "id": 7, "links": [], "liveNow": false, "panels": [ { "datasource": { "type": "marcusolsson-static-datasource", "uid": "P1D2C73DC01F2359B" }, "gridPos": { "h": 10, "w": 19, "x": 0, "y": 0 }, "id": 2, "options": { "buttonGroup": { "orientation": "center", "size": "md" }, "confirmModal": { "body": "Вы уверены, что хотите внести новую запись в оперативный журнал?", "cancel": "Отменить", "columns": { "name": "Название", "newValue": "Новое значение", "oldValue": "Старое значение" }, "confirm": "Да", "title": "Подтверждение новой записи" }, "elementValueChanged": "", "elements": [ { "disableIf": "", "id": "ts", "labelWidth": 20, "max": "", "min": "", "section": "", "showIf": "", "title": "Время", "tooltip": "Время, к которому относится значение:", "type": "datetime", "uid": "84724314-0221-428c-8bc4-86b050aae6b6", "unit": "", "value": "" }, { "hidden": false, "id": "id", "labelWidth": 20, "section": "", "title": "Объект", "tooltip": "guid род.объекта модели", "type": "string", "uid": "e899f01c-3dcb-4e06-a16e-b05807295dd5", "unit": "", "value": "" }, { "hidden": false, "id": "value", "labelWidth": 20, "section": "", "title": "Параметр", "tooltip": "например, Power", "type": "string", "uid": "6f6b8bab-0ec1-402b-86e9-39d8b05297e4", "unit": "", "value": "" }, { "id": "param_val", "labelWidth": 20, "section": "", "title": "Значение", "tooltip": "", "type": "number", "uid": "6e39148e-750b-496c-9010-072c9961f169", "unit": "", "value": 0 } ], "initial": { "code": "context.panel.onChangeElements(context.panel.elements.map((element) => {\n if (element.id === 'ts') {\n return {\n ...element,\n value: element.value || new Date().toISOString(),\n }\n }\n return element;\n}))\n\n// console.log(data, response, initial, elements);\nconsole.log(elements);\nreturn;\n\n/**\n * Data Source\n * Requires form elements to be defined\n */\nconst dataQuery = toDataQueryResponse(response);\nconsole.log(dataQuery);", "contentType": "application/json", "getPayload": "return {\n rawSql: '',\n format: 'table',\n}", "highlight": false, "highlightColor": "red", "method": "-" }, "layout": { "orientation": "horizontal", "padding": 10, "variant": "single" }, "reset": { "backgroundColor": "purple", "foregroundColor": "yellow", "icon": "process", "text": "Reset", "variant": "hidden" }, "resetAction": { "code": "if (response && response.ok) {\n notifySuccess(['Update', 'Values updated successfully.']);\n locationService.reload();\n} else {\n notifyError(['Update', 'An error occured updating values.']);\n}", "confirm": false, "getPayload": "return {\n rawSql: '',\n format: 'table',\n}", "mode": "initial" }, "saveDefault": { "icon": "save", "text": "Save Default", "variant": "hidden" }, "submit": { "backgroundColor": "purple", "foregroundColor": "yellow", "icon": "check", "text": "Внести запись", "variant": "primary" }, "sync": false, "update": { "code": "if (response && response.ok) {\n notifySuccess(['Update', 'Values updated successfully.']);\n locationService.reload();\n} else {\n notifyError(['Update', 'An error occured updating values.']);\n}", "confirm": true, "contentType": "application/json", "getPayload": "const payload = {};\n\n// elements.forEach((element) => {\n// if (!element.value) {\n// return;\n// }\n\n// payload[element.id] = element.value;\n// })\n// let Date = new Date(elements[0].value);\n// payload[\"ts\"] = Date.getTime();\n// payload[\"ts\"] = elements[0].value;\npayload[\"ts\"] = Math.floor(new Date(elements[0].value).getTime());\n// payload[\"ts\"] = 1706789116000;\npayload[\"id\"] = elements[1].value;\npayload[\"dateFrom\"] = 0;\npayload[\"dateTo\"] = 0;\npayload[\"value\"] = {};\npayload[\"value\"][elements[2].value] = elements[3].value;\n\nreturn [payload];\n\n/**\n * Data Source payload\n */\nreturn {\n rawSql: '',\n format: 'table',\n};", "method": "POST", "payloadMode": "custom", "url": "http://213.219.215.242:30200/raw?type=raw" }, "updateEnabled": "auto" }, "pluginVersion": "3.6.0", "targets": [ { "datasource": { "type": "marcusolsson-static-datasource", "uid": "P1D2C73DC01F2359B" }, "frame": { "fields": [ { "config": {}, "name": "Field 1", "type": "string", "values": [] } ], "meta": {} }, "refId": "A" } ], "title": "Внесение новой записи в журнал", "transparent": true, "type": "volkovlabs-form-panel" }, { "datasource": { "type": "postgres", "uid": "PCC52D03280B7034C" }, "fieldConfig": { "defaults": { "color": { "mode": "thresholds" }, "custom": { "align": "auto", "cellOptions": { "type": "auto" }, "filterable": true, "inspect": true }, "mappings": [], "thresholds": { "mode": "absolute", "steps": [ { "color": "green", "value": null }, { "color": "red", "value": 80 } ] }, "unitScale": true }, "overrides": [ { "matcher": { "id": "byRegexp", "options": "/Время*/" }, "properties": [ { "id": "custom.filterable", "value": false } ] }, { "matcher": { "id": "byName", "options": "Категория события" }, "properties": [ { "id": "custom.width", "value": 300 } ] }, { "matcher": { "id": "byName", "options": "Содержание" }, "properties": [ { "id": "custom.width", "value": 300 } ] } ] }, "gridPos": { "h": 9, "w": 24, "x": 0, "y": 10 }, "id": 1, "options": { "cellHeight": "md", "footer": { "countRows": false, "fields": "", "reducer": [ "sum" ], "show": false }, "showHeader": true }, "pluginVersion": "10.3.1", "targets": [ { "datasource": { "type": "postgres", "uid": "PCC52D03280B7034C" }, "editorMode": "builder", "format": "table", "rawQuery": true, "rawSql": "SELECT ts AS \"Время записи\", eventtime AS \"Время события\", category AS \"Категория события\", object AS \"Объект\", message AS \"Содержание\", who AS \"Запись внес\" FROM operjournal LIMIT 50 ", "refId": "A", "sql": { "columns": [ { "alias": "\"Время записи\"", "parameters": [ { "name": "ts", "type": "functionParameter" } ], "type": "function" }, { "alias": "\"Время события\"", "parameters": [ { "name": "eventtime", "type": "functionParameter" } ], "type": "function" }, { "alias": "\"Категория события\"", "parameters": [ { "name": "category", "type": "functionParameter" } ], "type": "function" }, { "alias": "\"Объект\"", "parameters": [ { "name": "object", "type": "functionParameter" } ], "type": "function" }, { "alias": "\"Содержание\"", "parameters": [ { "name": "message", "type": "functionParameter" } ], "type": "function" }, { "alias": "\"Запись внес\"", "parameters": [ { "name": "who", "type": "functionParameter" } ], "type": "function" } ], "groupBy": [ { "property": { "type": "string" }, "type": "groupBy" } ], "limit": 50 }, "table": "operjournal" } ], "title": "Оперативный журнал", "transparent": true, "type": "table" } ], "refresh": "", "schemaVersion": 39, "tags": [], "templating": { "list": [] }, "time": { "from": "now-12h", "to": "now" }, "timepicker": {}, "timezone": "", "title": "Ввод данных", "uid": "cfd215f9-fe72-498c-b4ff-b30fdd5e3a55", "version": 8, "weekStart": "" }
I have loaded this panel.json, but I got the same result.
I have found the true reason of my problem. It was some unusual settings in date format ENV variables.
DateTime form always has red frame. Maybe, localization problems? How can I fix it?