Related Project added to TaskType
This commit is contained in:
@@ -25,16 +25,18 @@ class Category{
|
|||||||
|
|
||||||
class TaskType{
|
class TaskType{
|
||||||
|
|
||||||
TaskType(this.id, this.name, this.category, [this.cat = null]);
|
TaskType(this.id, this.name, this.category,{this.relatedProject, this.cat});
|
||||||
|
|
||||||
String id;
|
String id;
|
||||||
String name;
|
String name;
|
||||||
String category;
|
String category;
|
||||||
Category? cat;
|
Category? cat;
|
||||||
|
Project? relatedProject;
|
||||||
|
|
||||||
static String colId = "id";
|
static String colId = "id";
|
||||||
static String colName="name";
|
static String colName="name";
|
||||||
static String colCategory = "category_id";
|
static String colCategory = "category_id";
|
||||||
|
static String colRelatedProject = "related_project";
|
||||||
}
|
}
|
||||||
|
|
||||||
class Activity{
|
class Activity{
|
||||||
@@ -108,6 +110,7 @@ class Project{
|
|||||||
Project(this.name, this.category, this.steps,this.eta, this.deadline,{this.cat});
|
Project(this.name, this.category, this.steps,this.eta, this.deadline,{this.cat});
|
||||||
|
|
||||||
String name;
|
String name;
|
||||||
|
String getName()=> name.replaceAll(User.username, "");
|
||||||
String category;
|
String category;
|
||||||
Category? cat;
|
Category? cat;
|
||||||
List<ProjectStep> steps;
|
List<ProjectStep> steps;
|
||||||
|
|||||||
@@ -151,7 +151,9 @@ class Dialogs{
|
|||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: stepWidgets,
|
children: stepWidgets,
|
||||||
)
|
),
|
||||||
|
SizedBox(height: 30,),
|
||||||
|
Text("Estimate Time : ${project.eta}")
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
|
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:tasktracker/NewCategory.dart';
|
import 'package:tasktracker/NewCategory.dart';
|
||||||
|
import 'package:tasktracker/NewProject.dart';
|
||||||
import 'User.dart' as User;
|
import 'User.dart' as User;
|
||||||
|
|
||||||
DateFormat dateFormat = DateFormat("yyyy-MM-dd HH:mm:ss");
|
DateFormat dateFormat = DateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
@@ -24,7 +25,19 @@ List<String> getCategoryNames(){
|
|||||||
return _cats;
|
return _cats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<String> getProjectNames(){
|
||||||
|
List<String> _projects = [];
|
||||||
|
_projects.add("None");
|
||||||
|
_projects.add('+Add New Project');
|
||||||
|
User.projects.forEach((element) {
|
||||||
|
String name = element.getName();
|
||||||
|
_projects.add(name);
|
||||||
|
});
|
||||||
|
return _projects;
|
||||||
|
}
|
||||||
|
|
||||||
String selectedCat = User.categories[0].name;
|
String selectedCat = User.categories[0].name;
|
||||||
|
String selectedProj = "None";
|
||||||
class _NewTaskState extends State<NewTask> {
|
class _NewTaskState extends State<NewTask> {
|
||||||
TextEditingController nameController = TextEditingController();
|
TextEditingController nameController = TextEditingController();
|
||||||
bool productive = true;
|
bool productive = true;
|
||||||
@@ -96,6 +109,48 @@ class _NewTaskState extends State<NewTask> {
|
|||||||
}
|
}
|
||||||
setState(() {
|
setState(() {
|
||||||
|
|
||||||
|
});
|
||||||
|
})),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(0, 20, 0, 10),
|
||||||
|
child: Text('Related Project'),
|
||||||
|
),
|
||||||
|
Container(
|
||||||
|
padding: EdgeInsets.symmetric(
|
||||||
|
horizontal: 12, vertical: 1),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.blueGrey,
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
border: Border.all(
|
||||||
|
color: Colors.grey, width: 2)),
|
||||||
|
child: DropdownButton<String>(
|
||||||
|
dropdownColor: Colors.blueGrey,
|
||||||
|
iconSize: 30,
|
||||||
|
elevation: 10,
|
||||||
|
borderRadius: BorderRadius.circular(10),
|
||||||
|
value: selectedProj,
|
||||||
|
isExpanded: true,
|
||||||
|
items: getProjectNames().map<DropdownMenuItem<String>>(
|
||||||
|
(String value) {
|
||||||
|
|
||||||
|
return DropdownMenuItem<String>(
|
||||||
|
value: value,
|
||||||
|
child: Text(value),
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
onChanged: (String? _value) {
|
||||||
|
if(_value != null) {
|
||||||
|
if (_value.contains("+Add New Project")) {
|
||||||
|
Navigator.of(context).push(MaterialPageRoute(builder: (context)=>NewProject()));
|
||||||
|
}else{
|
||||||
|
selectedProj = _value!;
|
||||||
|
if(_value.contains("None")){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setState(() {
|
||||||
|
|
||||||
});
|
});
|
||||||
})),
|
})),
|
||||||
Container(
|
Container(
|
||||||
@@ -157,7 +212,7 @@ class _NewTaskState extends State<NewTask> {
|
|||||||
showAlertDialog(context, 'Category needs a name', 'Please enter a name for this category');
|
showAlertDialog(context, 'Category needs a name', 'Please enter a name for this category');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await User.UserOperations.addTaskType(catName,selectedCat);
|
await User.UserOperations.addTaskType(catName,selectedCat,relatedProject: (selectedProj == 'None') ? '' : selectedProj);
|
||||||
Navigator.of(context).popUntil((route){
|
Navigator.of(context).popUntil((route){
|
||||||
return route.isFirst;
|
return route.isFirst;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -31,13 +31,20 @@ class _ProjectsState extends State<Projects> {
|
|||||||
super.dispose();
|
super.dispose();
|
||||||
refreshSub?.close();
|
refreshSub?.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void refresh(){
|
||||||
|
setState(() {
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
int selectedPage = 0;
|
int selectedPage = 0;
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return SafeArea(child: Scaffold(
|
return SafeArea(child: Scaffold(
|
||||||
floatingActionButton: FloatingActionButton.extended(
|
floatingActionButton: FloatingActionButton.extended(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.of(context).push(MaterialPageRoute(builder: (context) => NewProject())).then((value) => {User.refreshUserData().then((va) => {})});
|
Navigator.of(context).push(MaterialPageRoute(builder: (context) => NewProject())).then((value) => {User.refreshUserData().then((va) => {refresh()})});
|
||||||
},
|
},
|
||||||
label: Text("New Project"),
|
label: Text("New Project"),
|
||||||
icon: Icon(Icons.add)),
|
icon: Icon(Icons.add)),
|
||||||
@@ -69,7 +76,9 @@ class _ProjectsState extends State<Projects> {
|
|||||||
? Icon(Icons.signal_cellular_connected_no_internet_4_bar_outlined)
|
? Icon(Icons.signal_cellular_connected_no_internet_4_bar_outlined)
|
||||||
: InkWell(
|
: InkWell(
|
||||||
onTap: () async{
|
onTap: () async{
|
||||||
await User.refreshUserData();
|
User.refreshUserData().then((val){setState(() {
|
||||||
|
|
||||||
|
});});
|
||||||
setState(() {
|
setState(() {
|
||||||
//LoadStats();
|
//LoadStats();
|
||||||
|
|
||||||
@@ -86,11 +95,19 @@ class _ProjectsState extends State<Projects> {
|
|||||||
)),
|
)),
|
||||||
drawer: navDrawer(context, 7),
|
drawer: navDrawer(context, 7),
|
||||||
body: (selectedPage == 0) ?
|
body: (selectedPage == 0) ?
|
||||||
Container(child:Text('Summary goes here'))
|
Container(child: Column(
|
||||||
|
children: [
|
||||||
|
|
||||||
|
],
|
||||||
|
))
|
||||||
:Container(
|
:Container(
|
||||||
padding: EdgeInsets.all(10),
|
padding: EdgeInsets.all(10),
|
||||||
child: Column(
|
child: Column(
|
||||||
children: printProjects(),
|
children: [
|
||||||
|
Column(
|
||||||
|
children: printProjects(),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
@@ -98,8 +115,9 @@ class _ProjectsState extends State<Projects> {
|
|||||||
|
|
||||||
List<Widget> printProjects(){
|
List<Widget> printProjects(){
|
||||||
List<Widget> projectWidgets = [];
|
List<Widget> projectWidgets = [];
|
||||||
|
print(User.projects.length);
|
||||||
for (var element in User.projects) {
|
for (var element in User.projects) {
|
||||||
|
print(element.name);
|
||||||
if(element.cat==null){print(element.name + " has no cat");continue;}
|
if(element.cat==null){print(element.name + " has no cat");continue;}
|
||||||
projectWidgets.add(ProjectCard(element));
|
projectWidgets.add(ProjectCard(element));
|
||||||
}
|
}
|
||||||
@@ -146,7 +164,7 @@ class _ProjectsState extends State<Projects> {
|
|||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
Text("${project.steps.length} steps"),
|
(project.steps.length > 0) ? Text("${project.steps.length} steps") : Container(),
|
||||||
Container(
|
Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.redAccent,
|
color: Colors.redAccent,
|
||||||
|
|||||||
136
lib/Tasks.dart
136
lib/Tasks.dart
@@ -10,31 +10,33 @@ class Tasks extends StatefulWidget {
|
|||||||
@override
|
@override
|
||||||
_TasksState createState() => _TasksState();
|
_TasksState createState() => _TasksState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _TasksState extends State<Tasks> {
|
class _TasksState extends State<Tasks> {
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
// TODO: implement initState
|
// TODO: implement initState
|
||||||
super.initState();
|
super.initState();
|
||||||
// UpdateList();
|
// UpdateList();
|
||||||
// init(context);
|
// init(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
var refreshSub;
|
var refreshSub;
|
||||||
void init(BuildContext context) async{
|
void init(BuildContext context) async {
|
||||||
await Future.delayed(Duration(seconds: 1));
|
await Future.delayed(Duration(seconds: 1));
|
||||||
refreshSub = User.refreshStream.stream.listen((value) {
|
refreshSub = User.refreshStream.stream.listen((value) {
|
||||||
print("Streaming refresh : $value");
|
print("Streaming refresh : $value");
|
||||||
if(value){
|
if (value) {
|
||||||
// dialogs.waiting(context, "Syncing");
|
// dialogs.waiting(context, "Syncing");
|
||||||
print("Opening progress dialog");
|
print("Opening progress dialog");
|
||||||
}else{
|
} else {
|
||||||
// dialogs.hide(context);
|
// dialogs.hide(context);
|
||||||
print("Closing progress dialog");
|
print("Closing progress dialog");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@override void dispose() {
|
@override
|
||||||
|
void dispose() {
|
||||||
// TODO: implement dispose
|
// TODO: implement dispose
|
||||||
super.dispose();
|
super.dispose();
|
||||||
refreshSub?.cancel();
|
refreshSub?.cancel();
|
||||||
@@ -43,34 +45,41 @@ class _TasksState extends State<Tasks> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
|
|
||||||
floatingActionButton: FloatingActionButton.extended(
|
floatingActionButton: FloatingActionButton.extended(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.of(context)
|
Navigator.of(context).push(MaterialPageRoute(builder: (context) => NewTask())).then((value) => UpdateList());
|
||||||
.push(MaterialPageRoute(builder: (context) => NewTask()))
|
|
||||||
.then((value) => UpdateList());
|
|
||||||
},
|
},
|
||||||
label: Text("New Task Type"),
|
label: Text("New Task Type"),
|
||||||
icon: Icon(Icons.add)),
|
icon: Icon(Icons.add)),
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Row(
|
title: Row(
|
||||||
mainAxisSize: MainAxisSize.max,
|
mainAxisSize: MainAxisSize.max,
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
Row(children: [
|
Row(children: [Icon(Icons.task, color: Theme.of(context).primaryColor), SizedBox(width: 10), Text('Task Types')]),
|
||||||
Icon(Icons.task, color: Theme.of(context).primaryColor),
|
(selecting)
|
||||||
SizedBox(width: 10),
|
? Row(children: [
|
||||||
Text('Task Types')
|
InkWell(
|
||||||
]),
|
onTap: () {
|
||||||
(selecting)?Row(children: [
|
DeleteSelectedTasks();
|
||||||
InkWell(onTap: (){
|
},
|
||||||
DeleteSelectedTasks();
|
child: Icon(
|
||||||
}, child: Icon(Icons.delete,size: 30,)),
|
Icons.delete,
|
||||||
SizedBox(width: 20,),
|
size: 30,
|
||||||
InkWell(onTap: (){setState(() {
|
)),
|
||||||
selecting=false;
|
SizedBox(
|
||||||
});}, child: Icon(Icons.close,size: 30),)
|
width: 20,
|
||||||
]) : Container(),
|
),
|
||||||
|
InkWell(
|
||||||
|
onTap: () {
|
||||||
|
setState(() {
|
||||||
|
selecting = false;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
child: Icon(Icons.close, size: 30),
|
||||||
|
)
|
||||||
|
])
|
||||||
|
: Container(),
|
||||||
],
|
],
|
||||||
)),
|
)),
|
||||||
drawer: navDrawer(context, 3),
|
drawer: navDrawer(context, 3),
|
||||||
@@ -83,13 +92,12 @@ class _TasksState extends State<Tasks> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void UpdateList() async {
|
void UpdateList() async {
|
||||||
|
// try{progressDialog.show(max:100, msg: 'Loading Task Types...');}catch(e){}
|
||||||
// try{progressDialog.show(max:100, msg: 'Loading Task Types...');}catch(e){}
|
|
||||||
await User.refreshUserData();
|
await User.refreshUserData();
|
||||||
// hideProgressDialog();
|
// hideProgressDialog();
|
||||||
if(mounted)setState(() {});
|
if (mounted) setState(() {});
|
||||||
|
|
||||||
// try{progressDialog.update(value: 100);}catch(e){}
|
// try{progressDialog.update(value: 100);}catch(e){}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Widget> PrintTasks() {
|
List<Widget> PrintTasks() {
|
||||||
@@ -102,7 +110,8 @@ class _TasksState extends State<Tasks> {
|
|||||||
} else {
|
} else {
|
||||||
Color color = HexColor.fromHex(element.cat?.color ?? '#000000');
|
Color color = HexColor.fromHex(element.cat?.color ?? '#000000');
|
||||||
bool productive = element.cat?.productive ?? true;
|
bool productive = element.cat?.productive ?? true;
|
||||||
Widget task = TaskCard(context, name, productive, color, element.cat?.name ?? 'n/a');
|
Widget task = TaskCard(
|
||||||
|
context, name, productive, color, element.cat?.name ?? 'n/a', (element.relatedProject != null) ? element.relatedProject!.getName() : '');
|
||||||
_tasks.add(task);
|
_tasks.add(task);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -111,8 +120,7 @@ class _TasksState extends State<Tasks> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool selecting = false;
|
bool selecting = false;
|
||||||
Widget TaskCard(
|
Widget TaskCard(BuildContext context, String name, bool productive, Color color, String catName, String relatedProjects) {
|
||||||
BuildContext context, String name, bool productive, Color color, String catName) {
|
|
||||||
return Row(children: [
|
return Row(children: [
|
||||||
// Container(),
|
// Container(),
|
||||||
(selecting)
|
(selecting)
|
||||||
@@ -129,57 +137,58 @@ class _TasksState extends State<Tasks> {
|
|||||||
Card(
|
Card(
|
||||||
|
|
||||||
// color: color,
|
// color: color,
|
||||||
elevation:20,
|
elevation: 20,
|
||||||
shadowColor: color,
|
shadowColor: color,
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
//Open Respective Category
|
//Open Respective Category
|
||||||
if(selecting){
|
if (selecting) {
|
||||||
OnItemSelected(name);
|
OnItemSelected(name);
|
||||||
}
|
}
|
||||||
setState(() {
|
setState(() {});
|
||||||
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
onLongPress: () {
|
onLongPress: () {
|
||||||
print('gonna delete');
|
print('gonna delete');
|
||||||
selecting = !selecting;
|
selecting = !selecting;
|
||||||
selectedTasks = [name];
|
selectedTasks = [name];
|
||||||
setState(() {});
|
setState(() {});
|
||||||
|
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
padding: EdgeInsets.all(10),
|
padding: EdgeInsets.all(10),
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
Row(
|
Row(mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
|
||||||
mainAxisSize: MainAxisSize.max,
|
Text(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
name,
|
||||||
|
),
|
||||||
|
// Icon(Icons.analytics, color: color, size: 20,),
|
||||||
|
Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
Text(name,
|
(relatedProjects.isNotEmpty)
|
||||||
),
|
? Container(
|
||||||
// Icon(Icons.analytics, color: color, size: 20,),
|
padding: EdgeInsets.symmetric(horizontal: 10),
|
||||||
|
decoration:
|
||||||
|
BoxDecoration(borderRadius: BorderRadius.circular(10), color: Colors.black26),
|
||||||
|
child: Text(relatedProjects))
|
||||||
|
: Container(),
|
||||||
Container(
|
Container(
|
||||||
padding: EdgeInsets.symmetric(horizontal: 10),
|
padding: EdgeInsets.symmetric(horizontal: 10),
|
||||||
decoration: BoxDecoration(
|
decoration:
|
||||||
borderRadius: BorderRadius.circular(10),
|
BoxDecoration(borderRadius: BorderRadius.circular(10), color: (productive) ? Colors.green : Colors.red),
|
||||||
color: (productive) ? Colors.green : Colors.red
|
child: Text(catName)),
|
||||||
),
|
],
|
||||||
child:Text(catName)
|
)
|
||||||
)
|
]),
|
||||||
]),
|
|
||||||
],
|
],
|
||||||
)))),
|
)))),
|
||||||
Container(
|
Container(margin: EdgeInsets.fromLTRB(15, 0, 15, 10), height: 2, color: color)
|
||||||
margin: EdgeInsets.fromLTRB(15, 0, 15, 10),
|
|
||||||
height: 2,
|
|
||||||
color: color)
|
|
||||||
]),
|
]),
|
||||||
),
|
),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnItemSelected(String name){
|
void OnItemSelected(String name) {
|
||||||
if (!selectedTasks.contains(name)) {
|
if (!selectedTasks.contains(name)) {
|
||||||
selectedTasks.add(name);
|
selectedTasks.add(name);
|
||||||
} else {
|
} else {
|
||||||
@@ -187,20 +196,17 @@ class _TasksState extends State<Tasks> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeleteSelectedTasks() async{
|
void DeleteSelectedTasks() async {
|
||||||
selectedTasks.forEach((element) async {
|
selectedTasks.forEach((element) async {
|
||||||
await User.UserOperations.deleteTask(element, bulk:true);
|
await User.UserOperations.deleteTask(element, bulk: true);
|
||||||
});
|
});
|
||||||
|
|
||||||
await Future.delayed(Duration(seconds: 2));
|
await Future.delayed(Duration(seconds: 2));
|
||||||
await User.UserOperations.executeQueries();
|
await User.UserOperations.executeQueries();
|
||||||
selectedTasks=[];
|
selectedTasks = [];
|
||||||
selecting=false;
|
selecting = false;
|
||||||
setState(() {
|
setState(() {});
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> selectedTasks = [];
|
List<String> selectedTasks = [];
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ void onCacheDatabaseCreate(Database db, int newVersion) async {
|
|||||||
await db.execute(CategoriesTableSQL);
|
await db.execute(CategoriesTableSQL);
|
||||||
print("Initiated Categories Table");
|
print("Initiated Categories Table");
|
||||||
|
|
||||||
String TaskTableSQL = 'CREATE TABLE TaskTypes(id TEXT PRIMARY KEY, ${TaskType.colName} TEXT, ${TaskType.colCategory} TEXT, '
|
String TaskTableSQL = 'CREATE TABLE TaskTypes(id TEXT PRIMARY KEY, ${TaskType.colName} TEXT, ${TaskType.colCategory} TEXT, ${TaskType.colRelatedProject} TEXT, '
|
||||||
'FOREIGN KEY (${TaskType.colCategory}) REFERENCES Categories(${Category.colCatId}))';
|
'FOREIGN KEY (${TaskType.colCategory}) REFERENCES Categories(${Category.colCatId}))';
|
||||||
// print(TaskTableSQL);
|
// print(TaskTableSQL);
|
||||||
await db.execute(TaskTableSQL);
|
await db.execute(TaskTableSQL);
|
||||||
@@ -376,14 +376,21 @@ Future<List<TaskType>> GetTaskTypes(bool forceOffline) async {
|
|||||||
String? id = element[TaskType.colId].toString();
|
String? id = element[TaskType.colId].toString();
|
||||||
String? name = element[TaskType.colName].toString();
|
String? name = element[TaskType.colName].toString();
|
||||||
String? category = element[TaskType.colCategory].toString();
|
String? category = element[TaskType.colCategory].toString();
|
||||||
|
String? related_project = element[TaskType.colRelatedProject].toString();
|
||||||
Category? cat = await getCatFromId(category);
|
Category? cat = await getCatFromId(category);
|
||||||
if (id == null || name == null || category == null) {
|
if (id == null || name == null || category == null) {
|
||||||
print("Something is null!");
|
print("Something is null!");
|
||||||
print("name:{$name}, cat:{$category}, prod:{$id}");
|
print("name:{$name}, cat:{$category}, prod:{$id}");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
Project? relatedProject;
|
||||||
|
if(related_project.isNotEmpty){
|
||||||
|
relatedProject = await getProjectFromId(related_project);
|
||||||
|
print('got a tasktype with project');
|
||||||
|
}
|
||||||
|
|
||||||
// print("name:{$name}, cat:{$category}, prod:{$id}");
|
// print("name:{$name}, cat:{$category}, prod:{$id}");
|
||||||
_taskTypes.add(TaskType(id, name, category, cat));
|
_taskTypes.add(TaskType(id, name, category, cat:cat, relatedProject: relatedProject));
|
||||||
}
|
}
|
||||||
taskTypes = _taskTypes;
|
taskTypes = _taskTypes;
|
||||||
} else {
|
} else {
|
||||||
@@ -399,7 +406,7 @@ Future<List<TaskType>> GetTaskTypes(bool forceOffline) async {
|
|||||||
for (var value in data) {
|
for (var value in data) {
|
||||||
Map<String, dynamic> data = jsonDecode(value);
|
Map<String, dynamic> data = jsonDecode(value);
|
||||||
Category? cat = await getCatFromId(data['category_id']);
|
Category? cat = await getCatFromId(data['category_id']);
|
||||||
_taskTypes.add(TaskType(data['task_id'], data['name'], data['category_id'], cat));
|
_taskTypes.add(TaskType(data['task_id'], data['name'], data['category_id'], cat:cat,relatedProject: data['related_project']));
|
||||||
//print(cat);
|
//print(cat);
|
||||||
}
|
}
|
||||||
}catch(e){
|
}catch(e){
|
||||||
@@ -424,8 +431,8 @@ Future<void> UpdateTaskTypesFromServer() async {
|
|||||||
for (var value in data) {
|
for (var value in data) {
|
||||||
Map<String, dynamic> cat = jsonDecode(value);
|
Map<String, dynamic> cat = jsonDecode(value);
|
||||||
//print(cat);
|
//print(cat);
|
||||||
await cacheDb.rawInsert("INSERT OR REPLACE INTO TaskTypes (${TaskType.colId},${TaskType.colName},${TaskType.colCategory}) "
|
await cacheDb.rawInsert("INSERT OR REPLACE INTO TaskTypes (${TaskType.colId},${TaskType.colName},${TaskType.colCategory},${TaskType.colRelatedProject}) "
|
||||||
"VALUES ('${cat['task_id']}','${cat['name']}','${cat['category_id']}') ");
|
"VALUES ('${cat['task_id']}','${cat['name']}','${cat['category_id']}', '${cat['related_project']}') ");
|
||||||
|
|
||||||
print(await cacheDb.query("TaskTypes"));
|
print(await cacheDb.query("TaskTypes"));
|
||||||
}
|
}
|
||||||
@@ -648,8 +655,10 @@ Future<List<Project>> GetProjects(bool forceOffline) async {
|
|||||||
String? category = element[Project.colCat];
|
String? category = element[Project.colCat];
|
||||||
String? stepsJson = element[Project.colSteps];
|
String? stepsJson = element[Project.colSteps];
|
||||||
String? deadline = element[Project.colDeadline];
|
String? deadline = element[Project.colDeadline];
|
||||||
|
int? eta= element[Project.colEta];
|
||||||
|
|
||||||
if (name == null || category == null || stepsJson == null || deadline == null) {
|
|
||||||
|
if (name == null || category == null || stepsJson == null || deadline == null || eta==null) {
|
||||||
print("Something is null!\nname:${name == null}, cat:${category == null}, steps:${stepsJson == null}, deadline${deadline == null}");
|
print("Something is null!\nname:${name == null}, cat:${category == null}, steps:${stepsJson == null}, deadline${deadline == null}");
|
||||||
print("TaskType:{$name}, Start Time:{$category}, endTime:{$stepsJson}, metadata:${deadline}");
|
print("TaskType:{$name}, Start Time:{$category}, endTime:{$stepsJson}, metadata:${deadline}");
|
||||||
continue;
|
continue;
|
||||||
@@ -659,13 +668,14 @@ Future<List<Project>> GetProjects(bool forceOffline) async {
|
|||||||
print('steps : $stepsJson');
|
print('steps : $stepsJson');
|
||||||
List<dynamic> _steps = jsonDecode(stepsJson);
|
List<dynamic> _steps = jsonDecode(stepsJson);
|
||||||
List<ProjectStep> steps = [];
|
List<ProjectStep> steps = [];
|
||||||
int eta = 0;
|
int m_eta = 0;
|
||||||
_steps.forEach((element) {
|
_steps.forEach((element) {
|
||||||
ProjectStep step = ProjectStep.fromJson(element);
|
ProjectStep step = ProjectStep.fromJson(element);
|
||||||
eta+=step.eta;
|
m_eta += step.eta;
|
||||||
steps.add(step);
|
steps.add(step);
|
||||||
print(element);
|
print(element);
|
||||||
});
|
});
|
||||||
|
eta = (m_eta > 0) ? m_eta : eta;
|
||||||
// print(steps);
|
// print(steps);
|
||||||
|
|
||||||
_projects.add(Project(name.replaceAll(username, ""),category,steps,eta,DateTime.parse(deadline),cat: cat));
|
_projects.add(Project(name.replaceAll(username, ""),category,steps,eta,DateTime.parse(deadline),cat: cat));
|
||||||
@@ -728,8 +738,8 @@ Future<void> UpdateProjectsFromServer() async {
|
|||||||
print('project data');
|
print('project data');
|
||||||
print(cat);
|
print(cat);
|
||||||
await cacheDb.rawInsert(
|
await cacheDb.rawInsert(
|
||||||
"INSERT OR REPLACE INTO Projects (${Project.colName}, ${Project.colCat}, ${Project.colSteps}, ${Project.colDeadline}) "
|
"INSERT OR REPLACE INTO Projects (${Project.colName}, ${Project.colCat}, ${Project.colSteps}, ${Project.colDeadline}, ${Project.colEta}) "
|
||||||
"VALUES ('${cat['name']}', '${cat['category']}', '${cat['steps']}', '${cat['deadline']}')");
|
"VALUES ('${cat['name']}', '${cat['category']}', '${cat['steps']}', '${cat['deadline']}', ${cat['eta']})");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
print("No activities for now");
|
print("No activities for now");
|
||||||
@@ -768,6 +778,21 @@ Future<Category?> getCatFromId(String catId) async {
|
|||||||
return cat;
|
return cat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<Project?> getProjectFromId(String projectId) async {
|
||||||
|
// await GetTaskTypes(false);
|
||||||
|
Project? project = null;
|
||||||
|
for (var element in projects) {
|
||||||
|
if (element.getName() ==projectId.replaceAll(username, "")) {
|
||||||
|
project = element;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (project == null) {
|
||||||
|
print('Got null project for ${projectId} after searching on ${projects.length}');
|
||||||
|
}
|
||||||
|
|
||||||
|
return project;
|
||||||
|
}
|
||||||
|
|
||||||
//Helpers
|
//Helpers
|
||||||
class Helpers {
|
class Helpers {
|
||||||
Future<String?> _getId() async {
|
Future<String?> _getId() async {
|
||||||
@@ -833,13 +858,14 @@ class UserOperations {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<void> addTaskType(String name, String category, {bool bulk = false}) async {
|
static Future<void> addTaskType(String name, String category, {bool bulk = false, String? relatedProject = null}) async {
|
||||||
Map<String, String> queryBody = <String, String>{
|
Map<String, String> queryBody = <String, String>{
|
||||||
'id': username + name,
|
'id': username + name,
|
||||||
'username': username,
|
'username': username,
|
||||||
'device_id': await Settings.UUID(),
|
'device_id': await Settings.UUID(),
|
||||||
'name': name,
|
'name': name,
|
||||||
'category': username + category
|
'category': username + category,
|
||||||
|
'related_project' :(relatedProject==null) ? '' : (username + relatedProject)
|
||||||
};
|
};
|
||||||
|
|
||||||
if (cacheEnabled) {
|
if (cacheEnabled) {
|
||||||
@@ -851,7 +877,8 @@ class UserOperations {
|
|||||||
await cacheDb.insert('Queries', query);
|
await cacheDb.insert('Queries', query);
|
||||||
|
|
||||||
//update Cache
|
//update Cache
|
||||||
Map<String, Object> data = {TaskType.colId: username + name, Category.colName: name, Category.colCatId: username + category};
|
Map<String, Object> data = {TaskType.colId: username + name, Category.colName: name, Category.colCatId: username + category,};
|
||||||
|
if(relatedProject!=null || relatedProject =='None'){data.putIfAbsent(TaskType.colRelatedProject, () => relatedProject.toString());}
|
||||||
await cacheDb.insert('TaskTypes', data);
|
await cacheDb.insert('TaskTypes', data);
|
||||||
await refreshUserData(forceOffline: true);
|
await refreshUserData(forceOffline: true);
|
||||||
} else {
|
} else {
|
||||||
@@ -1057,7 +1084,7 @@ class UserOperations {
|
|||||||
await cacheDb.insert('Queries', query);
|
await cacheDb.insert('Queries', query);
|
||||||
|
|
||||||
//update Cache
|
//update Cache
|
||||||
Map<String, Object> data = {Project.colName: username+name, Project.colCat: category, Project.colSteps: jsonEncode(steps), Project.colDeadline: deadline.toString()};
|
Map<String, Object> data = {Project.colName: username+name, Project.colCat: category, Project.colSteps: jsonEncode(steps),Project.colEta: eta, Project.colDeadline: deadline.toString()};
|
||||||
await cacheDb.insert('Projects', data);
|
await cacheDb.insert('Projects', data);
|
||||||
await refreshUserData(forceOffline: true);
|
await refreshUserData(forceOffline: true);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user