Mobile Client: In forms, get values from previous state + delete action button

This commit is contained in:
Arthi-chaud
2022-02-08 16:32:50 +01:00
parent 8761af1d33
commit ef9773f5bb
5 changed files with 136 additions and 128 deletions
+1 -1
View File
@@ -42,7 +42,7 @@ class Aeris extends StatelessWidget {
],
supportedLocales: const [Locale('fr', ''), Locale('en', '')],
theme: ThemeData(colorScheme: aerisScheme),
initialRoute: '/',
initialRoute: '/home',
onGenerateRoute: (settings) {
Map pageRoutes = {
'/': () => const StartupPage(),
+11 -7
View File
@@ -90,13 +90,17 @@ class _CreatePipelinePageState extends State<CreatePipelinePage> {
...[
for (Reaction reaction in reactions)
ActionCard(
leading: reaction.service.getLogo(logoSize: 50),
title: reaction.service.name,
trailing: ActionCardPopupMenu(
deletable: reaction != reactions[0],
action: reaction,
then: () => setState(() {})),
)
leading: reaction.service.getLogo(logoSize: 50),
title: reaction.service.name,
trailing: ActionCardPopupMenu(
deletable: reaction != reactions[0],
action: reaction,
then: () => setState(() {}),
onDelete: () {
setState(() {
reactions.remove(reaction);
});
}))
],
Padding(
padding: const EdgeInsets.all(8.0),
+102 -110
View File
@@ -35,7 +35,9 @@ class _PipelineDetailPageState extends State<PipelineDetailPage> {
@override
Widget build(BuildContext context) =>
Consumer<PipelineProvider>(builder: (context, provider, _) {
final PipelineDetailPageArguments arguments = ModalRoute.of(context)!.settings.arguments as PipelineDetailPageArguments;
final PipelineDetailPageArguments arguments = ModalRoute.of(context)!
.settings
.arguments as PipelineDetailPageArguments;
Pipeline pipeline = arguments.pipeline;
final cardHeader = Row(
@@ -47,139 +49,129 @@ class _PipelineDetailPageState extends State<PipelineDetailPage> {
Align(
alignment: Alignment.centerLeft,
child: Text(pipeline.name,
style: const TextStyle(
fontSize: 25,
)
),
style: const TextStyle(
fontSize: 25,
)),
),
const SizedBox(height: 10),
Align(
alignment: Alignment.centerLeft,
child: Text(pipeline.trigger.lastToString(),
style: const TextStyle(
fontSize: 17,
)
),
style: const TextStyle(
fontSize: 17,
)),
),
],
),
),
Expanded(
flex: 3,
child: Column(
children: [
const SizedBox(height: 10),
Align(
alignment: Alignment.center,
child: FlutterSwitch(
activeColor: Colors.green,
width: 60,
value: pipeline.enabled,
onToggle: (value) {
setState(() {
pipeline.enabled = !pipeline.enabled;
provider.sortPipelines();
provider.notifyListeners();
// TODO call api
});
},
flex: 3,
child: Column(
children: [
const SizedBox(height: 10),
Align(
alignment: Alignment.center,
child: FlutterSwitch(
activeColor: Colors.green,
width: 60,
value: pipeline.enabled,
onToggle: (value) {
setState(() {
pipeline.enabled = !pipeline.enabled;
provider.sortPipelines();
provider.notifyListeners();
// TODO call api
});
},
),
),
),
const SizedBox(height: 10),
Align(
alignment: Alignment.center,
child: Text(pipeline.enabled ? AppLocalizations.of(context).enabled : AppLocalizations.of(context).disabled,
style: const TextStyle(fontSize: 13)
const SizedBox(height: 10),
Align(
alignment: Alignment.center,
child: Text(
pipeline.enabled
? AppLocalizations.of(context).enabled
: AppLocalizations.of(context).disabled,
style: const TextStyle(fontSize: 13)),
),
),
],
)
)
],
))
],
);
final Widget addReactionbutton = ColoredClickableCard(
color: Theme.of(context).colorScheme.secondaryContainer,
text: AppLocalizations.of(context).addReaction,
onTap: () {
Reaction newreaction = Reaction.template();
Navigator.of(context).pushNamed('/pipeline/action/new',
arguments: SetupActionPageArguments(newreaction)
).then((r) {
if (newreaction != Reaction.template()) {
setState(() {
pipeline.reactions.add(newreaction);
});
}
return r;
}); // TODO add reaction in db
}
);
color: Theme.of(context).colorScheme.secondaryContainer,
text: AppLocalizations.of(context).addReaction,
onTap: () {
Reaction newreaction = Reaction.template();
Navigator.of(context)
.pushNamed('/pipeline/action/new',
arguments: SetupActionPageArguments(newreaction))
.then((r) {
if (newreaction != Reaction.template()) {
setState(() {
pipeline.reactions.add(newreaction);
});
}
return r;
}); // TODO add reaction in db
});
final Widget deleteButton = ColoredClickableCard(
color: Theme.of(context).colorScheme.error,
text: AppLocalizations.of(context).deletePipeline,
onTap: () => showDialog<String>(
context: context,
builder: (BuildContext context) => WarningDialog(
message:
AppLocalizations.of(context).deletePipelineWarningMessage,
onAccept: () {
provider.removePipeline(pipeline);
print("Delete pipeline"); /*TODO call api*/
Navigator.of(context).pop();
},
warnedAction: AppLocalizations.of(context).delete
)
),
context: context,
builder: (BuildContext context) => WarningDialog(
message:
AppLocalizations.of(context).deletePipelineWarningMessage,
onAccept: () {
provider.removePipeline(pipeline);
print("Delete pipeline"); /*TODO call api*/
Navigator.of(context).pop();
},
warnedAction: AppLocalizations.of(context).delete)),
);
return AerisCardPage(
body: Padding(
padding: const EdgeInsets.only(top: 10),
child: ListView(
children: [
Padding(
padding: const EdgeInsets.only(bottom: 40),
child: cardHeader,
),
const Text("Action",
style: TextStyle(fontWeight: FontWeight.w500)
),
ActionCard(
leading: pipeline.trigger.service.getLogo(logoSize: 50),
title: pipeline.trigger.name,
trailing: ActionCardPopupMenu(
body: Padding(
padding: const EdgeInsets.only(top: 10),
child: ListView(children: [
Padding(
padding: const EdgeInsets.only(bottom: 40),
child: cardHeader,
),
const Text("Action", style: TextStyle(fontWeight: FontWeight.w500)),
ActionCard(
leading: pipeline.trigger.service.getLogo(logoSize: 50),
title: pipeline.trigger.name,
trailing: ActionCardPopupMenu(
deletable: false,
action: pipeline.trigger,
then: () => setState(() {}))
),
const SizedBox(height: 25),
const Text("Reactions",
style: TextStyle(fontWeight: FontWeight.w500)
),
for (var reaction in pipeline.reactions)
ActionCard(
leading: reaction.service.getLogo(logoSize: 50),
title: reaction.name,
trailing: ActionCardPopupMenu(
deletable: reaction != pipeline.reactions.first,
action: reaction,
then: () => setState(() {}))
),
addReactionbutton,
const Padding(
padding: EdgeInsets.only(top: 30, bottom: 5),
child: Text("Danger Zone",
style: TextStyle(fontWeight: FontWeight.w500)
)
),
deleteButton,
const SizedBox(height: 25),
]
),
)
);
}
);
then: () => setState(() {}))),
const SizedBox(height: 25),
const Text("Reactions",
style: TextStyle(fontWeight: FontWeight.w500)),
for (var reaction in pipeline.reactions)
ActionCard(
leading: reaction.service.getLogo(logoSize: 50),
title: reaction.name,
trailing: ActionCardPopupMenu(
deletable: reaction != pipeline.reactions.first,
action: reaction,
then: () => setState(() {}),
onDelete: () {
pipeline.reactions.remove(reaction);
},
)),
addReactionbutton,
const Padding(
padding: EdgeInsets.only(top: 30, bottom: 5),
child: Text("Danger Zone",
style: TextStyle(fontWeight: FontWeight.w500))),
deleteButton,
const SizedBox(height: 25),
]),
));
});
}
+1 -1
View File
@@ -105,7 +105,7 @@ class _SetupActionPageState extends State<SetupActionPage> {
name: availableAction.name,
parametersNames:
availableAction.parameters.keys.toList(),
initValues: availableAction.parameters,
initValues: arguments.action.parameters,
onValidate: (parameters) {
arguments.action.service = serviceState!;
arguments.action.parameters = parameters;
@@ -7,12 +7,17 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
/// [StatelessWidget] displayed as a PopupMenu
class ActionCardPopupMenu extends StatelessWidget {
const ActionCardPopupMenu({
ActionCardPopupMenu({
Key? key,
required this.action,
required this.then,
required this.deletable,
}) : super(key: key);
this.onDelete,
}) : super(key: key) {
if (deletable) {
assert(onDelete != null);
}
}
/// Action to trigger
final aeris.Action action;
@@ -23,17 +28,24 @@ class ActionCardPopupMenu extends StatelessWidget {
/// Deletable characteristic
final bool deletable;
final void Function()? onDelete;
@override
Widget build(BuildContext context) {
return AerisPopupMenu(
onSelected: (value) {
Map object = value as Map;
Navigator.pushNamed(context, object['route'] as String,
arguments: object['params'])
.then((r) {
then();
return r;
});
if (value == '/pipeline/action/del') {
onDelete!();
} else {
Map object = value as Map;
Navigator.pushNamed(context, object['route'] as String,
arguments: object['params'])
.then((r) {
then();
return r;
});
}
;
},
icon: Icons.more_vert,
itemBuilder: (context) => [