3.3.198 • Published 3 days ago

@smartbit4all/ng-client v3.3.198

Weekly downloads
-
License
-
Repository
-
Last release
3 days ago

Smart Ng Client


How to use

Installation

Go to your project, open the terminal and use the following command:

npm i @smartbit4all/ng-client

Provide the SmartNgClientModule in the app.module:

app.module.ts:

@NgModule({
    declarations: [...],
    imports: [
        SmartNgClientModule,
        ...
    ],
    providers: [
        SmartSessionService,
	    SmartViewContextService,
        ...
    ],
    ...
})

Usage

In order to use the SmartSessionService I recommend to follow the guideline belove.

Generate a service which will handle the session and the authentication.

Terminal:

>>> cd src/app

>>> mkdir services

>>> cd ./services

>>> ng g s authentication

Provide this new service as a global service:

app.module.ts:

@NgModule({
    declarations: [...],
    imports: [...],
    providers: [
        SmartSessionService,
        AuthenticationService,
        ...
    ],
    ...
})

Authentication state changed

The change of authentication state can be detected in any components. To handle it you must subscribe to the change itself.

Note that in this version a user is authenticated when the response of the GET session contains a list of authentications.

this.isAuthenticated = response.authentications.length > 0

any.component.ts:

constructor(
	private auth: AuthenticationService,
	private session: SmartSessionService
) {
	this.session.authenticationStateChanged.subscribe((isAuth: boolean) => {
		if (!isAuth) {
			this.router.navigate(['/login']);
		}
	});
}

Using locales

The SmartSessionService supports the usage of locales in you application. It is important to note that the language is related to the session!

This example uses the NgxTranslate/core package.

authentication.service.ts:

import { TranslateService } from '@ngx-translate/core';
...

export class AuthenticationService {
    ...

    constructor(
        ...
        private translate: TranslateService
    ) {
        this.session.localeChanged.subscribe(() => {
            this.translate.use(this.session.getLocale());
        });
    }

    async changeLocale(locale: string): Promise<void> {
        await this.session.changeLocale(locale);
    }

    getLocale(): string {
        return this.session.getLocale();
    }
}

SmartDevTool usage

Turn on and off the devTool:

// active
localStorage.setItem('smartDevToolActive', 'true');
// inactive
localStorage.setItem('smartDevToolActive', 'false');

Set the devTool's button visibility

// visible
localStorage.setItem('useDevTool', 'true');
// invisible
localStorage.setItem('useDevTool', 'false');

In order to use this package properly, please create a folder called viewcontext in which a view-context.pages.model.ts shall be created:

  • src/app/viewcontext/
    • view-context.pages.ts
    • view-context.handlers.ts

view-context.pages.ts:

export enum Pages {
    // mandatory
    VIEW_CONTEXT = 'viewContextUuid',

    // optionals
    ANY_PAGE = 'anyPage',
    ANY_DIALOG = 'anyDialog,
    ANY_COMPONENT = 'anyComponent,
    ...
}

view-context.handlers.ts:

import { SmartViewHandlerModel, ViewType } from '@smartbit4all/view-context';
import { Pages } from './view-context.pages';
import { AnyDialogService } from '../any-dialog/any-dialog.service';

export const viewContextHandlers: SmartViewHandlerModel[] = [
    // ViewType.Normal
    {
        name: Pages.ANY_PAGE,
        route: 'any'
    },
    // ViewType.Dialog
    {
        name: Pages.ANY_DIALOG,
        component: AnyDialogComponent
    },
    // ViewType.Normal or ViewType.Dialog
    {
        name: Pages.ANY_COMPONENT,
        route: 'any',
        component: AnyComponent
    }
];

Don't forget to define some ApiErrors and inject it into the AuthenticationService:

view-context.api-errors.ts:

const viewContextApiErrors: SmartViewContextApiErrors = {
    viewContextApiErrors:  [
        {
            code: "001",
            dialogTitle?: "Error"
            message: "An error message"
            buttonLabel?: "Ok"
        }
    ]
}

