Commit 94f84cae authored by zpc's avatar zpc

Match split release panel to approved design

parent 94e79115
......@@ -19,9 +19,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.3.0</string>
<string>1.3.1</string>
<key>CFBundleVersion</key>
<string>7</string>
<string>8</string>
<key>LSMinimumSystemVersion</key>
<string>14.0</string>
<key>LSUIElement</key>
......
......@@ -8,63 +8,81 @@ struct SplitReleasePanel: View {
let settings: () -> Void
let quit: () -> Void
private var columnWidth: CGFloat {
let available = (NSScreen.main?.visibleFrame.width ?? 1440) - 32
return min(383, max(310, floor((available - 2) / CGFloat(max(1, model.panes.count)))))
}
private var width: CGFloat {
let desired = CGFloat(max(1, model.panes.count)) * 346 + 30
return min(desired, (NSScreen.main?.visibleFrame.width ?? 1440) - 36)
let desired = CGFloat(max(1, model.panes.count)) * columnWidth + 2
return min(desired, (NSScreen.main?.visibleFrame.width ?? 1440) - 32)
}
private var columnHeight: CGFloat {
min(630, max(420, (NSScreen.main?.visibleFrame.height ?? 900) - 160))
min(700, max(470, (NSScreen.main?.visibleFrame.height ?? 900) - 145))
}
var body: some View {
VStack(spacing: 0) {
HStack {
Label("Java 发布", systemImage: "circle.dotted.circle")
.font(ReleaseTypography.heading)
HStack(spacing: 12) {
ZStack {
Circle().stroke(ReleaseColors.blue.opacity(0.25), lineWidth: 3)
Circle().trim(from: 0, to: 0.76)
.stroke(
ReleaseColors.blue, style: StrokeStyle(lineWidth: 3, lineCap: .round)
)
.rotationEffect(.degrees(-90))
}
.frame(width: 26, height: 26)
Text("Java 发布").font(.system(size: 18, weight: .semibold))
Spacer()
Button {
model.add()
} label: {
Button(action: model.add) {
Label("增加窗口", systemImage: "plus")
.font(ReleaseTypography.action)
.padding(.horizontal, 10)
.frame(height: 29)
}
.disabled(
model.isRunning || model.panes.count >= 4
|| model.panes.count >= model.settings.projects.count
)
.buttonStyle(ReleaseButtonStyle())
.overlay { RoundedRectangle(cornerRadius: 7).strokeBorder(ReleaseColors.border) }
Menu {
Button("项目设置…", action: settings)
Divider()
Button("退出 Java 发布", action: quit)
} label: {
Image(systemName: "gearshape")
.frame(width: 28, height: 28)
.font(.system(size: 17))
.frame(width: 30, height: 29)
}
.menuStyle(.borderlessButton)
.menuIndicator(.hidden)
.fixedSize()
.disabled(model.isRunning)
.accessibilityLabel("项目设置")
}
.padding(15)
.padding(.horizontal, 18)
.frame(height: 58)
Rectangle().fill(ReleaseColors.border).frame(height: 1)
if model.panes.isEmpty {
VStack(spacing: 14) {
Text("先在项目设置中添加项目,再增加发布窗口。")
.foregroundStyle(ReleaseColors.muted)
VStack(spacing: 12) {
Text("添加项目后即可创建发布窗口。").foregroundStyle(ReleaseColors.muted)
Button("项目设置…", action: settings)
}
.frame(maxWidth: .infinity, minHeight: 240)
.frame(maxWidth: .infinity, minHeight: 220)
} else {
ScrollView(.horizontal) {
HStack(alignment: .top, spacing: 0) {
ForEach(model.panes) { pane in
ProjectReleaseColumn(model: model, pane: pane)
.frame(width: 345)
ProjectReleaseColumn(model: model, pane: pane, height: columnHeight)
.frame(width: columnWidth)
if pane.id != model.panes.last?.id {
Rectangle().fill(ReleaseColors.border).frame(
width: 1, height: columnHeight)
Rectangle().fill(ReleaseColors.border)
.frame(width: 1, height: columnHeight)
}
}
}
......@@ -74,33 +92,30 @@ struct SplitReleasePanel: View {
HStack {
if model.isRunning {
Text(
"运行 \(model.panes.filter { $0.state == .running }.count) · 排队 \(model.panes.filter { $0.state == .queued }.count)"
"运行 \(model.panes.filter { $0.state == .running }.count) / \(model.panes.count) · 排队 \(model.panes.filter { $0.state == .queued }.count)"
)
.foregroundStyle(ReleaseColors.muted)
} else {
Text("\(model.panes.count) / 4 个窗口")
.foregroundStyle(ReleaseColors.muted)
}
Spacer()
Button {
model.publishAll()
} label: {
Button(action: model.publishAll) {
Text("一起发布 \(model.panes.count) 个项目")
.font(ReleaseTypography.action)
.padding(.horizontal, 22)
.frame(height: 36)
.font(.system(size: 14, weight: .semibold))
.foregroundStyle(.white)
.padding(.horizontal, 23)
.frame(height: 40)
}
.disabled(model.isRunning || model.panes.count < 2)
.buttonStyle(ReleaseButtonStyle(base: ReleaseColors.action, prominent: true))
}
.padding(14)
.font(ReleaseTypography.detail)
.foregroundStyle(ReleaseColors.muted)
.padding(.horizontal, 18)
.frame(height: 66)
}
if let error = model.error {
Text(error)
.font(.caption)
.foregroundStyle(.red)
.textSelection(.enabled)
.padding([.horizontal, .bottom], 14)
Text(error).font(.caption).foregroundStyle(.red)
.textSelection(.enabled).padding([.horizontal, .bottom], 14)
}
}
.frame(width: width)
......@@ -113,221 +128,301 @@ struct SplitReleasePanel: View {
private struct ProjectReleaseColumn: View {
let model: SplitReleaseModel
@Bindable var pane: ReleasePaneState
let height: CGFloat
@State private var configurationDraft: DeployProfile?
@State private var showsModules = false
private var project: ReleaseProject? { model.project(for: pane) }
private var profile: DeployProfile? { project?.profiles.first { $0.id == pane.profileID } }
private var editable: Bool {
pane.state != .running && pane.state != .queued && !model.isRunning
}
private var columnHeight: CGFloat {
min(630, max(420, (NSScreen.main?.visibleFrame.height ?? 900) - 160))
}
private var matches: [String] {
let search = pane.search.trimmingCharacters(in: .whitespacesAndNewlines)
return search.isEmpty
let query = pane.search.trimmingCharacters(in: .whitespacesAndNewlines)
return query.isEmpty
? pane.availableModules
: pane.availableModules.filter { $0.localizedStandardContains(search) }
: pane.availableModules.filter { $0.localizedStandardContains(query) }
}
var body: some View {
ScrollView(.vertical) {
VStack(alignment: .leading, spacing: 11) {
HStack {
Menu {
ForEach(
model.settings.projects.filter { project in
!model.panes.contains {
$0.id != pane.id && $0.projectID == project.id
VStack(spacing: 0) {
ScrollView(.vertical) {
VStack(alignment: .leading, spacing: 12) {
HStack(spacing: 8) {
Image(systemName: "folder")
.foregroundStyle(ReleaseColors.muted)
Menu {
ForEach(
model.settings.projects.filter { candidate in
!model.panes.contains {
$0.id != pane.id && $0.projectID == candidate.id
}
}
) { candidate in
Button(candidate.name) { model.replace(pane, with: candidate) }
}
} label: {
HStack {
Text(project?.name ?? "选择项目")
.lineLimit(1)
.frame(maxWidth: .infinity, alignment: .leading)
Image(systemName: "chevron.down")
.font(.system(size: 10, weight: .semibold))
}
) { item in
Button(item.name) { model.replace(pane, with: item) }
.font(.system(size: 16, weight: .semibold))
}
} label: {
HStack {
Image(systemName: "folder")
Text(project?.name ?? "选择项目").lineLimit(1)
Image(systemName: "chevron.down")
.font(.system(size: 9))
.menuStyle(.borderlessButton)
.menuIndicator(.hidden)
.disabled(!editable)
Button {
model.remove(pane)
} label: {
Image(systemName: "xmark")
.font(.system(size: 11, weight: .semibold))
.frame(width: 24, height: 24)
}
.font(.system(size: 14, weight: .semibold))
}
.menuStyle(.borderlessButton)
.menuIndicator(.hidden)
.disabled(!editable)
Spacer(minLength: 4)
Button {
model.remove(pane)
} label: {
Image(systemName: "xmark")
.frame(width: 22, height: 22)
.buttonStyle(ReleaseButtonStyle())
.overlay { Circle().strokeBorder(ReleaseColors.border) }
.disabled(!editable)
.help("减少窗口")
}
.help("减少窗口")
.disabled(!editable)
.buttonStyle(ReleaseButtonStyle())
}
.frame(height: 28)
if let project {
if project.type == .cityKeeper {
menuRow("发布配置", selection: profile?.title ?? "选择配置文件") {
let files =
(try? project.configurationFiles()) ?? project.profiles.map(\.file)
ForEach(files, id: \.self) { file in
Button(
project.profiles.first(where: { $0.file == file })?.title
?? file
) {
selectConfiguration(file, in: project)
if let project {
if project.type == .cityKeeper {
menuRow("发布配置", value: profile?.title ?? "选择配置文件") {
let files =
(try? project.configurationFiles())
?? project.profiles.map(\.file)
ForEach(files, id: \.self) { file in
Button(
project.profiles.first(where: { $0.file == file })?.title
?? file
) {
selectConfiguration(file, in: project)
}
}
Divider()
Button("浏览其他 YAML…") { browseConfiguration(in: project) }
}
Divider()
Button("浏览其他 YAML…") { browseConfiguration(in: project) }
}
if let profile {
Button("编辑别名与 SSH 目标…") { configurationDraft = profile }
.font(ReleaseTypography.detail)
.buttonStyle(ReleaseButtonStyle())
.disabled(!editable)
}
menuRow(
"服务器",
selection: pane.servers.first(where: { $0.name == pane.server })?
.displayName
?? "选择服务器"
) {
ForEach(pane.servers, id: \.name) { target in
Button(target.displayName) {
pane.server = target.name
model.save()
menuRow(
"服务器",
value: pane.servers.first(where: { $0.name == pane.server })?
.displayName ?? "选择服务器"
) {
ForEach(pane.servers, id: \.name) { target in
Button(target.displayName) {
pane.server = target.name
model.save()
}
}
}
}
}
if project.type == .cityKeeper {
menuRow("Maven", selection: pane.mavenCommand.title) {
ForEach(MavenCommand.allCases) { command in
Button(command.title) {
pane.mavenCommand = command
model.save()
menuRow("Maven", value: pane.mavenCommand.title) {
ForEach(MavenCommand.allCases) { command in
Button(command.title) {
pane.mavenCommand = command
model.save()
}
}
}
HStack(spacing: 12) {
Toggle("VPC", isOn: $pane.useVPC)
if project.supportsVerifiedRelease(profile) {
Toggle("验证发布", isOn: $pane.verified)
Spacer(minLength: 0)
Button("预检") { model.publish(pane, action: .preflight) }
.buttonStyle(ReleaseButtonStyle())
.disabled(!editable || pane.modules.isEmpty)
} else {
Spacer(minLength: 0)
}
if let profile {
Button {
configurationDraft = profile
} label: {
Image(systemName: "slider.horizontal.3")
}
.buttonStyle(ReleaseButtonStyle())
.help("编辑配置别名和 SSH 目标")
.disabled(!editable)
}
}
.toggleStyle(.checkbox)
.font(ReleaseTypography.detail)
.disabled(!editable)
.onChange(of: pane.useVPC) { model.save() }
.onChange(of: pane.verified) { model.save() }
}
}
if project.type == .cityKeeper {
HStack {
Toggle("VPC", isOn: $pane.useVPC)
Text("模块").font(.system(size: 13, weight: .medium))
Spacer()
if project.supportsVerifiedRelease(profile) {
Toggle("验证发布", isOn: $pane.verified)
Button("预检") { model.publish(pane, action: .preflight) }
.disabled(!editable || pane.modules.isEmpty)
.buttonStyle(ReleaseButtonStyle())
}
Text("已选 \(pane.selectedCount) 个")
.foregroundStyle(ReleaseColors.muted)
}
.toggleStyle(.checkbox)
.font(ReleaseTypography.detail)
.disabled(!editable)
.onChange(of: pane.useVPC) { model.save() }
.onChange(of: pane.verified) { model.save() }
}
HStack {
Image(systemName: "magnifyingglass")
.foregroundStyle(ReleaseColors.muted)
TextField("搜索模块", text: $pane.search)
.textFieldStyle(.plain)
if !pane.search.isEmpty {
.padding(.top, 4)
HStack(spacing: 7) {
Image(systemName: "magnifyingglass")
.foregroundStyle(ReleaseColors.muted)
TextField("搜索模块…", text: $pane.search)
.textFieldStyle(.plain)
.onChange(of: pane.search) { showsModules = true }
if !pane.search.isEmpty {
Button {
pane.search = ""
} label: {
Image(systemName: "xmark.circle.fill")
}
.buttonStyle(.plain)
}
Button {
pane.search = ""
showsModules.toggle()
} label: {
Image(systemName: "xmark.circle.fill")
Image(systemName: showsModules ? "chevron.up" : "chevron.down")
}
.buttonStyle(.plain)
.help("选择模块")
}
}
.padding(8)
.background(ReleaseColors.surface, in: RoundedRectangle(cornerRadius: 7))
.disabled(!editable)
.font(ReleaseTypography.body)
.padding(.horizontal, 11)
.frame(height: 35)
.background(ReleaseColors.surface, in: RoundedRectangle(cornerRadius: 7))
.overlay {
RoundedRectangle(cornerRadius: 7).strokeBorder(ReleaseColors.border)
}
.disabled(!editable)
ScrollView {
LazyVStack(spacing: 2) {
ForEach(matches, id: \.self) { module in
Button {
pane.toggle(module)
} label: {
HStack(spacing: 8) {
Image(
systemName: pane.modules.contains(module)
? "checkmark.square.fill" : "square"
)
.foregroundStyle(
pane.modules.contains(module)
? ReleaseColors.blue : ReleaseColors.muted)
Text(module).lineLimit(1)
Spacer()
if showsModules {
ScrollView {
LazyVStack(spacing: 2) {
ForEach(matches, id: \.self) { module in
Button {
pane.toggle(module)
} label: {
HStack(spacing: 8) {
Image(
systemName: pane.modules.contains(module)
? "checkmark.square.fill" : "square"
)
.foregroundStyle(
pane.modules.contains(module)
? ReleaseColors.blue : ReleaseColors.muted)
Text(module).lineLimit(1)
Spacer()
}
.padding(.horizontal, 10)
.frame(height: 29)
}
.buttonStyle(
ReleaseButtonStyle(
base: pane.modules.contains(module)
? ReleaseColors.blue.opacity(0.12) : .clear))
}
if matches.isEmpty {
Text("没有匹配的模块")
.foregroundStyle(ReleaseColors.muted).padding(8)
}
.frame(height: 27)
.padding(.horizontal, 7)
}
.buttonStyle(ReleaseButtonStyle())
.disabled(!editable)
.padding(4)
}
if matches.isEmpty {
Text("没有匹配的模块").foregroundStyle(ReleaseColors.muted).padding(8)
.frame(height: min(112, CGFloat(matches.count) * 31 + 8))
.background(
ReleaseColors.terminal, in: RoundedRectangle(cornerRadius: 7))
}
if !pane.modules.isEmpty {
ScrollView(.horizontal) {
HStack(spacing: 6) {
ForEach(pane.modules, id: \.self) { module in
Button {
pane.toggle(module)
} label: {
HStack(spacing: 5) {
Text(module).lineLimit(1)
Image(systemName: "xmark")
.font(.system(size: 9, weight: .semibold))
}
.font(ReleaseTypography.detail)
.foregroundStyle(ReleaseColors.blue)
.padding(.horizontal, 10)
.frame(height: 27)
.background(
ReleaseColors.blue.opacity(0.15),
in: Capsule())
}
.buttonStyle(.plain)
.disabled(!editable)
}
}
}
.scrollIndicators(.hidden)
.frame(height: 30)
}
}
.frame(height: 78)
.background(ReleaseColors.terminal, in: RoundedRectangle(cornerRadius: 7))
Text("已选 \(pane.selectedCount) 个模块")
.foregroundStyle(ReleaseColors.muted)
.font(ReleaseTypography.detail)
HStack {
Text(paneTitle).font(ReleaseTypography.detail)
Spacer()
if pane.state == .running {
Button(pane.paused ? "继续" : "暂停") { model.togglePause(pane) }
.disabled(pane.stopping)
Button("停止") { model.stop(pane) }
.disabled(pane.stopping)
}
}
.buttonStyle(ReleaseButtonStyle())
.foregroundStyle(ReleaseColors.muted)
LogTextView(
text: pane.log.isEmpty
? (pane.state == .queued ? "等待构建资源…" : "") : pane.log,
errorLine: nil, jumpRequest: 0,
followsOutput: pane.state == .running
)
.frame(height: 150)
.background(ReleaseColors.terminal, in: RoundedRectangle(cornerRadius: 7))
if let result = pane.result {
Button("打开完整日志") {
NSWorkspace.shared.open(model.logURL(for: result))
VStack(spacing: 0) {
HStack {
Text("实时输出 · \(paneTitle)")
.font(.system(size: 12, weight: .medium))
Spacer()
if pane.state == .running {
Button(pane.paused ? "继续" : "暂停") { model.togglePause(pane) }
.disabled(pane.stopping)
Button("停止") { model.stop(pane) }
.disabled(pane.stopping)
}
}
.foregroundStyle(ReleaseColors.muted)
.padding(.horizontal, 11)
.frame(height: 34)
.background(ReleaseColors.surface)
LogTextView(
text: pane.log.isEmpty
? (pane.state == .queued ? "等待构建资源…" : "等待发布,命令和输出将在这里显示。")
: pane.log,
errorLine: nil, jumpRequest: 0,
followsOutput: pane.state == .running
)
.frame(height: 195)
}
.font(ReleaseTypography.detail)
.buttonStyle(ReleaseButtonStyle())
.background(ReleaseColors.terminal, in: RoundedRectangle(cornerRadius: 8))
.clipShape(RoundedRectangle(cornerRadius: 8))
.overlay {
RoundedRectangle(cornerRadius: 8).strokeBorder(ReleaseColors.border)
}
if let result = pane.result {
Button("打开完整日志") {
NSWorkspace.shared.open(model.logURL(for: result))
}
.font(ReleaseTypography.detail)
.buttonStyle(ReleaseButtonStyle())
}
if let issue = pane.error ?? pane.result?.message, !issue.isEmpty {
Text(issue).font(.caption).foregroundStyle(.red).lineLimit(2)
}
}
if let issue = pane.error ?? pane.result?.message, !issue.isEmpty {
Text(issue).font(.caption).foregroundStyle(.red).lineLimit(2)
}
Spacer(minLength: 2)
Button {
model.publish(pane)
} label: {
Text("发布此项目")
.font(ReleaseTypography.action)
.frame(maxWidth: .infinity, minHeight: 33)
}
.disabled(model.isRunning || pane.modules.isEmpty)
.buttonStyle(ReleaseButtonStyle(base: ReleaseColors.surface))
}
.padding(18)
}
Button(action: { model.publish(pane) }) {
Text("发布此项目")
.font(.system(size: 13, weight: .semibold))
.foregroundStyle(editable ? ReleaseColors.blue : ReleaseColors.muted)
.frame(maxWidth: .infinity)
.frame(height: 39)
}
.disabled(model.isRunning || pane.modules.isEmpty)
.buttonStyle(ReleaseButtonStyle())
.overlay {
RoundedRectangle(cornerRadius: 8)
.strokeBorder(editable ? ReleaseColors.blue : ReleaseColors.border)
.allowsHitTesting(false)
}
.padding(13)
.padding(.horizontal, 18)
.padding(.bottom, 18)
}
.frame(height: columnHeight)
.frame(height: height)
.font(ReleaseTypography.body)
.popover(item: $configurationDraft) { draft in
ConfigurationEditor(profile: draft) { updated in
......@@ -339,33 +434,37 @@ private struct ProjectReleaseColumn: View {
private var paneTitle: String {
switch pane.state {
case .idle: return "命令行输出"
case .queued: return "排队中"
case .idle: "等待发布"
case .queued: "排队中"
case .running:
return pane.stopping ? "正在停止" : pane.paused ? "已暂停" : pane.phase?.title ?? "正在发布"
case .skipped: return "未执行"
case .finished: return pane.result?.headline ?? "发布结束"
pane.stopping ? "正在停止" : pane.paused ? "已暂停" : pane.phase?.title ?? "正在发布"
case .skipped: "未执行"
case .finished: pane.result?.headline ?? "发布结束"
}
}
private func menuRow<Content: View>(
_ title: String, selection: String,
_ label: String, value: String,
@ViewBuilder content: () -> Content
) -> some View {
HStack(spacing: 7) {
Text(title).foregroundStyle(ReleaseColors.muted).frame(width: 60, alignment: .leading)
HStack(spacing: 8) {
Text(label).foregroundStyle(ReleaseColors.muted)
.frame(width: 60, alignment: .leading)
Menu(content: content) {
HStack {
Text(selection).lineLimit(1)
Spacer(minLength: 2)
Image(systemName: "chevron.down").font(.system(size: 9))
Text(value).lineLimit(1)
Spacer(minLength: 3)
Image(systemName: "chevron.down").font(.system(size: 10))
}
.padding(.horizontal, 8)
.frame(height: 30)
.background(ReleaseColors.surface, in: RoundedRectangle(cornerRadius: 6))
.padding(.horizontal, 11)
.frame(height: 36)
.frame(maxWidth: .infinity)
.background(ReleaseColors.surface, in: RoundedRectangle(cornerRadius: 7))
.overlay { RoundedRectangle(cornerRadius: 7).strokeBorder(ReleaseColors.border) }
}
.menuStyle(.borderlessButton)
.menuIndicator(.hidden)
.frame(maxWidth: .infinity)
.disabled(!editable)
}
}
......
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