Commit 6524daa8 by Julio Hermosa

primera entrega

parent 57491b63
...@@ -42,6 +42,15 @@ class CoreDataManager { ...@@ -42,6 +42,15 @@ class CoreDataManager {
print("error al guardar \(error)") print("error al guardar \(error)")
} }
} }
func deleteFavorites(id: Int, array: [Entity]){
let context = container.viewContext
for i in 0..<array.count {
if array[i].id == Int64(id){
context.delete(array[i])
}
}
}
func fetchFavorites()->[Entity]{ func fetchFavorites()->[Entity]{
let fetchRequest: NSFetchRequest<Entity> = Entity.fetchRequest() let fetchRequest: NSFetchRequest<Entity> = Entity.fetchRequest()
do { do {
......
...@@ -6,9 +6,10 @@ ...@@ -6,9 +6,10 @@
<attribute name="id" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/> <attribute name="id" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="message" optional="YES" attributeType="String"/> <attribute name="message" optional="YES" attributeType="String"/>
<attribute name="name" optional="YES" attributeType="String"/> <attribute name="name" optional="YES" attributeType="String"/>
<attribute name="phoneNumber" optional="YES" attributeType="String"/>
<attribute name="title" optional="YES" attributeType="String"/> <attribute name="title" optional="YES" attributeType="String"/>
</entity> </entity>
<elements> <elements>
<element name="Entity" positionX="-54" positionY="-9" width="128" height="133"/> <element name="Entity" positionX="-54" positionY="-9" width="128" height="148"/>
</elements> </elements>
</model> </model>
\ No newline at end of file
...@@ -22,5 +22,6 @@ extension Entity { ...@@ -22,5 +22,6 @@ extension Entity {
@NSManaged public var date: Date? @NSManaged public var date: Date?
@NSManaged public var address: String? @NSManaged public var address: String?
@NSManaged public var title: String? @NSManaged public var title: String?
@NSManaged public var phoneNumber: String?
} }
...@@ -56,7 +56,7 @@ extension String{ ...@@ -56,7 +56,7 @@ extension String{
returnValue = String(subStr) returnValue = String(subStr)
case .hour: case .hour:
let start = date.index(date.startIndex, offsetBy: 10) let start = date.index(date.startIndex, offsetBy: 11)
let end = date.index(date.startIndex, offsetBy: 16) let end = date.index(date.startIndex, offsetBy: 16)
let range = start..<end let range = start..<end
let subStr = date[range] let subStr = date[range]
......
...@@ -149,7 +149,6 @@ class MapViewController: UIViewController { ...@@ -149,7 +149,6 @@ class MapViewController: UIViewController {
marker.map = self.mapView marker.map = self.mapView
marker.iconView = markerView marker.iconView = markerView
//marker.icon = markerImage
marker.title = "\(features[i].properties.pk)" marker.title = "\(features[i].properties.pk)"
} }
}) })
......
...@@ -10,17 +10,29 @@ import UIKit ...@@ -10,17 +10,29 @@ import UIKit
class MyPendingsTableViewCell: UITableViewCell { class MyPendingsTableViewCell: UITableViewCell {
var id = Int()
let format = Format.init()
let manager = CoreDataManager()
@IBOutlet weak var dayLabel: UILabel! @IBOutlet weak var dayLabel: UILabel!
@IBOutlet weak var monthLabel: UILabel! @IBOutlet weak var monthLabel: UILabel!
@IBOutlet weak var titleLabel: UILabel! @IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var detailLabel: UILabel! @IBOutlet weak var detailLabel: UILabel!
let format = Format.init() @IBOutlet weak var deleteButton: UIButton!
@IBAction func deleteRow(_ sender: Any) {
let array = manager.fetchFavorites()
print(id)
manager.deleteFavorites(id: id, array: array)
}
override func awakeFromNib() { override func awakeFromNib() {
super.awakeFromNib() super.awakeFromNib()
dayLabel.textColor = format.subTitleTextColor dayLabel.textColor = format.subTitleTextColor
monthLabel.textColor = format.titleTextColor monthLabel.textColor = format.titleTextColor
} }
override func setSelected(_ selected: Bool, animated: Bool) { override func setSelected(_ selected: Bool, animated: Bool) {
......
...@@ -9,10 +9,20 @@ ...@@ -9,10 +9,20 @@
import UIKit import UIKit
import CoreData import CoreData
struct MyPendings{
var id: Int
var title: String?
var message: String?
var date: String
var address: String?
var contactNumber: String?
var contactName: String?
}
class PendingsViewController: UIViewController { class PendingsViewController: UIViewController {
let manager = CoreDataManager() let manager = CoreDataManager()
var favorites = [(Int64, String, String)]() var myPendings = [MyPendings]()
let format = Format.init() let format = Format.init()
@IBOutlet weak var tableView: UITableView! @IBOutlet weak var tableView: UITableView!
...@@ -20,11 +30,10 @@ class PendingsViewController: UIViewController { ...@@ -20,11 +30,10 @@ class PendingsViewController: UIViewController {
override func viewWillAppear(_ animated: Bool) { override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated) super.viewWillAppear(animated)
let array = manager.fetchFavorites() let array = manager.fetchFavorites()
for i in 0..<manager.fetchFavorites().count { for i in 0..<manager.fetchFavorites().count {
favorites.append((Int64(array[i].id),array[i].message!,"\(array[i].date!)")) myPendings.append(MyPendings(id: Int(array[i].id), title: array[i].title, message: array[i].message, date: "\(array[i].date!)", address: array[i].address, contactNumber: array[i].name, contactName: array[i].phoneNumber))
//print(array[i].id, array[i].name!, array[i].date!)
} }
//print(favorites)
} }
override func viewDidLoad() { override func viewDidLoad() {
...@@ -42,17 +51,35 @@ extension PendingsViewController: UITableViewDelegate, UITableViewDataSource{ ...@@ -42,17 +51,35 @@ extension PendingsViewController: UITableViewDelegate, UITableViewDataSource{
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! MyPendingsTableViewCell let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! MyPendingsTableViewCell
let date = favorites[indexPath.row].2 let date = myPendings[indexPath.row].date
let month = date.getDatePart(dateUnit: .month) let month = date.getDatePart(dateUnit: .month)
let monthString = month.getMonthShortString() let monthString = month.getMonthShortString()
let day = date.getDatePart(dateUnit: .day) let day = date.getDatePart(dateUnit: .day)
cell.titleLabel.text = "\(favorites[indexPath.row].1)" var detailLabel:String = ""
cell.detailLabel.text = "\(favorites[indexPath.row].2)" cell.titleLabel.text = myPendings[indexPath.row].title
cell.titleLabel.textColor = format.subTitleTextColor
cell.titleLabel.font = format.subTitleFontStyle
if let address = myPendings[indexPath.row].address {
detailLabel = address
}
if let contactName = myPendings[indexPath.row].contactName {
detailLabel = detailLabel + "\n\(contactName)"
}
if let contactNumber = myPendings[indexPath.row].contactNumber {
detailLabel = detailLabel + "\n\(contactNumber)"
}
cell.detailLabel.text = detailLabel
cell.detailLabel.font = format.bodyFontStyle
cell.dayLabel.text = day cell.dayLabel.text = day
cell.monthLabel.text = monthString cell.monthLabel.text = monthString
let id = myPendings[indexPath.row].id
cell.id = id
return cell return cell
} }
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 100, height: 50)) let headerLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 100, height: 50))
headerLabel.text = "Mis Pendientes" headerLabel.text = "Mis Pendientes"
......
...@@ -24,8 +24,6 @@ class RequestViewController: UIViewController { ...@@ -24,8 +24,6 @@ class RequestViewController: UIViewController {
var isFavorite = Bool() var isFavorite = Bool()
var checked = Bool() var checked = Bool()
var favorites = [Int]() var favorites = [Int]()
// private let appDelegate = UIApplication.shared.delegate as! AppDelegate
// private let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
private let manager = CoreDataManager() private let manager = CoreDataManager()
...@@ -52,8 +50,12 @@ class RequestViewController: UIViewController { ...@@ -52,8 +50,12 @@ class RequestViewController: UIViewController {
} }
func showRequestInformation(){ func showRequestInformation(){
let day = date.getDatePart(dateUnit: .day)
let month = (date.getDatePart(dateUnit: .month)).getMonthInSpanish()
let year = date.getDatePart(dateUnit: .year)
let hour = date.getDatePart(dateUnit: .hour)
let dateLabel = UILabel() let dateLabel = UILabel()
dateLabel.text = "Publicado el:\(date)" dateLabel.text = "Publicado el \(day) de \(month) de \(year) a las \(hour)"
dateLabel.font = format.dateFontStyle dateLabel.font = format.dateFontStyle
dateLabel.textColor = format.dateTextColor dateLabel.textColor = format.dateTextColor
let titleLbl = UILabel() let titleLbl = UILabel()
...@@ -81,17 +83,11 @@ class RequestViewController: UIViewController { ...@@ -81,17 +83,11 @@ class RequestViewController: UIViewController {
addressLabel.text = "\(address)" addressLabel.text = "\(address)"
addressLabel.lineBreakMode = .byWordWrapping addressLabel.lineBreakMode = .byWordWrapping
addressLabel.numberOfLines = .max addressLabel.numberOfLines = .max
// let cityLabel = UILabel()
// cityLabel.text = city let howToGetButton = UIButton()
let howToGetButton = UIButton()//(frame: CGRect(x: 0, y: 0, width: view.frame.width * 0.9, height: 20))
howToGetButton.backgroundColor = format.subTitleTextColor howToGetButton.backgroundColor = format.subTitleTextColor
howToGetButton.layer.cornerRadius = 10 howToGetButton.layer.cornerRadius = 10
// let howToGetLabel = UILabel()
// howToGetLabel.text = "Como LLegar"
// howToGetLabel.font = format.subTitleFontStyle
// howToGetLabel.textColor = .white
// howToGetLabel.textAlignment = .center
// howToGetButton.addSubview(howToGetLabel)
howToGetButton.setTitle("Como llegar", for: .normal) howToGetButton.setTitle("Como llegar", for: .normal)
howToGetButton.titleLabel?.font = format.subTitleFontStyle howToGetButton.titleLabel?.font = format.subTitleFontStyle
let contactLabel = UILabel() let contactLabel = UILabel()
......
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