Fakultas Ilmu Komputer UI

Commit 4e545b17 authored by Dzaky Noor Hasyim's avatar Dzaky Noor Hasyim
Browse files

Merge branch 'dev-putsal' of...

Merge branch 'dev-putsal' of https://gitlab.cs.ui.ac.id/ppl-fasilkom-ui/sosial/bisago/bisago-fe into dev-noor
parents f93d3b87 ebd90b71
import 'dart:async';
import 'package:bisaGo/model/komentar_posting_kegiatan.dart';
import 'package:bisaGo/network/data/network_model.dart';
import 'package:bisaGo/repository/komentar_posting_kegiatan_repository.dart';
import 'package:get_it/get_it.dart';
import 'package:http/http.dart';
class KomentarPostingKegiatanBloc {
KomentarPostingKegiatanRepository _komentarPostingKegiatanRepository;
StreamController _komentarPostingKegiatanListController;
List<KomentarPostingKegiatanModel> allKomentarPositngKegiatanFromApi;
StreamSink<NetworkModel<KomentarPostingKegiatanList>> get komentarPostingKegiatanListSink =>
_komentarPostingKegiatanListController.sink;
Stream<NetworkModel<KomentarPostingKegiatanList>> get komentarPostingKegiatanListStream =>
_komentarPostingKegiatanListController.stream;
KomentarPostingKegiatanBloc(String namaLokasi, int id) {
_komentarPostingKegiatanListController =
StreamController<NetworkModel<KomentarPostingKegiatanList>>();
_komentarPostingKegiatanRepository =
GetIt.instance.get<BaseKomentarPostingKegiatanRepository>();
fetchKomentarPostingKegiatanList(namaLokasi, id);
}
Future<void> fetchKomentarPostingKegiatanList(String namaLokasi, int id) async {
komentarPostingKegiatanListSink.add(NetworkModel.loading('Getting Komentar'));
try {
final komentarPostingKegiatanListResponse =
await _komentarPostingKegiatanRepository.fetchKomentarPostingKegiatan(namaLokasi, id);
allKomentarPositngKegiatanFromApi =
List.from(komentarPostingKegiatanListResponse.allKomentarKegiatan);
komentarPostingKegiatanListSink
.add(NetworkModel.completed(komentarPostingKegiatanListResponse));
} catch (e) {
komentarPostingKegiatanListSink.add(NetworkModel.error(e.toString()));
}
}
Future<dynamic> addKomentarPostingKegiatan(
Map<String, dynamic> newKomentarPostingKegiatanData,
String namaLokasi,
int id) async {
try {
return await _komentarPostingKegiatanRepository.createKomentarPostingKegiatan(
newKomentarPostingKegiatanData, namaLokasi, id);
} catch (e) {
return Response('Failed to add komentar', 400);
}
}
void resetKomentarPostingKegiatanList() {
komentarPostingKegiatanListSink.add(
NetworkModel.completed(KomentarPostingKegiatanList(allKomentarPositngKegiatanFromApi)));
}
void dispose() {
_komentarPostingKegiatanListController?.close();
}
}
import 'package:bisaGo/repository/kegiatan_repository.dart';
import 'package:bisaGo/repository/komentar_posting_kegiatan_repository.dart';
import 'package:bisaGo/repository/komentar_posting_repository.dart';
import 'package:bisaGo/repository/komentar_repository.dart';
import 'package:bisaGo/repository/komunitas_repository.dart';
......@@ -23,11 +22,13 @@ class AppGetIt {
() => KomentarRepository());
_getIt.registerLazySingleton<BaseKomentarPostingRepository>(
() => KomentarPostingRepository());
_getIt
.registerLazySingleton<BaseLokasiRepository>(() => LokasiRepository());
_getIt
.registerLazySingleton<BaseLayananRepository>(() => LayananRepository());
_getIt
.registerLazySingleton<BaseKegiatanRepository>(() => KegiatanRepository());
_getIt.registerLazySingleton<BaseKomentarPostingKegiatanRepository>(
() => KomentarPostingKegiatanRepository());
_getIt.registerLazySingleton<BaseLokasiRepository>(
() => LokasiRepository());
_getIt.registerLazySingleton<BaseLayananRepository>(
() => LayananRepository());
_getIt.registerLazySingleton<BaseKegiatanRepository>(
() => KegiatanRepository());
}
}
import 'package:json_annotation/json_annotation.dart';
import 'package:bisaGo/config/custom_serializer.dart';
part 'komentar_posting_kegiatan.g.dart';
@JsonSerializable()
class KomentarPostingKegiatanList {
final List<KomentarPostingKegiatanModel> allKomentarKegiatan;
KomentarPostingKegiatanList(this.allKomentarKegiatan);
}
@JsonSerializable()
class KomentarPostingKegiatanModel {
final int id;
final String creator;
final String deskripsi;
@JsonKey(name: 'created', fromJson: CustomSerializer.stringToDateTime)
final DateTime created;
KomentarPostingKegiatanModel(
{this.id,
this.creator,
this.deskripsi,
this.created}
);
factory KomentarPostingKegiatanModel.fromJson(Map<String, dynamic> json) =>
_$KomentarPostingKegiatanModelFromJson(json);
Map<String, dynamic> toJson() => _$KomentarPostingKegiatanModelToJson(this);
}
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'komentar_posting_kegiatan.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
KomentarPostingKegiatanList _$KomentarPostingKegiatanListFromJson(
Map<String, dynamic> json) {
return KomentarPostingKegiatanList(
(json['allKomentarKegiatan'] as List)
?.map((e) => e == null
? null
: KomentarPostingKegiatanModel.fromJson(e as Map<String, dynamic>))
?.toList(),
);
}
Map<String, dynamic> _$KomentarPostingKegiatanListToJson(
KomentarPostingKegiatanList instance) =>
<String, dynamic>{
'allKomentarKegiatan': instance.allKomentarKegiatan,
};
KomentarPostingKegiatanModel _$KomentarPostingKegiatanModelFromJson(
Map<String, dynamic> json) {
return KomentarPostingKegiatanModel(
id: json['id'] as int,
creator: json['creator'] as String,
deskripsi: json['deskripsi'] as String,
created: CustomSerializer.stringToDateTime(json['created'] as String)
);
}
Map<String, dynamic> _$KomentarPostingKegiatanModelToJson(
KomentarPostingKegiatanModel instance) =>
<String, dynamic>{
'id': instance.id,
'creator': instance.creator,
'deskripsi': instance.deskripsi,
'created': instance.created?.toIso8601String(),
};
// import 'package:bisaGo/config/strings.dart';
import 'package:bisaGo/config/styles.dart';
import 'package:bisaGo/model/lokasi.dart';
import 'package:bisaGo/model/kegiatan.dart';
import 'package:bisaGo/page/filter_fasilitas/postingan/detail_post_kegiatan.dart';
import 'package:flutter/material.dart';
// import 'package:bisaGo/component/image_holder.dart';
import 'package:bisaGo/config/styles.dart';
import 'package:bisaGo/model/kegiatan.dart';
class Kegiatan extends StatefulWidget {
final Lokasi lokasi;
......@@ -24,7 +24,25 @@ class _KegiatanState extends State<Kegiatan> {
@override
Widget build(BuildContext context) {
return InkWell(
// key: Key('Kegiatan'),
key: Key('Kegiatan'),
onTap: () {
Navigator.of(context).pushReplacement(MaterialPageRoute(
builder: (BuildContext context) => DetailPostKegiatanPage(
lokasi: widget.lokasi,
kegiatan: KegiatanModel(
id: widget.kegiatan.id,
namaLokasi: widget.lokasi.name,
creator: widget.kegiatan.creator,
namaKegiatan: widget.kegiatan.namaKegiatan,
penyelenggara: widget.kegiatan.penyelenggara,
narahubung: widget.kegiatan.narahubung,
deskripsi: widget.kegiatan.deskripsi,
timeStart: widget.kegiatan.timeStart,
timeEnd: widget.kegiatan.timeEnd
),
)
));
},
child: Container(
margin: const EdgeInsets.only(bottom: regularSpace),
padding: const EdgeInsets.all(doubleSpace),
......
import 'dart:async';
import 'package:bisaGo/config/strings.dart';
import 'package:bisaGo/model/kegiatan.dart';
import 'package:bisaGo/model/lokasi.dart';
import 'package:bisaGo/page/filter_fasilitas/fasilitas.dart';
import 'package:bisaGo/page/updateInformasi/update_informasi.dart';
// import 'package:bisaGo/page/updateInformasi/update_informasi.dart';
import 'package:bisaGo/utils/validator.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:intl/intl.dart';
import 'package:bisaGo/bloc/komentar_posting_bloc.dart';
import 'package:bisaGo/bloc/komentar_posting_kegiatan_bloc.dart';
import 'package:bisaGo/component/image_holder.dart';
import 'package:bisaGo/component/bisago_appbar.dart';
import 'package:bisaGo/config/styles.dart';
import 'package:bisaGo/model/komentar.dart';
import 'package:bisaGo/model/komentar_posting.dart';
import 'package:bisaGo/model/komentar_posting_kegiatan.dart';
import 'package:bisaGo/network/data/network_model.dart';
import 'package:bisaGo/page/login/login.dart';
import 'package:share/share.dart';
......@@ -25,28 +22,23 @@ class DetailPostKegiatanPage extends StatefulWidget {
final Lokasi lokasi;
final KegiatanModel kegiatan; // ganti model x // sudah
const DetailPostKegiatanPage(
{@required this.lokasi, @required this.kegiatan, Key key})
{@required this.kegiatan, @required this.lokasi, Key key})
: super(key: key);
@override
_DetailPostKegiatanPageState createState() => _DetailPostKegiatanPageState();
}
class _DetailPostKegiatanPageState extends State<DetailPostKegiatanPage> {
Map<String, dynamic> newKomentarPostingData = {};
KomentarPostingBloc _bloc;
List<KomentarPostingModel> allKomentarPostingFromApi;
TextEditingController komentarController = TextEditingController();
Map<String, dynamic> newKomentarPostingKegiatanData = {};
KomentarPostingKegiatanBloc _bloc;
List<KomentarPostingKegiatanModel> allKomentarPositngKegiatanFromApi;
TextEditingController komentarKegiatanController = TextEditingController();
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
int like;
int dislike;
int alreadyLikeFlag;
int alreadyDislikeFlag;
@override
void initState() {
alreadyLikeFlag = 0;
alreadyDislikeFlag = 0;
allKomentarPostingFromApi = [];
_bloc = KomentarPostingBloc(widget.lokasi.placeId, widget.komentar.id);
allKomentarPositngKegiatanFromApi = [];
_bloc = KomentarPostingKegiatanBloc(widget.lokasi.placeId, widget.kegiatan.id);
super.initState();
}
......@@ -56,7 +48,7 @@ class _DetailPostKegiatanPageState extends State<DetailPostKegiatanPage> {
child: Scaffold(
appBar: BisaGoAppBar(
title: widget.kegiatan.namaLokasi, // ganti widget.x.namalokasi // sudah
key: Key('appbar-text-${widget.komentar.namaLokasi}'),
key: Key('appbar-text-${widget.kegiatan.namaLokasi}'),
actions: <Widget>[
InkWell(
child: const Icon(Icons.share),
......@@ -106,53 +98,38 @@ class _DetailPostKegiatanPageState extends State<DetailPostKegiatanPage> {
],
),
),
PopupMenuButton(
key: const Key('Button Ubah Informasi'),
elevation: 4.0,
offset: const Offset(0.0, 40.0),
itemBuilder: (BuildContext context) {
final choices = ['Ubah Informasi'];
return choices.map((String choice) {
return PopupMenuItem(
key: Key(choice),
child: ElevatedButton(
style: ButtonStyle(
padding: MaterialStateProperty.all(
EdgeInsets.symmetric(
vertical: 0, horizontal: 0)),
backgroundColor:
MaterialStateProperty.all(Colors.white),
foregroundColor:
MaterialStateProperty.all(Colors.black),
elevation: MaterialStateProperty.all(0)),
onPressed: _updateInformasi,
child: SizedBox(
width: double.infinity,
child: Text(choice),
),
),
);
}).toList();
},
),
// PopupMenuButton(
// key: const Key('Button Ubah Informasi'),
// elevation: 4.0,
// offset: const Offset(0.0, 40.0),
// itemBuilder: (BuildContext context) {
// final choices = ['Ubah Informasi'];
// return choices.map((String choice) {
// return PopupMenuItem(
// key: Key(choice),
// child: ElevatedButton(
// style: ButtonStyle(
// padding: MaterialStateProperty.all(
// EdgeInsets.symmetric(
// vertical: 0, horizontal: 0)),
// backgroundColor:
// MaterialStateProperty.all(Colors.white),
// foregroundColor:
// MaterialStateProperty.all(Colors.black),
// elevation: MaterialStateProperty.all(0)),
// onPressed: _updateInformasi,
// child: SizedBox(
// width: double.infinity,
// child: Text(choice),
// ),
// ),
// );
// }).toList();
// },
// ),
],
),
),
// Container(
// key: const Key('Text Jumlah'),
// width: MediaQuery.of(context).size.width,
// color: red,
// padding: const EdgeInsets.symmetric(
// vertical: regularSpace, horizontal: doubleSpace),
// child: Text(
// 'Tersedia sebanyak ${widget.komentar.jumlah} '
// 'unit fasilitas.',
// style: const TextStyle(
// fontSize: 16,
// color: Colors.white,
// fontFamily: 'Comfortaa',
// ),
// )),
Container(
margin: const EdgeInsets.all(doubleSpace),
child: Column(
......@@ -161,39 +138,11 @@ class _DetailPostKegiatanPageState extends State<DetailPostKegiatanPage> {
SizedBox(
height: 150,
child: ImageHolder(
url: widget.komentar.image,
fasilitas: widget.komentar.tag)),
url: null,
fasilitas: null)),
const SizedBox(
height: 10,
),
// Wrap(
// alignment: WrapAlignment.start,
// direction: Axis.horizontal,
// crossAxisAlignment: WrapCrossAlignment.start,
// children: widget.komentar.tag
// .map<Widget>((tag) =>
// _createTagContainer(getTag(tag)))
// .toList(),
// ),
// Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
// children: <Widget>[
// const Text(
// 'Dapat digunakan oleh',
// style: TextStyle(fontSize: 16),
// textAlign: TextAlign.left,
// ),
// Row(
// mainAxisAlignment: MainAxisAlignment.spaceEvenly,
// children: <Widget>[
// _showIfContains('DF'),
// _showIfContains('DI'),
// _showIfContains('DM'),
// _showIfContains('DS'),
// ],
// )
// ],
// ),
Container(
key: const Key('desc'),
// decoration: BoxDecoration(
......@@ -328,7 +277,7 @@ class _DetailPostKegiatanPageState extends State<DetailPostKegiatanPage> {
),
),
StreamBuilder(
stream: _bloc.komentarPostingListStream,
stream: _bloc.komentarPostingKegiatanListStream,
builder: (context, snapshot) {
if (snapshot.hasData) {
switch (snapshot.data.status) {
......@@ -340,16 +289,16 @@ class _DetailPostKegiatanPageState extends State<DetailPostKegiatanPage> {
);
break;
case Status.completed:
allKomentarPostingFromApi =
snapshot.data.data.allKomentar;
if (allKomentarPostingFromApi.isEmpty) {
allKomentarPositngKegiatanFromApi =
snapshot.data.data.allKomentarKegiatan; // kalo error, brarti allKegiatan
if (allKomentarPositngKegiatanFromApi.isEmpty) {
return const Center(
child: Text('Tidak ada komentar'));
} else {
return Column(
children: allKomentarPostingFromApi.map<Widget>((k) =>
komentarPlaceHolder(
k.creator, k.dateTime, k.deskripsi
children: allKomentarPositngKegiatanFromApi.map<Widget>((k) =>
komentarKegiatanPlaceHolder(
k.creator, k.created, k.deskripsi
)
).toList()
);
......@@ -376,7 +325,7 @@ class _DetailPostKegiatanPageState extends State<DetailPostKegiatanPage> {
maxLines: null,
minLines: 3,
validator: FieldValidator.validateInfo,
controller: komentarController,
controller: komentarKegiatanController,
style: const TextStyle(
fontSize: 18,
),
......@@ -464,34 +413,34 @@ class _DetailPostKegiatanPageState extends State<DetailPostKegiatanPage> {
MaterialPageRoute(builder: (BuildContext context) => const Login()),
(Route<dynamic> route) => false);
} else {
await _validateKomentarInput();
await _validateKomentarKegiatanInput();
}
}
Future<void> _validateKomentarInput() async {
Future<void> _validateKomentarKegiatanInput() async {
final form = _formKey.currentState;
if (_formKey.currentState.validate()) {
form.save();
await _submitKomentar(komentarController.text);
await _submitKomentarKegiatan(komentarKegiatanController.text);
}
}
Future<void> _submitKomentar(String komentar) async {
Future<void> _submitKomentarKegiatan(String komentarKegiatan) async {
final _namaLokasi = widget.lokasi.placeId;
newKomentarPostingData['deskripsi'] = komentar;
newKomentarPostingData['namaLokasi'] = _namaLokasi;
newKomentarPostingData['id'] = widget.komentar.id;
newKomentarPostingKegiatanData['deskripsi'] = komentarKegiatan;
newKomentarPostingKegiatanData['namaLokasi'] = _namaLokasi;
newKomentarPostingKegiatanData['id'] = widget.kegiatan.id; // ganti widget.x.id // sudah
_bloc = KomentarPostingBloc(_namaLokasi, widget.komentar.id);
final response = await _bloc.addKomentarPosting(
newKomentarPostingData, _namaLokasi, widget.komentar.id);
_bloc = KomentarPostingKegiatanBloc(_namaLokasi, widget.kegiatan.id); // ganti widget.x.id // sudah
final response = await _bloc.addKomentarPostingKegiatan(
newKomentarPostingKegiatanData, _namaLokasi, widget.kegiatan.id); // ganti widget.x.id // sudah
if (response['response'] == 'komentar added') {
successDialog(context);
Timer(const Duration(seconds: 2), () {
Navigator.pop(context);
});
await _bloc.fetchKomentarPostingList(_namaLokasi, widget.komentar.id);
komentarController.clear();
await _bloc.fetchKomentarPostingKegiatanList(_namaLokasi, widget.kegiatan.id); // ganti widget.x.id // sudah
komentarKegiatanController.clear();
} else {
failedDialog(context);
}
......@@ -521,7 +470,7 @@ class _DetailPostKegiatanPageState extends State<DetailPostKegiatanPage> {
});
}
Widget komentarPlaceHolder(String name, DateTime date, String description) {
Widget komentarKegiatanPlaceHolder(String name, DateTime created, String description) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
......@@ -545,7 +494,7 @@ class _DetailPostKegiatanPageState extends State<DetailPostKegiatanPage> {
name,
style: const TextStyle(fontSize: 18),
),
Text('${DateFormat('dd MMMM yyy hh:mm').format(date)}',
Text('${DateFormat('dd MMMM yyy hh:mm').format(created)}',
style: const TextStyle(color: grayPrimary, fontSize: 14))
],
),
......@@ -574,54 +523,20 @@ class _DetailPostKegiatanPageState extends State<DetailPostKegiatanPage> {
return initials;
}
// Widget _showIfContains(String disabilitas) {
// String imageUrl;
// switch (disabilitas) {
// case 'DF':
// imageUrl = 'assets/images/DF_I.png';
// break;
// case 'DI':
// imageUrl = 'assets/images/DI_I.png';
// break;
// case 'DM':
// imageUrl = 'assets/images/DM_I.png';
// break;
// case 'DS':
// imageUrl = 'assets/images/DS_I.png';
// break;
// Future<void> _updateInformasi() async {
// final sharedPreferences = await SharedPreferences.getInstance();
// if (sharedPreferences.getString('token') == null) {
// await Navigator.of(context).pushAndRemoveUntil(
// MaterialPageRoute(builder: (BuildContext context) => const Login()),
// (Route<dynamic> route) => false);
// } else {
// await Navigator.of(context).push(MaterialPageRoute(
// builder: (BuildContext context) => UpdateInformasi(
// komentar: widget.komentar, lokasi: widget.lokasi) // ganti modelnya di update_informasi.dart
// ));
// }
// return widget.komentar.disabilitas.toString().contains(disabilitas)
// ? Row(
// children: [
// const SizedBox(
// width: regularSpace,
// ),
// Image.asset(
// imageUrl,
// height: 40,
// key: Key('Icon $disabilitas'),
// ),
// ],
// )
// : const SizedBox(width: 0);
// }
Future<void> _updateInformasi() async {
final sharedPreferences = await SharedPreferences.getInstance();
if (sharedPreferences.getString('token') == null) {
await Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute(builder: (BuildContext context) => const Login()),
(Route<dynamic> route) => false);
} else {
await Navigator.of(context).push(MaterialPageRoute(
builder: (BuildContext context) => UpdateInformasi(
komentar: widget.komentar, lokasi: widget.lokasi)));
}
}
@override
void dispose() {
_bloc.dispose();
......
import 'package:bisaGo/model/komentar_posting_kegiatan.dart';
import 'package:bisaGo/network/network_interface.dart';
abstract class BaseKomentarPostingKegiatanRepository {
Future<KomentarPostingKegiatanList> fetchKomentarPostingKegiatan(String namaLokasi, int id);
Future<dynamic> createKomentarPostingKegiatan(
Map<String, dynamic> newKomentarPostingKegiatanData, String namaLokasi, int id
);
}
class KomentarPostingKegiatanRepository implements BaseKomentarPostingKegiatanRepository {
final NetworkInterface _network = NetworkInterface();
@override
// ganti namaLokasi jd placeId kyaknya
Future<KomentarPostingKegiatanList> fetchKomentarPostingKegiatan(String namaLokasi, int id) async {
final nama = namaLokasi.replaceAll(' ', '%20');
final url =
'/informasi-fasilitas/lokasi/list-kegiatan/$nama/${id.toString()}';
final response = await _network.get(url: url