ManagementViewController.m 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. //
  2. // ManagementViewController.m
  3. // OneCable
  4. //
  5. // Created by nComz on 2017. 4. 12..
  6. // Copyright © 2017년 ntels. All rights reserved.
  7. //
  8. #import "JDObject.h"
  9. #import "RequestHandler.h"
  10. #import "CustomLabelButton.h"
  11. #import "ImageUtil.h"
  12. #import "HomeModeUpdateViewController.h"
  13. #import "HomeModeSettingsViewController.h"
  14. #import "PwdPopupView.h"
  15. #import "MainViewController.h"
  16. #import "ManagementViewController.h"
  17. /**
  18. 모드 버튼 Bg Image
  19. on : common_homemode_icon_bg_on
  20. off : common_homemode_icon_bg_off
  21. 모드 버튼 Icon Image
  22. 기상 : common_homemode_icon_wakeup_on , _off
  23. 외출 : common_homemode_icon_outing_on , _off
  24. 귀가 : common_homemode_icon_homecoming_on , _off
  25. 취침 : common_homemode_icon_sleep_on , _off
  26. **/
  27. @interface ManagementViewController ()
  28. {
  29. DashboardModel *_dashboard;
  30. BOOL _isNotFirstLoading;
  31. }
  32. @end
  33. @implementation ManagementViewController
  34. - (void)viewDidLoad {
  35. [super viewDidLoad];
  36. }
  37. - (void)prepareViewDidLoad {
  38. [self setContents];
  39. [self performSelector:@selector(requestDashboard:) withObject:nil afterDelay:0.0f];
  40. }
  41. - (void)updateHomeHubStatusToManage {
  42. [self setContents];
  43. }
  44. // 공지사항 이동
  45. - (IBAction)btnNoticeTouched:(id)sender {
  46. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"NoticeViewController" storyboardName:@"Main"];
  47. [self presentViewController:vc animated:YES completion:nil];
  48. }
  49. // 자주 찾는 질문 이동
  50. - (IBAction)btnFaqTouched:(id)sender {
  51. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"FaqViewController" storyboardName:@"Main"];
  52. [self presentViewController:vc animated:YES completion:nil];
  53. }
  54. // 메시지 박스 이동
  55. - (IBAction)btnMessageBoxTouched:(id)sender {
  56. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"MessageBoxViewController" storyboardName:@"Main"];
  57. [self presentViewController:vc animated:YES completion:nil];
  58. }
  59. // 홈허브 이동
  60. - (IBAction)btnHomeHubTouched:(id)sender {
  61. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"HomeHubViewController" storyboardName:@"Main"];
  62. [self presentViewController:vc animated:YES completion:nil];
  63. }
  64. // 설정 이동
  65. - (IBAction)btnSettingsTouched:(id)sender {
  66. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"SettingsViewController" storyboardName:@"Settings"];
  67. [self presentViewController:vc animated:YES completion:nil];
  68. }
  69. - (IBAction)btnModeHomeTouched:(id)sender {
  70. [self doChangeHomeMode:HOME_MODE_HOME];
  71. }
  72. - (IBAction)btnModeAwayTouched:(id)sender {
  73. [self doChangeHomeMode:HOME_MODE_AWAY];
  74. }
  75. - (IBAction)btnModeMorningTouched:(id)sender {
  76. [self doChangeHomeMode:HOME_MODE_MORNING];
  77. }
  78. - (IBAction)btnModeNightTouched:(id)sender {
  79. [self doChangeHomeMode:HOME_MODE_NIGHT];
  80. }
  81. //- (IBAction)btnDashboardRefresh:(id)sender {
  82. // [self requestDashboard:nil];
  83. //}
  84. - (void)requestDashboard:(JDFacadeCompletionCallBackHandler)completion {
  85. //parameters
  86. NSDictionary *parameter = @{@"member_id": [JDFacade facade].loginUser.memberId,
  87. @"notice_read_datetime": [JDFacade facade].loginUser.noticeReadTime ? [JDFacade facade].loginUser.noticeReadTime : ksEmptyString,
  88. @"message_read_datetime": [JDFacade facade].loginUser.personalNoticeReadTime ? [JDFacade facade].loginUser.personalNoticeReadTime : ksEmptyString};
  89. NSString *path = [[JDFacade facade] getUrlWithCustAndGroupID:API_GET_DASHBOARD arguments:nil];
  90. // NSString *path = [NSString stringWithFormat:API_GET_DASHBOARD, [[JDFacade facade].loginUser custId], [[JDFacade facade].loginUser ctrtGrpId]];
  91. [[RequestHandler handler] sendAsyncGetRequestAPIPath:path parameters:parameter modelClass:[DashboardModel class] completion:^(id responseObject) {
  92. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  93. return;
  94. }
  95. DashboardModel *dashboard = (DashboardModel *) responseObject;
  96. NSLog(@"DashBoard Info : %@", responseObject);
  97. if (dashboard) {//API 성공 ,
  98. _dashboard = dashboard;
  99. // if (!_isNotFirstLoading) {
  100. // _isNotFirstLoading = YES;
  101. // FIXME : 이부분이 어떤 내용인지 파악해야 한다.
  102. // [JDFacade facade].loginUser.homehubDeviceId = _dashboard.deviceId; //초대에서 넘어오는 경우,
  103. // when first loading this view.
  104. // [self initThingsViewController];
  105. //
  106. // self.currentChildViewController = _tvc;
  107. // [_btnThings setHighlighted:YES];
  108. // }
  109. // [self setContents];
  110. }
  111. if (completion) {
  112. completion();
  113. }
  114. } failure:^(id errorObject) {
  115. JDErrorModel *error = (JDErrorModel *)errorObject;
  116. [[JDFacade facade] alert:error.errorMessage];
  117. }];
  118. }
  119. //extendView 컨텐츠 설정
  120. - (void)setContents {
  121. _lblNoticeCount.text = _dashboard.noticeCount;
  122. _lblPushCount.text = _dashboard.pushCount;
  123. _imgvHomehubOff.hidden = [JDFacade facade].loginUser.isHomehubOnline;
  124. // _btnHomeHub.enabled = [JDFacade facade].loginUser.hasHomeHub;
  125. // _btnHomeHub.alpha = _btnHomeHub.enabled ? 1.0f : 0.4f;
  126. //don't delete - FOR KNEET2.0
  127. // [_btnHomegrpImage sd_setImageWithURL:[NSURL URLWithString:_dashboard.imageFileName] forState:UIControlStateNormal placeholderImage:nil options:SDWebImageRefreshCached];
  128. NSInteger i = 0;
  129. for (ModeModel *mode in _dashboard.modeList) {//모드버튼 설정
  130. CustomLabelButton *btn = _btnModes[i];
  131. [btn setTitle:mode.modeName];
  132. if (![JDFacade facade].loginUser.hasHomeHub) {//비활성모드 : 홈허브가 없을 경우, 또는 삭제된 경우,
  133. [btn sd_setImageWithURL:[NSURL URLWithString:mode.imageFileDisableName] forState:UIControlStateNormal];
  134. // btn.label.textColor = kUITextColor04;
  135. // btn.label.alpha = 0.4f;
  136. btn.enabled = NO;
  137. } else {
  138. if ([mode.useYn boolValue]) {//활성모드
  139. [btn sd_setImageWithURL:[NSURL URLWithString:mode.imageFileActiveName] forState:UIControlStateNormal];
  140. // btn.label.textColor = kUITextColor01;
  141. // btn.label.alpha = 1.0f;
  142. btn.enabled = YES;
  143. } else {//일반모드
  144. [btn sd_setImageWithURL:[NSURL URLWithString:mode.imageFileName] forState:UIControlStateNormal];
  145. // btn.label.textColor = kUITextColor04;
  146. // btn.label.alpha = 1.0f;
  147. btn.enabled = YES;
  148. }
  149. }
  150. i++;
  151. }
  152. // MainViewController *main = [[MainViewController alloc]init];
  153. // [main checkTempPassword];
  154. }
  155. - (void)doChangeHomeMode:(NSString *)modeCode {
  156. if (![JDFacade facade].loginUser.isHomehubOnline || ![JDFacade facade].loginUser.hasHomeHub) {
  157. [[JDFacade facade] toast:@"홈허브가 온라인 상태로\n연결되어 있을 때 시도해주세요"];
  158. return;
  159. }
  160. ModeModel *mode = [_dashboard.modeList objectKey:@"basicModeCode" eqaulToString:modeCode];
  161. // 로직 변경
  162. // if (!mode.homegrpSceneId || [mode.homegrpSceneId isEmptyString]) {
  163. //
  164. // if ([JDFacade facade].loginUser.level < 90) {//일반 멤버
  165. // [[JDFacade facade] toast:@"아직 선택된 장치가 없습니다.\r장치선택은 마스터만 할 수 있습니다."];
  166. // } else {
  167. // HomeModeSettingsViewController *vc = (HomeModeSettingsViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"HomeModeSettingsViewController" storyboardName:@"Main"];
  168. // vc.mode = mode;
  169. //
  170. // [self presentViewController:vc animated:YES completion:nil];
  171. // }
  172. // return;
  173. // }
  174. HomeModeUpdateViewController *vc = (HomeModeUpdateViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"HomeModeUpdateViewController" storyboardName:@"Main"];
  175. vc.mode = mode;
  176. [self presentViewController:vc animated:YES completion:nil];
  177. }
  178. - (void)didReceiveMemoryWarning {
  179. [super didReceiveMemoryWarning];
  180. }
  181. @end