Fix exporting of large files in overhead allocation
This commit is contained in:
@@ -12,7 +12,6 @@
|
||||
5A1986FB2996502C00FA0471 /* FileButtonSelector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A1986FA2996502C00FA0471 /* FileButtonSelector.swift */; };
|
||||
5A450751298CE6D500E3D402 /* CsvDocument.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A450750298CE6D500E3D402 /* CsvDocument.swift */; };
|
||||
5A45075B298D01EF00E3D402 /* libcoster_rs.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5A45075A298D01EF00E3D402 /* libcoster_rs.a */; };
|
||||
5A4995C829BC423900A1A107 /* TempFileDocument.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A4995C729BC423900A1A107 /* TempFileDocument.swift */; };
|
||||
5ADD9F2D298A713300F998F5 /* FastCosterApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5ADD9F2C298A713300F998F5 /* FastCosterApp.swift */; };
|
||||
5ADD9F2F298A713300F998F5 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5ADD9F2E298A713300F998F5 /* ContentView.swift */; };
|
||||
5ADD9F31298A713400F998F5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5ADD9F30298A713400F998F5 /* Assets.xcassets */; };
|
||||
@@ -49,7 +48,6 @@
|
||||
5A450755298CFFE400E3D402 /* create-lib.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = "create-lib.sh"; sourceTree = "<group>"; };
|
||||
5A450756298D00AE00E3D402 /* remove-lib.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = "remove-lib.sh"; sourceTree = "<group>"; };
|
||||
5A45075A298D01EF00E3D402 /* libcoster_rs.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libcoster_rs.a; path = "../costerrs/target/aarch64-apple-ios/release/libcoster_rs.a"; sourceTree = "<group>"; };
|
||||
5A4995C729BC423900A1A107 /* TempFileDocument.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TempFileDocument.swift; sourceTree = "<group>"; };
|
||||
5ADD9F29298A713300F998F5 /* FastCoster.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FastCoster.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
5ADD9F2C298A713300F998F5 /* FastCosterApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FastCosterApp.swift; sourceTree = "<group>"; };
|
||||
5ADD9F2E298A713300F998F5 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
|
||||
@@ -142,7 +140,6 @@
|
||||
5A1986F62996436500FA0471 /* OverheadAllocation.swift */,
|
||||
5A1986F82996436D00FA0471 /* MoveMoney.swift */,
|
||||
5A1986FA2996502C00FA0471 /* FileButtonSelector.swift */,
|
||||
5A4995C729BC423900A1A107 /* TempFileDocument.swift */,
|
||||
);
|
||||
path = FastCoster;
|
||||
sourceTree = "<group>";
|
||||
@@ -351,7 +348,6 @@
|
||||
5A1986F92996436D00FA0471 /* MoveMoney.swift in Sources */,
|
||||
5ADD9F2D298A713300F998F5 /* FastCosterApp.swift in Sources */,
|
||||
5A450751298CE6D500E3D402 /* CsvDocument.swift in Sources */,
|
||||
5A4995C829BC423900A1A107 /* TempFileDocument.swift in Sources */,
|
||||
5A1986F72996436500FA0471 /* OverheadAllocation.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
|
||||
@@ -13,12 +13,10 @@ struct OverheadAllocation: View {
|
||||
@State private var areas: String?
|
||||
@State private var allocationStatistics: String?
|
||||
@State private var costCentres: String?
|
||||
@State private var showExportPicker = false
|
||||
@State private var document: TempFileDocument?
|
||||
@State private var showMovePicker = false
|
||||
@State private var accountType = "E"
|
||||
@State private var show_from = false
|
||||
|
||||
private let tempPath = FileManager.default.temporaryDirectory.appendingPathComponent("OverheadAllocation.csv", conformingTo: .commaSeparatedText)
|
||||
@State private var showFrom = false
|
||||
@State private var tempPath: URL?;
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
@@ -38,7 +36,7 @@ struct OverheadAllocation: View {
|
||||
costCentres = result
|
||||
}
|
||||
TextField("Account Type", text: $accountType)
|
||||
Toggle(isOn: $show_from) {
|
||||
Toggle(isOn: $showFrom) {
|
||||
Text("Show from cc movements")
|
||||
}
|
||||
Button {
|
||||
@@ -46,34 +44,31 @@ struct OverheadAllocation: View {
|
||||
} label: {
|
||||
Text("Allocate Overheads")
|
||||
}.padding()
|
||||
.fileExporter(isPresented: $showExportPicker, document: document, contentType: .commaSeparatedText) { result in
|
||||
|
||||
.fileMover(isPresented: $showMovePicker, file: tempPath) { result in
|
||||
if case .success = result {
|
||||
do {
|
||||
try FileManager.default.removeItem(at: tempPath)
|
||||
try FileManager.default.removeItem(at: tempPath!)
|
||||
} catch {
|
||||
|
||||
}
|
||||
}else {
|
||||
|
||||
print(result)
|
||||
}
|
||||
|
||||
}
|
||||
}.padding()
|
||||
.textFieldStyle(.roundedBorder)
|
||||
}
|
||||
|
||||
func allocate_overheads() {
|
||||
tempPath = FileManager.default.temporaryDirectory.appendingPathComponent("OverheadAllocation.csv", conformingTo: .commaSeparatedText)
|
||||
// Cut off file://
|
||||
// TODO: There has to be a better way to do string slicing right?
|
||||
let tempPathString = String(tempPath!.absoluteString.dropFirst(7))
|
||||
DispatchQueue.global(qos: .userInitiated).async {
|
||||
// Cut off file://
|
||||
// TODO: There has to be a better way to do string slicing right?
|
||||
let tempPathString = String(tempPath.absoluteString.dropFirst(7))
|
||||
|
||||
allocate_overheads_from_text_to_file(lines, accounts, allocationStatistics, areas, costCentres, accountType, tempPathString, false, show_from)
|
||||
allocate_overheads_from_text_to_file(lines, accounts, allocationStatistics, areas, costCentres, accountType, tempPathString, false, showFrom)
|
||||
|
||||
DispatchQueue.main.async {
|
||||
document = TempFileDocument(url: tempPath)
|
||||
showExportPicker = true;
|
||||
showMovePicker = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
//
|
||||
// TempFileDocument.swift
|
||||
// FastCoster
|
||||
//
|
||||
// Created by Michael Pivato on 11/3/2023.
|
||||
//
|
||||
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
import UniformTypeIdentifiers
|
||||
|
||||
struct TempFileDocument: FileDocument {
|
||||
var tempFileUrl: URL?
|
||||
var wrapper: FileWrapper?
|
||||
|
||||
static var readableContentTypes: [UTType] {[.commaSeparatedText]}
|
||||
|
||||
init(configuration: ReadConfiguration) throws {
|
||||
wrapper = configuration.file
|
||||
}
|
||||
|
||||
init(url: URL) {
|
||||
tempFileUrl = url
|
||||
}
|
||||
|
||||
func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper {
|
||||
return try wrapper ?? FileWrapper(url: tempFileUrl!)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -45,7 +45,7 @@ pub extern "C" fn move_money_from_text(
|
||||
&mut csv::Reader::from_reader(safe_cost_centres.to_bytes()),
|
||||
&mut output_writer,
|
||||
use_numeric_accounts,
|
||||
true,
|
||||
false,
|
||||
)
|
||||
.expect("Failed to move money");
|
||||
// TODO: Replace all these unwraps with something more elegant
|
||||
|
||||
Reference in New Issue
Block a user