Commit f6bf6c60 authored by jan.koester's avatar jan.koester
Browse files

surveys

parent 95c0772a
Loading
Loading
Loading
Loading
+2 −0
Changes for editor/CMakeLists.txt: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -47,6 +47,8 @@ qt_add_qml_module(blogi-editor
        qml/AiPromptDialog.qml
        qml/AiTab.qml
        qml/LlmSettingsDialog.qml
        qml/SurveyListDialog.qml
        qml/SurveyEditorDialog.qml
)

target_link_libraries(blogi-editor PRIVATE
+76 −0
Changes for editor/localapi.cpp: 76 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -707,6 +707,82 @@ void LocalApi::fetchSurveyList() {
    });
}

void LocalApi::fetchSurvey(const QString &name) {
    QJsonArray cmds;
    QJsonObject cmd;
    cmd["command"] = "get_survey";
    cmd["name"] = name;
    cmds.append(cmd);

    _pub->apiRequest(cmds, [this](bool ok, const QJsonArray &resp) {
        if (!ok) {
            emit statusMessage("Failed to fetch survey");
            return;
        }
        for (int i = 0; i < resp.size(); ++i) {
            QJsonObject obj = resp.at(i).toObject();
            if (obj.contains("survey")) {
                QString name = obj["name"].toString();
                QString json = QString::fromUtf8(QJsonDocument(obj["survey"].toObject()).toJson(QJsonDocument::Compact));
                emit surveyLoaded(name, json);
                return;
            }
        }
        emit statusMessage("Survey not found");
    });
}

void LocalApi::saveSurvey(const QString &name, const QString &surveyJson, const QString &originalName) {
    QJsonArray cmds;
    QJsonObject cmd;
    cmd["command"] = "save_survey";
    cmd["name"] = name;
    cmd["survey"] = QJsonDocument::fromJson(surveyJson.toUtf8()).object();
    if (!originalName.isEmpty())
        cmd["originalName"] = originalName;
    cmds.append(cmd);

    _pub->apiRequest(cmds, [this](bool ok, const QJsonArray &resp) {
        if (!ok) {
            emit surveySaved(false, "Connection failed");
            return;
        }
        for (int i = 0; i < resp.size(); ++i) {
            QJsonObject obj = resp.at(i).toObject();
            if (obj.contains("message")) {
                bool success = obj["status"].toString() == "success";
                emit surveySaved(success, obj["message"].toString());
                return;
            }
        }
        emit surveySaved(false, "Unknown error");
    });
}

void LocalApi::deleteSurvey(const QString &name) {
    QJsonArray cmds;
    QJsonObject cmd;
    cmd["command"] = "delete_survey";
    cmd["name"] = name;
    cmds.append(cmd);

    _pub->apiRequest(cmds, [this](bool ok, const QJsonArray &resp) {
        if (!ok) {
            emit surveyDeleted(false, "Connection failed");
            return;
        }
        for (int i = 0; i < resp.size(); ++i) {
            QJsonObject obj = resp.at(i).toObject();
            if (obj.contains("message")) {
                bool success = obj["status"].toString() == "success";
                emit surveyDeleted(success, obj["message"].toString());
                return;
            }
        }
        emit surveyDeleted(false, "Unknown error");
    });
}

QString LocalApi::collectRepeaterParams(QObject *repeater) {
    if (!repeater) return "{}";
    QJsonObject params;
+6 −0
Changes for editor/localapi.h: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -83,6 +83,9 @@ public:

    /* Survey list (requires connection) */
    Q_INVOKABLE void fetchSurveyList();
    Q_INVOKABLE void fetchSurvey(const QString &name);
    Q_INVOKABLE void saveSurvey(const QString &name, const QString &surveyJson, const QString &originalName);
    Q_INVOKABLE void deleteSurvey(const QString &name);

    /* Publish (requires connection) */
    Q_INVOKABLE void fetchPublishTargets();
@@ -151,6 +154,9 @@ signals:
    void publishCompleted(bool ok, const QString &msg);
    void themeColorsLoaded(const QString &json);
    void surveyListLoaded(const QString &json);
    void surveyLoaded(const QString &name, const QString &json);
    void surveySaved(bool ok, const QString &msg);
    void surveyDeleted(bool ok, const QString &msg);
    void savedConnectionsChanged();
    void gitOperationFinished(bool ok, const QString &msg);

+5 −0
Changes for editor/qml/Main.qml: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -36,6 +36,10 @@ ApplicationWindow {
            title: qsTr("&Publish")
            Action { text: qsTr("&Publish to Server..."); shortcut: "Ctrl+Shift+P"; onTriggered: connPanelInst.doPublish(false, "") }
        }
        Menu {
            title: qsTr("&Edit")
            Action { text: qsTr("&Survey Editor..."); onTriggered: surveyListDlg.show() }
        }
    }

    header: ToolBar {
@@ -186,4 +190,5 @@ ApplicationWindow {

    AiPromptDialog { id: aiPromptDlg }
    LlmSettingsDialog { id: llmSettingsDlg }
    SurveyListDialog { id: surveyListDlg; visible: false }
}
+551 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading