Commit 61a8bfd5 authored by Wei Han's avatar Wei Han

code update

parent 5ac78689
......@@ -18,7 +18,8 @@
@property (nonatomic, copy) NSString *selectedTypeName;
@property (nonatomic, copy) NSString * selectedIssueID;
@property (nonatomic, assign) BOOL isEditMode;
@property (nonatomic, strong) NSMutableArray *existingImages;
@property (nonatomic, strong) NSMutableArray *addedImages;
@end
@implementation AddIssueDetailsViewController
......@@ -26,6 +27,8 @@
- (void)viewDidLoad {
[super viewDidLoad];
self.isEditMode = [self.action isEqualToString:@"edit_issue"];
self.existingImages = [NSMutableArray array];
self.addedImages = [NSMutableArray array];
self.view.backgroundColor = UIColor.whiteColor;
NSLog(@"📦 Data being brought over:\n planID: %@\n locationID: %@\n selectedLocationName: %@\n defectMatrix: %@\n projectName: %@\n projectCode: %@\n XCoordinates: %f\n YCoordinates: %f\n action: %@\n issueFullData: %@\n issueContent: %@\n locationData: %@",
......@@ -148,7 +151,8 @@
NSDictionary *imgDict = firstImages[i];
NSString *urlStr = imgDict[@"thumb_image"] ?: imgDict[@"image"];
if (![urlStr isKindOfClass:[NSString class]]) continue;
[self.existingImages addObject:urlStr];
NSURL *url = [NSURL URLWithString:urlStr];
if (!url) continue;
......@@ -228,6 +232,7 @@
title.textColor = UIColor.whiteColor;
title.font = [UIFont systemFontOfSize:18 weight:UIFontWeightMedium];
title.textAlignment = NSTextAlignmentCenter;
title.tag = 101;
[self.headerView addSubview:title];
// ✅ Reset button (refresh icon)
......@@ -733,10 +738,16 @@ didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey,id> *
NSInteger index = picker.view.tag; // will be 0–2 after fix
// Store image
if (index < self.uploadedImages.count) {
self.uploadedImages[index] = image;
if (self.isEditMode) {
// Only new images go here
[self.addedImages addObject:image];
} else {
[self.uploadedImages addObject:image];
// Normal add mode (keep using uploadedImages)
if (index < self.uploadedImages.count) {
self.uploadedImages[index] = image;
} else {
[self.uploadedImages addObject:image];
}
}
// Update UI
......@@ -890,19 +901,10 @@ didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey,id> *
NSLog(@"⚠️ Edit mode is ON, but no issueFullData passed!");
}
// Prefer issue_id first, fallback to id
NSString *issueID = nil;
if ([self.issueFullData[@"issue_id"] isKindOfClass:[NSString class]]) {
issueID = self.issueFullData[@"issue_id"];
} else if ([self.issueFullData[@"id"] isKindOfClass:[NSString class]]) {
issueID = self.issueFullData[@"id"];
} else {
issueID = [NSString stringWithFormat:@"%@", self.issueFullData[@"issue_id"] ?: self.issueFullData[@"id"] ?: @"0"];
}
// ✅ Build update payload
NSDictionary *updateData = @{
@"issue_id": issueID ?: @"0",
@"location_id": self.locationID ?: @"",
@"issue_id": self.issueFullData[@"issue_reference_id"] ?: @"0",
@"issue_setting_id": self.selectedIssueID ?: @"",
@"position_x": @(self.planX).stringValue ?: @"",
@"position_y": @(self.planY).stringValue ?: @"",
......@@ -913,7 +915,7 @@ didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey,id> *
NSLog(@"📦 Sending UpdateIssue with data: %@", updateData);
[AddIssueAPIClient submitUpdateIssue:updateData
images:self.uploadedImages
images:self.addedImages
completion:^(NSDictionary * _Nullable response, NSError * _Nullable error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (error) {
......@@ -952,7 +954,8 @@ didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey,id> *
});
}];
} else {
NSLog(@"Calling addIssue API:\n planID: %@\n locationID: %@\n selectedIssueID: %@\n XCoordinates: %f\n YCoordinates: %f\n commentField: %@",
NSLog(@"Calling addIssue API:\n locationID: %@\n planID: %@\n locationID: %@\n selectedIssueID: %@\n XCoordinates: %f\n YCoordinates: %f\n commentField: %@",
self.locationID,
self.planID,
self.locationID,
self.selectedIssueID,
......
......@@ -55,6 +55,13 @@
[self refreshDashboardContent];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSLog(@"Dashboard loaded, refreshing data");
[self refreshDashboardContent];
}
#pragma mark - Refresh Logic
- (void)refreshDashboardContent {
NSLog(@"🔁 Refreshing dashboard content...");
......
......@@ -414,7 +414,7 @@
HistoryViewController *nextVC = [[HistoryViewController alloc] init];
nextVC.modalPresentationStyle = UIModalPresentationFullScreen;
nextVC.issueID = self.issueData[@"issue_reference_id"] ?: self.issueData[@"id"] ?: @"";
nextVC.issueID = self.issueData[@"issue_id"] ?: @"";
nextVC.planID = self.issueData[@"plan_id"];
nextVC.status = self.issueData[@"status_external"];
nextVC.unitName = self.issueData[@"plan_unit"];
......@@ -460,7 +460,7 @@
} mutableCopy];
if (data[@"id"] && ![data[@"id"] isKindOfClass:[NSNull class]]) {
issueContent[@"issue_id"] = [NSString stringWithFormat:@"%@", data[@"id"]];
issueContent[@"issue_id"] = [NSString stringWithFormat:@"%@", data[@"issue_reference_id"]];
}
if (data[@"pos_x"] && ![data[@"pos_x"] isKindOfClass:[NSNull class]]) {
issueContent[@"pos_x"] = [NSString stringWithFormat:@"%@", data[@"pos_x"]];
......@@ -522,6 +522,7 @@
withdrawVC.unitName = unitName;
withdrawVC.reference = reference;
withdrawVC.titleText = strTitle;
withdrawVC.isMultiWithdraw = NO;
NSLog(@"📦 Navigating to WithdrawSingleIssueViewController with:\n issueID=%@\n planID=%@\n status=%@\n unitName=%@\n reference=%@\n title=%@",
issueID, planID, status, unitName, reference, strTitle);
......
......@@ -3,6 +3,7 @@
#import "IssueAPIClient.h"
#import "IssueDetailViewController.h"
#import "WithdrawSingleIssueViewController.h"
#import "WithdrawIssuesViewController.h"
#pragma mark - Internal IssueCell
@interface IssueCell : UITableViewCell
......@@ -118,7 +119,6 @@
@property (nonatomic, strong) UIButton *backButton;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIButton *withdrawButton;
@property (nonatomic, strong) UIButton *poaButton;
@property (nonatomic, strong) UIButton *filterButton;
@property (nonatomic, strong) UILabel *filterLabel;
@property (nonatomic, strong) UISearchBar *searchBar;
......@@ -181,14 +181,6 @@
self.withdrawButton.translatesAutoresizingMaskIntoConstraints = NO;
[self.withdrawButton addTarget:self action:@selector(withdrawTapped) forControlEvents:UIControlEventTouchUpInside];
[self.headerView addSubview:self.withdrawButton];
// POA Button
self.poaButton = [UIButton buttonWithType:UIButtonTypeSystem];
[self.poaButton setImage:[UIImage systemImageNamed:@"doc.text"] forState:UIControlStateNormal];
self.poaButton.tintColor = UIColor.whiteColor;
self.poaButton.translatesAutoresizingMaskIntoConstraints = NO;
[self.poaButton addTarget:self action:@selector(poaTapped) forControlEvents:UIControlEventTouchUpInside];
[self.headerView addSubview:self.poaButton];
}
- (void)setupFilterBar {
......@@ -247,10 +239,8 @@
[self.backButton.centerYAnchor constraintEqualToAnchor:self.headerView.centerYAnchor],
[self.titleLabel.centerXAnchor constraintEqualToAnchor:self.headerView.centerXAnchor],
[self.titleLabel.centerYAnchor constraintEqualToAnchor:self.headerView.centerYAnchor],
[self.withdrawButton.trailingAnchor constraintEqualToAnchor:self.headerView.trailingAnchor constant:-56],
[self.withdrawButton.trailingAnchor constraintEqualToAnchor:self.headerView.trailingAnchor constant:-12],
[self.withdrawButton.centerYAnchor constraintEqualToAnchor:self.headerView.centerYAnchor],
[self.poaButton.trailingAnchor constraintEqualToAnchor:self.headerView.trailingAnchor constant:-12],
[self.poaButton.centerYAnchor constraintEqualToAnchor:self.headerView.centerYAnchor],
// Filter
[self.filterButton.topAnchor constraintEqualToAnchor:self.headerView.bottomAnchor constant:12],
......@@ -402,10 +392,10 @@
- (void)withdrawTapped {
NSLog(@"Withdraw button tapped");
}
- (void)poaTapped {
NSLog(@"POA button tapped");
WithdrawIssuesViewController *withdrawVC = [[WithdrawIssuesViewController alloc] init];
withdrawVC.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:withdrawVC animated:YES completion:nil];
}
# pragma mark - Filter
......
// WithdrawIssuesViewController.h
#import <UIKit/UIKit.h>
@interface WithdrawIssuesViewController : UIViewController
@property (nonatomic, strong) NSString *unitID; // passed from previous screen if needed
@end
// WithdrawSingleIssueViewController.h
// WithdrawSingleIssueViewController.h
#import <UIKit/UIKit.h>
@interface WithdrawSingleIssueViewController : UIViewController
@property (nonatomic, strong) NSString *issueID;
@property (nonatomic, strong) NSString *issueID; // for single issue
@property (nonatomic, strong) NSArray *selectedIssues; // for multiple issues
@property (nonatomic, strong) NSString *planID;
@property (nonatomic, strong) NSString *status;
@property (nonatomic, strong) NSString *unitName;
@property (nonatomic, strong) NSString *reference;
@property (nonatomic, strong) NSString *titleText; // "Delete Issue" or "Void Issue"
@property (nonatomic, strong) NSString *titleText; // e.g. @"Delete Issue" or @"Withdraw Issue"
@property (nonatomic, assign) BOOL isMultiWithdraw; // YES = multiple issues, NO = single
@end
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