2.0.1
Co-authored-by: Richard Pavlikán <richardpavlikan@gmail.com>
This commit is contained in:
parent
95b26b4063
commit
f7eaf804bd
32 changed files with 4664 additions and 1487 deletions
152
lib/utils/csv.dart
Normal file
152
lib/utils/csv.dart
Normal file
|
@ -0,0 +1,152 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:csv/csv.dart';
|
||||
import 'package:denikprogramatora/utils/datum_cas.dart';
|
||||
import 'package:denikprogramatora/utils/loading_widget.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
|
||||
final csvHeader = "id,date,time_spent,language,rating,description".split(",");
|
||||
|
||||
Future<int> importCsv(String name) async {
|
||||
FilePickerResult? result = await FilePicker.platform.pickFiles(
|
||||
dialogTitle: "Vyberte CSV soubor s databází",
|
||||
type: FileType.custom,
|
||||
allowedExtensions: ['csv']);
|
||||
if (result == null) return -1;
|
||||
var content = const CsvToListConverter(eol: "\n").convert(
|
||||
String.fromCharCodes(
|
||||
result.files.first.bytes!)); // načíst a rozdělit na řádky
|
||||
|
||||
// Zkontrolovat počet sloupců
|
||||
if (content.first.length != csvHeader.length) {
|
||||
throw "CSV soubor není v platném formátu: neplatný počet sloupců";
|
||||
}
|
||||
|
||||
Map<String, List<dynamic>> csv = {};
|
||||
var nazvySloupcu = [];
|
||||
for (var radek in content) {
|
||||
if (nazvySloupcu.isEmpty) {
|
||||
// získat názvy sloupců
|
||||
nazvySloupcu = radek;
|
||||
if (nazvySloupcu.any((element) => !csvHeader.contains(element))) {
|
||||
throw "CSV soubor není v platném formátu: neznámý název sloupce";
|
||||
}
|
||||
for (var nazevSloupce in nazvySloupcu) {
|
||||
csv[nazevSloupce] = [];
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (radek.length != nazvySloupcu.length) continue;
|
||||
|
||||
// zkontrolovat, že máme všechny potřebné údaje v řádku
|
||||
var j = 0;
|
||||
var neplatny = false;
|
||||
for (var sloupec in radek) {
|
||||
if ((nazvySloupcu[j] != "description") && sloupec == "") {
|
||||
neplatny = true;
|
||||
break;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
if (neplatny) continue;
|
||||
|
||||
// přiřadit hodnotu sloupce do mapy
|
||||
var i = 0;
|
||||
for (var sloupec in radek) {
|
||||
csv[nazvySloupcu[i]]!.add(sloupec);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
var userDoc = await FirebaseFirestore.instance
|
||||
.collection("users/${FirebaseAuth.instance.currentUser!.uid}/records")
|
||||
.get();
|
||||
var p = 0;
|
||||
var pouzitaId = <String>[];
|
||||
for (var i = 0; i < csv[nazvySloupcu[0]]!.length; i++) {
|
||||
var id = csv[nazvySloupcu[nazvySloupcu.indexOf("id")]]![i];
|
||||
if (pouzitaId.contains(id)) continue;
|
||||
pouzitaId.add(id);
|
||||
if (userDoc.docs.any((element) => element.id == id)) {
|
||||
continue;
|
||||
} // přeskočit dokumenty se stejným ID
|
||||
|
||||
var date = csv[nazvySloupcu[nazvySloupcu.indexOf("date")]]![i].split("-");
|
||||
|
||||
var timeToSec = textToSec(
|
||||
csv[nazvySloupcu[nazvySloupcu.indexOf("time_spent")]]![i] as String);
|
||||
if (timeToSec == null) continue;
|
||||
var timeSpent = Duration(seconds: timeToSec);
|
||||
|
||||
var lang = csv[nazvySloupcu[nazvySloupcu.indexOf("language")]]![i];
|
||||
Map<String, dynamic> jazyk = {};
|
||||
if (jazyky.any((element) => element["jazyk"] == lang)) {
|
||||
jazyk = jazyky.where((element) => element["jazyk"] == lang).toList()[0];
|
||||
} else {
|
||||
jazyk = {"jazyk": lang, "barva": 0xffffffff};
|
||||
}
|
||||
|
||||
var rating = csv[nazvySloupcu[nazvySloupcu.indexOf("rating")]]![i];
|
||||
if (rating > 5 || rating < 0) rating = 0;
|
||||
|
||||
var desc = csv[nazvySloupcu[nazvySloupcu.indexOf("description")]]![i];
|
||||
DateTime? d;
|
||||
try {
|
||||
d = DateTime.parse(
|
||||
"${date[2]}-${int.parse(date[1]) < 10 ? '0${date[1]}' : date[1]}-${int.parse(date[0]) < 10 ? "0${date[0]}" : date[0]}");
|
||||
} catch (e) {
|
||||
continue;
|
||||
}
|
||||
|
||||
await FirebaseFirestore.instance
|
||||
.collection("users/${FirebaseAuth.instance.currentUser!.uid}/records")
|
||||
.doc(id)
|
||||
.set({
|
||||
"date": d,
|
||||
"time_spent": timeSpent.durationText,
|
||||
"time_spentRaw": timeSpent.inSeconds,
|
||||
"programming_language": jazyk,
|
||||
"rating": rating,
|
||||
"descriptionRaw": desc,
|
||||
"description": null,
|
||||
"programmer": FirebaseAuth.instance.currentUser!.uid,
|
||||
"categories": []
|
||||
});
|
||||
p++;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
Future<List<int>> exportCsv() async {
|
||||
List<List<dynamic>> csv = [csvHeader];
|
||||
var records = await FirebaseFirestore.instance
|
||||
.collection("users/${FirebaseAuth.instance.currentUser!.uid}/records")
|
||||
.get();
|
||||
for (var rec in records.docs) {
|
||||
var data = rec.data();
|
||||
csv.add([
|
||||
rec.id,
|
||||
(data['date'] as Timestamp).toDate().rawDateString,
|
||||
Duration(seconds: data['time_spentRaw']).durationText,
|
||||
data['programming_language']['jazyk'],
|
||||
data['rating'],
|
||||
data['descriptionRaw']
|
||||
]);
|
||||
}
|
||||
return utf8.encode(const ListToCsvConverter(eol: "\n").convert(csv));
|
||||
}
|
||||
|
||||
/// Převede `40 hodin 50 minut` na sekundy
|
||||
int? textToSec(String vstup) {
|
||||
var match =
|
||||
RegExp(r'(\d+) hodin(?: |y |a )(\d+) minut(?:$|a$|y$)').firstMatch(vstup);
|
||||
if (match == null) return null;
|
||||
print(match.group(1));
|
||||
print(match.group(2));
|
||||
var h = int.tryParse(match.group(1)!);
|
||||
var m = int.tryParse(match.group(2)!);
|
||||
if (h == null || m == null) return null;
|
||||
return h * 3600 + m * 60;
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
extension DateString on DateTime {
|
||||
String get dateString => "$day. $month. $year";
|
||||
String get dateTimeString =>
|
||||
"$day. $month. $year $hour:${minute < 10 ? "0$minute" : minute}";
|
||||
}
|
11
lib/utils/datum_cas.dart
Normal file
11
lib/utils/datum_cas.dart
Normal file
|
@ -0,0 +1,11 @@
|
|||
extension DateString on DateTime {
|
||||
String get dateString => "$day. $month. $year";
|
||||
String get dateTimeString =>
|
||||
"$day. $month. $year $hour:${minute < 10 ? "0$minute" : minute}";
|
||||
String get rawDateString => "$day-$month-$year";
|
||||
}
|
||||
|
||||
extension TextDuration on Duration {
|
||||
String get durationText =>
|
||||
"$inHours hodin${(inHours < 5 && inHours > 1) ? "y" : (inHours == 1) ? "a" : ""} ${inMinutes - inHours * 60} minut${(inMinutes - inHours * 60) < 5 && (inMinutes - inHours * 60) > 1 ? "y" : (inMinutes - inHours * 60) == 1 ? "a" : ""}";
|
||||
}
|
|
@ -18,7 +18,7 @@ final jazyky = <Map<String, dynamic>>[
|
|||
{"jazyk": "C#", "barva": 0xff8200f3},
|
||||
{"jazyk": "JavaScript", "barva": 0xfffdd700},
|
||||
{"jazyk": "Python", "barva": 0xff0080ee},
|
||||
{"jazyk": "PHP🤢", "barva": 0xff00abff},
|
||||
{"jazyk": "PHP", "barva": 0xff00abff},
|
||||
{"jazyk": "C++", "barva": 0xff1626ff},
|
||||
{"jazyk": "Kotlin", "barva": 0xffe34b7c},
|
||||
{"jazyk": "Java", "barva": 0xfff58219},
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
import 'package:denikprogramatora/okna/app.dart';
|
||||
import 'package:denikprogramatora/utils/datum.dart';
|
||||
import 'package:denikprogramatora/utils/datum_cas.dart';
|
||||
import 'package:denikprogramatora/utils/devicecontainer.dart';
|
||||
import 'package:denikprogramatora/utils/dokument.dart';
|
||||
import 'package:denikprogramatora/utils/loading_widget.dart';
|
||||
import 'package:denikprogramatora/utils/programmer.dart';
|
||||
import 'package:denikprogramatora/utils/really_delete.dart';
|
||||
import 'package:denikprogramatora/utils/vzhled.dart';
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:duration_picker/duration_picker.dart';
|
||||
import 'package:fleather/fleather.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:responsive_sizer/responsive_sizer.dart';
|
||||
|
@ -15,37 +15,33 @@ import 'package:uuid/uuid.dart';
|
|||
import '../utils/my_category.dart';
|
||||
|
||||
Future<void> showCreateItemDialog(context,
|
||||
{DateTime? from,
|
||||
DateTime? to,
|
||||
{DateTime? originDate,
|
||||
Duration? timeSpent,
|
||||
String? j,
|
||||
int hvezdicky = 0,
|
||||
String? p,
|
||||
List<MyCategory>? k,
|
||||
String? originalId,
|
||||
ParchmentDocument? doc}) async {
|
||||
DateTime fromDate = from ??
|
||||
DateTime date = originDate ??
|
||||
DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day,
|
||||
DateTime.now().hour - 1);
|
||||
DateTime toDate = to ??
|
||||
DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day,
|
||||
DateTime.now().hour);
|
||||
|
||||
// nastavení jazyka na oblíbený jazyk
|
||||
String jazyk = "C#";
|
||||
if (j == null) {
|
||||
await ref.get().then((value) {
|
||||
jazyk = value["favourite"];
|
||||
jazyk = value["favourite"] ?? "Dart";
|
||||
});
|
||||
} else {
|
||||
jazyk = j;
|
||||
}
|
||||
|
||||
timeSpent = timeSpent ?? const Duration(hours: 0, minutes: 0);
|
||||
|
||||
int review = hvezdicky;
|
||||
|
||||
Programmer programmer = p == null
|
||||
? Programmer(name, userUid)
|
||||
: await Programmer.ziskatProgramatora(
|
||||
FirebaseAuth.instance.currentUser!, p);
|
||||
Programmer programmer = Programmer(name, "pK8iCAtMFiUUhK9FJd6HpWdwA3I3");
|
||||
|
||||
List<MyCategory> categories = k ?? [];
|
||||
|
||||
|
@ -83,39 +79,25 @@ Future<void> showCreateItemDialog(context,
|
|||
const SizedBox(height: 15),
|
||||
Row(
|
||||
children: [
|
||||
Text("Od ${toDate.dateTimeString}"),
|
||||
Text(
|
||||
"Datum ${date.day}. ${date.month}. ${date.year}"),
|
||||
const SizedBox(width: 15),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
showDatePicker(
|
||||
context: context,
|
||||
initialDate: fromDate,
|
||||
initialDate: date,
|
||||
firstDate:
|
||||
DateTime(DateTime.now().year - 5),
|
||||
lastDate:
|
||||
DateTime(DateTime.now().year + 5))
|
||||
.then((value) {
|
||||
showTimePicker(
|
||||
context: context,
|
||||
initialTime:
|
||||
TimeOfDay.fromDateTime(fromDate))
|
||||
.then((time) {
|
||||
if (value!.day == toDate.day &&
|
||||
value.month == toDate.month &&
|
||||
value.year == toDate.year &&
|
||||
(time!.hour > toDate.hour ||
|
||||
(time.hour <= toDate.hour &&
|
||||
time.minute > toDate.minute))) {
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
fromDate = DateTime(
|
||||
value.year,
|
||||
value.month,
|
||||
value.day,
|
||||
time!.hour,
|
||||
time.minute);
|
||||
});
|
||||
setState(() {
|
||||
date = DateTime(
|
||||
value!.year,
|
||||
value.month,
|
||||
value.day,
|
||||
);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
@ -126,89 +108,45 @@ Future<void> showCreateItemDialog(context,
|
|||
)
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
const SizedBox(height: 30),
|
||||
Row(
|
||||
children: [
|
||||
Text("Do ${toDate.dateTimeString}"),
|
||||
Text(
|
||||
"Strávený čas ${timeSpent!.inHours} hodin ${timeSpent!.inMinutes - timeSpent!.inHours * 60} minut"),
|
||||
const SizedBox(width: 15),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
showDatePicker(
|
||||
onPressed: () async {
|
||||
await showDurationPicker(
|
||||
context: context,
|
||||
initialDate: toDate,
|
||||
firstDate:
|
||||
DateTime(DateTime.now().year - 5),
|
||||
lastDate:
|
||||
DateTime(DateTime.now().year + 5))
|
||||
.then((value) {
|
||||
showTimePicker(
|
||||
baseUnit: BaseUnit.hour,
|
||||
initialTime:
|
||||
timeSpent ?? const Duration())
|
||||
.then((hours) {
|
||||
showDurationPicker(
|
||||
context: context,
|
||||
initialTime:
|
||||
TimeOfDay.fromDateTime(toDate))
|
||||
.then((time) {
|
||||
if (value!.day == fromDate.day &&
|
||||
value.month == fromDate.month &&
|
||||
value.year == fromDate.year &&
|
||||
(time!.hour < fromDate.hour ||
|
||||
(time.hour >= fromDate.hour &&
|
||||
time.minute <
|
||||
fromDate.minute))) {
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
toDate = DateTime(value.year, value.month,
|
||||
value.day, time!.hour, time.minute);
|
||||
});
|
||||
});
|
||||
baseUnit: BaseUnit.minute,
|
||||
initialTime: Duration(
|
||||
minutes: (timeSpent ??
|
||||
const Duration())
|
||||
.inMinutes -
|
||||
(timeSpent ??
|
||||
const Duration())
|
||||
.inHours *
|
||||
60))
|
||||
.then((minutes) => setState(() {
|
||||
timeSpent = Duration(
|
||||
hours: hours!.inHours,
|
||||
minutes: minutes!.inMinutes);
|
||||
}));
|
||||
});
|
||||
},
|
||||
child: const Text(
|
||||
("Změnit"),
|
||||
"Změnit",
|
||||
style: Vzhled.textBtn,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 30),
|
||||
const Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
"Strávený čas",
|
||||
style: Vzhled.nadpis,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
"${toDate.difference(fromDate).inHours} ${toDate.difference(fromDate).inHours == 1 ? "hodina" : toDate.difference(fromDate).inHours > 1 && toDate.difference(fromDate).inHours < 5 ? "hodiny" : "hodin"}${(toDate.difference(fromDate).inMinutes - toDate.difference(fromDate).inHours * 60 == 0) ? "" : " a ${(toDate.difference(fromDate).inMinutes - toDate.difference(fromDate).inHours * 60)} ${(toDate.difference(fromDate).inMinutes - toDate.difference(fromDate).inHours * 60) == 1 ? "minuta" : (toDate.difference(fromDate).inMinutes - toDate.difference(fromDate).inHours * 60) > 1 && (toDate.difference(fromDate).inMinutes - toDate.difference(fromDate).inHours * 60) < 5 ? "minuty" : "minut"}"}"),
|
||||
),
|
||||
const SizedBox(height: 30),
|
||||
const Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
"Programátor",
|
||||
style: Vzhled.nadpis,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: TextButton(
|
||||
onPressed: () async {
|
||||
await showProgrammersDialog(context, doc: doc)
|
||||
.then((value) {
|
||||
setState(() {
|
||||
programmer = value;
|
||||
});
|
||||
});
|
||||
},
|
||||
child: Text(
|
||||
programmer.name,
|
||||
style: Vzhled.textBtn,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
@ -350,35 +288,33 @@ Future<void> showCreateItemDialog(context,
|
|||
onPressed: () {
|
||||
if (originalId == null) {
|
||||
ref.collection("records").add({
|
||||
"fromDate": fromDate,
|
||||
"toDate": toDate,
|
||||
"codingTime":
|
||||
"${toDate.difference(fromDate).inHours} ${toDate.difference(fromDate).inHours == 1 ? "hodina" : toDate.difference(fromDate).inHours > 1 && toDate.difference(fromDate).inHours < 5 ? "hodiny" : "hodin"}${(toDate.difference(fromDate).inMinutes - toDate.difference(fromDate).inHours * 60 == 0) ? "" : " a ${(toDate.difference(fromDate).inMinutes - toDate.difference(fromDate).inHours * 60)} ${(toDate.difference(fromDate).inMinutes - toDate.difference(fromDate).inHours * 60) == 1 ? "minuta" : (toDate.difference(fromDate).inMinutes - toDate.difference(fromDate).inHours * 60) > 1 && (toDate.difference(fromDate).inMinutes - toDate.difference(fromDate).inHours * 60) < 5 ? "minuty" : "minut"}"}",
|
||||
"date": DateTime(date.year, date.month, date.day),
|
||||
"time_spent": timeSpent!.durationText,
|
||||
"time_spentRaw": timeSpent!.inSeconds,
|
||||
"programmer": programmer.id,
|
||||
"programmerName": programmer.name,
|
||||
"language": jazyky
|
||||
"programming_language": jazyky
|
||||
.where((element) => element["jazyk"] == jazyk)
|
||||
.toList()[0],
|
||||
"review": review,
|
||||
"rating": review,
|
||||
"categories": categories.map((e) => e.id).toList(),
|
||||
"description": controller.document.toActualJson(),
|
||||
"descriptionRaw": controller.document.toPlainText()
|
||||
}).then((value) =>
|
||||
Navigator.of(context, rootNavigator: true)
|
||||
.pop("dialog"));
|
||||
return;
|
||||
}
|
||||
ref.collection("records").doc(originalId).update({
|
||||
"fromDate": fromDate,
|
||||
"toDate": toDate,
|
||||
"codingTime":
|
||||
"${toDate.difference(fromDate).inHours} ${toDate.difference(fromDate).inHours == 1 ? "hodina" : toDate.difference(fromDate).inHours > 1 && toDate.difference(fromDate).inHours < 5 ? "hodiny" : "hodin"}${(toDate.difference(fromDate).inMinutes - toDate.difference(fromDate).inHours * 60 == 0) ? "" : " a ${(toDate.difference(fromDate).inMinutes - toDate.difference(fromDate).inHours * 60)} ${(toDate.difference(fromDate).inMinutes - toDate.difference(fromDate).inHours * 60) == 1 ? "minuta" : (toDate.difference(fromDate).inMinutes - toDate.difference(fromDate).inHours * 60) > 1 && (toDate.difference(fromDate).inMinutes - toDate.difference(fromDate).inHours * 60) < 5 ? "minuty" : "minut"}"}",
|
||||
"date": DateTime(date.year, date.month, date.day),
|
||||
"time_spentRaw": timeSpent!.inSeconds,
|
||||
"time_spent": timeSpent!.durationText,
|
||||
"programmer": programmer.id,
|
||||
"programmerName": programmer.name,
|
||||
"language": jazyky
|
||||
"programming_language": jazyky
|
||||
.where((element) => element["jazyk"] == jazyk)
|
||||
.toList()[0],
|
||||
"review": review,
|
||||
"rating": review,
|
||||
"categories": categories.map((e) => e.id).toList(),
|
||||
"descriptionRaw": controller.document.toPlainText(),
|
||||
"description": controller.document.toActualJson(),
|
||||
}).then((value) =>
|
||||
Navigator.of(context, rootNavigator: true).pop("dialog"));
|
||||
|
@ -398,277 +334,6 @@ Future<void> showCreateItemDialog(context,
|
|||
);
|
||||
}
|
||||
|
||||
Future<Programmer> showProgrammersDialog(context,
|
||||
{ParchmentDocument? doc, bool jenMenit = false}) async {
|
||||
bool showAddProgrammer = false;
|
||||
bool editing = false;
|
||||
GlobalKey<FormState> key = GlobalKey<FormState>();
|
||||
TextEditingController nameCon = TextEditingController();
|
||||
late String editId;
|
||||
|
||||
Programmer programmer = Programmer(name, userUid);
|
||||
|
||||
await showDialog(
|
||||
context: context,
|
||||
builder: (_) => AlertDialog(
|
||||
title: const Text("Programátoři", style: Vzhled.velkyText),
|
||||
scrollable: true,
|
||||
content: SizedBox(
|
||||
width: 50.w,
|
||||
child: StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
return showAddProgrammer
|
||||
? Form(
|
||||
key: key,
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextFormField(
|
||||
controller: nameCon,
|
||||
decoration: Vzhled.inputDecoration("Jméno"),
|
||||
validator: (value) {
|
||||
if (value!.trim().isEmpty) {
|
||||
return "Toto pole je povinné!";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 5),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
if (key.currentState!.validate()) {
|
||||
if (editing) {
|
||||
ref
|
||||
.collection("programmers")
|
||||
.doc(editId)
|
||||
.update({"name": nameCon.text});
|
||||
} else {
|
||||
var uuid = const Uuid();
|
||||
String id = uuid.v1();
|
||||
|
||||
ref
|
||||
.collection("programmers")
|
||||
.doc(id)
|
||||
.set({"name": nameCon.text, "id": id});
|
||||
}
|
||||
nameCon.text = "";
|
||||
|
||||
setState(() {
|
||||
editing = false;
|
||||
showAddProgrammer = false;
|
||||
});
|
||||
}
|
||||
},
|
||||
child: Text(
|
||||
editing ? "Uložit" : "Přidat",
|
||||
style: Vzhled.textBtn,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
showAddProgrammer = false;
|
||||
});
|
||||
},
|
||||
child: const Text(
|
||||
"Zpátky",
|
||||
style: Vzhled.textBtn,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: Column(
|
||||
children: [
|
||||
Material(
|
||||
color: Vzhled.dialogColor,
|
||||
child: InkWell(
|
||||
splashColor: (jenMenit) ? Colors.transparent : null,
|
||||
onTap: () {
|
||||
if (jenMenit) return;
|
||||
programmer = Programmer(name, userUid);
|
||||
Navigator.of(context, rootNavigator: true)
|
||||
.pop("dialog");
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(name),
|
||||
if (!jenMenit)
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
programmer = Programmer(name, userUid);
|
||||
Navigator.of(context, rootNavigator: true)
|
||||
.pop("dialog");
|
||||
},
|
||||
child: const Text(
|
||||
"Vybrat",
|
||||
style: Vzhled.textBtn,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
StreamBuilder(
|
||||
stream: ref.collection("programmers").snapshots(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
var docs = snapshot.data!.docs;
|
||||
|
||||
return Column(
|
||||
children: List.generate(docs.length, (index) {
|
||||
var data = docs[index].data();
|
||||
return Material(
|
||||
color: Vzhled.dialogColor,
|
||||
child: InkWell(
|
||||
splashColor: (jenMenit)
|
||||
? Colors.transparent
|
||||
: null,
|
||||
onTap: () {
|
||||
if (jenMenit) return;
|
||||
programmer = Programmer(
|
||||
data["name"], data["id"]);
|
||||
Navigator.of(context,
|
||||
rootNavigator: true)
|
||||
.pop("dialog");
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Row(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(data["name"]),
|
||||
Row(
|
||||
children: [
|
||||
if (!jenMenit)
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
programmer = Programmer(
|
||||
data["name"],
|
||||
data["id"]);
|
||||
Navigator.of(context,
|
||||
rootNavigator:
|
||||
true)
|
||||
.pop("dialog");
|
||||
},
|
||||
child: const Text(
|
||||
"Vybrat",
|
||||
style: Vzhled.textBtn,
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
editId = data["id"];
|
||||
|
||||
setState(() {
|
||||
showAddProgrammer = true;
|
||||
editing = true;
|
||||
nameCon =
|
||||
TextEditingController(
|
||||
text:
|
||||
data["name"]);
|
||||
});
|
||||
},
|
||||
icon: const Icon(Icons.edit,
|
||||
color: Vzhled.textColor),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
showReallyDelete(context,
|
||||
() async {
|
||||
Navigator.of(context,
|
||||
rootNavigator:
|
||||
true)
|
||||
.pop("dialog");
|
||||
Navigator.of(context,
|
||||
rootNavigator:
|
||||
true)
|
||||
.pop("dialog");
|
||||
if (doc != null) {
|
||||
Navigator.of(context,
|
||||
rootNavigator:
|
||||
true)
|
||||
.pop("dialog");
|
||||
}
|
||||
|
||||
// deleting all records
|
||||
await ref
|
||||
.collection("records")
|
||||
.where("programmer",
|
||||
isEqualTo:
|
||||
data["id"])
|
||||
.get()
|
||||
.then((value) {
|
||||
for (var snap
|
||||
in value.docs) {
|
||||
ref
|
||||
.collection(
|
||||
"records")
|
||||
.doc(snap.id)
|
||||
.delete();
|
||||
}
|
||||
});
|
||||
|
||||
// deleting
|
||||
await ref
|
||||
.collection(
|
||||
"programmers")
|
||||
.doc(data["id"])
|
||||
.delete();
|
||||
},
|
||||
doNavigatorPop: false,
|
||||
text:
|
||||
"Odstranit programátora a všechny jeho záznamy?");
|
||||
},
|
||||
icon: const Icon(Icons.delete,
|
||||
color: Vzhled.textColor),
|
||||
),
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
return const LoadingWidget();
|
||||
}),
|
||||
const SizedBox(height: 5),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
showAddProgrammer = true;
|
||||
});
|
||||
},
|
||||
child: const Text(
|
||||
"Přidat nového programátora",
|
||||
style: Vzhled.textBtn,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return programmer;
|
||||
}
|
||||
|
||||
Future<List<MyCategory>> showCategoriesDialog(
|
||||
context, List<MyCategory> categories,
|
||||
{bool jenMenit = false}) async {
|
||||
|
|
|
@ -4,29 +4,29 @@ var razeni = [
|
|||
// VZESTUPNĚ ČAS
|
||||
(QueryDocumentSnapshot<Map<String, dynamic>> a,
|
||||
QueryDocumentSnapshot<Map<String, dynamic>> b) =>
|
||||
((a.data()["fromDate"] as Timestamp).toDate().hour ==
|
||||
(b.data()["fromDate"] as Timestamp).toDate().hour)
|
||||
? (a.data()["fromDate"] as Timestamp)
|
||||
((a.data()["date"] as Timestamp).toDate().hour ==
|
||||
(b.data()["date"] as Timestamp).toDate().hour)
|
||||
? (a.data()["date"] as Timestamp)
|
||||
.toDate()
|
||||
.minute
|
||||
.compareTo((b.data()["fromDate"] as Timestamp).toDate().minute)
|
||||
: (a.data()["fromDate"] as Timestamp)
|
||||
.compareTo((b.data()["date"] as Timestamp).toDate().minute)
|
||||
: (a.data()["date"] as Timestamp)
|
||||
.toDate()
|
||||
.hour
|
||||
.compareTo((b.data()["fromDate"] as Timestamp).toDate().hour),
|
||||
.compareTo((b.data()["date"] as Timestamp).toDate().hour),
|
||||
// SESTUPNĚ ČAS
|
||||
(QueryDocumentSnapshot<Map<String, dynamic>> a,
|
||||
QueryDocumentSnapshot<Map<String, dynamic>> b) =>
|
||||
((b.data()["fromDate"] as Timestamp).toDate().hour ==
|
||||
(a.data()["fromDate"] as Timestamp).toDate().hour)
|
||||
? (b.data()["fromDate"] as Timestamp)
|
||||
((b.data()["date"] as Timestamp).toDate().hour ==
|
||||
(a.data()["date"] as Timestamp).toDate().hour)
|
||||
? (b.data()["date"] as Timestamp)
|
||||
.toDate()
|
||||
.minute
|
||||
.compareTo((a.data()["fromDate"] as Timestamp).toDate().minute)
|
||||
: (b.data()["fromDate"] as Timestamp)
|
||||
.compareTo((a.data()["date"] as Timestamp).toDate().minute)
|
||||
: (b.data()["date"] as Timestamp)
|
||||
.toDate()
|
||||
.hour
|
||||
.compareTo((a.data()["fromDate"] as Timestamp).toDate().hour),
|
||||
.compareTo((a.data()["date"] as Timestamp).toDate().hour),
|
||||
// VZESTUPNĚ HODNOCENÍ
|
||||
(QueryDocumentSnapshot<Map<String, dynamic>> a,
|
||||
QueryDocumentSnapshot<Map<String, dynamic>> b) =>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:denikprogramatora/okna/app.dart';
|
||||
import 'package:denikprogramatora/utils/datum.dart';
|
||||
import 'package:denikprogramatora/utils/datum_cas.dart';
|
||||
import 'package:denikprogramatora/utils/devicecontainer.dart';
|
||||
import 'package:denikprogramatora/utils/my_category.dart';
|
||||
import 'package:denikprogramatora/utils/new_record_dialog.dart';
|
||||
|
@ -12,12 +12,11 @@ import 'package:flutter/material.dart';
|
|||
import 'package:responsive_sizer/responsive_sizer.dart';
|
||||
|
||||
void showInfoDialog(
|
||||
context, Map<String, dynamic> data, String originalId) async {
|
||||
var denOd = (data["fromDate"] as Timestamp).toDate().toLocal();
|
||||
var denDo = (data["toDate"] as Timestamp).toDate().toLocal();
|
||||
context, Map<String, dynamic> data, String originalId, String jmeno) async {
|
||||
var date = (data["date"] as Timestamp).toDate().toLocal();
|
||||
List<MyCategory> categories = [];
|
||||
|
||||
if ((data["categories"] as List).isNotEmpty) {
|
||||
if (((data["categories"] ?? []) as List).isNotEmpty) {
|
||||
for (var category in data["categories"]) {
|
||||
await ref.collection("categories").doc(category).get().then((value) {
|
||||
var data = value.data();
|
||||
|
@ -30,7 +29,9 @@ void showInfoDialog(
|
|||
showDialog(
|
||||
context: context,
|
||||
builder: (_) {
|
||||
var document = ParchmentDocument.fromJson(data["description"]);
|
||||
var document = (data["description"] != null && data["description"] != "")
|
||||
? ParchmentDocument.fromJson(data["description"])
|
||||
: (ParchmentDocument()..insert(0, data["descriptionRaw"]));
|
||||
var controller = FleatherController(document);
|
||||
|
||||
return AlertDialog(
|
||||
|
@ -51,13 +52,13 @@ void showInfoDialog(
|
|||
style: Vzhled.purpleCudlik,
|
||||
onPressed: () {
|
||||
showCreateItemDialog(context,
|
||||
from: denOd,
|
||||
to: denDo,
|
||||
originDate: date,
|
||||
timeSpent: Duration(seconds: data["time_spentRaw"]),
|
||||
k: categories,
|
||||
p: data["programmer"],
|
||||
hvezdicky: data["review"],
|
||||
hvezdicky: data["rating"],
|
||||
originalId: originalId,
|
||||
j: data["language"]["jazyk"],
|
||||
j: data["programming_language"]["jazyk"],
|
||||
doc: document)
|
||||
.then((_) => Navigator.of(context).pop());
|
||||
},
|
||||
|
@ -69,7 +70,7 @@ void showInfoDialog(
|
|||
),
|
||||
],
|
||||
title: Text(
|
||||
"Záznam ze dne ${denOd.dateString}",
|
||||
"Záznam ze dne ${date.dateString}",
|
||||
style: Vzhled.dialogNadpis,
|
||||
),
|
||||
scrollable: true,
|
||||
|
@ -97,9 +98,7 @@ void showInfoDialog(
|
|||
style: Vzhled.nadpis,
|
||||
),
|
||||
Text(
|
||||
(Device.screenType == ScreenType.mobile)
|
||||
? "od ${denOd.dateTimeString}\ndo ${denDo.dateTimeString} (${data["codingTime"]})"
|
||||
: "od ${denOd.dateTimeString} do ${denDo.dateTimeString} (${data["codingTime"]})",
|
||||
"${date.dateString} (${data["time_spent"]})",
|
||||
)
|
||||
],
|
||||
),
|
||||
|
@ -113,9 +112,10 @@ void showInfoDialog(
|
|||
style: Vzhled.nadpis,
|
||||
),
|
||||
Text(
|
||||
data["language"]["jazyk"],
|
||||
data["programming_language"]["jazyk"],
|
||||
style: TextStyle(
|
||||
color: Color(data["language"]["barva"])),
|
||||
color: Color(
|
||||
data["programming_language"]["barva"])),
|
||||
)
|
||||
],
|
||||
),
|
||||
|
@ -138,7 +138,9 @@ void showInfoDialog(
|
|||
style: Vzhled.nadpis,
|
||||
),
|
||||
Text(
|
||||
data["programmerName"],
|
||||
FirebaseAuth
|
||||
.instance.currentUser!.displayName ??
|
||||
jmeno,
|
||||
)
|
||||
],
|
||||
),
|
||||
|
@ -156,7 +158,7 @@ void showInfoDialog(
|
|||
5,
|
||||
(index) {
|
||||
return Icon(Icons.star,
|
||||
color: (index + 1) <= data["review"]
|
||||
color: (index + 1) <= data["rating"]
|
||||
? Colors.yellow
|
||||
: Colors.grey);
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue