update reordering
This commit is contained in:
@ -235,6 +235,13 @@ class DestinationController extends GetxController {
|
||||
});
|
||||
}
|
||||
|
||||
void deleteAllDestinations(){
|
||||
DatabaseHelper db = DatabaseHelper.instance;
|
||||
db.deleteAllDestinations().then((value){
|
||||
PopulateDestinations();
|
||||
});
|
||||
}
|
||||
|
||||
// ---------- database ------------------///
|
||||
|
||||
void addDestinations(Destination dest){
|
||||
@ -294,8 +301,11 @@ class DestinationController extends GetxController {
|
||||
}
|
||||
|
||||
|
||||
void makeOrder(String locationId){
|
||||
|
||||
void makeOrder(Destination d, int dir){
|
||||
DatabaseHelper db = DatabaseHelper.instance;
|
||||
db.updateOrder(d, dir).then((value){
|
||||
PopulateDestinations();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -39,14 +39,15 @@ class DestinationMapPage extends StatelessWidget {
|
||||
}
|
||||
|
||||
String getDisplaytext(Destination dp){
|
||||
RegExp regex = RegExp(r'([.]*0)(?!.*\d)');
|
||||
String txt = "";
|
||||
if(dp.cp! > 0){
|
||||
txt = "${dp.cp}";
|
||||
txt = "${dp.cp.toString().replaceAll(regex, '')}";
|
||||
if(dp.checkin_point != null && dp.checkin_point! > 0){
|
||||
txt = txt + "{${dp.checkin_point}}";
|
||||
txt = txt + "{${dp.checkin_point.toString().replaceAll(regex, '')}}";
|
||||
}
|
||||
if(dp.buy_point != null && dp.buy_point! > 0){
|
||||
txt = txt + "[${dp.buy_point}]";
|
||||
txt = txt + "[${dp.buy_point.toString().replaceAll(regex, '')}]";
|
||||
}
|
||||
}
|
||||
return txt;
|
||||
|
||||
@ -70,9 +70,38 @@ class DatabaseHelper{
|
||||
Database db = await instance.database;
|
||||
var dest = await db.delete('destination', where: "location_id = ${location_id}");
|
||||
int ret = dest > 0 ? dest : -1;
|
||||
|
||||
//after deleting set correct order
|
||||
await setOrder();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Future<void>setOrder() async {
|
||||
Database db = await instance.database;
|
||||
var byOrder = await db.query('destination', orderBy: 'list_order');
|
||||
|
||||
List<Destination> des_db = byOrder.isNotEmpty
|
||||
? byOrder.map((e) => Destination.fromMap(e)).toList() : [];
|
||||
|
||||
int order = 1;
|
||||
for( Destination d in des_db){
|
||||
|
||||
Map<String, dynamic> row_target = {
|
||||
"list_order": order
|
||||
};
|
||||
|
||||
await db.update(
|
||||
"destination",
|
||||
row_target,
|
||||
where: 'location_id = ?',
|
||||
whereArgs: [d.location_id]
|
||||
);
|
||||
|
||||
order += 1;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deleteAllDestinations() async {
|
||||
Database db = await instance.database;
|
||||
await db.delete('destination');
|
||||
@ -117,6 +146,10 @@ class DatabaseHelper{
|
||||
Database db = await instance.database;
|
||||
var target = await db.query('destination', where: "list_order = ${d.list_order! + dir}");
|
||||
var dest = await db.query('destination', where: "location_id = ${d.location_id}");
|
||||
|
||||
print("--- target in db is ${target}");
|
||||
print("--- destine in db is ${dest}");
|
||||
|
||||
if(target.isNotEmpty){
|
||||
|
||||
List<Destination> target_indb = target.isNotEmpty
|
||||
@ -130,9 +163,12 @@ class DatabaseHelper{
|
||||
};
|
||||
|
||||
Map<String, dynamic> row_des = {
|
||||
"list_order": dest_indb[0].list_order
|
||||
"list_order": dest_indb[0].list_order! + dir
|
||||
};
|
||||
|
||||
// print("--- target destination is ${target_indb[0].location_id}");
|
||||
// print("--- destine destination is is ${dest_indb[0].location_id}");
|
||||
|
||||
await db.update(
|
||||
"destination",
|
||||
row_target,
|
||||
|
||||
@ -35,7 +35,13 @@ class StringValues extends Translations{
|
||||
'select_travel_mode':'Select your travel mode',
|
||||
'walking':'Walking',
|
||||
'driving': 'Driving',
|
||||
'transit': 'Transit'
|
||||
'transit': 'Transit',
|
||||
'are_you_sure_want_to_delete_all' : 'Are you sure want to delete all',
|
||||
'all_added_destination_will_be_deleted' : 'All added destination will be deleted',
|
||||
'confirm': 'Confirm',
|
||||
'cancel': 'Cancel',
|
||||
'all_destinations_are_deleted_successfully' : 'All destinations are deleted successfully',
|
||||
'deleted': "Deleted"
|
||||
},
|
||||
'ja_JP': {
|
||||
'drawer_title':'ロゲイニング参加者はログイン するとチェックポイントが参照 できます',
|
||||
@ -69,9 +75,15 @@ class StringValues extends Translations{
|
||||
'rogaining_user_need_tosign_up': "ロゲイニング参加者はサインアップの必要はありません。",
|
||||
'add_location': '目的地選択',
|
||||
'select_travel_mode':'移動モードを選択してください',
|
||||
'walking':'ウォーキング',
|
||||
'driving': '運転中',
|
||||
'transit': 'トランジット'
|
||||
'walking':'歩行',
|
||||
'driving': '自動車利用',
|
||||
'transit': '公共交通機関利用',
|
||||
'are_you_sure_want_to_delete_all' : '本当にすべて削除しますか',
|
||||
'all_added_destination_will_be_deleted' : '追加したすべての宛先が削除されます',
|
||||
'confirm': '確認',
|
||||
'cancel': 'キャンセル',
|
||||
'all_destinations_are_deleted_successfully' : 'すべての宛先が正常に削除されました',
|
||||
'deleted': "削除された"
|
||||
},
|
||||
};
|
||||
}
|
||||
@ -60,24 +60,57 @@ class DestinationWidget extends StatelessWidget {
|
||||
}
|
||||
|
||||
void moveUp() {
|
||||
for(Destination d in destinationController.destinations){
|
||||
// if(d.selected){
|
||||
|
||||
// }
|
||||
Destination? d = null;
|
||||
for(Destination ad in destinationController.destinations){
|
||||
if(ad.selected == true){
|
||||
d = ad;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(d != null){
|
||||
print("--- selected destination is ${d.list_order}");
|
||||
destinationController.makeOrder(d, -1);
|
||||
}
|
||||
destinationController.destination_index_data.forEach((element) {
|
||||
//print(element["index"]);
|
||||
//int action_id = destinationController.destinations[element["index"]]["id"] as int;
|
||||
//destinationController.makeOrder(action_id, (element["index"] as int) - 1, "up");
|
||||
});
|
||||
}
|
||||
|
||||
void moveDown() {
|
||||
destinationController.destination_index_data.forEach((element) {
|
||||
//print(element["index"]);
|
||||
//int action_id = destinationController.destinations[element["index"]]["id"] as int;
|
||||
//destinationController.makeOrder(action_id, (element["index"] as int) + 1, "up");
|
||||
});
|
||||
Destination? d = null;
|
||||
for(Destination ad in destinationController.destinations){
|
||||
if(ad.selected == true){
|
||||
d = ad;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(d != null){
|
||||
print("--- selected destination is ${d.list_order}");
|
||||
destinationController.makeOrder(d, 1);
|
||||
}
|
||||
}
|
||||
|
||||
void clearall(){
|
||||
Get.defaultDialog(
|
||||
title: "are_you_sure_want_to_delete_all".tr,
|
||||
middleText: "all_added_destination_will_be_deleted".tr,
|
||||
backgroundColor: Colors.blue.shade300,
|
||||
titleStyle: TextStyle(color: Colors.white),
|
||||
middleTextStyle: TextStyle(color: Colors.white),
|
||||
textConfirm: "confirm".tr,
|
||||
textCancel: "cancel".tr,
|
||||
cancelTextColor: Colors.white,
|
||||
confirmTextColor: Colors.blue,
|
||||
buttonColor: Colors.white,
|
||||
barrierDismissible: false,
|
||||
radius: 10,
|
||||
content: Column(
|
||||
children: [
|
||||
],
|
||||
),
|
||||
onConfirm: (){
|
||||
destinationController.deleteAllDestinations();
|
||||
Get.back();
|
||||
Get.snackbar("deleted".tr, "all_destinations_are_deleted_successfully".tr);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void interChange() {
|
||||
@ -148,20 +181,34 @@ class DestinationWidget extends StatelessWidget {
|
||||
},
|
||||
onLongPress: (){
|
||||
|
||||
Destination? match_element = null;
|
||||
destinationController.currentSelectedDestinations.forEach((element) {
|
||||
if(element.location_id == destinationController.destinations[index].location_id){
|
||||
match_element = element;
|
||||
for(Destination d in destinationController.destinations){
|
||||
if(destinationController.currentSelectedDestinations.length > 0){
|
||||
if(destinationController.currentSelectedDestinations[0].location_id == destinationController.destinations[index].location_id){
|
||||
destinationController.currentSelectedDestinations.clear();
|
||||
print("---- fount ----");
|
||||
destinationController.PopulateDestinations();
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
if(match_element != null){
|
||||
destinationController.currentSelectedDestinations.remove(destinationController.destinations[index]);
|
||||
}
|
||||
}
|
||||
|
||||
destinationController.currentSelectedDestinations.clear();
|
||||
destinationController.currentSelectedDestinations.add(destinationController.destinations[index]);
|
||||
|
||||
// Destination? match_element = null;
|
||||
// destinationController.currentSelectedDestinations.forEach((element) {
|
||||
// if(element.location_id == destinationController.destinations[index].location_id){
|
||||
// match_element = element;
|
||||
// return;
|
||||
// }
|
||||
// });
|
||||
|
||||
// if(match_element != null){
|
||||
// destinationController.currentSelectedDestinations.remove(destinationController.destinations[index]);
|
||||
// }
|
||||
// //destinationController.currentSelectedDestinations.clear();
|
||||
// destinationController.currentSelectedDestinations.add(destinationController.destinations[index]);
|
||||
|
||||
destinationController.PopulateDestinations();
|
||||
|
||||
},
|
||||
@ -205,6 +252,11 @@ class DestinationWidget extends StatelessWidget {
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
IconButton(
|
||||
icon:Icon(Icons.delete_forever),
|
||||
//onPressed: (){doDelete();},
|
||||
onPressed: clearall,
|
||||
),
|
||||
IconButton(
|
||||
icon:Icon(Icons.cancel),
|
||||
//onPressed: (){doDelete();},
|
||||
@ -212,16 +264,16 @@ class DestinationWidget extends StatelessWidget {
|
||||
),
|
||||
IconButton(
|
||||
icon:Icon(Icons.move_up),
|
||||
onPressed: destinationController.destination_index_data.length > 0 ? moveUp : null,
|
||||
onPressed: destinationController.currentSelectedDestinations.length > 0 ? moveUp : null,
|
||||
),
|
||||
IconButton(
|
||||
icon:Icon(Icons.move_down),
|
||||
onPressed: destinationController.destination_index_data.length > 0 ? moveDown : null,
|
||||
),
|
||||
IconButton(
|
||||
icon:Icon(Icons.sync),
|
||||
onPressed: destinationController.destination_index_data.length == 2 ? interChange : null,
|
||||
onPressed: destinationController.currentSelectedDestinations.length > 0 ? moveDown : null,
|
||||
),
|
||||
// IconButton(
|
||||
// icon:Icon(Icons.sync),
|
||||
// onPressed: destinationController.destination_index_data.length == 2 ? interChange : null,
|
||||
// ),
|
||||
],
|
||||
),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user