feat(app): wire saved schedules into the pipeline summary
This commit is contained in:
@@ -81,7 +81,11 @@ class _PipelinesScreenState extends State<PipelinesScreen> {
|
||||
final wide = constraints.maxWidth >= kPipelinesWideBreakpoint;
|
||||
if (!wide) {
|
||||
return _controller.hasSelection
|
||||
? PipelineDetailPanel(controller: _controller, showBack: true)
|
||||
? PipelineDetailPanel(
|
||||
controller: _controller,
|
||||
gateway: widget.gateway,
|
||||
showBack: true,
|
||||
)
|
||||
: PipelineListPanel(controller: _controller);
|
||||
}
|
||||
return Row(
|
||||
@@ -96,6 +100,7 @@ class _PipelinesScreenState extends State<PipelinesScreen> {
|
||||
flex: 3,
|
||||
child: PipelineDetailPanel(
|
||||
controller: _controller,
|
||||
gateway: widget.gateway,
|
||||
showBack: false,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../graph/widgets/stage_definition_view.dart';
|
||||
import '../pipeline_models.dart';
|
||||
import '../pipeline_query.dart';
|
||||
@@ -25,10 +26,12 @@ class PipelineDetailPanel extends StatefulWidget {
|
||||
const PipelineDetailPanel({
|
||||
super.key,
|
||||
required this.controller,
|
||||
required this.gateway,
|
||||
required this.showBack,
|
||||
});
|
||||
|
||||
final PipelinesController controller;
|
||||
final ApiGateway gateway;
|
||||
final bool showBack;
|
||||
|
||||
@override
|
||||
@@ -94,7 +97,11 @@ class _PipelineDetailPanelState extends State<PipelineDetailPanel> {
|
||||
Expanded(
|
||||
child: switch (_tab) {
|
||||
PipelineDetailTab.summary => _scrolling(
|
||||
PipelineSummaryView(controller: _controller, detail: detail),
|
||||
PipelineSummaryView(
|
||||
controller: _controller,
|
||||
detail: detail,
|
||||
gateway: widget.gateway,
|
||||
),
|
||||
),
|
||||
PipelineDetailTab.graph => PipelineGraphTab(
|
||||
detail: detail,
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../schedules/ui/pipeline/schedule_pipeline_section.dart';
|
||||
import '../pipeline_format.dart';
|
||||
import '../pipeline_models.dart';
|
||||
import '../pipeline_query.dart';
|
||||
@@ -8,18 +10,20 @@ import '../pipelines_controller.dart';
|
||||
import 'pipeline_controls.dart';
|
||||
import 'pipeline_detail_styles.dart';
|
||||
|
||||
/// Summary tab: key/value facts plus the version history. Version rows are
|
||||
/// selectable; the latest version's row is marked and a historical selection
|
||||
/// offers an explicit return to latest.
|
||||
/// Summary tab: key/value facts, the pipeline's saved schedules and the version
|
||||
/// history. Version rows are selectable; the latest version's row is marked and
|
||||
/// a historical selection offers an explicit return to latest.
|
||||
class PipelineSummaryView extends StatelessWidget {
|
||||
const PipelineSummaryView({
|
||||
super.key,
|
||||
required this.controller,
|
||||
required this.detail,
|
||||
required this.gateway,
|
||||
});
|
||||
|
||||
final PipelinesController controller;
|
||||
final PipelineDetail detail;
|
||||
final ApiGateway gateway;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -37,6 +41,11 @@ class PipelineSummaryView extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
_fields(context),
|
||||
SchedulePipelineSection(
|
||||
gateway: gateway,
|
||||
pipelineId: detail.id,
|
||||
version: detail.resolvedVersion,
|
||||
),
|
||||
_versions(context),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -28,6 +28,7 @@ class ScheduleEditorForm extends StatefulWidget {
|
||||
required this.onSubmit,
|
||||
this.onCancel,
|
||||
this.title,
|
||||
this.showHeading = true,
|
||||
});
|
||||
|
||||
final ScheduleDraft draft;
|
||||
@@ -35,6 +36,10 @@ class ScheduleEditorForm extends StatefulWidget {
|
||||
final VoidCallback? onCancel;
|
||||
final String? title;
|
||||
|
||||
/// False when the hosting native page already shows the add/edit title in its
|
||||
/// navigation bar, so the form does not repeat it.
|
||||
final bool showHeading;
|
||||
|
||||
@override
|
||||
State<ScheduleEditorForm> createState() => _ScheduleEditorFormState();
|
||||
}
|
||||
@@ -149,6 +154,7 @@ class _ScheduleEditorFormState extends State<ScheduleEditorForm> {
|
||||
final cupertino = usesCupertinoHost(context);
|
||||
return ScheduleEditorFormBody(
|
||||
heading: _heading,
|
||||
showHeading: widget.showHeading,
|
||||
name: _name,
|
||||
prompt: _prompt,
|
||||
version: _version,
|
||||
|
||||
@@ -14,6 +14,7 @@ class ScheduleEditorFormBody extends StatelessWidget {
|
||||
const ScheduleEditorFormBody({
|
||||
super.key,
|
||||
required this.heading,
|
||||
this.showHeading = true,
|
||||
required this.name,
|
||||
required this.prompt,
|
||||
required this.version,
|
||||
@@ -37,6 +38,7 @@ class ScheduleEditorFormBody extends StatelessWidget {
|
||||
});
|
||||
|
||||
final String heading;
|
||||
final bool showHeading;
|
||||
final TextEditingController name;
|
||||
final TextEditingController prompt;
|
||||
final TextEditingController version;
|
||||
@@ -106,8 +108,10 @@ class ScheduleEditorFormBody extends StatelessWidget {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(heading, style: titleStyle),
|
||||
const SizedBox(height: 8),
|
||||
if (showHeading) ...[
|
||||
Text(heading, style: titleStyle),
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
Text(scheduleEditorNote, style: scheduleEditorSecondaryStyle(context)),
|
||||
_gap,
|
||||
_textField(
|
||||
|
||||
@@ -39,6 +39,28 @@ String scheduleTimerValue(SavedSchedule schedule) {
|
||||
return rule.days.isEmpty ? repeat : '$repeat · ${rule.days.join(', ')}';
|
||||
}
|
||||
|
||||
/// The web's `scheduleRuleLabel`, used by the pipeline Summary: timer words,
|
||||
/// weekdays and the effective timezone in one line. A rule without an interval
|
||||
/// or clock times is reported as unavailable instead of showing only a zone.
|
||||
String scheduleRuleSummary(SavedSchedule schedule) {
|
||||
final rule = schedule.rule;
|
||||
final repeat = rule.every.isNotEmpty
|
||||
? 'Every ${rule.every}'
|
||||
: rule.times.isNotEmpty
|
||||
? rule.times.join(', ')
|
||||
: '';
|
||||
if (repeat.isEmpty) return 'Timer unavailable';
|
||||
return [
|
||||
repeat,
|
||||
if (rule.days.isNotEmpty) rule.days.join(', '),
|
||||
scheduleTimezoneValue(schedule),
|
||||
].join(' · ');
|
||||
}
|
||||
|
||||
/// The pinned version on its own, for a section already scoped to one pipeline.
|
||||
String schedulePinnedVersionValue(SavedSchedule schedule) =>
|
||||
schedule.version == null ? 'Version unavailable' : 'v${schedule.version}';
|
||||
|
||||
/// Matches the web client: an empty or `Local` rule timezone means the server
|
||||
/// applies its own timezone, which is not an absent value.
|
||||
String scheduleTimezoneValue(SavedSchedule schedule) {
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../ui/adaptive/host.dart';
|
||||
import 'schedule_pipeline_wording.dart';
|
||||
|
||||
/// Deletes the exact schedule revision. Returns null once the server accepted
|
||||
/// the delete, or the server's own reasons verbatim.
|
||||
typedef ScheduleDeleteSubmit = Future<String?> Function();
|
||||
|
||||
/// Opens the one native confirmation for a schedule deletion.
|
||||
///
|
||||
/// Nothing is sent until `Delete schedule` is pressed; `Keep schedule` only
|
||||
/// closes the prompt. A refusal keeps the prompt open with the server's words.
|
||||
Future<void> showScheduleDeleteDialog({
|
||||
required BuildContext context,
|
||||
required String name,
|
||||
required ScheduleDeleteSubmit onSubmit,
|
||||
}) {
|
||||
final prompt = _ScheduleDeletePrompt(name: name, onSubmit: onSubmit);
|
||||
if (usesCupertinoHost(context)) {
|
||||
return showCupertinoDialog<void>(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (_) => prompt,
|
||||
);
|
||||
}
|
||||
return showDialog<void>(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (_) => prompt,
|
||||
);
|
||||
}
|
||||
|
||||
class _ScheduleDeletePrompt extends StatefulWidget {
|
||||
const _ScheduleDeletePrompt({required this.name, required this.onSubmit});
|
||||
|
||||
final String name;
|
||||
final ScheduleDeleteSubmit onSubmit;
|
||||
|
||||
@override
|
||||
State<_ScheduleDeletePrompt> createState() => _ScheduleDeletePromptState();
|
||||
}
|
||||
|
||||
class _ScheduleDeletePromptState extends State<_ScheduleDeletePrompt> {
|
||||
bool _sending = false;
|
||||
String? _refusal;
|
||||
|
||||
void _keep() {
|
||||
if (!_sending) Navigator.of(context).pop();
|
||||
}
|
||||
|
||||
Future<void> _confirm() async {
|
||||
if (_sending) return;
|
||||
setState(() {
|
||||
_sending = true;
|
||||
_refusal = null;
|
||||
});
|
||||
final refusal = await widget.onSubmit();
|
||||
if (!mounted) return;
|
||||
if (refusal == null) {
|
||||
Navigator.of(context).pop();
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
_sending = false;
|
||||
_refusal = refusal;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final dialog = usesCupertinoHost(context)
|
||||
? _cupertino(context)
|
||||
: _material(context);
|
||||
return PopScope(canPop: !_sending, child: dialog);
|
||||
}
|
||||
|
||||
Widget _material(BuildContext context) {
|
||||
return AlertDialog(
|
||||
scrollable: true,
|
||||
title: Text(scheduleDeleteTitle(widget.name)),
|
||||
content: _body(
|
||||
errorStyle: TextStyle(color: Theme.of(context).colorScheme.error),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
key: scheduleDeleteKeepKey,
|
||||
onPressed: _sending ? null : _keep,
|
||||
child: const Text(scheduleDeleteKeepLabel),
|
||||
),
|
||||
FilledButton(
|
||||
key: scheduleDeleteConfirmKey,
|
||||
onPressed: _sending ? null : _confirm,
|
||||
child: const Text(scheduleDeleteConfirmLabel),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _cupertino(BuildContext context) {
|
||||
return CupertinoAlertDialog(
|
||||
title: Text(scheduleDeleteTitle(widget.name)),
|
||||
content: _body(
|
||||
errorStyle: TextStyle(
|
||||
color: CupertinoColors.systemRed.resolveFrom(context),
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
CupertinoDialogAction(
|
||||
key: scheduleDeleteKeepKey,
|
||||
onPressed: _sending ? null : _keep,
|
||||
child: const Text(scheduleDeleteKeepLabel),
|
||||
),
|
||||
CupertinoDialogAction(
|
||||
key: scheduleDeleteConfirmKey,
|
||||
isDestructiveAction: true,
|
||||
onPressed: _sending ? null : _confirm,
|
||||
child: const Text(scheduleDeleteConfirmLabel),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _body({required TextStyle errorStyle}) {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const Text(scheduleDeleteMessage),
|
||||
if (_refusal case final refusal?)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: Text(
|
||||
refusal,
|
||||
key: scheduleDeleteErrorKey,
|
||||
style: errorStyle,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import '../../../../core/api_gateway.dart';
|
||||
import '../../data/schedules_repository.dart';
|
||||
import '../../domain/saved_schedule.dart';
|
||||
import '../list/schedule_list_controller.dart';
|
||||
|
||||
/// The message to show for a failed save/delete/pause, using the repository's
|
||||
/// older-server guidance when the reply itself is unsupported.
|
||||
String scheduleActionError(Object error) =>
|
||||
ScheduleListFailure.from(error).message;
|
||||
|
||||
/// Saved schedules for exactly one pipeline, with the two mutations the
|
||||
/// pipeline Summary offers.
|
||||
///
|
||||
/// Every accepted save/delete is followed by `list_schedules`; the section never
|
||||
/// invents, edits or reorders a row locally. Saving does not start a run and
|
||||
/// nothing here publishes, validates or runs a workflow.
|
||||
class SchedulePipelineController extends ChangeNotifier {
|
||||
SchedulePipelineController({
|
||||
required this.repository,
|
||||
required this.pipelineId,
|
||||
});
|
||||
|
||||
final SchedulesRepository repository;
|
||||
final int pipelineId;
|
||||
|
||||
List<SavedSchedule> _schedules = const [];
|
||||
bool _loading = false;
|
||||
bool _loaded = false;
|
||||
ScheduleListFailure? _failure;
|
||||
int _generation = 0;
|
||||
bool _disposed = false;
|
||||
|
||||
List<SavedSchedule> get schedules => _schedules;
|
||||
bool get isLoading => _loading;
|
||||
bool get hasLoaded => _loaded;
|
||||
bool get isInitialLoading => _loading && !_loaded;
|
||||
ScheduleListFailure? get failure => _failure;
|
||||
|
||||
/// Re-reads server truth. A failed refresh keeps the rows already loaded so a
|
||||
/// refused mutation never silently empties the section.
|
||||
Future<void> refresh() async {
|
||||
final generation = ++_generation;
|
||||
_loading = true;
|
||||
_failure = null;
|
||||
_notify();
|
||||
try {
|
||||
final rows = await repository.listSchedules(pipelineId: pipelineId);
|
||||
if (!_owns(generation)) return;
|
||||
_schedules = List.unmodifiable(rows);
|
||||
_loaded = true;
|
||||
} catch (error) {
|
||||
if (!_owns(generation)) return;
|
||||
_failure = ScheduleListFailure.from(error);
|
||||
} finally {
|
||||
if (_owns(generation)) {
|
||||
_loading = false;
|
||||
_notify();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates (with a stable create key) or updates from the editor's exact
|
||||
/// record. A server refusal is propagated unchanged; a later refresh failure
|
||||
/// is reported separately and does not pretend the accepted save failed.
|
||||
Future<void> saveRecord(JsonMap record, {String? requestKey}) async {
|
||||
await repository.saveSchedule(record, requestKey: requestKey);
|
||||
await refresh();
|
||||
}
|
||||
|
||||
/// Reuses the exact loaded record, changing only `enabled`. Identity,
|
||||
/// revision and unknown fields stay in the payload.
|
||||
Future<void> setEnabled(SavedSchedule schedule) =>
|
||||
saveRecord(schedule.withEnabled(!schedule.enabled).toJson());
|
||||
|
||||
/// Sends the exact identity and compare-and-swap revision of the loaded row.
|
||||
Future<void> delete(SavedSchedule schedule) async {
|
||||
final id = schedule.id;
|
||||
final revision = schedule.revision;
|
||||
if (id == null || revision == null) {
|
||||
throw const SchedulesRepositoryException(
|
||||
'An exact schedule ID and revision are required.',
|
||||
);
|
||||
}
|
||||
await repository.deleteSchedule(id, revision);
|
||||
await refresh();
|
||||
}
|
||||
|
||||
bool _owns(int generation) => !_disposed && generation == _generation;
|
||||
|
||||
void _notify() {
|
||||
if (!_disposed) notifyListeners();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_disposed = true;
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../core/api_gateway.dart';
|
||||
import '../../../../ui/adaptive/host.dart';
|
||||
import '../../domain/editor/schedule_draft.dart';
|
||||
import '../editor/schedule_editor_form.dart';
|
||||
import '../editor/schedule_editor_wording.dart';
|
||||
|
||||
/// A create request key minted once when the editor is opened for a new
|
||||
/// schedule. Retrying that same editor reuses it, so a lost reply cannot create
|
||||
/// a duplicate; a new Add opens a new key.
|
||||
String newScheduleCreateRequestKey() {
|
||||
final now = DateTime.now().microsecondsSinceEpoch.toRadixString(36);
|
||||
// `1 << 32` is 0 under the web's 32-bit shifts, so keep the range below that.
|
||||
final random = Random().nextInt(1 << 30).toRadixString(36);
|
||||
return 'schedule:flutter-$now-$random';
|
||||
}
|
||||
|
||||
/// Opens the landed [ScheduleEditorForm] as a native full-screen page.
|
||||
///
|
||||
/// The page supplies only the route and its standard back/title chrome; the
|
||||
/// form validates and builds the exact record. [onSubmit] is the save callback:
|
||||
/// it throwing a server refusal keeps this page open with every typed value,
|
||||
/// and returning accepted truth closes it.
|
||||
Future<void> openSchedulePipelineEditor(
|
||||
BuildContext context, {
|
||||
required ScheduleDraft draft,
|
||||
required Future<void> Function(JsonMap record) onSubmit,
|
||||
}) {
|
||||
final page = _SchedulePipelineEditorPage(draft: draft, onSubmit: onSubmit);
|
||||
final settings = RouteSettings(
|
||||
name: draft.source == null
|
||||
? 'schedule/new/${draft.pipelineId ?? 0}'
|
||||
: 'schedule/${draft.source?.id ?? 0}',
|
||||
);
|
||||
final title = draft.source == null
|
||||
? scheduleEditorAddTitle
|
||||
: scheduleEditorEditTitle;
|
||||
final route = usesCupertinoHost(context)
|
||||
? CupertinoPageRoute<void>(
|
||||
settings: settings,
|
||||
builder: (_) => CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(middle: Text(title)),
|
||||
child: SafeArea(top: false, child: page),
|
||||
),
|
||||
)
|
||||
: MaterialPageRoute<void>(
|
||||
settings: settings,
|
||||
builder: (_) => Scaffold(
|
||||
appBar: AppBar(title: Text(title)),
|
||||
body: SafeArea(child: page),
|
||||
),
|
||||
);
|
||||
return Navigator.of(context).push(route);
|
||||
}
|
||||
|
||||
class _SchedulePipelineEditorPage extends StatefulWidget {
|
||||
const _SchedulePipelineEditorPage({
|
||||
required this.draft,
|
||||
required this.onSubmit,
|
||||
});
|
||||
|
||||
final ScheduleDraft draft;
|
||||
final Future<void> Function(JsonMap record) onSubmit;
|
||||
|
||||
@override
|
||||
State<_SchedulePipelineEditorPage> createState() =>
|
||||
_SchedulePipelineEditorPageState();
|
||||
}
|
||||
|
||||
class _SchedulePipelineEditorPageState
|
||||
extends State<_SchedulePipelineEditorPage> {
|
||||
Future<void> _submit(JsonMap record) async {
|
||||
await widget.onSubmit(record);
|
||||
if (mounted) Navigator.of(context).pop();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: ScheduleEditorForm(
|
||||
draft: widget.draft,
|
||||
showHeading: false,
|
||||
onSubmit: _submit,
|
||||
onCancel: () => Navigator.of(context).pop(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../domain/saved_schedule.dart';
|
||||
import '../list/schedule_list_controller.dart';
|
||||
import 'schedule_pipeline_controller.dart';
|
||||
import 'schedule_pipeline_row.dart';
|
||||
import 'schedule_pipeline_styles.dart';
|
||||
import 'schedule_pipeline_wording.dart';
|
||||
|
||||
/// The visible schedule list of the pipeline Summary. State and mutations stay
|
||||
/// in `SchedulePipelineSection`; this widget renders one frame of them.
|
||||
class SchedulePipelineListBody extends StatelessWidget {
|
||||
const SchedulePipelineListBody({
|
||||
super.key,
|
||||
required this.controller,
|
||||
required this.busyRows,
|
||||
required this.rowErrors,
|
||||
required this.onAdd,
|
||||
required this.onEdit,
|
||||
required this.onToggle,
|
||||
required this.onDelete,
|
||||
});
|
||||
|
||||
final SchedulePipelineController controller;
|
||||
final Set<int> busyRows;
|
||||
final Map<int, String> rowErrors;
|
||||
final VoidCallback onAdd;
|
||||
final ValueChanged<SavedSchedule> onEdit;
|
||||
final ValueChanged<SavedSchedule> onToggle;
|
||||
final ValueChanged<SavedSchedule> onDelete;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final failure = controller.failure;
|
||||
final schedules = controller.schedules;
|
||||
return Padding(
|
||||
key: scheduleSectionKey,
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 4),
|
||||
child: _header(context),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Text(
|
||||
scheduleSectionNote,
|
||||
style: schedulePipelineMutedStyle(context),
|
||||
),
|
||||
),
|
||||
if (controller.isInitialLoading)
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 8),
|
||||
child: Semantics(
|
||||
liveRegion: true,
|
||||
label: scheduleSectionLoading,
|
||||
child: Text(
|
||||
scheduleSectionLoading,
|
||||
style: schedulePipelineMutedStyle(context),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (failure != null)
|
||||
_failure(context, failure)
|
||||
else if (controller.hasLoaded && schedules.isEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 8),
|
||||
child: Text(
|
||||
scheduleSectionEmpty,
|
||||
style: schedulePipelineMutedStyle(context),
|
||||
),
|
||||
),
|
||||
for (var index = 0; index < schedules.length; index++) ...[
|
||||
_row(context, schedules[index]),
|
||||
if (index < schedules.length - 1)
|
||||
schedulePipelineSeparator(context),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _header(BuildContext context) {
|
||||
return Wrap(
|
||||
spacing: 12,
|
||||
runSpacing: 4,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [
|
||||
Semantics(
|
||||
header: true,
|
||||
container: true,
|
||||
child: Text(
|
||||
controller.hasLoaded && controller.failure == null
|
||||
? '$scheduleSectionTitle (${controller.schedules.length})'
|
||||
: scheduleSectionTitle,
|
||||
style: schedulePipelineHeadingStyle(context),
|
||||
),
|
||||
),
|
||||
schedulePipelineTextButton(
|
||||
context,
|
||||
key: scheduleRefreshKey,
|
||||
label: scheduleRefreshLabel,
|
||||
onPressed: controller.isLoading ? null : controller.refresh,
|
||||
),
|
||||
schedulePipelineTextButton(
|
||||
context,
|
||||
key: scheduleAddKey,
|
||||
label: scheduleAddLabel,
|
||||
onPressed: onAdd,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _row(BuildContext context, SavedSchedule schedule) {
|
||||
final id = schedule.id;
|
||||
return SchedulePipelineRow(
|
||||
schedule: schedule,
|
||||
busy: id != null && busyRows.contains(id),
|
||||
error: id == null ? null : rowErrors[id],
|
||||
onEdit: () => onEdit(schedule),
|
||||
onToggle: () => onToggle(schedule),
|
||||
onDelete: () => onDelete(schedule),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _failure(BuildContext context, ScheduleListFailure failure) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 8),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Semantics(
|
||||
liveRegion: true,
|
||||
child: Text(
|
||||
failure.message,
|
||||
style: schedulePipelineErrorStyle(context),
|
||||
),
|
||||
),
|
||||
schedulePipelineTextButton(
|
||||
context,
|
||||
label: 'Retry',
|
||||
onPressed: controller.isLoading ? null : controller.refresh,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../domain/saved_schedule.dart';
|
||||
import '../list/schedule_list_format.dart';
|
||||
import 'schedule_pipeline_styles.dart';
|
||||
import 'schedule_pipeline_wording.dart';
|
||||
|
||||
/// One saved schedule in the pipeline Summary: name, state, pinned version and
|
||||
/// timer words, the recorded due time, and its Edit/Pause-Enable/Delete actions.
|
||||
class SchedulePipelineRow extends StatelessWidget {
|
||||
const SchedulePipelineRow({
|
||||
super.key,
|
||||
required this.schedule,
|
||||
required this.busy,
|
||||
required this.onEdit,
|
||||
required this.onToggle,
|
||||
required this.onDelete,
|
||||
this.error,
|
||||
});
|
||||
|
||||
final SavedSchedule schedule;
|
||||
final bool busy;
|
||||
final String? error;
|
||||
final VoidCallback onEdit;
|
||||
final VoidCallback onToggle;
|
||||
final VoidCallback onDelete;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final id = schedule.id;
|
||||
return Padding(
|
||||
key: scheduleRowKey(id),
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 12),
|
||||
child: Semantics(
|
||||
container: true,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
scheduleDisplayName(schedule),
|
||||
style: schedulePipelineBodyStyle(context),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
scheduleStatusLabel(schedule),
|
||||
style: schedulePipelineStatusStyle(context, schedule.enabled),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'Pinned ${schedulePinnedVersionValue(schedule)} · '
|
||||
'${scheduleRuleSummary(schedule)}',
|
||||
style: schedulePipelineMutedStyle(context),
|
||||
),
|
||||
if (schedule.prompt.isNotEmpty) ...[
|
||||
const SizedBox(height: 4),
|
||||
Text(schedule.prompt, style: schedulePipelineBodyStyle(context)),
|
||||
],
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'$scheduleNextPrefix${scheduleNextDueValue(schedule)}',
|
||||
style: schedulePipelineMutedStyle(context),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 4,
|
||||
children: [
|
||||
schedulePipelineTextButton(
|
||||
context,
|
||||
key: scheduleRowEditKey(id),
|
||||
label: scheduleEditLabel,
|
||||
onPressed: busy ? null : onEdit,
|
||||
),
|
||||
schedulePipelineTextButton(
|
||||
context,
|
||||
key: scheduleRowToggleKey(id),
|
||||
label: schedule.enabled
|
||||
? schedulePauseLabel
|
||||
: scheduleEnableLabel,
|
||||
onPressed: busy ? null : onToggle,
|
||||
),
|
||||
schedulePipelineTextButton(
|
||||
context,
|
||||
key: scheduleRowDeleteKey(id),
|
||||
label: scheduleDeleteLabel,
|
||||
onPressed: busy ? null : onDelete,
|
||||
),
|
||||
],
|
||||
),
|
||||
if (error case final text?)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 4),
|
||||
child: Semantics(
|
||||
liveRegion: true,
|
||||
child: Text(
|
||||
text,
|
||||
key: scheduleRowErrorKey(id),
|
||||
style: schedulePipelineErrorStyle(context),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../core/api_gateway.dart';
|
||||
import '../../../settings/settings_store.dart';
|
||||
import '../../data/schedules_repository.dart';
|
||||
import '../../domain/editor/schedule_draft.dart';
|
||||
import '../../domain/saved_schedule.dart';
|
||||
import '../list/schedule_list_format.dart';
|
||||
import 'schedule_delete_dialog.dart';
|
||||
import 'schedule_pipeline_controller.dart';
|
||||
import 'schedule_pipeline_editor.dart';
|
||||
import 'schedule_pipeline_list_body.dart';
|
||||
|
||||
/// The pipeline Summary's Schedules section.
|
||||
///
|
||||
/// Lists exactly this pipeline's saved run configurations and offers Add,
|
||||
/// Edit, Pause/Enable and Delete. Every accepted mutation re-reads
|
||||
/// `list_schedules`; nothing is updated optimistically. This section never
|
||||
/// publishes, validates or runs a workflow and never starts a run.
|
||||
class SchedulePipelineSection extends StatefulWidget {
|
||||
const SchedulePipelineSection({
|
||||
super.key,
|
||||
required this.gateway,
|
||||
required this.pipelineId,
|
||||
required this.version,
|
||||
this.settingsStore = const SharedPreferencesSettingsStore(),
|
||||
});
|
||||
|
||||
final ApiGateway gateway;
|
||||
final int pipelineId;
|
||||
|
||||
/// The resolved version currently shown, used as a new schedule's pin.
|
||||
final int version;
|
||||
|
||||
/// The operator's persisted server workspace seeds a new schedule's absolute
|
||||
/// workspace, matching the web client's configured workspace.
|
||||
final SettingsStore settingsStore;
|
||||
|
||||
@override
|
||||
State<SchedulePipelineSection> createState() =>
|
||||
_SchedulePipelineSectionState();
|
||||
}
|
||||
|
||||
class _SchedulePipelineSectionState extends State<SchedulePipelineSection> {
|
||||
late SchedulePipelineController _controller;
|
||||
final Map<int, String> _rowErrors = {};
|
||||
final Set<int> _busyRows = {};
|
||||
Future<SettingsValues>? _settings;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = _createController()..refresh();
|
||||
}
|
||||
|
||||
SchedulePipelineController _createController() => SchedulePipelineController(
|
||||
repository: SchedulesRepository(widget.gateway),
|
||||
pipelineId: widget.pipelineId,
|
||||
);
|
||||
|
||||
@override
|
||||
void didUpdateWidget(SchedulePipelineSection oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.gateway != widget.gateway ||
|
||||
oldWidget.pipelineId != widget.pipelineId) {
|
||||
_controller.dispose();
|
||||
_controller = _createController()..refresh();
|
||||
_rowErrors.clear();
|
||||
_busyRows.clear();
|
||||
}
|
||||
if (oldWidget.settingsStore != widget.settingsStore) _settings = null;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<String> _workspace() async {
|
||||
final settings = _settings ??= widget.settingsStore.load();
|
||||
try {
|
||||
return (await settings).workspace.trim();
|
||||
} catch (_) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _add() async {
|
||||
final workspace = await _workspace();
|
||||
if (!mounted) return;
|
||||
final requestKey = newScheduleCreateRequestKey();
|
||||
final draft = ScheduleDraft.create(
|
||||
pipelineId: widget.pipelineId,
|
||||
version: '${widget.version}',
|
||||
workspace: workspace,
|
||||
);
|
||||
await openSchedulePipelineEditor(
|
||||
context,
|
||||
draft: draft,
|
||||
onSubmit: (record) async {
|
||||
await _controller.saveRecord(record, requestKey: requestKey);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _edit(SavedSchedule schedule) {
|
||||
return openSchedulePipelineEditor(
|
||||
context,
|
||||
draft: ScheduleDraft.fromSchedule(schedule),
|
||||
onSubmit: (record) async {
|
||||
await _controller.saveRecord(record);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _toggle(SavedSchedule schedule) async {
|
||||
final id = schedule.id;
|
||||
if (id == null) return;
|
||||
setState(() {
|
||||
_busyRows.add(id);
|
||||
_rowErrors.remove(id);
|
||||
});
|
||||
try {
|
||||
await _controller.setEnabled(schedule);
|
||||
} catch (error) {
|
||||
if (mounted) {
|
||||
setState(() => _rowErrors[id] = scheduleActionError(error));
|
||||
}
|
||||
} finally {
|
||||
if (mounted) setState(() => _busyRows.remove(id));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _delete(SavedSchedule schedule) {
|
||||
return showScheduleDeleteDialog(
|
||||
context: context,
|
||||
name: scheduleDisplayName(schedule),
|
||||
onSubmit: () async {
|
||||
try {
|
||||
await _controller.delete(schedule);
|
||||
return null;
|
||||
} catch (error) {
|
||||
return scheduleActionError(error);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AnimatedBuilder(
|
||||
animation: _controller,
|
||||
builder: (context, _) => SchedulePipelineListBody(
|
||||
controller: _controller,
|
||||
busyRows: _busyRows,
|
||||
rowErrors: _rowErrors,
|
||||
onAdd: _add,
|
||||
onEdit: _edit,
|
||||
onToggle: _toggle,
|
||||
onDelete: _delete,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../ui/adaptive/host.dart';
|
||||
|
||||
/// Host text roles and standard buttons for the pipeline schedule section.
|
||||
/// No palette, font family or explicit point size is introduced.
|
||||
TextStyle? schedulePipelineHeadingStyle(BuildContext context) =>
|
||||
usesCupertinoHost(context)
|
||||
? CupertinoTheme.of(context).textTheme.navTitleTextStyle
|
||||
: Theme.of(context).textTheme.titleMedium;
|
||||
|
||||
TextStyle? schedulePipelineBodyStyle(BuildContext context) =>
|
||||
usesCupertinoHost(context)
|
||||
? CupertinoTheme.of(context).textTheme.textStyle
|
||||
: Theme.of(context).textTheme.bodyLarge;
|
||||
|
||||
TextStyle? schedulePipelineMutedStyle(BuildContext context) {
|
||||
if (usesCupertinoHost(context)) {
|
||||
return CupertinoTheme.of(context).textTheme.tabLabelTextStyle.copyWith(
|
||||
color: CupertinoColors.secondaryLabel.resolveFrom(context),
|
||||
);
|
||||
}
|
||||
final theme = Theme.of(context);
|
||||
return theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
);
|
||||
}
|
||||
|
||||
TextStyle? schedulePipelineStatusStyle(BuildContext context, bool enabled) {
|
||||
final base = schedulePipelineMutedStyle(context);
|
||||
if (!enabled) return base;
|
||||
return usesCupertinoHost(context)
|
||||
? base?.copyWith(color: CupertinoTheme.of(context).primaryColor)
|
||||
: base?.copyWith(color: Theme.of(context).colorScheme.primary);
|
||||
}
|
||||
|
||||
TextStyle? schedulePipelineErrorStyle(BuildContext context) =>
|
||||
usesCupertinoHost(context)
|
||||
? CupertinoTheme.of(context).textTheme.textStyle.copyWith(
|
||||
color: CupertinoColors.systemRed.resolveFrom(context),
|
||||
)
|
||||
: TextStyle(color: Theme.of(context).colorScheme.error);
|
||||
|
||||
/// A standard platform text action.
|
||||
Widget schedulePipelineTextButton(
|
||||
BuildContext context, {
|
||||
required String label,
|
||||
required VoidCallback? onPressed,
|
||||
Key? key,
|
||||
}) {
|
||||
if (usesCupertinoHost(context)) {
|
||||
return CupertinoButton(
|
||||
key: key,
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: onPressed,
|
||||
child: Text(label),
|
||||
);
|
||||
}
|
||||
return TextButton(key: key, onPressed: onPressed, child: Text(label));
|
||||
}
|
||||
|
||||
Widget schedulePipelineSeparator(BuildContext context) {
|
||||
if (usesCupertinoHost(context)) {
|
||||
return Container(
|
||||
height: 1 / MediaQuery.devicePixelRatioOf(context),
|
||||
color: CupertinoColors.separator.resolveFrom(context),
|
||||
);
|
||||
}
|
||||
return const Divider(height: 1);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
/// Browser wording and stable keys for the pipeline Summary schedule section,
|
||||
/// kept verbatim from `web/src/views/schedules.js`.
|
||||
const scheduleSectionTitle = 'Schedules';
|
||||
const scheduleSectionNote =
|
||||
'Independent prompts and timers for this pipeline. Schedules do not '
|
||||
'change its definition.';
|
||||
const scheduleSectionEmpty =
|
||||
'No schedules yet. Add one for each topic or recurring task.';
|
||||
const scheduleSectionLoading = 'Loading schedules…';
|
||||
const scheduleAddLabel = 'Add schedule';
|
||||
const scheduleRefreshLabel = 'Refresh';
|
||||
const scheduleEditLabel = 'Edit';
|
||||
const schedulePauseLabel = 'Pause';
|
||||
const scheduleEnableLabel = 'Enable';
|
||||
const scheduleDeleteLabel = 'Delete';
|
||||
const scheduleDeleteKeepLabel = 'Keep schedule';
|
||||
const scheduleDeleteConfirmLabel = 'Delete schedule';
|
||||
const scheduleDeleteMessage =
|
||||
'Future runs only. Run history and active runs will not be deleted.';
|
||||
const scheduleNextPrefix = 'Next: ';
|
||||
|
||||
String scheduleDeleteTitle(String name) => 'Delete $name?';
|
||||
|
||||
const scheduleSectionKey = ValueKey<String>('schedule-pipeline-section');
|
||||
const scheduleAddKey = ValueKey<String>('schedule-pipeline-add');
|
||||
const scheduleRefreshKey = ValueKey<String>('schedule-pipeline-refresh');
|
||||
const scheduleDeleteKeepKey = ValueKey<String>('schedule-delete-keep');
|
||||
const scheduleDeleteConfirmKey = ValueKey<String>('schedule-delete-confirm');
|
||||
const scheduleDeleteErrorKey = ValueKey<String>('schedule-delete-error');
|
||||
|
||||
ValueKey<String> scheduleRowKey(int? id) =>
|
||||
ValueKey<String>('schedule-pipeline-row-${id ?? 'unknown'}');
|
||||
ValueKey<String> scheduleRowEditKey(int? id) =>
|
||||
ValueKey<String>('schedule-pipeline-edit-${id ?? 'unknown'}');
|
||||
ValueKey<String> scheduleRowToggleKey(int? id) =>
|
||||
ValueKey<String>('schedule-pipeline-toggle-${id ?? 'unknown'}');
|
||||
ValueKey<String> scheduleRowDeleteKey(int? id) =>
|
||||
ValueKey<String>('schedule-pipeline-delete-${id ?? 'unknown'}');
|
||||
ValueKey<String> scheduleRowErrorKey(int? id) =>
|
||||
ValueKey<String>('schedule-pipeline-error-${id ?? 'unknown'}');
|
||||
Reference in New Issue
Block a user