Commit d59d269a authored by  Joel  Oksanen's avatar Joel Oksanen

Cleaned up frontend code

parent f66016af
{
"images" : [
{
"idiom" : "universal",
"filename" : "star_border.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "star_fill.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
//
// Product.swift
// ProductInfo.swift
// ADAbot
//
// Created by Joel Oksanen on 23.2.2020.
......
......@@ -22,7 +22,7 @@ struct ProductView: View {
VStack {
Spacer()
HStack(alignment: .top) {
VStack {
VStack(alignment: .leading) {
Text(connectionManager.product.name)
.font(Font.custom("Helvetica Neue", size: 14))
.foregroundColor(Color.gray)
......@@ -40,6 +40,6 @@ struct ProductView: View {
.frame(height: height)
}
}
}
......@@ -7,15 +7,37 @@
objects = {
/* Begin PBXBuildFile section */
94467A1E2495119100E61CF8 /* ProductView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94467A1D2495119100E61CF8 /* ProductView.swift */; };
94467A202495127C00E61CF8 /* ProductInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94467A1F2495127C00E61CF8 /* ProductInfo.swift */; };
94467A222495128700E61CF8 /* Product.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94467A212495128700E61CF8 /* Product.swift */; };
94467A24249512A100E61CF8 /* ProductData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94467A23249512A100E61CF8 /* ProductData.swift */; };
94467A262495132000E61CF8 /* RatingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94467A252495132000E61CF8 /* RatingView.swift */; };
9466F4462494F1A40035B8B6 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9466F4452494F1A40035B8B6 /* AppDelegate.swift */; };
9466F4482494F1A40035B8B6 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9466F4472494F1A40035B8B6 /* SceneDelegate.swift */; };
9466F44A2494F1A40035B8B6 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9466F4492494F1A40035B8B6 /* ContentView.swift */; };
9466F44C2494F1A80035B8B6 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9466F44B2494F1A80035B8B6 /* Assets.xcassets */; };
9466F44F2494F1A80035B8B6 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9466F44E2494F1A80035B8B6 /* Preview Assets.xcassets */; };
9466F4522494F1A80035B8B6 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9466F4502494F1A80035B8B6 /* LaunchScreen.storyboard */; };
9466F47E2494FE320035B8B6 /* EdgeMapView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9466F4702494FE320035B8B6 /* EdgeMapView.swift */; };
9466F47F2494FE320035B8B6 /* MapView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9466F4712494FE320035B8B6 /* MapView.swift */; };
9466F4802494FE320035B8B6 /* EdgeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9466F4722494FE320035B8B6 /* EdgeView.swift */; };
9466F4812494FE320035B8B6 /* NodeMapView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9466F4732494FE320035B8B6 /* NodeMapView.swift */; };
9466F4822494FE320035B8B6 /* SurfaceView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9466F4742494FE320035B8B6 /* SurfaceView.swift */; };
9466F4832494FE320035B8B6 /* NodeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9466F4752494FE320035B8B6 /* NodeView.swift */; };
9466F4852494FE320035B8B6 /* Graph.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9466F4782494FE320035B8B6 /* Graph.swift */; };
9466F4862494FE320035B8B6 /* SelectionHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9466F4792494FE320035B8B6 /* SelectionHandler.swift */; };
9466F4872494FE320035B8B6 /* Edge.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9466F47A2494FE320035B8B6 /* Edge.swift */; };
9466F4892494FE320035B8B6 /* Node.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9466F47C2494FE320035B8B6 /* Node.swift */; };
9466F48F2494FED40035B8B6 /* ConnectionManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9466F48E2494FED40035B8B6 /* ConnectionManager.swift */; };
9466F4912494FF140035B8B6 /* Argument.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9466F4902494FF130035B8B6 /* Argument.swift */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
94467A1D2495119100E61CF8 /* ProductView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ProductView.swift; path = ../../ADAbot/ADAbot/Product/ProductView.swift; sourceTree = "<group>"; };
94467A1F2495127C00E61CF8 /* ProductInfo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ProductInfo.swift; path = ../../ADAbot/ADAbot/Product/ProductInfo.swift; sourceTree = "<group>"; };
94467A212495128700E61CF8 /* Product.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Product.swift; path = ../../ADAbot/ADAbot/Product/Product.swift; sourceTree = "<group>"; };
94467A23249512A100E61CF8 /* ProductData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductData.swift; sourceTree = "<group>"; };
94467A252495132000E61CF8 /* RatingView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = RatingView.swift; path = ../../ADAbot/ADAbot/Product/RatingView.swift; sourceTree = "<group>"; };
9466F4422494F1A40035B8B6 /* ADAgraph.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ADAgraph.app; sourceTree = BUILT_PRODUCTS_DIR; };
9466F4452494F1A40035B8B6 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
9466F4472494F1A40035B8B6 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
......@@ -24,6 +46,18 @@
9466F44E2494F1A80035B8B6 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
9466F4512494F1A80035B8B6 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
9466F4532494F1A80035B8B6 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
9466F4702494FE320035B8B6 /* EdgeMapView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EdgeMapView.swift; sourceTree = "<group>"; };
9466F4712494FE320035B8B6 /* MapView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MapView.swift; sourceTree = "<group>"; };
9466F4722494FE320035B8B6 /* EdgeView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EdgeView.swift; sourceTree = "<group>"; };
9466F4732494FE320035B8B6 /* NodeMapView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NodeMapView.swift; sourceTree = "<group>"; };
9466F4742494FE320035B8B6 /* SurfaceView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SurfaceView.swift; sourceTree = "<group>"; };
9466F4752494FE320035B8B6 /* NodeView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NodeView.swift; sourceTree = "<group>"; };
9466F4782494FE320035B8B6 /* Graph.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Graph.swift; sourceTree = "<group>"; };
9466F4792494FE320035B8B6 /* SelectionHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SelectionHandler.swift; sourceTree = "<group>"; };
9466F47A2494FE320035B8B6 /* Edge.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Edge.swift; sourceTree = "<group>"; };
9466F47C2494FE320035B8B6 /* Node.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Node.swift; sourceTree = "<group>"; };
9466F48E2494FED40035B8B6 /* ConnectionManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConnectionManager.swift; sourceTree = "<group>"; };
9466F4902494FF130035B8B6 /* Argument.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Argument.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
......@@ -56,9 +90,18 @@
9466F4442494F1A40035B8B6 /* ADAgraph */ = {
isa = PBXGroup;
children = (
9466F48E2494FED40035B8B6 /* ConnectionManager.swift */,
9466F4902494FF130035B8B6 /* Argument.swift */,
94467A1D2495119100E61CF8 /* ProductView.swift */,
94467A252495132000E61CF8 /* RatingView.swift */,
94467A23249512A100E61CF8 /* ProductData.swift */,
94467A1F2495127C00E61CF8 /* ProductInfo.swift */,
94467A212495128700E61CF8 /* Product.swift */,
9466F4452494F1A40035B8B6 /* AppDelegate.swift */,
9466F4472494F1A40035B8B6 /* SceneDelegate.swift */,
9466F4492494F1A40035B8B6 /* ContentView.swift */,
9466F4772494FE320035B8B6 /* Model */,
9466F46F2494FE320035B8B6 /* Views */,
9466F44B2494F1A80035B8B6 /* Assets.xcassets */,
9466F4502494F1A80035B8B6 /* LaunchScreen.storyboard */,
9466F4532494F1A80035B8B6 /* Info.plist */,
......@@ -75,6 +118,32 @@
path = "Preview Content";
sourceTree = "<group>";
};
9466F46F2494FE320035B8B6 /* Views */ = {
isa = PBXGroup;
children = (
9466F4702494FE320035B8B6 /* EdgeMapView.swift */,
9466F4712494FE320035B8B6 /* MapView.swift */,
9466F4722494FE320035B8B6 /* EdgeView.swift */,
9466F4732494FE320035B8B6 /* NodeMapView.swift */,
9466F4742494FE320035B8B6 /* SurfaceView.swift */,
9466F4752494FE320035B8B6 /* NodeView.swift */,
);
name = Views;
path = ../../../RazeMindApp/final/RazeMind/Views;
sourceTree = "<group>";
};
9466F4772494FE320035B8B6 /* Model */ = {
isa = PBXGroup;
children = (
9466F4782494FE320035B8B6 /* Graph.swift */,
9466F4792494FE320035B8B6 /* SelectionHandler.swift */,
9466F47A2494FE320035B8B6 /* Edge.swift */,
9466F47C2494FE320035B8B6 /* Node.swift */,
);
name = Model;
path = ../../../RazeMindApp/final/RazeMind/Model;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
......@@ -146,9 +215,26 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
9466F4822494FE320035B8B6 /* SurfaceView.swift in Sources */,
94467A24249512A100E61CF8 /* ProductData.swift in Sources */,
9466F4912494FF140035B8B6 /* Argument.swift in Sources */,
9466F4862494FE320035B8B6 /* SelectionHandler.swift in Sources */,
9466F4852494FE320035B8B6 /* Graph.swift in Sources */,
9466F4812494FE320035B8B6 /* NodeMapView.swift in Sources */,
9466F4462494F1A40035B8B6 /* AppDelegate.swift in Sources */,
94467A262495132000E61CF8 /* RatingView.swift in Sources */,
9466F4872494FE320035B8B6 /* Edge.swift in Sources */,
9466F4892494FE320035B8B6 /* Node.swift in Sources */,
9466F4482494F1A40035B8B6 /* SceneDelegate.swift in Sources */,
9466F47F2494FE320035B8B6 /* MapView.swift in Sources */,
9466F4832494FE320035B8B6 /* NodeView.swift in Sources */,
94467A202495127C00E61CF8 /* ProductInfo.swift in Sources */,
9466F48F2494FED40035B8B6 /* ConnectionManager.swift in Sources */,
9466F4802494FE320035B8B6 /* EdgeView.swift in Sources */,
94467A1E2495119100E61CF8 /* ProductView.swift in Sources */,
9466F47E2494FE320035B8B6 /* EdgeMapView.swift in Sources */,
9466F44A2494F1A40035B8B6 /* ContentView.swift in Sources */,
94467A222495128700E61CF8 /* Product.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
uuid = "11A410FC-B942-445D-A528-1528513D8B56"
type = "1"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "1F83A6A4-50AC-4AC0-BAB3-7B81A2CFDDAE"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "ADAgraph/AppDelegate.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "16"
endingLineNumber = "16"
landmarkName = "application(_:didFinishLaunchingWithOptions:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
......@@ -11,8 +11,6 @@ import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
......
......@@ -7,3 +7,42 @@
//
import Foundation
import SwiftUI
struct Argument: Decodable, Equatable {
let text: String
let polarity: Polarity
let supporters: [Argument]
let attackers: [Argument]
let phrase: String
let size: CGFloat
static func == (lhs: Argument, rhs: Argument) -> Bool {
return lhs.text == rhs.text
}
func children() -> [Argument] {
return supporters + attackers
}
func hasChild() -> Bool {
return children().count > 0
}
func color() -> Color {
return polarity == .POS ? Color(red: 121/255, green: 197/255, blue: 88/255) : Color(red: 220/255, green: 86/255, blue: 72/255)
}
func strokeColor() -> Color {
return polarity == .POS ? Color(red: 90/255, green: 150/255, blue: 60/255) : Color(red: 180/255, green: 65/255, blue: 56/255)
}
}
enum Polarity: String, Decodable {
case POS
case NEG
}
......@@ -6,4 +6,53 @@
// Copyright © 2020 Joel Oksanen. All rights reserved.
//
import Foundation
import SwiftUI
class ConnectionManager: ObservableObject {
@Published var graph: Graph!
@Published var product: Product!
private let ip = "192.168.1.104"
private let port = "8000"
init() {
requestArguments(id: "B0000TIKK8")
}
private func requestArguments(id: String) {
let url = URL(string: "http://" + ip + ":" + port + "/ios_server/arguments?id=" + id)!
let task = URLSession.shared.dataTask(with: url) {(data, response, error) in
guard let data = data else { return }
do {
let resp = try JSONDecoder().decode(ProductData.self, from: data)
DispatchQueue.main.async {
self.graph = Graph.fromRoot(resp.root)
print(resp)
self.requestImage(for: resp.info)
}
} catch let parseError {
print(parseError)
DispatchQueue.main.async {
// Handle error in UI
}
}
}
task.resume()
}
private func requestImage(for productInfo: ProductInfo) {
let url = URL(string: productInfo.imageURL)!
let task = URLSession.shared.dataTask(with: url) {(data, response, error) in
guard let data = data else { return }
if let image = UIImage(data: data) {
DispatchQueue.main.async {
self.product = Product(id: productInfo.id, name: productInfo.name, starRating: productInfo.starRating, image: image)
}
}
}
task.resume()
}
}
......@@ -9,13 +9,16 @@
import SwiftUI
struct ContentView: View {
var body: some View {
Text("Hello, World!")
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
@ObservedObject var connectionManager: ConnectionManager
@ObservedObject var selection: SelectionHandler
var body: some View {
VStack {
if connectionManager.graph != nil && connectionManager.product != nil {
SurfaceView(graph: connectionManager.graph, selection: selection, connectionManager: connectionManager)
} else {
Text("Loading arguments...")
}
}
}
}
......@@ -7,3 +7,10 @@
//
import Foundation
struct ProductData: Decodable {
let root: Argument
let info: ProductInfo
}
......@@ -13,6 +13,8 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
@Published var connectionManager = ConnectionManager()
@Published var selection = SelectionHandler()
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
......@@ -20,7 +22,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
// Create the SwiftUI view that provides the window contents.
let contentView = ContentView()
let contentView = ContentView(connectionManager: connectionManager, selection: selection)
// Use a UIHostingController as window root view controller.
if let windowScene = scene as? UIWindowScene {
......
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