Installations
npm install ng2-alfresco-core
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
8.6.0
NPM Version
5.3.0
Releases
Contributors
Languages
TypeScript (91.2%)
HTML (4.28%)
SCSS (2.5%)
JavaScript (1.69%)
Shell (0.13%)
Rich Text Format (0.11%)
EJS (0.06%)
CSS (0.02%)
Developer
Download Statistics
Total Downloads
3,741,913
Last Day
11
Last Week
43
Last Month
168
Last Year
7,359
GitHub Statistics
294 Stars
10,802 Commits
268 Forks
104 Watching
261 Branches
487 Contributors
Bundle Size
1.91 MB
Minified
375.54 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.9.0
Package Id
ng2-alfresco-core@1.9.0
Size
756.44 kB
NPM Version
5.3.0
Node Version
8.6.0
Total Downloads
Cumulative downloads
Total Downloads
3,741,913
Last day
22.2%
11
Compared to previous day
Last week
72%
43
Compared to previous week
Last month
-84%
168
Compared to previous month
Last year
-51.2%
7,359
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
22
Dev Dependencies
56
Alfresco Core Library
- Prerequisites
- Install
- Toolbar Component
- Upload Directive
- Alfresco Api Service
- AppConfigService
- Notification Service
- Context Menu directive
- Accordion Component
- Authentication Service
- ADF Card View
- AlfrescoTranslationService
- Renditions Service
- Build from sources
- Build from sources
- NPM scripts
- Demo
- License
Prerequisites
Before you start using this development framework, make sure you have installed all required software and done all the necessary configuration, see this page.
If you plan using this component with projects generated by Angular CLI, please refer to the following article: Using ADF with Angular CLI
Install
1npm install ng2-alfresco-core
Toolbar Component
1<adf-toolbar title="Toolbar"> 2 <button md-icon-button> 3 <md-icon>create_new_folder</md-icon> 4 </button> 5 <button md-icon-button> 6 <md-icon>delete</md-icon> 7 </button> 8</adf-toolbar>
Properties
Name | Type | Default | Description |
---|---|---|---|
title | string | Toolbar title | |
color | string | Toolbar color, can be changed to empty value (default), primary , accent or warn . |
Upload Directive
Allows your components or common HTML elements reacting on File drag and drop in order to upload content. Used by attaching to an element or component.
Basic usage
The directive itself does not do any file management process, but collects information on dropped files and raises corresponding events instead.
1<div style="width:100px; height:100px" 2 [adf-upload]="true" 3 [adf-upload-data]="{ some: 'data' }"> 4 Drop files here... 5</div>
It is possible controlling when upload behaviour is enabled/disabled by binding directive to a boolean
value or expression:
1<div [adf-upload]="true">...</div> 2<div [adf-upload]="allowUpload">...</div> 3<div [adf-upload]="isUploadEnabled()">...</div>
You can decorate any element including buttons, for example:
1<button [adf-upload]="true" [multiple]="true" [accept]="'image/*'"> 2 Upload photos 3</button>
Modes
Directive supports several modes:
- drop mode, where decorated element acts like a drop zone for files (default mode)
- click mode, where decorated element invokes File Dialog to select files or folders.
It is also possible combining modes together.
1<div [adf-upload]="true" mode="['click']">...</div> 2<div [adf-upload]="true" mode="['drop']">...</div> 3<div [adf-upload]="true" mode="['click', 'drop']">...</div>
Click mode
For the click mode you can provide additional attributes for the File Dialog:
- directory, enables directory selection
- multiple, enables multiple file/folder selection
- accept, filters the content accepted
1<div style="width: 50px; height: 50px; background-color: brown" 2 [adf-upload]="true" 3 [multiple]="true" 4 [accept]="'image/*'"> 5</div> 6 7<div style="width: 50px; height: 50px; background-color: blueviolet" 8 [adf-upload]="true" 9 [multiple]="true" 10 [directory]="true"> 11</div>
Drop mode
For the moment upload directive supports only Files (single or multiple).
Support for Folders and accept
filters is subject to implement.
Events
Once a single or multiple files are dropped on the decorated element the upload-files
CustomEvent is raised.
The DOM event is configured to have bubbling
enabled, so any component up the component tree can handle, process or prevent it:
1<div (upload-files)="onUploadFiles($event)"> 2 <div [adf-upload]="true"></div> 3</div>
1onUploadFiles(e: CustomEvent) { 2 console.log(e.detail.files); 3 4 // your code 5}
Please note that event will be raised only if valid Files were dropped onto the decorated element.
The upload-files
event is cancellable, so you can stop propagation of the drop event to uppper levels in case it has been already handled by your code:
1onUploadFiles(e: CustomEvent) { 2 e.stopPropagation(); 3 e.preventDefault(); 4 5 // your code 6}
It is also possible attaching arbitrary data to each event in order to access it from within external event handlers. A typical scenario is data tables where you may want to handle also the data row and/or underlying data to be accessible upon files drop.
You may be using adf-upload-data
to bind custom values or objects for every event raised:
1<div [adf-upload]="true" [adf-upload-data]="dataRow"></div> 2<div [adf-upload]="true" [adf-upload-data]="'string value'"></div> 3<div [adf-upload]="true" [adf-upload-data]="{ name: 'custom object' }"></div> 4<div [adf-upload]="true" [adf-upload-data]="getUploadData()"></div>
As part of the details
property of the CustomEvent you can get access to the following:
1detail: { 2 sender: UploadDirective, // directive that raised given event 3 data: any, // arbitrary data associated (bound) 4 files: File[] // dropped files 5}
Styling
The decorated element gets adf-upload__dragging
CSS class name in the class list every time files are dragged over it.
This allows changing look and feel of your components in case additional visual indication is required,
for example you may want drawing a dashed border around the table row on drag:
1<table> 2 <tr [adf-upload]="true"> 3 ... 4 </tr> 5</table>
1.adf-upload__dragging > td:first-child { 2 border-left: 1px dashed rgb(68,138,255); 3} 4 5.adf-upload__dragging > td { 6 border-top: 1px dashed rgb(68,138,255); 7 border-bottom: 1px dashed rgb(68,138,255); 8} 9 10.adf-upload__dragging > td:last-child { 11 border-right: 1px dashed rgb(68,138,255); 12}
Alfresco Api Service
Provides access to initialized AlfrescoJSApi instance.
1export class MyComponent implements OnInit { 2 3 constructor(private apiService: AlfrescoApiService) { 4 } 5 6 ngOnInit() { 7 let nodeId = 'some-node-id'; 8 let params = {}; 9 this.apiService.getInstance().nodes 10 .getNodeChildren(nodeId, params) 11 .then(result => console.log(result)); 12 } 13}
Note for developers: the TypeScript declaration files for Alfresco JS API
are still under development and some Alfresco APIs may not be accessed
via your favourite IDE's intellisense or TypeScript compiler.
In case of any TypeScript type check errors you can still call any supported
Alfresco JS api by casting the instance to any
type like the following:
1let api: any = this.apiService.getInstance(); 2api.nodes.addNode('-root-', body, {});
AppConfigService
The AppConfigService
service provides support for loading and accessing global application configuration settings that you store on the server side in the form of a JSON file.
You may need this service when deploying your ADF-based application to production servers. There can be more than one server running web apps with different settings, like different addresses for Alfreco Content/Process services. Or there is a need to change global settings for all the clients.
The service is already pre-configured to look for the "app.config.json" file in the application root address.
That allows deploying ADF-based web applications to multiple servers together with different settings files, for example having development, staging or production environments.
Example of the default settings file content:
app.config.json
1{ 2 "ecmHost": "http://localhost:3000/ecm", 3 "bpmHost": "http://localhost:3000/bpm", 4 "application": { 5 "name": "Alfresco" 6 } 7}
Please note that settings above are default ones coming with the server.
You can override the values in your custom app.config.json
file if needed.
You can also change the path or name of the configuration file when importing the CoreModule in your main application.
1... 2@NgModule({ 3 imports: [ 4 ... 5 CoreModule.forRoot({ 6 appConfigFile: 'app.production.config.json' 7 }) 8 ], 9 ... 10} 11export class AppModule { }
Below is a simple example of using the AppConfigService in practice.
app.component.ts
1import { AppConfigService } from 'ng2-alfresco-core'; 2 3@Component({...}) 4export class AppComponent { 5 6 constructor(appConfig: AppConfigService) { 7 8 // get nested properties by the path 9 console.log(appConfig.get('application.name')); 10 11 // use generics for type safety 12 let version: number = appConfig.get<number>('version'); 13 console.log(version); 14 } 15}
You custom components can also benefit from the AppConfigService
,
you can put an unlimited number of settings and optionally a nested JSON hierarchy.
Different configurations based on environment settings
The CoreModule allows you to provide custom application configuration path. That means you can evaluate the final file name based on conditions, for example environment settings:
1let appConfigFile = 'app.config-dev.json'; 2if (process.env.ENV === 'production') { 3 appConfigFile = 'app.config-prod.json'; 4} 5 6@NgModule({ 7 imports: [ 8 ... 9 CoreModule.forRoot({ 10 appConfigFile: appConfigFile 11 }), 12 ... 13 ] 14})
Notification Service
The Notification Service is implemented on top of the Angular 2 Material Design snackbar. Use this service to show a notification message, and optionaly get feedback from it.
1import { NotificationService } from 'ng2-alfresco-core'; 2 3export class MyComponent implements OnInit { 4 5 constructor(private notificationService: NotificationService) { 6 } 7 8 ngOnInit() { 9 this.notificationService.openSnackMessage('test', 200000).afterDismissed().subscribe(() => { 10 console.log('The snack-bar was dismissed'); 11 }); 12 } 13}
1import { NotificationService } from 'ng2-alfresco-core'; 2 3export class MyComponent implements OnInit { 4 5 constructor(private notificationService: NotificationService) { 6 } 7 8 ngOnInit() { 9 this.notificationService.openSnackMessageAction('Do you want to report this issue?', 'send', 200000).afterDismissed().subscribe(() => { 10 console.log('The snack-bar was dismissed'); 11 }); 12 } 13}
Context Menu directive
See Demo Shell or DocumentList implementation for more details and use cases.
1<my-component [context-menu]="menuItems"></my-component> 2<context-menu-holder></context-menu-holder>
1@Component({ 2 selector: 'my-component' 3}) 4export class MyComponent implements OnInit { 5 6 menuItems: any[]; 7 8 constructor() { 9 this.menuItems = [ 10 { title: 'Item 1', subject: new Subject() }, 11 { title: 'Item 2', subject: new Subject() }, 12 { title: 'Item 3', subject: new Subject() } 13 ]; 14 } 15 16 ngOnInit() { 17 this.menuItems.forEach(l => l.subject.subscribe(item => this.commandCallback(item))); 18 } 19 20 commandCallback(item) { 21 alert(`Executing ${item.title} command.`); 22 } 23 24}
Accordion Component
The component provide a way to easy create an accordion menu. You can customize the header and the icon.
1<adf-accordion> 2 <adf-accordion-group [heading]="titleHeading" [isSelected]="true" [headingIcon]="'assignment'"> 3 <my-list></my-list> 4 </adf-accordion-group> 5</adf-accordion>
1@Component({ 2 selector: 'my-component' 3}) 4export class MyComponent implements OnInit { 5 6 titleHeading: string; 7 8 constructor() { 9 this.titleHeading = 'My Group'; 10 } 11 12}
Properties
Name | Type | Description |
---|---|---|
heading | string | The header title. |
isSelected | boolean | Define if the accordion group is selected or not. |
headingIcon | string | The material design icon. |
hasAccordionIcon | boolean | Define if the accordion (expand) icon needs to be shown or not, the default value is true |
Authentication Service
The authentication service is used inside the login component and is possible to find there an example of how to use it.
Events
Name | Description |
---|---|
onLogin | Raised when user logs in |
onLogout | Raised when user logs out |
app.component.ts
1import { AlfrescoAuthenticationService } from 'ng2-alfresco-core'; 2 3@Component({...}) 4export class AppComponent { 5 constructor(authService: AlfrescoAuthenticationService) { 6 this.alfrescoAuthenticationService.login('admin', 'admin').subscribe( 7 token => { 8 console.log(token); 9 }, 10 error => { 11 console.log(error); 12 } 13 ); 14 } 15}
ADF Card View
The component shows the CardViewModel} object.
1<adf-card-view 2 [properties]="[{label: 'My Label', value: 'My value'}]"> 3</adf-card-view> 4
Properties
Name | Type | Description |
---|---|---|
properties | {arrayCardViewModel} | (required) The custom view to render |
CardViewModel
1{ 2 "label": "string", 3 "value": "any", 4 "format": "string", 5 "default": "string" 6}
Name | Type | Description |
---|---|---|
label | string | The label to render |
value | string | The value to render |
format | string | The format to use in case the value is a date |
default | string | The default value to render in case the value is empty |
AlfrescoTranslationService
In order to enable localisation support you will need creating a /resources/i18n/en.json
file
and registering path to it's parent i18n
folder:
1class MainApplication { 2 constructor(translateService: AlfrescoTranslationService) { 3 translateService.addTranslationFolder('app', 'resources'); 4 } 5}
Service also allows changing current language for entire application.
Imagine you got a language picker that invokes onLanguageClicked
method:
1class MyComponent { 2 constructor(private translateService: AlfrescoTranslationService) { 3 } 4 5 onLanguageClicked(lang: string) { 6 this.translateService.use('en'); 7 } 8}
It is also possible providing custom translations for existing components by overriding their resource paths:
1class MyComponent {
2 constructor(private translateService: AlfrescoTranslationService) {
3 translateService.addTranslationFolder(
4 'ng2-alfresco-login',
5 'i18n/custom-translation/alfresco-login'
6 );
7 }
8}
Important note: addTranslationFolder
method redirects all languages to a new folder, you may need implementing multiple languages
or copying existing translation files to a new path.
Renditions Service
- getRenditionsListByNodeId(nodeId: string)
- createRendition(nodeId: string, encoding: string)
- getRendition(nodeId: string, encoding: string)
- isRenditionAvailable(nodeId: string, encoding: string)
Build from sources
Alternatively you can build component from sources with the following commands:
1npm install 2npm run build
Build from sources
You can build component from sources with the following commands:
1npm install 2npm run build
The
build
task rebuilds all the code, runs tslint, license checks and other quality check tools before performing unit testing.
NPM scripts
Command | Description |
---|---|
npm run build | Build component |
npm run test | Run unit tests in the console |
npm run test-browser | Run unit tests in the browser |
npm run coverage | Run unit tests and display code coverage report |
Demo
Please check the demo folder for a demo project
1cd demo 2npm install 3npm start
License
No vulnerabilities found.
Reason
all changesets reviewed
Reason
30 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0
Reason
no binaries found in the repo
Reason
SAST tool is run on all commits
Details
- Info: SAST configuration detected: CodeQL
- Info: all commits (30) are checked with a SAST tool
Reason
dependency not pinned by hash detected -- score normalized to 8
Details
- Info: Possibly incomplete results: error parsing shell code: a command can only contain words and redirects; encountered (: scripts/github/build/npm-check-bundles.sh:0
- Info: Possibly incomplete results: error parsing shell code: a command can only contain words and redirects; encountered (: scripts/github/release/deprecate-develop-build.sh:0
- Info: Possibly incomplete results: error parsing shell code: a command can only contain words and redirects; encountered (: scripts/update-version.sh:0
- Warn: containerImage not pinned by hash: Dockerfile:3
- Warn: containerImage not pinned by hash: Dockerfile:9: pin your Docker image by updating nginxinc/nginx-unprivileged:1.21-alpine to nginxinc/nginx-unprivileged:1.21-alpine@sha256:0fd172200e9ef7d3187cf526b24567027992ffce8a34cc9d5ac0d18deb974d33
- Info: 33 out of 33 GitHub-owned GitHubAction dependencies pinned
- Info: 10 out of 10 third-party GitHubAction dependencies pinned
- Info: 0 out of 2 containerImage dependencies pinned
- Info: 3 out of 3 npmCommand dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Info: jobLevel 'contents' permission set to 'read': .github/workflows/release-branch.yml:72
- Warn: jobLevel 'packages' permission set to 'write': .github/workflows/release-branch.yml:73
- Info: jobLevel 'contents' permission set to 'read': .github/workflows/release.yml:107
- Warn: jobLevel 'packages' permission set to 'write': .github/workflows/release.yml:108
- Info: jobLevel 'contents' permission set to 'read': .github/workflows/release.yml:193
- Info: jobLevel 'packages' permission set to 'read': .github/workflows/release.yml:194
- Info: jobLevel 'actions' permission set to 'read': .github/workflows/release.yml:195
- Warn: no topLevel permission defined: .github/workflows/codeql-analysis.yml:1
- Warn: no topLevel permission defined: .github/workflows/git-tag.yml:1
- Warn: no topLevel permission defined: .github/workflows/package_dispatch.yml:1
- Warn: no topLevel permission defined: .github/workflows/pull-from-crowdin.yml:1
- Warn: no topLevel permission defined: .github/workflows/pull-request.yml:1
- Warn: no topLevel permission defined: .github/workflows/rebase.yml:1
- Warn: no topLevel permission defined: .github/workflows/release-branch.yml:1
- Warn: no topLevel permission defined: .github/workflows/release.yml:1
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
14 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-c7qv-q95q-8v27
- Warn: Project is vulnerable to: GHSA-rhx6-c78j-4q9w
- Warn: Project is vulnerable to: GHSA-wgrm-67xf-hhpq
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-w5p7-h5w8-2hfq
- Warn: Project is vulnerable to: GHSA-776f-qx25-q3cc
- Warn: Project is vulnerable to: GHSA-cwfw-4gq5-mrqx
- Warn: Project is vulnerable to: GHSA-g95f-p29q-9xw4
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-hxm2-r34f-qmc5
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-rp65-9cf3-cjxr
Score
6.1
/10
Last Scanned on 2024-12-09
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More