Commit d7d2568a authored by Wei Han's avatar Wei Han

code update

parent b47a3b6b
{
"images" : [
{
"filename" : "icon_green_active.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "icon_red_blocked.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "Mask group.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "Mask group (1).png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "Mask group (2).png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
......@@ -6,7 +6,7 @@
<dict>
<key>Assets.car</key>
<data>
apewM0kg8bkb0nA0BqxaEqt0L8I=
1i2tuf6x04oClRQdI25h80iAWww=
</data>
<key>Headers/QmsPlugin.h</key>
<data>
......@@ -31,7 +31,7 @@
<dict>
<key>hash2</key>
<data>
kujF94lp6x0Gv/ur/rYZEuwSRGB/AosKCC73EYwiL8g=
1mZEAflZoNOaTXIhGRR7gPGBZ99fx2jFZ147Fkro4WM=
</data>
</dict>
<key>Headers/QmsPlugin.h</key>
......
......@@ -6,7 +6,7 @@
<dict>
<key>Assets.car</key>
<data>
apewM0kg8bkb0nA0BqxaEqt0L8I=
1i2tuf6x04oClRQdI25h80iAWww=
</data>
<key>Headers/QmsPlugin.h</key>
<data>
......@@ -31,7 +31,7 @@
<dict>
<key>hash2</key>
<data>
kujF94lp6x0Gv/ur/rYZEuwSRGB/AosKCC73EYwiL8g=
1mZEAflZoNOaTXIhGRR7gPGBZ99fx2jFZ147Fkro4WM=
</data>
</dict>
<key>Headers/QmsPlugin.h</key>
......
......@@ -16,6 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, copy) NSString *projectId;
@property (nonatomic, copy) NSString *drawingPlanId;
@property (nonatomic, copy) NSString *projectLogo;
@property (nonatomic, copy) NSString *lotId;
@end
......
......@@ -15,6 +15,7 @@
#import "LocalStorage.h"
#import "APIConfig.h"
#import "ImageCacheHelper.h"
#import "ThirdPartyViewController.h"
@interface DashboardViewController () <UIScrollViewDelegate>
......@@ -366,8 +367,8 @@
footerView.clipsToBounds = YES;
[self.view addSubview:footerView];
NSArray *titles = @[ @"Make Appt.", @"Add Issue", @"Access Item" ];
NSArray *icons = @[ @"calendar.badge.plus", @"plus.circle", @"key.horizontal" ];
NSArray *titles = @[ @"Make Appt.", @"Add Issue", @"3rd Party Link", @"Access Item" ];
NSArray *icons = @[ @"calendar.badge.plus", @"plus.circle", @"link", @"key.horizontal" ];
CGFloat buttonWidth = self.view.bounds.size.width / titles.count;
CGFloat iconSize = 24.0;
......@@ -381,7 +382,7 @@
button.tintColor = [UIColor whiteColor];
UIImage *iconImage;
if (i == 2) {
if (i == 3) {
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
iconImage = [UIImage imageNamed:@"icon_white_acessitem"
inBundle:bundle
......@@ -446,6 +447,16 @@
break;
}
case 2: {
NSLog(@"Navigating to 3rd Party Link");
ThirdPartyViewController *linkVC = [[ThirdPartyViewController alloc] init];
linkVC.unitID = self.projectCode;
linkVC.unitName = self.projectName;
linkVC.lotId = self.lotId;
linkVC.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:linkVC animated:YES completion:nil];
break;
}
case 3: {
NSLog(@"Navigating to Access Item");
AccessItemViewController *nextVC = [[AccessItemViewController alloc] init];
nextVC.unitID = self.projectCode;
......
......@@ -111,29 +111,29 @@
}
- (void)checkAndRefreshAPIs {
// NSLog(@"🔍 Checking credentials...");
// NSLog(@"ClientID: %@", self.ClientID);
// NSLog(@"ClientCode: %@", self.ClientCode);
// NSLog(@"user_token: %@", self.user_token);
//
// [self showLoadingOverlay:@"Loading..."];
//
// if (![self isReadyToLoadDashboard]) {
// NSLog(@"⏳ Waiting for all credentials to be ready...");
// return;
// }
//
// if (_isLoadingDashboard) return;
//
// self.isLoadingDashboard = YES;
//
// NSLog(@"✅ All credentials ready. ClientID: %@, ClientCode: %@, user_token: %@",
// self.ClientID, self.ClientCode, self.user_token);
//
//
// [APIConfig setAuthTokem:self.user_token];
// [APIConfig setClientId:self.ClientID];
self.ClientCode = @"spt";
NSLog(@"🔍 Checking credentials...");
NSLog(@"ClientID: %@", self.ClientID);
NSLog(@"ClientCode: %@", self.ClientCode);
NSLog(@"user_token: %@", self.user_token);
[self showLoadingOverlay:@"Loading..."];
if (![self isReadyToLoadDashboard]) {
NSLog(@"⏳ Waiting for all credentials to be ready...");
return;
}
if (_isLoadingDashboard) return;
self.isLoadingDashboard = YES;
NSLog(@"✅ All credentials ready. ClientID: %@, ClientCode: %@, user_token: %@",
self.ClientID, self.ClientCode, self.user_token);
[APIConfig setAuthTokem:self.user_token];
[APIConfig setClientId:self.ClientID];
// self.ClientCode = @"spt";
[self requestCompanyCode];
}
......
......@@ -284,6 +284,7 @@ didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
vc.drawingPlanId = drawingPlanId ?: @"";
vc.drawerController = self.drawerController;
vc.projectLogo = self.projectLogo;
vc.lotId = unit[@"lot_id"] ?: @"";
vc.modalPresentationStyle = UIModalPresentationFullScreen;
[self.navigationController pushViewController:vc animated:YES];
}
......
......@@ -5,6 +5,8 @@ NS_ASSUME_NONNULL_BEGIN
@interface ThirdPartyDetailsViewController : UIViewController
@property (nonatomic, strong) NSDictionary *item;
@end
NS_ASSUME_NONNULL_END
......
......@@ -5,7 +5,11 @@
NS_ASSUME_NONNULL_BEGIN
@interface ThirdPartyViewController : UIViewController
@property (nonatomic, strong) NSString *unitID;
@property (nonatomic, strong) NSString *unitName;
@property (nonatomic, strong) NSString *lotId;
@end
NS_ASSUME_NONNULL_END
......
// ThirdTutorialViewController.h
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface ThirdPartyTutorialViewController : UIViewController
@end
NS_ASSUME_NONNULL_END
......@@ -78,7 +78,16 @@ NS_ASSUME_NONNULL_BEGIN
completion:(void (^)(BOOL success, NSString *filePath))completion;
+ (void)requestCompanyCode:(NSString *)companyCode
completion:(void(^)(BOOL success, NSDictionary * _Nullable response, NSError * error))completion;
completion:(void(^)(BOOL success, NSDictionary * _Nullable response, NSError * error))completion;
+ (void)requestThirdPartyList:(void(^)(BOOL success, NSDictionary * _Nullable response, NSError * _Nullable error))completion;
+ (void)createThirdPartyLink:(NSString *)title
lotId:(NSString *)lotId
completion:(void(^)(BOOL success, NSDictionary * _Nullable response, NSError * _Nullable error))completion;
+ (void)updateThirdPartyLink:(NSDictionary *)payload
completion:(void(^)(NSDictionary * _Nullable response,NSError * _Nullable error))completion;
@end
......
......@@ -1950,6 +1950,185 @@
[task resume];
}
+ (void)requestThirdPartyList:(void(^)(BOOL success, NSDictionary * _Nullable response, NSError * _Nullable error))completion {
if ([APIConfig handleOfflineForAPI:@"ThirdPartyList" completion:completion]) {
return;
}
NSURL *url = [APIConfig urlWithPath:@"/framework/third-party/auth/listCode"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
request.HTTPMethod = @"POST";
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
NSLog(@"🌍 Request URL: %@", url.absoluteString);
NSError *jsonError;
if (jsonError) {
NSLog(@"❌ JSON Serialization Error: %@", jsonError);
if (completion) completion(NO, nil, jsonError);
return;
}
NSLog(@"🔄 Request thirdPartyList started...");
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(), ^{
completion(NO, nil, error);
});
return;
}
NSError *parseError;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&parseError];
if (parseError) {
NSLog(@"⚠️ JSON Parse Error: %@", parseError);
dispatch_async(dispatch_get_main_queue(), ^{
completion(NO, nil, parseError);
});
return;
}
NSString *cacheKey = [NSString stringWithFormat:@"AccessItem_%@", [APIConfig projectId]];
NSDictionary *safeJson = [APIConfig dictionaryByReplacingNullsWithBlanks:json];
[LocalStorage saveDictionary:safeJson forKey:cacheKey];
NSLog(@"💾 Saved to cache: %@", cacheKey);
dispatch_async(dispatch_get_main_queue(), ^{
completion(YES, json, nil);
});
}];
[task resume];
}
+ (void)createThirdPartyLink:(NSString *)title
lotId:(NSString *)lotId
completion:(void(^)(BOOL success, NSDictionary * _Nullable response, NSError * _Nullable error))completion {
NSURL *url = [APIConfig urlWithPath:@"/framework/third-party/auth/generateCode"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
request.HTTPMethod = @"POST";
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
NSDictionary *jsonBody = @{
@"title": title ?: @"",
@"unit_id": lotId ?: @"",
@"status": @1,
@"created_by": [APIConfig clientId],
};
// ✅ Convert dictionary → NSData
NSError *jsonError;
NSData *bodyData = [NSJSONSerialization dataWithJSONObject:jsonBody options:0 error:&jsonError];
if (jsonError) {
NSLog(@"❌ JSON Serialization Error: %@", jsonError);
if (completion) completion(NO, nil, jsonError);
return;
}
request.HTTPBody = bodyData;
// 🧭 Debug logs
NSLog(@"🌍 URL: %@", url);
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(NO, nil, error);
});
return;
}
NSError *jsonParseError;
NSDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonParseError];
if (jsonParseError) {
NSLog(@"⚠️ JSON Parse Error: %@", jsonParseError);
} else {
NSLog(@"✅ Create Third Party Link Response:\n%@", jsonResponse);
}
dispatch_async(dispatch_get_main_queue(), ^{
if (completion) {
completion(YES, jsonResponse, jsonParseError);
}
});
}];
[task resume];
}
+ (void)updateThirdPartyLink:(NSDictionary *)payload
completion:(void(^)(NSDictionary * _Nullable response,NSError * _Nullable error))completion {
NSURL *url = [APIConfig urlWithPath:@"/framework/third-party/auth/update"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
request.HTTPMethod = @"POST";
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
NSError *jsonError;
NSData *bodyData =
[NSJSONSerialization dataWithJSONObject:payload
options:0
error:&jsonError];
if (jsonError) {
if (completion) completion(nil, jsonError);
return;
}
request.HTTPBody = bodyData;
NSLog(@"🌍 URL: %@", url);
NSLog(@"📦 Body JSON: %@", payload);
NSURLSessionDataTask *task =
[[NSURLSession sharedSession] dataTaskWithRequest:request
completionHandler:^(NSData *data,
NSURLResponse *response,
NSError *error) {
if (error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (completion) completion(nil, error);
});
return;
}
NSError *parseError;
NSDictionary *jsonResponse =
[NSJSONSerialization JSONObjectWithData:data
options:0
error:&parseError];
dispatch_async(dispatch_get_main_queue(), ^{
if (completion) {
completion(jsonResponse, parseError);
}
});
}];
[task resume];
}
#pragma mark - Helper Methods
+ (NSString *)multipartFormField:(NSString *)name value:(NSString *)value boundary:(NSString *)boundary {
return [NSString stringWithFormat:@"--%@\r\nContent-Disposition: form-data; name=\"data[%@]\"\r\n\r\n%@\r\n", boundary, name, value];
......
......@@ -7,7 +7,7 @@ static NSString *kBaseURL = @"https://sptest.commudesk.com/api";
static NSString *kDrawingPlanId = @"";
static NSString *kProjectId = @"";
static NSString *kAuthToken = @"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzY29wZSI6InNlcnZlci10by1zZXJ2ZXIiLCJmcmFtZXdvcmstYXBpIjp0cnVlLCJjb21wYW55X2NvZGUiOiJTUFQiLCJzdWIiOjE1NTcsImlzcyI6Imh0dHBzOi8vc3B0ZXN0LmNvbW11ZGVzay5jb20vYXBpL2ZyYW1ld29yay9vd25lci9hdXRoL2NsaWVudF9hdXRoZW50aWNhdGlvbiIsImlhdCI6MTc2Nzc1MjU5OSwiZXhwIjoyMDgzMzIyMTE5LCJuYmYiOjE3Njc3NTI1OTksImp0aSI6IktEcmhmSXgzeWU0WmxaUEYifQ.Bv4ZSjGRm9YYOjGItLSV_3wS7grKuPTabL60BFnp88o";
static NSString *kClientId = @"3";
static NSString *kClientId = @"1";
@implementation APIConfig
#pragma mark - OS
......
......@@ -6,7 +6,7 @@
<dict>
<key>Assets.car</key>
<data>
apewM0kg8bkb0nA0BqxaEqt0L8I=
1i2tuf6x04oClRQdI25h80iAWww=
</data>
<key>Headers/QmsPlugin.h</key>
<data>
......@@ -31,7 +31,7 @@
<dict>
<key>hash2</key>
<data>
kujF94lp6x0Gv/ur/rYZEuwSRGB/AosKCC73EYwiL8g=
1mZEAflZoNOaTXIhGRR7gPGBZ99fx2jFZ147Fkro4WM=
</data>
</dict>
<key>Headers/QmsPlugin.h</key>
......
......@@ -6,7 +6,7 @@
<dict>
<key>Assets.car</key>
<data>
apewM0kg8bkb0nA0BqxaEqt0L8I=
1i2tuf6x04oClRQdI25h80iAWww=
</data>
<key>Headers/QmsPlugin.h</key>
<data>
......@@ -31,7 +31,7 @@
<dict>
<key>hash2</key>
<data>
kujF94lp6x0Gv/ur/rYZEuwSRGB/AosKCC73EYwiL8g=
1mZEAflZoNOaTXIhGRR7gPGBZ99fx2jFZ147Fkro4WM=
</data>
</dict>
<key>Headers/QmsPlugin.h</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