| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873 |
- //
- // RulesAddViewController.m
- // kneet2
- //
- // Created by Jason Lee on 11/20/15.
- // Copyright © 2015 ntels. All rights reserved.
- //
- #import "JDObject.h"
- #import "RequestHandler.h"
- #import "ItemModel.h"
- #import "RuleModel.h"
- #import "DeviceModel.h"
- #import "CustomLabel.h"
- #import "CustomButton.h"
- #import "CustomImageView.h"
- #import "CustomTableView.h"
- #import "CustomCheckBox.h"
- #import "CustomTextView.h"
- #import "CustomTextField.h"
- #import "UIImageView+WebCache.h"
- #import "ValidateUtil.h"
- #import "DeviceSelectPopupView.h"
- #import "DeviceNodePopupView.h"
- #import "TriggerSelectPopupView.h"
- #import "ConditionSelectPopupView.h"
- #import "RulesConditionHomeModePopupView.h"
- #import "RulesConditionViewController.h"
- #import "RulesAddViewController.h"
- #import "RulesAddCompleteViewController.h"
- #import "RulesDetailViewController.h"
- #import "RulesViewController.h"
- #import "TimePickerPopupView.h"
- #import "DaylightPopupView.h"
- #import "ExternHeatPopupView.h"
- #import "ActionDeviceCommandPopupView.h"
- //규칙이름
- @implementation RulesAddTitleTableViewCell
- #pragma mark - textfield delegate
- - (BOOL)textFieldShouldReturn:(UITextField *)textField {
-
- return YES;
- }
- - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
- NSString *text = [textField.text stringByReplacingCharactersInRange:range withString:string];
- BOOL input = text.length == 0;
-
- _btnConfirm.hidden = input;
- _btnAdd.hidden = !input;
-
- return YES;
- }
- @end
- //알림 메시지
- @interface RulesAddTextTableViewCell() <UITextViewDelegate>
- @property (nonatomic, strong) void (^statusChangeBlock)(NSInteger tag, CGFloat height) ;
- @property (weak, nonatomic) IBOutlet NSLayoutConstraint *constTxtHeight;
- @property CGRect previousRect;
- @end
- @implementation RulesAddTextTableViewCell
- - (void)awakeFromNib {
- [super awakeFromNib];
-
- _previousRect = CGRectZero;
- _previousRect.origin.y = 11.f;
- }
- - (void)registTvStatusChangeBlock:(void (^)(NSInteger tag, CGFloat height)) statusChangeBlock {
-
- _statusChangeBlock = statusChangeBlock ;
- }
- - (void)invokeChangeHeight:(CGFloat)height {
-
- if( _statusChangeBlock != nil )
- _statusChangeBlock(1, height) ;
- }
- #pragma mark - textView delegate
- - (void)textViewDidChange:(UITextView *)textView {
-
- UITextPosition* pos = _txtView.endOfDocument;
- CGRect currentRect = [_txtView caretRectForPosition:pos];
- CGFloat previousY = _previousRect.origin.y;
-
-
- if (previousY != currentRect.origin.y) {
-
- CGFloat height = currentRect.origin.y - previousY;
- _constTxtHeight.constant = _constTxtHeight.constant + height < 48.f ? 48.f : _constTxtHeight.constant + height;
- [self invokeChangeHeight:height];
- }
-
- _previousRect = currentRect;
- }
- - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
-
- NSString *string = [textView.text stringByReplacingCharactersInRange:range withString:text];
- BOOL input = string.length == 0;
-
- _btnConfirm.hidden = input;
- _btnAdd.hidden = !input;
-
- return YES;
- }
- - (void)textViewDidBeginEditing:(UITextView *)textView {
-
- _imgTxtBg.highlighted = YES;
-
- if( _statusChangeBlock != nil )
- _statusChangeBlock(0, 0) ;
- }
- - (void)textViewDidEndEditing:(UITextView *)textView {
-
- _imgTxtBg.highlighted = NO;
- }
- @end
- @implementation RulesAddHeaderTableViewCell
- @end
- @implementation RulesAddTableViewCell
- @end
- @implementation RulesAddPushTableViewCell
- @end
- @implementation RulesAddConditionHeaderTableViewCell
- @end
- @implementation RulesAddConditionTableViewCell
- @end
- @implementation RulesAddFooterTableViewCell
- @end
- @interface RulesAddViewController () <KeyboardFrameChangedDelegate> {
-
-
- NSMutableArray<ItemModel> *_triggerDevices, *_actionDevices, *_conditionDevices;
-
- BOOL _isNotFirstLoading, _hasCondition;
- NSMutableArray *_arrayForHeader, *_arrayForFooter;
- CGFloat textCellChangeHeight; //알림 메세지 셀 사이즈 변동
-
-
- CustomTextField *_txtRuleTitle;
- CustomTextView *_txvMessage;
- CustomButton *_btnTriggerAdd, *_btnPushAdd;
-
- CustomCheckBox *_chkConditions;
-
- RulesConditionHomeModePopupView *_mpopup;
- RulesConditionViewController *_rcv;
-
- __weak IBOutlet NSLayoutConstraint *constTableBottom;
-
- }
- @property (strong, nonatomic) NSMutableArray<ItemModel> *triggers;
- @property (strong, nonatomic) NSMutableArray<ItemModel> *actions;
- @property (strong, nonatomic) NSMutableArray<ItemModel> *conditions;
- @end
- @implementation RulesAddViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- [self initProperties];
- [self initUI];
- [self prepareViewDidLoad];
-
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
-
- [self addObserverKeyboardFrameChanged:self] ;
- }
- - (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
-
- [self removeObserverKeyboard] ;
- }
- #pragma mark - Keyboard Frame Changed Delegate
- - (void)keyboardFrameChanged:(CGRect)frame duration:(CGFloat)duration display:(BOOL)display {
- [UIView animateWithDuration:duration animations:^{
-
- if( display ) {
- constTableBottom.constant = frame.size.height;
- }
- else {
- constTableBottom.constant = 50.0f;
- }
- [self.view layoutIfNeeded];
-
- }] ;
- }
- #pragma mark - init
- - (void)initProperties {
- _arrayForHeader = [[NSMutableArray alloc] init];
- _arrayForFooter = [[NSMutableArray alloc] init];
-
- if (!_triggers) {
- _triggers = (NSMutableArray<ItemModel> *)[[NSMutableArray alloc] init];
- }
-
- if (!_actions) {
- _actions = (NSMutableArray<ItemModel> *)[[NSMutableArray alloc] init];
- }
- if (!_conditions) {
- _conditions = (NSMutableArray<ItemModel> *)[[NSMutableArray alloc] init];
- }
- }
- - (void)initUI {
-
- [self initTableViewAsDefaultStyle:_tableView];
-
- if (_refRuleDetail) {
- _lblTitle.text = @"규칙 편집";
- }
- }
- - (void)prepareViewDidLoad {
-
- [self requestDeviceListForAction:ksItemTypeCodeTrigger];
- [self requestDeviceListForAction:ksItemTypeCodeAction];
- }
- //말줄임표 conv
- - (NSString*)convMaxLengthName:(NSString*)name len:(NSInteger)len {
-
-
- if (name.length > len) {
-
- return [NSString stringWithFormat:@"%@..", [name substringToIndex:len]];
- }
-
- return name;
- }
- #pragma mark - Main Logic
- - (void)requestDeviceListForAction:(NSString *)typeCode {
- //parameters
- // NSDictionary *parameter = @{@"item_type_code": typeCode};
- NSArray *arr = @[typeCode];
- // NSString *path = [NSString stringWithFormat:API_GET_ITEM_DEVICES, ksItemTypeCodeAction];
- NSString *path = [[JDFacade facade] getUrlWithCustAndGroupID:API_GET_ITEM_DEVICES arguments:arr];
-
- [[RequestHandler handler] sendAsyncGetRequestAPIPath:path parameters:nil modelClass:[ItemListModel class] completion:^(id responseObject) {
- if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
- return;
- }
-
- ItemListModel *fetchedItemList = (ItemListModel *)responseObject;
-
- if (fetchedItemList && fetchedItemList.list && fetchedItemList.list.count) {//API 성공 ,
-
- if ([typeCode isEqualToString:ksItemTypeCodeAction]) {
- _actionDevices = fetchedItemList.list;
- if (_refRuleDetail) {//편집일 경우,
- ItemModel *actionDevice = [_actions objectKey:@"itemSubTypeCode" eqaulToString:ksItemSubTypeCodeDevice];
- [self matchValueOfDevices:actionDevice devices:_actionDevices];
- }
-
- } else {
-
- _triggerDevices = fetchedItemList.list;
- _conditionDevices = [(NSMutableArray<ItemModel> *)[NSMutableArray alloc] initWithArray:_triggerDevices copyItems:YES];
-
- if (_refRuleDetail) {//편집일 경우,
- ItemModel *triggerDevice = [_triggers objectKey:@"itemSubTypeCode" eqaulToString:ksItemSubTypeCodeDevice];
- ItemModel *conditionDevice = [_conditions objectKey:@"itemSubTypeCode" eqaulToString:ksItemSubTypeCodeDevice];
-
- [self matchValueOfDevices:triggerDevice devices:_triggerDevices];
- [self matchValueOfDevices:conditionDevice devices:_conditionDevices];
- }
-
- [self requestDeviceListForAction:ksItemTypeCodeAction];
- }
-
- }
-
- [_tableView reloadData];
-
- } failure:^(id errorObject) {
- JDErrorModel *error = (JDErrorModel *)errorObject;
- [[JDFacade facade] alert:error.errorMessage];
- }];
- }
- - (void)matchValueOfDevices:(ItemModel *)deviceItem devices:(NSMutableArray<ItemModel> *)devices {
-
- for (ItemSubModel *subItem in deviceItem.subItems) {
- NSArray *matchedArray = [devices matchedArrayInSubArrays:@"subItems" predicateFormat:@"sourceId == %@ && sourceSubId == %@", subItem.sourceId, subItem.sourceSubId];
- if (matchedArray.count) {
- ItemSubModel *matchedSubItem = matchedArray.firstObject;
- [[JDFacade facade] setRadioButtonStatus:@YES object:matchedSubItem];
-
- CmdClsValueModel *pCmdClsValue = [matchedSubItem.cmdclsValueList objectKey:@"cmdclsValue" eqaulToString:subItem.cmdclsValue];
- [[JDFacade facade] setRadioButtonStatus:@YES object:pCmdClsValue];
- }
- }
- }
- - (NSArray<ItemModel> *)makePushData{
-
- ItemModel *model = [ItemModel new];
- model.itemSubTypeCode = @"03";
- model.itemName = @"Notification message";
-
- NSMutableArray *pushes = [NSMutableArray new];
-
- ItemSubModel *subModel = [ItemSubModel new];
- subModel.conditionTypeCode = @"02";
- subModel.cmdclsValue = _txvMessage.text;
- subModel.actionTypeCode = @"00";
- [pushes addObject:subModel];
- [model.pushes arrayByAddingObjectsFromArray:pushes];
-
- NSArray *itemModels = @[model];
-
- return (NSArray<ItemModel> *)itemModels;
-
- //수정
- // if (addPush && _txvMessage.text.length > 0) {
- //
- // NSMutableArray *rSubItems = [[NSMutableArray alloc] init];
- // NSDictionary *rSubItem = @{@"condition_type_code": @"01",
- // @"cmdcls_value": @"푸시알림"};
- //
- // [rSubItems addObject:rSubItem];
- // [subItems addObjectsFromArray:rSubItems];
- // }
- }
- - (void)requestRegisterRule {
-
- NSArray *triggers = [self items:_triggers];
- NSArray *actions = [self items:_actions];
-
- //추가 푸시
- if (_txvMessage.text.length > 0) {
-
- NSMutableArray *mutableActions = [actions mutableCopy];
- [mutableActions addObjectsFromArray:[self items:[self makePushData]]];
- actions = [NSArray arrayWithArray:mutableActions];
- }
- NSArray *conditions = [self conditions:_conditions];
-
-
- //validate
- if (!triggers || !triggers.count) {
- [[JDFacade facade] alert:NSLocalizedString(@"규칙을 실행할 조건을 설정하세요.", @"규칙을 실행할 조건을 설정하세요.")];
- return;
- }
-
- if (!actions || !actions.count) {
- [[JDFacade facade] alert:NSLocalizedString(@"실행 조건에 맞춰 동작할 장치나 알림 메시지 중 최소 하나 이상을 설정하세요.", @"실행 조건에 맞춰 동작할 장치나 알림 메시지 중 최소 하나 이상을 설정하세요.")];
- return;
- }
-
- //parameters
- NSMutableDictionary *parameter = [NSMutableDictionary
- dictionaryWithDictionary:@{@"rule_name" : _txtRuleTitle.text,
- @"use_yn" : ksYES,
- @"triggers": triggers ? triggers : [NSNull null],
- @"actions": actions ? actions : [NSNull null]}];
- if (conditions) [parameter setObject:conditions forKey:@"conditions"];
-
-
- NSString *path = [[JDFacade facade] getUrlWithCustAndGroupID:API_POST_RULE_ADD aditional:@""];
-
- [[RequestHandler handler] sendAsyncPostRequestAPIPath:path
- parameters:parameter
- modelClass:[RuleModel class]
- completion:^(id responseObject) {
-
- if (!responseObject) return;
-
-
- RuleModel *newRule = (RuleModel *) responseObject;
-
- if (newRule) {//API 성공 ,
-
- ItemModel *item = _triggers.firstObject;
- if (item) {
- newRule.ruleName = _txtRuleTitle.text;
- newRule.triggerItemSubTypeCode = item.itemSubTypeCode;
- }
-
- RulesAddCompleteViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"RulesAddCompleteViewController" storyboardName:@"Rules"];
- vc.refRule = newRule;
- vc.providesPresentationContextTransitionStyle = YES;
- vc.definesPresentationContext = YES;
-
- [vc setModalPresentationStyle:UIModalPresentationOverCurrentContext];
-
- [self presentViewController:vc animated:YES completion:nil];
-
- }
- } failure:^(id errorObject) {
- JDErrorModel *error = (JDErrorModel *)errorObject;
- [[JDFacade facade] alert:error.errorMessage];
- }];
- }
- - (void)requestModifyRule {
-
- NSArray *triggers = [self items:_triggers];
- NSArray *actions = [self items:_actions];
- NSArray *conditions = [self conditions:_conditions];
-
- // BOOL hasConditionForRegister = [_conditions matchedArrayInSubArrays:@"subItems" predicateFormat:@"conditionTypeCode == %@", @"09"].count || _chkConditions.checked;
- // NSArray *conditions = hasConditionForRegister ? [self conditions:_conditions] : nil;
-
- //validate
- if (!triggers || !triggers.count) {
- [[JDFacade facade] alert:NSLocalizedString(@"실행할 때를 선택하세요", @"실행할 때를 선택하세요")];
- return;
- }
-
- if (!actions || !actions.count) {
- [[JDFacade facade] alert:NSLocalizedString(@"실행할 장치를 선택하세요", @"실행할 장치를 선택하세요")];
- return;
- }
-
- //parameters
- NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:@{@"rule_name" : _txtRuleTitle.text,
- @"use_yn" : ksYES,
- @"triggers": triggers ? triggers : [NSNull null],
- @"actions": actions ? actions : [NSNull null]}];
- if (conditions) {
- [parameter setObject:conditions forKey:@"conditions"];
- }
-
-
- NSArray *arr = @[_refRuleDetail.ruleId];
- NSString *path = [[JDFacade facade] getUrlWithCustAndGroupID:API_PUT_RULE_MODIFY arguments:arr];
-
- [[RequestHandler handler] sendAsyncPutRequestAPIPath:path parameters:parameter modelClass:[RuleModel class] completion:^(id responseObject) {
- if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
- return;
- }
-
- RuleModel *rule = (RuleModel *) responseObject;
-
- if (rule) {//API 성공
-
- RulesDetailViewController *vc = [[JDFacade facade] viewControllerOnPresentingViewController:self viewControllerClass:[RulesDetailViewController class]];
- if (vc) {
- [vc requestRuleDetail];
- } else {
- RulesViewController *rvc = [[JDFacade facade] viewControllerOnPresentingViewController:self viewControllerClass:[RulesViewController class]];
- [rvc prepareViewDidLoad];
- }
-
- [self dismissViewControllerAnimated:YES completion:^{
- [[JDFacade facade] toast:@"편집을 완료합니다"];
- }];
- }
-
- } failure:^(id errorObject) {
- JDErrorModel *error = (JDErrorModel *)errorObject;
- [[JDFacade facade] alert:error.errorMessage];
- }];
- }
- //아이템 배열을 리턴함.
- - (NSArray *)items:(NSArray<ItemModel> *)items{
-
- //triggers, actions, conditions
-
- NSMutableArray *rItems = [[NSMutableArray alloc] init];
-
- for (ItemModel *item in items) {
- NSDictionary *dic = nil;
- NSMutableArray *subItems = [[NSMutableArray alloc] init];
-
- NSArray *pdevices = [self subItemsForType:item.subItems itemSubType:ksItemSubTypeCodeDevice];
-
- NSArray *pushes = [self subItemsForType:item.pushes itemSubType:ksItemSubTypeCodeAppPush];
-
- NSArray *timers = [self subItemsForType:item.timers itemSubType:ksItemSubTypeCodeTimer];
- NSArray *daylights = [self subItemsForType:item.daylights itemSubType:ksItemSubTypeCodeDaylight];
-
- NSArray *heats = [self subItemsForType:item.heats itemSubType:ksItemSubTypeCodeHeat];
-
-
- if (pdevices && pdevices.count) {//device
- [subItems addObjectsFromArray:pdevices];
- }
-
- if (pushes && pushes.count) {//push
- [subItems addObjectsFromArray:pushes];
- }
-
- if (timers && timers.count) {//timer
- [subItems addObjectsFromArray:timers];
- }
-
- if (daylights && daylights.count) {//해뜰때/질때
- [subItems addObjectsFromArray:daylights];
- }
- if (heats && heats.count) {//더울떄 / 추울때
- [subItems addObjectsFromArray:heats];
- }
-
- if (subItems.count) {
- dic = @{@"item_name": item.itemName,
- @"item_sub_type_code": item.itemSubTypeCode,
- @"item_sub": subItems};
- [rItems addObject:dic];
-
- NSLog(@"dic : %@ %@", dic, item.itemName);
- }
- }
-
- return rItems;
- }
- //서브아이템 배열을 리턴함.
- - (NSArray *)subItemsForType:(NSArray *)subItems itemSubType:(NSString *)itemSubTypeCode {
-
- NSMutableArray *rSubItems = [NSMutableArray new];
-
- if ([itemSubTypeCode isEqualToString:ksItemSubTypeCodeDevice]) {//디바이스일 경우,
- NSArray<ItemSubModel> *pdevices = (NSArray<ItemSubModel> *)[subItems matchedArrayByObjectName:ksCustomRadioButtonStatus condition:YES];
-
-
- for (ItemSubModel *pdevice in pdevices) {
-
- NSDictionary *rSubItem = @{@"source_id": pdevice.sourceId,
- @"source_sub_id": pdevice.sourceSubId,
- @"cmdcls_value": pdevice.cmdclsValue,
- @"condition_type_code": pdevice.conditionTypeCode,
- @"data_type_code": pdevice.dataTypeCode};
-
-
- [rSubItems addObject:rSubItem];
- }
-
- }
- else if ([itemSubTypeCode isEqualToString:ksItemSubTypeCodeAppPush]) {//푸시일 경우,
- //at once.
-
- for (ItemSubModel *subItem in subItems) {
-
- NSDictionary *rSubItem = @{@"condition_type_code": subItem.conditionTypeCode,
- @"cmdcls_value": subItem.cmdclsValue,
- @"action_type_code": subItem.actionTypeCode};
-
- [rSubItems addObject:rSubItem];
- }
-
- }
- else if ([itemSubTypeCode isEqualToString:ksItemSubTypeCodeTimer]) {//타이머일 경우,
-
- for (ItemSubModel *subItem in subItems) {
-
- NSDictionary *rSubItem = @{@"hour": subItem.hour,
- @"minute": subItem.minute,
- @"dayofweek": subItem.dayofweek};
-
- [rSubItems addObject:rSubItem];
- }
- }
- else if ([itemSubTypeCode isEqualToString:ksItemSubTypeCodeDaylight]) {//해뜰때/질때 일 경우,
-
- for (ItemSubModel *subItem in subItems) {
-
- NSDictionary *rSubItem = @{@"source_id": subItem.sourceId,
- @"source_sub_id": subItem.sourceSubId,
- @"dayofweek": subItem.dayofweek};
-
- [rSubItems addObject:rSubItem];
- }
- }
- else if ([itemSubTypeCode isEqualToString:ksItemSubTypeCodeHeat]) {//온도
-
- for (ItemSubModel *subItem in subItems) {
-
- NSDictionary *rSubItem = @{@"source_id": subItem.sourceId,
- @"condition_type_code": subItem.conditionTypeCode,
- @"cmdcls_value": subItem.cmdclsValue,
- @"dayofweek": subItem.dayofweek};
-
- [rSubItems addObject:rSubItem];
- }
- }
- return rSubItems;
- }
- - (NSArray *)conditions:(NSArray<ItemModel> *)items {//trigger만 해당됨.
-
- //conditions
- NSMutableArray *rConditions = [[NSMutableArray alloc] init];
-
- for (ItemModel *condition in items) {//item = condition
-
- NSMutableArray *rSubItems = [[NSMutableArray alloc] init];
-
- if ([condition.itemSubTypeCode isEqualToString:ksConditionSubTypeCodeHomeMode]) {
-
- for (ItemSubModel *mode in condition.subItems) {
-
- NSDictionary *rSubItem = @{@"source_id": mode.sourceId,
- @"cmdcls_value": mode.cmdclsValue,
- @"condition_type_code": mode.conditionTypeCode};
-
- [rSubItems addObject:rSubItem];
- }
- }
- else if ([condition.itemSubTypeCode isEqualToString:ksConditionSubTypeCodeDueDate]) {
-
- for (ItemSubModel *subItem in condition.subItems) {
-
- NSDictionary *rSubItem = @{@"condition_type_code": subItem.conditionTypeCode,
- @"cmdcls_value": subItem.cmdclsValue};
-
- [rSubItems addObject:rSubItem];
- }
- }
- else if ([condition.itemSubTypeCode isEqualToString:ksItemSubTypeCodeDevice]) {
-
- for (ItemSubModel *pdevice in condition.subItems) {
-
- NSDictionary *rSubItem = @{@"source_id": pdevice.sourceId,
- @"source_sub_id": pdevice.sourceSubId,
- @"cmdcls_value": pdevice.cmdclsValue,
- @"data_type_code": pdevice.dataTypeCode,
- @"condition_type_code": pdevice.conditionTypeCode};
-
- [rSubItems addObject:rSubItem];
- }
- }
- else if ([condition.itemSubTypeCode isEqualToString:ksConditionSubTypeCodeDaysOfWeek]) {
-
- for (ItemSubModel *subItem in condition.subItems) {
-
- NSDictionary *rSubItem = @{@"cmdcls_value": subItem.cmdclsValue,
- @"condition_type_code": subItem.conditionTypeCode};
-
- [rSubItems addObject:rSubItem];
- }
- }
-
- if (rSubItems.count) {
- NSDictionary *dic = @{@"item_name": condition.itemName,
- @"item_sub_type_code": condition.itemSubTypeCode,
- @"item_sub": rSubItems};
- [rConditions addObject:dic];
-
- NSLog(@"dic : %@ %@", dic, condition.itemName);
- }
- }
-
- return rConditions;
- }
- - (void)cloneSubItemsForItemSubType:(NSArray<ItemModel> *)items {
-
- for (ItemModel *item in items) {
- if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeDevice]) {//디바이스일 경우,
- //기존 아이템을 그대로 사용함.
- for (ItemSubModel *subItem in item.subItems) {
- [[JDFacade facade] setRadioButtonStatus:@YES object:subItem];
- [[JDFacade facade] setCheckBoxStatus:@YES object:subItem];
- }
- } else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeAppPush]) {//푸시일 경우,
- item.pushes = (NSMutableArray<ItemSubModel> *)[[NSMutableArray alloc] initWithArray:item.subItems copyItems:YES];
- item.subItems = nil;
-
- } else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeTimer]) {//타이머일 경우,
- item.timers = (NSMutableArray<ItemSubModel> *)[[NSMutableArray alloc] initWithArray:item.subItems copyItems:YES];
- item.subItems = nil;
- } else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeDaylight]) {//해뜰때/질때 경우,
- item.daylights = (NSMutableArray<ItemSubModel> *)[[NSMutableArray alloc] initWithArray:item.subItems copyItems:YES];
- item.subItems = nil;
- } else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeHeat]) {//더울때/추울때 경우,
- item.heats = (NSMutableArray<ItemSubModel> *)[[NSMutableArray alloc] initWithArray:item.subItems copyItems:YES];
- item.subItems = nil;
- } else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeMode]) {//더울때/추울때 경우,
- //기존 아이템을 그대로 사용함.
- }
- }
- }
- - (void)setRefRuleDetail:(RuleDetailModel *)refRuleDetail {
-
-
- _refRuleDetail = refRuleDetail;
-
- _triggers = (NSMutableArray<ItemModel> *)[[NSMutableArray alloc] initWithArray:_refRuleDetail.triggers copyItems:YES];
- _actions = (NSMutableArray<ItemModel> *)[[NSMutableArray alloc] initWithArray:_refRuleDetail.actions copyItems:YES];
- _conditions = (NSMutableArray<ItemModel> *)[[NSMutableArray alloc] initWithArray:_refRuleDetail.conditions copyItems:YES];
-
- [self cloneSubItemsForItemSubType:_triggers];
- [self cloneSubItemsForItemSubType:_actions];
- [self cloneSubItemsForItemSubType:_conditions];
-
- _hasCondition = [_conditions objectKey:@"itemSubTypeCode" eqaulToString:ksConditionSubTypeCodeHomeMode];
- _hasCondition = [_conditions objectKey:@"itemSubTypeCode" eqaulToString:ksConditionSubTypeCodeDueDate] ? YES : _hasCondition;
- _hasCondition = [_conditions objectKey:@"itemSubTypeCode" eqaulToString:ksItemSubTypeCodeDevice] ? YES : _hasCondition;
- }
- #pragma mark - UITableView DataSource & Delegate
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 5;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
-
- NSInteger count = 0;
- if (section == 0) {//title
- count = 1;
-
- } else if (section == 1) {//triggers
- count = _triggers && _triggers.count ? _triggers.count : 0;
-
- } else if (section == 2) {//actions
- ItemModel *deviceItem = [_actions objectKey:@"itemSubTypeCode" eqaulToString:ksItemSubTypeCodeDevice];
- count = deviceItem.subItems && deviceItem.subItems.count ? deviceItem.subItems.count : 0;
-
- } else if (section == 3) {//push-message
- count = 1;
-
- } else if (section == 4) {//conditions
- count = 1;//_chkConditions.checked || _hasCondition ? 1 : 0;
- }
-
- return count;
- }
- - (NSString *)headerTitleForSection:(NSInteger)section {
- NSString *title = nil;
-
- if (section == 1) {//trigger
- title = @"실행 조건";
- if (_triggers && _triggers.count) {
- ItemModel *item = _triggers[0];
-
- if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeDevice]) {
- title = @"장치 상태가 바뀔 때";
- } else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeTimer]) {
- title = @"이 시간마다";
- } else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeHeat]) {
- title = @"더울때 / 추울때";
- } else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeDaylight]) {
- title = @"해뜰때 / 질때";
- }
- }
-
- } else if (section == 2) {//action
- title = @"동작할 장치";
- // title = _actions && _actions.count ? @"선택됨" : title;
- }
-
- // else if (section == 3) {//conditions
- // title = @"추가 조건";
- // title = _triggers && triggers.count ? @"선택됨" : title;
- // }
- return title;
- }
- - (void)addTargetToHeaderAddButton:(CustomButton *)btnAdd section:(NSInteger)section {
- if (section == 1) {
- _btnTriggerAdd = btnAdd;
- [btnAdd addTarget:self action:@selector(btnAddTriggerTouched:) forControlEvents:UIControlEventTouchUpInside];
-
- } else if (section == 2) {
- [btnAdd addTarget:self action:@selector(btnAddActionTouched:) forControlEvents:UIControlEventTouchUpInside];
-
- }
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
-
- UIView *view = _arrayForHeader.count > section ? _arrayForHeader[section] : nil;
-
- if (!view) {
-
- if (section == 0 || section == 3) {//title
- view = [[UIView alloc] init];
- }
- else if (section == 1 || section == 2) {//hide add button or not;
- RulesAddHeaderTableViewCell *hcell = (RulesAddHeaderTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"HeaderCellIdentifier"];
- hcell.width = IPHONE_WIDTH;
-
- view = [[UIView alloc] initWithFrame:hcell.contentView.frame];
- [view addSubview:hcell];
- hcell.lblTitle.text = [self headerTitleForSection:section];
- if (![hcell.btnAdd actionsForTarget:self forControlEvent:UIControlEventTouchUpInside]) {
- [self addTargetToHeaderAddButton:hcell.btnAdd section:section];
- }
-
- }
- else if (section == 4) {//conditions
- RulesAddConditionHeaderTableViewCell *hcell = (RulesAddConditionHeaderTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"ConditionHeaderCellIdentifier"];
- hcell.width = IPHONE_WIDTH;
-
- view = [[UIView alloc] initWithFrame:hcell.contentView.frame];
- [view addSubview:hcell];
-
- _chkConditions = hcell.chkConditions;
-
- if (!_isNotFirstLoading) {
- _chkConditions.checked = _hasCondition;
- _isNotFirstLoading = YES;
- }
-
- if (![_chkConditions actionsForTarget:self forControlEvent:UIControlEventTouchUpInside]) {
- [_chkConditions addTarget:self action:@selector(chkConditionsTouched:) forControlEvents:UIControlEventTouchUpInside];
- }
-
- if (![hcell.btnConditions actionsForTarget:self forControlEvent:UIControlEventTouchUpInside]) {
- [hcell.btnConditions addTarget:self action:@selector(btnConditionsTouched:) forControlEvents:UIControlEventTouchUpInside];
- }
- }
-
- if (_arrayForHeader.count == section) {
- [_arrayForHeader insertObject:view atIndex:section];
- }
-
- } else {
-
- if (section == 1 || section == 2) {
- RulesAddHeaderTableViewCell *hcell = (RulesAddHeaderTableViewCell *)view.subviews[0];
- hcell.lblTitle.text = hcell.lblTitle.text = [self headerTitleForSection:section];
- }
- else if (section == 4) {
- // RulesAddConditionHeaderTableViewCell *hcell = (RulesAddConditionHeaderTableViewCell *)view.subviews[0];
- }
- }
-
- [self checkHeaderButton:section];
-
- return view;
- }
- - (void)checkHeaderButton:(NSInteger)section {
-
- if (section == 1) {
- _btnTriggerAdd.hidden = self.triggers.count > 0;
- }
- }
- #pragma mark - conditions
- //rule controll vc section 4 활성화 비활성화
- - (void)chkConditionsTouched:(id)sender {
- [_tableView reloadData];
-
- CustomCheckBox *chkCondition = (CustomCheckBox *)sender;
-
- if (chkCondition.checked) {
- NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:4];
- [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
- }
- }
- - (void)btnConditionsTouched:(id)sender {
-
- ConditionSelectPopupView *popup = [[ConditionSelectPopupView alloc] initFromNib];
- [popup showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
- switch (buttonIndex) {
- case 10:
- [_rcv btnAddModeTouched:nil];
- break;
- case 11:
- [_rcv btnAddDurationTouched:nil];
- break;
- case 12:
- [_rcv btnAddDeviceTouched:nil];
- break;
- }
-
- }];
-
- };
- //- (void)btnAddModeTouched:(id)sender {
- //
- // ItemModel *mode = (ItemModel *)[_conditions objectKey:@"itemSubTypeCode" eqaulToString:ksConditionSubTypeCodeHomeMode];
- // BOOL isNewTrigger = mode == nil;
- // mode = isNewTrigger ? [[ItemModel alloc] init] : mode;
- //
- // if (!_mpopup) {
- // _mpopup = [[RulesConditionHomeModePopupView alloc] initFromNib];
- // }
- //
- // _mpopup.condition = mode;
- // [_mpopup showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
- // if (buttonIndex == 0) {//OK
- // if (isNewTrigger) {
- // [_conditions addObject:mode];
- // }
- //
- // [self.tableView reloadData];
- // }
- // }];
- //}
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
-
- if (section == 0 || section == 3) {
- return 0.01f;
- }
- else if (section == 4) {
- return 56.0f;
- }
-
- return 56.0f;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
-
- UIView *view = _arrayForFooter.count > section ? _arrayForFooter[section] : nil;
- if (!view) {
-
- RulesAddFooterTableViewCell *hcell = (RulesAddFooterTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"FooterCellIdentifier"];
- hcell.width = IPHONE_WIDTH;
-
- view = [[UIView alloc] initWithFrame:hcell.contentView.frame];
- [view addSubview:hcell];
-
- if (_arrayForHeader.count == section) {
- [_arrayForHeader insertObject:view atIndex:section];
- }
- }
-
- return view;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
- // if (section == 0) {
- // return 0.01f;
- // }
- return 0.01f;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- CGFloat height = 0.0f;
- NSInteger section = indexPath.section;
-
- if (section == 0) {//title
- height = 122;
-
- } else if (section == 1) {//triggers
- height = 80;
-
- } else if (section == 2) {//actions
- height = 80;
-
- } else if (section == 3) {//push-message
- // height = UITableViewAutomaticDimension;
- height = 122 + textCellChangeHeight;
-
- } else if (section == 4) {//conditions
- if (!_rcv) {
- _rcv = [CommonUtil instantiateViewControllerWithIdentifier:@"RulesConditionViewController" storyboardName:@"Rules"];
-
- [self addChildViewController:_rcv];
- [_rcv didMoveToParentViewController:self];
- }
-
- height = _rcv.tableHeight;
- }
-
- return height;
- }
- + (BOOL)hasDeleteNode:(ItemModel *)deviceItem {
- NSArray *matchedArray = [deviceItem.subItems filteredArrayUsingPredicateFormat:@"deleteYn == %@", ksYES];
- return matchedArray.count;
- }
- - (void)configureTriggerCell:(RulesAddTableViewCell *)cell item:(ItemModel *)item {
-
- ItemSubModel *subItem = nil;
- NSString *deviceImageFileName = nil;
-
- NSLog(@"configureTriggerCell");
- if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeDevice]) {//장치일 경우
- subItem = [item.subItems matchedObjectName:ksCustomRadioButtonStatus condition:YES];
-
- cell.lblItem.text = subItem.sourceName;
- deviceImageFileName = subItem.imageFileName;
- if ([subItem.deleteYn boolValue]) {
- [cell.lblItem setStrikethrough:cell.lblItem.text];
- }
-
- cell.lblSubItem.text = subItem.sourceSubName;
-
- //노드의 액션 값을 세팅함.
- if (subItem.cmdclsValueList && subItem.cmdclsValueList.count) {//커맨드클래스 밸루 리스트가 있을 경우,
-
- CmdClsValueModel *cmdclsValue = [subItem.cmdclsValueList matchedObjectName:ksCustomRadioButtonStatus condition:YES];
-
- cell.lblCondition.text = [DeviceModel contentValueMsgByCmdClsCode:subItem.cmdclsCode cmdclsTypeId:(NSString *)subItem.cmdclsTypeId contentValue:cmdclsValue.cmdclsValue];
- }
- else {
-
- if (subItem.cmdclsValueMsg) {
- cell.lblCondition.text = subItem.cmdclsValueMsg;
- } else {
- NSString *condition = [subItem.conditionTypeCode isEqualToString:ksConditionTypeCodeGreatOrEqual] ? @"이상" : @"이하";
- cell.lblCondition.text = [NSString stringWithFormat:@"%@%@ %@", subItem.cmdclsValue, subItem.unit, condition];
- }
- }
-
- //[cell.lblCondition setUnderLine:cell.lblCondition.text];
- cell.lblCondition.hidden = NO;
-
- } else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeTimer]) {
-
- subItem = item.timers && item.timers.count ? item.timers[0] : nil;
- if (subItem) {
-
- NSInteger phour = [subItem.hour integerValue];
- NSString *period = phour < 12 ? @"오전" : @"오후";
- NSString *title = [NSString stringWithFormat:@"%@ %zd:%@", period, phour, subItem.minute];
-
- // NSDictionary *titleColor = @{NSForegroundColorAttributeName : kUITextColor02};
- cell.lblItem.text = title;
- cell.lblSubItem.text = subItem.dayofweek;//[self daysOfWeekAtSubItem];
-
- cell.lblCondition.hidden = YES;
- }
- } else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeDaylight]) {
-
- subItem = item.daylights && item.daylights.count ? item.daylights[0] : nil;
- if (subItem) {
- NSString *title = [subItem.sourceSubId isEqualToString:@"sunriseUtcTime"] ? @"해뜰때" : @"해질때";
- cell.lblItem.text = title;
- cell.lblSubItem.text = [NSString stringWithFormat:@"%@ / %@", subItem.sourceName, subItem.dayofweek];//[self daysOfWeekAtSubItem]];
-
- cell.lblCondition.hidden = YES;
- }
- } else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeHeat]) {
-
- subItem = item.heats && item.heats.count ? item.heats[0] : nil;
- if (subItem) {
- NSString *title = [subItem.conditionTypeCode isEqualToString:ksConditionTypeCodeGreatOrEqual] ? @"더울때" : @"추울때";
-
- cell.lblItem.text = title;
- cell.lblSubItem.text = [NSString stringWithFormat:@"%@ / %@℃ / %@", subItem.sourceName, subItem.cmdclsValue, subItem.dayofweek];//[self daysOfWeekAtSubItem]];
-
- cell.lblCondition.hidden = YES;
- }
- }
-
- // if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeDevice]) {
- // if (item.imageFileName) {
- // [cell.imgvIcon sd_setImageWithURL:[NSURL URLWithString:item.imageFileName] placeholderImage:nil options:SDWebImageRefreshCached];
- // } else {
- // [cell.imgvIcon sd_setImageWithURL:[NSURL URLWithString:deviceImageFileName] placeholderImage:nil options:SDWebImageRefreshCached];
- // }
- // } else {
- cell.imgvIcon.image = [self imageForTrigger:item];
- // }
- }
- - (NSString *)daysOfWeekAtSubItem {
-
- NSString *daysOfWeek = ksEmptyString;
- ItemModel *daysCondition = [_conditions objectKey:@"itemSubTypeCode" eqaulToString:ksConditionSubTypeCodeDaysOfWeek];
- if (daysCondition) {
- ItemSubModel *subCondition = daysCondition.subItems[0];
- daysOfWeek = subCondition.dayofweek;
- }
- return daysOfWeek;
- }
- - (UIImage *)imageForTrigger:(ItemModel *)item {
- UIImage *image = nil;
-
- if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeTimer]) {//타이머일 경우,
- image = [UIImage imageNamed:@"img_rule_icon_time"];
-
- }
- else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeDaylight]) {//해뜰때/질때 경우,
- image = [UIImage imageNamed:@"img_rule_icon_sunrises"];
-
- }
- else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeHeat]) {//더울때/추울때 경우,
- image = [UIImage imageNamed:@"img_rule_icon_Temperature"];
- }
- else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeDevice]) {
-
- ItemSubModel *subItem = [item.subItems matchedObjectName:ksCustomRadioButtonStatus condition:YES];
- image = [UIImage imageNamed:[[JDFacade facade] deviceIconFromSourceSubId:subItem.sourceSubId]];
-
- }
- return image;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- NSInteger section = indexPath.section;
-
- UITableViewCell *cell = nil;
-
- if (section == 0) {//title
- RulesAddTitleTableViewCell *tcell = (RulesAddTitleTableViewCell *)[_tableView dequeueReusableCellWithIdentifier:@"TitleCellIdentifier"];
-
- tcell.txtRuleTitle.text = [tcell.txtRuleTitle.text isEmptyString] && _refRuleDetail ? _refRuleDetail.ruleName : tcell.txtRuleTitle.text;
- if (!_txtRuleTitle) {
- _txtRuleTitle = tcell.txtRuleTitle;
- }
-
- [self insertActionAddButton:tcell.btnAdd];
-
- cell = tcell;
-
- } else if (section == 1) {//triggers
-
- ItemModel *item = _triggers[indexPath.row];
-
- RulesAddTableViewCell *tcell = (RulesAddTableViewCell *)[_tableView dequeueReusableCellWithIdentifier:@"RulesCellIdentifier"];
- [self configureTriggerCell:tcell item:item];
-
- tcell.lblItem.textColor = kUITextColor04;
-
- tcell.btnDelete.value = item;
-
- [tcell.btnDelete removeTarget:nil action:NULL forControlEvents:UIControlEventAllEvents];
- [tcell.btnDelete addTarget:self action:@selector(btnDeleteTriggerTouched:) forControlEvents:UIControlEventTouchUpInside];
-
- cell = tcell;
- } else if (section == 2) {//actions
-
- ItemModel *deviceItem = [_actions objectKey:@"itemSubTypeCode" eqaulToString:ksItemSubTypeCodeDevice];
- ItemSubModel *subItem = deviceItem.subItems[indexPath.row];
-
- RulesAddTableViewCell *tcell = (RulesAddTableViewCell *)[_tableView dequeueReusableCellWithIdentifier:@"RulesCellIdentifier"];
-
- //title
- BOOL multiHub = [JDFacade facade].loginUser.isMultiHomeHub;
- NSArray *ids = [subItem.sourceId componentsSeparatedByString:@"-"];
- DeviceModel *hub = nil;
-
- if (ids.count > 1) hub = [[JDFacade facade].loginUser getHomeHub:[ids objectAtIndex:0]];
-
- NSString *name = hub == nil ? @"전체" : (hub.prdUserName != nil ? hub.prdUserName : hub.prdName);
- NSString *hubName = multiHub ? [self convMaxLengthName:name len:4] : @"";
- NSString *deviceName = [self convMaxLengthName:subItem.sourceName len:6];
-
- tcell.lblItem.text = multiHub ? [NSString stringWithFormat:@"[%@]%@", hubName,deviceName] : deviceName ;
-
- if ([subItem.deleteYn boolValue]) {
- [tcell.lblItem setStrikethrough:tcell.lblItem.text];
- }
- tcell.lblSubItem.text = subItem.sourceSubName;
- // tcell.lblItem.textColor = kUITextColor01;
- tcell.imgvIcon.image = [UIImage imageNamed:[[JDFacade facade] deviceIconFromSourceSubId:subItem.sourceSubId]];
- // [tcell.imgvIcon sd_setImageWithURL:[NSURL URLWithString:subItem.imageFileName] placeholderImage:nil options:SDWebImageRefreshCached];
- //노드의 액션 값을 세팅함.
- if (subItem.cmdclsValueList && subItem.cmdclsValueList.count) {//커맨드클래스 밸루 리스트가 있을 경우,
- CmdClsValueModel *cmdclsValue = [subItem.cmdclsValueList matchedObjectName:ksCustomRadioButtonStatus condition:YES];
-
- tcell.lblCondition.text = cmdclsValue.cmdclsValueMsg;
- }
- else {
-
- if (subItem.cmdclsValueMsg) {
-
- tcell.lblCondition.text = subItem.cmdclsValueMsg;
- }
- else {
-
- NSString *condition = [subItem.conditionTypeCode isEqualToString:ksConditionTypeCodeGreatOrEqual] ? @"이상" : @"이하";
- tcell.lblCondition.text = [NSString stringWithFormat:@"%@%@ %@", subItem.cmdclsValue, subItem.unit, condition];
- }
- }
-
- tcell.btnDelete.value = subItem;
-
- [tcell.btnDelete removeTarget:nil action:NULL forControlEvents:UIControlEventAllEvents];
- [tcell.btnDelete addTarget:self action:@selector(btnDeleteDeviceActionTouched:) forControlEvents:UIControlEventTouchUpInside];
-
- cell = tcell;
-
- } else if (section == 3) {//push-message
-
- ItemModel *pushItem = [_actions objectKey:@"itemSubTypeCode" eqaulToString:ksItemSubTypeCodeAppPush];
- ItemSubModel *subItem = pushItem.pushes[indexPath.row];
-
- RulesAddTextTableViewCell *tcell = (RulesAddTextTableViewCell *)[_tableView dequeueReusableCellWithIdentifier:@"TextCellIdentifier"];
-
- //높이변경
- [tcell registTvStatusChangeBlock:^(NSInteger tag, CGFloat height) {
-
- if (tag == 0) {
- [tableView scrollToRowAtIndexPath:indexPath
- atScrollPosition:UITableViewScrollPositionTop
- animated:NO];
- }
- else {
-
- textCellChangeHeight += height;
- [self tableView:_tableView reloadRowWhileShowingKeyboard:indexPath];
- }
- }];
-
- if (!_txvMessage) {
- _txvMessage = tcell.txtView;
- }
- _txvMessage.text = [_txvMessage.text isEqualToString:_txvMessage.placeHolder] && _refRuleDetail ? subItem.cmdclsValue : _txvMessage.text;
- [self insertActionAddButton:tcell.btnAdd];
-
- cell = tcell;
- } else if (section == 4) {//conditions
-
- RulesAddConditionTableViewCell *tcell = (RulesAddConditionTableViewCell *)[_tableView dequeueReusableCellWithIdentifier:@"ConditionCellIdentifier"];
-
- // if (_chkConditions.checked) {
- if (!tcell.container.subviews.count) {
- if ([self isViewLoaded]) {
- [_rcv beginAppearanceTransition:YES animated:NO];
- [tcell.container addSubview:_rcv.view];
- [_rcv endAppearanceTransition];
- }
- }
-
- // NSLog(@"section == 4");
- // NSLog(@"_conditionDevices : %@", _conditionDevices);
-
- _rcv.conditions = _conditions;
- _rcv.refDevices = _conditionDevices;
-
- tcell.constraintContainerHeight.constant = _rcv.tableHeight;
- // }
-
- cell = tcell;
- }
-
- return cell;
- }
- //키보드 유지 셀 높이 변경
- - (void)tableView:(UITableView *)tableView reloadRowWhileShowingKeyboard:(NSIndexPath *)indexPath {
-
- [tableView beginUpdates];
- [tableView endUpdates];
-
- [tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
-
- if (indexPath.section == 1) {//triggers
- ItemModel *item = _triggers[0];
-
- if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeDevice]) {//디바이스일 경우,
- ItemSubModel *subItem = item.subItems[indexPath.row];
- [RulesAddViewController modifyTrigger:item subItem:subItem refDevices:_triggerDevices tableView:_tableView];
-
- } else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeTimer]) {//타이머일 경우,
- [self modifyTriggerOfTimer:item];
-
- } else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeDaylight]) {//해뜰때/질때 경우,
- [self modifyTriggerOfDaylight:item];
-
- } else if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeHeat]) {//더울때/추울때 경우,
- [self modifyTriggerOfHeat:item];
- }
-
- } else if (indexPath.section == 2) {//actions
- ItemModel *deviceItem = [_actions objectKey:@"itemSubTypeCode" eqaulToString:ksItemSubTypeCodeDevice];
- if (deviceItem) {
- ItemSubModel *subItem = deviceItem.subItems[indexPath.row];
- [RulesAddViewController modifyAction:subItem refDevices:_actionDevices tableView:_tableView];
- }
- }
- }
- #pragma mark
- - (void)modifyTriggerOfTimer:(ItemModel *)item {
-
- TimePickerPopupView *tpopup = [[TimePickerPopupView alloc] initFromNib];
- tpopup.timeTrigger = item;
- tpopup.refConditions = _conditions;
-
- [tpopup showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
- if (buttonIndex == 0) {//OK
- [_tableView reloadData];
- }
- }];
- }
- - (void)modifyTriggerOfDaylight:(ItemModel *)item {
-
- DaylightPopupView *dpopup = [[DaylightPopupView alloc] initFromNib];
- dpopup.daylightTrigger = item;
- dpopup.refConditions = _conditions;
-
- [dpopup showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
- if (buttonIndex == 0) {//OK
- [_tableView reloadData];
- }
- }];
- }
- - (void)modifyTriggerOfHeat:(ItemModel *)item {
-
- ExternHeatPopupView *epopup = [[ExternHeatPopupView alloc] initFromNib];
- epopup.externHeatTrigger = item;
- epopup.refConditions = _conditions;
-
- [epopup showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
- if (buttonIndex == 0) {//OK
- [_tableView reloadData];
- }
- }];
- }
- + (void)modifyTrigger:(ItemModel *)trigger subItem:(ItemSubModel *)subItem refDevices:(NSMutableArray<ItemModel> *)refDevices tableView:(CustomTableView *)tableView {
-
- if ([subItem.deleteYn boolValue]) {
- [[JDFacade facade] toast:@"삭제된 장치입니다\r목록에서 제거하세요"];
- return;
- }
-
- ItemModel *deviceItem = [refDevices objectKey:@"sourceId" eqaulToString:subItem.sourceId];
-
- NSLog(@"deviceItem : %@", deviceItem);
-
- //노드 선택 팝럽.
- DeviceNodePopupView *npopup = [[DeviceNodePopupView alloc] initFromNib];
- npopup.refDevice = deviceItem;
- npopup.typeCode = ksItemTypeCodeTrigger;
- npopup.isModifyMode = YES;
-
- [npopup showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
- if (buttonIndex == 0) {//OK
-
- ItemSubModel *fsubItem = [deviceItem.subItems matchedObjectName:ksCustomRadioButtonStatus condition:YES];
-
- if (fsubItem != nil) {
-
- [trigger.subItems removeAllObjects];
- [trigger.subItems addObject:fsubItem];
-
- }
-
-
- // subItem.cmdclsCode = matchedSubItem.cmdclsCode;
- // subItem.cmdclsTypeId = matchedSubItem.cmdclsTypeId;
- //
- // if (matchedSubItem.cmdclsValueList) {
- // subItem.cmdclsValueList = matchedSubItem.cmdclsValueList;
- //
- // CmdClsValueModel *pCmdClsValue = [subItem.cmdclsValueList matchedObjectName:ksCustomRadioButtonStatus condition:YES];
- // subItem.cmdclsValue = pCmdClsValue.cmdclsValue; //CommandClassControlNodeView - 에서 선택됨.
- // }
-
- if (tableView) {
- [tableView reloadData];
- }
- }
- }];
- }
- + (void)modifyAction:(ItemSubModel *)subItem refDevices:(NSMutableArray<ItemModel> *)refDevices tableView:(CustomTableView *)tableView {
-
- if ([subItem.deleteYn boolValue]) {
- [[JDFacade facade] toast:@"삭제된 장치입니다\r목록에서 제거하세요"];
- return;
- }
-
- ItemModel *item = [refDevices objectKey:@"sourceId" eqaulToString:subItem.sourceId];
- ItemSubModel *matchedSubItem = [item.subItems objectKey:@"sourceSubId" eqaulToString:subItem.sourceSubId];
-
- //노드 선택 팝럽.
- DeviceNodePopupView *npopup = [[DeviceNodePopupView alloc] initFromNib];
- npopup.refDevice = item;
- npopup.typeCode = ksItemTypeCodeTrigger;
- npopup.isModifyMode = YES;
-
- [npopup showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
-
- if (buttonIndex == 0) {//OK
-
- subItem.cmdclsCode = matchedSubItem.cmdclsCode;
- subItem.cmdclsTypeId = matchedSubItem.cmdclsTypeId;
- subItem.cmdclsValueList = matchedSubItem.cmdclsValueList;
- CmdClsValueModel *pCmdClsValue = [subItem.cmdclsValueList matchedObjectName:ksCustomRadioButtonStatus condition:YES];
- subItem.cmdclsValue = pCmdClsValue.cmdclsValue; //CommandClassControlNodeView - 에서 선택됨.
-
- if (tableView) {
-
- [tableView reloadData];
- }
- }
- }];
-
-
- // NSString *cmdclsCode = matchedSubItem != nil ? matchedSubItem.cmdclsCode : nil;
- //
- // ActionDeviceCommandPopupView *popup = [[ActionDeviceCommandPopupView alloc] initFromNib];
- // popup.typeCode = ksItemTypeCodeTrigger;
- // popup.cmdclsCode = cmdclsCode;
- // popup.refDevice = item;
- // [popup showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
- //
- //
- // if (buttonIndex == 0) {//OK
- //
- // subItem.cmdclsCode = matchedSubItem.cmdclsCode;
- // subItem.cmdclsTypeId = matchedSubItem.cmdclsTypeId;
- // subItem.cmdclsValueList = matchedSubItem.cmdclsValueList;
- // CmdClsValueModel *pCmdClsValue = [subItem.cmdclsValueList matchedObjectName:ksCustomRadioButtonStatus condition:YES];
- // subItem.cmdclsValue = pCmdClsValue.cmdclsValue; //CommandClassControlNodeView - 에서 선택됨.
- //
- // if (tableView) {
- //
- // [tableView reloadData];
- // }
- // }
- // }];
- }
- #pragma mark - TableView UI Events
- - (void)btnAddTriggerTouched:(id)sender {
-
- TriggerSelectPopupView *tpopup = [[TriggerSelectPopupView alloc] initFromNib];
- tpopup.refTriggers = _triggers;
- tpopup.refDevices = _triggerDevices;
- tpopup.refConditions = _conditions;
-
-
- [tpopup showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
- if (buttonIndex == 0) {
- // NSLog(@"_triggers : %@", _triggers);
- [_tableView reloadData];
- }
- }];
- }
- //동작할 장치 추가
- - (void)btnAddActionTouched:(id)sender {
-
- DeviceSelectPopupView *dpopup = [[DeviceSelectPopupView alloc] initFromNib];
- dpopup.refDevices = _actionDevices;
- dpopup.typeCode = ksItemTypeCodeTrigger;
- [dpopup showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
-
- if (buttonIndex == 0) {//ok
-
- // ItemModel *device = dpopup.selectedDevices[0];
- //
- // NSLog(@"device : %@", device);
- //
- // ItemSubModel *subModel = device.subItems.count > 0 ? [device.subItems objectAtIndex:0] : nil ;
- // NSString *cmdclsCode = subModel != nil ? subModel.cmdclsCode : nil;
- //
- //
- // if ( !(EQUALS(cmdclsCode, ksCmdClassTypeSwitchBinary) ||
- // EQUALS(cmdclsCode, ksCmdClassTypeValve)) ) {
- //
- // return ;
- // }
- //
- // ActionDeviceCommandPopupView *popup = [[ActionDeviceCommandPopupView alloc] initFromNib];
- // popup.typeCode = ksItemTypeCodeTrigger;
- // popup.cmdclsCode = cmdclsCode;
- // popup.refDevice = device;
- // [popup showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
- //
- //
- // if (buttonIndex == 0) {//OK
- //
- // ItemModel *deviceItem = [_actions objectKey:@"itemSubTypeCode" eqaulToString:ksItemSubTypeCodeDevice];
- // if (!deviceItem) {//디바이스 아이템이 없을 경우,
- // deviceItem = [[ItemModel alloc] init];
- // deviceItem.itemName = @"이 장치를 실행";
- // deviceItem.itemSubTypeCode = ksItemSubTypeCodeDevice;
- //
- // deviceItem.subItems = [(NSMutableArray<ItemSubModel> *)[NSMutableArray alloc] init];
- //
- // [_actions addObject:deviceItem];
- // }
- //
- //
- // ItemSubModel *snode = popup.selectedNode;
- // //존재 여부 확인
- // if (![deviceItem.subItems objectByUsingPredicateFormat:@"sourceId == %@ && sourceSubId == %@", snode.sourceId, snode.sourceSubId]) {
- // [deviceItem.subItems addObject: snode];
- // }
- //
- // [_tableView reloadData];
- // }
- // }];
-
- DeviceNodePopupView *npopup = [[DeviceNodePopupView alloc] initFromNib];
- npopup.refDevice = dpopup.selectedDevices[0];
- npopup.typeCode = ksItemTypeCodeTrigger;
-
- [npopup showWithCompletion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
- //action add
- if (buttonIndex == 0) {//OK
-
- ItemModel *deviceItem = [_actions objectKey:@"itemSubTypeCode" eqaulToString:ksItemSubTypeCodeDevice];
- if (!deviceItem) {//디바이스 아이템이 없을 경우,
- deviceItem = [[ItemModel alloc] init];
- deviceItem.itemName = @"이 장치를 실행";
- deviceItem.itemSubTypeCode = ksItemSubTypeCodeDevice;
-
- deviceItem.subItems = [(NSMutableArray<ItemSubModel> *)[NSMutableArray alloc] init];
-
- [_actions addObject:deviceItem];
- }
-
-
- ItemSubModel *snode = npopup.selectedNode;
- //존재 여부 확인
- if (![deviceItem.subItems objectByUsingPredicateFormat:@"sourceId == %@ && sourceSubId == %@", snode.sourceId, snode.sourceSubId]) {
- [deviceItem.subItems addObject: snode];
- }
-
- [_tableView reloadData];
- }
- }];
- }
- }];
- }
- - (void)btnAddPushMessageTouched:(id)sender {
-
- ItemModel *pushItem = [_actions objectKey:@"itemSubTypeCode" eqaulToString:ksItemSubTypeCodeAppPush];
-
- if (!pushItem) {//디바이스 아이템이 없을 경우,
-
- pushItem = [[ItemModel alloc] init];
- pushItem.itemName = [JDFacade facade].loginUser.memberId;
- pushItem.itemSubTypeCode = ksItemSubTypeCodeAppPush;
-
- pushItem.pushes = [(NSMutableArray<ItemSubModel> *)[NSMutableArray alloc] init];
-
- ItemSubModel *push = [[ItemSubModel alloc] init];
- push.conditionTypeCode = @"02";
-
- [pushItem.pushes addObject:push];
- [_actions addObject:pushItem];
- }
-
- [_tableView reloadData];
- }
- - (void)btnDeleteTriggerTouched:(id)sender {
-
- NSLog(@"btnDeleteTriggerTouched");
-
- CustomButton *btnDelete = (CustomButton *)sender;
-
- ItemModel *item = btnDelete.value;
-
- NSLog(@"item : %@", item);
-
- if ([item.itemSubTypeCode isEqualToString:ksItemSubTypeCodeDevice]) {//장치일 경우
-
- ItemSubModel *subItem = [item.subItems matchedObjectName:ksCustomRadioButtonStatus condition:YES];
-
- NSLog(@"subItem : %@", subItem);
-
- if (subItem) {
-
- [[JDFacade facade] setRadioButtonStatus:@NO object:subItem];
- NSLog(@"subItem.cmdclsValueList : %@", subItem.cmdclsValueList);
-
- for (CmdClsValueModel *cmdclsValue in subItem.cmdclsValueList) {
-
- [[JDFacade facade] setRadioButtonStatus:@NO object:cmdclsValue];
- cmdclsValue.isSelected = NO;
- }
- }
- }
-
- if (_triggers && _triggers.count) {
- [_triggers removeAllObjects];
- }
-
- [_tableView reloadData];
- }
- - (void)btnDeleteDeviceActionTouched:(id)sender {
-
- NSLog(@"btnDeleteDeviceActionTouched");
-
- CustomButton *btnDelete = (CustomButton *)sender;
-
- ItemSubModel *subItem = (ItemSubModel *)btnDelete.value;
-
- //선택 설정을 초기화
- [[JDFacade facade] setRadioButtonStatus:@NO object:subItem];
-
- for (CmdClsValueModel *cmdclsValue in subItem.cmdclsValueList) {
- [[JDFacade facade] setRadioButtonStatus:@NO object:cmdclsValue];
- cmdclsValue.isSelected = NO;
- }
-
- ItemModel *deviceItem = [_actions objectKey:@"itemSubTypeCode" eqaulToString:ksItemSubTypeCodeDevice];
- [deviceItem.subItems removeObject:subItem];
-
- [_tableView reloadData];
- }
- - (void)btnDeletePushActionTouched:(id)sender {
-
- ItemModel *pushItem = [_actions objectKey:@"itemSubTypeCode" eqaulToString:ksItemSubTypeCodeAppPush];
- [_actions removeObject:pushItem];
- [_tableView reloadData];
-
- }
- - (void)btnAddTouched:(id)sender {
- UIButton *btn = sender;
-
- //1001:규칙add, 2001:알림add
-
- UIControl *control;
-
- if ([btn tag] > 2000) {
-
- control = [self.view viewWithTag:2000];
- }
- else {
-
- control = [self.view viewWithTag:1000];
-
- }
-
- [control becomeFirstResponder];
-
- }
- //- (void)btnInputConfirmTouched:(id)sender {
- //
- // UIButton *btn = sender;
- //
- // //1002:규칙add, 2002:알림add
- // if ([btn tag] > 2000) {
- //
- //
- // }
- // else {
- //
- // }
- //
- //}
- - (void)insertActionAddButton:(UIButton*)button {
-
- if (![button actionsForTarget:self forControlEvent:UIControlEventTouchUpInside]) {
- [button addTarget:self action:@selector(btnAddTouched:) forControlEvents:UIControlEventTouchUpInside];
- }
- }
- //- (void)insertActionInputConfirmButton:(UIButton*)button {
- //
- // if (![button actionsForTarget:self forControlEvent:UIControlEventTouchUpInside]) {
- // [button addTarget:self action:@selector(btnInputConfirmTouched:) forControlEvents:UIControlEventTouchUpInside];
- // }
- //}
- - (IBAction)btnCancelTouched:(id)sender {
-
- [self dismissViewControllerAnimated:YES completion:nil];
- }
- #pragma mark - UI Events
- - (IBAction)btnConfirmTouched:(id)sender {
- [self.view endEditing:YES];
-
- //1.Validate Title
- RulesAddTitleTableViewCell *tcell = (RulesAddTitleTableViewCell *)[_tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; //타이틀 섹션
-
- if (tcell && ![ValidateUtil validateTextfiled:tcell.txtRuleTitle type:ValidateTypeNull title:NSLocalizedString(@"규칙 이름", @"규칙 이름")]) {
- return;
- }
-
- if (tcell.txtRuleTitle.text.length > 40) {
- [[JDFacade facade] alert:@"규칙이름은 최대 40자까지 입력할 수 있습니다"];
- return;
- }
-
- ItemModel *pushItem = [_actions objectKey:@"itemSubTypeCode" eqaulToString:ksItemSubTypeCodeAppPush];
-
- if (pushItem) {
-
- if (_txvMessage && [_txvMessage.text isEmptyString]) {//푸시메시지 여부 확인
- [_actions removeObject:pushItem];
- }
- else if (_txvMessage) {
-
- ItemSubModel *subItem = pushItem.pushes[0];
- subItem.cmdclsValue = _txvMessage.text;
-
- if (_txvMessage.text.length > 120) {
- [[JDFacade facade] alert:@"알림메시지는 최대 120자까지 입력할 수 있습니다"];
- return;
- }
- }
- }
-
- if (!_refRuleDetail) {//생성
-
- [self requestRegisterRule];
-
- }
- else {//수정
- BOOL hasDeleteNode = NO;
- ItemModel *triggerDevice = [_triggers objectKey:@"itemSubTypeCode" eqaulToString:ksItemSubTypeCodeDevice];
- ItemModel *actionDevice = [_actions objectKey:@"itemSubTypeCode" eqaulToString:ksItemSubTypeCodeDevice];
- ItemModel *conditionDevice = [_conditions objectKey:@"itemSubTypeCode" eqaulToString:ksItemSubTypeCodeDevice];
-
- hasDeleteNode = [RulesAddViewController hasDeleteNode:triggerDevice];
- hasDeleteNode = [RulesAddViewController hasDeleteNode:actionDevice] ? YES : hasDeleteNode;
- hasDeleteNode = [RulesAddViewController hasDeleteNode:conditionDevice] ? YES : hasDeleteNode;
-
- if (hasDeleteNode) {
- [[JDFacade facade] confirm:@"삭제된 장치를 제외 후 저장합니다" completion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
- if (buttonIndex == 0) {//OK
- [self getRidOfDeleteDevices:triggerDevice];
- [self getRidOfDeleteDevices:actionDevice];
- [self getRidOfDeleteDevices:conditionDevice];
-
- [_tableView reloadData];
-
- [self requestModifyRule];
- }
- }];
- }
- else {
-
- [self requestModifyRule];
- }
- }
- }
- //삭제된 장치를 제거함.
- - (void)getRidOfDeleteDevices:(ItemModel *)deviceItem {
-
- [deviceItem.subItems enumerateObjectsUsingBlock:^(ItemSubModel *subItem, NSUInteger idx, BOOL * _Nonnull stop) {
-
- if (subItem.deleteYn) {
-
- if ([_triggers containsObject:deviceItem]) {
- [_triggers removeObject:deviceItem];
- return;
- }
- [deviceItem.subItems removeObject:subItem];
- }
- }];
- }
- #pragma mark - MemoryWarning
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- @end
|