Skip to content

Commit

Permalink
add list servers
Browse files Browse the repository at this point in the history
  • Loading branch information
ngxson committed Apr 27, 2019
1 parent 3db0140 commit 352c37c
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 2 deletions.
35 changes: 35 additions & 0 deletions activity/list-servers/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">

<title>Quick Parsec</title>

<!-- Stylesheets -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="../../styles.css">

<!-- Scripts -->
<script>
delete module.exports
</script>
<script src="https://code.jquery.com/jquery-3.2.1.js"></script>
<script src="window.js"></script>
</head>

<body>
<div id="container" class="container-fluid">

<div class="">
<div class="col-12">
<h1>Your computers</h1>
</div>
</div>
<div id="list-computers">
</div>

</div>
</body>

</html>
52 changes: 52 additions & 0 deletions activity/list-servers/window.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

const request = require('request')
const savedData = require('../../utils/saved-data')
const navigate = require('../../utils/navigate')
var session_id = null
var listServer = []

$(() => {
init()
})

async function init() {
session_id = await savedData.get('session_id')
if (!session_id) navigate('/activity/login/')
refreshList()
}

function refreshList() {
request({
url: 'https://parsecgaming.com/v1/server-list?include_managed=true',
method: 'post',
headers: {
'X-Parsec-Session-Id': session_id,
}
}, (err, res, body) => {
body = JSON.parse(body)

if (body.error) {
alert(body.error)
navigate('/activity/login/')
return
}

listServer = body
renderListServer()
})
}

function renderListServer() {
let buildServerEntry = (server, i) => {
return `
<div class="col-12">
<b>${server.name}</b> (${server.status})<br>
<button class="btn btn-success" onclick="btnSetDefault(${i})">Set default</button>&nbsp;&nbsp;
<button class="btn btn-default" onclick="btnConnect(${i})">Connect</button>&nbsp;&nbsp;
</div>
`
}
let html = listServer.map(buildServerEntry).join('')
console.log(html)
$('#list-computers').html(html)
}
3 changes: 2 additions & 1 deletion activity/login/window.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

const request = require('request')
const savedData = require('../../utils/saved-data')
const navigate = require('../../utils/navigate')

$(() => {
init()
Expand Down Expand Up @@ -29,7 +30,7 @@ function doLogin() {
alert(body.error)
} else if (body.session_id) {
savedData.save('session_id', body.session_id)
// TODO: redirect to home
navigate('/activity/list-servers/')
} else {
alert('Unknown error')
}
Expand Down
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
},
"dependencies": {
"electron-json-storage": "^4.1.6",
"request": "^2.88.0"
"request": "^2.88.0",
"ws": "^6.2.1"
}
}
1 change: 1 addition & 0 deletions window.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ async function init() {
if (!session_id) {
navigate('/activity/login/')
} else {
navigate('/activity/list-servers/')
}
}

0 comments on commit 352c37c

Please sign in to comment.