Skip to content

Commit

Permalink
Refactor using new APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunkomath committed Dec 22, 2023
1 parent 0f47478 commit 75b3678
Show file tree
Hide file tree
Showing 12 changed files with 172 additions and 479 deletions.
265 changes: 13 additions & 252 deletions netdata.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@
"revision" : "a4f4267f6454259ba4ed8f9dadb87334a789c26c",
"version" : "1.3.7"
}
},
{
"identity" : "bugsnag-cocoa",
"kind" : "remoteSourceControl",
"location" : "https://github.com/bugsnag/bugsnag-cocoa",
"state" : {
"revision" : "3850d4cd88f3eeabc8fff271a1b08a6a6d4e381a",
"version" : "6.10.2"
}
}
],
"version" : 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<key>netdata.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
<integer>2</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
Expand Down
10 changes: 0 additions & 10 deletions netdata/Core/Data/ServerService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@ import WidgetKit
import os.log

@MainActor class ServerService: ObservableObject, PublicCloudService {

public static var cancellable = Set<AnyCancellable>()

// MARK: - Vars
public static let shared = ServerService()
public static var userCloudKitId: CKRecord.ID?

@Published public var favouriteServers: [NDServer] = []
@Published public var defaultServers: [NDServer] = []
Expand All @@ -31,12 +27,6 @@ import os.log
self.isCloudEnabled = status == .available
}
}

container.fetchUserRecordID { (id, error) in
if (id != nil) {
Self.userCloudKitId = id
}
}
}

public func refresh() async {
Expand Down
5 changes: 0 additions & 5 deletions netdata/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,5 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>bugsnag</key>
<dict>
<key>apiKey</key>
<string>407cac143e35e9fffbe2cf3ee3fd4b2c</string>
</dict>
</dict>
</plist>
41 changes: 21 additions & 20 deletions netdata/Modules/ServerDetail/ServerDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -213,22 +213,6 @@ struct ServerDetailView: View {
}
}
.listStyle(InsetGroupedListStyle())

BottomBar {
NavigationLink(destination: ChartsListView(serverUrl: server.url, basicAuthBase64: server.basicAuthBase64)) {
Label("Charts", systemImage: "chart.pie")
.labelStyle(.titleAndIcon)
}
.padding(.leading)

Spacer()

NavigationLink(destination: AlarmsListView(serverUrl: server.url, basicAuthBase64: server.basicAuthBase64)) {
Label("Alarms", systemImage: "alarm")
.labelStyle(.titleAndIcon)
}
.padding(.trailing)
}
}
.task {
viewModel.baseUrl = server.url
Expand All @@ -239,9 +223,6 @@ struct ServerDetailView: View {
// Start timer
self.timer = Timer.publish(every: 1, on: .main, in: .common)
_ = self.timer.connect()

// hide scroll indicators
UITableView.appearance().showsVerticalScrollIndicator = false
}
.onReceive(timer) { _ in
Task {
Expand All @@ -266,7 +247,7 @@ struct ServerDetailView: View {
}
.navigationBarTitle(server.name)
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
ToolbarItem(placement: .navigation) {
PulsatingView(live: viewModel.isLive)
}

Expand All @@ -279,6 +260,26 @@ struct ServerDetailView: View {
.pickerStyle(.segmented)
}
}

ToolbarItemGroup(placement: .bottomBar) {
NavigationLink(destination: ChartsListView(serverUrl: server.url, basicAuthBase64: server.basicAuthBase64)) {
HStack {
Image(systemName: "chart.pie")
Text("Charts")
}
}
.padding(.leading)

Spacer()

NavigationLink(destination: AlarmsListView(serverUrl: server.url, basicAuthBase64: server.basicAuthBase64)) {
HStack {
Image(systemName: "alarm")
Text("Alarms")
}
}
.padding(.trailing)
}
}
}

Expand Down
22 changes: 14 additions & 8 deletions netdata/Modules/ServerList/Components/AddServerForm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,16 @@ struct AddServerForm: View {
}
.submitLabel(.done)
.navigationBarTitle("Add Server", displayMode: .inline)
.navigationBarItems(leading: dismissButton, trailing: saveButton)
.toolbar {
ToolbarItemGroup(placement: .bottomBar) {
saveButton
Spacer()
}

ToolbarItem(placement: .navigation) {
dismissButton
}
}
}
}

Expand Down Expand Up @@ -106,16 +115,13 @@ struct AddServerForm: View {
await addServer()
}
}) {
if (viewModel.validatingUrl) {
ProgressView()
} else {
HStack {
Image(systemName: "plus.circle.fill")
Text("Add")
.font(.subheadline)
.bold()
.foregroundColor(.accentColor)
.fontWeight(.bold)
}
}
.buttonStyle(BorderedBarButtonStyle())
.disabled(viewModel.validatingUrl)
.alert(isPresented: $viewModel.invalidUrlAlert) {
Alert(title: Text("Oops!"), message: Text("You've entered an invalid URL"), dismissButton: .default(Text("OK")))
}
Expand Down
173 changes: 68 additions & 105 deletions netdata/Modules/ServerList/ServerListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,118 +23,98 @@ final class ServerListActiveSheet: ObservableObject {
}

struct ServerListView: View {
@EnvironmentObject private var serverService: ServerService
@EnvironmentObject var serverService: ServerService

@ObservedObject var userSettings = UserSettings()
@ObservedObject var activeSheet = ServerListActiveSheet()

var body: some View {
NavigationView {
VStack(spacing: 0) {
List {
if !self.serverService.isCloudEnabled && !serverService.isSynching {
ErrorMessage(message: "iCloud not enabled, you need an iCloud account to view / add servers")
}

if let error = self.serverService.mostRecentError {
ErrorMessage(message: error.localizedDescription)
}

if serverService.isSynching && serverService.defaultServers.isEmpty && serverService.favouriteServers.isEmpty {
ForEach((1...4), id: \.self) { _ in
Group {
VStack(alignment: .leading, spacing: 5) {
Text("name")
.font(.headline)
Text("description")
.font(.subheadline)
.foregroundColor(.gray)
}
.redacted(reason: .placeholder)
}
.padding(8)
}
} else {
if !serverService.favouriteServers.isEmpty {
Section("Favourites") {
ForEach(serverService.favouriteServers) { server in
ServerListRow(server: server)
}
.onDelete(perform: self.deleteFavouriteServer)
VStack(spacing: 0) {
List {
if !self.serverService.isCloudEnabled && !serverService.isSynching {
ErrorMessage(message: "iCloud not enabled, you need an iCloud account to view / add servers")
}

if let error = self.serverService.mostRecentError {
ErrorMessage(message: error.localizedDescription)
}

if serverService.isSynching && serverService.defaultServers.isEmpty && serverService.favouriteServers.isEmpty {
ForEach((1...4), id: \.self) { _ in
Group {
VStack(alignment: .leading, spacing: 5) {
Text("name")
.font(.headline)
Text("description")
.font(.subheadline)
.foregroundColor(.gray)
}
.headerProminence(.increased)
.redacted(reason: .placeholder)
}

Section("Servers") {
ForEach(serverService.defaultServers) { server in
.padding(8)
}
} else {
if !serverService.favouriteServers.isEmpty {
Section("Favourites") {
ForEach(serverService.favouriteServers) { server in
ServerListRow(server: server)
}
.onDelete(perform: self.deleteServer)
.onDelete(perform: self.deleteFavouriteServer)
}
.headerProminence(.increased)
}
}
.listStyle(.insetGrouped)

BottomBar {
Menu {
Link("Report an issue", destination: URL(string: "https://github.com/arjunkomath/netdata-ios/issues")!)
Link("Q&A", destination: URL(string: "https://github.com/arjunkomath/netdata-ios/discussions/categories/q-a")!)
} label: {
Label("Support", systemImage: "lifepreserver.fill")
.padding(.leading)
}

Spacer()

addButton
.padding(.trailing)
}
}
.ifNotMacCatalyst { view in
view.refreshable {
await serverService.refresh()
Section("Servers") {
ForEach(serverService.defaultServers) { server in
ServerListRow(server: server)
}
.onDelete(perform: self.deleteServer)
}
.headerProminence(.increased)
}
}
.listStyle(.insetGrouped)
.sheet(isPresented: self.$activeSheet.showSheet, content: { self.sheet })
.toolbar {
ToolbarItemGroup(placement: .navigationBarLeading) {
settingsButton
}
}
.task {
await serverService.refresh()

// show welcome screen
if !userSettings.HasLaunchedOnce {
userSettings.HasLaunchedOnce = true
self.activeSheet.kind = .welcome
}
.navigationTitle("My Servers")
.task {
}
.ifNotMacCatalyst { view in
view.refreshable {
await serverService.refresh()
// hide scroll indicators
UITableView.appearance().showsVerticalScrollIndicator = false
// show welcome screen
if !userSettings.HasLaunchedOnce {
userSettings.HasLaunchedOnce = true
self.activeSheet.kind = .welcome
}
}
.toolbar {
ToolbarItemGroup(placement: .navigation) {
Button(action: {
self.activeSheet.kind = .settings
}) {
Label("Settings", systemImage: "gearshape")
}
}

VStack {
if serverService.defaultServers.isEmpty && serverService.favouriteServers.isEmpty {
Image(systemName: "tray")
.imageScale(.large)
.frame(width: 48, height: 48)

Button(action: {
self.addServer()
}) {
Text("Add Netdata server")
ToolbarItemGroup(placement: .bottomBar) {
Button(action: {
self.addServer()
}) {
HStack {
Image(systemName: "externaldrive.badge.plus")
Text("Add")
}
.buttonStyle(BorderedBarButtonStyle())
} else {
Image(systemName: "tray")
.imageScale(.large)
.frame(width: 48, height: 48)
Text("Select a server")
}

Spacer()

SupportOptions()
}
}
.navigationTitle("My Servers")
}

func addServer() {
Expand All @@ -153,23 +133,6 @@ struct ServerListView: View {
self.serverService.delete(server: serverService.favouriteServers[offsets.first!])
}

private var addButton: some View {
Button(action: {
self.addServer()
}) {
Label("Add", systemImage: "externaldrive.badge.plus")
.labelStyle(.titleAndIcon)
}
}

private var settingsButton: some View {
Button(action: {
self.activeSheet.kind = .settings
}) {
Label("Settings", systemImage: "gear")
}
}

@ViewBuilder
private var sheet: some View {
switch activeSheet.kind {
Expand Down
Loading

0 comments on commit 75b3678

Please sign in to comment.