mirror of
https://github.com/wahyd4/Yep.git
synced 2026-08-14 15:26:40 +10:00
add skill in EditSkills
This commit is contained in:
@@ -22,6 +22,13 @@ class EditSkillsViewController: BaseViewController {
|
||||
|
||||
@IBOutlet weak var addSkillsView: BottomButtonView!
|
||||
|
||||
lazy var selectSkillsTransitionManager = RegisterPickSkillsSelectSkillsTransitionManager()
|
||||
|
||||
var masterSkills = [Skill]()
|
||||
var learningSkills = [Skill]()
|
||||
|
||||
var skillCategories: [SkillCategory]?
|
||||
|
||||
|
||||
let editSkillCellID = "EditSkillCell"
|
||||
|
||||
@@ -47,6 +54,146 @@ class EditSkillsViewController: BaseViewController {
|
||||
|
||||
addSkillsView.title = NSLocalizedString("Add Skills", comment: "")
|
||||
|
||||
allSkillCategories(failureHandler: { (reason, errorMessage) -> Void in
|
||||
defaultFailureHandler(reason, errorMessage)
|
||||
|
||||
}, completion: { skillCategories -> Void in
|
||||
self.skillCategories = skillCategories
|
||||
})
|
||||
addSkillsView.tapAction = { [weak self] in
|
||||
let storyboard = UIStoryboard(name: "Intro", bundle: nil)
|
||||
let vc = storyboard.instantiateViewControllerWithIdentifier("RegisterSelectSkillsViewController") as! RegisterSelectSkillsViewController
|
||||
|
||||
vc.modalPresentationStyle = UIModalPresentationStyle.Custom
|
||||
vc.transitioningDelegate = self?.selectSkillsTransitionManager
|
||||
|
||||
if let strongSelf = self, me = strongSelf.me, skillSet = strongSelf.skillSet {
|
||||
|
||||
strongSelf.masterSkills = skillsFromUserSkillList(me.masterSkills)
|
||||
strongSelf.learningSkills = skillsFromUserSkillList(me.learningSkills)
|
||||
|
||||
switch skillSet {
|
||||
|
||||
case .Master:
|
||||
|
||||
vc.annotationText = NSLocalizedString("What are you good at?", comment: "")
|
||||
vc.selectedSkillsSet = Set(strongSelf.masterSkills)
|
||||
vc.anotherSelectedSkillsSet = Set(strongSelf.learningSkills)
|
||||
vc.failedSelectSkillMessage = NSLocalizedString("This skill already in another learning skills set!", comment: "")
|
||||
|
||||
case .Learning:
|
||||
|
||||
vc.annotationText = NSLocalizedString("What are you learning?", comment: "")
|
||||
vc.selectedSkillsSet = Set(strongSelf.learningSkills)
|
||||
vc.anotherSelectedSkillsSet = Set(strongSelf.masterSkills)
|
||||
vc.failedSelectSkillMessage = NSLocalizedString("This skill already in another master skills set!", comment: "")
|
||||
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
if let skillCategories = self?.skillCategories {
|
||||
vc.skillCategories = skillCategories
|
||||
}
|
||||
|
||||
vc.selectSkillAction = { [weak self] skill, selected in
|
||||
|
||||
var success = false
|
||||
|
||||
if let strongSelf = self {
|
||||
|
||||
switch skillSet {
|
||||
|
||||
case .Master:
|
||||
|
||||
if selected {
|
||||
|
||||
if strongSelf.learningSkills.filter({ $0.id == skill.id }).count == 0 {
|
||||
|
||||
strongSelf.masterSkills.append(skill)
|
||||
|
||||
success = true
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
let skillsToDelete = strongSelf.masterSkills.filter({ $0.id == skill.id })
|
||||
|
||||
if skillsToDelete.count > 0 {
|
||||
|
||||
for skill in skillsToDelete {
|
||||
|
||||
let realm = Realm()
|
||||
|
||||
if let userSkill = userSkillWithSkillID(skill.id, inRealm: realm) {
|
||||
realm.write {
|
||||
realm.delete(userSkill)
|
||||
}
|
||||
}
|
||||
|
||||
deleteSkill(skill, fromSkillSet: .Master, failureHandler: nil, completion: { success in
|
||||
println("deleteSkill \(skill.localName) from Master: \(success)")
|
||||
})
|
||||
}
|
||||
|
||||
strongSelf.masterSkills = strongSelf.masterSkills.filter({ $0.id != skill.id })
|
||||
|
||||
success = true
|
||||
}
|
||||
}
|
||||
|
||||
case .Learning:
|
||||
|
||||
if selected {
|
||||
if strongSelf.masterSkills.filter({ $0.id == skill.id }).count == 0 {
|
||||
|
||||
strongSelf.learningSkills.append(skill)
|
||||
|
||||
success = true
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
let skillsToDelete = strongSelf.learningSkills.filter({ $0.id == skill.id })
|
||||
|
||||
if skillsToDelete.count > 0 {
|
||||
|
||||
for skill in skillsToDelete {
|
||||
|
||||
let realm = Realm()
|
||||
|
||||
if let userSkill = userSkillWithSkillID(skill.id, inRealm: realm) {
|
||||
realm.write {
|
||||
realm.delete(userSkill)
|
||||
}
|
||||
}
|
||||
|
||||
deleteSkill(skill, fromSkillSet: .Learning, failureHandler: nil, completion: { success in
|
||||
println("deleteSkill \(skill.localName) from Learning: \(success)")
|
||||
})
|
||||
}
|
||||
|
||||
strongSelf.learningSkills = strongSelf.learningSkills.filter({ $0.id != skill.id })
|
||||
|
||||
success = true
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
strongSelf.updateSkillsTableView()
|
||||
strongSelf.afterChangedSkillsAction?()
|
||||
}
|
||||
|
||||
return success
|
||||
}
|
||||
}
|
||||
|
||||
self?.navigationController?.presentViewController(vc, animated: true, completion: nil)
|
||||
}
|
||||
|
||||
|
||||
realm = Realm()
|
||||
|
||||
@@ -56,6 +203,12 @@ class EditSkillsViewController: BaseViewController {
|
||||
self.me = me
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Actions
|
||||
|
||||
func updateSkillsTableView() {
|
||||
skillsTableView.reloadData()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - UITableViewDataSource, UITableViewDelegate
|
||||
|
||||
Reference in New Issue
Block a user