SmartLink

In order to use SmartLinks in your application, follow the instruction:

Firstly, set up the routing:

app-routing.module.ts:

const routes: Routes = [
    // Out of the box solution
    {
        path: `redirect/:${SmartLinkChannelVariableInPath}/:${SmartLinkUuidVariableInPath}`,
        component: SmartViewRedirect,
    },
    // Custom solution
    {
        path: `customRedirect/:${SmartLinkChannelVariableInPath}/:${SmartLinkUuidVariableInPath}`,
        component: RedirectComponent,
    },
    ...
]

Then you can set up your custom redirect component as you wish:

redirect.component.ts:

@Component({
    selector: "app-redirect",
    templateUrl: "./redirect.component.html",
    styleUrls: ["./redirect.component.css"],
})
export class RedirectComponent extends SmartViewRedirect {
    constructor(
        service: SmartViewContextService,
        navigation: SmartNavigationService,
        route: ActivatedRoute
    ) {
        super(
            service,
            navigation,
            route
        );
    }
}

Then subscribe for the openSmartLink event and handle it in your AuthenticationService:

authentication.service.ts:

constructor(...) {
    ...
    this.viewContext.openSmartLink.subscribe(() => {
        this.handleOpenSmartLinkEvent();
    })
}

private async handleOpenSmartLinkEvent(): Promise<void> {
    // Do your business logic here

    // If authentication is needed to open the link:
    let isAuthenticated = await this.isAuthenticated();
    if (isAuthenticated) {
        this.viewContext.openSmartLink.complete();
    } else {
        // Navigate to login screen without reloading the site!
    }
}

// Modify this if authentication is needed to open links
async login(request: LocalAuthenticationLoginRequest): Promise<boolean> {
    await this.auth.login(request);
    let isAuth = await this.session.getIsAuthenticated();
    if (isAuth) {
        await this.viewContext.initialize();

        await this.anyBffApi.startAnyPage().toPromise();

        // If there is a smart link waiting for opening...
        if (this.viewContext.isOpeningSmartLink) {
            this.viewContext.openSmartLink.complete();
            return isAuth;
        }

        let uuid = this.viewContext.getUuidOfPage(Pages.VIEW_CONTEXT);
        await this.viewContext.getAndSyncViewContext(uuid);
    }
    return isAuth;
}

UiActions

The ViewContext package contains a common manager for the UiActions. To use this tool, please follow the instructions.

action.descriptors.ts:

import {
    UiActionButtonIconPos,
    UiActionButtonType,
    UiActionDescriptor
} from '@smartbit4all/view-context';

// Build your own action descriptors
export const ActionDescriptors: Map<string, UiActionDescriptor> = new Map([
    [
        'EXAMPLE',
        {
            title: 'Example action',
	        type: UiActionButtonType.Raised,
	        color: 'primary',
            dialog: {
                title: 'Example dialog title',
                text: 'Example dialog text',
                actionButton: {
                    caption: 'Example action',
                    color: 'primary'
                },
                cancelButton: {
                    caption: 'Cancel',
                    color: ''
                }
            },
            inputDialog: { ... },
            confirmDialog: { ... },
            feedbackType: UiActionFeedbackType.SNACKBAR;
            feedbackText: "Example feedback";
        }
    ]
])

authentication.service.ts:

constructor(...) {
    ...
    // Set your descriptors
    this.viewContext.setActionDescriptors(ActionDescriptors);

    // Set basic feedback
    this.viewContext.commonFeedbackText = "Basic feedback."
    ...
}

example.component.ts:

@Component({
    selector: 'app-example',
    templateUrl: './example.component.html',
    styleUrls: ['./example.component.css']
})
export class ExampleComponent implements UseUiAction {
    possibleActions: UiAction[]; // Comes from the backend
    actions: UiActionModel[] = [];

