<commit_before>//
//  PrinterJobViewCell.swift
//  CDFLabs
//
//  Created by Qasim on 2016-04-03.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import UIKit

class PrinterJobViewCell: UITableViewCell {

    init(job: PrintJob) {
        super.init(style: .Default, reuseIdentifier: job.id)

        self.backgroundColor = UIColor.cdfGreyColor()

        let insetView = self.createInsetView(job)
        self.addSubview(insetView)

        let viewsDict: [String: AnyObject] = [
            "insetView": insetView
        ]

        let metricsDict: [String: AnyObject] = [
            "cellPadding": CLTable.cellPadding,
            "cellHeight": CLTable.cellHeight + 6
        ]

        let options = NSLayoutFormatOptions(rawValue: 0)

        self.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(
            "|-cellPadding-[insetView]-cellPadding-|", options: options, metrics: metricsDict, views: viewsDict))

        self.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(
            "V:|[insetView(cellHeight)]-cellPadding-|", options: options, metrics: metricsDict, views: viewsDict))
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }

    func createInsetView(job: PrintJob) -> UIView {
        let insetView = UIView()
        insetView.translatesAutoresizingMaskIntoConstraints = false
        insetView.backgroundColor = UIColor.whiteColor()
        insetView.layer.cornerRadius = CLTable.cellCornerRadius

        let freeView = self.createFreeView(job)
        insetView.addSubview(freeView)

        let ownerLabel = UILabel()
        ownerLabel.translatesAutoresizingMaskIntoConstraints = false
        ownerLabel.textColor = UIColor.blackColor()
        ownerLabel.font = UIFont.systemFontOfSize(20.0, weight: UIFontWeightLight)
        ownerLabel.text = job.owner
        ownerLabel.sizeToFit()
        insetView.addSubview(ownerLabel)

        let jobSizeLabel = UILabel()
        jobSizeLabel.translatesAutoresizingMaskIntoConstraints = false
        jobSizeLabel.textColor = UIColor.grayColor()
        jobSizeLabel.font = UIFont.systemFontOfSize(16.0, weight: UIFontWeightLight)

        let f = NSNumberFormatter()
        f.numberStyle = .DecimalStyle
        let sizeString = f.stringFromNumber(job.size)!
        jobSizeLabel.text = "\(sizeString) KB"

        insetView.addSubview(jobSizeLabel)

        let viewsDict: [String: AnyObject] = [
            "insetView": insetView,
            "freeView": freeView,
            "ownerLabel": ownerLabel,
            "jobSizeLabel": jobSizeLabel
        ]

        let metricsDict: [String: AnyObject] = [
            "cellPadding": CLTable.cellPadding,
            "cellHeight": CLTable.printerCellHeight
        ]

        let options = NSLayoutFormatOptions(rawValue: 0)

        insetView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(
            "|-16-[ownerLabel]", options: options, metrics: metricsDict, views: viewsDict))

        insetView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(
            "|-16-[freeView(68)]-[jobSizeLabel]", options: options, metrics: metricsDict, views: viewsDict))

        insetView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(
            "V:[freeView(20)]", options: options, metrics: metricsDict, views: viewsDict))

        insetView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(
            "V:|-16-[ownerLabel]-12-[jobSizeLabel]-16-|", options: options, metrics: metricsDict, views: viewsDict))

        insetView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(
            "V:[ownerLabel]-12-[freeView]-16-|", options: options, metrics: metricsDict, views: viewsDict))

        return insetView
    }

    func createFreeView(job: PrintJob) -> UIView {
        let freeView = UIView()
        freeView.translatesAutoresizingMaskIntoConstraints = false
        freeView.layer.cornerRadius = CLTable.cellCornerRadius

        let freeTextLabel = UILabel()
        freeTextLabel.translatesAutoresizingMaskIntoConstraints = false
        freeTextLabel.textColor = UIColor.whiteColor()
        freeTextLabel.textAlignment = .Center
        freeTextLabel.font = UIFont.systemFontOfSize(14.0)

        freeView.addSubview(freeTextLabel)

        if job.rank.containsString("done") {
            freeView.backgroundColor = UIColor.cdfGreenColor()
            freeTextLabel.text = "DONE"
        } else if job.rank.containsString("active") {
            freeView.backgroundColor = UIColor.cdfGreenColor()
            freeTextLabel.text = "ACTIVE"
        } else if job.rank.containsString("stalled") {
            freeView.backgroundColor = UIColor.cdfRedColor()
            freeTextLabel.text = "STALLED"
        } else {
            freeView.backgroundColor = UIColor.cdfYellowColor()
            freeTextLabel.text = "RANK \(job.rank)"
        }

        let viewsDict: [String: AnyObject] = [
            "freeTextLabel": freeTextLabel
        ]

        let options = NSLayoutFormatOptions(rawValue: 0)

        freeView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(
            "|[freeTextLabel]|", options: options, metrics: nil, views: viewsDict))

        freeView.addConstraint(NSLayoutConstraint(item: freeTextLabel, attribute: .CenterY, relatedBy: .Equal, toItem: freeView, attribute: .CenterY, multiplier: 1.0, constant: 0.0))

        return freeView
    }

    override func setSelected(selected: Bool, animated: Bool) {
        // Do nothing
    }
<commit_msg>Add custom freeView size<commit_after>//
//  PrinterJobViewCell.swift
//  CDFLabs
//
//  Created by Qasim on 2016-04-03.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import UIKit

class PrinterJobViewCell: UITableViewCell {

    var freeViewSize: Int = 0

    init(job: PrintJob) {
        super.init(style: .Default, reuseIdentifier: job.id)

        self.backgroundColor = UIColor.cdfGreyColor()

        let insetView = self.createInsetView(job)
        self.addSubview(insetView)

        let viewsDict: [String: AnyObject] = [
            "insetView": insetView
        ]

        let metricsDict: [String: AnyObject] = [
            "cellPadding": CLTable.cellPadding,
            "cellHeight": CLTable.cellHeight + 6
        ]

        let options = NSLayoutFormatOptions(rawValue: 0)

        self.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(
            "|-cellPadding-[insetView]-cellPadding-|", options: options, metrics: metricsDict, views: viewsDict))

        self.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(
            "V:|[insetView(cellHeight)]-cellPadding-|", options: options, metrics: metricsDict, views: viewsDict))
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }

    func createInsetView(job: PrintJob) -> UIView {
        let insetView = UIView()
        insetView.translatesAutoresizingMaskIntoConstraints = false
        insetView.backgroundColor = UIColor.whiteColor()
        insetView.layer.cornerRadius = CLTable.cellCornerRadius

        let freeView = self.createFreeView(job)
        insetView.addSubview(freeView)

        let ownerLabel = UILabel()
        ownerLabel.translatesAutoresizingMaskIntoConstraints = false
        ownerLabel.textColor = UIColor.blackColor()
        ownerLabel.font = UIFont.systemFontOfSize(20.0, weight: UIFontWeightLight)
        ownerLabel.text = job.owner
        ownerLabel.sizeToFit()
        insetView.addSubview(ownerLabel)

        let jobSizeLabel = UILabel()
        jobSizeLabel.translatesAutoresizingMaskIntoConstraints = false
        jobSizeLabel.textColor = UIColor.grayColor()
        jobSizeLabel.font = UIFont.systemFontOfSize(16.0, weight: UIFontWeightLight)

        let f = NSNumberFormatter()
        f.numberStyle = .DecimalStyle
        let sizeString = f.stringFromNumber(job.size)!
        jobSizeLabel.text = "\(sizeString) KB"

        insetView.addSubview(jobSizeLabel)

        let viewsDict: [String: AnyObject] = [
            "insetView": insetView,
            "freeView": freeView,
            "ownerLabel": ownerLabel,
            "jobSizeLabel": jobSizeLabel
        ]

        let metricsDict: [String: AnyObject] = [
            "cellPadding": CLTable.cellPadding,
            "cellHeight": CLTable.printerCellHeight,
            "freeViewSize": self.freeViewSize
        ]

        let options = NSLayoutFormatOptions(rawValue: 0)

        insetView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(
            "|-16-[ownerLabel]", options: options, metrics: metricsDict, views: viewsDict))

        insetView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(
            "|-16-[freeView(freeViewSize)]-[jobSizeLabel]", options: options, metrics: metricsDict, views: viewsDict))

        insetView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(
            "V:[freeView(20)]", options: options, metrics: metricsDict, views: viewsDict))

        insetView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(
            "V:|-16-[ownerLabel]-12-[jobSizeLabel]-16-|", options: options, metrics: metricsDict, views: viewsDict))

        insetView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(
            "V:[ownerLabel]-12-[freeView]-16-|", options: options, metrics: metricsDict, views: viewsDict))

        return insetView
    }

    func createFreeView(job: PrintJob) -> UIView {
        let freeView = UIView()
        freeView.translatesAutoresizingMaskIntoConstraints = false
        freeView.layer.cornerRadius = CLTable.cellCornerRadius

        let freeTextLabel = UILabel()
        freeTextLabel.translatesAutoresizingMaskIntoConstraints = false
        freeTextLabel.textColor = UIColor.whiteColor()
        freeTextLabel.textAlignment = .Center
        freeTextLabel.font = UIFont.systemFontOfSize(14.0)

        freeView.addSubview(freeTextLabel)

        if job.rank.containsString("done") {
            freeView.backgroundColor = UIColor.cdfGreenColor()
            freeTextLabel.text = "DONE"
            self.freeViewSize = 50
        } else if job.rank.containsString("active") {
            freeView.backgroundColor = UIColor.cdfGreenColor()
            freeTextLabel.text = "ACTIVE"
            self.freeViewSize = 58
        } else if job.rank.containsString("stalled") {
            freeView.backgroundColor = UIColor.cdfRedColor()
            freeTextLabel.text = "STALLED"
            self.freeViewSize = 66
        } else {
            freeView.backgroundColor = UIColor.cdfYellowColor()
            freeTextLabel.text = "RANK \(job.rank)"
            if job.rank.characters.count == 1 {
                self.freeViewSize = 60
            } else {
                self.freeViewSize = 68
            }
        }

        let viewsDict: [String: AnyObject] = [
            "freeTextLabel": freeTextLabel
        ]

        let options = NSLayoutFormatOptions(rawValue: 0)

        freeView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(
            "|[freeTextLabel]|", options: options, metrics: nil, views: viewsDict))

        freeView.addConstraint(NSLayoutConstraint(item: freeTextLabel, attribute: .CenterY, relatedBy: .Equal, toItem: freeView, attribute: .CenterY, multiplier: 1.0, constant: 0.0))

        return freeView
    }

    override func setSelected(selected: Bool, animated: Bool) {
        // Do nothing
    }

{'fraction_non_alphanumeric': 0.09907013122447206, 'fraction_numerical': 0.009037976883636048, 'mean_word_length': 2.8017839444995043, 'pattern_counts': {'":': 21, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '119337', 'n_tokens_mistral': 3383, 'n_tokens_neox': 3162, 'n_words': 593}