Added webAppServer features
This commit is contained in:
parent
1396012858
commit
02ae6936d4
133
index.html
133
index.html
@ -504,11 +504,13 @@
|
|||||||
|
|
||||||
//for cloud apps
|
//for cloud apps
|
||||||
subAdmins: [],
|
subAdmins: [],
|
||||||
|
webAppURL: "167.172.219.249:8368",
|
||||||
application: "TestApp",
|
application: "TestApp",
|
||||||
vectorClock: {},
|
vectorClock: {},
|
||||||
appObjects: {},
|
appObjects: {},
|
||||||
generalData: {},
|
generalData: {},
|
||||||
generalVC: {}
|
generalVC: {}
|
||||||
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -9728,27 +9730,74 @@
|
|||||||
reactor.addEventListener("startUpErrorLog", log => console.error(log))
|
reactor.addEventListener("startUpErrorLog", log => console.error(log))
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script>
|
<script id="webAppClient">
|
||||||
// helper functions
|
//Add this to the client script to request data from floWebappServer
|
||||||
(async () => {
|
const webAppClient = {
|
||||||
let repourl = "https://api.github.com/repos/ranchimall/articles/contents"
|
util: {
|
||||||
let repocontent = null
|
|
||||||
window.articles = {}
|
|
||||||
window.parsedarticles = {}
|
|
||||||
|
|
||||||
repocontent = await (await fetch(repourl)).json();
|
requestData(request = []) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
var websocket = new WebSocket("ws://" + floGlobals.webAppURL + "/ws");
|
||||||
|
websocket.onmessage = (evt => {
|
||||||
|
if (evt.data == '$+') {
|
||||||
|
websocket.send(`?${JSON.stringify(request)}`);
|
||||||
|
} else if (evt.data == '$-') {
|
||||||
|
reject(`webApp not available`)
|
||||||
|
websocket.close()
|
||||||
|
} else {
|
||||||
|
resolve(JSON.parse(evt.data));
|
||||||
|
websocket.close();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
websocket.onerror = (evt) => {
|
||||||
|
reject(`webApp server not found`)
|
||||||
|
};
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
for (let i = 0; i < repocontent.length; i++) {
|
requestGeneralData: function (type, vectorClock = '0') {
|
||||||
articlehtml = await (await fetch(repocontent[i]["download_url"])).text()
|
if (typeof vectorClock !== 'string')
|
||||||
if (repocontent[i]['name'].slice(-5, repocontent[i]['name'].length) == '.html' && repocontent[i]['name'].slice(0, -5) != 'index') {
|
vectorClock.toString()
|
||||||
articles[repocontent[i]['name'].slice(0, repocontent[i]['name'].length - 5)] = articlehtml
|
return new Promise((resolve, reject) => {
|
||||||
|
this.util.requestData([floGlobals.application, 'generalData', type, vectorClock])
|
||||||
|
.then(
|
||||||
|
result => {
|
||||||
|
if (result[0])
|
||||||
|
resolve(result[1])
|
||||||
|
else
|
||||||
|
reject(result[1])
|
||||||
|
}).catch(error => reject(error))
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
requestObjectData: function (keyPath) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this.util.requestData([floGlobals.application, 'appObjects'].concat(keyPath)).then(
|
||||||
|
result => {
|
||||||
|
if (result[0])
|
||||||
|
resolve(result[1])
|
||||||
|
else
|
||||||
|
reject(result[1])
|
||||||
|
}).catch(error => reject(error))
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
requestSubAdminList: function () {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this.util.requestData([floGlobals.application, 'subAdmins']).then(
|
||||||
|
result => {
|
||||||
|
if (result[0])
|
||||||
|
resolve(result[1])
|
||||||
|
else
|
||||||
|
reject(result[1])
|
||||||
|
}).catch(error => reject(error))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
parseArticles(articles)
|
<script id="onLoadStartUp">
|
||||||
renderColumns(parsedarticles)
|
|
||||||
|
|
||||||
})();
|
|
||||||
|
|
||||||
async function fetchArticleDetails() {
|
async function fetchArticleDetails() {
|
||||||
let applicants = await floCloudAPI.requestGeneralData('test')
|
let applicants = await floCloudAPI.requestGeneralData('test')
|
||||||
@ -9792,6 +9841,7 @@
|
|||||||
numberOfColumns = Object.keys(parsedarticles).length
|
numberOfColumns = Object.keys(parsedarticles).length
|
||||||
let columns = document.getElementById('columnsmain')
|
let columns = document.getElementById('columnsmain')
|
||||||
let parsedArticlesKeys = Object.keys(parsedarticles)
|
let parsedArticlesKeys = Object.keys(parsedarticles)
|
||||||
|
let map_articlekey_column = {}
|
||||||
|
|
||||||
for (let i = 0; i < parsedArticlesKeys.length; i++) {
|
for (let i = 0; i < parsedArticlesKeys.length; i++) {
|
||||||
columnhtml = `<div class="column" id="column${i + 1}" data-articlekey="${parsedArticlesKeys[i]}">
|
columnhtml = `<div class="column" id="column${i + 1}" data-articlekey="${parsedArticlesKeys[i]}">
|
||||||
@ -9809,8 +9859,11 @@
|
|||||||
</div>`
|
</div>`
|
||||||
//columns.append(columnhtml)
|
//columns.append(columnhtml)
|
||||||
columns.innerHTML += columnhtml
|
columns.innerHTML += columnhtml
|
||||||
|
map_articlekey_column[parsedArticlesKeys[i]] = `column${i + 1}`
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return map_articlekey_column
|
||||||
}
|
}
|
||||||
|
|
||||||
function switchtoArticle(element) {
|
function switchtoArticle(element) {
|
||||||
@ -9864,9 +9917,8 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
|
||||||
|
|
||||||
<script id="onLoadStartUp">
|
|
||||||
function updateVotes(articles_votesmapping, map_articlekey_column) {
|
function updateVotes(articles_votesmapping, map_articlekey_column) {
|
||||||
|
|
||||||
var articleKeys = Object.keys(map_articlekey_column)
|
var articleKeys = Object.keys(map_articlekey_column)
|
||||||
@ -9878,6 +9930,46 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
let repourl = "https://api.github.com/repos/ranchimall/articles/contents"
|
||||||
|
|
||||||
|
Promise.all([fetch(repourl), webAppClient.requestGeneralData('test')]).then(async (values) => {
|
||||||
|
|
||||||
|
let repocontent = null
|
||||||
|
window.articles = {}
|
||||||
|
window.parsedarticles = {}
|
||||||
|
|
||||||
|
repocontent = await values[0].json()
|
||||||
|
|
||||||
|
for (let i = 0; i < repocontent.length; i++) {
|
||||||
|
articlehtml = await (await fetch(repocontent[i]["download_url"])).text()
|
||||||
|
if (repocontent[i]['name'].slice(-5, repocontent[i]['name'].length) == '.html' && repocontent[i]['name'].slice(0, -5) != 'index') {
|
||||||
|
articles[repocontent[i]['name'].slice(0, repocontent[i]['name'].length - 5)] = articlehtml
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
parseArticles(articles)
|
||||||
|
let map_articlekey_column = renderColumns(parsedarticles)
|
||||||
|
let articleInfo = values[1]
|
||||||
|
let articles_votesmapping = {}
|
||||||
|
|
||||||
|
for (let i = 0; i < articleInfo.length; i++) {
|
||||||
|
|
||||||
|
let article_message = JSON.parse(articleInfo[i].message)
|
||||||
|
|
||||||
|
if (!(article_message.articlekey in articles_votesmapping)) {
|
||||||
|
articles_votesmapping[article_message.articlekey] = 1
|
||||||
|
} else {
|
||||||
|
articles_votesmapping[article_message.articlekey]++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
updateVotes(articles_votesmapping, map_articlekey_column)
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
let myCustomLogin = function () {
|
let myCustomLogin = function () {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|
||||||
@ -9894,9 +9986,8 @@
|
|||||||
//floDapps.setAppObjectStores({sampleObs1:{}, sampleObs2:{options{autoIncrement:true, keyPath:'SampleKey'}, Indexes:{sampleIndex:{}}}})
|
//floDapps.setAppObjectStores({sampleObs1:{}, sampleObs2:{options{autoIncrement:true, keyPath:'SampleKey'}, Indexes:{sampleIndex:{}}}})
|
||||||
floDapps.setCustomPrivKeyInput(myCustomLogin);
|
floDapps.setCustomPrivKeyInput(myCustomLogin);
|
||||||
|
|
||||||
floCloudAPI.requestGeneralData('test');
|
|
||||||
|
|
||||||
floDapps.launchStartUp().then(result => {
|
floDapps.launchStartUp().then(result => {
|
||||||
|
|
||||||
document.getElementById("login-button").style.display = 'none'
|
document.getElementById("login-button").style.display = 'none'
|
||||||
document.getElementById("user-button").style.display = 'initial'
|
document.getElementById("user-button").style.display = 'initial'
|
||||||
console.log(result)
|
console.log(result)
|
||||||
@ -9943,9 +10034,9 @@
|
|||||||
updateVotes(articles_votesmapping, map_articlekey_column)
|
updateVotes(articles_votesmapping, map_articlekey_column)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}).catch(error => console.error(error))
|
}).catch(error => console.error(error))
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
Loading…
Reference in New Issue
Block a user