126 lines
8.1 KiB
Text
126 lines
8.1 KiB
Text
import { Theme, ActionButton } from "theme.slint";
|
|
import { ThemeInput, DeviceSelect } from "controls.slint";
|
|
|
|
export struct WebhookRow { id: string, name: string, detail: string, paused: bool }
|
|
|
|
export component WebhookWindow inherits Window {
|
|
title: @tr("Channel webhooks");
|
|
preferred-width: 820px; preferred-height: 700px; min-width: 680px; min-height: 620px;
|
|
background: Theme.bg-base;
|
|
in property <string> channel-name;
|
|
in property <[WebhookRow]> hooks;
|
|
in property <bool> allowed;
|
|
in property <bool> busy;
|
|
in property <string> error;
|
|
in property <string> secret;
|
|
in property <string> secret-name;
|
|
in property <string> secret-path;
|
|
in property <bool> secret-outgoing;
|
|
in property <string> confirmation-name;
|
|
in property <bool> confirming;
|
|
in property <bool> confirming-revoke;
|
|
in-out property <string> new-name;
|
|
in-out property <string> new-endpoint;
|
|
in-out property <int> new-kind;
|
|
callback refresh();
|
|
callback create();
|
|
callback rotate(string);
|
|
callback revoke(string);
|
|
callback confirm();
|
|
callback cancel-confirmation();
|
|
callback hide-secret();
|
|
callback dismiss();
|
|
VerticalLayout {
|
|
padding: 28px; spacing: 12px;
|
|
HorizontalLayout {
|
|
VerticalLayout {
|
|
spacing: 4px;
|
|
Text { text: @tr("Channel webhooks"); color: Theme.text-primary; font-size: Theme.font-size + 8px; font-weight: 600; }
|
|
Text { text: root.channel-name; color: Theme.text-muted; font-size: Theme.font-size; overflow: elide; }
|
|
}
|
|
if !root.busy && root.secret == "" && !root.confirming : ActionButton { text: @tr("Refresh"); clicked => { root.refresh(); } }
|
|
}
|
|
Text { text: @tr("Receive updates here, or send signed channel events to your own service."); color: Theme.text-secondary; wrap: word-wrap; }
|
|
Rectangle { height: 1px; background: Theme.border; }
|
|
if root.error != "" : Text { text: root.error; color: Theme.danger; wrap: word-wrap; }
|
|
if root.busy : Text { text: @tr("Waiting for the server…"); color: Theme.text-muted; }
|
|
if root.secret != "" : Rectangle {
|
|
height: secret-content.preferred-height + 28px;
|
|
background: Theme.bg-surface; border-radius: Theme.radius;
|
|
border-width: 1px; border-color: Theme.accent;
|
|
secret-content := VerticalLayout {
|
|
padding: 14px; spacing: 10px;
|
|
Text { text: @tr("Save this secret now"); color: Theme.text-primary; font-weight: 600; }
|
|
Text { text: root.secret-name; color: Theme.text-secondary; overflow: elide; }
|
|
Text { text: @tr("It is shown once. Closing this window or hiding it removes it from the client."); color: Theme.text-muted; wrap: word-wrap; }
|
|
credential := TextInput {
|
|
text: root.secret; read-only: true; wrap: word-wrap; height: 44px;
|
|
color: Theme.text-primary; font-family: "monospace"; font-size: Theme.font-size - 2px;
|
|
selection-background-color: Theme.selected;
|
|
accessible-label: @tr("Webhook secret");
|
|
}
|
|
if !root.secret-outgoing : Text { text: root.secret-path; color: Theme.text-secondary; wrap: word-wrap; }
|
|
Text { text: root.secret-outgoing ? @tr("Use this key to verify X-Vnox-Signature over the timestamp and raw request body.") : @tr("Use your server's HTTPS webhook endpoint. Generic integrations send this secret in Authorization: Bearer; GitHub uses it as the webhook secret."); color: Theme.text-muted; wrap: word-wrap; }
|
|
HorizontalLayout {
|
|
ActionButton { text: @tr("Copy and hide"); active: true; clicked => { credential.select-all(); credential.copy(); root.hide-secret(); } }
|
|
ActionButton { text: @tr("Hide secret"); quiet: true; clicked => { root.hide-secret(); } }
|
|
Rectangle { horizontal-stretch: 1; }
|
|
}
|
|
}
|
|
}
|
|
if root.confirming : Rectangle {
|
|
height: confirm-content.preferred-height + 28px; background: Theme.bg-surface; border-radius: Theme.radius;
|
|
confirm-content := VerticalLayout {
|
|
padding: 14px; spacing: 10px;
|
|
Text { text: root.confirming-revoke ? @tr("Revoke this webhook?") : @tr("Rotate this secret?"); color: Theme.text-primary; font-weight: 600; }
|
|
Text { text: root.confirmation-name; color: Theme.text-secondary; overflow: elide; }
|
|
Text { text: root.confirming-revoke ? @tr("New deliveries stop. Existing messages stay in the channel.") : @tr("The old secret stops working. Update the external integration with the new secret."); color: Theme.text-muted; wrap: word-wrap; }
|
|
HorizontalLayout {
|
|
ActionButton { text: root.confirming-revoke ? @tr("Revoke webhook") : @tr("Rotate secret"); danger: root.confirming-revoke; clicked => { root.confirm(); } }
|
|
ActionButton { text: @tr("Cancel"); quiet: true; clicked => { root.cancel-confirmation(); } }
|
|
Rectangle { horizontal-stretch: 1; }
|
|
}
|
|
}
|
|
}
|
|
list := Flickable {
|
|
min-height: 80px; vertical-stretch: 1; content-width: self.width;
|
|
VerticalLayout {
|
|
spacing: 0; alignment: start;
|
|
if root.allowed && !root.busy && root.hooks.length == 0 : Text { text: @tr("No webhooks yet. Add an integration below."); color: Theme.text-muted; wrap: word-wrap; }
|
|
for hook in root.hooks : Rectangle {
|
|
height: 76px; background: transparent;
|
|
HorizontalLayout {
|
|
padding-top: 10px; padding-bottom: 10px; spacing: 10px;
|
|
VerticalLayout {
|
|
spacing: 5px; horizontal-stretch: 1;
|
|
Text { text: hook.name; color: Theme.text-primary; font-weight: 600; overflow: elide; }
|
|
Text { text: hook.detail; color: hook.paused ? Theme.danger : Theme.text-muted; font-size: Theme.font-size - 3px; overflow: elide; }
|
|
}
|
|
if root.allowed && !root.busy && root.secret == "" && !root.confirming : ActionButton { text: @tr("Rotate"); clicked => { root.rotate(hook.id); } }
|
|
if root.allowed && !root.busy && root.secret == "" && !root.confirming : ActionButton { text: @tr("Revoke"); quiet: true; danger: true; clicked => { root.revoke(hook.id); } }
|
|
}
|
|
Rectangle { y: parent.height - 1px; height: 1px; background: Theme.border; }
|
|
}
|
|
}
|
|
}
|
|
if root.allowed && !root.busy && root.secret == "" && !root.confirming : VerticalLayout {
|
|
spacing: 10px;
|
|
Text { text: @tr("Add an integration"); color: Theme.text-primary; font-weight: 600; }
|
|
HorizontalLayout {
|
|
spacing: 10px;
|
|
ThemeInput { text <=> root.new-name; placeholder-text: @tr("Integration name"); horizontal-stretch: 1; }
|
|
DeviceSelect { width: 210px; model: [@tr("Incoming message"), @tr("GitHub updates"), @tr("Outgoing events")]; current-index <=> root.new-kind; }
|
|
}
|
|
if root.new-kind == 2 : ThemeInput { text <=> root.new-endpoint; placeholder-text: "https://example.org/vnox-events"; }
|
|
HorizontalLayout {
|
|
Text { text: root.new-kind == 2 ? @tr("Only public HTTPS destinations. Events: message.created.") : @tr("An integration can post only in this channel, using its own identity."); color: Theme.text-muted; wrap: word-wrap; horizontal-stretch: 1; }
|
|
ActionButton { text: @tr("Create webhook"); active: true; clicked => { root.create(); } }
|
|
}
|
|
}
|
|
if !root.allowed && !root.busy : Text { text: @tr("Only the server owner or members with Manage Webhooks can change integrations."); color: Theme.text-muted; wrap: word-wrap; }
|
|
HorizontalLayout {
|
|
Rectangle { horizontal-stretch: 1; }
|
|
ActionButton { text: @tr("Close"); quiet: true; clicked => { root.dismiss(); } }
|
|
}
|
|
}
|
|
}
|