Skip to content

Commit

Permalink
Merge pull request #5 from Y0ngg4n/dev
Browse files Browse the repository at this point in the history
Fix nginx errors
  • Loading branch information
Y0ngg4n authored Nov 17, 2021
2 parents 91c6708 + 80b9102 commit c08ec9e
Show file tree
Hide file tree
Showing 12 changed files with 216 additions and 142 deletions.
2 changes: 1 addition & 1 deletion lib/auth/google_login_manager_html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class GoogleLoginManagerHtlm implements GoogleLoginManager {
BrowserOAuth2Flow flow = await createImplicitBrowserFlow(
ClientId(webClientId, webClientSecret), scopes);
AccessCredentials accessCredentials =
await flow.obtainAccessCredentialsViaUserConsent();
await flow.obtainAccessCredentialsViaUserConsent(hostedDomain: "volteuropa.org");
flow.close();
return AccessedCredentials(
AccessedToken(
Expand Down
19 changes: 10 additions & 9 deletions lib/drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -319,17 +319,16 @@ class _DrawerViewState extends State<DrawerView> {

_refreshPlacemarks() async {
double radius =
(prefs.get(SharedPrefsSlugs.posterRadius) ?? 100.0) as double;
(prefs.get(SharedPrefsSlugs.posterRadius) ?? 100.0) as double;
bool loadAll = (prefs.get(SharedPrefsSlugs.posterLoadAll) ?? false) as bool;
PlacemarkModels placemarkModels;
if (loadAll) {
placemarkModels = await PlacemarkApiUtils.getAllPlacemarks(widget.apiToken) ??
PlacemarkModels.empty();
placemarkModels =
await PlacemarkApiUtils.getAllPlacemarks(widget.apiToken) ??
PlacemarkModels.empty();
} else {
placemarkModels = await PlacemarkApiUtils.getPlacemarksInDistance(
currentPosition,
radius,
widget.apiToken) ??
currentPosition, radius, widget.apiToken) ??
PlacemarkModels.empty();
}
setState(() {
Expand All @@ -350,7 +349,7 @@ class _DrawerViewState extends State<DrawerView> {

if (loadAll) {
posterModels = await PosterApiUtils.getAllPosters(
radius, hanging, widget.apiToken) ??
radius, hanging, widget.apiToken, context) ??
PosterModels.empty();
} else {
if (customDateSwitch) {
Expand All @@ -359,15 +358,17 @@ class _DrawerViewState extends State<DrawerView> {
radius,
hanging,
customDate,
widget.apiToken) ??
widget.apiToken,
context) ??
PosterModels.empty();
} else {
posterModels = await PosterApiUtils.getPostersInDistance(
currentPosition,
radius,
hanging,
DateTime.fromMicrosecondsSinceEpoch(0).toString(),
widget.apiToken) ??
widget.apiToken,
context) ??
PosterModels.empty();
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/map/areas/add_area_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class _AddAreaMapState extends State<AddAreaMap> {
body: jsonEncode({
'id': widget.id,
'name': widget.name,
'max_poster': widget.maxPosterCount,
'maxPoster': widget.maxPosterCount,
'points': points,
}));
if (response.statusCode == 201) {
Expand Down
4 changes: 4 additions & 0 deletions lib/map/flyer/flyer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:geolocator/geolocator.dart';
import 'package:latlong2/latlong.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_location_marker/flutter_map_location_marker.dart';
import 'package:volt_campaigner/auth/login.dart';
import 'package:volt_campaigner/drawer.dart';
import 'package:volt_campaigner/map/map_search.dart';
import 'package:volt_campaigner/map/map_settings.dart';
Expand Down Expand Up @@ -290,6 +291,9 @@ class FlyerState extends State<Flyer> {
body: jsonEncode({"id": ownUUID, "polyline": points}));
if (response.statusCode == 201) {
print("Upserted Route");
}else if (response.statusCode == 403) {
Navigator.of(context).pushReplacement(
MaterialPageRoute(builder: (context) => LoginView()));
} else {
print("Could not add route");
print(response.body);
Expand Down
80 changes: 31 additions & 49 deletions lib/map/poster/add_poster.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:http/http.dart' as http;
import 'package:volt_campaigner/utils/api/model/poster.dart';
import 'package:volt_campaigner/utils/api/poster.dart';
import 'package:volt_campaigner/utils/http_utils.dart';
import 'package:latlong2/latlong.dart';
import 'package:shared_preferences/shared_preferences.dart';
Expand All @@ -26,17 +27,17 @@ class AddPoster extends StatefulWidget {
PosterModel? preset;
bool placeMarkerByHand;

AddPoster({
Key? key,
required this.posterTagsLists,
required this.location,
required this.onAddPoster,
required this.centerLocation,
required this.campaignTags,
required this.apiToken,
this.preset,
required this.placeMarkerByHand
}) : super(key: key);
AddPoster(
{Key? key,
required this.posterTagsLists,
required this.location,
required this.onAddPoster,
required this.centerLocation,
required this.campaignTags,
required this.apiToken,
this.preset,
required this.placeMarkerByHand})
: super(key: key);

@override
_AddPosterState createState() => _AddPosterState();
Expand All @@ -52,11 +53,13 @@ class _AddPosterState extends State<AddPoster> {
@override
void initState() {
super.initState();
if(widget.preset != null){
if (widget.preset != null) {
selectedPosterTypes = widget.preset!.posterTagsLists.posterType;
selectedMotiveTypes = widget.preset!.posterTagsLists.posterMotive;
selectedTargetGroupTypes = widget.preset!.posterTagsLists.posterTargetGroups;
selectedEnvironmentTypes = widget.preset!.posterTagsLists.posterEnvironment;
selectedTargetGroupTypes =
widget.preset!.posterTagsLists.posterTargetGroups;
selectedEnvironmentTypes =
widget.preset!.posterTagsLists.posterEnvironment;
selectedOtherTypes = widget.preset!.posterTagsLists.posterOther;
}
}
Expand Down Expand Up @@ -124,7 +127,20 @@ class _AddPosterState extends State<AddPoster> {
child: Padding(
padding: EdgeInsets.symmetric(vertical: 4, horizontal: 4),
child: ElevatedButton(
onPressed: _addPoster,
onPressed: () => PosterApiUtils.addPoster(
widget.apiToken,
widget.placeMarkerByHand
? widget.centerLocation
: widget.location,
PosterTagsLists(
widget.campaignTags.posterTags,
selectedPosterTypes,
selectedMotiveTypes,
selectedTargetGroupTypes,
selectedEnvironmentTypes,
selectedOtherTypes),
(poster) => widget.onAddPoster(poster),
context),
child: Row(
children: [
Icon(Icons.save),
Expand Down Expand Up @@ -152,38 +168,4 @@ class _AddPosterState extends State<AddPoster> {
PosterSettings.onTagSelected(p, selectedPosterTags, multiple);
});
}

_addPoster() async {
try {
http.Response response = await http.post(
Uri.parse((dotenv.env['REST_API_URL']!) + "/poster/create"),
headers: HttpUtils.createHeader(widget.apiToken),
body: jsonEncode({
'latitude': widget.placeMarkerByHand
? widget.centerLocation.latitude
: widget.location.latitude,
'longitude': widget.placeMarkerByHand
? widget.centerLocation.longitude
: widget.location.longitude,
'campaign':
widget.campaignTags.posterTags.map((e) => e.id).toList(),
'poster_type': selectedPosterTypes.map((e) => e.id).toList(),
'motive': selectedMotiveTypes.map((e) => e.id).toList(),
'target_groups': selectedTargetGroupTypes.map((e) => e.id).toList(),
'environment': selectedEnvironmentTypes.map((e) => e.id).toList(),
'other': selectedOtherTypes.map((e) => e.id).toList()
}));
if (response.statusCode == 201) {
widget.onAddPoster(PosterModel.fromJson(jsonDecode(response.body)));
Navigator.pop(context);
} else {
Messenger.showError(
context, AppLocalizations.of(context)!.errorAddPoster);
}
} catch (e) {
print(e);
Messenger.showError(
context, AppLocalizations.of(context)!.errorAddPoster);
}
}
}
75 changes: 23 additions & 52 deletions lib/map/poster/update_poster.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:http/http.dart' as http;
import 'package:volt_campaigner/utils/api/model/poster.dart';
import 'package:volt_campaigner/utils/api/poster.dart';
import 'package:volt_campaigner/utils/http_utils.dart';
import 'package:latlong2/latlong.dart';
import 'package:flutter_map/flutter_map.dart';
Expand Down Expand Up @@ -76,6 +77,7 @@ class _UpdatePosterState extends State<UpdatePoster> {

@override
Widget build(BuildContext context) {

return Scaffold(
appBar: AppBar(title: Text(AppLocalizations.of(context)!.posterEdit)),
body: Stack(
Expand Down Expand Up @@ -139,8 +141,7 @@ class _UpdatePosterState extends State<UpdatePoster> {
Padding(
padding: EdgeInsets.symmetric(vertical: 4, horizontal: 4),
child: OutlinedButton(
onPressed: () =>
_updatePoster(widget.selectedPoster, 2),
onPressed: () => _onUpdatePoster(2),
child: Row(
children: [
Icon(Icons.repeat),
Expand All @@ -158,8 +159,7 @@ class _UpdatePosterState extends State<UpdatePoster> {
Padding(
padding: EdgeInsets.symmetric(vertical: 4, horizontal: 4),
child: OutlinedButton(
onPressed: () =>
_updatePoster(widget.selectedPoster, 1),
onPressed: () => _onUpdatePoster(1),
child: Row(
children: [
Icon(Icons.delete),
Expand All @@ -177,8 +177,7 @@ class _UpdatePosterState extends State<UpdatePoster> {
Padding(
padding: EdgeInsets.symmetric(vertical: 4, horizontal: 4),
child: ElevatedButton(
onPressed: () =>
_updatePoster(widget.selectedPoster, 0),
onPressed: () => _onUpdatePoster(0),
child: Row(
children: [
Icon(Icons.save),
Expand All @@ -202,56 +201,28 @@ class _UpdatePosterState extends State<UpdatePoster> {
);
}

_onUpdatePoster(int hanging){
PosterTagsLists posterTagsLists = PosterTagsLists(
widget.campaignTags.posterTags,
selectedPosterTypes,
selectedMotiveTypes,
selectedTargetGroupTypes,
selectedEnvironmentTypes,
selectedOtherTypes);
PosterApiUtils.updatePoster(
widget.apiToken,
widget.selectedPoster,
posterTagsLists,
0,
context,
(poster) => widget.onUnhangPoster(poster),
(poster) => widget.onUpdatePoster(poster));
}

_onTagSelected(
PosterTag p, List<PosterTag> selectedPosterTags, bool multiple) {
setState(() {
PosterSettings.onTagSelected(p, selectedPosterTags, multiple);
});
}

_updatePoster(PosterModel posterModel, int hanging) async {
try {
http.Response response = await http.post(
Uri.parse((dotenv.env['REST_API_URL']!) + "/poster/update"),
headers: HttpUtils.createHeader(widget.apiToken),
body: jsonEncode({
'id': posterModel.id,
'campaign':
widget.campaignTags.posterTags.map((e) => e.id).toList(),
'hanging': hanging,
'latitude': widget.location.latitude,
'longitude': widget.location.longitude,
'poster_type': selectedPosterTypes.map((e) => e.id).toList(),
'motive': selectedMotiveTypes.map((e) => e.id).toList(),
'target_groups': selectedTargetGroupTypes.map((e) => e.id).toList(),
'environment': selectedEnvironmentTypes.map((e) => e.id).toList(),
'other': selectedOtherTypes.map((e) => e.id).toList()
}));
if (response.statusCode == 201) {
switch (hanging) {
case 0:
widget.onUpdatePoster(
PosterModel.fromJson(jsonDecode(response.body)));
break;
case 1:
widget.onUnhangPoster(
PosterModel.fromJson(jsonDecode(response.body)));
break;
case 2:
widget.onUnhangPoster(
PosterModel.fromJson(jsonDecode(response.body)));
break;
}
Navigator.pop(context);
} else {
print(response.body);
Messenger.showError(
context, AppLocalizations.of(context)!.errorEditPoster);
}
} catch (e) {
print(e);
Messenger.showError(
context, AppLocalizations.of(context)!.errorEditPoster);
}
}
}
3 changes: 0 additions & 3 deletions lib/map/poster_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,6 @@ class PosterMapViewState extends State<PosterMapView> {
posterModel.posterTagsLists.posterMotive,
widget.posterTagsLists.posterMotive);
}
if (widget.currentPosition == LatLng(0, 0)) {
placeMarkerByHand = true;
}
});
});
}
Expand Down
10 changes: 5 additions & 5 deletions lib/settings/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class _SettingsViewState extends State<SettingsView> {
Slider(
min: 100,
value: posterRadius,
max: 10000,
max: 50000,
divisions: 100,
onChanged: (double value) {
setState(() {
Expand Down Expand Up @@ -466,12 +466,12 @@ class _SettingsViewState extends State<SettingsView> {
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(AppLocalizations.of(context)!.flyerRadius +
_getRadiusPosterText()),
_getRadiusFlyerText()),
),
Slider(
min: 100,
value: flyerRadius,
max: 10000,
max: 50000,
divisions: 100,
onChanged: (double value) {
setState(() {
Expand Down Expand Up @@ -584,12 +584,12 @@ class _SettingsViewState extends State<SettingsView> {
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(AppLocalizations.of(context)!.areasRadius +
_getRadiusPosterText()),
_getRadiusAreasText()),
),
Slider(
min: 100,
value: areasRadius,
max: 10000,
max: 50000,
divisions: 100,
onChanged: (double value) {
setState(() {
Expand Down
6 changes: 3 additions & 3 deletions lib/utils/api/area.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AreaApiUtils {
"latitude": location.latitude.toString(),
"longitude": location.longitude.toString(),
"distance": distance.toString(),
"last_update": last_update,
"lastupdate": last_update,
"authorization": AuthApiUtils.getBearerToken(apiToken)
});
if (response.statusCode == 200) {
Expand All @@ -43,7 +43,7 @@ class AreaApiUtils {
"accept": "application/json",
"latitude": location.latitude.toString(),
"longitude": location.longitude.toString(),
"last_update": last_update,
"lastupdate": last_update,
"authorization": AuthApiUtils.getBearerToken(apiToken)
});
if (response.statusCode == 200) {
Expand Down Expand Up @@ -87,7 +87,7 @@ class AreaApiUtils {
"accept": "application/json",
"latitude": location.latitude.toString(),
"longitude": location.longitude.toString(),
"last_update": last_update,
"lastupdate": last_update,
"authorization": AuthApiUtils.getBearerToken(apiToken)
});
if (response.statusCode == 200) {
Expand Down
Loading

0 comments on commit c08ec9e

Please sign in to comment.