Commit 1c49cf8f authored by Wei Han's avatar Wei Han

UI update

parent 98fa8e66
...@@ -21,7 +21,7 @@ xcodebuild -create-xcframework \ ...@@ -21,7 +21,7 @@ xcodebuild -create-xcframework \
## To use in test app ## To use in test app
1. add this line under dependencies in testApp's package.json 1. add this line under dependencies in testApp's package.json
"QmsPlugin": "git+http://convep.ddns.me:20000/WeiHan/weihan-plugin.git", - "QmsPlugin": "git+http://convep.ddns.me:20000/WeiHan/weihan-plugin.git",
2. then run yarn install 2. then run yarn install
......
...@@ -8,32 +8,32 @@ ...@@ -8,32 +8,32 @@
<key>BinaryPath</key> <key>BinaryPath</key>
<string>QmsPluginFramework.framework/QmsPluginFramework</string> <string>QmsPluginFramework.framework/QmsPluginFramework</string>
<key>LibraryIdentifier</key> <key>LibraryIdentifier</key>
<string>ios-arm64</string> <string>ios-arm64_x86_64-simulator</string>
<key>LibraryPath</key> <key>LibraryPath</key>
<string>QmsPluginFramework.framework</string> <string>QmsPluginFramework.framework</string>
<key>SupportedArchitectures</key> <key>SupportedArchitectures</key>
<array> <array>
<string>arm64</string> <string>arm64</string>
<string>x86_64</string>
</array> </array>
<key>SupportedPlatform</key> <key>SupportedPlatform</key>
<string>ios</string> <string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict> </dict>
<dict> <dict>
<key>BinaryPath</key> <key>BinaryPath</key>
<string>QmsPluginFramework.framework/QmsPluginFramework</string> <string>QmsPluginFramework.framework/QmsPluginFramework</string>
<key>LibraryIdentifier</key> <key>LibraryIdentifier</key>
<string>ios-arm64_x86_64-simulator</string> <string>ios-arm64</string>
<key>LibraryPath</key> <key>LibraryPath</key>
<string>QmsPluginFramework.framework</string> <string>QmsPluginFramework.framework</string>
<key>SupportedArchitectures</key> <key>SupportedArchitectures</key>
<array> <array>
<string>arm64</string> <string>arm64</string>
<string>x86_64</string>
</array> </array>
<key>SupportedPlatform</key> <key>SupportedPlatform</key>
<string>ios</string> <string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict> </dict>
</array> </array>
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
......
...@@ -4,10 +4,10 @@ ...@@ -4,10 +4,10 @@
@interface DashboardAPIClient : NSObject @interface DashboardAPIClient : NSObject
+ (void)fetchDashboardSummary:(void (^)(NSDictionary *data))completion; + (void)fetchDashboardSummary:(void (^)(NSDictionary *data))completion;
+ (void)fetchAnnouncement:(void (^)(NSArray *data))completion;
+ (void)fetchAppointments:(void (^)(NSArray *data))completion; + (void)fetchAppointments:(void (^)(NSArray *data))completion;
+ (void)fetchIssues:(void (^)(NSArray *data))completion; + (void)fetchIssues:(void (^)(NSArray *data))completion;
+ (void)fetchHeaderInfo:(void (^)(NSDictionary *data))completion; + (void)fetchHeaderInfo:(void (^)(NSDictionary *data))completion;
+ (void)fetchDashboardInfo:(void (^)(NSDictionary *data, NSError *error))completion; + (void)fetchDashboardInfo:(void (^)(NSDictionary *data, NSError *error))completion;
+ (void)fetchAnnouncement:(void (^)(NSDictionary *data, NSError *error))completion;
@end @end
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
@property (nonatomic, strong) NSString *projectCode; @property (nonatomic, strong) NSString *projectCode;
@property (nonatomic, strong) NSString *projectName; @property (nonatomic, strong) NSString *projectName;
@property (nonatomic, strong) UIImage *headerBackgroundImage; @property (nonatomic, strong) UIImage *headerBackgroundImage;
@property (nonatomic, strong) NSArray *announcements;
@end @end
...@@ -69,14 +70,21 @@ ...@@ -69,14 +70,21 @@
return; return;
} }
NSLog(@"🗞️ Announcement response: %@", data); NSLog(@"🗞️ Announcement response received");
// Optional: save to file for reference // 🔍 Optional: Log the whole JSON structure for debugging
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:data options:NSJSONWritingPrettyPrinted error:nil];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
NSLog(@"%@", jsonString);
// 💾 Save to file for offline reference
NSString *docsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject; NSString *docsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject;
NSString *filePath = [docsPath stringByAppendingPathComponent:@"AnnouncementResponse.txt"]; NSString *filePath = [docsPath stringByAppendingPathComponent:@"AnnouncementResponse.txt"];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:data options:NSJSONWritingPrettyPrinted error:nil];
[jsonData writeToFile:filePath atomically:YES]; [jsonData writeToFile:filePath atomically:YES];
NSLog(@"📁 Announcement response saved to %@", filePath); NSLog(@"📁 Announcement response saved to %@", filePath);
// ✅ Process and show popup announcements
[self processAnnouncementResponse:data];
}]; }];
} }
...@@ -414,6 +422,51 @@ ...@@ -414,6 +422,51 @@
}); });
} }
// DashboardViewController.m
- (void)processAnnouncementResponse:(NSDictionary *)data {
NSLog(@"Handling announcement: %@", data);
NSDictionary *appData = data[@"AppData"];
if (![appData[@"status"] isEqualToString:@"success"]) {
NSLog(@"Announcement fetch failed: %@", appData[@"message"]);
return;
}
// === Combine ===
NSDictionary *innerData = data[@"Data"] ?: data[@"data"];
NSArray *client = innerData[@"client_announcement"] ?: @[];
NSArray *project = innerData[@"project_announcement"] ?: @[];
NSMutableArray *merged = [NSMutableArray arrayWithArray:client];
[merged addObjectsFromArray:project];
// === Sort by date descending ===
NSArray *sorted = [merged sortedArrayUsingComparator:^NSComparisonResult(NSDictionary *a, NSDictionary *b) {
NSString *dateA = a[@"date"] ?: @"";
NSString *dateB = b[@"date"] ?: @"";
return [dateB compare:dateA];
}];
// === Save to property ===
self.announcements = sorted;
// === Save to UserDefaults if needed ===
[[NSUserDefaults standardUserDefaults] setObject:sorted forKey:@"CLIENT_ANNOUNCEMENTS"];
[[NSUserDefaults standardUserDefaults] synchronize];
NSLog(@"✅ Stored %lu announcements", (unsigned long)sorted.count);
// === Check for popup announcements ===
// for (NSDictionary *ann in sorted) {
// if ([ann[@"popup"] integerValue] == 1) {
// [self showPopupForAnnouncement:ann];
// break;
// }
// }
}
- (void)refreshDashboardSectionsWithData:(NSDictionary *)mainData { - (void)refreshDashboardSectionsWithData:(NSDictionary *)mainData {
NSLog(@"🔄 Refreshing dashboard sections..."); NSLog(@"🔄 Refreshing dashboard sections...");
...@@ -424,7 +477,7 @@ ...@@ -424,7 +477,7 @@
_currentY = 16.0; _currentY = 16.0;
// === PROJECT UPDATES === // === PROJECT UPDATES ===
NSArray *announcements = mainData[@"announcement"]; NSArray *announcements = self.announcements;
if (announcements.count > 0) { if (announcements.count > 0) {
UIView *announcementSection = [self buildAnnouncementSection:announcements]; UIView *announcementSection = [self buildAnnouncementSection:announcements];
CGRect f = announcementSection.frame; CGRect f = announcementSection.frame;
...@@ -590,16 +643,28 @@ ...@@ -590,16 +643,28 @@
card.layer.shadowOpacity = 0.3; card.layer.shadowOpacity = 0.3;
card.layer.shadowOffset = CGSizeMake(0, 1); card.layer.shadowOffset = CGSizeMake(0, 1);
UILabel *date = [[UILabel alloc] initWithFrame:CGRectMake(12, 8, 200, 16)]; // === 1. Resolve the date field (support both created_at and date) ===
NSString *dateString = item[@"created_at"] ?: item[@"date"];
NSString *dateOnly = dateString;
// === take only the date portion (before space) ===
if ([dateString containsString:@" "]) {
dateOnly = [[dateString componentsSeparatedByString:@" "] firstObject];
}
// === format it ===
NSDateFormatter *fmt = [[NSDateFormatter alloc] init]; NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
fmt.dateFormat = @"yyyy-MM-dd HH:mm:ss"; fmt.dateFormat = @"yyyy-MM-dd";
NSDate *dateObj = [fmt dateFromString:item[@"created_at"]]; NSDate *dateObj = [fmt dateFromString:dateOnly];
fmt.dateFormat = @"dd/MM/yyyy"; fmt.dateFormat = @"dd/MM/yyyy";
UILabel *date = [[UILabel alloc] initWithFrame:CGRectMake(12, 8, 200, 16)];
date.text = dateObj ? [fmt stringFromDate:dateObj] : @"--/--/----"; date.text = dateObj ? [fmt stringFromDate:dateObj] : @"--/--/----";
date.textColor = [UIColor grayColor]; date.textColor = [UIColor grayColor];
date.font = [UIFont systemFontOfSize:13]; date.font = [UIFont systemFontOfSize:13];
[card addSubview:date]; [card addSubview:date];
// === 2. Title ===
UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(12, 28, 256, 60)]; UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(12, 28, 256, 60)];
title.text = item[@"title"] ?: @"Untitled announcement"; title.text = item[@"title"] ?: @"Untitled announcement";
title.numberOfLines = 3; title.numberOfLines = 3;
...@@ -612,6 +677,7 @@ ...@@ -612,6 +677,7 @@
return card; return card;
} }
- (UIView *)makeAppointmentCard:(NSDictionary *)item width:(CGFloat)width { - (UIView *)makeAppointmentCard:(NSDictionary *)item width:(CGFloat)width {
UIView *card = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, 90)]; UIView *card = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, 90)];
card.backgroundColor = UIColor.whiteColor; card.backgroundColor = UIColor.whiteColor;
......
...@@ -8,32 +8,32 @@ ...@@ -8,32 +8,32 @@
<key>BinaryPath</key> <key>BinaryPath</key>
<string>QmsPluginFramework.framework/QmsPluginFramework</string> <string>QmsPluginFramework.framework/QmsPluginFramework</string>
<key>LibraryIdentifier</key> <key>LibraryIdentifier</key>
<string>ios-arm64</string> <string>ios-arm64_x86_64-simulator</string>
<key>LibraryPath</key> <key>LibraryPath</key>
<string>QmsPluginFramework.framework</string> <string>QmsPluginFramework.framework</string>
<key>SupportedArchitectures</key> <key>SupportedArchitectures</key>
<array> <array>
<string>arm64</string> <string>arm64</string>
<string>x86_64</string>
</array> </array>
<key>SupportedPlatform</key> <key>SupportedPlatform</key>
<string>ios</string> <string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict> </dict>
<dict> <dict>
<key>BinaryPath</key> <key>BinaryPath</key>
<string>QmsPluginFramework.framework/QmsPluginFramework</string> <string>QmsPluginFramework.framework/QmsPluginFramework</string>
<key>LibraryIdentifier</key> <key>LibraryIdentifier</key>
<string>ios-arm64_x86_64-simulator</string> <string>ios-arm64</string>
<key>LibraryPath</key> <key>LibraryPath</key>
<string>QmsPluginFramework.framework</string> <string>QmsPluginFramework.framework</string>
<key>SupportedArchitectures</key> <key>SupportedArchitectures</key>
<array> <array>
<string>arm64</string> <string>arm64</string>
<string>x86_64</string>
</array> </array>
<key>SupportedPlatform</key> <key>SupportedPlatform</key>
<string>ios</string> <string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict> </dict>
</array> </array>
<key>CFBundlePackageType</key> <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