RulesDetailViewController.m 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. //
  2. // RulesDetailViewController.m
  3. // kneet2
  4. //
  5. // Created by Jason Lee on 11/30/15.
  6. // Copyright © 2015 ntels. All rights reserved.
  7. //
  8. #import "JDObject.h"
  9. #import "RequestHandler.h"
  10. #import "RuleModel.h"
  11. #import "CustomTableView.h"
  12. #import "CustomLabel.h"
  13. #import "CustomButton.h"
  14. #import "CustomImageView.h"
  15. #import "UIImageView+WebCache.h"
  16. #import "RulesDetailViewController.h"
  17. #import "RulesConditionViewController.h"
  18. #import "DeviceModel.h"
  19. #import "RulesAddViewController.h"
  20. @implementation RulesDetailTitleTableViewCell
  21. @end
  22. @implementation RulesDetailHeaderTableViewCell
  23. @end
  24. @implementation RulesDetailTableViewCell
  25. @end
  26. @implementation RulesDetailPushTableViewCell
  27. @end
  28. @implementation RulesDetailConditionHeaderTableViewCell
  29. @end
  30. @implementation RulesDetailConditionTableViewCell
  31. @end
  32. @implementation RulesDetailExecutionTableViewCell
  33. @end
  34. @implementation RulesDetailFooterTableViewCell
  35. @end
  36. @interface RulesDetailViewController () {
  37. RuleDetailModel *_ruleDetail;
  38. NSMutableArray<ItemModel> *_triggers, *_actions, *_conditions;
  39. NSMutableArray *_arrayForHeader, *_arrayForFooter;
  40. RulesConditionViewController *_rcv;
  41. NSInteger _sectionCount;
  42. BOOL _hasDeviceAction, _hasPushAction, _hasCondition; //요일 조건 외의 조건
  43. CustomButton *_btnUseRule;
  44. UIImage *_btnImageRun, *_btnImageStop;
  45. }
  46. @end
  47. #pragma mark - Class Definition
  48. @implementation RulesDetailViewController
  49. - (void)viewDidLoad {
  50. [super viewDidLoad];
  51. // Do any additional setup after loading the view.
  52. [self initProperties];
  53. [self initUI];
  54. [self prepareViewDidLoad];
  55. }
  56. - (void)initProperties {
  57. _arrayForHeader = [[NSMutableArray alloc] init];
  58. _arrayForFooter = [[NSMutableArray alloc] init];
  59. }
  60. - (void)initUI {
  61. if (![JDFacade facade].loginUser.isHomehubOnline) {
  62. _lblTitle.text = @"홈허브 오프라인";
  63. [_lblTitle setColor:kUITextColor02 text:_lblTitle.text];
  64. }
  65. [self initTableViewAsDefaultStyle:_tableView];
  66. [self setThingsPopoverOptions];
  67. _btnImageRun = [UIImage imageNamed:@"img_rule_list_playbtn_active"];
  68. _btnImageStop = [UIImage imageNamed:@"img_rule_list_playbtn_disable"];
  69. }
  70. - (void)prepareViewDidLoad {
  71. [self requestRuleDetail];
  72. }
  73. - (void)setThingsPopoverOptions {
  74. //set Popover Contents
  75. __weak typeof(self) weakSelf = self;
  76. _popooverOptionArray = [[NSMutableArray alloc] init];
  77. [_popooverOptionArray addObject:@{@"menuName" : NSLocalizedString(@"새로고침",nil),
  78. @"iconName": @"img_bg_morepopup_icon_refresh",
  79. @"target": weakSelf,
  80. @"selector": [NSValue valueWithPointer:@selector(requestRuleDetail)]}];
  81. if ([JDFacade facade].loginUser.level > 10) {//파워유저 이상일 경우,
  82. [_popooverOptionArray addObject:@{@"menuName" : NSLocalizedString(@"편집", @"편집"),
  83. @"iconName": @"img_bg_morepopup_icon_edit",
  84. @"target": weakSelf,
  85. @"selector": [NSValue valueWithPointer:@selector(editRule)]}];
  86. [_popooverOptionArray addObject:@{@"menuName" : NSLocalizedString(@"삭제", @"삭제"),
  87. @"iconName": @"img_bg_morepopup_icon_del",
  88. @"target": weakSelf,
  89. @"selector": [NSValue valueWithPointer:@selector(deleteRule)]}];
  90. }
  91. }
  92. - (void)editRule {
  93. RulesAddViewController *vc = (RulesAddViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"RulesAddViewController" storyboardName:@"Rules"];
  94. vc.refRuleDetail = _ruleDetail;
  95. [self presentViewController:vc animated:YES completion:nil];
  96. }
  97. - (void)deleteRule {
  98. [[JDFacade facade] confirmTitle:@"규칙 삭제" message:@"규칙을 삭제하시겠습니까?" completion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  99. if (buttonIndex == 0) {//OK
  100. [self requestDeleteRule];
  101. }
  102. }];
  103. }
  104. #pragma mark - Main Logic
  105. - (void)requestRuleDetail {
  106. NSString *path = [NSString stringWithFormat:API_GET_RULE_DETAIL, _refRule.homegrpRuleId];
  107. [[RequestHandler handler] sendAsyncGetRequestAPIPath:path parameters:nil modelClass:[RuleDetailModel class] completion:^(id responseObject) {
  108. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  109. return;
  110. }
  111. _ruleDetail = (RuleDetailModel *) responseObject;
  112. if (_ruleDetail) {//API 성공 ,
  113. [self setContents];
  114. }
  115. } failure:^(id errorObject) {
  116. JDErrorModel *error = (JDErrorModel *)errorObject;
  117. [[JDFacade facade] alert:error.errorMessage];
  118. }];
  119. }
  120. - (void)setDeviceValue:(NSMutableArray<ItemModel> *)items {
  121. NSArray *matchedArray = [_triggers filteredArrayUsingPredicateFormat:@"itemTypeCode == %@", ksItemSubTypeCodeDevice];
  122. for (ItemModel *item in matchedArray) {//device items
  123. for (ItemSubModel *subItem in item.subItems) {
  124. [[JDFacade facade] setRadioButtonStatus:@YES object:subItem];
  125. [[JDFacade facade] setCheckBoxStatus:@YES object:subItem];
  126. }
  127. }
  128. }
  129. - (void)setContents {
  130. _triggers = (NSMutableArray<ItemModel> *)[[NSMutableArray alloc] initWithArray:_ruleDetail.triggers];
  131. _actions = (NSMutableArray<ItemModel> *)[[NSMutableArray alloc] initWithArray:_ruleDetail.actions];
  132. _conditions = (NSMutableArray<ItemModel> *)[[NSMutableArray alloc] initWithArray:_ruleDetail.conditions];
  133. [self setDeviceValue:_triggers];
  134. [self setDeviceValue:_actions];
  135. [self setDeviceValue:_conditions];
  136. //check elements
  137. _hasDeviceAction = [_actions objectKey:@"itemSubTypeCode" eqaulToString:ksItemSubTypeCodeDevice] != nil;
  138. _hasPushAction = [_actions objectKey:@"itemSubTypeCode" eqaulToString:ksItemSubTypeCodeAppPush] != nil;
  139. _hasCondition = [_conditions objectKey:@"itemSubTypeCode" eqaulToString:ksConditionSubTypeCodeHomeMode] != nil;
  140. _hasCondition = [_conditions objectKey:@"itemSubTypeCode" eqaulToString:ksConditionSubTypeCodeDueDate] ? YES : _hasCondition;
  141. _hasCondition = [_conditions objectKey:@"itemSubTypeCode" eqaulToString:ksItemSubTypeCodeDevice] ? YES : _hasCondition;
  142. [_tableView reloadData];
  143. }
  144. - (void)requestDeleteRule {
  145. NSString *path = [NSString stringWithFormat:API_DELETE_RULE, _ruleDetail.homegrpRuleId];
  146. [[RequestHandler handler] sendAsyncRequestAPIPath:path method:ksHTTPRequestDELETE parameters:nil modelClass:[JDJSONModel class] showLoadingView:YES completion:^(id responseObject) {
  147. [[JDFacade facade] dismissModalStack:YES completion:^{
  148. [[JDFacade facade] toast:NSLocalizedString(@"삭제되었습니다", @"삭제되었습니다")];
  149. }];
  150. } failure:^(id errorObject) {
  151. JDErrorModel *error = (JDErrorModel *)errorObject;
  152. [[JDFacade facade] alert:error.errorMessage];
  153. }];
  154. }
  155. - (void)requestChangeRuleStatus {
  156. //parameters
  157. NSDictionary *parameter = @{@"status_code" : [_ruleDetail.useYn boolValue] ? @"03" : @"02"};
  158. NSString *path = [NSString stringWithFormat:API_POST_RULE_STATUS, _ruleDetail.homegrpRuleId];
  159. [[RequestHandler handler] sendAsyncPostRequestAPIPath:path parameters:parameter modelClass:[JDJSONModel class] completion:^(id responseObject) {
  160. _ruleDetail.useYn = [_ruleDetail.useYn boolValue] ? ksNO : ksYES; //toggle
  161. if ([_ruleDetail.useYn boolValue]) {
  162. [[JDFacade facade] toast:@"규칙을 다시 시작합니다"];
  163. } else {
  164. [[JDFacade facade] toast:@"규칙을 중단합니다"];
  165. }
  166. [_tableView reloadData];
  167. } failure:^(id errorObject) {
  168. JDErrorModel *error = (JDErrorModel *)errorObject;
  169. [[JDFacade facade] alert:error.errorMessage];
  170. }];
  171. }
  172. #pragma mark - UITableView DataSource & Delegate
  173. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  174. return 6;
  175. }
  176. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  177. NSInteger count = 0;
  178. if (section == 0 || section == 5) {//title
  179. count = 1;
  180. } else if (section == 1) {//triggers
  181. count = _triggers && _triggers.count ? _triggers.count : 0;
  182. } else if (section == 2) {//actions
  183. ItemModel *deviceItem = [_actions objectKey:@"itemSubTypeCode" eqaulToString:ksItemSubTypeCodeDevice];
  184. count = deviceItem.subItems && deviceItem.subItems.count ? deviceItem.subItems.count : 0;
  185. } else if (section == 3) {
  186. count = _hasPushAction;
  187. } else if (section == 4) {
  188. count = _hasCondition;
  189. }
  190. return count;
  191. }
  192. - (NSString *)headerTitleForSection:(NSInteger)section {
  193. NSString *title = nil;
  194. if (section == 1) {//trigger
  195. title = @"이 때가 되면";
  196. if (_triggers && _triggers.count) {
  197. ItemModel *item = _triggers[0];
  198. if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeDevice]) {
  199. title = @"장치 상태가 바뀔 때";
  200. } else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeTimer]) {
  201. title = @"이 시간마다";
  202. } else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeHeat]) {
  203. title = @"더울때 / 추울때";
  204. } else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeDaylight]) {
  205. title = @"해뜰때 / 질때";
  206. }
  207. }
  208. } else if (section == 2) {//action
  209. title = @"이 장치를 실행";
  210. } else if (section == 3) {//pushes
  211. title = @"알림 메시지";
  212. }
  213. return title;
  214. }
  215. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  216. UIView *view = _arrayForHeader.count > section ? _arrayForHeader[section] : nil;
  217. if (!view) {
  218. if (section == 0 || section == 5) {//title
  219. view = [[UIView alloc] init];
  220. } else if (section == 1 || section == 2 || section == 3) {
  221. RulesDetailHeaderTableViewCell *hcell = (RulesDetailHeaderTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"HeaderCellIdentifier"];
  222. hcell.width = IPHONE_WIDTH;
  223. view = [[UIView alloc] initWithFrame:hcell.contentView.frame];
  224. [view addSubview:hcell];
  225. hcell.lblTitle.text = [self headerTitleForSection:section];
  226. } else if (section == 4) {//conditions
  227. RulesDetailConditionHeaderTableViewCell *hcell = (RulesDetailConditionHeaderTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"ConditionHeaderCellIdentifier"];
  228. hcell.width = IPHONE_WIDTH;
  229. view = [[UIView alloc] initWithFrame:hcell.contentView.frame];
  230. [view addSubview:hcell];
  231. }
  232. if (_arrayForHeader.count == section) {
  233. [_arrayForHeader insertObject:view atIndex:section];
  234. }
  235. } else {
  236. if ((section == 2 && !_hasDeviceAction) || (section == 3 && !_hasPushAction) || (section == 4 && !_hasCondition)) {
  237. view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, CGFLOAT_MIN)];
  238. } else if (section == 1 || section == 2 || section == 3) {
  239. RulesDetailHeaderTableViewCell *hcell = (RulesDetailHeaderTableViewCell *)view.subviews[0];
  240. hcell.lblTitle.text = hcell.lblTitle.text = [self headerTitleForSection:section];
  241. }
  242. }
  243. return view;
  244. }
  245. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  246. CGFloat height = 75.0f;
  247. if (section == 0 || section == 5) {
  248. height = CGFLOAT_MIN;
  249. } else if (section == 2) {
  250. height = _hasDeviceAction ? 75.0f : CGFLOAT_MIN;
  251. } else if (section == 3) {
  252. height = _hasPushAction ? 75.0f : CGFLOAT_MIN;
  253. } else if (section == 4) {
  254. height = _hasCondition ? 75.0f : CGFLOAT_MIN;
  255. }
  256. return height;
  257. }
  258. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  259. UIView *view = _arrayForFooter.count > section ? _arrayForFooter[section] : nil;
  260. if (!view) {
  261. RulesDetailFooterTableViewCell *hcell = (RulesDetailFooterTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"FooterCellIdentifier"];
  262. hcell.width = IPHONE_WIDTH;
  263. if (section == 4) {
  264. hcell.topLine.hidden = YES;
  265. }
  266. view = [[UIView alloc] initWithFrame:hcell.contentView.frame];
  267. [view addSubview:hcell];
  268. if (_arrayForHeader.count == section) {
  269. [_arrayForHeader insertObject:view atIndex:section];
  270. }
  271. }
  272. return view;
  273. }
  274. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  275. CGFloat height = 15.0f;
  276. if (section == 0 || section == 5) {
  277. height = CGFLOAT_MIN;
  278. } else if (section == 2) {
  279. height = _hasDeviceAction ? 15.0f : CGFLOAT_MIN;
  280. } else if (section == 3) {
  281. height = _hasPushAction ? 15.0f : CGFLOAT_MIN;
  282. } else if (section == 4) {
  283. height = _hasCondition ? 15.0f : CGFLOAT_MIN;
  284. }
  285. return height;
  286. }
  287. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  288. CGFloat height = 0.0f;
  289. NSInteger section = indexPath.section;
  290. if (section == 0) {//title
  291. height = 56;
  292. } else if (section == 1) {//triggers
  293. height = 86;
  294. } else if (section == 2) {//actions
  295. height = 86;
  296. } else if (section == 3) {//push-message
  297. ItemModel *pushItem = [_actions objectKey:@"itemSubTypeCode" eqaulToString:ksItemSubTypeCodeAppPush];
  298. ItemSubModel *push = pushItem.subItems[0];
  299. CGFloat width = IPHONE_WIDTH - 85;
  300. CustomLabel *lblTemp = [[CustomLabel alloc] initWithFrame:CGRectMake(0, 0, width, 18)];
  301. lblTemp.font = [UIFont systemFontOfSize:kUIFontSize02];
  302. lblTemp.numberOfLines = 0;
  303. CGFloat adjustHeight = [CommonUtil getSizeFromString:push.cmdclsValue font:lblTemp.font width:width].height;
  304. adjustHeight = adjustHeight < 18 ? 0 : adjustHeight - 18;
  305. height = 61 + adjustHeight;
  306. } else if (section == 4) {//conditions
  307. if (!_rcv) {
  308. _rcv = [CommonUtil instantiateViewControllerWithIdentifier:@"RulesConditionViewController" storyboardName:@"Rules"];
  309. [self addChildViewController:_rcv];
  310. [_rcv didMoveToParentViewController:self];
  311. }
  312. height = _rcv.tableHeight;
  313. } else if (section == 5) {//execution
  314. height = [JDFacade facade].loginUser.level == 90 ? 190.0f: 190.0f - 75.0f; //마스터만 규칙 실행 여부를 설정 가능함.
  315. }
  316. return height;
  317. }
  318. - (void)configureTriggerCell:(RulesDetailTableViewCell *)cell item:(ItemModel *)item {
  319. ItemSubModel *subItem = nil;
  320. if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeDevice]) {//장치일 경우
  321. subItem = [item.subItems matchedObjectName:ksCustomRadioButtonStatus condition:YES];
  322. cell.lblItem.text = subItem.sourceName;
  323. if ([subItem.deleteYn boolValue]) {
  324. [cell.lblItem setStrikethrough:cell.lblItem.text];
  325. }
  326. cell.lblSubItem.text = subItem.sourceSubName;
  327. //노드의 액션 값을 세팅함.
  328. if (subItem.cmdclsValueList && subItem.cmdclsValueList.count) {//커맨드클래스 밸루 리스트가 있을 경우,
  329. CmdClsValueModel *cmdclsValue = [subItem.cmdclsValueList matchedObjectName:ksCustomRadioButtonStatus condition:YES];
  330. cell.lblCondition.text = [DeviceModel contentValueMsgByCmdClsCode:subItem.cmdclsCode cmdclsTypeId:(NSString *)subItem.cmdclsTypeId contentValue:cmdclsValue.cmdclsValue];
  331. } else {
  332. if (subItem.cmdclsValueMsg) {
  333. cell.lblCondition.text = subItem.cmdclsValueMsg;
  334. } else {
  335. NSString *condition = [subItem.conditionTypeCode isEqualToString:ksConditionTypeCodeGreatOrEqual] ? @"이상" : @"이하";
  336. cell.lblCondition.text = [NSString stringWithFormat:@"%@%@ %@", subItem.cmdclsValue, subItem.unit, condition];
  337. }
  338. }
  339. cell.lblCondition.hidden = NO;
  340. } else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeTimer]) {
  341. subItem = item.subItems && item.subItems.count ? item.subItems[0] : nil;
  342. if (subItem) {
  343. NSInteger phour = [subItem.hour integerValue];
  344. NSString *period = phour < 12 ? @"AM" : @"PM";//NSLocalizedString(@"오전", @"오전") : NSLocalizedString(@"오후", @"오후");
  345. if ([period isEqualToString:@"PM"]) {
  346. if (phour > 12) {
  347. phour -= 12;
  348. }
  349. }
  350. NSString *title = [NSString stringWithFormat:@"%@ %zd:%@", period, phour, subItem.minute];
  351. // NSDictionary *titleColor = @{NSForegroundColorAttributeName : kUITextColor02};
  352. cell.lblItem.text = title;
  353. cell.lblSubItem.text = [self daysOfWeekAtSubItem];
  354. cell.lblCondition.hidden = YES;
  355. }
  356. } else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeDaylight]) {
  357. subItem = item.subItems && item.subItems.count ? item.subItems[0] : nil;
  358. if (subItem) {
  359. NSString *title = [subItem.sourceSubId isEqualToString:@"sunriseUtcTime"] ? @"해뜰때" : @"해질때";
  360. cell.lblItem.text = title;
  361. cell.lblSubItem.text = [NSString stringWithFormat:@"%@ / %@", subItem.sourceName, [self daysOfWeekAtSubItem]];
  362. cell.lblCondition.hidden = YES;
  363. }
  364. } else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeHeat]) {
  365. subItem = item.subItems && item.subItems.count ? item.subItems[0] : nil;
  366. if (subItem) {
  367. NSString *title = [subItem.conditionTypeCode isEqualToString:ksConditionTypeCodeGreatOrEqual] ? @"더울때" : @"추울때";
  368. cell.lblItem.text = title;
  369. cell.lblSubItem.text = [NSString stringWithFormat:@"%@ / %@℃ / %@", subItem.sourceName, subItem.cmdclsValue, [self daysOfWeekAtSubItem]];
  370. cell.lblCondition.hidden = YES;
  371. }
  372. }
  373. [cell.imgvIcon sd_setImageWithURL:[NSURL URLWithString:subItem.imageFileName] placeholderImage:nil options:SDWebImageRefreshCached];
  374. }
  375. - (NSString *)daysOfWeekAtSubItem {
  376. NSString *daysOfWeek = ksEmptyString;
  377. ItemModel *daysCondition = [_conditions objectKey:@"itemSubTypeCode" eqaulToString:ksConditionSubTypeCodeDaysOfWeek];
  378. if (daysCondition) {
  379. ItemSubModel *subCondition = daysCondition.subItems[0];
  380. daysOfWeek = subCondition.daysOfWeek;
  381. }
  382. return daysOfWeek;
  383. }
  384. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  385. NSInteger section = indexPath.section;
  386. UITableViewCell *cell = nil;
  387. if (section == 0) {//title
  388. RulesDetailTitleTableViewCell *tcell = (RulesDetailTitleTableViewCell *)[_tableView dequeueReusableCellWithIdentifier:@"TitleCellIdentifier"];
  389. tcell.lblRuleTitle.text = _ruleDetail.ruleName;
  390. cell = tcell;
  391. } else if (section == 1) {//triggers
  392. ItemModel *item = _triggers[indexPath.row];
  393. RulesDetailTableViewCell *tcell = (RulesDetailTableViewCell *)[_tableView dequeueReusableCellWithIdentifier:@"RulesCellIdentifier"];
  394. [self configureTriggerCell:tcell item:item];
  395. tcell.lblItem.textColor = kUITextColor02;
  396. cell = tcell;
  397. } else if (section == 2) {//actions - 장치일 경우,
  398. ItemModel *deviceItem = [_actions objectKey:@"itemSubTypeCode" eqaulToString:ksItemSubTypeCodeDevice];
  399. ItemSubModel *subItem = deviceItem.subItems[indexPath.row];
  400. RulesDetailTableViewCell *tcell = (RulesDetailTableViewCell *)[_tableView dequeueReusableCellWithIdentifier:@"RulesCellIdentifier"];
  401. tcell.lblItem.text = subItem.sourceName;
  402. tcell.lblItem.textColor = kUITextColor01;
  403. if ([subItem.deleteYn boolValue]) {
  404. [tcell.lblItem setStrikethrough:tcell.lblItem.text];
  405. }
  406. tcell.lblSubItem.text = subItem.sourceSubName;
  407. tcell.lblCondition.text = subItem.cmdclsValueMsg; //노드의 액션 값을 세팅함.
  408. [tcell.imgvIcon sd_setImageWithURL:[NSURL URLWithString:subItem.imageFileName] placeholderImage:nil options:SDWebImageRefreshCached];
  409. cell = tcell;
  410. } else if (section == 3) {//actions - push-message
  411. ItemModel *pushItem = [_actions objectKey:@"itemSubTypeCode" eqaulToString:ksItemSubTypeCodeAppPush];
  412. ItemSubModel *subItem = pushItem.subItems[indexPath.row];
  413. RulesDetailPushTableViewCell *tcell = (RulesDetailPushTableViewCell *)[_tableView dequeueReusableCellWithIdentifier:@"PushCellIdentifier"];
  414. tcell.lblMessage.text = subItem.cmdclsValue;
  415. cell = tcell;
  416. } else if (section == 4) {//conditions
  417. RulesDetailConditionTableViewCell *tcell = (RulesDetailConditionTableViewCell *)[_tableView dequeueReusableCellWithIdentifier:@"ConditionCellIdentifier"];
  418. if (!tcell.container.subviews.count) {
  419. if ([self isViewLoaded]) {
  420. [_rcv beginAppearanceTransition:YES animated:NO];
  421. [tcell.container addSubview:_rcv.view];
  422. [_rcv endAppearanceTransition];
  423. }
  424. }
  425. tcell.constraintContainerHeight.constant = _rcv.tableHeight;
  426. _rcv.isShowingMode = YES;
  427. _rcv.conditions = _conditions;
  428. cell = tcell;
  429. } else if (section == 5) {//execution
  430. RulesDetailExecutionTableViewCell *tcell = (RulesDetailExecutionTableViewCell *)[_tableView dequeueReusableCellWithIdentifier:@"ExecutionCellIdentifier"];
  431. tcell.lblExecutionDate.text = !_ruleDetail.latestExecutionDatetime || [_ruleDetail.latestExecutionDatetime isEmptyString] ? @"-" : [CommonUtil localDateFromUTC2:_ruleDetail.latestExecutionDatetime];
  432. tcell.btnUseRule.selected = [_ruleDetail.useYn boolValue];
  433. tcell.statusView.hidden = [JDFacade facade].loginUser.level < 90; //심플 유저일 경우,
  434. if (tcell.statusView.hidden) {
  435. // tcell.constraintStatusViewBottom.constant = 0;
  436. tcell.constraintStatusViewHeight.constant = 0;
  437. tcell.statusView.hidden = YES;
  438. } else {//마스터일 경우,
  439. if (!_btnUseRule) {
  440. _btnUseRule = tcell.btnUseRule;
  441. }
  442. [self changeBtnRunStatus:[_ruleDetail.useYn boolValue]];
  443. if (![tcell.btnUseRule actionsForTarget:self forControlEvent:UIControlEventTouchUpInside]) {
  444. [tcell.btnUseRule addTarget:self action:@selector(btnUseRuleTouched:) forControlEvents:UIControlEventTouchUpInside];
  445. }
  446. }
  447. cell = tcell;
  448. }
  449. return cell;
  450. }
  451. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  452. [super tableView:tableView didSelectRowAtIndexPath:indexPath];
  453. }
  454. #pragma mark - Table Events
  455. - (void)btnUseRuleTouched:(id)sender {
  456. if ([_ruleDetail.useYn isEqualToString:ksKneetRulesDisable]) {
  457. [[JDFacade facade] toast:@"일부 장치 또는 멤버가 삭제되어 비활성 되었습니다.\n편집 후 다시 사용해주세요."];
  458. return;
  459. }
  460. [self requestChangeRuleStatus];
  461. }
  462. - (void)changeBtnRunStatus:(BOOL)isRun {
  463. if (isRun) {
  464. [_btnUseRule setImage:_btnImageRun forState:UIControlStateNormal];
  465. } else {
  466. [_btnUseRule setImage:_btnImageStop forState:UIControlStateNormal];
  467. }
  468. }
  469. #pragma mark - UI Events
  470. - (IBAction)btnOptionTouched:(id)sender {
  471. [self toggleOptions:sender];
  472. }
  473. - (void)btnCloseTouched:(id)sender {
  474. [[JDFacade facade] dismissModalStack:YES completion:nil];
  475. }
  476. #pragma mark - MemoryWarning
  477. - (void)didReceiveMemoryWarning
  478. {
  479. [super didReceiveMemoryWarning];
  480. // Dispose of any resources that can be recreated.
  481. }
  482. @end