Commit 6524daa8 by Julio Hermosa

primera entrega

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