This is a library of services and components to interact with a DotCMS instance from Angular 2.
npm install dotcms-js --save
// Import all the services
import {
AppConfig,
FileSystemService,
HttpClient,
JWTAuthService,
LocalStoreService,
LoggerService,
NotificationService,
SettingsStorageService,
SiteBrowserService,
SiteBrowserState,
SiteSelectorService,
SiteTreetableService,
} from 'dotcms-js/dotcms-js';
// Add it to the declarations in your @NgModule
@NgModule({
providers: [
{provide: AppConfig, useClass: AppConfig},
{provide: FileSystemService, useClass: FileSystemService},
{provide: HttpClient, useClass: HttpClient},
{provide: JWTAuthService, useClass: JWTAuthService},
{provide: LocalStoreService, useClass: LocalStoreService},
{provide: LoggerService, useClass: LoggerService},
{provide: NotificationService, useClass: NotificationService},
{provide: SettingsStorageService, useClass: SettingsStorageService},
{provide: SiteBrowserService, useClass: SiteBrowserService},
{provide: SiteBrowserState, useClass: SiteBrowserState},
{provide: SiteSelectorService, useClass: SiteSelectorService},
{provide: SiteTreetableService, useClass: SiteTreetableService},
]
})
In order to start using the components you need to make sure you have a Auth Token. To get it we provide a login
method in the JWTAuthService
class.
If the login it's succefull the login
method will save an Auth Token to the localStorage in the browser so other services can use it, more info in our documentation.
In this example we are doing the login from the app.component.ts
but you can do it from aywhere you need.
import {Component, ViewEncapsulation} from '@angular/core';
import {JWTAuthService} from "dotcms-js/core/util/jwt-auth.service";
@Component({
selector: 'my-app',
template: '<h1>My App Component</h1>',
})
export class AppComponent {
constructor(authService: JWTAuthService) {
authService.login("http://demo.dotcms.com", "admin@dotcms.com", "admin").subscribe(token => {
console.log('Login successfully');
}, (err) => {
console.log('Error on login', err);
});
}
}
// Import all modules
import {
DotcmsBreadcrumbModule,
DotcmsSiteDatatableModule,
DotcmsSiteSelectorModule,
DotcmsSiteTreeTableModule,
DotcmsTreeableDetailModule,
} from 'dotcms-js/dotcms-js';
// Add it to the declarations in your @NgModule
@NgModule({
imports: [
DotcmsBreadcrumbModule,
DotcmsSiteDatatableModule,
DotcmsSiteSelectorModule,
DotcmsSiteTreeTableModule,
DotcmsTreeableDetailModule,
]
})
`
<site-selector></site-selector>
<breadcrumb></breadcrumb>
<treeable-detail></treeable-detail>
<site-datatable></site-datatable>
Initial commit
After you clone the repo
npm i
typings install
npm run build
Generated using TypeDoc