Skip to content

Instantly share code, notes, and snippets.

@embedded4ever
Last active September 3, 2021 14:48
Show Gist options
  • Save embedded4ever/b39e63756c6ec9378af155adae625dcd to your computer and use it in GitHub Desktop.
Save embedded4ever/b39e63756c6ec9378af155adae625dcd to your computer and use it in GitHub Desktop.
import QtQuick 2.9
import QtQuick.Controls 2.4
import QtQuick.Window 2.2
import QtQuick.Layouts 1.11
Window {
id: root
visible: true
maximumWidth: 720
minimumWidth: 720
maximumHeight: 1920
minimumHeight: 1920
Rectangle {
width: parent.width
height: parent.height
border.width: 0
color: "lightblue"
ListModel {
id: busModel
}
Component {
id: busDelegate
Item {
id: delegateColumn
width: root.width
height: 190
RowLayout {
id: row
anchors.fill: parent
spacing: 50
Text {
id: line
font.bold: true
text: name
font.family: "Helvetica"
font.pointSize: 18
Layout.fillWidth: true
Layout.minimumWidth: 100
Layout.preferredWidth: 45
Layout.maximumWidth: 120
wrapMode: Text.WordWrap
}
Text {
text: address
font.bold: true
font.family: "Helvetica"
font.pointSize: 20
Layout.fillWidth: true
Layout.minimumWidth: 300
Layout.preferredWidth: 300
Layout.maximumWidth: 300
Layout.alignment: Qt.AlignCenter
wrapMode: Text.WordWrap
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
Text {
id: timertext
ColorAnimation on color {
id: anim
to: "red"
duration: 300
}
font.bold: true
text: phone
font.family: "Helvetica"
font.pointSize: 20
Layout.alignment: Qt.AlignCenter
}
}
Line {
}
}
}
ListView {
anchors {
fill: parent
}
model: busModel
delegate: busDelegate
}
}
function request(url, callback) {
var xhr = new XMLHttpRequest()
xhr.withCredentials = true
xhr.onreadystatechange = (function (myxhr) {
return function () {
if (myxhr.readyState === 4) {
callback(myxhr)
}
}
})(xhr)
var data = null
xhr.open("GET", url)
xhr.setRequestHeader("Content-Type", "application/json")
xhr.setRequestHeader(
"authorization",
"apikey yourtoken")
xhr.send(data)
}
Timer {
id: timer
interval: 60000
running: true
repeat: true
triggeredOnStart: true
onTriggered: request(
"https://api.collectapi.com/health/dutyPharmacy?ilce=%C3%87ankaya&il=Ankara",
function (o) {
console.log(o.responseText)
if (o.status === 200) {
busModel.clear()
var obj = JSON.parse(o.responseText).result
for (var i = 0; i < obj.length
&& i < 12; ++i) {
busModel.append({
name: obj[i].name,
address: obj[i].address,
phone: obj[i].phone
})
}
} else {
console.log(" Connection Failed -> " + o.status)
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment