show password categories

This commit is contained in:
Bob Sun 2017-02-06 21:53:54 +08:00
parent ceba7d271b
commit 59eb4af8bb
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4
6 changed files with 44 additions and 12 deletions

View file

@ -37,12 +37,12 @@ extension PasswordEntity {
var decrypted_password = ""
var decrypted_addtions = [String: String]()
plain.enumerateLines(invoking: { line, _ in
let item = line.characters.split(separator: ":").map(String.init)
if item.count == 1 {
decrypted_password = item[0]
let items = line.characters.split(separator: ":").map(String.init)
if items.count == 1 {
decrypted_password = items[0]
} else {
let key = item[0]
let value = item[1].trimmingCharacters(in: .whitespaces)
let key = items[0]
let value = items[1].trimmingCharacters(in: .whitespaces)
decrypted_addtions[key] = value
}
})

View file

@ -10,6 +10,8 @@ import UIKit
class PasswordDetailTableViewController: UITableViewController, UIGestureRecognizerDelegate {
var passwordEntity: PasswordEntity?
var passwordCategoryEntities: [PasswordCategoryEntity]?
var passwordCategoryText = ""
var password = Password()
struct TableCell {
@ -29,6 +31,11 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
tableView.register(UINib(nibName: "LabelTableViewCell", bundle: nil), forCellReuseIdentifier: "labelCell")
tableView.register(UINib(nibName: "PasswordDetailTitleTableViewCell", bundle: nil), forCellReuseIdentifier: "passwordDetailTitleTableViewCell")
let passwordCategoryArray = passwordCategoryEntities?.map({ (value: PasswordCategoryEntity) -> String in
value.category!
})
passwordCategoryText = (passwordCategoryArray?.joined(separator: " > "))!
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(PasswordDetailTableViewController.tapMenu(recognizer:)))
tableView.addGestureRecognizer(tapGesture)
tapGesture.delegate = self
@ -119,7 +126,7 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
let cell = tableView.dequeueReusableCell(withIdentifier: "passwordDetailTitleTableViewCell", for: indexPath) as! PasswordDetailTitleTableViewCell
cell.passwordImageImageView.image = #imageLiteral(resourceName: "PasswordImagePlaceHolder")
cell.nameLabel.text = passwordEntity?.name
cell.categoryLabel.text = "category1 > category2"
cell.categoryLabel.text = passwordCategoryText
return cell
} else {

View file

@ -33,7 +33,7 @@
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="category1 &gt; category2" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Ctk-b6-pjw">
<rect key="frame" x="86" y="34.5" width="226" height="16"/>
<rect key="frame" x="86" y="38.5" width="226" height="16"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleFootnote"/>
<color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
@ -48,7 +48,7 @@
<constraint firstItem="KvF-3d-EbG" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="topMargin" constant="10" id="OFd-QE-rRm"/>
<constraint firstAttribute="bottomMargin" secondItem="gKV-Cd-wIk" secondAttribute="bottom" constant="6" id="fyJ-BI-Jls"/>
<constraint firstAttribute="trailingMargin" secondItem="KvF-3d-EbG" secondAttribute="trailing" id="jPo-Fz-5h5"/>
<constraint firstItem="Ctk-b6-pjw" firstAttribute="top" secondItem="KvF-3d-EbG" secondAttribute="bottom" constant="-4" id="wDX-Mb-bsB"/>
<constraint firstItem="Ctk-b6-pjw" firstAttribute="top" secondItem="KvF-3d-EbG" secondAttribute="bottom" id="wDX-Mb-bsB"/>
<constraint firstItem="gKV-Cd-wIk" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leadingMargin" constant="8" id="wjc-N6-2b9"/>
</constraints>
</tableViewCellContentView>

View file

@ -135,10 +135,16 @@ class PasswordStore {
fm.enumerator(atPath: storeURL.path)?.forEach({ (e) in
if let e = e as? String, let url = URL(string: e) {
if url.pathExtension == "gpg" {
let entity = PasswordEntity(context: context)
let passwordEntity = PasswordEntity(context: context)
let endIndex = url.lastPathComponent.index(url.lastPathComponent.endIndex, offsetBy: -4)
entity.name = url.lastPathComponent.substring(to: endIndex)
entity.rawPath = "password-store/\(url.absoluteString)"
passwordEntity.name = url.lastPathComponent.substring(to: endIndex)
passwordEntity.rawPath = "password-store/\(url.path)"
let items = url.path.characters.split(separator: "/").map(String.init)
for i in 0 ..< items.count - 1 {
let passwordCategoryEntity = PasswordCategoryEntity(context: context)
passwordCategoryEntity.category = items[i]
passwordCategoryEntity.password = passwordEntity
}
}
}
})
@ -161,6 +167,17 @@ class PasswordStore {
}
}
func fetchPasswordCategoryEntityCoreData(password: PasswordEntity) -> [PasswordCategoryEntity] {
let passwordCategoryEntityFetch = NSFetchRequest<NSFetchRequestResult>(entityName: "PasswordCategoryEntity")
passwordCategoryEntityFetch.predicate = NSPredicate(format: "password = %@", password)
do {
let passwordCategoryEntities = try context.fetch(passwordCategoryEntityFetch) as! [PasswordCategoryEntity]
return passwordCategoryEntities
} catch {
fatalError("Failed to fetch employees: \(error)")
}
}
func updateRemoteRepo() {
}
}

View file

@ -182,6 +182,8 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
passwordEntity = passwordEntities![index]
}
viewController.passwordEntity = passwordEntity
let passwordCategoryEntities = PasswordStore.shared.fetchPasswordCategoryEntityCoreData(password: passwordEntity)
viewController.passwordCategoryEntities = passwordCategoryEntities
}
}
}

View file

@ -1,11 +1,17 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="11759" systemVersion="16D32" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<entity name="PasswordCategoryEntity" representedClassName="PasswordCategoryEntity" syncable="YES" codeGenerationType="class">
<attribute name="category" optional="YES" attributeType="String" syncable="YES"/>
<relationship name="password" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="PasswordEntity" inverseName="categories" inverseEntity="PasswordEntity" syncable="YES"/>
</entity>
<entity name="PasswordEntity" representedClassName="PasswordEntity" syncable="YES" codeGenerationType="class">
<attribute name="name" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="raw" optional="YES" attributeType="Binary" syncable="YES"/>
<attribute name="rawPath" optional="YES" attributeType="String" syncable="YES"/>
<relationship name="categories" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="PasswordCategoryEntity" inverseName="password" inverseEntity="PasswordCategoryEntity" syncable="YES"/>
</entity>
<elements>
<element name="PasswordEntity" positionX="-63" positionY="-18" width="128" height="90"/>
<element name="PasswordEntity" positionX="-63" positionY="-18" width="128" height="103"/>
<element name="PasswordCategoryEntity" positionX="115" positionY="-9" width="128" height="73"/>
</elements>
</model>