1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-12 22:10:07 +02:00

♻️ Rename SiteList to DomainList

This commit is contained in:
2022-03-30 19:18:41 +02:00
parent 4c7aa7fead
commit a13990b96f
21 changed files with 232 additions and 308 deletions

View File

@@ -0,0 +1,14 @@
//
// DomainListCellProtocol.swift
// PHP Monitor
//
// Created by Nico Verbruggen on 03/12/2021.
// Copyright © 2021 Nico Verbruggen. All rights reserved.
//
import Cocoa
import AppKit
protocol DomainListCellProtocol {
func populateCell(with site: ValetSite)
}

View File

@@ -0,0 +1,33 @@
//
// DomainListTypeCell.swift
// PHP Monitor
//
// Created by Nico Verbruggen on 16/03/2022.
// Copyright © 2022 Nico Verbruggen. All rights reserved.
//
import Cocoa
import AppKit
class DomainListKindCell: NSTableCellView, DomainListCellProtocol
{
static let reusableName = "domainListKindCell"
@IBOutlet weak var imageViewType: NSImageView!
func populateCell(with site: ValetSite) {
// If the `aliasPath` is nil, we're dealing with a parked site (otherwise: linked).
imageViewType.image = NSImage(
named: site.aliasPath == nil
? "IconParked"
: "IconLinked"
)
// Unless, of course, this is a default site
if site.absolutePath == Valet.shared.config.defaultSite {
imageViewType.image = NSImage(named: "IconDefault")
}
imageViewType.contentTintColor = NSColor.tertiaryLabelColor
}
}

View File

@@ -0,0 +1,26 @@
//
// DomainListNameCell.swift
// PHP Monitor
//
// Created by Nico Verbruggen on 16/03/2022.
// Copyright © 2022 Nico Verbruggen. All rights reserved.
//
import Cocoa
import AppKit
class DomainListNameCell: NSTableCellView, DomainListCellProtocol
{
static let reusableName = "domainListNameCell"
@IBOutlet weak var labelSiteName: NSTextField!
@IBOutlet weak var labelPathName: NSTextField!
func populateCell(with site: ValetSite) {
// Show the name of the site (including tld)
labelSiteName.stringValue = "\(site.name).\(Valet.shared.config.tld)"
// Show the absolute path, except make sure to replace the /Users/username segment with ~ for readability
labelPathName.stringValue = site.absolutePathRelative
}
}

View File

@@ -0,0 +1,90 @@
//
// DomainListPhpCell.swift
// PHP Monitor
//
// Created by Nico Verbruggen on 16/03/2022.
// Copyright © 2022 Nico Verbruggen. All rights reserved.
//
import Cocoa
import AppKit
class DomainListPhpCell: NSTableCellView, DomainListCellProtocol
{
static let reusableName = "domainListPhpCell"
var site: ValetSite? = nil
@IBOutlet weak var buttonPhpVersion: NSButton!
@IBOutlet weak var imageViewPhpVersionOK: NSImageView!
func populateCell(with site: ValetSite) {
self.site = site
buttonPhpVersion.title = " PHP \(site.servingPhpVersion)"
if site.isolatedPhpVersion != nil {
imageViewPhpVersionOK.isHidden = false
imageViewPhpVersionOK.image = NSImage(named: "Isolated")
} else {
imageViewPhpVersionOK.isHidden = (site.composerPhp == "???" || !site.composerPhpCompatibleWithLinked)
imageViewPhpVersionOK.image = NSImage(named: "Checkmark")
}
}
@IBAction func pressedPhpVersion(_ sender: Any) {
guard let site = self.site else { return }
let alert = NSAlert.init()
alert.alertStyle = .informational
var information = ""
if (self.site?.isolatedPhpVersion != nil) {
information += "alert.composer_php_isolated.desc".localized(
self.site!.isolatedPhpVersion!.versionNumber.homebrewVersion,
PhpEnv.phpInstall.version.short
)
information += "\n\n"
}
information += "alert.composer_php_requirement.type.\(site.composerPhpSource.rawValue)"
.localized
alert.messageText = "alert.composer_php_requirement.title"
.localized("\(site.name).\(Valet.shared.config.tld)", site.composerPhp)
alert.informativeText = information
alert.addButton(withTitle: "site_link.close".localized)
var mapIndex: Int = NSApplication.ModalResponse.alertSecondButtonReturn.rawValue
var map: [Int: String] = [:]
if site.isolatedPhpVersion == nil {
// Determine which installed versions would be ideal to switch to,
// but make sure to exclude the currently linked version
PhpEnv.shared.validVersions(for: site.composerPhp).filter({ version in
version.homebrewVersion != PhpEnv.phpInstall.version.short
}).forEach { version in
alert.addButton(withTitle: "site_link.switch_to_php".localized(version.homebrewVersion))
map[mapIndex] = version.homebrewVersion
mapIndex += 1
}
// Site is not isolated, show options to switch global PHP version
alert.beginSheetModal(for: App.shared.domainListWindowController!.window!) { response in
if response.rawValue > NSApplication.ModalResponse.alertFirstButtonReturn.rawValue {
if map.keys.contains(response.rawValue) {
let version = map[response.rawValue]!
Log.info("Pressed button to switch to \(version)")
MainMenu.shared.switchToPhpVersion(version)
}
}
}
} else {
// Site is isolated, do not show any options to switch
alert.beginSheetModal(for: App.shared.domainListWindowController!.window!)
}
}
}

