-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from abhik-wil/ret-ui
Ret UI
- Loading branch information
Showing
9 changed files
with
14,779 additions
and
479 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// const {getFeatures} = require("./features") | ||
function getStringAfterEquals(inputString) { | ||
const index = inputString.indexOf("="); | ||
if (index !== -1) { | ||
return inputString.slice(index + 1).trim(); | ||
} else { | ||
return ""; | ||
} | ||
} | ||
|
||
async function readBuildFile(branchName) { | ||
if (!branchName) return; | ||
const url = `https://api.github.com/repos/ONDC-Official/ONDC-LOG-Specifications/contents/ui/build.js?ref=${branchName}`; | ||
const features = await getFeatures(branchName) | ||
|
||
try { | ||
const response = await fetch(url, { | ||
headers: { | ||
Authorization: "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", | ||
}, | ||
}); | ||
const formattedResponse = await response?.json(); | ||
// reading data using github raw apis. | ||
if(formattedResponse?.download_url){ | ||
setTimeout(async ()=>{ | ||
const rawResponse = await fetch(formattedResponse.download_url, { | ||
// headers: { | ||
// Authorization: "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", | ||
// }, | ||
}); | ||
const formattedrawResponse = await rawResponse?.text(); | ||
build_spec = JSON.parse(getStringAfterEquals(formattedrawResponse)); | ||
|
||
onFirstLoad(build_spec,features); | ||
},1200) | ||
} | ||
|
||
// let splitedText = atob(formattedResponse?.content); | ||
// build_spec = JSON.parse(getStringAfterEquals(splitedText)); | ||
// onFirstLoad(build_spec); | ||
|
||
} catch (error) { | ||
console.log("Error fetching contract", error?.message || error); | ||
//alert('Something went wrong, Please try again later') | ||
} | ||
} | ||
|
||
async function fetchRequest(url){ | ||
try{ | ||
const response = await fetch(url, { | ||
headers: { | ||
Authorization: "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", | ||
}, | ||
}); | ||
return await response?.json(); | ||
}catch{ | ||
console.log("Error fetching contract", error?.message || error); | ||
} | ||
} | ||
|
||
async function loadContracts() { | ||
//fetch branches & tags from repo | ||
const BRANCHES_URL= "https://api.github.com/repos/ONDC-Official/ONDC-LOG-Specifications/branches"; | ||
const TAGS_URL= "https://api.github.com/repos/ONDC-Official/ONDC-LOG-Specifications/tags"; | ||
|
||
let response1, response2; | ||
response1 = await fetchRequest(BRANCHES_URL) | ||
response2 = await fetchRequest(TAGS_URL) | ||
const response = [...response1,...response2] | ||
const selectedOption = document.getElementById("contract-dropdown"); | ||
selectedOption.innerHTML = ""; | ||
response.forEach((flow) => { | ||
var option = document.createElement("option"); | ||
option.text = flow.name; | ||
selectedOption.add(option); | ||
}); | ||
readBuildFile(response[0]?.name); | ||
} | ||
|
||
function upadteContract() { | ||
const selectedOption = document.getElementById("contract-dropdown")?.value; | ||
readBuildFile(selectedOption); | ||
} | ||
|
||
|
||
window.onload = function () { | ||
loadContracts() | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.