Skip to content

Commit

Permalink
Merge pull request #37 from thaidmfinnick/develop
Browse files Browse the repository at this point in the history
build: 0.0.1+13
  • Loading branch information
thaidmfinnick authored Dec 30, 2024
2 parents 84c1108 + a2229d4 commit 2f4847b
Show file tree
Hide file tree
Showing 24 changed files with 848 additions and 126 deletions.
13 changes: 12 additions & 1 deletion api/lib/cecr_unwomen_web/controllers/user_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,25 @@ defmodule CecrUnwomenWeb.UserController do

def update_info(conn, params) do
user_id = conn.assigns.user.user_id

response = Repo.get_by(User, id: user_id)
|> case do
nil -> Helper.response_json_message(false, "Không tìm thấy người dùng!", 300)
user ->
keys = ["first_name", "last_name", "date_of_birth", "email", "gender", "location"]
data_changes = Enum.reduce(keys, %{}, fn key, acc ->
key_atom = String.to_atom(key)
if params[key], do: Map.put(acc, key_atom, params[key]), else: acc
value = case key do
"date_of_birth" ->
if (!is_nil(params[key])) do
String.split(params[key], "T")
|> List.first()
|> Date.from_iso8601!()
end

_ -> params[key]
end
if params[key], do: Map.put(acc, key_atom, value), else: acc
end)
Ecto.Changeset.change(user, data_changes)
|> Repo.update
Expand Down
21 changes: 15 additions & 6 deletions mobile/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -496,9 +496,11 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 4;
DEVELOPMENT_TEAM = PHG66TGA97;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = PHG66TGA97;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = WazNet;
Expand All @@ -512,6 +514,7 @@
PRODUCT_BUNDLE_IDENTIFIER = vn.sparc.waznet;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = build_testflight_waznet;
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_VERSION = 5.0;
VERSIONING_SYSTEM = "apple-generic";
Expand Down Expand Up @@ -688,9 +691,11 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 4;
DEVELOPMENT_TEAM = PHG66TGA97;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = PHG66TGA97;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = WazNet;
Expand All @@ -704,6 +709,7 @@
PRODUCT_BUNDLE_IDENTIFIER = vn.sparc.waznet;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = build_testflight_waznet;
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
Expand All @@ -720,9 +726,11 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 4;
DEVELOPMENT_TEAM = PHG66TGA97;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = PHG66TGA97;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = WazNet;
Expand All @@ -736,6 +744,7 @@
PRODUCT_BUNDLE_IDENTIFIER = vn.sparc.waznet;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = build_testflight_waznet;
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_VERSION = 5.0;
VERSIONING_SYSTEM = "apple-generic";
Expand Down
3 changes: 3 additions & 0 deletions mobile/lib/constants/color_constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,7 @@ class ColorConstants {
// letterSpacing: 0.1
);
}

TextStyle placeholderStyle() => fastStyle(14, FontWeight.w400, textPlaceholder);
TextStyle highlightPlaceHolderStyle() => fastStyle(14, FontWeight.w500, textSubHeader);
}
10 changes: 10 additions & 0 deletions mobile/lib/features/authentication/bloc/authentication_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class AuthenticationBloc extends Bloc<AuthenticationEvent, AuthenticationState>
on<AuthSubscription>(_onAuthSubscription);
on<LogoutRequest>(_onLogoutRequest);
on<AutoLogin>(_onAutoLogin);
on<UpdateInfo>(_onUpdateInfo);
}

Future<void> _onAuthSubscription(AuthSubscription event, Emitter emit) async {
Expand Down Expand Up @@ -59,4 +60,13 @@ class AuthenticationBloc extends Bloc<AuthenticationEvent, AuthenticationState>
emit(state.copyWith(status: AuthenticationStatus.error));
}
}

