@ozguraltan/strapi-content-input 1.0.22 → 1.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -6
- package/dist/admin/{AnalyticsHubPage-DUj3D2kA.mjs → AnalyticsHubPage-Dvpx3KsP.mjs} +168 -55
- package/dist/admin/{AnalyticsHubPage-B1_chQkG.js → AnalyticsHubPage-K_trli5i.js} +186 -55
- package/dist/admin/{ContentInputField-BrtpTCDd.mjs → ContentInputField-C2kmtUwD.mjs} +6 -236
- package/dist/admin/{ContentInputField-CQFQxxgm.js → ContentInputField-CjxYYEps.js} +22 -252
- package/dist/admin/{SurveyWidgetEditor-DGSwgTzR.mjs → SurveyWidgetEditor-DMWOkHUt.mjs} +3222 -228
- package/dist/admin/{SurveyWidgetEditor-C5Uvyf_h.js → SurveyWidgetEditor-DOYxWop9.js} +3198 -204
- package/dist/admin/{index-Dc7AFLOj.mjs → index-AePRA0IB.mjs} +2 -2
- package/dist/admin/{index-i0NfSYto.js → index-B9C8Qrfd.js} +2 -2
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/admin/src/components/widgets/SurveyLivePreviewPane.d.ts +9 -0
- package/dist/admin/src/components/widgets/SurveyWidgetEditor.d.ts +3 -1
- package/dist/server/index.js +183 -12
- package/dist/server/index.mjs +165 -12
- package/dist/server/src/index.d.ts +10 -1
- package/dist/server/src/services/ci-survey.d.ts +10 -1
- package/dist/server/src/services/index.d.ts +10 -1
- package/dist/server/src/utils/surveyEngine.d.ts +5 -0
- package/package.json +1 -1
|
@@ -153,7 +153,7 @@ const index = {
|
|
|
153
153
|
},
|
|
154
154
|
icon: PluginIcon,
|
|
155
155
|
components: {
|
|
156
|
-
Input: async () => import("./ContentInputField-
|
|
156
|
+
Input: async () => import("./ContentInputField-C2kmtUwD.mjs").then((mod) => ({
|
|
157
157
|
default: mod.ContentInputField
|
|
158
158
|
}))
|
|
159
159
|
},
|
|
@@ -188,7 +188,7 @@ const index = {
|
|
|
188
188
|
defaultMessage: "ContentInput Hub"
|
|
189
189
|
},
|
|
190
190
|
permissions: [],
|
|
191
|
-
Component: () => import("./AnalyticsHubPage-
|
|
191
|
+
Component: () => import("./AnalyticsHubPage-Dvpx3KsP.mjs").then((mod) => ({
|
|
192
192
|
default: mod.AnalyticsHubPage
|
|
193
193
|
})),
|
|
194
194
|
position: 7
|
|
@@ -156,7 +156,7 @@ const index = {
|
|
|
156
156
|
},
|
|
157
157
|
icon: PluginIcon,
|
|
158
158
|
components: {
|
|
159
|
-
Input: async () => Promise.resolve().then(() => require("./ContentInputField-
|
|
159
|
+
Input: async () => Promise.resolve().then(() => require("./ContentInputField-CjxYYEps.js")).then((mod) => ({
|
|
160
160
|
default: mod.ContentInputField
|
|
161
161
|
}))
|
|
162
162
|
},
|
|
@@ -191,7 +191,7 @@ const index = {
|
|
|
191
191
|
defaultMessage: "ContentInput Hub"
|
|
192
192
|
},
|
|
193
193
|
permissions: [],
|
|
194
|
-
Component: () => Promise.resolve().then(() => require("./AnalyticsHubPage-
|
|
194
|
+
Component: () => Promise.resolve().then(() => require("./AnalyticsHubPage-K_trli5i.js")).then((mod) => ({
|
|
195
195
|
default: mod.AnalyticsHubPage
|
|
196
196
|
})),
|
|
197
197
|
position: 7
|
package/dist/admin/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
-
const index = require("./index-
|
|
3
|
+
const index = require("./index-B9C8Qrfd.js");
|
|
4
4
|
require("react");
|
|
5
5
|
exports.default = index.index;
|
package/dist/admin/index.mjs
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { CISurveyRecord } from './SurveyWidgetEditor';
|
|
3
|
+
import { StrapiLocaleInfo } from '../../core/useStrapiLocales';
|
|
4
|
+
export interface SurveyLivePreviewPaneProps {
|
|
5
|
+
draft: CISurveyRecord;
|
|
6
|
+
uiLocale: string;
|
|
7
|
+
strapiLocales: StrapiLocaleInfo[];
|
|
8
|
+
}
|
|
9
|
+
export declare const SurveyLivePreviewPane: React.FC<SurveyLivePreviewPaneProps>;
|
|
@@ -38,6 +38,7 @@ export interface CISurveyQuestionDef {
|
|
|
38
38
|
scaleMax?: number;
|
|
39
39
|
lowLabel?: Record<string, string> | string;
|
|
40
40
|
highLabel?: Record<string, string> | string;
|
|
41
|
+
scaleLabels?: Record<string, Record<string, string> | string>;
|
|
41
42
|
options?: CISurveyOptionItem[];
|
|
42
43
|
matrixRows?: CISurveyOptionItem[];
|
|
43
44
|
matrixColumns?: CISurveyOptionItem[];
|
|
@@ -79,10 +80,11 @@ export interface CISurveyRecord {
|
|
|
79
80
|
npsScore?: number | null;
|
|
80
81
|
}
|
|
81
82
|
export declare function createBlankSurveyDraft(locale?: string): CISurveyRecord;
|
|
83
|
+
export type SurveyStudioTabId = 'builder' | 'preview' | 'settings' | 'analytics';
|
|
82
84
|
export interface SurveyStudioModalProps {
|
|
83
85
|
open: boolean;
|
|
84
86
|
initialSurvey: CISurveyRecord;
|
|
85
|
-
initialTab?:
|
|
87
|
+
initialTab?: SurveyStudioTabId;
|
|
86
88
|
uiLocale?: string;
|
|
87
89
|
onClose: () => void;
|
|
88
90
|
onSaved?: (saved: CISurveyRecord) => void;
|
package/dist/server/index.js
CHANGED
|
@@ -5,11 +5,30 @@ const fs = require("fs");
|
|
|
5
5
|
const module$1 = require("module");
|
|
6
6
|
const os = require("os");
|
|
7
7
|
const path = require("path");
|
|
8
|
+
const XLSXNs = require("xlsx");
|
|
8
9
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
10
|
+
function _interopNamespace(e) {
|
|
11
|
+
if (e && e.__esModule) return e;
|
|
12
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
13
|
+
if (e) {
|
|
14
|
+
for (const k in e) {
|
|
15
|
+
if (k !== "default") {
|
|
16
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
17
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: () => e[k]
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
n.default = e;
|
|
25
|
+
return Object.freeze(n);
|
|
26
|
+
}
|
|
9
27
|
const crypto__default = /* @__PURE__ */ _interopDefault(crypto);
|
|
10
28
|
const fs__default = /* @__PURE__ */ _interopDefault(fs);
|
|
11
29
|
const os__default = /* @__PURE__ */ _interopDefault(os);
|
|
12
30
|
const path__default = /* @__PURE__ */ _interopDefault(path);
|
|
31
|
+
const XLSXNs__namespace = /* @__PURE__ */ _interopNamespace(XLSXNs);
|
|
13
32
|
const register = ({ strapi }) => {
|
|
14
33
|
strapi.customFields.register({
|
|
15
34
|
name: "content-input",
|
|
@@ -1915,18 +1934,31 @@ const ciSurveyController = ({ strapi }) => ({
|
|
|
1915
1934
|
async exportResponses(ctx) {
|
|
1916
1935
|
try {
|
|
1917
1936
|
const { id } = ctx.params;
|
|
1918
|
-
const
|
|
1937
|
+
const rawFmt = String(ctx.query?.format || "xlsx").toLowerCase();
|
|
1938
|
+
const format = rawFmt === "json" ? "json" : rawFmt === "csv" ? "csv" : "xlsx";
|
|
1919
1939
|
const locale = String(ctx.query?.locale || "en").trim();
|
|
1920
1940
|
const from = ctx.query?.from ? String(ctx.query.from) : void 0;
|
|
1921
1941
|
const to = ctx.query?.to ? String(ctx.query.to) : void 0;
|
|
1942
|
+
const encoding = String(ctx.query?.encoding || "").toLowerCase();
|
|
1922
1943
|
const exported = await strapi.plugin("content-input").service("ci-survey").exportResponses(id, { format, locale, from, to });
|
|
1923
1944
|
if (!exported) {
|
|
1924
1945
|
return ctx.notFound("Survey not found");
|
|
1925
1946
|
}
|
|
1947
|
+
if (encoding === "base64") {
|
|
1948
|
+
const buf = Buffer.isBuffer(exported.body) ? exported.body : Buffer.from(String(exported.body), "utf8");
|
|
1949
|
+
ctx.status = 200;
|
|
1950
|
+
ctx.body = {
|
|
1951
|
+
filename: exported.filename,
|
|
1952
|
+
contentType: exported.contentType,
|
|
1953
|
+
base64: buf.toString("base64")
|
|
1954
|
+
};
|
|
1955
|
+
return;
|
|
1956
|
+
}
|
|
1957
|
+
ctx.body = exported.body;
|
|
1958
|
+
ctx.type = exported.contentType;
|
|
1926
1959
|
ctx.set("Content-Type", exported.contentType);
|
|
1927
1960
|
ctx.set("Content-Disposition", `attachment; filename="${exported.filename}"`);
|
|
1928
1961
|
ctx.status = 200;
|
|
1929
|
-
ctx.body = exported.body;
|
|
1930
1962
|
} catch (err) {
|
|
1931
1963
|
ctx.throw(500, err);
|
|
1932
1964
|
}
|
|
@@ -5274,6 +5306,7 @@ const ciFormService = ({ strapi }) => ({
|
|
|
5274
5306
|
};
|
|
5275
5307
|
}
|
|
5276
5308
|
});
|
|
5309
|
+
const XLSX = XLSXNs__namespace?.utils ? XLSXNs__namespace : XLSXNs__namespace?.default || XLSXNs__namespace;
|
|
5277
5310
|
function evalSingleRule(rule, answers) {
|
|
5278
5311
|
const targetVal = answers ? answers[rule.questionKey] : void 0;
|
|
5279
5312
|
const op = rule.operator;
|
|
@@ -5650,6 +5683,7 @@ function computeSurveyAnalytics(survey, rawResponses, filter = {}) {
|
|
|
5650
5683
|
}
|
|
5651
5684
|
const distribution = Object.keys(distMap).map(Number).sort((a, b) => a - b).map((value) => ({
|
|
5652
5685
|
value,
|
|
5686
|
+
labels: q.scaleLabels ? q.scaleLabels[String(value)] : void 0,
|
|
5653
5687
|
count: distMap[value] || 0,
|
|
5654
5688
|
percentage: answeredCount > 0 ? Math.round((distMap[value] || 0) / answeredCount * 1e3) / 10 : 0
|
|
5655
5689
|
}));
|
|
@@ -5660,6 +5694,7 @@ function computeSurveyAnalytics(survey, rawResponses, filter = {}) {
|
|
|
5660
5694
|
max: maxVal,
|
|
5661
5695
|
lowLabel: q.lowLabel,
|
|
5662
5696
|
highLabel: q.highLabel,
|
|
5697
|
+
scaleLabels: q.scaleLabels,
|
|
5663
5698
|
average: answeredCount > 0 ? Math.round(sum / answeredCount * 100) / 100 : 0,
|
|
5664
5699
|
distribution,
|
|
5665
5700
|
npsBreakdown: q.type === "nps" ? {
|
|
@@ -5848,6 +5883,7 @@ function computePublicSurveyResults(survey, rawResponses) {
|
|
|
5848
5883
|
optionsBreakdown: qs.optionsBreakdown,
|
|
5849
5884
|
average: qs.average,
|
|
5850
5885
|
distribution: qs.distribution,
|
|
5886
|
+
scaleLabels: qs.scaleLabels,
|
|
5851
5887
|
npsBreakdown: qs.npsBreakdown,
|
|
5852
5888
|
rankingBreakdown: qs.rankingBreakdown
|
|
5853
5889
|
}))
|
|
@@ -5860,9 +5896,17 @@ function escapeCsvCell(val) {
|
|
|
5860
5896
|
}
|
|
5861
5897
|
return str;
|
|
5862
5898
|
}
|
|
5863
|
-
function
|
|
5899
|
+
function buildSurveyResponseExportAoA(survey, rawResponses, locale = "en") {
|
|
5900
|
+
const tr = String(locale || "").toLowerCase().startsWith("tr");
|
|
5864
5901
|
const activeQuestions = (survey.questions || []).filter((q) => q && q.type !== "statement");
|
|
5865
|
-
const headers = [
|
|
5902
|
+
const headers = tr ? [
|
|
5903
|
+
"Yanıt ID",
|
|
5904
|
+
"Gönderim Tarihi",
|
|
5905
|
+
"Dil",
|
|
5906
|
+
"Süre (sn)",
|
|
5907
|
+
"NPS Puanı",
|
|
5908
|
+
"NPS Kategorisi"
|
|
5909
|
+
] : [
|
|
5866
5910
|
"Response ID",
|
|
5867
5911
|
"Submitted At",
|
|
5868
5912
|
"Locale",
|
|
@@ -5880,18 +5924,18 @@ function exportSurveyResponsesToCsv(survey, rawResponses, locale = "en") {
|
|
|
5880
5924
|
} else {
|
|
5881
5925
|
headers.push(`${qTitle} (${q.key})`);
|
|
5882
5926
|
if (q.allowOther) {
|
|
5883
|
-
headers.push(`${qTitle} [Other Text]`);
|
|
5927
|
+
headers.push(`${qTitle} [${tr ? "Diğer Açıklama" : "Other Text"}]`);
|
|
5884
5928
|
}
|
|
5885
5929
|
}
|
|
5886
5930
|
}
|
|
5887
|
-
const
|
|
5931
|
+
const rows = [];
|
|
5888
5932
|
for (const r of rawResponses || []) {
|
|
5889
5933
|
const rowCells = [
|
|
5890
5934
|
String(r.id || r.documentId || ""),
|
|
5891
5935
|
String(r.submittedAt || r.createdAt || ""),
|
|
5892
5936
|
String(r.locale || ""),
|
|
5893
|
-
String(r.durationSeconds ?? ""),
|
|
5894
|
-
r.npsValue !== null && r.npsValue !== void 0 ?
|
|
5937
|
+
typeof r.durationSeconds === "number" ? r.durationSeconds : String(r.durationSeconds ?? ""),
|
|
5938
|
+
typeof r.npsValue === "number" ? r.npsValue : r.npsValue !== null && r.npsValue !== void 0 && r.npsValue !== "" ? Number(r.npsValue) : "",
|
|
5895
5939
|
String(r.npsCategory || "")
|
|
5896
5940
|
];
|
|
5897
5941
|
for (const q of activeQuestions) {
|
|
@@ -5908,7 +5952,7 @@ function exportSurveyResponsesToCsv(survey, rawResponses, locale = "en") {
|
|
|
5908
5952
|
} else if (Array.isArray(q.options) && q.options.length > 0) {
|
|
5909
5953
|
if (Array.isArray(ans)) {
|
|
5910
5954
|
const mapped = ans.map((optId) => {
|
|
5911
|
-
if (optId === "__other__") return
|
|
5955
|
+
if (optId === "__other__") return tr ? "Diğer" : "Other";
|
|
5912
5956
|
const found = q.options.find((o) => o.id === optId);
|
|
5913
5957
|
return found ? resolveLocalizedText(found.labels, locale, optId) : optId;
|
|
5914
5958
|
});
|
|
@@ -5916,7 +5960,7 @@ function exportSurveyResponsesToCsv(survey, rawResponses, locale = "en") {
|
|
|
5916
5960
|
} else if (ans !== void 0 && ans !== null && ans !== "") {
|
|
5917
5961
|
const strAns = String(ans);
|
|
5918
5962
|
if (strAns === "__other__") {
|
|
5919
|
-
rowCells.push(
|
|
5963
|
+
rowCells.push(tr ? "Diğer" : "Other");
|
|
5920
5964
|
} else {
|
|
5921
5965
|
const found = q.options.find((o) => o.id === strAns);
|
|
5922
5966
|
rowCells.push(found ? resolveLocalizedText(found.labels, locale, strAns) : strAns);
|
|
@@ -5928,16 +5972,131 @@ function exportSurveyResponsesToCsv(survey, rawResponses, locale = "en") {
|
|
|
5928
5972
|
rowCells.push(String(r.otherTexts?.[q.key] || ""));
|
|
5929
5973
|
}
|
|
5930
5974
|
} else {
|
|
5931
|
-
|
|
5975
|
+
if (q.type === "likert_scale" && q.scaleLabels && ans !== void 0 && ans !== null && ans !== "") {
|
|
5976
|
+
const ptLbl = resolveLocalizedText(q.scaleLabels[String(ans)], locale, "");
|
|
5977
|
+
rowCells.push(ptLbl ? `${ans} - ${ptLbl}` : Number.isNaN(Number(ans)) ? String(ans) : Number(ans));
|
|
5978
|
+
} else if ((q.type === "nps" || q.type === "star_rating" || q.type === "likert_scale") && ans !== void 0 && ans !== null && ans !== "" && !Number.isNaN(Number(ans))) {
|
|
5979
|
+
rowCells.push(Number(ans));
|
|
5980
|
+
} else {
|
|
5981
|
+
rowCells.push(ans === void 0 || ans === null ? "" : String(ans));
|
|
5982
|
+
}
|
|
5932
5983
|
if (q.allowOther) {
|
|
5933
5984
|
rowCells.push(String(r.otherTexts?.[q.key] || ""));
|
|
5934
5985
|
}
|
|
5935
5986
|
}
|
|
5936
5987
|
}
|
|
5937
|
-
|
|
5988
|
+
rows.push(rowCells);
|
|
5989
|
+
}
|
|
5990
|
+
return { headers, rows };
|
|
5991
|
+
}
|
|
5992
|
+
function computeAutoColWidths(aoa) {
|
|
5993
|
+
const colCount = aoa.reduce((m, r) => Math.max(m, r.length), 0);
|
|
5994
|
+
const widths = [];
|
|
5995
|
+
for (let c = 0; c < colCount; c++) {
|
|
5996
|
+
let maxLen = 12;
|
|
5997
|
+
for (let r = 0; r < Math.min(aoa.length, 300); r++) {
|
|
5998
|
+
const cell = aoa[r]?.[c];
|
|
5999
|
+
const str = cell === null || cell === void 0 ? "" : String(cell);
|
|
6000
|
+
if (str.length > maxLen) maxLen = str.length;
|
|
6001
|
+
}
|
|
6002
|
+
widths.push({ wch: Math.min(54, maxLen + 3) });
|
|
6003
|
+
}
|
|
6004
|
+
return widths;
|
|
6005
|
+
}
|
|
6006
|
+
function exportSurveyResponsesToCsv(survey, rawResponses, locale = "en") {
|
|
6007
|
+
const { headers, rows } = buildSurveyResponseExportAoA(survey, rawResponses, locale);
|
|
6008
|
+
const lines = [headers.map(escapeCsvCell).join(",")];
|
|
6009
|
+
for (const r of rows) {
|
|
6010
|
+
lines.push(r.map(escapeCsvCell).join(","));
|
|
5938
6011
|
}
|
|
5939
6012
|
return `\uFEFF${lines.join("\r\n")}`;
|
|
5940
6013
|
}
|
|
6014
|
+
function exportSurveyResponsesToXlsxBuffer(survey, rawResponses, locale = "en") {
|
|
6015
|
+
const tr = String(locale || "").toLowerCase().startsWith("tr");
|
|
6016
|
+
const { headers, rows } = buildSurveyResponseExportAoA(survey, rawResponses, locale);
|
|
6017
|
+
const responsesAoA = [headers, ...rows];
|
|
6018
|
+
const wb = XLSX.utils.book_new();
|
|
6019
|
+
const wsResponses = XLSX.utils.aoa_to_sheet(responsesAoA);
|
|
6020
|
+
wsResponses["!cols"] = computeAutoColWidths(responsesAoA);
|
|
6021
|
+
XLSX.utils.book_append_sheet(wb, wsResponses, tr ? "Yanitlar" : "Responses");
|
|
6022
|
+
const analytics = computeSurveyAnalytics(survey, rawResponses);
|
|
6023
|
+
const s = analytics.summary;
|
|
6024
|
+
const summaryAoA = [
|
|
6025
|
+
[tr ? "Anket Başlığı" : "Survey Title", resolveLocalizedText(survey.titleI18n, locale, survey.title)],
|
|
6026
|
+
["Survey Slug", survey.slug],
|
|
6027
|
+
[tr ? "Dışa Aktarım Tarihi" : "Exported At", (/* @__PURE__ */ new Date()).toISOString()],
|
|
6028
|
+
[tr ? "Toplam Yanıt" : "Total Responses", s.totalResponses],
|
|
6029
|
+
[tr ? "Ortalama Süre (sn)" : "Average Duration (s)", s.avgDurationSeconds],
|
|
6030
|
+
[tr ? "Medyan Süre (sn)" : "Median Duration (s)", s.medianDurationSeconds]
|
|
6031
|
+
];
|
|
6032
|
+
if (s.nps?.hasNps) {
|
|
6033
|
+
summaryAoA.push(
|
|
6034
|
+
["Net Promoter Score (NPS)", s.nps.score ?? 0],
|
|
6035
|
+
[
|
|
6036
|
+
tr ? "NPS Dağılımı" : "NPS Breakdown",
|
|
6037
|
+
`Promoters: ${s.nps.promoters} (${s.nps.promotersPct}%) | Passives: ${s.nps.passives} (${s.nps.passivesPct}%) | Detractors: ${s.nps.detractors} (${s.nps.detractorsPct}%)`
|
|
6038
|
+
]
|
|
6039
|
+
);
|
|
6040
|
+
}
|
|
6041
|
+
summaryAoA.push(
|
|
6042
|
+
[],
|
|
6043
|
+
tr ? ["Soru Anahtarı", "Soru Başlığı", "Tip", "Seçenek / Kriter", "Adet / Ort.", "Yüzde (%)"] : ["Question Key", "Question Title", "Type", "Option / Metric", "Count / Avg", "Share (%)"]
|
|
6044
|
+
);
|
|
6045
|
+
for (const qs of analytics.questionStats) {
|
|
6046
|
+
const qTitle = resolveLocalizedText(qs.title, locale, qs.key);
|
|
6047
|
+
if (Array.isArray(qs.optionsBreakdown)) {
|
|
6048
|
+
for (const opt of qs.optionsBreakdown) {
|
|
6049
|
+
const optLbl = opt.id === "__other__" ? tr ? "Diğer" : "Other" : resolveLocalizedText(opt.labels, locale, opt.id);
|
|
6050
|
+
summaryAoA.push([qs.key, qTitle, qs.type, optLbl, opt.count, opt.percentage]);
|
|
6051
|
+
}
|
|
6052
|
+
} else if (Array.isArray(qs.distribution)) {
|
|
6053
|
+
summaryAoA.push([
|
|
6054
|
+
qs.key,
|
|
6055
|
+
qTitle,
|
|
6056
|
+
qs.type,
|
|
6057
|
+
tr ? "Ortalama Puan" : "Average Score",
|
|
6058
|
+
qs.average,
|
|
6059
|
+
""
|
|
6060
|
+
]);
|
|
6061
|
+
for (const d of qs.distribution) {
|
|
6062
|
+
const ptLbl = d.labels ? resolveLocalizedText(d.labels, locale, "") : "";
|
|
6063
|
+
summaryAoA.push([
|
|
6064
|
+
qs.key,
|
|
6065
|
+
qTitle,
|
|
6066
|
+
qs.type,
|
|
6067
|
+
ptLbl ? `${d.value} - ${ptLbl}` : String(d.value),
|
|
6068
|
+
d.count,
|
|
6069
|
+
d.percentage
|
|
6070
|
+
]);
|
|
6071
|
+
}
|
|
6072
|
+
} else if (Array.isArray(qs.rankingBreakdown)) {
|
|
6073
|
+
for (const rk of qs.rankingBreakdown) {
|
|
6074
|
+
summaryAoA.push([
|
|
6075
|
+
qs.key,
|
|
6076
|
+
qTitle,
|
|
6077
|
+
qs.type,
|
|
6078
|
+
resolveLocalizedText(rk.labels, locale, rk.id),
|
|
6079
|
+
rk.averageRank,
|
|
6080
|
+
rk.scorePercentage
|
|
6081
|
+
]);
|
|
6082
|
+
}
|
|
6083
|
+
} else {
|
|
6084
|
+
summaryAoA.push([
|
|
6085
|
+
qs.key,
|
|
6086
|
+
qTitle,
|
|
6087
|
+
qs.type,
|
|
6088
|
+
tr ? "Toplam Yanıt" : "Answered Count",
|
|
6089
|
+
qs.answeredCount || 0,
|
|
6090
|
+
""
|
|
6091
|
+
]);
|
|
6092
|
+
}
|
|
6093
|
+
}
|
|
6094
|
+
const wsSummary = XLSX.utils.aoa_to_sheet(summaryAoA);
|
|
6095
|
+
wsSummary["!cols"] = computeAutoColWidths(summaryAoA);
|
|
6096
|
+
XLSX.utils.book_append_sheet(wb, wsSummary, tr ? "Ozet_Istatistik" : "Summary");
|
|
6097
|
+
const out = XLSX.write(wb, { type: "buffer", bookType: "xlsx" });
|
|
6098
|
+
return Buffer.isBuffer(out) ? out : Buffer.from(out);
|
|
6099
|
+
}
|
|
5941
6100
|
const SURVEY_UID = "plugin::content-input.ci-survey";
|
|
5942
6101
|
const SURVEY_RESPONSE_UID = "plugin::content-input.ci-survey-response";
|
|
5943
6102
|
let activeSeedPromise = null;
|
|
@@ -6509,6 +6668,18 @@ const ciSurveyService = ({ strapi }) => ({
|
|
|
6509
6668
|
return true;
|
|
6510
6669
|
});
|
|
6511
6670
|
}
|
|
6671
|
+
if (options2.format === "xlsx") {
|
|
6672
|
+
const xlsxBuf = exportSurveyResponsesToXlsxBuffer(
|
|
6673
|
+
survey,
|
|
6674
|
+
responses,
|
|
6675
|
+
options2.locale || "en"
|
|
6676
|
+
);
|
|
6677
|
+
return {
|
|
6678
|
+
filename: `${survey.slug}-responses.xlsx`,
|
|
6679
|
+
contentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
6680
|
+
body: xlsxBuf
|
|
6681
|
+
};
|
|
6682
|
+
}
|
|
6512
6683
|
if (options2.format === "json") {
|
|
6513
6684
|
return {
|
|
6514
6685
|
filename: `${survey.slug}-responses.json`,
|
package/dist/server/index.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import fs from "fs";
|
|
|
3
3
|
import { createRequire } from "module";
|
|
4
4
|
import os from "os";
|
|
5
5
|
import path from "path";
|
|
6
|
+
import * as XLSXNs from "xlsx";
|
|
6
7
|
const register = ({ strapi }) => {
|
|
7
8
|
strapi.customFields.register({
|
|
8
9
|
name: "content-input",
|
|
@@ -1908,18 +1909,31 @@ const ciSurveyController = ({ strapi }) => ({
|
|
|
1908
1909
|
async exportResponses(ctx) {
|
|
1909
1910
|
try {
|
|
1910
1911
|
const { id } = ctx.params;
|
|
1911
|
-
const
|
|
1912
|
+
const rawFmt = String(ctx.query?.format || "xlsx").toLowerCase();
|
|
1913
|
+
const format = rawFmt === "json" ? "json" : rawFmt === "csv" ? "csv" : "xlsx";
|
|
1912
1914
|
const locale = String(ctx.query?.locale || "en").trim();
|
|
1913
1915
|
const from = ctx.query?.from ? String(ctx.query.from) : void 0;
|
|
1914
1916
|
const to = ctx.query?.to ? String(ctx.query.to) : void 0;
|
|
1917
|
+
const encoding = String(ctx.query?.encoding || "").toLowerCase();
|
|
1915
1918
|
const exported = await strapi.plugin("content-input").service("ci-survey").exportResponses(id, { format, locale, from, to });
|
|
1916
1919
|
if (!exported) {
|
|
1917
1920
|
return ctx.notFound("Survey not found");
|
|
1918
1921
|
}
|
|
1922
|
+
if (encoding === "base64") {
|
|
1923
|
+
const buf = Buffer.isBuffer(exported.body) ? exported.body : Buffer.from(String(exported.body), "utf8");
|
|
1924
|
+
ctx.status = 200;
|
|
1925
|
+
ctx.body = {
|
|
1926
|
+
filename: exported.filename,
|
|
1927
|
+
contentType: exported.contentType,
|
|
1928
|
+
base64: buf.toString("base64")
|
|
1929
|
+
};
|
|
1930
|
+
return;
|
|
1931
|
+
}
|
|
1932
|
+
ctx.body = exported.body;
|
|
1933
|
+
ctx.type = exported.contentType;
|
|
1919
1934
|
ctx.set("Content-Type", exported.contentType);
|
|
1920
1935
|
ctx.set("Content-Disposition", `attachment; filename="${exported.filename}"`);
|
|
1921
1936
|
ctx.status = 200;
|
|
1922
|
-
ctx.body = exported.body;
|
|
1923
1937
|
} catch (err) {
|
|
1924
1938
|
ctx.throw(500, err);
|
|
1925
1939
|
}
|
|
@@ -5267,6 +5281,7 @@ const ciFormService = ({ strapi }) => ({
|
|
|
5267
5281
|
};
|
|
5268
5282
|
}
|
|
5269
5283
|
});
|
|
5284
|
+
const XLSX = XLSXNs?.utils ? XLSXNs : XLSXNs?.default || XLSXNs;
|
|
5270
5285
|
function evalSingleRule(rule, answers) {
|
|
5271
5286
|
const targetVal = answers ? answers[rule.questionKey] : void 0;
|
|
5272
5287
|
const op = rule.operator;
|
|
@@ -5643,6 +5658,7 @@ function computeSurveyAnalytics(survey, rawResponses, filter = {}) {
|
|
|
5643
5658
|
}
|
|
5644
5659
|
const distribution = Object.keys(distMap).map(Number).sort((a, b) => a - b).map((value) => ({
|
|
5645
5660
|
value,
|
|
5661
|
+
labels: q.scaleLabels ? q.scaleLabels[String(value)] : void 0,
|
|
5646
5662
|
count: distMap[value] || 0,
|
|
5647
5663
|
percentage: answeredCount > 0 ? Math.round((distMap[value] || 0) / answeredCount * 1e3) / 10 : 0
|
|
5648
5664
|
}));
|
|
@@ -5653,6 +5669,7 @@ function computeSurveyAnalytics(survey, rawResponses, filter = {}) {
|
|
|
5653
5669
|
max: maxVal,
|
|
5654
5670
|
lowLabel: q.lowLabel,
|
|
5655
5671
|
highLabel: q.highLabel,
|
|
5672
|
+
scaleLabels: q.scaleLabels,
|
|
5656
5673
|
average: answeredCount > 0 ? Math.round(sum / answeredCount * 100) / 100 : 0,
|
|
5657
5674
|
distribution,
|
|
5658
5675
|
npsBreakdown: q.type === "nps" ? {
|
|
@@ -5841,6 +5858,7 @@ function computePublicSurveyResults(survey, rawResponses) {
|
|
|
5841
5858
|
optionsBreakdown: qs.optionsBreakdown,
|
|
5842
5859
|
average: qs.average,
|
|
5843
5860
|
distribution: qs.distribution,
|
|
5861
|
+
scaleLabels: qs.scaleLabels,
|
|
5844
5862
|
npsBreakdown: qs.npsBreakdown,
|
|
5845
5863
|
rankingBreakdown: qs.rankingBreakdown
|
|
5846
5864
|
}))
|
|
@@ -5853,9 +5871,17 @@ function escapeCsvCell(val) {
|
|
|
5853
5871
|
}
|
|
5854
5872
|
return str;
|
|
5855
5873
|
}
|
|
5856
|
-
function
|
|
5874
|
+
function buildSurveyResponseExportAoA(survey, rawResponses, locale = "en") {
|
|
5875
|
+
const tr = String(locale || "").toLowerCase().startsWith("tr");
|
|
5857
5876
|
const activeQuestions = (survey.questions || []).filter((q) => q && q.type !== "statement");
|
|
5858
|
-
const headers = [
|
|
5877
|
+
const headers = tr ? [
|
|
5878
|
+
"Yanıt ID",
|
|
5879
|
+
"Gönderim Tarihi",
|
|
5880
|
+
"Dil",
|
|
5881
|
+
"Süre (sn)",
|
|
5882
|
+
"NPS Puanı",
|
|
5883
|
+
"NPS Kategorisi"
|
|
5884
|
+
] : [
|
|
5859
5885
|
"Response ID",
|
|
5860
5886
|
"Submitted At",
|
|
5861
5887
|
"Locale",
|
|
@@ -5873,18 +5899,18 @@ function exportSurveyResponsesToCsv(survey, rawResponses, locale = "en") {
|
|
|
5873
5899
|
} else {
|
|
5874
5900
|
headers.push(`${qTitle} (${q.key})`);
|
|
5875
5901
|
if (q.allowOther) {
|
|
5876
|
-
headers.push(`${qTitle} [Other Text]`);
|
|
5902
|
+
headers.push(`${qTitle} [${tr ? "Diğer Açıklama" : "Other Text"}]`);
|
|
5877
5903
|
}
|
|
5878
5904
|
}
|
|
5879
5905
|
}
|
|
5880
|
-
const
|
|
5906
|
+
const rows = [];
|
|
5881
5907
|
for (const r of rawResponses || []) {
|
|
5882
5908
|
const rowCells = [
|
|
5883
5909
|
String(r.id || r.documentId || ""),
|
|
5884
5910
|
String(r.submittedAt || r.createdAt || ""),
|
|
5885
5911
|
String(r.locale || ""),
|
|
5886
|
-
String(r.durationSeconds ?? ""),
|
|
5887
|
-
r.npsValue !== null && r.npsValue !== void 0 ?
|
|
5912
|
+
typeof r.durationSeconds === "number" ? r.durationSeconds : String(r.durationSeconds ?? ""),
|
|
5913
|
+
typeof r.npsValue === "number" ? r.npsValue : r.npsValue !== null && r.npsValue !== void 0 && r.npsValue !== "" ? Number(r.npsValue) : "",
|
|
5888
5914
|
String(r.npsCategory || "")
|
|
5889
5915
|
];
|
|
5890
5916
|
for (const q of activeQuestions) {
|
|
@@ -5901,7 +5927,7 @@ function exportSurveyResponsesToCsv(survey, rawResponses, locale = "en") {
|
|
|
5901
5927
|
} else if (Array.isArray(q.options) && q.options.length > 0) {
|
|
5902
5928
|
if (Array.isArray(ans)) {
|
|
5903
5929
|
const mapped = ans.map((optId) => {
|
|
5904
|
-
if (optId === "__other__") return
|
|
5930
|
+
if (optId === "__other__") return tr ? "Diğer" : "Other";
|
|
5905
5931
|
const found = q.options.find((o) => o.id === optId);
|
|
5906
5932
|
return found ? resolveLocalizedText(found.labels, locale, optId) : optId;
|
|
5907
5933
|
});
|
|
@@ -5909,7 +5935,7 @@ function exportSurveyResponsesToCsv(survey, rawResponses, locale = "en") {
|
|
|
5909
5935
|
} else if (ans !== void 0 && ans !== null && ans !== "") {
|
|
5910
5936
|
const strAns = String(ans);
|
|
5911
5937
|
if (strAns === "__other__") {
|
|
5912
|
-
rowCells.push(
|
|
5938
|
+
rowCells.push(tr ? "Diğer" : "Other");
|
|
5913
5939
|
} else {
|
|
5914
5940
|
const found = q.options.find((o) => o.id === strAns);
|
|
5915
5941
|
rowCells.push(found ? resolveLocalizedText(found.labels, locale, strAns) : strAns);
|
|
@@ -5921,16 +5947,131 @@ function exportSurveyResponsesToCsv(survey, rawResponses, locale = "en") {
|
|
|
5921
5947
|
rowCells.push(String(r.otherTexts?.[q.key] || ""));
|
|
5922
5948
|
}
|
|
5923
5949
|
} else {
|
|
5924
|
-
|
|
5950
|
+
if (q.type === "likert_scale" && q.scaleLabels && ans !== void 0 && ans !== null && ans !== "") {
|
|
5951
|
+
const ptLbl = resolveLocalizedText(q.scaleLabels[String(ans)], locale, "");
|
|
5952
|
+
rowCells.push(ptLbl ? `${ans} - ${ptLbl}` : Number.isNaN(Number(ans)) ? String(ans) : Number(ans));
|
|
5953
|
+
} else if ((q.type === "nps" || q.type === "star_rating" || q.type === "likert_scale") && ans !== void 0 && ans !== null && ans !== "" && !Number.isNaN(Number(ans))) {
|
|
5954
|
+
rowCells.push(Number(ans));
|
|
5955
|
+
} else {
|
|
5956
|
+
rowCells.push(ans === void 0 || ans === null ? "" : String(ans));
|
|
5957
|
+
}
|
|
5925
5958
|
if (q.allowOther) {
|
|
5926
5959
|
rowCells.push(String(r.otherTexts?.[q.key] || ""));
|
|
5927
5960
|
}
|
|
5928
5961
|
}
|
|
5929
5962
|
}
|
|
5930
|
-
|
|
5963
|
+
rows.push(rowCells);
|
|
5964
|
+
}
|
|
5965
|
+
return { headers, rows };
|
|
5966
|
+
}
|
|
5967
|
+
function computeAutoColWidths(aoa) {
|
|
5968
|
+
const colCount = aoa.reduce((m, r) => Math.max(m, r.length), 0);
|
|
5969
|
+
const widths = [];
|
|
5970
|
+
for (let c = 0; c < colCount; c++) {
|
|
5971
|
+
let maxLen = 12;
|
|
5972
|
+
for (let r = 0; r < Math.min(aoa.length, 300); r++) {
|
|
5973
|
+
const cell = aoa[r]?.[c];
|
|
5974
|
+
const str = cell === null || cell === void 0 ? "" : String(cell);
|
|
5975
|
+
if (str.length > maxLen) maxLen = str.length;
|
|
5976
|
+
}
|
|
5977
|
+
widths.push({ wch: Math.min(54, maxLen + 3) });
|
|
5978
|
+
}
|
|
5979
|
+
return widths;
|
|
5980
|
+
}
|
|
5981
|
+
function exportSurveyResponsesToCsv(survey, rawResponses, locale = "en") {
|
|
5982
|
+
const { headers, rows } = buildSurveyResponseExportAoA(survey, rawResponses, locale);
|
|
5983
|
+
const lines = [headers.map(escapeCsvCell).join(",")];
|
|
5984
|
+
for (const r of rows) {
|
|
5985
|
+
lines.push(r.map(escapeCsvCell).join(","));
|
|
5931
5986
|
}
|
|
5932
5987
|
return `\uFEFF${lines.join("\r\n")}`;
|
|
5933
5988
|
}
|
|
5989
|
+
function exportSurveyResponsesToXlsxBuffer(survey, rawResponses, locale = "en") {
|
|
5990
|
+
const tr = String(locale || "").toLowerCase().startsWith("tr");
|
|
5991
|
+
const { headers, rows } = buildSurveyResponseExportAoA(survey, rawResponses, locale);
|
|
5992
|
+
const responsesAoA = [headers, ...rows];
|
|
5993
|
+
const wb = XLSX.utils.book_new();
|
|
5994
|
+
const wsResponses = XLSX.utils.aoa_to_sheet(responsesAoA);
|
|
5995
|
+
wsResponses["!cols"] = computeAutoColWidths(responsesAoA);
|
|
5996
|
+
XLSX.utils.book_append_sheet(wb, wsResponses, tr ? "Yanitlar" : "Responses");
|
|
5997
|
+
const analytics = computeSurveyAnalytics(survey, rawResponses);
|
|
5998
|
+
const s = analytics.summary;
|
|
5999
|
+
const summaryAoA = [
|
|
6000
|
+
[tr ? "Anket Başlığı" : "Survey Title", resolveLocalizedText(survey.titleI18n, locale, survey.title)],
|
|
6001
|
+
["Survey Slug", survey.slug],
|
|
6002
|
+
[tr ? "Dışa Aktarım Tarihi" : "Exported At", (/* @__PURE__ */ new Date()).toISOString()],
|
|
6003
|
+
[tr ? "Toplam Yanıt" : "Total Responses", s.totalResponses],
|
|
6004
|
+
[tr ? "Ortalama Süre (sn)" : "Average Duration (s)", s.avgDurationSeconds],
|
|
6005
|
+
[tr ? "Medyan Süre (sn)" : "Median Duration (s)", s.medianDurationSeconds]
|
|
6006
|
+
];
|
|
6007
|
+
if (s.nps?.hasNps) {
|
|
6008
|
+
summaryAoA.push(
|
|
6009
|
+
["Net Promoter Score (NPS)", s.nps.score ?? 0],
|
|
6010
|
+
[
|
|
6011
|
+
tr ? "NPS Dağılımı" : "NPS Breakdown",
|
|
6012
|
+
`Promoters: ${s.nps.promoters} (${s.nps.promotersPct}%) | Passives: ${s.nps.passives} (${s.nps.passivesPct}%) | Detractors: ${s.nps.detractors} (${s.nps.detractorsPct}%)`
|
|
6013
|
+
]
|
|
6014
|
+
);
|
|
6015
|
+
}
|
|
6016
|
+
summaryAoA.push(
|
|
6017
|
+
[],
|
|
6018
|
+
tr ? ["Soru Anahtarı", "Soru Başlığı", "Tip", "Seçenek / Kriter", "Adet / Ort.", "Yüzde (%)"] : ["Question Key", "Question Title", "Type", "Option / Metric", "Count / Avg", "Share (%)"]
|
|
6019
|
+
);
|
|
6020
|
+
for (const qs of analytics.questionStats) {
|
|
6021
|
+
const qTitle = resolveLocalizedText(qs.title, locale, qs.key);
|
|
6022
|
+
if (Array.isArray(qs.optionsBreakdown)) {
|
|
6023
|
+
for (const opt of qs.optionsBreakdown) {
|
|
6024
|
+
const optLbl = opt.id === "__other__" ? tr ? "Diğer" : "Other" : resolveLocalizedText(opt.labels, locale, opt.id);
|
|
6025
|
+
summaryAoA.push([qs.key, qTitle, qs.type, optLbl, opt.count, opt.percentage]);
|
|
6026
|
+
}
|
|
6027
|
+
} else if (Array.isArray(qs.distribution)) {
|
|
6028
|
+
summaryAoA.push([
|
|
6029
|
+
qs.key,
|
|
6030
|
+
qTitle,
|
|
6031
|
+
qs.type,
|
|
6032
|
+
tr ? "Ortalama Puan" : "Average Score",
|
|
6033
|
+
qs.average,
|
|
6034
|
+
""
|
|
6035
|
+
]);
|
|
6036
|
+
for (const d of qs.distribution) {
|
|
6037
|
+
const ptLbl = d.labels ? resolveLocalizedText(d.labels, locale, "") : "";
|
|
6038
|
+
summaryAoA.push([
|
|
6039
|
+
qs.key,
|
|
6040
|
+
qTitle,
|
|
6041
|
+
qs.type,
|
|
6042
|
+
ptLbl ? `${d.value} - ${ptLbl}` : String(d.value),
|
|
6043
|
+
d.count,
|
|
6044
|
+
d.percentage
|
|
6045
|
+
]);
|
|
6046
|
+
}
|
|
6047
|
+
} else if (Array.isArray(qs.rankingBreakdown)) {
|
|
6048
|
+
for (const rk of qs.rankingBreakdown) {
|
|
6049
|
+
summaryAoA.push([
|
|
6050
|
+
qs.key,
|
|
6051
|
+
qTitle,
|
|
6052
|
+
qs.type,
|
|
6053
|
+
resolveLocalizedText(rk.labels, locale, rk.id),
|
|
6054
|
+
rk.averageRank,
|
|
6055
|
+
rk.scorePercentage
|
|
6056
|
+
]);
|
|
6057
|
+
}
|
|
6058
|
+
} else {
|
|
6059
|
+
summaryAoA.push([
|
|
6060
|
+
qs.key,
|
|
6061
|
+
qTitle,
|
|
6062
|
+
qs.type,
|
|
6063
|
+
tr ? "Toplam Yanıt" : "Answered Count",
|
|
6064
|
+
qs.answeredCount || 0,
|
|
6065
|
+
""
|
|
6066
|
+
]);
|
|
6067
|
+
}
|
|
6068
|
+
}
|
|
6069
|
+
const wsSummary = XLSX.utils.aoa_to_sheet(summaryAoA);
|
|
6070
|
+
wsSummary["!cols"] = computeAutoColWidths(summaryAoA);
|
|
6071
|
+
XLSX.utils.book_append_sheet(wb, wsSummary, tr ? "Ozet_Istatistik" : "Summary");
|
|
6072
|
+
const out = XLSX.write(wb, { type: "buffer", bookType: "xlsx" });
|
|
6073
|
+
return Buffer.isBuffer(out) ? out : Buffer.from(out);
|
|
6074
|
+
}
|
|
5934
6075
|
const SURVEY_UID = "plugin::content-input.ci-survey";
|
|
5935
6076
|
const SURVEY_RESPONSE_UID = "plugin::content-input.ci-survey-response";
|
|
5936
6077
|
let activeSeedPromise = null;
|
|
@@ -6502,6 +6643,18 @@ const ciSurveyService = ({ strapi }) => ({
|
|
|
6502
6643
|
return true;
|
|
6503
6644
|
});
|
|
6504
6645
|
}
|
|
6646
|
+
if (options2.format === "xlsx") {
|
|
6647
|
+
const xlsxBuf = exportSurveyResponsesToXlsxBuffer(
|
|
6648
|
+
survey,
|
|
6649
|
+
responses,
|
|
6650
|
+
options2.locale || "en"
|
|
6651
|
+
);
|
|
6652
|
+
return {
|
|
6653
|
+
filename: `${survey.slug}-responses.xlsx`,
|
|
6654
|
+
contentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
6655
|
+
body: xlsxBuf
|
|
6656
|
+
};
|
|
6657
|
+
}
|
|
6505
6658
|
if (options2.format === "json") {
|
|
6506
6659
|
return {
|
|
6507
6660
|
filename: `${survey.slug}-responses.json`,
|