Switch between TrueView environments
by Евгений
HTML
<div id="current-env">Current: ...</div>
<select id="env-select">
<option value="localhost">localhost</option>
<option value="dev">dev</option>
<option value="qa">qa</option>
<option value="stable">stable</option>
<option value="stage">stage</option>
<option value="prod">prod</option>
</select>
<label><input type="checkbox" id="is-new-checkbox" /> <span>New Angular</span></label>
<label><input type="checkbox" id="is-new-tab-checkbox" /> <span>New tab</span></label>
<button id="go-new">Go</button>
<div class="result">...</div>
JavaScript
const url = new URL('https://dev.trueview.ecosure.com/#/prg/3b0fe694-ed84-4f36-9cc6-cd52092ab40a/iwf/32e6935d-cdd6-4023-97ff-2723b4cd1568/sft/')
const envMap = {
'localhost': 'localhost',
'dev.trueview.ecosure.com': 'dev',
'qa.trueview.ecosure.com': 'qa',
'stable.trueview.ecosure.com': 'stable',
'stage.trueview.ecosure.com': 'stage',
'trueview.ecosure.com': 'prod'
};
const exceptions = [
[
'#/mi/', '#/mi/reg/'
]
];
const noOldPatterns = ['#/mi/adv/'];
const noNewPatterns = [''];
const regexMappings = [
{
pattern: /#\/prg\/([^/]+)\/iwf\/([^/]+)\/(i|sft+)/i,
to: "#/cloud/prg/{1}/iwf/{2}/{3}"
},
];
function mapSpecialPaths(hashPath) {
console.log(hashPath);
for (const mapping of regexMappings) {
const match = hashPath.match(mapping.pattern);
if (match) {
let result = mapping.to;
const keys = (result.match(/{\w+}/g) || []);
keys.forEach((key, i) => {
const index = parseInt(key.replace('{', '')) || [i + 1];
result = result.replace(key, match[index]);
});
return result;
}
}
return null;
}
document.addEventListener('DOMContentLoaded', async () => {
const hostname = url.hostname;
const env = envMap[hostname];
document.getElementById('current-env').textContent = `Current: ${env || 'unknown'}`;
if (env) {
document.getElementById('env-select').value = env;
}
const isNew = url.pathname.startsWith('/cloud');
document.getElementById('is-new-checkbox').checked = isNew;
const comparator = patterns => patterns.some(item => url.hash.match(item));
if (isNew && comparator(noOldPatterns) || !isNew && comparator(noNewPatterns)) {
document.getElementById('is-new-checkbox').disabled = true;
}
});
document.getElementById('go-new').addEventListener('click', () => handleGo());
async function handleGo() {
const forceCloud = document.getElementById('is-new-checkbox').checked;
const isNewTab =...