View File

@@ -0,0 +1,34 @@
//
// DomainListNameCell.swift
// PHP Monitor
//
// Created by Nico Verbruggen on 16/03/2022.
// Copyright © 2022 Nico Verbruggen. All rights reserved.
//
import Cocoa
import AppKit
class DomainListProxiesCell: NSTableCellView, DomainListCellProtocol
{
static let reusableName = "domainListProxiesCell"
@IBOutlet weak var textFieldPrimary: NSTextField!
@IBOutlet weak var textFieldAdditional: NSTextField!
@IBOutlet weak var buttonProxyList: NSButton!
func populateCell(with site: ValetSite) {
// Show the first proxy
textFieldPrimary.stringValue = (site.proxies.count == 0)
? ""
: site.proxies[0]
// Show additional proxy count
textFieldAdditional.stringValue = site.proxies.count > 1
? "and \(site.proxies.count - 1) more active"
: site.proxies.count == 1 ? "(active)" : ""
// Show button
buttonProxyList.isHidden = site.proxies.count == 0
}
}

View File

@@ -0,0 +1,24 @@
//
// DomainListNameCell.swift
// PHP Monitor
//
// Created by Nico Verbruggen on 16/03/2022.
// Copyright © 2022 Nico Verbruggen. All rights reserved.
//
import Cocoa
import AppKit
class DomainListTLSCell: NSTableCellView, DomainListCellProtocol
{
static let reusableName = "domainListTLSCell"
@IBOutlet weak var imageViewLock: NSImageView!
func populateCell(with site: ValetSite) {
// Show the green or red lock based on whether the site was secured
imageViewLock.contentTintColor = site.secured
? NSColor(named: "IconColorGreen") // green
: NSColor(named: "IconColorRed")
}
}

View File

@@ -0,0 +1,31 @@
//
// DomainListTypeCell.swift
// PHP Monitor
//
// Created by Nico Verbruggen on 16/03/2022.
// Copyright © 2022 Nico Verbruggen. All rights reserved.
//
import Cocoa
import AppKit
class DomainListTypeCell: NSTableCellView, DomainListCellProtocol
{
static let reusableName = "domainListTypeCell"
@IBOutlet weak var labelDriver: NSTextField!
@IBOutlet weak var labelPhpVersion: NSTextField!
func populateCell(with site: ValetSite) {
labelDriver.stringValue = site.driver ?? "driver.not_detected".localized
// Determine the Laravel version
if site.driver == "Laravel" && site.notableComposerDependencies.keys.contains("laravel/framework") {
let constraint = site.notableComposerDependencies["laravel/framework"]!
labelDriver.stringValue = "Laravel (\(constraint))"
}
// PHP version
labelPhpVersion.stringValue = site.composerPhp == "???" ? "Any PHP" : "PHP \(site.composerPhp)"
}
}