* @brief Chain: resolve dataset + workspace, enable option, patch ranges, addWidget, validate. */
| 725 | * @brief Chain: resolve dataset + workspace, enable option, patch ranges, addWidget, validate. |
| 726 | */ |
| 727 | API::CommandResponse API::Handlers::AssistantHandler::workspaceAddTile(const QString& id, |
| 728 | const QJsonObject& params) |
| 729 | { |
| 730 | if (!params.contains(QStringLiteral("widgetType"))) |
| 731 | return CommandResponse::makeError( |
| 732 | id, |
| 733 | ErrorCode::MissingParam, |
| 734 | QStringLiteral("Missing required parameter: widgetType (slug or integer).")); |
| 735 | |
| 736 | const QString slug = resolveWidgetSlug(params.value(QStringLiteral("widgetType"))); |
| 737 | if (slug.isEmpty()) |
| 738 | return CommandResponse::makeError( |
| 739 | id, |
| 740 | ErrorCode::InvalidParam, |
| 741 | QStringLiteral("Unknown widgetType. Use a slug (plot, fft, gauge, ...) or DashboardWidget " |
| 742 | "integer.")); |
| 743 | |
| 744 | QJsonArray steps; |
| 745 | |
| 746 | int gid = -1, did = -1, uid = -1; |
| 747 | const bool hasDataset = |
| 748 | params.contains(QStringLiteral("dataset")) || params.contains(Keys::UniqueId); |
| 749 | if (hasDataset) { |
| 750 | const auto dsResp = resolveAddTileDataset(params, gid, did, uid); |
| 751 | steps.append(toStep(QStringLiteral("dataset.resolve"), dsResp)); |
| 752 | if (!dsResp.success) |
| 753 | return stepFailure(id, dsResp, steps); |
| 754 | } |
| 755 | |
| 756 | int workspaceId = -1; |
| 757 | const auto wsResp = resolveOrCreateWorkspace(params, workspaceId, steps); |
| 758 | if (!wsResp.success) |
| 759 | return stepFailure(id, wsResp, steps); |
| 760 | |
| 761 | const auto custResp = ensureCustomizeMode(); |
| 762 | steps.append(toStep(QStringLiteral("workspace.setCustomizeMode"), custResp)); |
| 763 | if (!custResp.success) |
| 764 | return stepFailure(id, custResp, steps); |
| 765 | |
| 766 | if (hasDataset) { |
| 767 | const auto optResp = applyAddTileDatasetOption(gid, did, slug, steps); |
| 768 | if (!optResp.success) |
| 769 | return stepFailure(id, optResp, steps); |
| 770 | |
| 771 | const auto rngResp = applyAddTileRanges(params, gid, did, steps); |
| 772 | if (!rngResp.success) |
| 773 | return stepFailure(id, rngResp, steps); |
| 774 | } |
| 775 | |
| 776 | if (!hasDataset) { |
| 777 | if (!params.contains(QStringLiteral("groupId"))) |
| 778 | return CommandResponse::makeError( |
| 779 | id, |
| 780 | ErrorCode::MissingParam, |
| 781 | QStringLiteral("Provide a dataset (path or uniqueId) OR a groupId for group-level tiles.")); |
| 782 | |
| 783 | gid = params.value(QStringLiteral("groupId")).toInt(); |
| 784 | } |
nothing calls this directly
no test coverage detected