Commit c186452e authored by A. Wilcox's avatar A. Wilcox

Merge branch 'EtsyTagSupport'

parents a907f6d4 6086a154
......@@ -224,6 +224,79 @@ EtsyItem::EtsyItem(EtsySite *site, JSONNode json)
updateWithJSON(json);
}
libAPI vector<const char *> *EtsyItem::getTags(void)
{
vector <const char *> *tags = new vector<const char *>;
for(unsigned long next_tag = 0; next_tag < this->_tags.size(); next_tag++)
tags->push_back(this->_tags.at(next_tag));
return tags;
}
libAPI size_t EtsyItem::tagCount()
{
return this->_tags.size();
}
libAPI vector<const char *> *EtsyItem::getMaterials(void)
{
vector <const char *> *materials = new vector<const char *>;
for(unsigned long next_mat = 0; next_mat < this->_materials.size(); next_mat++)
materials->push_back(this->_materials.at(next_mat));
return materials;
}
libAPI size_t EtsyItem::materialCount()
{
return this->_materials.size();
}
void EtsyItem::loadTagsFromJSON(JSONNode tags)
{
for(unsigned long next_tag = 0; next_tag < this->_tags.size(); next_tag++)
free(this->_tags.at(next_tag));
this->_tags.clear();
for(JSONNode::iterator tag_iter = tags.begin();
tag_iter != tags.end();
tag_iter++)
{
JSONNode curr_tag = *tag_iter;
this->_tags.push_back(strdup(curr_tag.as_string().c_str()));
}
return;
}
void EtsyItem::loadMaterialsFromJSON(JSONNode materials)
{
for(unsigned long next_mat = 0; next_mat < this->_materials.size(); next_mat++)
free(this->_materials.at(next_mat));
this->_materials.clear();
for(JSONNode::iterator mat_iter = materials.begin();
mat_iter != materials.end();
mat_iter++)
{
JSONNode curr_material = *mat_iter;
this->_materials.push_back(strdup(curr_material.as_string().c_str()));
}
return;
}
void EtsyItem::updateWithJSON(JSONNode json)
{
JSONNode *listing_json = NULL, *transaction_json = NULL;
......@@ -395,6 +468,16 @@ void EtsyItem::updateWithJSON(JSONNode json)
this->_condition = NULL;
if(listing_json->find("tags") != listing_json->end())
{
loadTagsFromJSON(listing_json->at("tags"));
}
if(listing_json->find("materials") != listing_json->end())
{
loadMaterialsFromJSON(listing_json->at("materials"));
}
if(json.find("who_made") != json.end())
{
const char *metadata_value;
......
......@@ -52,6 +52,13 @@ public:
libAPI virtual ~EtsyItem();
libAPI EtsyItemState getItemState(void) { return this->_itemState; };
libAPI vector<const char *> *getTags(void);
libAPI vector<const char *> *getMaterials(void);
libAPI size_t materialCount(void);
libAPI size_t tagCount(void);
private:
/*!
@brief Initialise an Etsy item from Etsy JSON.
......@@ -61,10 +68,15 @@ private:
libAPI EtsyItem(EtsySite *site, JSONNode json);
libAPI void updateWithJSON(JSONNode json);
void loadTagsFromJSON(JSONNode tags);
void loadMaterialsFromJSON(JSONNode materials);
EtsyItemState _itemState;
friend class EtsySite;
vector<char *> _tags;
vector<char *> _materials;
};
#endif /*!__AUCTIONS_COMMON_ETSY_ITEM_H_*/
......@@ -98,7 +98,7 @@ void bridge_helper_cppify_dict(NSDictionary *changedKeys, WTDictionary *properti
abort();
}
}
array[++next_obj] = NULL;
array[next_obj] = NULL;
properties->set([key UTF8String], array, WTDICT_KEY_MANAGED);
}
else
......
......@@ -29,6 +29,7 @@
#include <Models/EtsyItem.h>
#include <Models/EtsySite.h>
#import "GANTracker.h"
#import "WTPrettyListViewController.h"
extern const char *site_names[3];
......@@ -49,8 +50,10 @@ extern const char *site_names[3];
@interface ItemViewController(Internal)
-(void)cancelTimers;
-(NSArray *)materialsForEtsyItem:(EtsyItem *)item;
-(void)sellSimilar;
-(void)setTimers;
-(NSArray *)tagsForEtsyItem:(EtsyItem *)item;
-(void)updateCategoryCells;
-(void)updateHeader;
-(void)updateHeaderFrame;
......@@ -300,6 +303,7 @@ extern const char *site_names[3];
if(item != nil)
{
[self updatePriceCells];
[self updateCategoryCells];
[self updateShippingCells];
......@@ -809,6 +813,36 @@ extern const char *site_names[3];
}
-(NSArray *)materialsForEtsyItem:(EtsyItem *)etsyItem
{
vector<const char *> *raw_materials = etsyItem->getMaterials();
NSMutableArray *materials = [NSMutableArray arrayWithCapacity:raw_materials->size()];
for(size_t next_elem = 0; next_elem < raw_materials->size(); next_elem++)
{
[materials addObject:[NSString stringWithCString:raw_materials->at(next_elem) encoding:NSASCIIStringEncoding]];
}
delete raw_materials;
return materials;
}
-(NSArray *)tagsForEtsyItem:(EtsyItem *)etsyItem
{
vector<const char *> *raw_tags = etsyItem->getTags();
NSMutableArray *tags = [NSMutableArray arrayWithCapacity:raw_tags->size()];
for(size_t next_tag = 0; next_tag < raw_tags->size(); next_tag++)
{
[tags addObject:[NSString stringWithCString:raw_tags->at(next_tag) encoding:NSASCIIStringEncoding]];
}
delete raw_tags;
return tags;
}
-(void)updateHeaderFrame
{
CGFloat addition = (isEditingHax ? 40.0 : 0.0);
......@@ -1162,6 +1196,51 @@ extern const char *site_names[3];
[priceSectionCells addObject:cell];
}
if(item->parent()->siteCode() == SITE_ETSY)
{
EtsyItem *etsy = static_cast<EtsyItem *>(item);
/* Tags */
cell = [self getPriceCell];
NSUInteger tagCount = 0;
if([changedKeys objectForKey:kItemPropertyTags] != nil)
tagCount = [[changedKeys objectForKey:kItemPropertyTags] count];
else
tagCount = etsy->tagCount();
cell.textLabel.text = @"tags";
cell.detailTextLabel.text = [NSString stringWithFormat:@"%u tag%@", tagCount, (tagCount > 1 ? @"s" : @"")];
cell.editableTextField.leftView = nil;
cell.textEditingStyle = WTEditableCellEditingStyleNone;
cell.accessoryType = cell.editingAccessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.selectionStyle = UITableViewCellSelectionStyleGray;
cell.tag = CELLTAG_TAGS;
[priceSectionCells addObject:cell];
/* Materials */
cell = [self getPriceCell];
NSUInteger materialCount = 0;
if([changedKeys objectForKey:kItemPropertyMaterials] != nil)
materialCount = [[changedKeys objectForKey:kItemPropertyMaterials] count];
else
materialCount = etsy->materialCount();
cell.textLabel.text = @"materials";
cell.detailTextLabel.text = [NSString stringWithFormat:@"%u tag%@", materialCount, (materialCount > 1 ? @"s" : @"")];
cell.editableTextField.leftView = nil;
cell.textEditingStyle = WTEditableCellEditingStyleNone;
cell.accessoryType = cell.editingAccessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.selectionStyle = UITableViewCellSelectionStyleGray;
cell.tag = CELLTAG_MATERIALS;
[priceSectionCells addObject:cell];
}
NSUInteger newPriceCellCount = [priceSectionCells count];
......@@ -2368,6 +2447,58 @@ extern const char *site_names[3];
[bridge release];
break;
}
case CELLTAG_TAGS:
{
EtsyItem *etsy = static_cast<EtsyItem *>(item);
NSMutableArray *tags;
if((tags = [changedKeys objectForKey:kItemPropertyTags]) == nil && etsy != nil)
{
tags = [NSMutableArray arrayWithArray:[self tagsForEtsyItem:etsy]];
[changedKeys setObject:tags forKey:kItemPropertyTags];
}
WTPrettyListViewController *tagList = [[WTPrettyListViewController alloc] initWithList:tags];
tagList.editing = self.isEditing;
if(self.isEditing)
tagList.maxItems = 13;
tagList.objectName = @"Tag";
tagList.title = @"Listing Tags";
[self.navigationController pushViewController:tagList animated:YES];
[tagList release];
break;
}
case CELLTAG_MATERIALS:
{
EtsyItem *etsy = static_cast<EtsyItem *>(item);
NSMutableArray *materials;
if((materials = [changedKeys objectForKey:kItemPropertyMaterials]) == nil && etsy != nil)
{
materials = [NSMutableArray arrayWithArray:[self materialsForEtsyItem:etsy]];
[changedKeys setObject:materials forKey:kItemPropertyMaterials];
}
WTPrettyListViewController *materialList = [[WTPrettyListViewController alloc] initWithList:materials];
materialList.editing = self.isEditing;
if(self.isEditing)
materialList.maxItems = 13;
materialList.objectName = @"Material";
materialList.title = @"Materials";
[self.navigationController pushViewController:materialList animated:YES];
[materialList release];
break;
}
}
switch (indexPath.section)
......
......@@ -13,6 +13,7 @@
#import "WTTextViewController.h"
#include <Models/AuSite.h>
#include <Models/eBaySite.h>
#include <Models/EtsyItem.h>
#include <Models/EtsySite.h>
#import "GANTracker.h"
......@@ -24,6 +25,9 @@ extern const char *site_names[3];
-(WTEditableCell *)getCategoryCell;
-(WTEditableCell *)getPriceCell;
-(WTEditableCell *)getShippingCell;
-(NSArray *)materialsForEtsyItem:(EtsyItem *)item;
-(NSArray *)tagsForEtsyItem:(EtsyItem *)item;
@end
@interface NewItemViewController(Internal)
......@@ -89,6 +93,14 @@ extern const char *site_names[3];
}
}
if(_item->parent()->siteCode() == SITE_ETSY)
{
EtsyItem *etsy = static_cast<EtsyItem *>(_item);
[changedKeys setObject:[self tagsForEtsyItem:etsy] forKey:kItemPropertyTags];
[changedKeys setObject:[self materialsForEtsyItem:etsy] forKey:kItemPropertyMaterials];
}
// This only works if the base item AND receiving site are eBay
if(_site->siteCode() == _item->parent()->siteCode() && _site->siteCode() == SITE_EBAY)
{
......@@ -116,7 +128,11 @@ extern const char *site_names[3];
[changedKeys setObject:[NSValue valueWithPointer:shipping_services] forKey:kItemPropertyShipping];
if(site->siteCode() == SITE_ETSY)
{
[changedKeys setObject:[NSNumber numberWithInt:1] forKey:kItemPropertyType];
[changedKeys setObject:[NSMutableArray array] forKey:kItemPropertyTags];
[changedKeys setObject:[NSMutableArray array] forKey:kItemPropertyMaterials];
}
else
[changedKeys setObject:[NSNumber numberWithInt:0] forKey:kItemPropertyType];
......@@ -1275,6 +1291,8 @@ extern const char *site_names[3];
case CELLTAG_CATEGORY:
case CELLTAG_CONDITION:
case CELLTAG_SHOPSECTION:
case CELLTAG_TAGS:
case CELLTAG_MATERIALS:
{
[super tableView:tableView didSelectRowAtIndexPath:indexPath];
break;
......@@ -1402,38 +1420,6 @@ extern const char *site_names[3];
[pickerController release];
break;
}
case CELLTAG_TAGS:
{
assert(site->siteCode() == SITE_ETSY);
if([changedKeys objectForKey:kItemPropertyTags] == nil)
[changedKeys setObject:[NSMutableArray array] forKey:kItemPropertyTags];
WTPrettyListViewController *tagList = [[WTPrettyListViewController alloc] initWithList:[changedKeys objectForKey:kItemPropertyTags]];
tagList.maxItems = 13;
tagList.objectName = @"Tag";
tagList.title = @"Listing Tags";
[self.navigationController pushViewController:tagList animated:YES];
[tagList release];
break;
}
case CELLTAG_MATERIALS:
{
assert(site->siteCode() == SITE_ETSY);
if([changedKeys objectForKey:kItemPropertyMaterials] == nil)
[changedKeys setObject:[NSMutableArray array] forKey:kItemPropertyMaterials];
WTPrettyListViewController *materialList = [[WTPrettyListViewController alloc] initWithList:[changedKeys objectForKey:kItemPropertyMaterials]];
materialList.maxItems = 13;
materialList.objectName = @"Material";
materialList.title = @"Materials";
[self.navigationController pushViewController:materialList animated:YES];
[materialList release];
break;
}
}
switch (indexPath.section)
......
......@@ -52,7 +52,6 @@
{
[super viewDidLoad];
[self setEditing:YES animated:NO];
[[self tableView] setAllowsSelectionDuringEditing:YES];
}
......@@ -85,6 +84,8 @@
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(![self isEditing]) return [model count];
return MIN([model count] + 1, maxItems);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment