Skip to content

Commit

Permalink
Fixed files uploading status (#587)
Browse files Browse the repository at this point in the history
* Fixed file uploading status
* fixed attachments count issue
  • Loading branch information
ankitgoyalgloballogic authored Apr 27, 2023
1 parent 7c0349d commit 03741e5
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 24 deletions.
4 changes: 2 additions & 2 deletions ContentApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -5009,7 +5009,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.4;
MARKETING_VERSION = 1.7.0;
PRODUCT_BUNDLE_IDENTIFIER = com.alfresco.contentapp;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -5036,7 +5036,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.4;
MARKETING_VERSION = 1.7.0;
PRODUCT_BUNDLE_IDENTIFIER = com.alfresco.contentapp;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class StartWorkflowController: NSObject {
var didSelectPriority: (() -> Void)?
var didSelectAssignee: (() -> Void)?
var didSelectAddAttachment: (() -> Void)?
internal var supportedNodeTypes: [NodeType] = []

init(viewModel: StartWorkflowViewModel = StartWorkflowViewModel(), currentTheme: PresentationTheme?) {
self.viewModel = viewModel
Expand Down Expand Up @@ -240,3 +241,23 @@ class StartWorkflowController: NSObject {
return rowVMs
}
}

// MARK: - Events
extension StartWorkflowController: EventObservable {

func registerEvents() {
viewModel.services?.eventBusService?.register(observer: self,
for: SyncStatusEvent.self,
nodeTypes: [.file])
}

func handle(event: BaseNodeEvent, on queue: EventQueueType) {
if let publishedEvent = event as? SyncStatusEvent {
handleSyncStatus(event: publishedEvent)
}
}

func handleSyncStatus(event: SyncStatusEvent) {
self.buildViewModel()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class StartWorkflowViewController: SystemSearchViewController {
getWorkflowDetails()
AnalyticsManager.shared.pageViewEvent(for: Event.Page.startWorkflowScreen)
self.dialogTransitionController = MDCDialogTransitionController()
controller.registerEvents()

// ReSignIn Notification
NotificationCenter.default.addObserver(self,
Expand All @@ -66,6 +67,7 @@ class StartWorkflowViewController: SystemSearchViewController {
super.viewWillAppear(animated)
self.tabBarController?.tabBar.isHidden = true
updateTheme()
controller.buildViewModel()
}

override func viewDidAppear(_ animated: Bool) {
Expand Down Expand Up @@ -527,8 +529,8 @@ extension StartWorkflowViewController {
private func didSelectUploadTransfers(uploadTransfers: [UploadTransfer]) {
for uploadTransfer in uploadTransfers {
viewModel.workflowOperationsModel?.uploadAttachmentOperation(transfer: uploadTransfer, completionHandler: {[weak self] isError in
guard let sSelf = self else { return }
sSelf.controller.buildViewModel()
guard self != nil else { return }
AlfrescoLog.debug("\(isError)")
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class WorkflowOperationsModel: NSObject {
completionHandler(isError)
}
}
publishSyncStatusEvent(for: eventNode)
}
}

Expand Down Expand Up @@ -155,3 +156,11 @@ extension WorkflowOperationsModel {
}
}
}

// MARK: - Publish Sync
extension WorkflowOperationsModel {
private func publishSyncStatusEvent(for listNode: ListNode) {
let syncStatusEvent = SyncStatusEvent(node: listNode)
services?.eventBusService?.publish(event: syncStatusEvent, on: .mainQueue)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class TaskAttachmentsController: NSObject {
var rowVMs = [RowViewModel]()
var attachments = viewModel.attachments.value
if viewModel.attachmentType == .workflow {
attachments = viewModel.workflowAttachments
attachments = viewModel.workflowOperationsModel?.attachments.value ?? []
}
if !attachments.isEmpty {
for attachment in attachments {
Expand Down Expand Up @@ -94,17 +94,21 @@ extension TaskAttachmentsController: EventObservable {
}

func handleSyncStatus(event: SyncStatusEvent) {
var attachments = viewModel.attachments.value
let eventNode = event.node
for (index, listNode) in attachments.enumerated() where listNode.id == eventNode.id {
attachments[index] = eventNode
self.viewModel.attachments.value = attachments
if viewModel.attachmentType == .workflow {
self.buildViewModel()
}

// Insert nodes to be uploaded
_ = self.uploadTransferDataAccessor.queryAll(for: viewModel.taskID, attachmentType: .task) { uploadTransfers in
self.insert(uploadTransfers: uploadTransfers)
} else {
var attachments = viewModel.attachments.value
let eventNode = event.node
for (index, listNode) in attachments.enumerated() where listNode.id == eventNode.id {
attachments[index] = eventNode
self.viewModel.attachments.value = attachments
self.buildViewModel()
}

// Insert nodes to be uploaded
_ = self.uploadTransferDataAccessor.queryAll(for: viewModel.taskID, attachmentType: .task) { uploadTransfers in
self.insert(uploadTransfers: uploadTransfers)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ class TaskAttachmentsControllerViewModel: TaskPropertiesViewModel {
return String(format: LocalizationConstants.Tasks.multipleAttachmentsTitle, attachments.value.count)
}
} else if attachmentType == .workflow {
if workflowAttachments.count > 1 {
return String(format: LocalizationConstants.Tasks.multipleAttachmentsTitle, workflowAttachments.count)
let attachments = workflowOperationsModel?.attachments.value ?? []
if attachments.count > 1 {
return String(format: LocalizationConstants.Tasks.multipleAttachmentsTitle, attachments.count)
}
}

Expand All @@ -38,7 +39,4 @@ class TaskAttachmentsControllerViewModel: TaskPropertiesViewModel {
var tempWorkflowId: String = ""
var processDefintionTitle: String = ""
var workflowOperationsModel: WorkflowOperationsModel?
var workflowAttachments: [ListNode] {
return workflowOperationsModel?.attachments.value ?? []
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,15 @@ extension TaskAttachmentsViewController {
}
} else {
AnalyticsManager.shared.didTapDeleteTaskAttachment(isWorkflow: true)
var attachments = viewModel.workflowAttachments
var attachments = viewModel.workflowOperationsModel?.attachments.value ?? []
if let index = attachments.firstIndex(where: {$0.guid == attachment.guid}) {
attachments.remove(at: index)
viewModel.workflowOperationsModel?.attachments.value = attachments
controller.buildViewModel()
DispatchQueue.main.async {
self.applyLocalization()
}
popToPreviousController(attachments: attachments)
}
}
}
Expand All @@ -289,10 +293,16 @@ extension TaskAttachmentsViewController {
attachments.remove(at: index)
viewModel.attachments.value = attachments
controller.buildViewModel()
popToPreviousController(attachments: attachments)
}
}

private func popToPreviousController(attachments: [ListNode]) {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3, execute: {
if attachments.isEmpty {
self.navigationController?.popViewController(animated: true)
}
}
})
}
}

Expand Down Expand Up @@ -433,9 +443,8 @@ extension TaskAttachmentsViewController {
for uploadTransfer in uploadTransfers {
viewModel.workflowOperationsModel?.uploadAttachmentOperation(transfer: uploadTransfer, completionHandler: {[weak self] isError in
guard let sSelf = self else { return }
sSelf.controller.buildViewModel()
DispatchQueue.main.async {
sSelf.tableView.reloadData()
sSelf.applyLocalization()
}
})
}
Expand Down

0 comments on commit 03741e5

Please sign in to comment.