Skip to content

Commit

Permalink
fix: export
Browse files Browse the repository at this point in the history
  • Loading branch information
monkey111111111 committed May 25, 2024
1 parent c823637 commit 6a73129
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 30 deletions.
4 changes: 2 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}
Expand Down
65 changes: 63 additions & 2 deletions lib/screens/buku_tamu/buku_tamu.dart
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -14,27 +18,84 @@ class _BukuTamuState extends State<BukuTamu> {

final double sizeColumn = 200;

List<QueryDocumentSnapshot>? 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<QuerySnapshot>(
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),
)),
),
],
),
),
Expand Down
63 changes: 61 additions & 2 deletions lib/screens/data_anggota/data_anggota.dart
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -11,27 +15,82 @@ class DataAnggota extends StatefulWidget {
class _DataAnggotaState extends State<DataAnggota> {
FirebaseFirestore firestore = FirebaseFirestore.instance;

List<QueryDocumentSnapshot>? 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<QuerySnapshot>(
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),
)),
),
],
),
),
Expand Down
56 changes: 56 additions & 0 deletions lib/screens/data_buku/data_buku.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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);
Expand Down Expand Up @@ -52,6 +55,8 @@ class _DataBukuState extends State<DataBuku> {
String pdfLink = "";
Map<String, dynamic> _pdfFile = {"fileBytes": null, "fileName": ""};

List<QueryDocumentSnapshot>? allData;

void defaultState() {
setState(() {
judul = "";
Expand Down Expand Up @@ -464,6 +469,40 @@ class _DataBukuState extends State<DataBuku> {
});
}

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<QuerySnapshot>(
Expand All @@ -472,6 +511,7 @@ class _DataBukuState extends State<DataBuku> {
: fs.getAllStream("books"),
builder: (context, snapshot) {
if (snapshot.hasData) {
allData = snapshot.data!.docs;
return Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
Expand Down Expand Up @@ -1004,6 +1044,22 @@ class _DataBukuState extends State<DataBuku> {
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),
)),
),
]));
}

Expand Down
30 changes: 6 additions & 24 deletions task.txt
Original file line number Diff line number Diff line change
@@ -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 ✅
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 ❌

0 comments on commit 6a73129

Please sign in to comment.