    // UseUiAction properties
    submit: Subject<void> = new Subject();
	reSubscribeToChange: Subject<void> = new Subject();

    constructor(private service: ExampleService) {}

    // UseUiAction functions
    getAdditionalParams(uiAction: UiAction): UiActionAdditionalParams {
        // return additional parameters if needed
        throw new Error('Method not implemented.');
    }
    getModel() {
        // return the model of the page
        throw new Error('Method not implemented.');
    }
    async performUiActionRequest(uiActionRequest: UiActionRequest): Promise<any> {
        // perform the uiActionRequest on the proper service
        await this.service.performAction(uiActionRequest)
    }
    handleSpecificDemandsAsynchronously(uiAction: UiAction): Promise<UiActionSpecificDemandResponse> {
        // handle specific demands if needed
        throw new Error('Method not implemented.');
    }

    // Construct
    constructActions(): void {
        this.actions = [];
        let exceptions = ['EXCEPTION'];
        this.possibleActions.map((uiAction: UiAction) => {
            this.actions?.push({
                uiAction,
                serviceToUse: this, // bind a class which implements the UseUiAction
                exception: exceptions.includes(uiAction.code!)
            });
        });
    }
}

example.component.html:

<smart-ui-action-toolbar [uiActionModels]="actions"></smart-ui-action-toolbar>

Version logs

3.3.198

3 days ago

3.3.197

4 days ago

3.3.196

5 days ago

3.3.194

5 days ago

3.3.195

5 days ago

3.3.187

5 days ago

3.3.185

5 days ago

3.3.186

5 days ago

3.3.183

5 days ago

3.3.184

5 days ago

3.3.181

6 days ago

3.3.182

6 days ago

3.3.192

5 days ago

3.3.193

5 days ago

3.3.190

5 days ago

3.3.191

5 days ago

3.3.180

6 days ago

3.3.178

6 days ago

3.3.179

6 days ago

3.3.176

6 days ago

3.3.177

6 days ago

3.3.174

6 days ago

3.3.175

6 days ago

3.3.172

7 days ago

3.3.173

7 days ago

3.3.171

7 days ago

3.3.169

7 days ago

3.3.167

7 days ago

3.3.168

7 days ago

3.3.165

7 days ago

3.3.166

7 days ago

3.3.163

7 days ago

3.3.164

7 days ago

2.0.10

7 days ago

3.3.170

7 days ago

2.0.9

8 days ago

2.0.8

8 days ago

3.3.161

13 days ago

3.3.162

13 days ago

3.3.160

13 days ago

3.3.159

15 days ago

3.3.158

18 days ago

3.3.156

20 days ago

3.3.157

19 days ago

3.3.154

21 days ago

3.3.155

21 days ago

3.3.153

21 days ago

3.3.152

21 days ago

3.3.151

24 days ago

3.3.150

26 days ago

3.3.149

26 days ago

3.3.147

26 days ago

3.3.148

26 days ago

3.3.146

26 days ago

3.3.145

28 days ago

3.3.143

28 days ago

3.3.144

28 days ago

3.3.141

28 days ago

3.3.142

28 days ago

3.3.140

28 days ago

3.3.139

28 days ago

3.3.138

29 days ago

3.3.136

1 month ago

3.3.137

1 month ago

3.3.134

1 month ago

3.3.135

1 month ago

3.3.132

1 month ago

3.3.133

1 month ago

3.3.130

1 month ago

3.3.131

1 month ago

3.3.129

1 month ago

3.3.127

1 month ago

3.3.128

1 month ago

3.3.125

1 month ago

3.3.126

1 month ago

3.3.123

1 month ago

3.3.124

1 month ago

3.3.121

1 month ago

3.3.122

1 month ago

3.3.120

1 month ago

3.3.119

1 month ago

3.3.118

1 month ago

3.3.116

1 month ago

3.3.117

1 month ago

3.3.115

1 month ago

3.3.114

