239 lines
6.8 KiB
QML
239 lines
6.8 KiB
QML
import QtQuick
|
|
import "../services" as S
|
|
|
|
Item {
|
|
id: root
|
|
|
|
required property string unitName
|
|
required property string description
|
|
required property string subState
|
|
required property bool isUser
|
|
property string machineName: ""
|
|
required property color accentColor
|
|
|
|
property string _jText: ""
|
|
property bool _expanded: false
|
|
property bool _loading: false
|
|
|
|
width: parent?.width ?? 0
|
|
height: _row.height + (_expanded ? _journalArea.height : 0)
|
|
|
|
Behavior on height {
|
|
NumberAnimation {
|
|
duration: 150
|
|
}
|
|
}
|
|
|
|
Connections {
|
|
target: S.SystemdService
|
|
enabled: root.machineName === ""
|
|
function onJournalReady(unitName, isUser, text) {
|
|
if (unitName === root.unitName && isUser === root.isUser) {
|
|
root._jText = text;
|
|
root._loading = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
Connections {
|
|
target: S.MachinectlService
|
|
enabled: root.machineName !== ""
|
|
function onMachineJournalReady(mname, unitName, text) {
|
|
if (mname === root.machineName && unitName === root.unitName) {
|
|
root._jText = text;
|
|
root._loading = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
function _fetchJournal() {
|
|
root._loading = true;
|
|
root._jText = "";
|
|
if (root.machineName === "")
|
|
S.SystemdService.fetchJournal(root.unitName, root.isUser);
|
|
else
|
|
S.MachinectlService.fetchMachineJournal(root.machineName, root.unitName);
|
|
}
|
|
|
|
function _doRestart() {
|
|
if (root.machineName === "")
|
|
S.SystemdService.restartUnit(root.unitName, root.isUser);
|
|
else
|
|
S.MachinectlService.restartMachineUnit(root.machineName, root.unitName);
|
|
}
|
|
|
|
// Row
|
|
Item {
|
|
id: _row
|
|
width: parent.width
|
|
height: 32
|
|
|
|
Rectangle {
|
|
anchors.fill: parent
|
|
anchors.leftMargin: 4
|
|
anchors.rightMargin: 4
|
|
color: _rowHover.hovered ? S.Theme.base02 : "transparent"
|
|
radius: S.Theme.radius
|
|
z: -1
|
|
}
|
|
|
|
HoverHandler {
|
|
id: _rowHover
|
|
}
|
|
|
|
Text {
|
|
anchors.left: parent.left
|
|
anchors.leftMargin: 12
|
|
anchors.right: _subStateTag.left
|
|
anchors.rightMargin: 6
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
text: root.unitName
|
|
color: S.Theme.base05
|
|
font.pixelSize: S.Theme.fontSize - 1
|
|
font.family: S.Theme.fontFamily
|
|
elide: Text.ElideRight
|
|
}
|
|
|
|
Rectangle {
|
|
id: _subStateTag
|
|
anchors.right: _restartBtn.left
|
|
anchors.rightMargin: 6
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
color: S.Theme.base08
|
|
opacity: 0.85
|
|
radius: 3
|
|
width: _subStateLbl.width + 8
|
|
height: 14
|
|
|
|
Text {
|
|
id: _subStateLbl
|
|
anchors.centerIn: parent
|
|
text: root.subState
|
|
color: S.Theme.base00
|
|
font.pixelSize: S.Theme.fontSize - 3
|
|
font.family: S.Theme.fontFamily
|
|
}
|
|
}
|
|
|
|
// Restart button - = fa-refresh
|
|
Item {
|
|
id: _restartBtn
|
|
anchors.right: _expandBtn.left
|
|
anchors.rightMargin: 2
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
width: 24
|
|
height: 24
|
|
|
|
Text {
|
|
anchors.centerIn: parent
|
|
text: ""
|
|
color: _rHover.hovered ? root.accentColor : S.Theme.base04
|
|
font.pixelSize: S.Theme.fontSize
|
|
font.family: S.Theme.iconFontFamily
|
|
Behavior on color {
|
|
ColorAnimation {
|
|
duration: 80
|
|
}
|
|
}
|
|
}
|
|
|
|
HoverHandler {
|
|
id: _rHover
|
|
cursorShape: Qt.PointingHandCursor
|
|
}
|
|
TapHandler {
|
|
onTapped: {
|
|
root._doRestart();
|
|
if (root._expanded) {
|
|
root._jText = "";
|
|
Qt.callLater(root._fetchJournal);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Expand chevron - = fa-chevron-down, = fa-chevron-up
|
|
Item {
|
|
id: _expandBtn
|
|
anchors.right: parent.right
|
|
anchors.rightMargin: 4
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
width: 24
|
|
height: 24
|
|
|
|
Text {
|
|
anchors.centerIn: parent
|
|
text: root._expanded ? "" : ""
|
|
color: _expHover.hovered ? root.accentColor : S.Theme.base04
|
|
font.pixelSize: S.Theme.fontSize - 1
|
|
font.family: S.Theme.iconFontFamily
|
|
Behavior on color {
|
|
ColorAnimation {
|
|
duration: 80
|
|
}
|
|
}
|
|
}
|
|
|
|
HoverHandler {
|
|
id: _expHover
|
|
cursorShape: Qt.PointingHandCursor
|
|
}
|
|
TapHandler {
|
|
onTapped: {
|
|
root._expanded = !root._expanded;
|
|
if (root._expanded && root._jText === "")
|
|
root._fetchJournal();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Journal area
|
|
Item {
|
|
id: _journalArea
|
|
anchors.top: _row.bottom
|
|
width: parent.width
|
|
height: 120
|
|
visible: root._expanded
|
|
clip: true
|
|
|
|
Rectangle {
|
|
anchors.fill: parent
|
|
anchors.leftMargin: 8
|
|
anchors.rightMargin: 8
|
|
anchors.bottomMargin: 4
|
|
color: S.Theme.base01
|
|
radius: S.Theme.radius
|
|
|
|
Text {
|
|
anchors.centerIn: parent
|
|
visible: root._loading
|
|
text: "loading..."
|
|
color: S.Theme.base04
|
|
font.pixelSize: S.Theme.fontSize - 2
|
|
font.family: S.Theme.fontFamily
|
|
}
|
|
|
|
Flickable {
|
|
id: _flick
|
|
anchors.fill: parent
|
|
anchors.margins: 6
|
|
visible: !root._loading
|
|
contentHeight: _jContent.height
|
|
clip: true
|
|
|
|
Text {
|
|
id: _jContent
|
|
width: _flick.width
|
|
text: root._jText
|
|
color: S.Theme.base04
|
|
font.pixelSize: S.Theme.fontSize - 3
|
|
font.family: S.Theme.fontFamily
|
|
wrapMode: Text.WrapAnywhere
|
|
}
|
|
|
|
onContentHeightChanged: contentY = Math.max(0, contentHeight - height)
|
|
}
|
|
}
|
|
}
|
|
}
|