Sakai-NG

repository·master·Indexed 21 days ago

https://github.com/primefaces/sakai-ng

An Angular-based template and starter application (version 21.0.0) generated with Angular CLI 21. It features PrimeNG integration with the Aura theme, a reactive LayoutService for managing UI state and dark mode, and various mock data services including CustomerService, ProductService, PhotoService, and IconService.

Tokens
5.6K
Snippets
25
Records
25
Agent score
76%

What's inside sakai-ng

  1. Start the Sakai19 development server

    master
    To start a local development server for Sakai19, use the Angular CLI ng serve command. The application will be available at http://localhost:4200/ and will automatically reload upon source file modifications.
    ng serve
  2. Bootstrap the Sakai-NG application

    master

    The application is initialized using Angular's bootstrapApplication function. It uses AppComponent as the root component and appConfig (imported from ./app.config) for application-wide configuration, including providers and dependency injection settings.

    import { bootstrapApplication } from '@angular/platform-browser';
    import { appConfig } from './app.config';
    import { AppComponent } from './app.component';
    
    bootstrapApplication(AppComponent, appConfig).catch((err) => console.error(err));
  3. Configure PrimeNG with Aura theme and Dark Mode

    master

    The providePrimeNG provider is used to initialize PrimeNG in the application. You can specify a theme preset (such as Aura) and configure dark mode behavior using the darkModeSelector option. In this project, dark mode is toggled via the .app-dark CSS class.

    To enable dark mode, ensure your application or a parent container has the .app-dark class applied.

    providePrimeNG({
        theme: {
            preset: Aura,
            options: {
                darkModeSelector: '.app-dark'
            }
        }
    })
  4. Configure application layout with LayoutConfig

    master

    The LayoutConfig interface defines the visual and structural settings for the application. You can manage these settings by updating the layoutConfig signal within the LayoutService.

    Available configuration keys:

    • preset: The UI preset name (e.g., 'Aura').
    • primary: The primary color theme (e.g., 'emerald').
    • surface: The surface color theme (optional).
    • darkTheme: Boolean indicating if dark mode is enabled.
    • menuMode: The menu behavior, such as 'static' or 'overlay'.
    export interface LayoutConfig {
        preset: string;
        primary: string;
        surface: string | undefined | null;
        darkTheme: boolean;
        menuMode: string;
    }
  5. Configure ESLint for Sakai-NG

    master

    Sakai-NG uses ESLint with specific configurations for TypeScript, Angular templates, and JavaScript files. The configuration enforces code style consistency, particularly regarding statement padding and Angular-specific selector patterns.

    Global Settings

    • Ignore Patterns: **/dist/** is ignored.
    • Plugins: Uses prettier for formatting.
    • Padding Rules: Enforces specific blank line requirements between statements (e.g., after variable declarations, before return statements, and around blocks).

    TypeScript (*.ts) Configuration

    When working with TypeScript files, the following rules and constraints apply:

    • Parser: Uses tsconfig.json and e2e/tsconfig.json for type-aware linting.
    • Angular Selectors:
      • Component selectors must use the p prefix, be of type element, and use kebab-case.
      • Directive selectors must use the p prefix, be of type attribute, and use camelCase.
    • Component Class Suffix: No specific suffix is required (empty string allowed).
    • Template Equality: @angular-eslint/template/eqeqeq is enabled but allows null or undefined comparisons.
    • Member Ordering: Enforces a specific order for class members: public-static-field -> static-field -> instance-field -> public-instance-method -> public-static-field.
    • Disabled Rules:
      • @angular-eslint/no-host-metadata-property is off.
      • @angular-eslint/no-output-on-prefix is off.
      • @typescript-eslint/ban-types is off.
      • @typescript-eslint/no-explicit-any is off.
      • @typescript-eslint/no-inferrable-types is off.
      • no-console is off.
      • prefer-const is off.

    HTML (*.html) Configuration

    Angular templates are linted using @angular-eslint/template/recommended and formatted with prettier.

    export default {
        root: true,
        ignorePatterns: ['**/dist/**'],
        plugins: ['prettier'],
        extends: ['prettier'],
        rules: {
            // ... rules
        },
        overrides: [
            { files: ['*.ts'], ... },
            { files: ['*.html'], ... },
            { files: ['*.js'], ... }
        ]
    };
  6. Use CustomerService to retrieve mock customer data

    master

    The CustomerService class provides a method getData() that returns an array of mock customer objects. This is useful for populating UI components like tables or lists during development. Each customer object includes details such as id, name, company, status, country, and representative information.

    import { CustomerService } from './customer.service';
    
    // Inside an Angular component or service
    constructor(private customerService: CustomerService) {}
    
    ngOnInit() {
        const customers = this.customerService.getData();
        console.log(customers);
    }
  7. Use IconService to retrieve icon assets

    master

    The IconService provides a way to fetch a list of available icons from a JSON configuration file located at assets/demo/data/icons.json. You can call getIcons() to trigger an HTTP GET request that populates the icons array and returns the list of icon objects.

    // Assuming IconService is provided in your component's dependencies
    this.iconService.getIcons().subscribe((icons) => {
        console.log('Available icons:', icons);
    });
  8. Retrieve product data from ProductService

    master

    The ProductService provides several methods to retrieve product information, returning data as Promises. These methods allow for different levels of data granularity and list sizes, which is useful for implementing pagination or different view modes (e.g., mini, small, or full lists).

    Available methods:

    • getProducts(): Returns all products.
    • getProductsSmall(): Returns the first 10 products.
    • getProductsMini(): Returns the first 5 products.
    • getProductsWithOrdersSmall(): Returns the first 10 products including their associated order history.
    • getProductsWithOrdersData(): Returns all products including their associated order history.
    // Example usage of ProductService methods
    this.productService.getProducts().then(products => {
        console.log('All products:', products);
    });
    
    this.productService.getProductsWithOrdersSmall().then(productsWithOrders => {
        console.log('Small list with orders:', productsWithOrders);
    });