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

code update

parent 9a381188
......@@ -8,32 +8,32 @@
<key>BinaryPath</key>
<string>QmsPluginFramework.framework/QmsPluginFramework</string>
<key>LibraryIdentifier</key>
<string>ios-arm64</string>
<string>ios-arm64_x86_64-simulator</string>
<key>LibraryPath</key>
<string>QmsPluginFramework.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
<dict>
<key>BinaryPath</key>
<string>QmsPluginFramework.framework/QmsPluginFramework</string>
<key>LibraryIdentifier</key>
<string>ios-arm64_x86_64-simulator</string>
<string>ios-arm64</string>
<key>LibraryPath</key>
<string>QmsPluginFramework.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
</array>
<key>CFBundlePackageType</key>
......
// HistoryApiClient.h
#import <Foundation/Foundation.h>
@interface HistoryAPIClient : NSObject
+ (void)fetchHistory:(NSString *)issueID
completion:(void (^)(NSDictionary *data, NSError *error))completion;
@end
// HistoryApiClient.mm
#import "HistoryAPIClient.h"
@implementation HistoryAPIClient
+ (void)fetchHistory:(NSString *)issueID
completion:(void (^)(NSDictionary *data, NSError *error))completion {
// ✅ URL
NSString *urlString = @"https://kitadev.commudesk.com/api/owner/issue/getIssueHistory?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6ImF0aGlyYWh6YWlkaUBjb252ZXAuY29tIiwicGFzc3dvcmQiOiIkMnkkMTAkNU9xYklqMnZ6UHJwckJrcVd5c3I2LmJCc1hVYS9Hd014eUhnL3RhUUhPUkNQcGdmTG8yakciLCJzdWIiOjIxNzAsImlzcyI6Imh0dHBzOi8va2l0YWRldi5jb21tdWRlc2suY29tL2FwaS9vd25lci9hdXRoL3Bhc3N3b3JkbGVzc19sb2dpbiIsImlhdCI6MTc2MDMxNTM1MiwiZXhwIjoyMDc1ODg0ODcyLCJuYmYiOjE3NjAzMTUzNTIsImp0aSI6IktoQmNyQnJEdDVNdDZlWmMifQ.JnxGbZ7hTeoOr6oibIzZMphgyKtTo2Aq9Efx6mrGfFA";
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
request.HTTPMethod = @"POST";
// ✅ JSON headers
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
// ✅ Build JSON body
NSDictionary *deviceInfo = @{
@"OS": @"AND",
@"IMEI": @"AND:2a2f13ff17b1cbb5",
@"OS_VERSION": @"35",
@"MODEL": @"2306EPN60G",
@"APP_VERSION": @"1.22.26"
};
NSDictionary *jsonBody = @{
@"data": @{
@"os": @"AND",
@"issue_id": issueID,
@"information": deviceInfo
}
};
// ✅ Convert dictionary → NSData
NSError *jsonError;
NSData *bodyData = [NSJSONSerialization dataWithJSONObject:jsonBody options:0 error:&jsonError];
if (jsonError) {
NSLog(@"❌ JSON Serialization Error: %@", jsonError);
if (completion) completion(nil, jsonError);
return;
}
request.HTTPBody = bodyData;
// 🧭 Debug logs
NSLog(@"🌍 URL: %@", urlString);
NSLog(@"📦 Body JSON: %@", jsonBody);
// ✅ Make request
NSURLSessionDataTask *task = [[NSURLSession sharedSession]
dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
NSLog(@"❌ Network Error: %@", error);
dispatch_async(dispatch_get_main_queue(), ^{
if (completion) completion(nil, error);
});
return;
}
NSError *jsonParseError;
NSDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonParseError];
if (jsonParseError) {
NSLog(@"⚠️ JSON Parse Error: %@", jsonParseError);
} else {
NSLog(@"✅ Issues API Response:\n%@", jsonResponse);
}
dispatch_async(dispatch_get_main_queue(), ^{
if (completion) completion(jsonResponse, jsonParseError);
});
}];
[task resume];
}
@end
// HistoryViewController.h
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface HistoryViewController : UIViewController
@property (nonatomic, strong) NSString *issueID;
@property (nonatomic, strong) NSString *planID;
@property (nonatomic, strong) NSString *status;
@property (nonatomic, strong) NSString *unitName;
@property (nonatomic, strong) NSString *reference;
@end
NS_ASSUME_NONNULL_END
#import "IssueDetailViewController.h"
#import "HistoryViewController.h"
@interface IssueDetailViewController ()
......@@ -22,6 +23,18 @@
self.title = @"Issue Details";
NSLog(@"📦 Received Issue Data: %@", self.issueData);
NSString *text = [NSString stringWithFormat:@"%@", self.issueData];
NSString *docsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject;
NSString *filePath = [docsPath stringByAppendingPathComponent:@"issueData.txt"];
// Convert issueData to a readable string
NSString *plainText = [NSString stringWithFormat:@"%@", self.issueData];
// Write as plain UTF-8 text
[plainText writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:nil];
// Log the path so you can find it
NSLog(@"📁 issueData saved as plain text to: %@", filePath);
[self setupHeader];
[self setupScrollView];
......@@ -162,7 +175,7 @@
}
- (void)setupButtons {
CGFloat y = CGRectGetMaxY(self.detailsCard.frame) + 16;
CGFloat y = CGRectGetMaxY(self.detailsCard.frame) + 4;
CGFloat buttonWidth = (self.view.bounds.size.width - 60) / 2;
// --- Edit Button ---
......@@ -170,6 +183,7 @@
self.editButton.frame = CGRectMake(20, y, buttonWidth, 44);
[self.editButton setTitle:@"Edit Issue" forState:UIControlStateNormal];
[self.editButton setTitleColor:[UIColor colorWithRed:0/255.0 green:115/255.0 blue:130/255.0 alpha:1] forState:UIControlStateNormal];
[self.editButton addTarget:self action:@selector(editIssueTapped) forControlEvents:UIControlEventTouchUpInside];
self.editButton.layer.cornerRadius = 8;
self.editButton.layer.borderWidth = 1;
self.editButton.layer.borderColor = [UIColor colorWithRed:0/255.0 green:115/255.0 blue:130/255.0 alpha:1].CGColor;
......@@ -180,6 +194,7 @@
self.deleteButton.frame = CGRectMake(CGRectGetMaxX(self.editButton.frame) + 20, y, buttonWidth, 44);
[self.deleteButton setTitle:@"Delete Issue" forState:UIControlStateNormal];
[self.deleteButton setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
[self.deleteButton addTarget:self action:@selector(deleteIssueTapped) forControlEvents:UIControlEventTouchUpInside];
self.deleteButton.backgroundColor = [UIColor systemRedColor];
self.deleteButton.layer.cornerRadius = 8;
[self.scrollView addSubview:self.deleteButton];
......@@ -188,12 +203,22 @@
self.scrollView.contentSize = CGSizeMake(self.view.bounds.size.width, totalHeight);
}
- (void)editIssueTapped {
NSLog(@"✏️ Edit Issue tapped");
// You can later navigate to an edit screen or present a modal here
}
- (void)deleteIssueTapped {
NSLog(@"🗑️ Delete Issue tapped");
// need to fill up later
}
#pragma mark - Data
- (void)populateData {
if (!self.issueData) return;
NSString *ref = self.issueData[@"issue_reference"] ?: @"Unknown Reference";
NSString *ref = self.issueData[@"issue_reference"] ?: self.issueData[@"reference"] ?: @"Unknown Reference";
NSString *status = self.issueData[@"status_external"] ?: @"No Status";
NSString *statusColor = self.issueData[@"status_ex_color"] ?: @"#999999";
NSString *imageURL = self.issueData[@"image"];
......@@ -237,7 +262,6 @@
}
#pragma mark - Helper
- (UIColor *)colorFromHex:(NSString *)hexString {
if (!hexString || hexString.length < 6) return [UIColor grayColor];
unsigned int rgbValue = 0;
......@@ -256,8 +280,24 @@
}
- (void)handleHistoryTap {
NSLog(@"🕓 History tapped");
// TODO: Navigate to issue history screen later
NSLog(@"🕓 Navigating to History");
HistoryViewController *nextVC = [[HistoryViewController alloc] init];
nextVC.modalPresentationStyle = UIModalPresentationFullScreen;
nextVC.issueID = self.issueData[@"issue_reference_id"];
nextVC.planID = self.issueData[@"plan_id"];
nextVC.status = self.issueData[@"status_external"];
nextVC.unitName = self.issueData[@"plan_unit"];
nextVC.reference = self.issueData[@"reference"] ?: self.issueData[@"issue_reference"];
NSLog(@"📦 Data being sent to History:\n issueID: %@\n planID: %@\n status: %@\n unitName: %@\n reference: %@",
nextVC.issueID,
nextVC.planID,
nextVC.status,
nextVC.unitName,
nextVC.reference);
[self presentViewController:nextVC animated:YES completion:nil];
}
@end
......@@ -8,32 +8,32 @@
<key>BinaryPath</key>
<string>QmsPluginFramework.framework/QmsPluginFramework</string>
<key>LibraryIdentifier</key>
<string>ios-arm64</string>
<string>ios-arm64_x86_64-simulator</string>
<key>LibraryPath</key>
<string>QmsPluginFramework.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
<dict>
<key>BinaryPath</key>
<string>QmsPluginFramework.framework/QmsPluginFramework</string>
<key>LibraryIdentifier</key>
<string>ios-arm64_x86_64-simulator</string>
<string>ios-arm64</string>
<key>LibraryPath</key>
<string>QmsPluginFramework.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
</array>
<key>CFBundlePackageType</key>
......
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