@esri/solution-common
Version:
Provides general helper functions for @esri/solution.js.
73 lines • 3.16 kB
JavaScript
;
/** @license
* Copyright 2018 Esri
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports._upgradeTwoDotFive = void 0;
const generalHelpers_1 = require("../generalHelpers");
/**
* Applies Survey123 Form Config Schema migrations.
*
* @param {ISolutionItem} model A Solution model
* @returns {ISolutionItem}
* @private
*/
function _upgradeTwoDotFive(model) {
if ((0, generalHelpers_1.getProp)(model, "item.properties.schemaVersion") >= 2.5) {
return model;
}
else {
const clone = (0, generalHelpers_1.cloneObject)(model);
clone.data.templates.forEach((template) => {
if (template.type === "Form") {
if ((0, generalHelpers_1.getProp)(template, "properties.form.portalUrl")) {
template.properties.form.portalUrl = "{{portalBaseUrl}}";
}
const ver = parseFloat((0, generalHelpers_1.getProp)(template, "properties.form.version") || "2.5");
const hasFormSchema = (0, generalHelpers_1.getProp)(template, "properties.form");
if (!hasFormSchema || ver >= 3.8) {
return template;
}
template.properties.form.layerName = "survey";
// nest the theme into themes
if ((0, generalHelpers_1.getProp)(template, "properties.form.theme")) {
template.properties.form.themes = [template.properties.form.theme];
delete template.properties.form.theme;
}
const updateLayout = (question) => {
if (question.appearance && question.appearance.layout) {
question.appearance.layout = "vertical";
}
return question;
};
// replace whatever layout on all questions with vertical
template.properties.form.questions = template.properties.form.questions.map((question) => {
return !question.questions
? updateLayout(question)
: {
...question,
questions: question.questions.map(updateLayout),
};
});
template.properties.form.version = 3.8;
}
});
// update the schema version
clone.item.properties.schemaVersion = 2.5;
return clone;
}
}
exports._upgradeTwoDotFive = _upgradeTwoDotFive;
//# sourceMappingURL=upgrade-two-dot-five.js.map