diff --git a/authentication/auth.go b/authentication/auth.go index 6b648543..8d47b2f6 100644 --- a/authentication/auth.go +++ b/authentication/auth.go @@ -173,6 +173,12 @@ func generateClaimsV2(claimValues map[string][]string, schema QuestionnaireSchem claims["tx_id"] = TxID.String() claims["version"] = "v2" + // always send survey_id for business/test surveys unless it's already in survey metadata + _, ok := claimValues["survey_id"] + if !ok && !isSocialSurvey(schema.SurveyType) { + claimValues["survey_id"] = []string{schema.SurveyId} + } + surveyMetadata := make(map[string]interface{}) data := make(map[string]interface{}) diff --git a/launch.go b/launch.go index e4eb2476..612134ff 100644 --- a/launch.go +++ b/launch.go @@ -168,7 +168,7 @@ func redirectURL(w http.ResponseWriter, r *http.Request) { } else if launchVersion != "" { http.Redirect(w, r, hostURL+"/session?token="+token, 301) } else { - http.Error(w,"Invalid Action", 500) + http.Error(w, "Invalid Action", 500) } } diff --git a/static/javascript/launch.js b/static/javascript/launch.js index 501c711d..be9a55e2 100644 --- a/static/javascript/launch.js +++ b/static/javascript/launch.js @@ -139,6 +139,9 @@ // store fetch so it only needs to be re-done if the survey changes let supplementaryDataSets = null; +// We always need survey_id from top-level schema metadata for SDS retrieval +let schemaSurveyId = null; + function clearSurveyMetadataFields() { document.querySelector("#survey_metadata_fields").innerHTML = ""; showSupplementaryData(false); @@ -386,14 +389,31 @@ function showCIRMetdata(cirInstrumentId, cirSchema) { } function updateSDSDropdown() { - const surveyId = document.getElementById("survey_id")?.value; + const surveyId = schemaSurveyId; const periodId = document.getElementById("period_id")?.value; + + const supplementaryDataSection = document.querySelector( + "#supplementary_data", + ); + const sdsDatasetIdElement = document.querySelector("#sds_dataset_id"); + loadSDSDatasetMetadata(surveyId, periodId) .then((sds_metadata_response) => { if (sds_metadata_response?.length) { + document.querySelector("#supplementary_data").innerHTML = ""; supplementaryDataSets = sds_metadata_response; showSupplementaryData(true); showSubmitFlushButtons(true); + + if ( + !document + .querySelector("#survey_metadata") + .contains(sdsDatasetIdElement) + ) { + // add sds_dataset_id field into the SDS metadata section if not already in survey metadata + supplementaryDataSection.innerHTML = `
${getLabelFor("sds_dataset_id")}
`; + } + document.querySelector("#sds_dataset_id").innerHTML = sds_metadata_response .map( @@ -428,6 +448,9 @@ function loadSchemaMetadata(schemaName, schemaUrl, cirInstrumentId) { document.querySelector("#survey_metadata").innerHTML = ""; document.querySelector("#survey_metadata").innerHTML = ""; + // We always need survey_id from top-level schema metadata for SDS retrieval + schemaSurveyId = schema_response.survey_id; + if (schema_response.metadata.length > 0) { document.querySelector("#survey_metadata").innerHTML = schema_response.metadata @@ -483,22 +506,30 @@ function loadSupplementaryDataInfo() { const selectedDataset = supplementaryDataSets?.find( (d) => d["dataset_id"] === selectedDatasetId, ); - if (selectedDataset) { - const sdsDatasetMetadataKeys = [ - "title", - "sds_schema_version", - "total_reporting_units", - "schema_version", - "sds_dataset_version", - ]; - - document.querySelector("#supplementary_data").innerHTML = - sdsDatasetMetadataKeys - .map( - (key) => - `
${getLabelFor(key)}${getInputField(key, "text", selectedDataset[key], true)}
`, - ) - .join(""); + + if (!selectedDataset) { + return; + } + + const sdsDatasetMetadataKeys = [ + "title", + "total_reporting_units", + "schema_version", + "sds_dataset_version", + ]; + + const sdsMetadataSection = document.querySelector("#supplementary_data"); + const sdsMetadataField = (key) => + `
${getLabelFor(key)}${getInputField(key, "text", selectedDataset[key], true)}
`; + + if (sdsMetadataSection.contains(document.querySelector("#sds_dataset_id"))) { + sdsMetadataSection.innerHTML += sdsDatasetMetadataKeys + .map(sdsMetadataField) + .join(""); + } else { + sdsMetadataSection.innerHTML = sdsDatasetMetadataKeys + .map(sdsMetadataField) + .join(""); } } diff --git a/surveys/surveys.go b/surveys/surveys.go index 9d6e839b..8c6f776d 100644 --- a/surveys/surveys.go +++ b/surveys/surveys.go @@ -44,7 +44,6 @@ type DatasetMetadata struct { SurveyID string `json:"survey_id"` PeriodID string `json:"period_id"` Title string `json:"title"` - SdsSchemaVersion int `json:"sds_schema_version"` SdsPublishedAt string `json:"sds_published_at"` TotalReportingUnits int `json:"total_reporting_units"` SchemaVersion string `json:"schema_version"` @@ -253,6 +252,7 @@ func GetSupplementaryDataSets(surveyId string, periodId string) ([]DatasetMetada log.Printf("SDS API Base URL: %s", hostURL) url := fmt.Sprintf("%s/v1/dataset_metadata?survey_id=%s&period_id=%s", hostURL, surveyId, periodId) + log.Printf("Getting SDS metadata: %s", url) resp, err := client.Get(url) if err != nil || (resp.StatusCode != 200 && resp.StatusCode != 404) { diff --git a/templates/launch.html b/templates/launch.html index dfca1a42..e0f2f07f 100644 --- a/templates/launch.html +++ b/templates/launch.html @@ -1,36 +1,41 @@ {{ define "title" }}Launch a Survey{{ end }} {{ define "body" }} -

Launch a survey

-
- Launch Pattern -
- - -
- Launch by Schema Name -
- - +
+ Launch by Schema Name +
+ + -
-

----------

- Launch Remote Schemas -
+ +
+

----------

+ Launch Remote Schemas +
-
-
+
+
Launch a survey class="qa-schema_url" onchange="setSchemaUrl(this)"> -
-
+
+
-
-
- -
-

----------

-
-
-

CIR Metadata

-
-
-

Survey Metadata

-
-

--- Metadata fields will be loaded when you select a version and load a schema ---

-
-
-

Supplementary Data

-
-
-

Required Data

-
- - +
+
+ +
+

----------

+
+
+

CIR Metadata

+
+
+

Survey Metadata

+
+

--- Metadata fields will be loaded when you select a version and load a schema ---

+
+
+

Supplementary Data

+
+
+

Required Data

+
+ + Reload symbol -
-
- - +
+
+ + Required Data src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/PjwhRE9DVFlQRSBzdmcgIFBVQkxJQyAnLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4nICAnaHR0cDovL3d3dy53My5vcmcvR3JhcGhpY3MvU1ZHLzEuMS9EVEQvc3ZnMTEuZHRkJz48c3ZnIGhlaWdodD0iNTEycHgiIGlkPSJMYXllcl8xIiBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCA1MTIgNTEyOyIgdmVyc2lvbj0iMS4xIiB2aWV3Qm94PSIwID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ii8+PC9nPjwvc3ZnPg==" alt="Reload symbol"> -
-

Runner Data

-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - - -
-
- + +

Runner Data

+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + + +
+ + -{{ end }} \ No newline at end of file +{{ end }}