From 0185005ef101e0c0702036432878bb22fd342839 Mon Sep 17 00:00:00 2001 From: PGAN-MIS Date: Tue, 7 Feb 2023 09:29:38 +0800 Subject: [PATCH] integrated work history API --- lib/model/profile/educational_background.dart | 145 ++++++++++++++++ lib/model/profile/profileInfomation.dart | 6 +- lib/model/profile/work_history.dart | 157 ++++++++++++++++++ .../profile/components/education_screen.dart | 71 ++++++++ .../components/work_history_screen.dart | 59 +++++++ lib/screens/profile/profile.dart | 14 +- lib/sevices/profile/profile_service.dart | 86 ++++++---- 7 files changed, 503 insertions(+), 35 deletions(-) create mode 100644 lib/model/profile/educational_background.dart create mode 100644 lib/model/profile/work_history.dart create mode 100644 lib/screens/profile/components/education_screen.dart create mode 100644 lib/screens/profile/components/work_history_screen.dart diff --git a/lib/model/profile/educational_background.dart b/lib/model/profile/educational_background.dart new file mode 100644 index 0000000..83c2086 --- /dev/null +++ b/lib/model/profile/educational_background.dart @@ -0,0 +1,145 @@ +// To parse this JSON data, do +// +// final educationalBackground = educationalBackgroundFromJson(jsonString); + +import 'dart:convert'; + +EducationalBackground educationalBackgroundFromJson(String str) => EducationalBackground.fromJson(json.decode(str)); + +String educationalBackgroundToJson(EducationalBackground data) => json.encode(data.toJson()); + +class EducationalBackground { + EducationalBackground({ + this.id, + this.honors, + this.education, + this.periodTo, + this.attachments, + this.periodFrom, + this.unitsEarned, + this.yearGraduated, + }); + + final int? id; + final List? honors; + final Education? education; + final String? periodTo; + final dynamic attachments; + final String? periodFrom; + final dynamic unitsEarned; + final String? yearGraduated; + + factory EducationalBackground.fromJson(Map json) => EducationalBackground( + id: json["id"], + honors: json["honors"] == null ? [] : List.from(json["honors"]!.map((x) => Honor.fromJson(x))), + education: json["education"] == null ? null : Education.fromJson(json["education"]), + periodTo: json["period_to"], + attachments: json["attachments"], + periodFrom: json["period_from"], + unitsEarned: json["units_earned"], + yearGraduated: json["year_graduated"], + ); + + Map toJson() => { + "id": id, + "honors": honors == null ? [] : List.from(honors!.map((x) => x.toJson())), + "education": education?.toJson(), + "period_to": periodTo, + "attachments": attachments, + "period_from": periodFrom, + "units_earned": unitsEarned, + "year_graduated": yearGraduated, + }; +} + +class Education { + Education({ + this.id, + this.level, + this.course, + this.school, + }); + + final int? id; + final String? level; + final Course? course; + final School? school; + + factory Education.fromJson(Map json) => Education( + id: json["id"], + level: json["level"], + course: json["course"] == null ? null : Course.fromJson(json["course"]), + school: json["school"] == null ? null : School.fromJson(json["school"]), + ); + + Map toJson() => { + "id": id, + "level": level, + "course": course?.toJson(), + "school": school?.toJson(), + }; +} + +class Course { + Course({ + this.id, + this.program, + }); + + final int? id; + final String? program; + + factory Course.fromJson(Map json) => Course( + id: json["id"], + program: json["program"], + ); + + Map toJson() => { + "id": id, + "program": program, + }; +} + +class School { + School({ + this.id, + this.name, + }); + + final int? id; + final String? name; + + factory School.fromJson(Map json) => School( + id: json["id"], + name: json["name"], + ); + + Map toJson() => { + "id": id, + "name": name, + }; +} + +class Honor { + Honor({ + this.id, + this.name, + this.academ, + }); + + final int? id; + final String? name; + final bool? academ; + + factory Honor.fromJson(Map json) => Honor( + id: json["id"], + name: json["name"], + academ: json["academ"], + ); + + Map toJson() => { + "id": id, + "name": name, + "academ": academ, + }; +} diff --git a/lib/model/profile/profileInfomation.dart b/lib/model/profile/profileInfomation.dart index 1e7fa36..d05987f 100644 --- a/lib/model/profile/profileInfomation.dart +++ b/lib/model/profile/profileInfomation.dart @@ -1,13 +1,17 @@ import 'package:unit2/model/profile/basic_info.dart'; import 'package:unit2/model/profile/basic_information/primary-information.dart'; +import 'package:unit2/model/profile/educational_background.dart'; import 'package:unit2/model/profile/eligibility.dart'; import 'package:unit2/model/profile/learning_development.dart'; import 'package:unit2/model/profile/references.dart'; +import 'package:unit2/model/profile/work_history.dart'; class ProfileInformation{ BasicInfo basicInfo; List eligibilities; List references; List learningsAndDevelopment; - ProfileInformation({required this.basicInfo,required this.eligibilities,required this.references, required this.learningsAndDevelopment}); + List educationalBackgrounds; + ListworkExperiences; + ProfileInformation({required this.workExperiences, required this.basicInfo,required this.eligibilities,required this.references, required this.learningsAndDevelopment,required this.educationalBackgrounds}); } \ No newline at end of file diff --git a/lib/model/profile/work_history.dart b/lib/model/profile/work_history.dart new file mode 100644 index 0000000..3fbd78d --- /dev/null +++ b/lib/model/profile/work_history.dart @@ -0,0 +1,157 @@ +// To parse this JSON data, do +// +// final workHistory = workHistoryFromJson(jsonString); + +import 'dart:convert'; + +WorkHistory workHistoryFromJson(String str) => WorkHistory.fromJson(json.decode(str)); + +String workHistoryToJson(WorkHistory data) => json.encode(data.toJson()); + +class WorkHistory { + WorkHistory({ + this.id, + this.agency, + this.sgStep, + this.toDate, + this.position, + this.fromDate, + // this.attachments, + this.salaryGrade, + this.monthlySalary, + this.appointmentStatus, + }); + + final int? id; + final Agency? agency; + final int? sgStep; + final DateTime? toDate; + final Position? position; + final DateTime? fromDate; + // final dynamic attachments; + final int? salaryGrade; + final int? monthlySalary; + final String? appointmentStatus; + + factory WorkHistory.fromJson(Map json) => WorkHistory( + id: json["id"], + agency: json["agency"] == null ? null : Agency.fromJson(json["agency"]), + sgStep: json["sg_step"], + toDate: json["to_date"] == null ? null : DateTime.parse(json["to_date"]), + position: json["position"] == null ? null : Position.fromJson(json["position"]), + fromDate: json["from_date"] == null ? null : DateTime.parse(json["from_date"]), + // attachments: json["attachments"], + salaryGrade: json["salary_grade"], + monthlySalary: json["monthly_salary"], + appointmentStatus: json["appointment_status"], + ); + + Map toJson() => { + "id": id, + "agency": agency?.toJson(), + "sg_step": sgStep, + "to_date": "${toDate!.year.toString().padLeft(4, '0')}-${toDate!.month.toString().padLeft(2, '0')}-${toDate!.day.toString().padLeft(2, '0')}", + "position": position?.toJson(), + "from_date": "${fromDate!.year.toString().padLeft(4, '0')}-${fromDate!.month.toString().padLeft(2, '0')}-${fromDate!.day.toString().padLeft(2, '0')}", + // "attachments": attachments, + "salary_grade": salaryGrade, + "monthly_salary": monthlySalary, + "appointment_status": appointmentStatus, + }; +} + +class Agency { + Agency({ + this.id, + this.name, + this.category, + this.privateEntity, + }); + + final int? id; + final String? name; + final Category? category; + final bool? privateEntity; + + factory Agency.fromJson(Map json) => Agency( + id: json["id"], + name: json["name"], + category: json["category"] == null ? null : Category.fromJson(json["category"]), + privateEntity: json["private_entity"], + ); + + Map toJson() => { + "id": id, + "name": name, + "category": category?.toJson(), + "private_entity": privateEntity, + }; +} + +class Category { + Category({ + this.id, + this.name, + this.industryClass, + }); + + final int? id; + final String? name; + final IndustryClass? industryClass; + + factory Category.fromJson(Map json) => Category( + id: json["id"], + name: json["name"], + industryClass: json["industry_class"] == null ? null : IndustryClass.fromJson(json["industry_class"]), + ); + + Map toJson() => { + "id": id, + "name": name, + "industry_class": industryClass?.toJson(), + }; +} + +class IndustryClass { + IndustryClass({ + this.id, + this.name, + this.description, + }); + + final int? id; + final String? name; + final dynamic description; + + factory IndustryClass.fromJson(Map json) => IndustryClass( + id: json["id"], + name: json["name"], + description: json["description"], + ); + + Map toJson() => { + "id": id, + "name": name, + "description": description, + }; +} + +class Position { + Position({ + this.id, + this.title, + }); + + final int? id; + final String? title; + + factory Position.fromJson(Map json) => Position( + id: json["id"], + title: json["title"], + ); + + Map toJson() => { + "id": id, + "title": title, + }; +} diff --git a/lib/screens/profile/components/education_screen.dart b/lib/screens/profile/components/education_screen.dart new file mode 100644 index 0000000..0cd6db4 --- /dev/null +++ b/lib/screens/profile/components/education_screen.dart @@ -0,0 +1,71 @@ +import 'package:flutter/material.dart'; +import 'package:flutter/src/widgets/framework.dart'; +import 'package:flutter/src/widgets/placeholder.dart'; +import 'package:unit2/model/profile/educational_background.dart'; +import 'package:unit2/theme-data.dart/colors.dart'; + +class EducationScreen extends StatefulWidget { + final List educationBackgrounds; + const EducationScreen({super.key, required this.educationBackgrounds}); + + @override + State createState() => _EducationScreenState(); +} + +class _EducationScreenState extends State { + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text("Educational Background"), + centerTitle: true, + backgroundColor: primary, + ), + body: ListView.builder( + itemCount: widget.educationBackgrounds.length, + itemBuilder: (BuildContext context, int index) { + String level = widget.educationBackgrounds[index].education!.level!; + String periodFrom = widget.educationBackgrounds[index].periodFrom!; + String periodTo = widget.educationBackgrounds[index].periodTo!; + String? program = widget.educationBackgrounds[index].education!.course == null? null: widget.educationBackgrounds[index].education!.course!.program!; + List? honors = widget.educationBackgrounds[index].honors!.toList(); + String school = widget.educationBackgrounds[index].education!.school!.name!; + return Column( + children: [ + Container( + decoration: BoxDecoration( + color: Colors.grey[200], + borderRadius: + const BorderRadius.all(Radius.circular(12))), + padding: + const EdgeInsets.symmetric(horizontal: 12, vertical: 8), + child: Row( + children: [ + Expanded( + child: Column(children: [ + Row( + children: [ + Text(level), + Text("$periodFrom $periodTo"), + ], + ), + Text(program??=''), + Text(school), + Container( + child: honors.isNotEmpty? Column( + children: honors.map((Honor honor) => Text(honor.name!)).toList(), + ):const SizedBox() + ) + ]), + ), + IconButton( + onPressed: () {}, icon: const Icon(Icons.more_vert)) + ], + ), + ) + ], + ); + }), + ); + } +} diff --git a/lib/screens/profile/components/work_history_screen.dart b/lib/screens/profile/components/work_history_screen.dart new file mode 100644 index 0000000..13442bb --- /dev/null +++ b/lib/screens/profile/components/work_history_screen.dart @@ -0,0 +1,59 @@ +import 'package:flutter/material.dart'; +import 'package:flutter/src/widgets/framework.dart'; +import 'package:flutter/src/widgets/placeholder.dart'; +import 'package:intl/intl.dart'; +import 'package:unit2/model/profile/work_history.dart'; +import 'package:unit2/theme-data.dart/colors.dart'; + +import '../../../utils/global.dart'; + +class WorkHistoryScreen extends StatefulWidget { + final ListworkExperiences; + const WorkHistoryScreen({super.key,required this.workExperiences}); + + @override + State createState() => _WorkHistoryScreenState(); +} + +class _WorkHistoryScreenState extends State { + DateFormat dteFormat2 = DateFormat.yMMMMd('en_US'); + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar(title: const Text("Work History"),backgroundColor: primary,centerTitle: true,), + body: ListView.builder( + itemCount: widget.workExperiences.length, + itemBuilder: (BuildContext context, int index){ + String position = widget.workExperiences[index].position!.title!; + String agency = widget.workExperiences[index].agency!.name!; + String from = dteFormat2.format(widget.workExperiences[index].fromDate!); + String? to = widget.workExperiences[index].toDate == null? "Present" : dteFormat2.format(widget.workExperiences[index].toDate!); + return Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container( + width: screenWidth, + decoration: BoxDecoration( + color: Colors.grey[200], + borderRadius: const BorderRadius.all(Radius.circular(12))), + padding: const EdgeInsets.symmetric(horizontal: 12,vertical: 8), + child: Row(children: [ + Expanded(child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(position), + Text(agency), + Text("$from to $to"), + ],)), + IconButton(onPressed: (){}, icon: const Icon(Icons.more_vert)) + ]), + ), + const SizedBox(height: 5,), + ], + ); + }), + ); + } +} \ No newline at end of file diff --git a/lib/screens/profile/profile.dart b/lib/screens/profile/profile.dart index 3cd5c79..8cea220 100644 --- a/lib/screens/profile/profile.dart +++ b/lib/screens/profile/profile.dart @@ -12,10 +12,12 @@ import 'package:unit2/screens/profile/components/basic_information/citizenship_s import 'package:unit2/screens/profile/components/basic_information/contact_information.dart'; import 'package:unit2/screens/profile/components/basic_information/identification_information.dart'; import 'package:unit2/screens/profile/components/basic_information/primary_information.dart'; +import 'package:unit2/screens/profile/components/education_screen.dart'; import 'package:unit2/screens/profile/components/eligibility.dart'; import 'package:unit2/screens/profile/components/learning_and_development_screen.dart'; import 'package:unit2/screens/profile/components/loading_screen.dart'; import 'package:unit2/screens/profile/components/references_screen.dart'; +import 'package:unit2/screens/profile/components/work_history_screen.dart'; import 'package:unit2/theme-data.dart/colors.dart'; import '../../bloc/user/user_bloc.dart'; import 'components/main_menu.dart'; @@ -116,7 +118,11 @@ class _ProfileInfoState extends State { MainMenu( icon: FontAwesome5.graduation_cap, title: "Education", - onTap: (){}, + onTap: (){ + Navigator.push(context, MaterialPageRoute(builder: (BuildContext context){ + return EducationScreen(educationBackgrounds: state.profileInformation.educationalBackgrounds); + })); + }, ), const Divider(), MainMenu( @@ -132,7 +138,11 @@ class _ProfileInfoState extends State { MainMenu( icon: FontAwesome5.shopping_bag, title: "Work History", - onTap: (){}, + onTap: (){ + Navigator.push(context, MaterialPageRoute(builder: (BuildContext context){ + return WorkHistoryScreen(workExperiences: state.profileInformation.workExperiences); + })); + }, ), const Divider(), MainMenu( diff --git a/lib/sevices/profile/profile_service.dart b/lib/sevices/profile/profile_service.dart index 6f25add..06658f9 100644 --- a/lib/sevices/profile/profile_service.dart +++ b/lib/sevices/profile/profile_service.dart @@ -5,10 +5,12 @@ import 'package:unit2/model/profile/basic_info.dart'; import 'package:unit2/model/profile/basic_information/citizenship.dart'; import 'package:unit2/model/profile/basic_information/contact_information.dart'; import 'package:unit2/model/profile/basic_information/identification_information.dart'; +import 'package:unit2/model/profile/educational_background.dart'; import 'package:unit2/model/profile/eligibility.dart'; import 'package:unit2/model/profile/learning_development.dart'; import 'package:unit2/model/profile/profileInfomation.dart'; import 'package:unit2/model/profile/references.dart'; +import 'package:unit2/model/profile/work_history.dart'; import 'package:unit2/utils/request.dart'; import 'package:unit2/utils/urls.dart'; @@ -21,16 +23,16 @@ class ProfileService { Future getProfile(String token, int id) async { String url = Url.instance.profileInformation(); String path = url + id.toString(); - ProfileInformation? profileInformation0; - List references = []; - ContactInfo contactInfo; - Identification identification; - List identificationInformation =[]; - List contactInformation = []; + ProfileInformation? profileInformation0; PrimaryInformation primaryInformation; + List workExperiences =[]; + List references = []; + List identificationInformation = []; + List contactInformation = []; List eligibilities = []; List citizenships = []; - List learningsDevelopments = []; + List learningsDevelopments = []; + List educationalBackgrounds = []; Map headers = { 'Content-Type': 'application/json; charset=UTF-8', 'Authorization': "Token $token" @@ -39,55 +41,75 @@ class ProfileService { http.Response response = await Request.instance .getRequest(path: path, param: {}, headers: headers); if (response.statusCode == 200) { - Map data = jsonDecode(response.body); + Map data = jsonDecode(response.body); // get primary information primaryInformation = PrimaryInformation.fromJson( data['data']['basic_information']['primary_information']); // get all contacts data['data']['basic_information']['contact_information'] .forEach((var contact) { - contactInfo = ContactInfo.fromJson(contact['contact_info']); + ContactInfo contactInfo = ContactInfo.fromJson(contact['contact_info']); contactInformation.add(contactInfo); }); // get all identifications - data['data']['basic_information']['identification_records'].forEach((var identity){ - identification = Identification.fromJson(identity); + data['data']['basic_information']['identification_records'] + .forEach((var identity) { + Identification identification = Identification.fromJson(identity); identificationInformation.add(identification); }); //get all eligibilities - data['data']['eligibilities'].forEach((var cert){ + data['data']['eligibilities'].forEach((var cert) { EligibityCert eligibility = EligibityCert.fromJson(cert); eligibilities.add(eligibility); }); // get all citizenships - if(data['data']['citizenship']!= null){ - data['data']['citizenships'].forEach((var citizenship){ + if (data['data']['citizenship'] != null) { + data['data']['citizenships'].forEach((var citizenship) { Citizenship person = Citizenship.fromJson(citizenship); citizenships.add(person); - }); + }); } // get all references; - data['data']['personal_references'].forEach((var person){ - PersonalReference reference = PersonalReference.fromJson(person); - references.add(reference); - }); + data['data']['personal_references'].forEach((var person) { + PersonalReference reference = PersonalReference.fromJson(person); + references.add(reference); + }); - //get all learning and developments - - data['data']['learning_development'].forEach((var training){ - LearningDevelopement learnings = LearningDevelopement.fromJson(training); - learningsDevelopments.add(learnings); - }); + //get all learning and developments + data['data']['learning_development'].forEach((var training) { + LearningDevelopement learnings = + LearningDevelopement.fromJson(training); + learningsDevelopments.add(learnings); + }); + //get all educational background + data['data']['education_background'].forEach((var education) { + EducationalBackground educationalBackground = + EducationalBackground.fromJson(education); + educationalBackgrounds.add(educationalBackground); + }); - BasicInfo basicInfo = BasicInfo(contactInformation: contactInformation, - primaryInformation: primaryInformation, - identifications: identificationInformation, - citizenships: citizenships - ); - ProfileInformation profileInformation = ProfileInformation(basicInfo: basicInfo,eligibilities: eligibilities,references: references!,learningsAndDevelopment: learningsDevelopments); - profileInformation0 = profileInformation; + // get all work history + + data['data']['work_experiences'].forEach((var work){ + WorkHistory experience = WorkHistory.fromJson(work); + workExperiences.add(experience); + }); + + BasicInfo basicInfo = BasicInfo( + contactInformation: contactInformation, + primaryInformation: primaryInformation, + identifications: identificationInformation, + citizenships: citizenships); + ProfileInformation profileInformation = ProfileInformation( + workExperiences: workExperiences, + basicInfo: basicInfo, + eligibilities: eligibilities, + references: references, + learningsAndDevelopment: learningsDevelopments, + educationalBackgrounds: educationalBackgrounds); + profileInformation0 = profileInformation; } // }catch(e){ // throw(e.toString());