# Angular Integration

To install client libraries:

npm install @skilltree/skills-client-ng --save

This JS library contains:

  1. Skills Configuration - Global configuration used by Skills utilities.
  2. Skills Display - Visualize your website users' skill profile
  3. Skill Event Reporting - Report skill events using JS utility

# Skills Configuration

Step one is to globally configure the Skills client, we suggest including it in the application's entry point for single page applications, or as the first script tag import in multi-page applications.

Reminder

SkillsConfiguration is a singleton and you only need to provide configuration information once per your application's runtime for single page applications.

This configuration is used by the Skills Display and Skills Reporting libraries so you won't need to configure those separately.

SkillsConfiguration configure parameters:

Parameter Type Explanation
serviceUrl String (representing URL) url to the skills service - this is the same url as the dashboard - the User Interface and service endpoints are co-located
projectId String the id of the project that was created in the dashboard; visualize and report skills for the project with this id
authenticator String url to your Authentication Endpoint

SkillsConfiguration supplies the afterConfigure() method which returns a promise which will be resolved once the SkillsConfiguration configure method completes. This allows support, for example, for configuration options to be supplied by the server asynchronously.



 
 
 
 






import { SkillsConfiguration } from '@skilltree/skills-client-ng';

SkillsConfiguration.afterConfigure()
  .then(() => {
    // SkillsConfiguration.configure has been called 
  });

axios.get('my/configuration/endpoint')
  .then((result) => {
     SkillsConfiguration.configure(result.data);
   });

# Skills Display

The Skills Display component provides a comprehensive visualization of a user's skill and progress profile!

User Skills Image

The previously installed skills-client-ng library is packaged with the Skills Display component.

First, import the module into your app.module.ts file:

import { SkillsDisplayModule } from '@skilltree/skills-client-ng'

@NgModule({
  declarations: [
    ShowSkillsComponent,
  ],
  imports: [SkillsDisplayModule],
})
export class YourAppModule {
}

Now that the SkillsDisplayModule has been imported, Usage is trivial:

  1. Import SkillsDisplay component: import { SkillsDisplay } from '@skilltree/skills-client-ng';
  2. Utilize SkillsDisplay component: <skills-display/>

Here is a full example of an Angular single-file component that uses SkillsDisplay:







 







import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  template: `
    <div class="container">
        <skills-display/>
    </div>
  `,
})
export class ShowSkillsComponent {
  constructor() { }
}

If you are taking advantage of Skills Versioning then you need to provide the version property to the SkillsDisplay component:

<skills-display [version]="currentVersion"/>

SkillsDisplay component properties:

Prop Type Explanation
version Number (Optional) version to use in Skills Versioning paradigm
options Object (Optional) options object to control various behaviors of skills-display. See Skills Display Options Object
theme Object (Optional) theme object to customize colors. See Skills Display Theme Object

# Route changed event Since skills-client:3.3.0

Each time a user navigates within the Skills Client Display, the handleRouteChanged event is emitted containing the new path that was navigated to. This can be useful if the hosting application displays a breadcrumb and would like to update the current location within the Skills Client Display component.







 






 
 
 


import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  template: `
    <div class="container">
        <skills-display [handleRouteChanged]="skillsDisplayRouteChanged">
    </div>
  `,
})
export class ShowSkillsComponent {
  constructor() { }
  
  skillsDisplayRouteChanged = (newPath: string) => {
     console.log(`New Skills Display path: [${newPath}]`);
  }
}

# Programmatic navigation Since skills-client:3.3.1

The internal route of the Skills Client Display component can be changed by passing the desired path to the navigate() method. This can be useful if the hosting application displays a breadcrumb and would like to navigate to different locations within the Skills Client Display component by clicking a breadcrumb link for example.







 






 
 



 
 
 


import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  template: `
    <div class="container">
        <button (click)="navigate()">Navigate</button>
        <skills-display/>
    </div>
  `,
})
export class ShowSkillsComponentExample {

  @ViewChild('skillsDisplay')
  skillsDisplay: ShowSkillsComponent;

  constructor() { }
  
  navigate() {
    this.skillsDisplay.navigate('/subjects/subj0')
  }
}

# Skills Display Options Object

Options object optionally controls various behaviors of skills display with the following properties:

Prop Type Default Explanation
disableAutoScroll boolean false As a convenience, by default, the Skills Client Display will auto scroll to the top whenever the user navigates to a new page (route) within the display. Disable auto scroll to top on route change.
autoScrollStrategy string 'top-of-frame' On route change, either scroll to the top of the entire document, or the top of skills-display ('top-of-page','top-of-frame', or 'top-offset' - 'top offset' must be used in conjunction with the 'scrollTopOffset' option)
scrollTopOffset number 0 Used in conjunction with the autoScrollStrategy 'top-offset', scrollTopOffset will be subtracted from the display's element offset as the scroll to target (relevant when fixed/statically positioned elements preceed the Skills Display container).
isSummaryOnly boolean false When enabled, display renders overall summary only. This mode is not interactive, it provides a user's progress preview that can be displayed on a landing page.
internalBackButton boolean false When enabled, displays a back button to the left of the page title that can be used for navigating back in the browser history within the Skills Client Display. When enabled, the native browser history will not be updated when navigating within the Skills Client Display. It is recommended to leave this internalBackButton disabled unless navigating within the Skills Client Display interferes with the hosting application.

Here is an example of an options object:

{ 
    disableAutoScroll: false,
    autoScrollStrategy: 'top-of-page',
}

# Skills Display Theme Object

The theme object supports the customization of the color palette of the Skills Display to match your application. For example, you can easily style Skills Display to look something like this:

User Skills Image

The theme object supports the following properties:

Prop Explanation
backgroundColor page background color
disableBreadcrumb when set to true, the breadcrumb bar in the title section will not be displayed. default is false
breadcrumb.linkColor breadcrumbs's parent/ancestor link color
breadcrumb.linkHoverColor breadcrumbs's parent/ancestor link hover color
breadcrumb.currentPageColor breadcrumbs's current page color
breadcrumb.align Since skills-service:1.6.0 breadcrumbs's alignment for the title card; valid values are start, center, end (uses css justify-content (opens new window))
disableSkillTreeBrand when set to true, the SkillTree brand logo in the title section will not be displayed. default is false
skillTreeBrandColor Since skills-service:1.6.0 text color for the SkillTree brand logo; if not supplied the default is pageTitle.textColor
maxWidth maximum width of the component, can use any units supported by max-width CSS property (opens new window) such as %, em and px (ex. 100%); default is 1140px
landingPageTitle title of the landing page, default is User Skills
pageTitle.fontSize Since skills-service:1.6.0 font size for the title, can use any units supported by font-size CSS property (opens new window) such as %, em and px (ex. 1.2em)
pageTitle.textColor Since skills-service:1.6.0 text color for the title
pageTitle.borderColor Since skills-service:1.6.0 border color for the title card
pageTitle.borderStyle Since skills-service:1.6.0 border style for the title card, for example: borderStyle: 'none none solid none'
pageTitle.backgroundColor Since skills-service:1.6.0 background color for the title card
pageTitle.textAlign Since skills-service:1.6.0 title alignment, supported values are left, right and center
pageTitle.padding Since skills-service:1.6.0 padding for the title card, for example: padding: '1.6rem 1rem 1.1rem 1rem'
pageTitle.margin Since skills-service:1.6.0 margin for the title card, for example: margin: '-10px -15px 1.6rem -15px'
circleProgressInteriorTextColor 'x out of yyyy' text color inside circle progress widgets
progressIndicators.beforeTodayColor progress bar color for points earned before today
progressIndicators.earnedTodayColor progress bar color for points earned today
progressIndicators.completeColor progress bar color for 100% completion
progressIndicators.incompleteColor progress bar color for points not yet earned
textSecondaryColor secondary text, for example 'Need Help?' and dependent skill text
textPrimaryColor chart titles, progress titles, tile titles, descriptions, rank tile text
stars.unearnedColor color of unearned level stars
stars.earnedColor color of earned level stars
charts.axisLabelColor color of scales/axis text on charts
charts.labelBackgroundColor Since skills-service:1.7.0 chart label background color; applies to charts like Point History and Level Breakdown; please note that labels visibility depends on the presence of points and achievements
charts.labelBorderColor Since skills-service:1.7.0 chart label border color; applies to charts like Point History and Level Breakdown; please note that labels visibility depends on the presence of points and achievements
charts.labelForegroundColor Since skills-service:1.7.0 chart label text/foreground color; applies to charts like Point History and Level Breakdown; please note that labels visibility depends on the presence of points and achievements
charts.pointHistory.lineColor Since skills-service:1.7.0 Point History chart line color
charts.pointHistory.gradientStartColor Since skills-service:1.7.0 Point History chart start gradient color (on the top)
charts.pointHistory.gradientStopColor Since skills-service:1.7.0 Point History chart start stop/end color (on the bottom)
tiles.backgroundColor tile background color, such as subject tiles
tiles.borderColor Since skills-service:1.7.0 tile border color
tiles.watermarkIconColor My Rank, Rank overview, My Badges watermark icon color
infoCards.backgroundColor Since skills-service:1.7.0 info card background color; info cards only appear within tiles for example on the skill overview page
infoCards.foregroundColor Since skills-service:1.7.0 info card foreground/text color; info cards only appear within tiles for example on the skill overview page
infoCards.borderColor Since skills-service:1.7.0 info card border color; info cards only appear within tiles for example on the skill overview page
infoCards.iconColors Since skills-service:1.7.0 info card icon colors; must provide a list of colors (up to 4), for example iconColors: ['blue', 'green']
buttons.backgroundColor button background color
buttons.foregroundColor botton foreground/text color
buttons.disabledColor button disabled color including text and border
buttons.borderColor Since skills-service:1.7.0 button border color
badges.backgroundColor Since skills-service:1.6.0 badge background color; badges include Self Reportable tag and counts on the skill and badge filters
badges.foregroundColor Since skills-service:1.6.0 badge foreground/text color; badges include Self Reportable tag and counts on the skill and badge filters
graphLegendBorderColor border color of dependency graph legend
subjectTileIconColor color of subject tile icons
trophyIconColor color of the My Level trophy
backButton.padding optionally customize back button's padding (only applicable if the internalBackButton is enabled via the options object)
backButton.fontSize optionally customize back button's icon size (only applicable if the internalBackButton is enabled via the options object)
backButton.lineHeight optionally customize back button's height (only applicable if the internalBackButton is enabled via the options object)

Example of a 'Dark Blue' theme object

    {
      maxWidth: '100%',
      backgroundColor: '#626d7d',
      landingPageTitle: 'Themed User Skills',
      pageTitle: {
        textColor: 'white',
        fontSize: '1.5rem',
      },
      textSecondaryColor: 'white',
      textPrimaryColor: 'white',
      stars: {
        unearnedColor: '#787886',
        earnedColor: 'gold',
      },
      progressIndicators: {
        beforeTodayColor: '#3e4d44',
        earnedTodayColor: '#667da4',
        completeColor: '#59ad52',
        incompleteColor: '#cdcdcd',
      },
      charts: {
        axisLabelColor: 'white',
      },
      tiles: {
        backgroundColor:'#152E4d',
        watermarkIconColor: '#a6c5f7',
      },
      buttons: {
        backgroundColor: '#152E4d',
        foregroundColor: '#59ad52',
      },
      graphLegendBorderColor: '1px solid grey',
    }

# Skills Level Display

The skills-client-ng library also includes a convenient component to display the users's current overall level in the application. This can be used to display the user's current level consistently throughout the application, for example, in the application header.

Reminder

Before using the SkillsLevel component, you must make sure to initialize SkillsConfiguration with your system settings.

First, import the module into your app.module.ts file:

import { SkillsLevelModule } from '@skilltree/skills-client-ng'

@NgModule({
  declarations: [
    ShowSkillsLevelComponent,
  ],
  imports: [SkillsLevelModule],
})
export class YourAppModule {
}

then simply declare the skill-level component where appropriate







 







import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  template: `
    <div class="container">
        <skills-level/>
    </div>
  `,
})
export class ShowSkillsLevelComponent {
  constructor() { }
}

# Skill Event Reporting

The skills-client-ng library is packaged with the ability to report skill events using either Angular directives or the JS utility.

# skilltree directive

Import the directive in your app.module.ts file:

import { SkilltreeModule } from '@skilltree/skills-client-ng'

@NgModule({
  imports: [SkilltreeModule],
})
export class YourAppModule {
}

Now you can use the skill-tree directive to report skill events, the following example will report an event for a skill with id 'IronMan' when the button is clicked:

<button [skilltree]="'IronMan'">Report Skill</button>

The skilltree directive supports both <button> and <input> HTML node types. For a <button> element, the click event will trigger the skill event reporting and on <input> elements the input event will trigger the skill event reporting for the passed in skillId. Here is an example of an input event:

<input type="text" [skilltree]="\'Thor\'"><input/>

The Skills service add-skill-event endpoint responds with a comprehensive metatdata object describing how that skill influenced the user's skills posture. The skilltree directive provides a way to capture that result via a callback method, for example:



 

<input type="text" 
    [skilltree]="'Thor'" 
    (skills-report-success)="onReporterResponse"/>

and then let's say:

onReporterResponse(response) {
   // do what you need with response object
},

a response object may look something like this:

{
  "success": true,
  "skillApplied": true,
  "explanation": "Skill event was applied",
  "completed": []
}

For a full description of the response object please see Endpoint Result Object.

There are times when the HTTP call could fail, such as access denied or internal server error. You can also listen on the skills-report-error event to handle these situations.




 

<input type="text" 
    [skilltree]="'Thor'" 
    (skills-report-success)="onReporterResponse"
    (skills-report-error)="onReporterError" />

# SkillsReporter JS utility

If you find that the skilltree directive is not meeting your needs then there is always the JS utility to report skills:

import { SkillsReporter } from '@skilltree/skills-client-ng';

SkillsReporter.reportSkill(skillId)
    .then((res) => {
        // res = metatdata describing how that skill influenced user's skills posture
    })
    .catch((err) => {
        // err = object describing why this error occrued
    });

# Global Event Handling

In many cases, it is useful to define a global success and/or error handler function rather than defining event listeners on each element where you include the reporting utility.
For example:

  • display messages congratulating users on skills completion as well as level and badge achievements
  • handle all reporting errors by sending them to a logging service

Alongside standard, promise based, success and error handling, the SkillsReporter native javascript utility allows you to configure global success and error handlers utilizing the addSuccessHandler and addErrorHandler methods.









 
 

const myGlobalSuccessHandler = (result) => {
    toastr.success('skill successfully recorded!');
};

const myGlobalErrorHandler = (result) => {
    toastr.error('There was an error recording your skill');
};

SkillsReporter.addSuccessHandler(myGlobalSuccessHandler);
SkillsReporter.addErrorHandler(myGlobalErrorHandler);

Note: By default, a global success handler will only by invoked for results where a skill has been applied (skillApplied=true). To change the default behavior and enable notifications even when a reported skill has not been applied, set the notifyIfSkillNotApplied configuration option on the SkillReporter utility:





SkillsReporter.configure({
    notifyIfSkillNotApplied: true,
});

For a full description of the success response object (named result in the above example) please see Endpoint Result Object.

Here is a full example that registers and handles an event by displaying a toast message:

export class ToastExampleComponent 
    registerToDisplayProgress() {
        const myGlobalSuccessHandler = (result) => {
          if (result.completed) {
            result.completed.forEach((completedItem) => {
              this.handleEvent(completedItem);
            });
          }
        };
        SkillsReporter.addSuccessHandler(myGlobalSuccessHandler);
    }

    handleEvent(completedItem) {
        let title = '';
        let msg = '';
        switch (completedItem.type) {
        case 'Overall':
          title = `Level ${completedItem.level}!!!!`;
          msg = `Wow! Congratulations on the Overall Level ${completedItem.level}!`;
          break;
        case 'Subject':
          title = 'Subject Level Achieved!!';
          msg = `Impressive!! Level ${completedItem.level} in ${completedItem.name} subject!`;
          break;
        case 'Skill':
          title = 'Skill Completed!!';
          msg = `Way to complete ${completedItem.name} skill!!!`;
          break;
        case 'Badge':
          title = `${completedItem.name}!!!`;
          msg = `You are now a proud owner of ${completedItem.name} badge!!!`;
          break;
        default:
          title = 'Completed!!';
          msg = `Way to finish ${completedItem.name}!`;
        }
        
        this.displayToast(msg, title);
    }
}

Please note that the displayToast implementation is omitted as that will be specific to your application.

# SkillsReporter Configuration

The SkillReporter object allows for overriding the default behavior if required via the configure() method.

The configure() method supports the following parameters:

Prop Explanation
notifyIfSkillNotApplied if set to true, invoke global success handler(s) even when a reported skill has not been applied. See Global Event Handling.
retryInterval If an error occurs when reporting a skill, the SkillsReporter will attempt to retry reporting the skill at a later time. This property allows you to set the time in milliseconds for how often a skill that failed to be reported will be retried. default is 60000 (every 60 seconds)
maxRetryQueueSize The maximum number of failed reported skill attempts that will be queued and retried. default is 1000
maxRetryAttempts The maximum number of retry attempts for a given skillId before the SkillsReporter will no longer retry to report that skillId. default is 1400

Below is an example of how to configure the SkillsReporter to only retry up to 100 failed reported skill attempts, and to retry every 5 minutes.






SkillsReporter.configure({
    retryInterval: 300000,
    maxRetryQueueSize: 100,
});

# Report Event By Listening to Routes

While the skilltree client library doesn't provide an automatic way to report skills based on route changes it is quite easy to implement if you are using Angular Router (opens new window). Here is an example using Vue Router Router Events (opens new window):

import { Router, NavigationEnd  } from '@angular/router';
constructor(private router:Router) {
  this.routeEvent(this.router);
}
routeEvent(router: Router){
  router.events.subscribe(e => {
    if(e instanceof NavigationEnd) {
      const reportSkillId = router.routerState.snapshot.root.params['reportSkillId']
      if (reportSkillId) {
        SkillsConfiguration.afterConfigure()
          .then(() => {
            SkillsReporter.reportSkill(reportSkillId);
          });    
      }
    }
  });
}
Last Updated: 9/29/2022, 4:38:10 PM