* @brief Orchestrates the workspace tile addition flow end-to-end. */
| 1684 | * @brief Orchestrates the workspace tile addition flow end-to-end. |
| 1685 | */ |
| 1686 | static QJsonObject executeAddTile(const QJsonObject& args) |
| 1687 | { |
| 1688 | QJsonArray steps; |
| 1689 | QJsonArray warnings; |
| 1690 | |
| 1691 | const QString widgetType = args.value(QStringLiteral("widgetType")).toString(); |
| 1692 | if (widgetType.isEmpty()) { |
| 1693 | QJsonObject out; |
| 1694 | out[QStringLiteral("ok")] = false; |
| 1695 | out[QStringLiteral("error")] = QStringLiteral("missing_widgetType"); |
| 1696 | return out; |
| 1697 | } |
| 1698 | |
| 1699 | static const QStringList kFanOutCommands = { |
| 1700 | QStringLiteral("project.workspace.add"), |
| 1701 | QStringLiteral("project.dataset.setOptions"), |
| 1702 | QStringLiteral("project.dataset.update"), |
| 1703 | QStringLiteral("project.workspace.setCustomizeMode"), |
| 1704 | QStringLiteral("project.workspace.addWidget"), |
| 1705 | }; |
| 1706 | for (const auto& command : kFanOutCommands) |
| 1707 | if (!innerOpAllowed(command)) |
| 1708 | return makeInnerOpRejection(command); |
| 1709 | |
| 1710 | auto wsReply = resolveOrCreateTileWorkspace(args, steps); |
| 1711 | if (!wsReply.value(QStringLiteral("ok")).toBool()) |
| 1712 | return wsReply; |
| 1713 | |
| 1714 | const auto workspace = wsReply.value(QStringLiteral("workspace")).toObject(); |
| 1715 | const int workspaceId = workspace.value(QStringLiteral("id")).toInt(); |
| 1716 | |
| 1717 | QJsonObject groupArgs = args; |
| 1718 | QJsonObject dataset; |
| 1719 | const auto dsReply = resolveTileDataset(args, groupArgs); |
| 1720 | if (!dsReply.isEmpty() && !dsReply.value(QStringLiteral("ok")).toBool()) |
| 1721 | return dsReply; |
| 1722 | |
| 1723 | if (!dsReply.isEmpty()) |
| 1724 | dataset = dsReply.value(QStringLiteral("dataset")).toObject(); |
| 1725 | |
| 1726 | auto groupReply = resolveGroup(groupArgs); |
| 1727 | if (!groupReply.value(QStringLiteral("ok")).toBool()) |
| 1728 | return groupReply; |
| 1729 | |
| 1730 | const auto group = groupReply.value(QStringLiteral("group")).toObject(); |
| 1731 | const int groupId = |
| 1732 | group.value(QStringLiteral("groupId")).toInt(group.value(QStringLiteral("id")).toInt()); |
| 1733 | |
| 1734 | const auto customize = enableCustomizeMode(steps); |
| 1735 | if (!customize.value(QStringLiteral("ok")).toBool()) |
| 1736 | return attachRepairHint(customize, QStringLiteral("assistant.workspace.addTile")); |
| 1737 | |
| 1738 | const QString optionSlug = optionSlugForWidget(widgetType); |
| 1739 | if (!optionSlug.isEmpty() && dataset.isEmpty()) |
| 1740 | warnings.append(QStringLiteral("Widget type needs a dataset option, but no dataset was " |
| 1741 | "provided; addWidget may fail if the group is not already " |
| 1742 | "compatible.")); |
| 1743 | else if (!optionSlug.isEmpty()) { |
no test coverage detected