Future<void> _onUpdateInfo(UpdateInfo event, Emitter emit) async {
try {
emit(state.copyWith(status: AuthenticationStatus.authorized, user: event.user));
} catch (e) {
print('udpate into :$e');
emit(state.copyWith(status: AuthenticationStatus.error));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
abstract class AuthenticationEvent {}
import 'package:cecr_unwomen/features/authentication/models/user.dart';
import 'package:equatable/equatable.dart';

abstract class AuthenticationEvent extends Equatable {
@override
List<Object> get props => [];
}

class AuthSubscription extends AuthenticationEvent {}

class LogoutRequest extends AuthenticationEvent {}

class AutoLogin extends AuthenticationEvent {}

class UpdateInfo extends AuthenticationEvent {
final User user;

UpdateInfo(this.user);

@override
List<Object> get props => [user];
}


Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:cecr_unwomen/features/authentication/models/user.dart';
import 'package:equatable/equatable.dart';

enum AuthenticationStatus { unknown, authorized, unauthorized, loading, error }
enum AuthenticationStatus { unknown, authorized, unauthorized, loading, error}

class AuthenticationState extends Equatable {
const AuthenticationState({
Expand All @@ -23,5 +23,5 @@ class AuthenticationState extends Equatable {
}

@override
List<Object> get props => [status];
List<Object?> get props => [status, user];
}
63 changes: 56 additions & 7 deletions mobile/lib/features/authentication/models/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class User extends Equatable {
final String lastName;
final String? email;
final String phoneNumber;
final int? dateOfBirth;
final DateTime? dateOfBirth;
final String? avatarUrl;
final Gender gender;
final int roleId;
Expand All @@ -31,9 +31,11 @@ class User extends Equatable {
lastName: json["last_name"],
email: json["email"] ?? "",
phoneNumber: json["phone_number"],
dateOfBirth: json["date_of_birth"],
dateOfBirth: json["date_of_birth"] != null
? DateTime.tryParse(json["date_of_birth"])
: null,
avatarUrl: json["avatar_url"],
gender: _getGenderBasedOnInt(json["gender"]),
gender: getGenderBasedOnInt(json["gender"]),
roleId: json["role_id"],
location: json["location"]
);
Expand All @@ -44,25 +46,72 @@ class User extends Equatable {
"last_name": lastName,
"email": email,
"phone_number": phoneNumber,
"birth": dateOfBirth,
"gender": gender,
"date_of_birth": dateOfBirth?.toIso8601String(),
"gender": convertGenderToInt(gender),
"avatar_url": avatarUrl,
"role_id": roleId,
"location": location
};

User clone(Map data) => User.fromJson(data);

User copyWith({
String? id,
String? firstName,
String? lastName,
String? email,
String? phoneNumber,
DateTime? dateOfBirth,
String? avatarUrl,
Gender? gender,
int? roleId,
String? location,
}) {
return User(
id: id ?? this.id,
firstName: firstName ?? this.firstName,
lastName: lastName ?? this.lastName,
email: email ?? this.email,
phoneNumber: phoneNumber ?? this.phoneNumber,
dateOfBirth: dateOfBirth ?? this.dateOfBirth,
avatarUrl: avatarUrl ?? this.avatarUrl,
gender: gender ?? this.gender,
roleId: roleId ?? this.roleId,
location: location ?? this.location,
);
}


@override
List<Object?> get props => [];
List<Object?> get props => [
id, firstName, lastName, email, phoneNumber, dateOfBirth, avatarUrl, gender, roleId, location
];
}

enum Gender {
male, female, other
}

Gender _getGenderBasedOnInt(int? gender) {
int convertGenderToInt(Gender gender) {
switch (gender) {
case Gender.male: return 1;
case Gender.female: return 2;
default: return 0;
}
}

Gender getGenderBasedOnInt(int? gender) {
switch (gender) {
case 1: return Gender.male;
case 2: return Gender.female;
default: return Gender.other;
}
}

String convertGenderToString(Gender gender) {
switch (gender) {
case Gender.male: return "Nam";
case Gender.female: return "Nữ";
default: return "Không xác định";
}
}
5 changes: 1 addition & 4 deletions mobile/lib/features/home/view/contribution_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -629,10 +629,7 @@ class _UserContributionWidgetState extends State<UserContributionWidget> {
}

num countTotal() {
return widget.oneDayData.entries.fold(0, (previousValue, element) {
if (!element.key.contains("reduced")) return previousValue;
return previousValue + element.value;
});
return widget.oneDayData["kg_co2e_reduced"] ?? 0;
}

String? getAvatarUrl() {
Expand Down
39 changes: 22 additions & 17 deletions mobile/lib/features/home/view/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:cecr_unwomen/features/home/view/component/header_widget.dart';
import 'package:cecr_unwomen/features/home/view/component/tab_bar_widget.dart';
import 'package:cecr_unwomen/features/home/view/contribution_screen.dart';
import 'package:cecr_unwomen/features/home/view/statistic_screen.dart';
import 'package:cecr_unwomen/features/home/view/user_info.dart';
import 'package:cecr_unwomen/features/user/view/user_info.dart';
import 'package:cecr_unwomen/temp_api.dart';
import 'package:cecr_unwomen/utils.dart';
import 'package:cecr_unwomen/widgets/circle_avatar.dart';
Expand Down Expand Up @@ -236,7 +236,12 @@ class _HomeScreenState extends State<HomeScreen> {
..add(OpenMessageTerminated())
..add(ReceiveMessageForeground()),
child: _currentIndex == 0 ? adminWidget
: _currentIndex == 1 ? StatisticScreen(householdStatisticData: householdData["statistic"] ?? {}, scraperStatisticData: scraperData["statistic"] ?? {})
: _currentIndex == 1 ?
StatisticScreen(
householdStatisticData: householdData["statistic"] ?? {},
scraperStatisticData: scraperData["statistic"] ?? {},
roleId: roleId,
)
: const UserInfo(),
),
);
Expand All @@ -259,6 +264,21 @@ class CardInfoWidget extends StatelessWidget {
),
child: Stack(
children: [
Positioned(
right: -5,
bottom: -20,
child: ShaderMask(
shaderCallback: (Rect bounds) {
return const LinearGradient(
colors: [Color(0xFFFFFCF0), Color(0xFFC8E6C9)], // Define your gradient colors here
tileMode: TileMode.clamp,
begin: Alignment.centerLeft,
end: Alignment.bottomRight,
).createShader(bounds);
},
child: icon
),
),
Container(
padding: const EdgeInsets.all(14),
child: Column(
Expand All @@ -278,21 +298,6 @@ class CardInfoWidget extends StatelessWidget {
],
),
),
Positioned(
right: -5,
bottom: -20,
child: ShaderMask(
shaderCallback: (Rect bounds) {
return const LinearGradient(
colors: [Color(0xFFFFFCF0), Color(0xFFC8E6C9)], // Define your gradient colors here
tileMode: TileMode.clamp,
begin: Alignment.centerLeft,
end: Alignment.bottomRight,
).createShader(bounds);
},
child: icon
),
),
],
),
);
Expand Down
12 changes: 8 additions & 4 deletions mobile/lib/features/home/view/statistic_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import 'package:flutter/material.dart';
import 'package:phosphor_flutter/phosphor_flutter.dart';

class StatisticScreen extends StatefulWidget {
const StatisticScreen({super.key, required this.householdStatisticData, required this.scraperStatisticData});
const StatisticScreen({super.key, required this.householdStatisticData, required this.scraperStatisticData, required this.roleId});
final Map householdStatisticData;
final Map scraperStatisticData;
final int roleId;

@override
State<StatisticScreen> createState() => _StatisticScreenState();
Expand All @@ -27,7 +28,11 @@ class _StatisticScreenState extends State<StatisticScreen> {

@override
Widget build(BuildContext context) {
final Map allData = isHouseholdTab ? (widget.householdStatisticData) : (widget.scraperStatisticData);
final Map allData = widget.roleId == 1 ?
isHouseholdTab ? (widget.householdStatisticData) : (widget.scraperStatisticData)
: widget.roleId == 2 ? (widget.householdStatisticData)
: widget.roleId == 3 ? (widget.scraperStatisticData)
: {};
return Column(
children: [
HeaderWidget(
Expand Down Expand Up @@ -58,8 +63,7 @@ class _StatisticScreenState extends State<StatisticScreen> {
BarWidget(isHousehold: isHouseholdTab, changeBar: changeBar),
if (allData["overall_data_one_month"] != null && allData["overall_data_one_month"].isNotEmpty)
...allData["overall_data_one_month"].map((e) {
final int roleIdUser = isHouseholdTab ? 2 : 3;
return UserContributionWidget(oneDayData: {...e, "role_id": roleIdUser});
return UserContributionWidget(oneDayData: {...e, "role_id": widget.roleId});
}).toList()
else
const Center(
Expand Down
Loading

0 comments on commit 2f4847b

Please sign in to comment.