1 month ago

3.3.113

1 month ago

3.3.112

2 months ago

3.3.110

2 months ago

3.3.111

2 months ago

3.3.109

2 months ago

3.3.108

2 months ago

3.3.107

2 months ago

3.3.106

2 months ago

3.3.103

2 months ago

3.3.104

2 months ago

3.3.102

2 months ago

3.3.105

2 months ago

3.3.101

2 months ago

3.3.100

2 months ago

3.3.99

2 months ago

3.3.98

2 months ago

3.3.97

2 months ago

3.3.94

2 months ago

3.3.95

2 months ago

3.3.96

2 months ago

3.3.93

2 months ago

3.3.92

2 months ago

3.3.91

2 months ago

3.3.90

3 months ago

3.3.88

3 months ago

3.3.89

3 months ago

3.3.87

3 months ago

3.3.86

3 months ago

3.3.79

3 months ago

3.3.82

3 months ago

3.3.83

3 months ago

3.3.84

3 months ago

3.3.85

3 months ago

3.3.80

3 months ago

3.3.81

3 months ago

3.3.76

3 months ago

3.3.77

3 months ago

3.3.78

3 months ago

3.3.73

3 months ago

3.3.74

3 months ago

3.3.75

3 months ago

3.3.71

3 months ago

3.3.72

3 months ago

3.3.70

3 months ago

3.3.68

3 months ago

3.3.69

3 months ago

3.3.60

3 months ago

3.3.61

3 months ago

3.3.62

3 months ago

3.3.63

3 months ago

3.3.64

3 months ago

3.3.65

3 months ago

3.3.66

3 months ago

3.3.67

3 months ago

3.3.58

3 months ago

3.3.59

3 months ago

3.3.57

3 months ago

3.3.56

3 months ago

3.3.50

3 months ago

3.3.51

3 months ago

3.3.52

3 months ago

3.3.53

3 months ago

3.3.54

3 months ago

3.3.55

3 months ago

3.3.39

3 months ago

3.3.46

3 months ago

3.3.47

3 months ago

3.3.48

3 months ago

3.3.49

3 months ago

3.3.40

3 months ago

3.3.41

3 months ago

3.3.42

3 months ago

3.3.43

3 months ago

3.3.44

3 months ago

3.3.45

3 months ago

3.3.35

3 months ago

3.3.36

3 months ago

3.3.37

3 months ago

3.3.38

3 months ago

3.3.34

3 months ago

3.3.30

3 months ago

3.3.31

3 months ago

3.3.32

3 months ago

3.3.33

3 months ago

3.3.29

3 months ago

3.3.17

3 months ago

3.3.18

3 months ago

3.3.19

3 months ago

3.3.24

3 months ago

3.3.25

3 months ago

3.3.26

3 months ago

3.3.27

3 months ago

3.3.28

3 months ago

3.3.20

3 months ago

3.3.21

3 months ago

3.3.22

3 months ago

3.3.23

3 months ago

3.3.16

3 months ago

3.3.14

3 months ago

3.3.15

3 months ago

3.3.9

4 months ago

3.3.13

4 months ago

3.3.10

4 months ago

3.3.11

4 months ago

3.3.12

4 months ago

3.3.8

4 months ago

3.3.7

4 months ago

3.3.6

4 months ago

3.3.5

4 months ago

3.3.4

4 months ago

3.3.3

4 months ago

3.3.1

4 months ago

3.3.0

4 months ago

3.3.2

4 months ago

3.2.49

4 months ago

3.2.46

4 months ago

3.2.45

4 months ago

3.2.48

4 months ago

3.2.47

4 months ago

3.2.40

4 months ago

3.2.42

4 months ago

3.2.41

4 months ago

3.2.44

4 months ago

3.2.43

4 months ago

3.2.39

4 months ago

3.2.38

4 months ago

3.2.35

4 months ago

3.2.34

4 months ago

3.2.37

4 months ago

3.2.36

4 months ago

3.2.33

4 months ago

3.2.32

4 months ago

3.2.31

4 months ago

3.2.30

4 months ago

3.2.29

4 months ago

3.2.26

4 months ago

3.2.28

4 months ago

3.2.27

4 months ago

3.2.24

4 months ago

3.2.25

4 months ago

3.2.23

5 months ago

3.2.22

5 months ago

3.2.21

5 months ago

3.2.20

5 months ago

3.2.19

5 months ago

3.2.18

5 months ago

3.2.17

5 months ago

3.2.16

5 months ago

3.1.56

6 months ago

3.1.55

6 months ago

3.1.58

6 months ago

3.1.57

6 months ago

3.1.59

6 months ago

3.1.50

6 months ago

3.1.52

6 months ago

3.1.51

6 months ago

3.1.54

6 months ago

3.1.53

6 months ago

3.2.2

6 months ago

3.1.67

6 months ago

3.2.1

6 months ago

3.1.66

6 months ago

3.2.0

6 months ago

3.1.69

6 months ago

3.1.68

6 months ago

3.2.6

6 months ago

3.2.5

6 months ago

3.2.4

6 months ago

3.2.3

6 months ago

3.1.61

6 months ago

3.1.60

6 months ago

3.1.63

6 months ago

3.1.62

6 months ago

3.1.65

6 months ago

3.1.64

6 months ago

3.1.34

7 months ago

3.1.33

7 months ago

3.1.36

7 months ago

3.1.35

7 months ago

3.1.38

7 months ago

3.1.37

7 months ago

3.1.39

7 months ago

3.1.30

7 months ago

3.1.32

7 months ago

3.1.31

7 months ago

3.2.9

6 months ago

3.2.8

6 months ago

3.2.7

6 months ago

3.2.13

6 months ago

3.1.45

7 months ago

3.1.3

7 months ago

3.2.12

6 months ago

3.1.44

7 months ago

3.1.2

7 months ago

3.2.15

5 months ago

3.1.47

6 months ago

3.1.1

7 months ago

3.2.14

6 months ago

3.1.46

7 months ago

3.1.0

7 months ago

3.1.49

6 months ago

3.1.7

7 months ago

3.1.48

6 months ago

3.1.6

7 months ago

3.1.5

7 months ago

3.1.4

7 months ago

3.1.41

7 months ago

3.1.40

7 months ago

3.2.11

6 months ago

3.1.43

7 months ago

3.2.10

6 months ago

3.1.42

7 months ago

3.1.99

6 months ago

3.1.92

6 months ago

3.1.91

6 months ago

3.1.94

6 months ago

3.1.93

6 months ago

3.1.96

6 months ago

3.1.95

6 months ago

3.1.98

6 months ago

3.1.97

6 months ago

2.2.1

8 months ago

2.2.0

8 months ago

2.2.2

8 months ago

3.1.90

6 months ago

3.1.9

7 months ago

3.1.8

7 months ago

3.0.4

8 months ago

3.0.3

8 months ago

3.0.2

8 months ago

3.0.1

8 months ago

3.0.8

8 months ago

3.0.7

8 months ago

3.0.6

8 months ago

3.0.5

8 months ago

3.0.0

8 months ago

3.1.78

6 months ago

3.1.77

6 months ago

3.1.79

6 months ago

3.1.70

6 months ago

3.1.72

6 months ago

3.1.71

6 months ago

3.1.74

6 months ago

3.1.73

6 months ago

3.1.76

6 months ago

3.1.75

6 months ago

2.1.2

8 months ago

2.1.1

8 months ago

2.1.3

8 months ago

3.0.9

8 months ago

2.1.0

8 months ago

3.1.89

6 months ago

3.1.88

6 months ago

3.1.81

6 months ago

3.1.80

6 months ago

3.1.83

6 months ago

3.1.82

6 months ago

3.1.85

6 months ago

3.1.84

