Commit 0289e567 authored by Administrator's avatar Administrator

tag and tag cloud admin

parent 7fdec90f
import 'package:encrateia/models/power_zone_schema.dart';
import 'package:encrateia/models/tag_group.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/model/model.dart';
import 'package:path_provider/path_provider.dart';
......@@ -83,6 +84,7 @@ class Athlete extends ChangeNotifier {
get weights => Weight.all(athlete: this);
get powerZoneSchemas => PowerZoneSchema.all(athlete: this);
get heartRateZoneSchemas => HeartRateZoneSchema.all(athlete: this);
get tagGroups => TagGroup.all(athlete: this);
delete() async {
var appDocDir = await getApplicationDocumentsDirectory();
......
......@@ -9,44 +9,23 @@ class TagGroup extends ChangeNotifier {
TagGroup({@required Athlete athlete}) {
db = DbTagGroup()
..athletesId = athlete.db.id
..color = Colors.lightGreen.value
..system = false
..name = "My Tag Group";
}
TagGroup.fromDb(this.db);
get powerZones => Tag.all(tagGroup: this);
get tags => Tag.all(tagGroup: this);
TagGroup.likeStryd({Athlete athlete}) {
TagGroup.by(
{@required Athlete athlete,
@required String name,
@required bool system}) {
db = DbTagGroup()
..athletesId = athlete.db.id
..name = "CP based";
}
addStrydZones() async {
await Tag(
tagGroup: this,
name: "Easy",
color: Colors.lightGreen.value,
).db.save();
await Tag(
tagGroup: this,
name: "Moderate",
color: Colors.lightBlue.value,
).db.save();
await Tag(
tagGroup: this,
name: "Threshold",
color: Colors.yellow.value,
).db.save();
await Tag(
tagGroup: this,
name: "Interval",
color: Colors.orange.value,
).db.save();
await Tag(
tagGroup: this,
name: "Repetition",
color: Colors.red.value,
).db.save();
..color = Colors.lightGreen.value
..system = system
..name = name;
}
String toString() => '$db.name';
......@@ -55,9 +34,25 @@ class TagGroup extends ChangeNotifier {
await this.db.delete();
}
static createDefaultTagGroups({Athlete athlete}) async {
var autoHeartRateZones = TagGroup.by(
name: "Auto Heart Rate Zones",
athlete: athlete,
system: true,
);
await autoHeartRateZones.db.save();
var autoPowerZonesTagGroup = TagGroup.by(
name: "Auto Power Zones",
athlete: athlete,
system: true,
);
await autoPowerZonesTagGroup.db.save();
}
static Future<List<TagGroup>> all({@required Athlete athlete}) async {
var dbTagGroupList =
await athlete.db.getDbTagGroups().orderByDesc('date').toList();
await athlete.db.getDbTagGroups().orderBy('name').toList();
var tagGroups = dbTagGroupList
.map((dbTagGroup) => TagGroup.fromDb(dbTagGroup))
.toList();
......@@ -73,7 +68,6 @@ class TagGroup extends ChangeNotifier {
.equals(athletesId)
.top(1)
.toList();
if (dbTagGroups.length != 0)
return TagGroup.fromDb(dbTagGroups.first);
if (dbTagGroups.length != 0) return TagGroup.fromDb(dbTagGroups.first);
}
}
import 'package:encrateia/utils/icon_utils.dart';
import 'package:encrateia/utils/my_button.dart';
import 'package:encrateia/utils/my_color.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/tag_group.dart';
import 'package:encrateia/models/tag.dart';
import 'package:flutter_material_color_picker/flutter_material_color_picker.dart';
import 'package:encrateia/model/model.dart';
import 'add_tag_screen.dart';
class AddTagGroupScreen extends StatefulWidget {
final TagGroup tagGroup;
const AddTagGroupScreen({Key key, this.tagGroup}) : super(key: key);
@override
_AddTagGroupScreenState createState() => _AddTagGroupScreenState();
}
class _AddTagGroupScreenState extends State<AddTagGroupScreen> {
List<Tag> tags = [];
int offset = 0;
int rows;
@override
void initState() {
getData();
super.initState();
}
void _openDialog(Widget content) {
showDialog(
context: context,
builder: (_) {
return AlertDialog(
contentPadding: const EdgeInsets.all(6.0),
title: Text("Select Color"),
content: content,
actions: [
MyButton.cancel(onPressed: Navigator.of(context).pop),
MyButton.save(
child: Text('Select'),
onPressed: () {
Navigator.of(context).pop();
MaterialColorPicker(
onColorChange: (color) =>
widget.tagGroup.db.color = color.value,
selectedColor: Color(widget.tagGroup.db.color));
},
),
],
);
},
);
}
void openColorPicker() async {
_openDialog(
MaterialColorPicker(
selectedColor: Color(widget.tagGroup.db.color),
onColorChange: (color) =>
setState(() => widget.tagGroup.db.color = color.value),
onBack: () => {},
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: MyColor.settings,
title: Text('Add Tag Group'),
),
body: ListView(
padding: EdgeInsets.only(left: 20, right: 20),
children: <Widget>[
TextFormField(
decoration: InputDecoration(labelText: "Name"),
initialValue: widget.tagGroup.db.name,
onChanged: (value) => widget.tagGroup.db.name = value,
),
SizedBox(height: 20),
Row(children: [
Text("Color"),
Spacer(),
CircleAvatar(
backgroundColor: Color(widget.tagGroup.db.color),
radius: 20.0,
),
Spacer(),
MyButton.detail(
onPressed: openColorPicker,
child: Text('Edit'),
),
]),
SizedBox(height: 20),
DataTable(
headingRowHeight: kMinInteractiveDimension * 0.80,
dataRowHeight: kMinInteractiveDimension * 0.75,
columnSpacing: 20,
horizontalMargin: 10,
columns: <DataColumn>[
DataColumn(label: Text("Tag")),
DataColumn(label: Text("Color")),
DataColumn(label: Text("Edit")),
],
rows: tags.map((Tag tag) {
return DataRow(
key: Key(tag.db.id.toString()),
cells: [
DataCell(Text(tag.db.name)),
DataCell(CircleColor(
circleSize: 20,
elevation: 0,
color: Color(tag.db.color),
)),
DataCell(
MyIcon.edit,
onTap: () async {
await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => AddTagScreen(
tag: tag,
),
),
);
getData();
},
)
],
);
}).toList(),
),
SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
MyButton.add(
child: Text("Add tag"),
onPressed: () async {
await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => AddTagScreen(
tag: Tag(tagGroup: widget.tagGroup),
),
),
);
getData();
},
),
],
),
SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
MyButton.delete(
onPressed: () => deleteTagGroup(
tagGroup: widget.tagGroup,
),
),
SizedBox(width: 5),
MyButton.cancel(onPressed: () => Navigator.of(context).pop()),
SizedBox(width: 5),
MyButton.save(onPressed: () => saveTagGroup(context)),
],
),
],
),
);
}
saveTagGroup(BuildContext context) async {
await widget.tagGroup.db.save();
await DbTag().upsertAll(tags.map((tag) => tag.db).toList());
Navigator.of(context).pop();
}
getData() async {
tags = await widget.tagGroup.tags;
setState(() {});
}
deleteTagGroup({TagGroup tagGroup}) async {
await tagGroup.delete();
Navigator.of(context).pop();
}
}
import 'package:encrateia/utils/my_button.dart';
import 'package:encrateia/utils/my_color.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/tag.dart';
import 'package:flutter_material_color_picker/flutter_material_color_picker.dart';
class AddTagScreen extends StatefulWidget {
final Tag tag;
final int base;
const AddTagScreen({
Key key,
this.tag,
this.base,
}) : super(key: key);
@override
_AddTagScreenState createState() => _AddTagScreenState();
}
class _AddTagScreenState extends State<AddTagScreen> {
void _openDialog(Widget content) {
showDialog(
context: context,
builder: (_) {
return AlertDialog(
contentPadding: const EdgeInsets.all(6.0),
title: Text("Select Color"),
content: content,
actions: [
MyButton.cancel(onPressed: Navigator.of(context).pop),
MyButton.save(
child: Text('Select'),
onPressed: () {
Navigator.of(context).pop();
MaterialColorPicker(
onColorChange: (color) => widget.tag.db.color = color.value,
selectedColor: Color(widget.tag.db.color));
},
),
],
);
},
);
}
void openColorPicker() async {
_openDialog(
MaterialColorPicker(
selectedColor: Color(widget.tag.db.color),
onColorChange: (color) =>
setState(() => widget.tag.db.color = color.value),
onBack: () => {},
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Add your Tag'),
backgroundColor: MyColor.settings,
),
body: ListView(
padding: EdgeInsets.all(20),
children: <Widget>[
TextFormField(
decoration: InputDecoration(labelText: "Name"),
initialValue: widget.tag.db.name,
onChanged: (value) => widget.tag.db.name = value,
),
SizedBox(height: 10),
Row(children: [
Text("Color"),
Spacer(),
CircleAvatar(
backgroundColor: Color(widget.tag.db.color),
radius: 20.0,
),
Spacer(),
MyButton.detail(
onPressed: openColorPicker,
child: Text('Edit'),
),
]),
SizedBox(height: 20),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
MyButton.delete(onPressed: () => deleteTag(context)),
SizedBox(width: 5),
MyButton.cancel(onPressed: () => Navigator.of(context).pop()),
SizedBox(width: 5),
MyButton.save(onPressed: () => saveTag(context)),
],
),
],
),
);
}
saveTag(BuildContext context) async {
await widget.tag.db.save();
Navigator.of(context).pop();
}
deleteTag(BuildContext context) async {
await widget.tag.db.delete();
Navigator.of(context).pop();
}
}
......@@ -3,6 +3,7 @@ import 'package:encrateia/utils/my_color.dart';
import 'package:encrateia/widgets/athlete_widgets/athlete_power_ratio_widget.dart';
import 'package:encrateia/widgets/athlete_widgets/athlete_power_zone_schema_widget.dart';
import 'package:encrateia/widgets/athlete_widgets/athlete_heart_rate_zone_schema_widget.dart';
import 'package:encrateia/widgets/athlete_widgets/athlete_tag_group_widget.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/models/activity.dart';
......@@ -145,6 +146,12 @@ class _ShowAthleteScreenState extends State<ShowAthleteScreen> {
nextWidget:
AthleteHeartRateZoneSchemaWidget(athlete: widget.athlete),
),
navigationButton(
color: MyColor.settings,
title: "Tags",
icon: MyIcon.tag,
nextWidget: AthleteTagGroupWidget(athlete: widget.athlete),
),
navigationButton(
color: MyColor.settings,
title: "Settings",
......
......@@ -80,6 +80,7 @@ class MyIcon {
static final strideRatio = Icon(Icons.signal_cellular_null);
static final strides = Icon(Icons.directions_walk);
// T
static final tag = Icon(Icons.label);
static final temperature = Icon(Icons.ac_unit);
static final time = Icon(Icons.timer);
static final timeStamp = Icon(Icons.access_time);
......
import 'package:encrateia/screens/add_tag_group_screen.dart';
import 'package:encrateia/utils/my_button.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/models/tag_group.dart';
import 'package:encrateia/utils/icon_utils.dart';
import 'package:flutter_material_color_picker/flutter_material_color_picker.dart';
class AthleteTagGroupWidget extends StatefulWidget {
final Athlete athlete;
AthleteTagGroupWidget({this.athlete});
@override
_AthleteTagGroupWidgetState createState() => _AthleteTagGroupWidgetState();
}
class _AthleteTagGroupWidgetState extends State<AthleteTagGroupWidget> {
List<TagGroup> tagGroups = [];
int offset = 0;
int rows;
@override
void initState() {
getData();
super.initState();
}
@override
Widget build(context) {
if (tagGroups != null) {
if (tagGroups.length > 0) {
rows = (tagGroups.length < 8) ? tagGroups.length : 8;
return ListView(
children: <Widget>[
Center(
child: Text(
"\nTag Groups ${offset + 1} - ${offset + rows} "
"of ${tagGroups.length}",
style: Theme.of(context).textTheme.title,
),
),
DataTable(
headingRowHeight: kMinInteractiveDimension * 0.80,
dataRowHeight: kMinInteractiveDimension * 0.80,
columnSpacing: 9,
columns: <DataColumn>[
DataColumn(label: Text("Name")),
DataColumn(label: Text("Color")),
DataColumn(label: Text("Edit")),
],
rows: tagGroups
.sublist(offset, offset + rows)
.map((TagGroup tagGroup) {
return DataRow(
key: Key(tagGroup.db.id.toString()),
cells: [
DataCell(Text(tagGroup.db.name)),
DataCell(CircleColor(
circleSize: 20,
elevation: 0,
color: Color(tagGroup.db.color),
)),
DataCell(
MyIcon.edit,
onTap: () async {
await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => AddTagGroupScreen(
tagGroup: tagGroup,
),
),
);
getData();
},
)
],
);
}).toList(),
),
SizedBox(height: 20),
Row(
children: <Widget>[
Spacer(),
MyButton.add(
child: Text("New tag group"),
onPressed: () async {
await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => AddTagGroupScreen(
tagGroup: TagGroup(athlete: widget.athlete),
),
),
);
getData();
}),
Spacer(),
MyButton.navigate(
child: Text("<<"),
onPressed: (offset == 0)
? null
: () => setState(() {
offset > 8 ? offset = offset - rows : offset = 0;
}),
),
Spacer(),
MyButton.navigate(
child: Text(">>"),
onPressed: (offset + rows == tagGroups.length)
? null
: () => setState(() {
offset + rows < tagGroups.length - rows
? offset = offset + rows
: offset = tagGroups.length - rows;
}),
),
Spacer(),
],
),
],
);
} else {
createDefaultTagGroups();
return Center(
child: Text("creating defaults ..."),
);
}
} else {
return Center(
child: Text("loading"),
);
}
}
getData() async {
Athlete athlete = widget.athlete;
tagGroups = await athlete.tagGroups;
setState(() {});
}
createDefaultTagGroups() async {
await TagGroup.createDefaultTagGroups(athlete: widget.athlete);
await getData();
setState(() {});
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment