#54 run multiple snippets
This commit is contained in:
@@ -147,6 +147,7 @@ class BackupPage extends StatelessWidget {
|
||||
|
||||
await showRoundDialog(
|
||||
context: context,
|
||||
title: Text(s.restore),
|
||||
child: Text(s.restoreSureWithDate(backup.date)),
|
||||
actions: [
|
||||
TextButton(
|
||||
@@ -170,6 +171,7 @@ class BackupPage extends StatelessWidget {
|
||||
context.pop();
|
||||
showRoundDialog(
|
||||
context: context,
|
||||
title: Text(s.restore),
|
||||
child: Text(s.restoreSuccess),
|
||||
actions: [
|
||||
TextButton(
|
||||
|
||||
@@ -180,6 +180,7 @@ class _DockerManagePageState extends State<DockerManagePage> {
|
||||
if (_textController.text == '') {
|
||||
showRoundDialog(
|
||||
context: context,
|
||||
title: Text(_s.attention),
|
||||
child: Text(_s.fieldMustNotEmpty),
|
||||
actions: [
|
||||
TextButton(
|
||||
@@ -286,6 +287,7 @@ class _DockerManagePageState extends State<DockerManagePage> {
|
||||
onPressed: () async {
|
||||
showRoundDialog(
|
||||
context: context,
|
||||
title: Text(_s.attention),
|
||||
child: Text(_s.sureDelete(e.repo)),
|
||||
actions: [
|
||||
TextButton(
|
||||
|
||||
@@ -89,6 +89,7 @@ class _PingPageState extends State<PingPage>
|
||||
} catch (e) {
|
||||
showRoundDialog(
|
||||
context: context,
|
||||
title: Text(_s.error),
|
||||
child: Text(e.toString()),
|
||||
actions: [
|
||||
TextButton(
|
||||
|
||||
@@ -88,6 +88,7 @@ class _PkgManagePageState extends State<PkgManagePage>
|
||||
if (_textController.text == '') {
|
||||
showRoundDialog(
|
||||
context: context,
|
||||
title: Text(_s.attention),
|
||||
child: Text(_s.fieldMustNotEmpty),
|
||||
actions: [
|
||||
TextButton(
|
||||
|
||||
@@ -90,6 +90,7 @@ class _ProcessPageState extends State<ProcessPage> {
|
||||
icon: const Icon(Icons.error),
|
||||
onPressed: () => showRoundDialog(
|
||||
context: context,
|
||||
title: Text(_s.error),
|
||||
child: Text(_result.error!),
|
||||
),
|
||||
));
|
||||
|
||||
@@ -15,7 +15,7 @@ import '../../../data/provider/server.dart';
|
||||
import '../../../data/res/ui.dart';
|
||||
import '../../../data/store/private_key.dart';
|
||||
import '../../../locator.dart';
|
||||
import '../../widget/tag_editor.dart';
|
||||
import '../../widget/tag/editor.dart';
|
||||
import '../private_key/edit.dart';
|
||||
|
||||
class ServerEditPage extends StatefulWidget {
|
||||
@@ -239,6 +239,7 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
if (!usePublicKey && _passwordController.text == '') {
|
||||
final cancel = await showRoundDialog<bool>(
|
||||
context: context,
|
||||
title: Text(_s.attention),
|
||||
child: Text(_s.sureNoPwd),
|
||||
actions: [
|
||||
TextButton(
|
||||
|
||||
@@ -5,11 +5,13 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:nil/nil.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:toolbox/core/extension/navigator.dart';
|
||||
import 'package:toolbox/core/extension/order.dart';
|
||||
import 'package:toolbox/core/utils/misc.dart';
|
||||
import 'package:toolbox/data/model/server/snippet.dart';
|
||||
import 'package:toolbox/data/provider/snippet.dart';
|
||||
import 'package:toolbox/view/page/process.dart';
|
||||
import 'package:toolbox/view/widget/tag_switcher.dart';
|
||||
import 'package:toolbox/view/widget/tag/picker.dart';
|
||||
import 'package:toolbox/view/widget/tag/switcher.dart';
|
||||
|
||||
import '../../../core/route.dart';
|
||||
import '../../../core/utils/ui.dart';
|
||||
@@ -273,7 +275,7 @@ class _ServerPageState extends State<ServerPage>
|
||||
Widget _buildMoreBtn(ServerPrivateInfo spi) {
|
||||
return PopupMenu(
|
||||
items: ServerTabMenuType.values.map((e) => e.build(_s)).toList(),
|
||||
onSelected: (ServerTabMenuType value) {
|
||||
onSelected: (ServerTabMenuType value) async {
|
||||
switch (value) {
|
||||
case ServerTabMenuType.pkg:
|
||||
AppRoute(PkgManagePage(spi), 'pkg manage').go(context);
|
||||
@@ -282,19 +284,33 @@ class _ServerPageState extends State<ServerPage>
|
||||
AppRoute(SFTPPage(spi), 'SFTP').go(context);
|
||||
break;
|
||||
case ServerTabMenuType.snippet:
|
||||
showSnippetDialog(context, _s, (s) async {
|
||||
final result = await _serverProvider.runSnippet(spi.id, s);
|
||||
final provider = locator<SnippetProvider>();
|
||||
final snippets = await showDialog<List<Snippet>>(
|
||||
context: context,
|
||||
builder: (_) => TagPicker<Snippet>(
|
||||
items: provider.snippets,
|
||||
containsTag: (t, tag) => t.tags?.contains(tag) ?? false,
|
||||
tags: provider.tags.toSet(),
|
||||
name: (t) => t.name,
|
||||
),
|
||||
);
|
||||
if (snippets == null) {
|
||||
return;
|
||||
}
|
||||
final result = await _serverProvider.runSnippets(spi.id, snippets);
|
||||
if (result != null && result.isNotEmpty) {
|
||||
showRoundDialog(
|
||||
context: context,
|
||||
child: Text(result ?? _s.error, style: textSize13),
|
||||
title: Text(_s.result),
|
||||
child: Text(result),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => context.pop(),
|
||||
child: Text(_s.ok),
|
||||
onPressed: () => copy2Clipboard(result),
|
||||
child: Text(_s.copy),
|
||||
)
|
||||
],
|
||||
);
|
||||
});
|
||||
}
|
||||
break;
|
||||
case ServerTabMenuType.edit:
|
||||
AppRoute(ServerEditPage(spi: spi), 'Edit server info').go(context);
|
||||
@@ -303,13 +319,6 @@ class _ServerPageState extends State<ServerPage>
|
||||
AppRoute(DockerManagePage(spi), 'Docker manage').go(context);
|
||||
break;
|
||||
case ServerTabMenuType.process:
|
||||
// AppRoute(
|
||||
// SSHPage(
|
||||
// spi: spi,
|
||||
// initCmd: 'sh $shellPath -${shellFuncProcess.flag}',
|
||||
// ),
|
||||
// 'ssh page (process)',
|
||||
// ).go(context);
|
||||
AppRoute(ProcessPage(spi: spi), 'process page').go(context);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -272,13 +272,18 @@ class _SettingPageState extends State<SettingPage> {
|
||||
await showRoundDialog(
|
||||
context: context,
|
||||
title: Text(_s.primaryColor),
|
||||
child: MaterialColorPicker(
|
||||
shrinkWrap: true,
|
||||
allowShades: true,
|
||||
onColorChange: (color) {
|
||||
_selectedColorValue.value = color.value;
|
||||
},
|
||||
selectedColor: primaryColor,
|
||||
child: SizedBox(
|
||||
height: 211,
|
||||
child: Center(
|
||||
child: MaterialColorPicker(
|
||||
shrinkWrap: true,
|
||||
allowShades: true,
|
||||
onColorChange: (color) {
|
||||
_selectedColorValue.value = color.value;
|
||||
},
|
||||
selectedColor: primaryColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
@@ -557,7 +562,11 @@ class _SettingPageState extends State<SettingPage> {
|
||||
context.pop();
|
||||
final fontSize = double.tryParse(ctrller.text);
|
||||
if (fontSize == null) {
|
||||
showRoundDialog(context: context, child: Text(_s.failed));
|
||||
showRoundDialog(
|
||||
context: context,
|
||||
title: Text(_s.failed),
|
||||
child: Text('Parsed failed: ${ctrller.text}'),
|
||||
);
|
||||
return;
|
||||
}
|
||||
_fontSize.value = fontSize;
|
||||
|
||||
@@ -178,6 +178,7 @@ class _SFTPDownloadedPageState extends State<SFTPDownloadedPage> {
|
||||
if (stat.size > editorMaxSize) {
|
||||
showRoundDialog(
|
||||
context: context,
|
||||
title: Text(_s.attention),
|
||||
child: Text(_s.fileTooLarge(fileName, stat.size, '1m')),
|
||||
);
|
||||
return;
|
||||
@@ -223,6 +224,7 @@ class _SFTPDownloadedPageState extends State<SFTPDownloadedPage> {
|
||||
context.pop();
|
||||
showRoundDialog(
|
||||
context: context,
|
||||
title: Text(_s.delete),
|
||||
child: Text(_s.sureDelete(fileName)),
|
||||
actions: [
|
||||
TextButton(
|
||||
|
||||
@@ -134,6 +134,7 @@ class _SFTPPageState extends State<SFTPPage> {
|
||||
onPressed: () async {
|
||||
final idx = await showRoundDialog(
|
||||
context: context,
|
||||
title: Text(_s.choose),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
@@ -517,6 +518,7 @@ class _SFTPPageState extends State<SFTPPage> {
|
||||
if (textController.text == '') {
|
||||
showRoundDialog(
|
||||
context: context,
|
||||
title: Text(_s.attention),
|
||||
child: Text(_s.fieldMustNotEmpty),
|
||||
actions: [
|
||||
TextButton(
|
||||
@@ -559,6 +561,7 @@ class _SFTPPageState extends State<SFTPPage> {
|
||||
if (textController.text == '') {
|
||||
showRoundDialog(
|
||||
context: context,
|
||||
title: Text(_s.attention),
|
||||
child: Text(_s.fieldMustNotEmpty),
|
||||
actions: [
|
||||
TextButton(
|
||||
|
||||
@@ -9,7 +9,7 @@ import '../../../data/model/server/snippet.dart';
|
||||
import '../../../data/provider/snippet.dart';
|
||||
import '../../../data/res/ui.dart';
|
||||
import '../../../locator.dart';
|
||||
import '../../widget/tag_editor.dart';
|
||||
import '../../widget/tag/editor.dart';
|
||||
|
||||
class SnippetEditPage extends StatefulWidget {
|
||||
const SnippetEditPage({Key? key, this.snippet}) : super(key: key);
|
||||
|
||||
@@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:toolbox/core/extension/order.dart';
|
||||
import 'package:toolbox/view/widget/tag_switcher.dart';
|
||||
import 'package:toolbox/view/widget/tag/switcher.dart';
|
||||
|
||||
import '../../../data/store/setting.dart';
|
||||
import '../../../locator.dart';
|
||||
|
||||
@@ -259,6 +259,7 @@ class _SSHPageState extends State<SSHPage> {
|
||||
if (initPath.isEmpty || !initPath.startsWith('/')) {
|
||||
showRoundDialog(
|
||||
context: context,
|
||||
title: Text(_s.error),
|
||||
child: const Text('Failed to get current path'),
|
||||
);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user