6 months ago

3.1.87

6 months ago

3.1.86

6 months ago

1.2.0

8 months ago

1.1.29

10 months ago

1.1.28

10 months ago

1.2.1

8 months ago

2.0.3

8 months ago

2.0.2

8 months ago

2.0.5

8 months ago

2.0.4

8 months ago

2.0.7

8 months ago

1.1.30

10 months ago

2.0.6

8 months ago

1.1.34

10 months ago

1.1.33

10 months ago

1.1.32

10 months ago

1.1.31

10 months ago

1.1.38

9 months ago

1.1.37

9 months ago

2.0.1

8 months ago

1.1.36

9 months ago

2.0.0

8 months ago

1.1.35

9 months ago

3.0.12

8 months ago

3.0.13

8 months ago

3.0.10

8 months ago

3.0.11

8 months ago

1.1.39

9 months ago

3.0.16

8 months ago

3.0.17

8 months ago

3.0.14

8 months ago

3.0.15

8 months ago

1.1.41

9 months ago

1.1.40

9 months ago

1.1.45

8 months ago

1.1.44

8 months ago

1.1.43

9 months ago

1.1.42

9 months ago

1.1.46

8 months ago

1.1.1

10 months ago

1.1.0

10 months ago

1.1.8

10 months ago

1.1.7

10 months ago

1.1.6

10 months ago

1.1.5

10 months ago

1.1.3

10 months ago

1.1.2

10 months ago

1.1.12

10 months ago

1.1.11

10 months ago

1.1.10

10 months ago

1.1.16

10 months ago

1.1.15

10 months ago

1.1.14

10 months ago

1.1.13

10 months ago

1.1.19

10 months ago

1.1.18

10 months ago

1.1.17

10 months ago

1.1.23

10 months ago

1.1.22

10 months ago

1.1.21

10 months ago

1.1.20

10 months ago

1.1.27

10 months ago

1.1.26

10 months ago

1.1.25

10 months ago

1.1.24

10 months ago

3.1.12

7 months ago

3.1.11

7 months ago

3.1.14

7 months ago

3.1.13

7 months ago

3.1.16

7 months ago

3.1.15

7 months ago

3.1.18

7 months ago

3.1.17

7 months ago

3.1.10

7 months ago

1.0.26

10 months ago

1.0.25

10 months ago

1.0.24

10 months ago

3.1.23

7 months ago

3.1.22

7 months ago

1.0.29

10 months ago

3.1.25

7 months ago

1.0.28

10 months ago

3.1.24

7 months ago

1.0.27

10 months ago

3.1.27

7 months ago

3.1.26

7 months ago

3.1.29

7 months ago

3.1.21

7 months ago

3.1.20

7 months ago

3.1.19

7 months ago

3.0.23

7 months ago

3.0.24

7 months ago

3.0.21

7 months ago

3.0.22

7 months ago

3.0.27

7 months ago

3.0.28

7 months ago

3.0.25

7 months ago

3.0.26

7 months ago

3.0.20

7 months ago

3.0.18

7 months ago

3.0.19

7 months ago

3.0.34

7 months ago

3.0.35

7 months ago

3.0.32

7 months ago

3.0.33

7 months ago

3.0.36

7 months ago

3.0.30

7 months ago

3.0.31

7 months ago

3.0.29

7 months ago

1.0.23

11 months ago

1.0.22

11 months ago

1.0.21

11 months ago

1.0.20

11 months ago

1.0.19

11 months ago

1.0.18

12 months ago

1.0.17

12 months ago

1.0.16

12 months ago

1.0.15

12 months ago

1.0.14

12 months ago

1.0.13

12 months ago

1.0.12

12 months ago

1.0.11

12 months ago

1.0.10

12 months ago

1.0.8

12 months ago

1.0.7

12 months ago

1.0.6

12 months ago

1.0.5

12 months ago

1.0.4

12 months ago

1.0.3

12 months ago

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago