From 6a73129de0dbfd4806a5d85aa23b8620963d84c0 Mon Sep 17 00:00:00 2001 From: Monkey D Luffy Date: Sat, 25 May 2024 21:11:07 +0800 Subject: [PATCH] fix: export --- lib/main.dart | 4 +- lib/screens/buku_tamu/buku_tamu.dart | 65 +++++++++++++++++++++- lib/screens/data_anggota/data_anggota.dart | 63 ++++++++++++++++++++- lib/screens/data_buku/data_buku.dart | 56 +++++++++++++++++++ task.txt | 30 ++-------- 5 files changed, 188 insertions(+), 30 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 77cb395..b5e15a6 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -26,8 +26,8 @@ class MyApp extends StatelessWidget { Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, - home: Login(), - // home: const DashboardScreen(), + // home: Login(), + home: const DashboardScreen(), navigatorKey: navigatorKey, ); } diff --git a/lib/screens/buku_tamu/buku_tamu.dart b/lib/screens/buku_tamu/buku_tamu.dart index 7670c43..6121e86 100644 --- a/lib/screens/buku_tamu/buku_tamu.dart +++ b/lib/screens/buku_tamu/buku_tamu.dart @@ -1,5 +1,9 @@ +import 'dart:convert'; + import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:flutter/material.dart'; +// ignore: avoid_web_libraries_in_flutter +import 'dart:html' as webFile; class BukuTamu extends StatefulWidget { const BukuTamu({Key? key}) : super(key: key); @@ -14,27 +18,84 @@ class _BukuTamuState extends State { final double sizeColumn = 200; + List? allData; + + void onExport() { + var l = []; + allData!.forEach((e) { + var noAnggota = e['no_anggota'].toString(); + var nama = e['nama'].toString(); + var alamat = e['alamat'].toString(); + + final tanggal = e["tanggal"]; + final hari = tanggal["hari"]; + final bulan = tanggal["bulan"]; + final tahun = tanggal["tahun"]; + var date = "$hari/$bulan/$tahun"; + + var pekerjaan = e['pekerjaan'].toString(); + var noHp = e['noHp']; + + l.add({ + "no_anggota": noAnggota, + "nama": nama, + "alamat": alamat, + "date": date, + "pekerjaan": pekerjaan, + "noHp": noHp, + }); + }); + var jsonString = jsonEncode(l); + var blob = webFile.Blob([ + [jsonString] + ], 'application/json', 'native'); + + webFile.AnchorElement( + href: webFile.Url.createObjectUrlFromBlob(blob).toString(), + ) + ..setAttribute("download", "buku-tamu.json") + ..click(); + } + @override Widget build(BuildContext context) { return StreamBuilder( stream: firestore.collection("tamu").snapshots(), builder: (context, snapshot) { if (snapshot.hasData) { + allData = snapshot.data!.docs; return Expanded( child: Column( children: [ - const Padding( + Padding( padding: EdgeInsets.only( left: 20, right: 20, top: 30, bottom: 10), child: Row( crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( "Buku Tamu", style: TextStyle( fontSize: 25, fontWeight: FontWeight.w600), ), + Container( + height: 40, + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(5)), + child: ElevatedButton( + style: ElevatedButton.styleFrom( + backgroundColor: Colors.greenAccent, + textStyle: const TextStyle(fontSize: 16)), + onPressed: () { + onExport(); + }, + child: const Text( + 'Export', + style: TextStyle(color: Colors.white), + )), + ), ], ), ), diff --git a/lib/screens/data_anggota/data_anggota.dart b/lib/screens/data_anggota/data_anggota.dart index 24b90d9..d9bc1b3 100644 --- a/lib/screens/data_anggota/data_anggota.dart +++ b/lib/screens/data_anggota/data_anggota.dart @@ -1,5 +1,9 @@ +import 'dart:convert'; + import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:flutter/material.dart'; +// ignore: avoid_web_libraries_in_flutter +import 'dart:html' as webFile; class DataAnggota extends StatefulWidget { const DataAnggota({Key? key}) : super(key: key); @@ -11,27 +15,82 @@ class DataAnggota extends StatefulWidget { class _DataAnggotaState extends State { FirebaseFirestore firestore = FirebaseFirestore.instance; + List? allData; + + void onExport() { + var l = []; + allData!.forEach((e) { + var noAnggota = e['no_anggota'].toString(); + var nama = e['nama'].toString(); + var email = e['email'].toString(); + var pekerjaan = e['pekerjaan'].toString(); + var alamat = e['alamat'].toString(); + var hp = e['hp']; + var ibuKandung = e['ibu_kandung']; + var nohpIbuKandung = e['no_hp_ibu_kandung']; + + l.add({ + "no_anggota": noAnggota, + "nama": nama, + "email": email, + "pekerjaan": pekerjaan, + "alamat": alamat, + "hp": hp, + "ibu_kandung": ibuKandung, + "no_hp_ibu_kandung": nohpIbuKandung, + }); + }); + var jsonString = jsonEncode(l); + var blob = webFile.Blob([ + [jsonString] + ], 'application/json', 'native'); + + webFile.AnchorElement( + href: webFile.Url.createObjectUrlFromBlob(blob).toString(), + ) + ..setAttribute("download", "buku-tamu.json") + ..click(); + } + @override Widget build(BuildContext context) { return StreamBuilder( stream: firestore.collection("users").snapshots(), builder: (context, snapshot) { if (snapshot.hasData) { + allData = snapshot.data!.docs; return Expanded( child: Column( children: [ - const Padding( + Padding( padding: EdgeInsets.only( left: 20, right: 20, top: 30, bottom: 10), child: Row( crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( "Data Anggota", style: TextStyle( fontSize: 25, fontWeight: FontWeight.w600), ), + Container( + height: 40, + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(5)), + child: ElevatedButton( + style: ElevatedButton.styleFrom( + backgroundColor: Colors.greenAccent, + textStyle: const TextStyle(fontSize: 16)), + onPressed: () { + onExport(); + }, + child: const Text( + 'Export', + style: TextStyle(color: Colors.white), + )), + ), ], ), ), diff --git a/lib/screens/data_buku/data_buku.dart b/lib/screens/data_buku/data_buku.dart index 014363c..42c22dc 100644 --- a/lib/screens/data_buku/data_buku.dart +++ b/lib/screens/data_buku/data_buku.dart @@ -1,5 +1,6 @@ // ignore_for_file: use_build_context_synchronously, non_constant_identifier_names +import 'dart:convert'; import 'dart:io'; import 'package:admin_perpustakaan/utils/log_utils.dart'; import 'package:admin_perpustakaan/utils/screen_utils.dart'; @@ -16,6 +17,8 @@ import 'package:admin_perpustakaan/services/FirebaseServices.dart'; import 'package:admin_perpustakaan/utils/flutter_pdf_split.dart'; import 'package:admin_perpustakaan/utils/position.dart'; import 'package:admin_perpustakaan/utils/string_utils.dart'; +// ignore: avoid_web_libraries_in_flutter +import 'dart:html' as webFile; class DataBuku extends StatefulWidget { const DataBuku({Key? key}) : super(key: key); @@ -52,6 +55,8 @@ class _DataBukuState extends State { String pdfLink = ""; Map _pdfFile = {"fileBytes": null, "fileName": ""}; + List? allData; + void defaultState() { setState(() { judul = ""; @@ -464,6 +469,40 @@ class _DataBukuState extends State { }); } + void onExport() { + var l = []; + allData!.forEach((e) { + var judulBuku = e['judul_buku'].toString(); + var pengarang = e['pengarang'].toString(); + var penerbit = e['penerbit'].toString(); + var kategori = e['kategori'].toString(); + var rak = e['rak'].toString(); + var stokBuku = e['stok_buku']; + var halaman = e['halaman'].toString(); + var image = e['image'].toString(); + l.add({ + "judul_buku": judulBuku, + "pengarang": pengarang, + "penerbit": penerbit, + "kategori": kategori, + "rak": rak, + "stokBuku": stokBuku, + "halaman": halaman, + "image": image, + }); + }); + var jsonString = jsonEncode(l); + var blob = webFile.Blob([ + [jsonString] + ], 'application/json', 'native'); + + webFile.AnchorElement( + href: webFile.Url.createObjectUrlFromBlob(blob).toString(), + ) + ..setAttribute("download", "data-buku.json") + ..click(); + } + @override Widget build(BuildContext context) { return StreamBuilder( @@ -472,6 +511,7 @@ class _DataBukuState extends State { : fs.getAllStream("books"), builder: (context, snapshot) { if (snapshot.hasData) { + allData = snapshot.data!.docs; return Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -1004,6 +1044,22 @@ class _DataBukuState extends State { style: TextStyle(color: Colors.white), )), ), + Container( + height: 40, + decoration: BoxDecoration( + color: Colors.white, borderRadius: BorderRadius.circular(5)), + child: ElevatedButton( + style: ElevatedButton.styleFrom( + backgroundColor: Colors.greenAccent, + textStyle: const TextStyle(fontSize: 16)), + onPressed: () { + onExport(); + }, + child: const Text( + 'Export', + style: TextStyle(color: Colors.white), + )), + ), ])); } diff --git a/task.txt b/task.txt index a90074a..af5d0e7 100644 --- a/task.txt +++ b/task.txt @@ -1,24 +1,6 @@ -version: v0.0.5 ✅ ❌ 🔥 -- tanggal terbit tidak ada di tambah buku web 🔥 -- list buku di scroll ke bawah 🔥 - -version: v0.0.4 ✅ ❌ 🔥 -- tambahkan stok buku ✅ -- tambahkan login ✅ -- tambahkan menu tamu ✅ -- harus ada konfirmasi dari admin ketika peminjaman offline ✅ - - -version: v0.0.3 ✅ ❌ 🔥 -- hilangkan tombol konfirmasi di peminjaman ketika melakukan peminjaman online ✅ - -version: v0.0.2 ✅ ❌ 🔥 -- perbaiki bug tambah buku ✅ - -version: v0.0.1 ✅ ❌ 🔥 -- Buat logic untuk konfirmasi di peminjaman ✅ -- Buat logic untuk perpanjangan di peminjaman ✅ -- Buat logic untuk hapus peminjaman ✅ -- Perbaiki page peminjaman ✅ -- buat logic untuk pengembalian ✅ -- buat data anggota ✅ \ No newline at end of file +version: v0.0.6 ✅ ❌ 🔥 +- Tambahkan import / export di data buku ❌ +- Tambahkan import / export di data anggota ❌ +- Tambahkan import / export di buku tamu ❌ +- Tambahkan import / export di peminjaman ❌ +- Tambahkan import / export di pengembalian ❌ \ No newline at end of file