Commit 227d7a6d authored by Wei Han's avatar Wei Han

side menu code update

parent 1323f31a
......@@ -73,7 +73,6 @@
//[[OfflineSyncManager shared] clearOfflineQueue];
[[NSNotificationCenter defaultCenter] postNotificationName:@"ShowHiddenButtonNotification" object:@(YES)];
}
- (void)viewWillAppear:(BOOL)animated {
......@@ -82,11 +81,13 @@
NSLog(@"Dashboard loaded, refreshing data");
[self refreshDashboardContent];
self.navigationController.navigationBarHidden = YES;
[[NSNotificationCenter defaultCenter] postNotificationName:@"ShowHiddenButtonNotification" object:@(YES)];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
self.navigationController.navigationBarHidden = YES;
[[NSNotificationCenter defaultCenter] postNotificationName:@"ShowHiddenButtonNotification" object:@(NO)];
}
#pragma mark - Refresh Logic
......
......@@ -146,7 +146,6 @@ static NSString * const ProfileDidUpdateNotification = @"ProfileDidUpdateNotific
- (void)loadDefaultsIfNeeded {
if (!self.profileName) self.profileName = @"Guest User";
if (!self.profileEmail) self.profileEmail = @"guest@example.com";
if (!self.profileImageURL) self.profileImageURL = nil;
self.nameLabel.text = self.profileName;
self.emailLabel.text = self.profileEmail;
......
// ManageAccountViewController.h
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface ManageAccountViewController : UIViewController
@property (nonatomic, strong) NSArray<NSDictionary *> *accounts;
@end
NS_ASSUME_NONNULL_END
......@@ -7,6 +7,7 @@
#import "APIConfig.h"
#import "AppointmentDetailsViewController.h"
#import "DashboardViewController.h"
#import "IssueDetailViewController.h"
static char kNotificationKey;
......@@ -418,6 +419,8 @@ static char kNotificationKey;
NSString *notificationType = item[@"type"];
NSDictionary *strData = item;
self.oldUnitId = [APIConfig drawingPlanId];
NSString *projectName = item[@"project_name"];
NSString *projectCode = item[@"draw_plan_name"];
NSString *unitID = @"";
if (strData[@"draw_plan_id"]) {
......@@ -461,7 +464,7 @@ static char kNotificationKey;
issueID = strData[@"issue_id"];
}
[self openIssueWithUnit:unitID issueID:issueID];
[self openIssueWithUnit:unitID issueID:issueID projectName:projectName projectCode:projectCode];
}
......@@ -470,6 +473,7 @@ static char kNotificationKey;
NSLog(@"➡️ Open Appointment | unit=%@ appt=%@", unitID, appointmentID);
[APIClient requestDashboardInfo:^(BOOL success, NSDictionary * _Nullable data, NSError * _Nonnull error) {
if (!success || !data) {
[APIConfig setDrawingPlanId:self.oldUnitId];
return;
}
......@@ -479,6 +483,7 @@ static char kNotificationKey;
appointment == [NSNull null] ||
![appointment isKindOfClass:[NSArray class]] ||
appointmentID.length == 0) {
[APIConfig setDrawingPlanId:self.oldUnitId];
return;
}
......@@ -500,12 +505,14 @@ static char kNotificationKey;
}
if (!matchedAppointment) {
// No match found
NSLog(@"❌ No matching appointment found");
[APIConfig setDrawingPlanId:self.oldUnitId];
return;
}
// 👉 Navigate to Appointment Details
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"navigating to appointment details");
AppointmentDetailsViewController *vc = [[AppointmentDetailsViewController alloc] init];
vc.modalPresentationStyle = UIModalPresentationFullScreen;
vc.appointmentData = matchedAppointment;
......@@ -520,14 +527,17 @@ static char kNotificationKey;
NSArray *projects = self.projectList;
if (!projects || projects.count == 0) {
NSLog(@"❌ Project list empty");
[APIConfig setDrawingPlanId:self.oldUnitId];
return;
}
for (NSDictionary *project in projects) {
if (![project isKindOfClass:[NSDictionary class]]) continue;
NSString *projectIDStr = [NSString stringWithFormat:@"%@", projectID];
NSString *projID = [NSString stringWithFormat:@"%@", project[@"id"]];
if (![projID isEqualToString:projectID]) continue;
if (![projID isEqualToString:projectIDStr]) continue;
NSArray *units = project[@"unit"];
if (![units isKindOfClass:[NSArray class]]) break;
......@@ -536,7 +546,9 @@ static char kNotificationKey;
if (![unit isKindOfClass:[NSDictionary class]]) continue;
NSString *uID = [NSString stringWithFormat:@"%@", unit[@"id"]];
if (![uID isEqualToString:unitID]) continue;
NSString *unitIDStr = [NSString stringWithFormat:@"%@", unitID];
if (![uID isEqualToString:unitIDStr]) continue;
NSLog(@"uID: %@", uID);
NSLog(@"✅ Found project %@ and unit %@", projectID, unitID);
......@@ -556,12 +568,53 @@ static char kNotificationKey;
}
}
NSLog(@"❌ No matching project/unit found");
[APIConfig setDrawingPlanId:self.oldUnitId];
}
- (void)openIssueWithUnit:(NSString *)unitID issueID:(NSString *)issueID {
- (void)openIssueWithUnit:(NSString *)unitID issueID:(NSString *)issueID projectName:(NSString *)projectName projectCode:(NSString *)projectCode {
NSLog(@"➡️ Open Issue | unit=%@ issue=%@", unitID, issueID);
// TODO: push IssueDetailViewController
[APIClient requestIssues:^(BOOL success, NSDictionary * _Nullable data, NSError * _Nonnull error) {
if (!success || !data) {
[APIConfig setDrawingPlanId:self.oldUnitId];
return;
};
NSArray *issues = data[@"Data"];
if (!issues || ![issues isKindOfClass:[NSArray class]]) {
[APIConfig setDrawingPlanId:self.oldUnitId];
return;
}
NSDictionary *matchedIssue = nil;
for (NSDictionary *issue in issues) {
if (![issue isKindOfClass:[NSDictionary class]]) continue;
NSString *iID = [NSString stringWithFormat:@"%@", issue[@"id"]];
NSString *issueIDStr = [NSString stringWithFormat:@"%@", issueID];
if ([iID isEqualToString:issueIDStr]) {
matchedIssue = issue;
break;
}
}
if (!matchedIssue) {
[APIConfig setDrawingPlanId:self.oldUnitId];
NSLog(@"❌ No matching issue found");
return;
}
// 2️⃣ Navigate to Issue Detail
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"➡️ Navigating to IssueDetailViewController");
IssueDetailViewController *vc = [[IssueDetailViewController alloc] init];
vc.modalPresentationStyle = UIModalPresentationFullScreen;
vc.issueData = matchedIssue;
vc.projectCode = projectCode;
vc.projectName = projectName;
[self presentViewController:vc animated:YES completion:nil];
});
}];
}
@end
......@@ -797,14 +797,14 @@ static NSString * const kSyncSelectedUnitsKey = @"SYNC_SELECTEDUNITS";
} next:next];
}];
// Task 9 — requestAnnouncement
// Task 9 — requestClientAnnouncement
[tasks addObject:^(void (^next)(void)) {
[self safeSequentialTask:@"task9" block:^(void (^safeNext)(void), void (^logSuccess)(BOOL)) {
NSLog(@"🚀 Starting Task 9");
[APIClient requestAnnouncement:^(BOOL success, NSDictionary *res, NSError *err) {
[APIClient requestClientAnnouncement:^(BOOL success, NSDictionary *res, NSError *err) {
NSString *logText = [NSString stringWithFormat:
@"\n🚀 Task 9 — requestAnnouncement\nTime: %@\nError: %@\nResponse: %@\n",
@"\n🚀 Task 9 — requestClientAnnouncement\nTime: %@\nError: %@\nResponse: %@\n",
[NSDate date], err, res];
[self appendOfflineLog:logText];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment