Skip to content

Commit

Permalink
[AAE-6242] upload a new version of a file attached in a form (#7651)
Browse files Browse the repository at this point in the history
* [AAE-6242] Create upload new version dialog to handle the upload of the new file version

* [AAE-6242] Create version manager service to open version manager dialog

* [AAE-6242] Export service and dialog

* [AAE-6242] add adf-upload button to the show the upload new file button

* [AAE-6242] open upload new version dialog

* [AAE-6242] Removed console log

* [AAE-8798] display update option name to newVersion

* [AAE-8799] Emit version manager data when new file version is uploaded

* [AAE-8799] When a new file version is uploaded open new version dialog and update current file version with the new file version

* [AAE-8799] Rename UploadNewVersionDialogComponent to VersionManagerDialogComponent and UploadNewVersionDialogData to VersionManagerDialogData

* [AAE-8799] Use default root folder id

* [AAE-8799] Add #uploadSingleFile ViewChild in order get the input reference

* [AAE-8799] Trigger adf-upload-button by clicking on the button in order to open the file chooser and upload a new file version

* [AAE-8799] Version manager dialog emits file upload error

* [AAE-8799] Format version manager dialog code

* [AAE-8799] Reject upload and permission errors

* [AAE-8799] Catch upload new version errors

* [AAE-8799] Update allowable operation type

* [AAE-8799] Rename VersionManagerDialogComponent into NewVersionUploaderDialogComponent and VersionManagerService into NewVersionUploaderService, create specific folder for new version uploader component and service

* Restore previous UploadButtonComponent version

* [AAE-8799] Use [adf-upload] directive to upload new file version

* [AAE-8799] Add mock file for new version uploader unit tests

* [AAE-8799] Override mat dialog configuration

* [AAE-8799] Add unit test related to event emitted from Dialog

* [AAE-8799] Create model to handle New Version Uploader data

* [AAE-8799] Return data on dialog close

* [AAE-8799] Add showVersionsOnly property to dialog to show only file version list

* [AAE-8799] Add dialogAction to emit dialog actions

* [AAE-8799] Return observable instead of promise

* [AAE-8799] Update new file version type

* [AAE-8799] Subscribe dialog because return an Observable

* [AAE-8799] Add license header

* [AAE-8799] Add i18n new version uploader translations

* [AAE-8799] If data.title is not provided, add a default title

* [AAE-8799] Change panelClass for manage versions visualizations, add dialog styles

* [AAE-8799] Add upload new version dialog unit test

* [AAE-8799] Add upload new version dialog unit test related to manage versions section

* [AAE-8799] Add onUploadNewFileVersion unit tests

* [AAE-8799] Test new dialog panelClass

* [AAE-8799] Create a method to set dialog title, if title isn't provided from parent component, a default title is set

* [AAE-8799] Add doc to new-version-uploader-dilog component and service

* [AAE-8799] Add new-version-uploader.dialog.service documentation
  • Loading branch information
alep85 committed May 27, 2022
1 parent 95fd3e8 commit 4457aed
Show file tree
Hide file tree
Showing 25 changed files with 1,278 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
Title: New Version Uploader service
Added: v1.0.0
Status: Active
Last reviewed: 2022-05-26
---

# [New Version Uploader service](../../../lib/content-services/src/lib/new-version-uploader/new-version-uploader.service.ts "Defined in new-version-uploader.service.ts")

Display a dialog that allows to upload new file version or to manage the current node versions.

## Class members

### Methods

- **openUploadNewVersionDialog**(data: [NewVersionUploaderDialogData](../../../lib/content-services/src/lib/new-version-uploader/models/new-version-uploader.model.ts), config: `MatDialogConfig`): `Observable`<br/>
Opens a dialog to upload new file version or to manage current node versions
- _data:_ [NewVersionUploaderDialogData](../../../lib/content-services/src/lib/new-version-uploader/models/new-version-uploader.model.ts) - The data to pass to the dialog
- _config:_ `MatDialogConfig` - A configuration object that allows to override default dialog configuration
- **Returns** `Observable` - [`Observable`](http://reactivex.io/documentation/observable.html) which you can subscribe in order to get information about the dialog actions or error notification in case of error condition.
## Details

You can open dialog in two different ways:

- [Upload new file version](#upload-new-version)
- [Manage node versions](#manage-versions)

### Upload New Version

The dialog shows

- a side by side comparison between the current target node (type, name, icon) and the new file that should update it's version
- the new version's minor/major changes
- the optional comment
- a button to upload a new file version
![Upload new version image](../../docassets/images/adf-new-version-uploader_upload.png)

Usage example:
```ts
import { NewVersionUploaderService } from '@alfresco/adf-content-services'

constructor(private newVersionUploaderService: NewVersionUploaderService){}

yourFunctionToOpenDialog(){
const newVersionUploaderDialogData: NewVersionUploaderDialogData = {
file,
node
};
this.newVersionUploaderService.openUploadNewVersionDialog(newVersionUploaderDialogData).subscribe(
(data: NewVersionUploaderData) => {
// place your action here on operation success!
},
(error) => {
// place your action here on operation error!
})
}
```

---

### Manage Versions

Setting `showVersionsOnly` to `true` the dialog displays the version history of a node, with the ability to restore, delete and view version of the current node
![Manage versions image](../../docassets/images/adf-new-version-uploader_manage-versions.png)

Usage example:
```ts
import { NewVersionUploaderService } from '@alfresco/adf-content-services'

constructor(private newVersionUploaderService: NewVersionUploaderService){}

yourFunctionToOpenDialog(){
const newVersionUploaderDialogData: NewVersionUploaderDialogData = {
file,
node,
showVersionsOnly: true
};
this.newVersionUploaderService.openUploadNewVersionDialog(newVersionUploaderDialogData).subscribe(
(data: NewVersionUploaderData) => {
// place your action here on operation success!
})
}
```

## See Also

- [Version list component](../components/docs/content-services/components/version-list.component.md)
- [Version Comparison Component](../components/docs/content-services/components/version-comparison.component.md)
- [Version Upload Component](../components/docs/content-services/components/version-upload.component.md)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions lib/content-services/src/lib/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@
"NO_LABEL": "No"
}
},
"ADF-NEW-VERSION-UPLOADER": {
"DIALOG_LIST": {
"TITLE": "Manage Versions",
"CLOSE": "Close"
},
"DIALOG_UPLOAD": {
"TITLE": "Upload New Version",
"CANCEL": "Cancel",
"UPLOAD": "Upload"
}
},
"ADF_VERSION_COMPARISON": {
"CURRENT_VERSION": "Current",
"NEW_VERSION": "New",
Expand Down
182 changes: 182 additions & 0 deletions lib/content-services/src/lib/mock/new-version-uploader.service.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export const mockNode: any = ({
isFile: true,
createdByUser: { id: 'admin', displayName: 'Administrator' },
modifiedAt: '2017-05-24T15:08:55.640Z',
nodeType: 'cm:content',
content: {
mimeType: 'application/rtf',
mimeTypeName: 'Rich Text Format',
sizeInBytes: 14530,
encoding: 'UTF-8'
},
parentId: 'd124de26-6ba0-4f40-8d98-4907da2d337a',
createdAt: '2017-05-24T15:08:55.640Z',
path: {
name: '/Company Home/Guest Home',
isComplete: true,
elements: [{
id: '94acfc73-7014-4475-9bd9-93a2162f0f8c',
name: 'Company Home'
}, { id: 'd124de26-6ba0-4f40-8d98-4907da2d337a', name: 'Guest Home' }]
},
isFolder: false,
modifiedByUser: { id: 'admin', displayName: 'Administrator' },
name: 'b_txt_file.rtf',
id: '70e1cc6a-6918-468a-b84a-1048093b06fd',
properties: { 'cm:versionLabel': '1.0', 'cm:versionType': 'MAJOR' },
allowableOperations: ['delete', 'update']
});

export const mockFile = new File(['fakefake'], 'file-fake.png', { type: 'image/png' });

export const mockNewVersionUploaderData: any = {
action: 'upload',
newVersion: {
value: {
entry: {
isFile: true,
createdByUser: {
id: 'hruser',
displayName: 'hruser'
},
modifiedAt: '2022-05-24T10:19:43.544Z',
nodeType: 'cm:content',
content: {
mimeType:
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
mimeTypeName: 'Microsoft Word 2007',
sizeInBytes: 11887,
encoding: 'UTF-8'
},
parentId: '422538ca-ea4b-4086-83f9-b36e4521ec7f',
aspectNames: [
'rn:renditioned',
'cm:versionable',
'cm:titled',
'cm:auditable',
'cm:author',
'cm:thumbnailModification'
],
createdAt: '2022-05-24T07:26:44.429Z',
isFolder: false,
modifiedByUser: {
id: 'hruser',
displayName: 'hruser'
},
name: 'Test3.docx',
id: '42ddb84d-fc96-4b45-aa3c-f24ca997d602',
properties: {
'cm:versionType': 'MINOR',
'cm:versionLabel': '1.1',
'cm:author': 'Amedeo Lepore',
'cm:lastThumbnailModification': ['doclib:1653377205499']
},
allowableOperations: ['delete', 'update', 'updatePermissions']
}
}
},
currentVersion: {
isFile: true,
createdByUser: {
id: 'hruser',
displayName: 'hruser'
},
modifiedAt: '2022-05-24T07:26:45.337Z',
nodeType: 'cm:content',
content: {
mimeType:
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
mimeTypeName: 'Microsoft Word 2007',
sizeInBytes: 11949,
encoding: 'UTF-8'
},
parentId: '422538ca-ea4b-4086-83f9-b36e4521ec7f',
aspectNames: [
'rn:renditioned',
'cm:versionable',
'cm:titled',
'cm:auditable',
'cm:author',
'cm:thumbnailModification'
],
createdAt: '2022-05-24T07:26:44.429Z',
path: {
name: '/Company Home/User Homes/hruser',
isComplete: true,
elements: [
{
id: '4e2284fd-9457-4914-a612-ea844e87f53f',
name: 'Company Home',
nodeType: 'cm:folder',
aspectNames: ['cm:titled', 'cm:auditable', 'app:uifacets']
},
{
id: '75a5d2d2-6edb-40b6-822e-499f5e8beffb',
name: 'User Homes',
nodeType: 'cm:folder',
aspectNames: ['cm:titled', 'cm:auditable', 'app:uifacets']
},
{
id: '422538ca-ea4b-4086-83f9-b36e4521ec7f',
name: 'hruser',
nodeType: 'cm:folder',
aspectNames: ['cm:ownable', 'cm:auditable']
}
]
},
isFolder: false,
permissions: {
inherited: [
{
authorityId: 'ROLE_OWNER',
name: 'All',
accessStatus: 'ALLOWED'
},
{
authorityId: 'hruser',
name: 'All',
accessStatus: 'ALLOWED'
}
],
settable: [
'Contributor',
'Collaborator',
'Coordinator',
'Editor',
'Consumer'
],
isInheritanceEnabled: true
},
modifiedByUser: {
id: 'hruser',
displayName: 'hruser'
},
name: 'Test2.docx',
id: '42ddb84d-fc96-4b45-aa3c-f24ca997d602',
properties: {
'cm:versionType': 'MAJOR',
'cm:versionLabel': '1.0',
'cm:author': 'Amedeo Lepore',
'cm:lastThumbnailModification': ['doclib:1653377205499']
},
allowableOperations: ['delete', 'update', 'updatePermissions'],
isExternal: true
}
};
1 change: 1 addition & 0 deletions lib/content-services/src/lib/mock/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ export * from './search.service.mock';
export * from './search-filter-mock';
export * from './sites-dropdown.component.mock';
export * from './search-query.mock';
export * from './new-version-uploader.service.mock';
18 changes: 18 additions & 0 deletions lib/content-services/src/lib/new-version-uploader/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export * from './public-api';
17 changes: 17 additions & 0 deletions lib/content-services/src/lib/new-version-uploader/models/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export * from './new-version-uploader.model';
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { MinimalNodeEntryEntity, Version, NodeChildAssociation, Node } from '@alfresco/js-api';
import { NodeEntityEvent } from '../../document-list';

export interface NewVersionUploaderDialogData {
title?: string;
node: MinimalNodeEntryEntity;
file?: File;
currentVersion?: Version;
showVersionsOnly?: boolean;
}

export type NewVersionUploaderData = VersionManagerUploadData | ViewVersion | RefreshData;

// eslint-disable-next-line no-shadow
export enum NewVersionUploaderDataAction {
refresh = 'refresh',
upload = 'upload',
view = 'view'
}

interface BaseData {
action: NewVersionUploaderDataAction;
}

export interface VersionManagerUploadData extends BaseData {
action: NewVersionUploaderDataAction.upload;
newVersion: NodeEntityEvent;
currentVersion: NodeChildAssociation;
}

export interface ViewVersion extends BaseData {
action: NewVersionUploaderDataAction.view;
versionId: string;
}

export interface RefreshData extends BaseData {
action: NewVersionUploaderDataAction.refresh;
node: Node;
}

0 comments on commit 4457aed

Please sign in to comment.