Skip to content

Commit

Permalink
Merge pull request #7 from unimegan59781/could
Browse files Browse the repository at this point in the history
Could requirements
  • Loading branch information
megan59781 authored Apr 24, 2024
2 parents b186578 + f2ba394 commit a7ac377
Show file tree
Hide file tree
Showing 25 changed files with 970 additions and 90 deletions.
Binary file added lib/images/childcare.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/images/default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/images/elderly.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/images/female.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/images/general care.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed lib/images/google_icon.png
Binary file not shown.
Binary file removed lib/images/google_icon1.png
Binary file not shown.
Binary file added lib/images/learning disabilities.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/images/male.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/images/non-binary.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/images/physical disabilities.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
173 changes: 171 additions & 2 deletions lib/pages/company/companyJob.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:firebase_database/firebase_database.dart';
import 'package:flutter/material.dart';
import 'package:fyp/pages/company/companyWorkerList.dart';
import 'package:fyp/templates/displayText.dart';
import 'package:fyp/templates/profileView.dart';
import 'package:fyp/templates/pushBut.dart';
import 'package:geocoding/geocoding.dart';
import 'package:intl/intl.dart';
Expand Down Expand Up @@ -182,6 +183,70 @@ class CompanyJobState extends State<CompanyJob> {
});
}

Future<void> deleteJobDb(String jobId, bool notComplete) async {
dbhandler
.child('Jobs')
.orderByChild('job_id')
.equalTo(jobId)
.onValue
.take(1)
.listen((event) async {
if (event.snapshot.value != null) {
Map<dynamic, dynamic>? data =
event.snapshot.value as Map<dynamic, dynamic>?;
if (data != null) {
// Assuming there is only one entry, you can access it directly
var jobKey = data.keys.first;
dbhandler.child('Jobs').child(jobKey).remove();
}
}
});
dbhandler
.child('Assigned Jobs')
.orderByChild('job_id')
.equalTo(jobId)
.onValue
.take(1)
.listen((event) async {
if (event.snapshot.value != null) {
Map<dynamic, dynamic>? data =
event.snapshot.value as Map<dynamic, dynamic>?;
if (data != null) {
// Assuming there is only one entry, you can access it directly
var assignedJobKey = data.keys.first;
var assignedData = data[assignedJobKey];

bool company = assignedData['company_job_complete'];
bool worker = assignedData['company_job_complete'];

if (company && worker || notComplete) {
dbhandler
.child("Risk Support Plans")
.orderByChild('job_id')
.equalTo(jobId)
.onValue
.take(1)
.listen((event) async {
if (event.snapshot.value != null) {
Map<dynamic, dynamic>? data =
event.snapshot.value as Map<dynamic, dynamic>?;
if (data != null) {
var riskSupportKey = data.keys.first;

dbhandler
.child('Risk Support Plans')
.child(riskSupportKey)
.remove();
}
}
});
dbhandler.child('Assigned Jobs').child(assignedJobKey).remove();
}
}
}
});
}

Future<void> confirmJob(String jobId) async {
dbhandler
.child('Assigned Jobs')
Expand Down Expand Up @@ -250,6 +315,7 @@ class CompanyJobState extends State<CompanyJob> {
onPressed: () {
setState(() {
confirmJob(jobId);
deleteJobDb(jobId, false);
});
Navigator.of(context).pop();
},
Expand Down Expand Up @@ -452,11 +518,109 @@ class CompanyJobState extends State<CompanyJob> {
} else if (riskSupport == false && assigned == true) {
addRiskSupportPlans(context, jobId);
// TO DO: risk support update true
} else if ((today.isAtSameMomentAs(date) &&
(stringTimeToMins(endTime) > ((8 * 60) + stringTimeToMins(now)))) ||
date.isAfter(today)) {
deleteJob(context, jobId);
} else {
// TO DO: error message say waiting for worker to accept
// TO DO: error message
}
}

void deleteJob(BuildContext context, String jobId) async {
showDialog<void>(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text("Delete Job"),
contentPadding: EdgeInsets.zero,
content: const Column(
mainAxisSize: MainAxisSize.min,
children: [
SizedBox(
height: 5,
),
DisplayText(
text: "Are You Sure You Want To Delete This Job?",
fontSize: 20,
colour: Colors.black),
],
),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text('Back'),
),
TextButton(
onPressed: () async {
await deleteJobDb(jobId, true);
Navigator.of(context).pop();
},
child: const Text('Delete'),
),
],
);
},
);
}

