Skip to content

Commit

Permalink
R chain: include schema summary (#3165)
Browse files Browse the repository at this point in the history
Co-authored-by: Stefano Ricci <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 30, 2023
1 parent a0e0d64 commit 044a10a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
3 changes: 2 additions & 1 deletion common/apiRoutes/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as rChain from './rChain'
import * as survey from './survey'

export { rChain }
export { rChain, survey }
2 changes: 2 additions & 0 deletions common/apiRoutes/survey.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export const getSurveyPath = (surveyId) => `/survey/${surveyId}`

export const schemaSummary = ({ surveyId, cycle }) => `${getSurveyPath(surveyId)}/schema-summary/?cycle=${cycle}`
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ export default class RFileReadData extends RFileSystem {
super(rChain, 'read-data')
}

async initSchemaSummary() {
const { survey, cycle } = this.rChain

const schemaSummaryCSV = arenaGetCSV(ApiRoutes.survey.schemaSummary({ surveyId: Survey.getId(survey), cycle }))
await this.appendContent(setVar('arena.schemaSummary', schemaSummaryCSV))
}

async initEntitiesData() {
const { chainUuid, survey, cycle, entities } = this.rChain

Expand Down Expand Up @@ -119,6 +126,8 @@ export default class RFileReadData extends RFileSystem {

const { listCategories, listTaxonomies } = this.rChain

await this.initSchemaSummary()

await this.initEntitiesData()

// Append categories and taxoniomies initialization
Expand Down
7 changes: 5 additions & 2 deletions server/modules/survey/service/schemaSummary/schemaSummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const getValidationsSummary = ({ nodeDef }) => {
.join('\n')
}

export const exportSchemaSummary = async ({ surveyId, cycle, outputStream }) => {
export const generateSchemaSummaryItems = async ({ surveyId, cycle }) => {
const survey = await SurveyManager.fetchSurveyAndNodeDefsBySurveyId({ surveyId, draft: true, advanced: true })
const nodeDefs = Survey.getNodeDefsArray(survey).filter(
(nodeDef) =>
Expand Down Expand Up @@ -85,7 +85,7 @@ export const exportSchemaSummary = async ({ surveyId, cycle, outputStream }) =>
return Taxonomy.getName(taxonomy) || ''
}

const items = nodeDefs.map((nodeDef) => {
return nodeDefs.map((nodeDef) => {
const { uuid, type } = nodeDef

const languages = Survey.getLanguages(Survey.getSurveyInfo(survey))
Expand Down Expand Up @@ -123,6 +123,9 @@ export const exportSchemaSummary = async ({ surveyId, cycle, outputStream }) =>
cycle: String(NodeDef.getCycles(nodeDef).map(RecordCycle.getLabel)), // this is to show the user the value that they see into the UI -> https://github.com/openforis/arena/issues/1677
}
})
}

export const exportSchemaSummary = async ({ surveyId, cycle, outputStream }) => {
const items = await generateSchemaSummaryItems({ surveyId, cycle })
await CSVWriter.writeItemsToStream({ outputStream, items, options: { removeNewLines: false } })
}

0 comments on commit 044a10a

Please sign in to comment.