Skip to content

Commit

Permalink
Feature/g drive (#171)
Browse files Browse the repository at this point in the history
* implementing google sdk

* Move dissmiss views to resetApp function

* add selected type of drive connection view

* add SelectSharedDrive view

* mock shared drives

* create drive folder view

* basic implemantation of d-drive library

* re-use successLoginView

* navigate from select shared drive to success

* final tweaks

* move google signIn to next button

* refactor buttonViews function in serverSelection class

* move gDrive login logic to separate function

* create gDrive repository and update view models

* add gdrive url to TellaURL list

* add isValid constraint when creating a folder in gDrive

* fix hardcoded strings, add space to VStacks and overall refactor

* add serverConnectinoType extension for successLoginView

* add domain model for shared drives

* add combine in gDriveRepository

* add combine to the rest of the gDrive endpoints

* remove toast if user is not authenticated

* add async await for gDrive methods

* implementing google sdk

* basic implemantation of d-drive library

* final tweaks

* add isValid constraint when creating a folder in gDrive

* implementing google sdk

* basic implemantation of d-drive library

* create folder in g-drive

* save server connection

* save shared drive connection and remove edit option from gDrive connection item

* some fixes after rebase

* refactor folder creation logic

* fix rebase conflicts

* disable gDrive connection if is already connected

* fix rebase conflicts

* fix create folder and remove token if the user remove a gDrive connection

* fix issues after rebase with develop

* add navbar to gDrive views

* add translations

* remove void from async auth function in gDrive repository

* refactor sharedDriveView

* move selected shared drive action to vm

* add state manager to shared drive view model

* add state management in create folder

* move viewModelState into a separate file

* fix issue in server selection

* move restoreSignIn to a private method inside the repository

* add no token error localization

* apply DI to gDriveRepository

* move mimeTypes to constants

* some refactors on gDriveSeverViewModel and state management

* change state management on gDriveAuthVM

* change onChange for onReceive

* Update Toast display

* add drive to homeView

* add pageView navigation inside gDriveView

* add title and description to gDriveDraftView

* create folder inside the root folder

* fix to supports all drives

* create report folder with title and description

* add files to GDrive report

* create unify draft view

* create a general baseReportsViewModel to handle list item navigation

* add isValid constraint to GDriveDraftVM

* save gDrive draft report

* Fix server subclassing (#165)

* Fix server subclassing

* Initialize allowMultiple to false

* create base report class and get GDrive drafts

* add gDriveList and show files saved in draft

* Remove accessToken from Webserver

* Create reusable report component

* update and delete draft report

* save outbox and submitted report

* fix UI bug on connection view and merge with latest draft changes

* Fix PR comments

* Update report id

* make report to conform with reusable report component

* make gDriveViewModel to conform with reportMainViewModel

* Remove unused code

* refactor tellaData and fix navigation between cells

* add DraftMainViewModel

* add server list menu on draft view

* Update Report classes

* Add serverId to BaseReport

* create OutboxMainVM

* add GDriveOutboxVM

* add submitMainViewModel and implement it on tella reports and drive reports

* Update ReportFile class,  Move redundant functions to DraftMainViewModel

* track progress update on gDrive

* show proper status of uploading

* add folderId to gDriveReport

* implement pause and resume

* add queue to send files sequentially

* persist outbox files progress

* prevent duplicated files

* fix no root folder error

* show offline error when is not connected to internet

* Centralise updateProgressInfos in OutboxMainViewModel

* fix drive encoding when adding and updating drive reports

* only update files when tracking progress

* Remove unused code

* Centralise fillReportVM function in SubmittedMainViewModel class

* Refactor code to start uploading report from draft

* fix duplicated files issue in shared drive and fix some bugs

* remove everything related to drive server after deleting the connection

* fix UI errors

* change client id and add navigation fix

* organize files and folder structure

* add remaining localizable strings

* pause submission when app enter bg mode or user exit the app

* fix localizable issues

* improve sign in state on GDriveAuthVM

* remove environmentObjects for mainAppModel

* fix wording for page component

* remove BaseReportsVM

* rename reportMainViewModel to ReportsMainViewModel

* remove EnvironmentObject from AddFilesToDraftView

* add debounceInterval to pause/resume to prevent app crashes

* fix design feedback

* fix localizableSettings format

* remove unused error

* fix connection item title and change db version

* add some fixes to deleteServerTexts

* fix localizable strings

* change disabling button to isValid in outbox details

* hotfix for large files

* remove server protocol and replace print for debugLog

* remove generic from draft report

* remove drive report files when deleting a report

* add missing localizable strings

* move Components/connections to CommonConnectionReport

* simplify serverArray logic in HomeView

* add struct for simplifying upload file function params

* add new initializer to ReportFile class

* remove server from driveOutboxVM

* move processing of vault files to parent method

* refactor initializers in reportViewModel

* fix thread issues in pause/resume

* remove environmentObject

* remove report initializaiton in submitReport method on tellaweb

* remove isUploading from drive repository

* small fix in submitReport method for google drive

* convert fileURL method into an asynchronous operation

* check if drive upload queue is empty before removing an item

* refactor drive errors

* add rest of localizable errors

* add folder name to driveserver

* change db version to apply folder name changes

* preven duplicated folder name

* Allow only one instace of Uwazi (#172)

* rollback to db version 6

* remove hardcoded client id and fix logical error in server list

* fix bug in uwazi card

* Add TellaConfig

* Refactor APIError errorMessage, remove optionnal message

* Remove unused code

* more fixes

* update g-drive server

* fix edge case in drive server connection

* refactor errors in gDrive

* refactor errors

* parse auth drive error as APIError

* remove TellaConfig

* re create tella config file

* add tella config to project configuration

* Select server view : Fix next button action (#176)

* Fix next button action

* Fix next button action

---------

Co-authored-by: gus valbuena <[email protected]>
Co-authored-by: Dhekra Rouatbi <[email protected]>
Co-authored-by: gus valbuena <[email protected]>
Co-authored-by: rimKtarii <[email protected]>
Co-authored-by: dhekra-rouatbi <[email protected]>
Co-authored-by: Rimktarii <[email protected]>
  • Loading branch information
7 people authored Aug 28, 2024
1 parent 8db8475 commit 46eee6f
Show file tree
Hide file tree
Showing 123 changed files with 4,908 additions and 1,799 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,5 @@ iOSInjectionProject/
!*.xcodeproj/project.pbxproj
!*.xcodeproj/xcshareddata
.idea

Tella/Supporting Files/TellaConfig.xcconfig
4 changes: 3 additions & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ target 'Tella' do
pod 'SQLCipher', ">= 4.5.2"
pod 'ZIPFoundation'
pod 'Mantis', '~> 2.21.0'

pod 'GoogleSignIn'
pod 'GoogleAPIClientForREST/Drive'

target 'TellaTests' do
inherit! :search_paths
# Pods for testing
Expand Down
398 changes: 333 additions & 65 deletions Tella.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Tella/Application/TellaApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ struct TellaApp: App {
UIApplication.getTopViewController()?.dismiss(animated: false)
self.saveData(lockApptype: .enterInBackground)
case .active:
UIApplication.getTopViewController()?.dismiss(animated: false)
self.resetApp()
case .inactive:
appViewState.homeViewModel.shouldShowSecurityScreen = true
Expand Down Expand Up @@ -72,7 +71,8 @@ struct TellaApp: App {
let shouldResetApp = appViewState.homeViewModel.shouldResetApp()

if shouldResetApp && appEnterInBackground && !hasFileOnBackground {

UIApplication.getTopViewController()?.dismiss(animated: false)

DispatchQueue.main.async {
appViewState.shouldHidePresentedView = true
appViewState.resetApp()
Expand Down
12 changes: 8 additions & 4 deletions Tella/Components/NavigationHeaderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,25 @@ import SwiftUI

enum NavigationType {
case save
case draft
case validate
case reload
case none
case delete

var imageName: String {
switch self {
case .save: return "reports.save"
case .draft: return "reports.save"
case .validate: return "report.select-files"
case .reload: return "arrow.clockwise"
case .delete: return "report.delete-outbox"
case .none: return ""
case .none, .save: return ""
}
}

var backButtonIcon: String {
switch self {
case .save: return "close"
case .save, .draft: return "close"
default: return "back"
}
}
Expand All @@ -40,13 +41,14 @@ struct NavigationHeaderView: View {
var rightButtonAction: (() -> Void)?
var title: String = ""
var type: NavigationType
var isRightButtonEnabled: Bool = true

var body: some View {
HStack(spacing: 0) {
backButton
headerTitleView
Spacer()
if(type != .none) {
if(!type.imageName.isEmpty) {
rightButton
}
}.frame(height: 56)
Expand Down Expand Up @@ -78,7 +80,9 @@ struct NavigationHeaderView: View {
Image(type.imageName)
.resizable()
.frame(width: 24, height: 24)
.opacity(isRightButtonEnabled ? 1 : 0.4)
}
.disabled(!isRightButtonEnabled)
}
}

Expand Down
32 changes: 32 additions & 0 deletions Tella/Components/ServerConnectionHeaderView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// ServerConnectionHeaderView.swift
// Tella
//
// Created by gus valbuena on 5/29/24.
// Copyright © 2024 HORIZONTAL. All rights reserved.
//

import SwiftUI

struct ServerConnectionHeaderView: View {
var title: String
var subtitle: String
var body: some View {
VStack(spacing: 8) {
Image("gdrive.icon")
.padding(.bottom, 16)
Text(title)
.font(.custom(Styles.Fonts.semiBoldFontName, size: 18))
.foregroundColor(.white)
.multilineTextAlignment(.center)
Text(subtitle)
.font(.custom(Styles.Fonts.regularFontName, size: 14))
.foregroundColor(.white)
.multilineTextAlignment(.center)
}.padding(.horizontal, 20)
}
}

#Preview {
ServerConnectionHeaderView(title: "title", subtitle: "subtitle")
}
6 changes: 3 additions & 3 deletions Tella/Components/Tabs/PageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import SwiftUI
class PageViewItem {

var title : String
var page : Pages
var page : Page
var number : Int

init(title: String, page: Pages, number: Int) {
init(title: String, page: Page, number: Int) {
self.title = title
self.page = page
self.number = number
Expand All @@ -19,7 +19,7 @@ class PageViewItem {

public struct PageView: View {

@Binding var selectedOption: Pages
@Binding var selectedOption: Page
var pageViewItems : [PageViewItem]

public var body: some View {
Expand Down
4 changes: 2 additions & 2 deletions Tella/Components/Tabs/PageViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ struct PageViewCell: View {
let title: String
let number: Int

let page: Pages
let page: Page

@Binding var selectedOption: Pages
@Binding var selectedOption: Page

public var body: some View {

Expand Down
2 changes: 1 addition & 1 deletion Tella/Components/Tabs/Pages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

public enum Pages: Hashable {
public enum Page: Hashable {

case draft
case outbox
Expand Down
46 changes: 26 additions & 20 deletions Tella/Components/ToastView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,37 @@
import SwiftUI

struct ToastView: View {

@State var isShowingView : Bool = true
var message : String
var width = CGFloat.infinity

var message: String
@State private var isShowing = true

var body: some View {

VStack {

Spacer()

Text(message)
.font(.custom(Styles.Fonts.regularFontName, size: 14))
.foregroundColor(.black)
.padding()
.frame(maxWidth: width)
.background(Color.white)
.cornerRadius(4)
.padding()
ZStack {
if isShowing {
Text(message)
.font(.custom(Styles.Fonts.regularFontName, size: 14))
.foregroundColor(.black)
.padding()
.frame(maxWidth: .infinity)
.background(Color.white)
.cornerRadius(4)
.padding()
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
withAnimation {
isShowing = false
}
}
}
}
}
.padding()
}
}

struct ToastView_Previews: PreviewProvider {
static var previews: some View {
ToastView( message: "Message")
ZStack {
Styles.Colors.backgroundMain
ToastView( message: "Message")
}
}
}
10 changes: 9 additions & 1 deletion Tella/Data/Database/Common/DatabaseConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct D {

/* DATABASE VERSION */

static let databaseVersion = 5
static let databaseVersion = 6

/* DEFAULT TYPES FOR DATABASE */
// MARK: - DEFAULT TYPES FOR DATABASE
Expand All @@ -34,6 +34,9 @@ struct D {
static let tUwaziEntityInstanceVaultFile = "t_uwazi_entity_instance_vault_file"
static let tFeedback = "t_feedback"
static let tResource = "t_resource"
static let tGDriveServer = "t_drive_server"
static let tGDriveReport = "t_drive_report_table"
static let tGDriveInstanceVaultFile = "t_drive_instance_vault_file"

/* DATABASE COLUMNS */
// MARK: - DATABASE COLUMNS
Expand Down Expand Up @@ -90,6 +93,11 @@ struct D {
static let cFilename = "c_filename"
static let cExternalId = "c_external_id"
static let cSize = "c_size"

//gDrive
static let cRootFolder = "c_root_folder_id"
static let cFolderId = "c_folder_id"
static let cRootFolderName = "c_root_folder_name"

}

Expand Down
8 changes: 0 additions & 8 deletions Tella/Data/Database/Common/SQLStatementBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,6 @@ class SQLiteStatementBuilder {
}
}

func addColumnToExistingTable(tableName: String, column: String) {
let sqlExpression = "ALTER TABLE " + tableName + " ADD COLUMN " + column
let ret = sqlite3_exec(dbPointer, sqlExpression, nil, nil, nil)

if (ret != SQLITE_OK) { // corrupt database.
logDbErr("Error altering db table - \(tableName)")
}
}
func setNewDatabaseVersion(version:Int) throws {

let sql = ("PRAGMA user_version = \(version)")
Expand Down
73 changes: 73 additions & 0 deletions Tella/Data/Database/GDriveData.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//
// GDriveData.swift
// Tella
//
// Created by gus valbuena on 6/28/24.
// Copyright © 2024 HORIZONTAL. All rights reserved.
//

import Foundation

extension TellaData {
func addGDriveReport(report : GDriveReport) -> Result<Int, Error> {
let id = database.addGDriveReport(report: report)

shouldReloadGDriveReports.send(true)

return id
}

func getDraftGDriveReport() -> [GDriveReport] {
return self.database.getDriveReports(reportStatus: [ReportStatus.draft])
}

func getOutboxedGDriveReport() -> [GDriveReport] {
return self.database.getDriveReports(reportStatus: [.finalized,
.submissionError,
.submissionPending,
.submissionPaused,
.submissionInProgress,
.submissionAutoPaused,
.submissionScheduled])
}

func getSubmittedGDriveReport() -> [GDriveReport] {
return self.database.getDriveReports(reportStatus: [ReportStatus.submitted])
}

func getDriveReport(id: Int?) -> GDriveReport? {
guard let id else { return nil }
return self.database.getGDriveReport(id: id)
}

func updateDriveReport(report: GDriveReport) -> Result<Bool, Error> {
shouldReloadGDriveReports.send(true)
return self.database.updateDriveReport(report: report)
}

func deleteDriveReport(reportId: Int?) -> Result<Bool, Error> {
shouldReloadGDriveReports.send(true)
return self.database.deleteDriveReport(reportId: reportId)
}

@discardableResult
func updateDriveReportStatus(reportId: Int, status: ReportStatus) -> Result<Bool, Error> {
shouldReloadGDriveReports.send(true)

return self.database.updateDriveReportStatus(idReport: reportId, status: status)
}

@discardableResult
func updateDriveFolderId(reportId: Int, folderId: String) -> Result<Bool, Error> {
shouldReloadGDriveReports.send(true)

return self.database.updateDriveReportFolderId(idReport: reportId, folderId: folderId)
}

@discardableResult
func updateDriveFiles(reportId: Int, files: [ReportFile]) -> Result<Bool, Error> {
shouldReloadGDriveReports.send(true)

return self.database.updateDriveReportFiles(files: files, reportId: reportId)
}
}
Loading

0 comments on commit 46eee6f

Please sign in to comment.