Future<void> profileViewer(BuildContext context, String userId) async {
dbhandler
.child('Profiles')
.orderByChild('user_id')
.equalTo(userId)
.onValue
.first
.then((event) async {
if (event.snapshot.value != null) {
Map<dynamic, dynamic>? data =
event.snapshot.value as Map<dynamic, dynamic>?;
if (data != null) {
var pKey = data.keys.first;
var pData = data[pKey];
String name = pData['name'];
String imgPath = pData['img'];
int experience = pData['experience'];
String description = pData['description'];

showDialog<void>(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text("Worker's Profile"),
contentPadding: EdgeInsets.zero,
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
const SizedBox(
height: 5,
),
ProfileView(
name: name,
imgPath: imgPath,
experience: '$experience Years Experience',
description: description,
scale: 2)
],
),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text('Back'),
),
],
);
},
);
}
}
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand Down Expand Up @@ -491,12 +655,17 @@ class CompanyJobState extends State<CompanyJob> {
job['riskSupport']);
});
},
onDoubleTap: () async {
profileViewer(context,
"AIhwMbH3ExbIWVzAITBTBk1GX813"); //job['workerId']);
},
child: Container(
margin: const EdgeInsets.all(5), // between items
padding:
const EdgeInsets.all(10), // space inside item box
decoration: BoxDecoration(
color: pickColour(job['assigned'], job['workerId'], job['riskSupport']),
color: pickColour(job['assigned'], job['workerId'],
job['riskSupport']),
border: Border.all(color: Colors.deepPurple),
borderRadius: BorderRadius.circular(10),
),
Expand Down
7 changes: 7 additions & 0 deletions lib/pages/company/companyNav.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:fyp/pages/Company/CompanyJob.dart';
import 'package:fyp/pages/Company/CompanySettings.dart';
import 'package:fyp/pages/company/companyCreate.dart';
import 'package:fyp/pages/company/companyProfile.dart';

class CompanyNavigationBar extends StatefulWidget {
final String companyId;
Expand All @@ -24,6 +25,7 @@ class CompanyNavigationBarState extends State<CompanyNavigationBar> {
static List<Widget> _widgetOptions(String companyId) => [
CompanyJob(companyId: companyId),
CompanyCreateJob(companyId: companyId),
CompanyProfile(companyId: companyId),
CompanySettings(companyId: companyId),
];

Expand All @@ -41,6 +43,7 @@ class CompanyNavigationBarState extends State<CompanyNavigationBar> {
child: _widgetOptions(companyId)[_selectedIndex],
),
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.work_outline),
Expand All @@ -50,6 +53,10 @@ class CompanyNavigationBarState extends State<CompanyNavigationBar> {
icon: Icon(Icons.add_business_outlined),
label: 'Create Job',
),
BottomNavigationBarItem(
icon: Icon(Icons.person_outline),
label: 'Profile',
),
BottomNavigationBarItem(
icon: Icon(Icons.settings_outlined),
label: 'Settings',
Expand Down
79 changes: 79 additions & 0 deletions lib/pages/company/companyProfile.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import 'package:firebase_database/firebase_database.dart';
import 'package:flutter/material.dart';
import 'package:fyp/templates/displayText.dart';
import 'package:fyp/templates/profileView.dart';

class CompanyProfile extends StatefulWidget {
final String companyId;

const CompanyProfile({super.key, required this.companyId});

@override
State createState() => CompanyProfileState();
}

class CompanyProfileState extends State<CompanyProfile> {
DatabaseReference dbhandler = FirebaseDatabase.instance.ref();
String name = "Company Name";
String imgPath = "general care";
String description = "No Description";

@override
void initState() {
super.initState();
setState(() {
getProfile(widget.companyId);
});
}

void getProfile(String userId) async {
await dbhandler
.child('Profiles')
.orderByChild('user_id')
.equalTo(userId)
.onValue
.first
.then((event) async {
if (event.snapshot.value != null) {
Map<dynamic, dynamic>? data =
event.snapshot.value as Map<dynamic, dynamic>?;
if (data != null) {
var pKey = data.keys.first;
var pData = data[pKey];
setState(() {
name = pData['name'];
imgPath = pData['img'];
description = pData['description'];
});
}
}
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: SafeArea(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const SizedBox(height: 30),
const DisplayText(
text: "Company Profile", fontSize: 30, colour: Colors.black),
const SizedBox(height: 40),
ProfileView(
name: name,
imgPath: imgPath,
experience: "",
description: description,
scale: 1),
const SizedBox(height: 40),
const DisplayText(
text: "To edit the profile go to settings",
fontSize: 20,
colour: Colors.deepPurple),
]))));
}
}
Loading

0 comments on commit a7ac377

Please sign in to comment.