0.0.90 • Published 7 years ago

@sitespirit/pagespirit v0.0.90

Weekly downloads
2
License
MIT
Repository
-
Last release
7 years ago

PageSpirit CMS package for Angular 5+

Contact: david@sitespirit.nl

Installation

npm i --save @sitespirit/pagespirit

Implementation

Minimum setup

The most basic implementation only gives you dynamic routes by providing a states object and api endpoint to the module:

import { PageSpiritModule, RouteLoader } from '@sitespirit/pagespirit';

Then put the PageSpiritModule inside your NgModule imports and provide the configuration object inside the forRoot method.

imports: [
  PageSpiritModule.forRoot({
    states: {
      content_page: { // State as named inside PageSpirit CMS
        component: ContentComponent, // The Component to be loaded for the found route
        items: { // The CMS data to be resolved before allowing the client access to the route
          content: {
            itemid: 1,
            seo_main: true
          }
        }
      }
    },
    apiEndpoint: 'https://client.telespirit.com' // TeleSpirit or Cloudant(WIP) Api Endpoint
  })
]

And add the RouteLoader to the end of your RouterModule.

imports: [
  RouterModule.forRoot([
    { // Make sure this is the last index of the routes array
      path: '**',
      canActivate: [RouteLoader],
      component: ErrorComponent
    }    
  ])
]

Static routes with dynamic data

import { RouteDataResolver } from '@sitespirit/pagespirit';

imports: [
  RouterModule.forRoot([
    {
      path: '',
      component: HomeComponent,
      pathMatch: 'full',
      data: {
        items: { // The CMS data to be resolved before allowing the client access to the route
          content: {
            itemid: 1
          }
        },
        language: 'nl', // Used for multi lingual websites
        uniqueKey: 'home', // Used for multi lingual webistes
        seo: { // SEO settings can be provided, but functionality is not working yet
          nl: {
            title: 'Title for this route' // WIP,
            description: 'Description for this route' // WIP
          }
        }
      },
      resolve: { // When the RouteDataResolver is done fetching the data, the data will be available via ActivatedRoute in the component
        stateData: RouteDataResolver
      }
    }
  ])
]

Get data without routing

Import the DataService in both the app.module as the component or service where you want to use it.

import { DataService } from '@sitespirit/pagespirit';

Provide the DataService in app.module.

providers: [DataService]

Example usage inside component or service:

constructor(private dataService: DataService);

this.dataService.getItemsData(
  {
    content: { // you can add multiple properties to fetch more items
      itemid: 1
    }
  }
).then(x => {
  console.log(x); // here the data is available
});

Rehydration

app.component.ts (your root component)

Rehydration is a little weird at this stage, for some reason rehydrating a child module isnt working yet in Angular 5, so for now we have to subscribe to some observables from the PageSpiritModule to get this working:

The following code is to be placed in your root component:

import { DataService, RouteLoader } from '@sitespirit/pagespirit';

constructor(private transferState: TransferState, private dataService: DataService, private routeLoader: RouteLoader)

To be placed inside your constructor:

const PAGESPIRIT_ITEMS_STATE = makeStateKey('pagespirit_items');
const PAGESPIRIT_URLS_STATE = makeStateKey('pagespirit_urls');
let pagespiritItemsState = this.transferState.get(PAGESPIRIT_ITEMS_STATE, null as any);
if(pagespiritItemsState){
  this.dataService.rehydrate(pagespiritItemsState);
}
this.dataService.items$.subscribe(x => {
  this.transferState.set(PAGESPIRIT_ITEMS_STATE, x as any);
});
let pagespiritUrlsState = this.transferState.get(PAGESPIRIT_URLS_STATE, null as any);
if(pagespiritUrlsState){
  this.routeLoader.rehydrate(pagespiritUrlsState);
}
this.routeLoader.transferObjSubject.asObservable().subscribe(x => {
  this.transferState.set(PAGESPIRIT_URLS_STATE, x as any);
});

app.module

import { BrowserModule, BrowserTransferStateModule } from '@angular/platform-browser'; import { DataService } from '@sitespirit/pagespirit';

imports: [
  BrowserModule.withServerTransition({ appId: 'pagespirit' }),
  BrowserTransferStateModule,
},
providers: [DataService]

app.server.module

import { ServerModule, ServerTransferStateModule } from '@angular/platform-server';

imports: [
  ServerModule,
  ServerTransferStateModule
]
0.0.90

7 years ago

0.0.89

7 years ago

0.0.88

7 years ago

0.0.87

7 years ago

0.0.86

7 years ago

0.0.85

7 years ago

0.0.84

7 years ago

0.0.82

7 years ago

0.0.81

7 years ago

0.0.80

7 years ago

0.0.79

7 years ago

0.0.78

7 years ago

0.0.77

7 years ago

0.0.76

7 years ago

0.0.75

7 years ago

0.0.74

7 years ago

0.0.73

7 years ago

0.0.72

7 years ago

0.0.70

7 years ago

0.0.69

7 years ago

0.0.68

7 years ago

0.0.67

7 years ago

0.0.66

7 years ago

0.0.65

7 years ago

0.0.64

7 years ago

0.0.63

7 years ago

0.0.62

7 years ago

0.0.61

7 years ago

0.0.60

7 years ago

0.0.59

8 years ago

0.0.58

8 years ago

0.0.57

8 years ago

0.0.56

8 years ago

0.0.55

8 years ago

0.0.54

8 years ago

0.0.53

8 years ago

0.0.52

8 years ago

0.0.51

8 years ago

0.0.50

8 years ago

0.0.49

8 years ago

0.0.48

8 years ago

0.0.47

8 years ago

0.0.46

8 years ago

0.0.45

8 years ago

0.0.44

8 years ago

0.0.43

8 years ago

0.0.42

8 years ago

0.0.41

8 years ago

0.0.40

8 years ago

0.0.39

8 years ago

0.0.38

8 years ago

0.0.37

8 years ago

0.0.36

8 years ago

0.0.35

8 years ago

0.0.34

8 years ago

0.0.33

8 years ago

0.0.32

8 years ago

0.0.31

8 years ago

0.0.30

8 years ago

0.0.29

8 years ago

0.0.28

8 years ago

0.0.27

8 years ago

0.0.26

8 years ago

0.0.25

8 years ago

0.0.24

8 years ago

0.0.23

8 years ago

0.0.22

8 years ago

0.0.21

8 years ago

0.0.20

8 years ago

0.0.19

8 years ago

0.0.18

8 years ago

0.0.17

8 years ago

0.0.16

8 years ago

0.0.15

8 years ago

0.0.14

8 years ago

0.0.13

8 years ago

0.0.12

8 years ago

0.0.11

8 years ago

0.0.10

8 years ago

0.0.9

8 years ago

0.0.8

8 years ago

0.0.7

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago