Giter Club home page Giter Club logo

worldskills-angular-lib's Introduction

WorldSkills Angular Library

This project was generated with Angular CLI version 10.0.3.

Changelog

Notable changes can be viewed here.

Usage examples

Examples of how library components work can be viewed here.

Development server

Run ng serve for a dev server. Navigate to http://localhost:4200/. The app will automatically reload if you change any of the source files.

Code scaffolding

Run ng generate component component-name to generate a new component. You can also use ng generate directive|pipe|service|class|guard|interface|enum|module.

Build

Run npm run ws_build_lib to build the project. The build artifacts will be stored in the dist/ directory.

Packaging

Run npm run ws_npm_pack to create the tgz package (a node module) in the dist/worldskills-angular-lib directory.

Build & Package together

Run npm run ws_package

Publishing

We publish our packages on npmjs under the WorldSkills organization, here. After building and packaging, go to the dist folder cd dist/worldskills-angular-lib and run npm publish.

Running unit tests

Run ng test to execute the unit tests via Karma.

Running end-to-end tests

Run ng e2e to execute the end-to-end tests via Protractor.

Further help

To get more help on the Angular CLI use ng help or go check out the Angular CLI README.

Getting Started

package installaion

once you've set up a new angular application install the following libraries:
ng add @ng-bootstrap/ng-bootstrap
npm i angular-oauth2-oidc
npm i popper.js
npm i angular-font-awesome
npm i ng-select
npm i @worldskills/bootstrap

Styling

Add the following line to an applications styles.css
@import "~@ng-select/ng-select/themes/default.theme.css";
@import "~@worldskills/worldskills-angular-lib/assets/styles/index.css";

app.module.ts

add the following import statement into your app.module.ts
import { WorldskillsAngularLibModule, WsHttpInterceptor } from '@worldskills/worldskills-angular-lib';

ensure the following modules are within the import: { ... } section of your app.module.ts

@NgModule({
  declarations: [
    AppComponent,
    // your components
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpClientModule,
    OAuthModule.forRoot(),
    RouterModule.forRoot(appRoutes, routerOptions),
    WorldskillsAngularLibModule,
    NgbModule,
    NgSelectModule
  ],
  providers: [
    { provide: HTTP_INTERCEPTORS, useClass: WsHttpInterceptor, multi: true },
  ],  bootstrap: [AppComponent]
})
export class AppModule {
}

configure the module

Add the following to your app.component.ts to configure teh module. All configuration is optional. this example provides a full set of what's available. calling the next() method of a config type propogates that config to the module

constructor(private wsi: WorldskillsAngularLibService) {
}
ngOnInit() {
    const appConfig = this.wsi.appConfigSubject.getValue();
    appConfig.notAuthorizedRoute = ['/not-authorized'];
    this.wsi.appConfigSubject.next(appConfig);

    this.wsi.authConfigSubject.next({
        loginUrl: 'http://localhost:50300/oauth/authorize',
        clientId: '7221138f6772',
        redirectUri: 'http://localhost:4200/home',
        userinfoEndpoint: 'http://localhost:8081/users/loggedIn?show_child_roles=false&app_code=500',
        oidc: false
    });

    const httpConfig = this.wsi.httpConfigSubject.getValue();
    httpConfig.encoderUriPatterns = [];
    httpConfig.authUriPatterns = ['http://localhost:8081'];
    this.wsi.httpConfigSubject.next(httpConfig);

    const serviceConfig = this.wsi.serviceConfigSubject.getValue();
    serviceConfig.appCode = [500];
    serviceConfig.apiEndpoint = 'http://localhost:8081';
    this.wsi.serviceConfigSubject.next(serviceConfig);
}

http auth injector

The WSHttpInjector will extract the current auth token and inject into in future web requests that match the patterns specified in the httpConfig object.
ensure the following provider is added within the providers: { ... } section of your app.module.ts
{ provide: HTTP_INTERCEPTORS, useClass: WsHttpInterceptor, multi: true }

Extending the library

When extending the library follow theese guidelies:

  • We've taken a somewhat feature design to the approach.
    • What this means is that eacch folder in the library source (/src/lib) is it's own feature.
    • the only exception is the common folder.
  • The common folder contains shared code that would be useful to all features.
  • Features may sometimes depend on classes other features, an example would be the entity-tree-select feature whicch depends on models from Auth.
  • When you creating a new module, it's alright to keep it self-contained until fully developped then common code can be identified and moved to the common folder.
  • We follow the one-class per file rule. exceptions can be made where it is sensible.
  • When creating a new service that requires config. please hook onto the config cchange event in your service constructor

Hooking onto the config change events

this.wsi.serviceConfigSubject.subscribe(
  next => {
    this.appCode = next.appCode;
    this.endpoint = next.apiEndpoint + '/auth';
  }
);

Translations

  • i18n translations are lazy loaded via json files in /assets/i18n/lazy-loaded
  • translationns are issolated so they will not overwrite app transslations

Upadding translatioons

  • the .json files mainly exist to support weblate
  • the json.ts files are required to transslations to work at a lib level (thiss is a workaround for now)
  • regardless of how the translations are uopdated, we still needd to publissh a new versionn of the lib.

worldskills-angular-lib's People

Contributors

dependabot[bot] avatar fabian avatar hengkysanjaya123 avatar rajeevsiewnath avatar tehwazzard avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.