From 1a7b39093079524b506e3c3b38f7472f6db7d499 Mon Sep 17 00:00:00 2001 From: Andy Stark <30621568+therealandeeee@users.noreply.github.com> Date: Thu, 5 Oct 2017 14:25:49 +0100 Subject: [PATCH] [ADF-1586] Added doc files for Document List library (#2435) --- docIndex.md | 4 + docs/data-column.component.md | 228 +++++++++++++++++---- docs/document-list.component.md | 350 +++++--------------------------- docs/permissions-style.model.md | 74 +++++++ docs/seeAlsoGraph.json | 3 +- 5 files changed, 324 insertions(+), 335 deletions(-) create mode 100644 docs/permissions-style.model.md diff --git a/docIndex.md b/docIndex.md index 9431b75ff9..99c2426f7e 100644 --- a/docIndex.md +++ b/docIndex.md @@ -402,6 +402,10 @@ for more information about installing and using the source code. - [Sites dropdown component](docs/sites-dropdown.component.md) - [*Content node selector component](ng2-components/ng2-alfresco-documentlist/src/components/content-node-selector/content-node-selector.component.ts) +### Models + +- [Permissions style model](docs/permissions-style.model.md) + ### Services - [Document actions service](docs/document-actions.service.md) diff --git a/docs/data-column.component.md b/docs/data-column.component.md index 5938e88845..0eabc4a9e3 100644 --- a/docs/data-column.component.md +++ b/docs/data-column.component.md @@ -11,7 +11,10 @@ Defines column properties for DataTable, Tasklist, Document List and other compo - [Details](#details) * [Automatic column header translation](#automatic-column-header-translation) * [Custom tooltips](#custom-tooltips) - * [Column Templates](#column-templates) + * [Column Template](#column-template) + * [Styling Techniques](#styling-techniques) + + [Custom icons for selected rows](#custom-icons-for-selected-rows) + + [Hiding columns on small screens](#hiding-columns-on-small-screens) @@ -94,48 +97,201 @@ export class MyComponent { To disable the tooltip your function can return `null` or an empty string. -### Column Templates +### Column Template -It is possible to assign a custom column template like the following: +You can provide custom column/cell templates that may contain other Angular components or HTML elements: + +Every cell in the DataTable component is bound to the dynamic data context containing the following properties: + +| Name | Type | Description | +| --- | --- | --- | +| data | [DataTableAdapter](https://github.com/Alfresco/alfresco-ng2-components/tree/master/ng2-components/ng2-alfresco-datatable#data-sources) | Data adapter instance. | +| row | [DataRow](https://github.com/Alfresco/alfresco-ng2-components/tree/master/ng2-components/ng2-alfresco-datatable#data-sources) | Current data row instance. | +| col | [DataColumn](https://github.com/Alfresco/alfresco-ng2-components/tree/master/ng2-components/ng2-alfresco-datatable#data-sources) | Current data column instance. | + +You can use all three properties to gain full access to underlying data from within your custom templates. +In order to wire HTML templates with the data context you will need defining a variable that is bound to `$implicit` like shown below: ```html - - - - - V. {{value}} - - - - -``` - -Example above shows access to the underlying cell value by binding `value` property to the underlying context `value`: - -```html - -``` - -Alternatively you can get access to the entire data context using the following syntax: - -```html - -``` - -That means you are going to create local variable `entry` that is bound to the data context via Angular's special `$implicit` keyword. - -```html - - V. {{entry.data.getValue(entry.row, entry.col)}} + + ``` -In the second case `entry` variable is holding a reference to the following data context: +The format of naming is `let-VARIABLE_NAME="$implicit"` where `VARIABLE_NAME` is the name of the variable you want to bind template data context to. + +Getting a cell value from the underlying DataTableAdapter: ```ts -{ - data: DataTableAdapter, - row: DataRow, - col: DataColumn +context.data.getValue(entry.row, entry.col); +``` + +You can retrieve all property values for underlying node, including nested properties (via property paths): + +```ts +context.row.getValue('name') +context.row.getValue('createdByUser.displayName') +``` + +You may want using **row** api to get raw value access. + +```html + + + Hi! {{context.row.getValue('createdByUser.displayName')}} + Hi! {{context.row.getValue('name')}} + + +``` + +Use **data** api to get values with post-processing, like datetime/icon conversion._ + +In the Example below we will prepend `Hi!` to each file and folder name in the list: + +```html + + + Hi! {{entry.data.getValue(entry.row, entry.col)}} + + +``` + +In the Example below we will add the [ng2-alfresco-tag](https://www.npmjs.com/package/ng2-alfresco-tag) component is integrate in the document list. + +```html + + + + + +``` + +![Tag component in document List](docassets/images/document-list-tag-template.png) + +### Styling Techniques + +You can add a custom CSS class to a column using its `class` property. This is useful for +many purposes - some examples are given below. + +#### Custom icons for selected rows + +Custom styling can be used to change the look and feel of the icon for the selected rows. + +Let's start by assigning an "image-table-cell" class to the thumbnail column: + +```html + + + + + + + ... + + +``` + +Now your application can define styles to change the content of the column based on conditions such as the selection state: + +```css +adf-document-list >>> adf-datatable tr.is-selected .image-table-cell { + position: relative; +} + +adf-document-list >>> adf-datatable tr.is-selected .image-table-cell::before { + content: "\E876"; /* "done" */ + font-family: "Material Icons"; + font-size: 24px; + line-height: 32px; + text-align: center; + color: white; + position: absolute; + width: 32px; + height: 32px; + top: 50%; + left: 50%; + margin-top: -16px; + margin-left: -14px; + border-radius: 100%; + background: #00bcd4; } ``` + +Once your application starts you should see the following icon for each selected row: + +![view-child](docassets/images/document-list-custom-icon.png) + +#### Hiding columns on small screens + +You can hide columns on small screens using custom CSS rules: + +```css +@media all and (max-width: 768px) { + + alfresco-document-list >>> th.desktop-only .cell-value { + display: none; + } + + alfresco-document-list >>> td.desktop-only .cell-value { + display: none; + } +} +``` + +Now you can declare columns and assign `desktop-only` class where needed: + +```html + + + + + + + + + + + + + + + + + +``` + +**Desktop View** + +![Responsive Desktop](docassets/images/responsive-desktop.png) + +**Mobile View** + +![Responsive Mobile](docassets/images/responsive-mobile.png) + + + +## See also + +- [Document list component](document-list.component.md) +- [Datatable component](datatable.component.md) +- [Tasklist component](tasklist.component.md) + \ No newline at end of file diff --git a/docs/document-list.component.md b/docs/document-list.component.md index 9b959b5dad..380ee9d243 100644 --- a/docs/document-list.component.md +++ b/docs/document-list.component.md @@ -17,22 +17,18 @@ Displays the documents from a repository. + [Repository aliases](#repository-aliases) + [DocumentList aliases](#documentlist-aliases) * [Setting default folder](#setting-default-folder) - * [Custom icons for selected rows](#custom-icons-for-selected-rows) * [Calling DocumentList api directly](#calling-documentlist-api-directly) - * [Custom columns](#custom-columns) * [Underlying node object](#underlying-node-object) + * [Custom columns](#custom-columns) * [Date Column](#date-column) * [Location Column](#location-column) - * [Column Template](#column-template) * [Actions](#actions) * [Navigation mode](#navigation-mode) - [Advanced usage and customization](#advanced-usage-and-customization) * [Custom row filter](#custom-row-filter) * [Custom image resolver](#custom-image-resolver) - * [Hiding columns on small screens](#hiding-columns-on-small-screens) - * [Custom row permissions style](#custom-row-permissions-style) - + [Examples](#examples) * [Custom 'empty folder' template](#custom-empty-folder-template) +- [See also](#see-also) @@ -61,7 +57,7 @@ The properties currentFolderId, folderNode and node are the entry initialization | rowStyleClass | string | | The CSS class to apply to every row | | currentFolderId | string | null | The ID of the folder node to display or a reserved string alias for special sources (see **Data Sources**) | | folderNode | [MinimalNodeEntryEntity](https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/NodeMinimalEntry.md) | null | Currently displayed folder node | -| permissionsStyle | [PermissionStyleModel[]](https://github.com/Alfresco/alfresco-ng2-components/blob/master/ng2-components/ng2-alfresco-documentlist/src/models/permissions-style.model.ts) | null | with this array you can define different styles depending on the permission of the user on that node. The PermissionStyleModel allows you to select also if you want to apply the style only on the file or folder nodes. PermissionStyleModel.permission accepts the following values [Permissions](https://github.com/Alfresco/alfresco-ng2-components/blob/development/ng2-components/ng2-alfresco-core/src/models/permissions.enum.ts) [see more](#custom-row-permissions-style). | +| permissionsStyle | [PermissionStyleModel[]](permission-style.model.md) | null | Define a set of CSS styles styles to apply depending on the permission of the user on that node. See the [Permission Style model](permission-style.model.md) page for further details and examples. | | paginationStrategy | PaginationStrategy | PaginationStrategy.Finite | The pagination type to be shown, can be Finite or Infinite | | node | [NodePaging](https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/NodePaging.md) | null | Document list will show all the nodes contained in the NodePaging entity | | navigate | boolean | true | Toggles navigation to folder content or file preview | @@ -114,7 +110,7 @@ Every event is represented by a [CustomEvent](https://developer.mozilla.org/en/d } ``` -Please refer to the DataTable documentation to find details about additional DOM events the DocumentList component bubbles up from the DataTable. +Please refer to the [DataTable](datatable.component.md) documentation to find details about additional DOM events the DocumentList component bubbles up from the DataTable. Below is a basic example of handling DOM events in the parent elements. @@ -315,60 +311,6 @@ It helps examining other valuable information you can have access to if needed: **Important note**: for this particular scenario you must also trigger `changeDetector.detectChanges()` as in the example above. -### Custom icons for selected rows - -You can use the "class" property of the [DataColumn component](data-column.component.md) to apply your custom css. - -As an example, this feature can be used to change the look and feel of the icon for the selected rows. - -Let's start by assigning an "image-table-cell" class to the thumbnail column: - -```html - - - - - - - ... - - -``` - -Now your application can define custom styles to change the content of the column based on some other conditions, like selection state: - -```css -adf-document-list >>> adf-datatable tr.is-selected .image-table-cell { - position: relative; -} - -adf-document-list >>> adf-datatable tr.is-selected .image-table-cell::before { - content: "\E876"; /* "done" */ - font-family: "Material Icons"; - font-size: 24px; - line-height: 32px; - text-align: center; - color: white; - position: absolute; - width: 32px; - height: 32px; - top: 50%; - left: 50%; - margin-top: -16px; - margin-left: -14px; - border-radius: 100%; - background: #00bcd4; -} -``` - -Once your application starts you should see the following icon for each selected row: - -![view-child](docassets/images/document-list-custom-icon.png) - ### Calling DocumentList api directly Typically you will be binding DocumentList properties to your application/component class properties: @@ -440,10 +382,55 @@ It is important accessing child components at least at the `AfterViewInit` state Any UI click (buttons, links, etc.) event handlers are absolutely fine. This cannot be `ngOnInit` event though. You can get more details in [Component lifecycle hooks](https://angular.io/docs/ts/latest/guide/lifecycle-hooks.html) article. +### Underlying node object + +DocumentList component assigns an instance of `MinimalNode` type (`alfresco-js-api`) as a data context of each row. + +```js +export interface MinimalNode { + id: string; + parentId: string; + name: string; + nodeType: string; + isFolder: boolean; + isFile: boolean; + modifiedAt: Date; + modifiedByUser: UserInfo; + createdAt: Date; + createdByUser: UserInfo; + content: ContentInfo; + path: PathInfoEntity; + properties: NodeProperties; +} +``` + +_See more details in [alfresco-js-api](https://github.com/Alfresco/alfresco-js-api/blob/master/index.d.ts) repository._ + +Binding to nested properties is also supported. You can define a column key as a property path similar to the following: + +```text +createdByUser.displayName +``` + +Here's a short example: + +```html + + + + + + + + +``` + ### Custom columns It is possible to reorder, extend or completely redefine data columns displayed by the component. -By default special `$thumbnail` and `displayName` columns are rendered. +By default, special `$thumbnail` and `displayName` columns are rendered. A custom set of columns can look like the following: @@ -491,52 +478,7 @@ You can also use HTML-based schema declaration used by DataTable, TaskList and o ``` -You can also add tooltips, automatic column title translation and other features. See the [DataColumn component page](data-column.component.md) for more information about specifying and customizing columns. - -### Underlying node object - -DocumentList component assigns an instance of `MinimalNode` type (`alfresco-js-api`) as a data context of each row. - -```js -export interface MinimalNode { - id: string; - parentId: string; - name: string; - nodeType: string; - isFolder: boolean; - isFile: boolean; - modifiedAt: Date; - modifiedByUser: UserInfo; - createdAt: Date; - createdByUser: UserInfo; - content: ContentInfo; - path: PathInfoEntity; - properties: NodeProperties; -} -``` - -_See more details in [alfresco-js-api](https://github.com/Alfresco/alfresco-js-api/blob/master/index.d.ts) repository._ - -Binding to nested properties is also supported. You can define a column key as a property path similar to the following: - -```text -createdByUser.displayName -``` - -Here's a short example: - -```html - - - - - - - - -``` +You can also add tooltips, styling, automatic column title translation and other features. See the [DataColumn component page](data-column.component.md) for more information about specifying and customizing columns. ### Date Column @@ -586,81 +528,6 @@ All links rendered in the column above will have an address mapped to `/files`: ... ``` -### Column Template - -It is possible to provide custom column/cell template that may contain other Angular components or HTML elements: - -Every cell in the DataTable component is bound to the dynamic data context containing the following properties: - -| Name | Type | Description | -| --- | --- | --- | -| data | [DataTableAdapter](https://github.com/Alfresco/alfresco-ng2-components/tree/master/ng2-components/ng2-alfresco-datatable#data-sources) | Data adapter instance. | -| row | [DataRow](https://github.com/Alfresco/alfresco-ng2-components/tree/master/ng2-components/ng2-alfresco-datatable#data-sources) | Current data row instance. | -| col | [DataColumn](https://github.com/Alfresco/alfresco-ng2-components/tree/master/ng2-components/ng2-alfresco-datatable#data-sources) | Current data column instance. | - -You can use all three properties to gain full access to underlying data from within your custom templates. -In order to wire HTML templates with the data context you will need defining a variable that is bound to `$implicit` like shown below: - -```html - - - -``` - -The format of naming is `let-VARIABLE_NAME="$implicit"` where `VARIABLE_NAME` is the name of the variable you want to bind template data context to. - -Getting a cell value from the underlying DataTableAdapter: - -```ts -context.data.getValue(entry.row, entry.col); -``` - -You can retrieve all property values for underlying node, including nested properties (via property paths): - -```ts -context.row.getValue('name') -context.row.getValue('createdByUser.displayName') -``` - -You may want using **row** api to get raw value access. - -```html - - - Hi! {{context.row.getValue('createdByUser.displayName')}} - Hi! {{context.row.getValue('name')}} - - -``` - -Use **data** api to get values with post-processing, like datetime/icon conversion._ - -In the Example below we will prepend `Hi!` to each file and folder name in the list: - -```html - - - Hi! {{entry.data.getValue(entry.row, entry.col)}} - - -``` - -In the Example below we will add the [ng2-alfresco-tag](https://www.npmjs.com/package/ng2-alfresco-tag) component is integrate in the document list. - -```html - - - - - -``` - -![Tag component in document List](docassets/images/document-list-tag-template.png) - ### Actions You can add actions to a dropdown menu for each item shown in a Document List. Several @@ -823,120 +690,6 @@ export class View1 { } ``` -### Hiding columns on small screens - -You can hide columns on small screens by means of custom CSS rules: - -```css -@media all and (max-width: 768px) { - - alfresco-document-list >>> th.desktop-only .cell-value { - display: none; - } - - alfresco-document-list >>> td.desktop-only .cell-value { - display: none; - } -} -``` - -Now you can declare columns and assign `desktop-only` class where needed: - -```html - - - - - - - - - - - - - - - - - -``` - -**Desktop View** - -![Responsive Desktop](docassets/images/responsive-desktop.png) - -**Mobile View** - -![Responsive Mobile](docassets/images/responsive-mobile.png) - -### Custom row permissions style - -You can customize the style of the row based on the permissions. -The property to use is permissionsStyle[]:[PermissionStyleModel[]](https://github.com/Alfresco/alfresco-ng2-components/blob/master/ng2-components/ng2-alfresco-documentlist/src/models/permissions-style.model.ts). -The permissionsStyle array can define different styles depending on the permission of the user on that node. - -[PermissionStyleModel](https://github.com/Alfresco/alfresco-ng2-components/blob/master/ng2-components/ng2-alfresco-documentlist/src/models/permissions-style.model.ts) - -| Property | Description | -| --- | --- | -| isFile/isFolder | allow you to select if you want apply the style to file/folder nodes | -| permission | is an enum value [Permissions](https://github.com/Alfresco/alfresco-ng2-components/blob/development/ng2-components/ng2-alfresco-core/src/models/permissions.enum.ts) | -| css| the name of the class to add | - -#### Examples - -If you want to change the style on rows where the user can create content: - -```ts -let permissionsStyle: PermissionStyleModel[] = []; - -this.permissionsStyle.push(new PermissionStyleModel('document-list__create', PermissionsEnum.CREATE)); -``` - -```html - - -``` - -```css -adf-document-list >>> adf-datatable tr.document-list__create { - background: green !important; -} -``` - -If you want to change the style on the folders where the user doesn't have the permission to update: - -```ts - -let permissionsStyle: PermissionStyleModel[] = []; - -this.permissionsStyle.push(new PermissionStyleModel('document-list__disable', PermissionsEnum.NOT_CREATE, false, true)); - -``` - -```html - - -``` - -```css -adf-document-list >>> adf-datatable tr.document-list__disable { - background: red !important; -} -``` - ### Custom 'empty folder' template By default DocumentList provides the following content for the empty folder: @@ -971,4 +724,5 @@ That will give the following output: - [Breadcrumb component](breadcrumb.component.md) - [Content action component](content-action.component.md) - [Dropdown breadcrumb component](dropdown-breadcrumb.component.md) +- [Permission style model](permission-style.model.md) \ No newline at end of file diff --git a/docs/permissions-style.model.md b/docs/permissions-style.model.md new file mode 100644 index 0000000000..d9a061e3c3 --- /dev/null +++ b/docs/permissions-style.model.md @@ -0,0 +1,74 @@ +# Permission Style model + +Sets custom CSS styles for rows of a [Document List](document-list.component.md) according to the item's permissions. + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| isFile | boolean | Does this style apply to files? | +| isFolder | boolean | Does this style apply to folders? | +| permission | Permissions | An enum value defining the permissions that this style applies to (see below) | +| css| string | The name of the CSS class to add | + +## Details + +You can customize the style of a [Document List](document-list.component.md) row based on the user's +permissions for that item. The list has a `permissionsStyle` property containing an array of +Permission Style model objects. These objects associate a particular CSS style with a permission level +and can be applied separately to files and folders by setting `isFile` and `isFolder` appropriately. + +### Permissions enum + +The [Permissions](https://github.com/Alfresco/alfresco-ng2-components/blob/development/ng2-components/ng2-alfresco-core/src/models/permissions.enum.ts) +enum contains all the valid permissions for which you can apply custom styles: **DELETE**, **UPDATE**, +**CREATE**, **UPDATEPERMISSIONS**, **NOT_DELETE**, **NOT_UPDATE**, **NOT_CREATE**, **NOT_UPDATEPERMISSIONS**. + +### Examples + +If you want to change the style on rows where the user can create content: + +```ts +let permissionsStyle: PermissionStyleModel[] = []; + +this.permissionsStyle.push(new PermissionStyleModel('document-list__create', PermissionsEnum.CREATE)); +``` + +```html + + +``` + +```css +adf-document-list >>> adf-datatable tr.document-list__create { + background: green !important; +} +``` + +If you want to change the style on the folders where the user doesn't have the permission to update: + +```ts + +let permissionsStyle: PermissionStyleModel[] = []; + +this.permissionsStyle.push(new PermissionStyleModel('document-list__disable', PermissionsEnum.NOT_UPDATE, false, true)); + +``` + +```html + + +``` + +```css +adf-document-list >>> adf-datatable tr.document-list__disable { + background: red !important; +} +``` + + + +## See also + +- [Document list component](document-list.component.md) + \ No newline at end of file diff --git a/docs/seeAlsoGraph.json b/docs/seeAlsoGraph.json index d66d001daa..4bc8c51da0 100644 --- a/docs/seeAlsoGraph.json +++ b/docs/seeAlsoGraph.json @@ -18,7 +18,7 @@ "context-menu.directive": [], "create-process-attachment.component": [], "create-task-attachment.component": [], - "data-column.component": ["document-list.component", "datatable.component"], + "data-column.component": ["document-list.component", "datatable.component", "tasklist.component"], "datatable.component": [ "data-column.component", "pagination.component" @@ -48,6 +48,7 @@ "node-permission.directive": [], "notification.service": [], "pagination.component": [], + "permission-style.model": ["document-list.component"], "people-search.component": [], "people.component": [], "process-attachment-list.component": [],