2.48.0 • Published 5 months ago

@memberjunction/ng-shared v2.48.0

Weekly downloads
-
License
ISC
Repository
-
Last release
5 months ago

@memberjunction/ng-shared

Utility functions and reusable components used across MemberJunction Explorer Angular packages.

Note: This package is intended for internal use within MJ Explorer and should not be used independently outside of the MemberJunction Explorer application.

Features

  • Shared services for consistent application behavior
  • Base components for navigation and resource management
  • Resource type management
  • Notification system integration
  • Event management
  • DOM utilities
  • Angular pipes for text and URL formatting

Installation

npm install @memberjunction/ng-shared

Dependencies

Peer Dependencies

  • @angular/common: ^18.0.2
  • @angular/core: ^18.0.2
  • rxjs: ^7.8.1

Core Dependencies

  • @memberjunction/core: Provides core functionality and metadata management
  • @memberjunction/core-entities: Entity definitions and resource management
  • @memberjunction/ng-notifications: Notification system integration
  • @memberjunction/ng-base-types: Base Angular component types
  • @memberjunction/graphql-dataprovider: GraphQL data provider for API communication
  • @progress/kendo-angular-notification: UI notification components

Module Import

import { MemberJunctionSharedModule } from '@memberjunction/ng-shared';

@NgModule({
  imports: [
    MemberJunctionSharedModule
    // ... other imports
  ]
})
export class YourModule { }

Key Components

SharedService

A singleton service that provides application-wide functionality:

import { SharedService } from '@memberjunction/ng-shared';

// Get singleton instance
const service = SharedService.Instance;

// Access session ID
const sessionId = service.SessionId;

// Access resource types
const viewResourceType = service.ViewResourceType;
const recordResourceType = service.RecordResourceType;
const dashboardResourceType = service.DashboardResourceType;
const reportResourceType = service.ReportResourceType;
const searchResultsResourceType = service.SearchResultsResourceType;
const listResourceType = service.ListResourceType;

// Get resource type by ID or name
const resourceTypeById = service.ResourceTypeByID('some-id');
const resourceTypeByName = service.ResourceTypeByName('reports');

// Format column values
const formattedValue = service.FormatColumnValue(column, value, maxLength, '...');

// Create notifications (Note: prefer MJNotificationService for new code)
service.CreateSimpleNotification('Operation completed', 'success', 3000);

// Convert between route segments and resource type names
const routeSegment = service.mapResourceTypeNameToRouteSegment('user views'); // returns 'view'
const resourceTypeName = service.mapResourceTypeRouteSegmentToName('view'); // returns 'user views'

Base Components

BaseNavigationComponent

Base class for all MJ Explorer navigation components that can be displayed from a route:

import { Component } from '@angular/core';
import { BaseNavigationComponent } from '@memberjunction/ng-shared';

@Component({
  selector: 'app-your-navigation',
  templateUrl: './your-navigation.component.html'
})
export class YourNavigationComponent extends BaseNavigationComponent {
  // Inherits from BaseAngularComponent
  // Provides foundation for routable components
}

BaseResourceComponent

Extended base class for components that work with MemberJunction resources:

import { Component } from '@angular/core';
import { BaseResourceComponent } from '@memberjunction/ng-shared';
import { ResourceData } from '@memberjunction/core-entities';

@Component({
  selector: 'app-your-resource',
  templateUrl: './your-resource.component.html'
})
export class YourResourceComponent extends BaseResourceComponent {
  // Access resource data
  ngOnInit() {
    console.log(this.Data); // ResourceData object
  }

  // Required abstract methods
  async GetResourceDisplayName(data: ResourceData): Promise<string> {
    // Return display name based on resource data
    return `Resource: ${data.ResourceRecordID}`;
  }

  async GetResourceIconClass(data: ResourceData): Promise<string> {
    // Return Font Awesome icon class
    return 'fa-solid fa-file';
  }

  // Lifecycle notifications
  protected onLoad() {
    this.NotifyLoadStarted();
    // ... load resource data
    this.NotifyLoadComplete();
  }

  // Handle resource save
  protected async saveResource() {
    const entity = await this.getResourceEntity();
    if (await entity.Save()) {
      this.ResourceRecordSaved(entity);
    }
  }
}

Angular Pipes

URLPipe (formatUrl)

Ensures URLs have proper protocol prefix:

// In template
<a [href]="website | formatUrl">Visit Site</a>

// Transforms:
// "example.com" → "https://example.com"
// "http://example.com" → "http://example.com" (unchanged)

SimpleTextFormatPipe (formatText)

Converts plain text formatting to HTML:

// In template
<div [innerHTML]="description | formatText"></div>

// Transforms:
// "Line 1\nLine 2" → "Line 1<br>Line 2"
// "Text\tIndented" → "Text&nbsp;&nbsp;&nbsp;&nbsp;Indented"

Utilities

Format Utilities

// Convert Markdown list to HTML
const htmlList = service.ConvertMarkdownStringToHtmlList('Unordered', '- Item 1\n- Item 2');
// Result: <ul><li>Item 1</li><li>Item 2</li></ul>

const orderedList = service.ConvertMarkdownStringToHtmlList('Ordered', '1. First\n2. Second');
// Result: <ol><li>First</li><li>Second</li></ol>

DOM Utilities

// Check if one element is a descendant of another
const isDescendant = SharedService.IsDescendant(parentRef, childRef);

// Trigger manual window resize event (useful for responsive components)
service.InvokeManualResize(50); // 50ms delay

Push Status Updates

// Subscribe to server push updates
service.PushStatusUpdates().subscribe(status => {
  console.log('Server status:', status);
});

Event Codes

Predefined event codes for standardized application event handling:

import { EventCodes } from '@memberjunction/ng-shared';

// Available event codes:
EventCodes.ViewClicked              // User clicked on a view
EventCodes.EntityRecordClicked      // User clicked on an entity record
EventCodes.AddDashboard            // Request to add a dashboard
EventCodes.AddReport               // Request to add a report
EventCodes.AddQuery                // Request to add a query
EventCodes.ViewCreated             // View was created
EventCodes.ViewUpdated             // View was updated
EventCodes.RunSearch               // Execute a search
EventCodes.ViewNotifications       // View notifications panel
EventCodes.PushStatusUpdates       // Server push status updates
EventCodes.UserNotificationsUpdated // User notifications changed
EventCodes.CloseCurrentTab         // Close current tab
EventCodes.ListCreated             // List was created
EventCodes.ListClicked             // User clicked on a list

Integration with Other MJ Packages

This package seamlessly integrates with:

  • @memberjunction/core: Uses Metadata for entity access and logging
  • @memberjunction/core-entities: Works with ResourceTypeEntity, UserNotificationEntity, and ResourceData
  • @memberjunction/ng-notifications: Delegates notification functionality to the dedicated notification service
  • @memberjunction/global: Uses global event system and utilities

Migration Notes

Deprecated Methods

Several notification-related methods in SharedService are deprecated in favor of MJNotificationService:

// Deprecated
SharedService.UserNotifications
SharedService.UnreadUserNotifications
SharedService.UnreadUserNotificationCount
service.CreateNotification(...)
SharedService.RefreshUserNotifications()
service.CreateSimpleNotification(...)

// Use instead
import { MJNotificationService } from '@memberjunction/ng-notifications';

MJNotificationService.UserNotifications
MJNotificationService.UnreadUserNotifications
MJNotificationService.UnreadUserNotificationCount
mjNotificationService.CreateNotification(...)
MJNotificationService.RefreshUserNotifications()
mjNotificationService.CreateSimpleNotification(...)

Build

To build this package:

cd packages/Angular/Explorer/shared
npm run build

The build uses Angular's ngc compiler and outputs to the dist directory.

2.27.1

9 months ago

2.23.2

9 months ago

2.46.0

5 months ago

2.23.1

9 months ago

2.27.0

9 months ago

2.34.0

7 months ago

2.30.0

8 months ago

2.19.4

10 months ago

2.19.5

10 months ago

2.19.2

10 months ago

2.19.3

10 months ago

2.19.0

10 months ago

2.19.1

10 months ago

2.15.2

10 months ago

2.34.2

7 months ago

2.15.0

10 months ago

2.34.1

7 months ago

2.15.1

10 months ago

2.38.0

6 months ago

2.45.0

5 months ago

2.22.1

9 months ago

2.22.0

9 months ago

2.41.0

6 months ago

2.22.2

9 months ago

2.26.1

9 months ago

2.26.0

9 months ago

2.33.0

7 months ago

2.18.3

10 months ago

2.18.1

10 months ago

2.18.2

10 months ago

2.18.0

10 months ago

2.37.1

6 months ago

2.37.0

6 months ago

2.14.0

10 months ago

2.21.0

9 months ago

2.44.0

6 months ago

2.40.0

6 months ago

2.29.0

8 months ago

2.29.2

8 months ago

2.29.1

8 months ago

2.25.0

9 months ago

2.48.0

5 months ago

2.32.0

8 months ago

2.32.2

8 months ago

2.32.1

8 months ago

2.17.0

10 months ago

2.13.4

11 months ago

2.36.0

7 months ago

2.13.2

12 months ago

2.13.3

11 months ago

2.13.0

12 months ago

2.36.1

7 months ago

2.13.1

12 months ago

2.43.0

6 months ago

2.20.2

10 months ago

2.20.3

9 months ago

2.20.0

10 months ago

2.20.1

10 months ago

2.28.0

9 months ago

2.47.0

5 months ago

2.24.1

9 months ago

2.24.0

9 months ago

2.31.0

8 months ago

2.12.0

1 year ago

2.39.0

6 months ago

2.16.1

10 months ago

2.35.1

7 months ago

2.35.0

7 months ago

2.16.0

10 months ago

2.42.1

6 months ago

2.42.0

6 months ago

2.23.0

9 months ago

2.11.0

1 year ago

2.10.0

1 year ago

2.9.0

1 year ago

2.8.0

1 year ago

2.7.0

1 year ago

2.7.1

1 year ago

2.6.1

1 year ago

2.6.0

1 year ago

2.5.2

1 year ago

1.6.1

1 year ago

1.6.0

1 year ago

2.4.1

1 year ago

2.4.0

1 year ago

2.0.0

1 year ago

1.5.3

1 year ago

1.5.2

1 year ago

1.5.1

1 year ago

1.5.0

1 year ago

2.3.0

1 year ago

2.3.2

1 year ago

2.3.1

1 year ago

2.3.3

1 year ago

1.8.1

1 year ago

1.8.0

1 year ago

1.4.1

1 year ago

1.4.0

1 year ago

2.2.1

1 year ago

2.2.0

1 year ago

1.7.1

1 year ago

1.7.0

1 year ago

1.3.3

1 year ago

1.3.2

1 year ago

1.3.1

1 year ago

1.3.0

1 year ago

2.1.2

1 year ago

2.1.1

1 year ago

2.5.0

1 year ago

2.1.4

1 year ago

2.1.3

1 year ago

2.5.1

1 year ago

2.1.5

1 year ago

2.1.0

1 year ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.0.11

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.8-next.6

2 years ago

1.0.8-next.5

2 years ago

1.0.8-next.4

2 years ago

1.0.8-next.3

2 years ago

1.0.8-next.2

2 years ago

1.0.8-next.1

2 years ago

1.0.8-next.0

2 years ago

1.0.7-next.0

2 years ago

1.0.8-beta.0

2 years ago

1.0.6

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.9.52

2 years ago

0.9.53

2 years ago

0.9.51

2 years ago

0.9.49

2 years ago

0.9.47

2 years ago

0.9.48

2 years ago

0.9.46

2 years ago

0.9.45

2 years ago

0.9.42

2 years ago

0.9.43

2 years ago

0.9.44

2 years ago

0.9.39

2 years ago

0.9.41

2 years ago

0.9.40

2 years ago

0.9.38

2 years ago

0.9.36

2 years ago

0.9.34

2 years ago

0.9.35

2 years ago

0.9.31

2 years ago

0.9.32

2 years ago

0.9.33

2 years ago

0.9.28

2 years ago

0.9.29

2 years ago

0.9.30

2 years ago

0.9.26

2 years ago

0.9.25

2 years ago

0.9.23

2 years ago

0.9.21

2 years ago

0.9.20

2 years ago

0.9.19

2 years ago

0.9.18

2 years ago

0.9.14

2 years ago

0.9.15

2 years ago

0.9.16

2 years ago

0.9.17

2 years ago

0.9.13

2 years ago

0.9.12

2 years ago

0.9.9

2 years ago

0.9.10

2 years ago

0.9.11

2 years ago

0.9.3

2 years ago

0.9.2

2 years ago